@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,2552 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZLinkUserSpotCreationCoordinator = exports.ZLinkHostSpotAddressTransport = exports.ZLinkRelocationStateIncompatibleError = exports.ZLinkRouteMeshRuntimeCoordinator = exports.ZLinkRetiringRollbackError = exports.transferIdString = exports.ZLinkActorTransferAuthorityRuntime = exports.ZLinkFrameworkRuntimeHost = void 0;
4
+ exports.hasUnsupportedManualTopology = hasUnsupportedManualTopology;
5
+ exports.hasExactPeerReadiness = hasExactPeerReadiness;
6
+ const framework_errors_internal_1 = require("../framework-errors-internal");
7
+ const node_crypto_1 = require("node:crypto");
8
+ const runtime_message_1 = require("../backend/runtime-message");
9
+ const runtime_values_1 = require("../backend/runtime-values");
10
+ const service_runtime_contracts_1 = require("../foundation/service-runtime-contracts");
11
+ const runtime_state_projections_1 = require("../foundation/runtime-state-projections");
12
+ const abort_1 = require("../abort");
13
+ const backend_1 = require("../backend");
14
+ const LEGACY_MESH_SEND_TIMEOUT_MS = 1000;
15
+ const contracts_1 = require("../../contracts");
16
+ const submission_result_1 = require("../messaging/submission-result");
17
+ const ZLinkDispatchOptions_1 = require("../../contracts/Dispatch/ZLinkDispatchOptions");
18
+ const DiagnosticsValidation_1 = require("../../contracts/Configuration/DiagnosticsValidation");
19
+ const channels_1 = require("../channels");
20
+ const channel_envelope_1 = require("../channels/channel-envelope");
21
+ const actors_1 = require("../actors");
22
+ const actor_transport_delivery_gate_1 = require("../actors/actor-transport-delivery-gate");
23
+ const application_job_queue_handler_start_gate_1 = require("../application-jobs/application-job-queue-handler-start-gate");
24
+ const execution_1 = require("../execution");
25
+ const diagnostics_1 = require("../diagnostics");
26
+ const topology_runtime_projections_1 = require("../diagnostics/topology-runtime-projections");
27
+ const runtime_observation_queue_1 = require("../diagnostics/runtime-observation-queue");
28
+ const spots_1 = require("../spots");
29
+ const actor_message_follow_context_1 = require("../actors/actor-message-follow-context");
30
+ const actors_2 = require("../actors");
31
+ const streams_1 = require("../streams");
32
+ const locations_1 = require("../locations");
33
+ const Locations_1 = require("../../contracts/Locations");
34
+ const actor_runtime_options_factory_1 = require("./actor-runtime-options-factory");
35
+ const actor_transfer_runtime_1 = require("./actor-transfer-runtime");
36
+ const actor_transfer_authority_runtime_1 = require("./actor-transfer-authority-runtime");
37
+ const entry_actor_runtime_1 = require("./entry-actor-runtime");
38
+ const location_runtime_owner_1 = require("./location-runtime-owner");
39
+ const mesh_router_resolver_1 = require("./mesh-router-resolver");
40
+ const bound_session_relay_1 = require("./bound-session-relay");
41
+ const routing_id_1 = require("../routing-id");
42
+ const service_authority_payload_codec_1 = require("../foundation/service-authority-payload-codec");
43
+ const service_relocation_runtime_1 = require("../foundation/service-relocation-runtime");
44
+ const spot_runtime_options_factory_1 = require("./spot-runtime-options-factory");
45
+ const channel_runtime_options_factory_1 = require("./channel-runtime-options-factory");
46
+ const spot_node_runtime_options_factory_1 = require("./spot-node-runtime-options-factory");
47
+ const runtime_shutdown_1 = require("./runtime-shutdown");
48
+ const admission_1 = require("../admission");
49
+ const route_mesh_runtime_1 = require("./route-mesh-runtime");
50
+ const ConfigurationException_1 = require("../../contracts/Configuration/ConfigurationException");
51
+ const stateful_authority_route_runtime_1 = require("./stateful-authority-route-runtime");
52
+ const instance_activation_authority_1 = require("./instance-activation-authority");
53
+ const spot_address_transport_1 = require("./spot-address-transport");
54
+ const user_spot_creation_coordinator_1 = require("./user-spot-creation-coordinator");
55
+ const actor_placement_coordinator_1 = require("./actor-placement-coordinator");
56
+ const payload_codec_1 = require("../messaging/payload-codec");
57
+ const creation_payload_codec_1 = require("../messaging/creation-payload-codec");
58
+ const route_mesh_runtime_options_1 = require("./route-mesh-runtime-options");
59
+ const service_relocation_host_runtime_1 = require("./service-relocation-host-runtime");
60
+ const application_job_queue_1 = require("./application-job-queue");
61
+ const application_job_queue_scope_1 = require("../application-jobs/application-job-queue-scope");
62
+ const host_capacity_status_1 = require("./host-capacity-status");
63
+ class ZLinkFrameworkRuntimeHost {
64
+ options;
65
+ backendAdapterFactory;
66
+ lifecycleSink;
67
+ executionState;
68
+ runtimeState = contracts_1.ZLinkFrameworkRuntimeState.Preparing;
69
+ runtimeSequence = 0n;
70
+ runtimeObservationSource = Symbol('zlink.framework-runtime');
71
+ runtimeDeadline;
72
+ runtimeRelocationResult;
73
+ runtimeTerminationResult;
74
+ relocationOperation;
75
+ relocationStopStarting;
76
+ relocationOperationKey;
77
+ relocationOperationStartedAt;
78
+ shutdownOperation;
79
+ shutdownOperationStartedAt;
80
+ relocationTargetApplicationVersion;
81
+ runtimeObservers = new Set();
82
+ channelRuntime;
83
+ spotNodeRuntime;
84
+ streamRuntime;
85
+ statefulAuthorityRoutes;
86
+ locationOwner;
87
+ meshRouters;
88
+ boundSessionRelay;
89
+ actorHandoff;
90
+ actorTransferRegistry;
91
+ actorTransferRuntime;
92
+ actorTransferAuthorityRuntime;
93
+ serviceRelocation;
94
+ entryActorRuntime;
95
+ actorManager;
96
+ actorPlacement;
97
+ spotManager;
98
+ ownerLeaseRecoveryRuntime;
99
+ ownerLeaseRecoveryHandler;
100
+ ownerLeaseFailureHandler;
101
+ registerUserSpotHandlers;
102
+ destroyedActorRefs = new Map();
103
+ runtimeEventPublisher;
104
+ metrics;
105
+ applicationJobQueue;
106
+ capacityStatus;
107
+ metricRegistrations = [];
108
+ admission = new admission_1.ZLinkRuntimeAdmissionGate();
109
+ cachedLocationSpotRouteResolver;
110
+ actorClientLocationResolver;
111
+ // Shared, runtime-mutable message-flow mode cell — installed once so
112
+ // setMessageFlowMode flips every surface live. Seeded from config at start().
113
+ messageFlowModeCell = {
114
+ mode: 'errors'
115
+ };
116
+ dispatchErrorReporters = new WeakMap();
117
+ runtimeOrPreStartErrorSink = {
118
+ reportRuntimeTaskException: (taskName, error) => (this.errorSink ?? this.preStartErrorSink).reportRuntimeTaskException(taskName, error)
119
+ };
120
+ cachedDiagnosticsContext;
121
+ preStartErrorSink = new execution_1.ZLinkRuntimeTaskErrorSink();
122
+ channelTransport = () => this.channelRuntime;
123
+ channelRuntimeOptions = new channels_1.DefaultZLinkChannelRuntimeOptions(() => this.channelRuntime);
124
+ routeMeshRuntimeOptions = new route_mesh_runtime_options_1.DefaultZLinkRouteMeshRuntimeOptions(() => this.spotNodeRuntime);
125
+ routeTransport;
126
+ spotAddressTransport;
127
+ spotPublisherTransport = new spots_1.ZLinkRuntimeSpotPublisherTransport(() => this.spotNodeRuntime);
128
+ streamBindingRuntime;
129
+ boundSessionFactory;
130
+ spotRouterChannelIdForMesh;
131
+ routeMeshRuntime;
132
+ clientServerRuntime;
133
+ fanoutRuntime;
134
+ routeMeshCoordinator;
135
+ constructor(options, internalOptions) {
136
+ this.options = options;
137
+ this.backendAdapterFactory = resolveBackendAdapterFactory(internalOptions);
138
+ this.lifecycleSink = options.lifecycleSink;
139
+ this.runtimeEventPublisher = options.runtimeEventPublisher ?? new diagnostics_1.DefaultZLinkRuntimeEventPublisher();
140
+ this.metrics = new diagnostics_1.ZLinkRuntimeMetrics(options.registration.metrics?.meterProvider);
141
+ this.applicationJobQueue = new application_job_queue_1.ApplicationJobQueue((0, application_job_queue_1.resolveApplicationJobQueueConfiguration)(options.registration.applicationJobQueue, () => (0, application_job_queue_1.nodeEffectiveProcessorCount)(options.registration.worker?.maxThreads)), undefined, () => {
142
+ try {
143
+ return this.options.providerResolver?.get?.(application_job_queue_handler_start_gate_1.ZLINK_INTERNAL_APPLICATION_JOB_QUEUE_HANDLER_START_GATE)?.shouldHoldPermitBeforeHandler() === true;
144
+ }
145
+ catch {
146
+ return false;
147
+ }
148
+ });
149
+ this.capacityStatus = new host_capacity_status_1.HostCapacityStatusProjection(options.registration.coreHwm, this.applicationJobQueue);
150
+ this.clientServerRuntime = new topology_runtime_projections_1.ZLinkClientServerRuntimeProjection(() => this.channelRuntime, () => this.runtimeState);
151
+ this.fanoutRuntime = new topology_runtime_projections_1.ZLinkFanoutRuntimeProjection(() => this.channelRuntime, () => this.runtimeState);
152
+ this.meshRouters = new mesh_router_resolver_1.MeshRouterResolver(options.registration);
153
+ this.spotRouterChannelIdForMesh = this.meshRouters.spotRouterChannelIdByMesh();
154
+ const sendTimeoutMsForSpotMesh = (meshName) => options.registration.spotNodes.get(meshName)?.router?.sendTimeoutMs
155
+ ?? LEGACY_MESH_SEND_TIMEOUT_MS;
156
+ const sendTimeoutMsForSpotRouteChannel = (routeChannelId) => {
157
+ const routeChannel = options.registration.routeChannelOptions.get(routeChannelId);
158
+ if (routeChannel !== undefined) {
159
+ return routeChannel.sendTimeoutMs ?? LEGACY_MESH_SEND_TIMEOUT_MS;
160
+ }
161
+ return sendTimeoutMsForSpotMesh(routeChannelId);
162
+ };
163
+ const defaultSpotSendTimeoutMs = Math.max(LEGACY_MESH_SEND_TIMEOUT_MS, ...[...options.registration.spotNodes.values()].map(node => node.router?.sendTimeoutMs ?? LEGACY_MESH_SEND_TIMEOUT_MS), ...[...options.registration.routeChannelOptions.values()].map(route => route.sendTimeoutMs ?? LEGACY_MESH_SEND_TIMEOUT_MS));
164
+ this.routeTransport = new channels_1.ZLinkRuntimeRouteTransport(() => this.channelRuntime, (routerChannelId) => this.meshRouters.canUseRouterChannel(routerChannelId), () => this.spotNodeRuntime, { serializers: options.registration.messageSerializers }, (meshName, targetNodeRid) => this.meshRouters.classifyManualNodeTarget(meshName, targetNodeRid), (meshName, sourceNodeRid, parts) => this.submitLocalMeshRoute(meshName, sourceNodeRid, parts), this.metrics);
165
+ this.spotAddressTransport = new spot_address_transport_1.ZLinkHostSpotAddressTransport({
166
+ resolver: () => this.createLocationSpotRouteResolver(),
167
+ routed: this.routeTransport,
168
+ meshNames: () => [...this.options.registration.spotNodes]
169
+ .filter(([, node]) => (0, spot_address_transport_1.hasObjectClientCapability)(node.objectRole))
170
+ .map(([meshName]) => meshName),
171
+ isMeshConfigured: (meshName) => this.options.registration.spotNodes.has(meshName),
172
+ meshNode: (meshName) => this.spotNodeRuntime?.meshNode(meshName),
173
+ completions: (meshName) => this.spotNodeRuntime?.meshCompletionTable(meshName),
174
+ codecs: { serializers: options.registration.messageSerializers },
175
+ defaultRequestTimeoutMs: options.registration.requestTimeoutMs ?? 30_000,
176
+ defaultSendTimeoutMs: defaultSpotSendTimeoutMs,
177
+ sendTimeoutMsForMesh: sendTimeoutMsForSpotMesh,
178
+ sendTimeoutMsForRouteChannel: sendTimeoutMsForSpotRouteChannel,
179
+ dispatchErrors: this.createDispatchErrorReporter(this.runtimeOrPreStartErrorSink)
180
+ });
181
+ this.locationOwner = new location_runtime_owner_1.ZLinkLocationRuntimeOwner({
182
+ registration: options.registration,
183
+ runtimeEventPublisher: this.runtimeEventPublisher,
184
+ metrics: this.metrics,
185
+ fallbackNodeRid: `node-${(0, node_crypto_1.randomUUID)()}`,
186
+ rewriteAuthorityPayloadForOwner
187
+ });
188
+ this.streamBindingRuntime = new streams_1.ZLinkStreamBindingRuntime({
189
+ streamPayloadCodec: resolveStreamPayloadCodec(options.registration),
190
+ streamCompression: options.registration.streamCompression,
191
+ messageSerializers: options.registration.messageSerializers,
192
+ sessionRelocationSealTimeoutMs: options.registration.locations.options.sessionRelocationSealTimeoutMs
193
+ ?? Locations_1.zlinkDefaultLocationOptions.sessionRelocationSealTimeoutMs,
194
+ metrics: this.metrics,
195
+ flowCreationEnabled: () => this.flowCreationEnabled(),
196
+ errorSink: () => this.errorSink ?? this.preStartErrorSink,
197
+ nativeActorNodeProvider: () => this.spotNodeRuntime?.primaryMeshNode,
198
+ nativeActorMeshNameProvider: () => this.meshRouters.primaryMeshName(),
199
+ actorAuthorityFenceResolver: async (actorId, signal) => {
200
+ const resolution = await this.createActorLocationResolver()
201
+ ?.resolveDirectActorRoute(actorId, signal);
202
+ return resolution === undefined || resolution.kind !== 'ready'
203
+ ? undefined
204
+ : {
205
+ authorityOwnerGeneration: resolution.route.authorityOwnerGeneration,
206
+ ownerLeaseGeneration: resolution.route.ownerLeaseGeneration,
207
+ ownerId: resolution.route.ownerId,
208
+ ownerNodeGeneration: resolution.route.ownerNodeGeneration,
209
+ authorityStoreVersion: resolution.route.authorityStoreVersion,
210
+ actorType: resolution.route.actorType
211
+ };
212
+ },
213
+ confirmRemoteActorSessionBinding: (actor, sessionRid, signal, options) => {
214
+ const sessionNode = this.spotNodeRuntime?.primaryMeshNode;
215
+ return sessionNode === undefined
216
+ ? Promise.resolve()
217
+ : this.boundSessionRelay.actorPackets.confirmRemoteSessionBinding(actor, sessionNode.status().routingId, sessionRid, signal, options);
218
+ },
219
+ relay: (actor, header, payload, signal) => this.boundSessionRelay.actorPackets.relayActorPacket(actor, header, payload, signal),
220
+ notifyDisconnected: (actor, signal) => this.boundSessionRelay.actorPackets.notifyBoundActorDisconnected(actor, signal)
221
+ });
222
+ this.actorHandoff = new actors_2.ZLinkActorHandoffCoordinator({
223
+ routedTransport: this.routeTransport,
224
+ messageFollowDurationMs: options.registration.locations.options.messageFollowDurationMs,
225
+ requestTimeoutMs: options.registration.requestTimeoutMs,
226
+ requestSource: (actorId) => {
227
+ const owner = this.locationOwner.currentRuntime?.currentOwnerToken;
228
+ const state = this.actorManager?.getState(actorId);
229
+ const current = state?.nativeActorRef;
230
+ const meshName = state?.meshName;
231
+ const node = meshName === undefined
232
+ ? undefined
233
+ : this.spotNodeRuntime?.meshNode(meshName)?.status();
234
+ if (owner === undefined
235
+ || state === undefined
236
+ || current === undefined
237
+ || meshName === undefined
238
+ || node === undefined
239
+ || state.locationGeneration === undefined
240
+ || state.ownerLeaseGeneration === undefined
241
+ || state.ownerLeaseGeneration !== owner.leaseGeneration
242
+ || !(0, routing_id_1.routingIdsEqual)(node.routingId, current.nodeRid)) {
243
+ throw new ConfigurationException_1.ZLinkConfigurationException(`Actor '${actorId}' handoff requires a committed source owner fence.`);
244
+ }
245
+ return {
246
+ meshName,
247
+ objectGeneration: current.generation,
248
+ ownerId: owner.ownerId,
249
+ ownerLeaseGeneration: state.ownerLeaseGeneration,
250
+ nodeRid: String(current.nodeRid),
251
+ nodeRidHex: (0, routing_id_1.encodeRoutingIdStorageHex)(current.nodeRid),
252
+ nodeGeneration: node.lifecycleGeneration,
253
+ authorityOwnerGeneration: state.locationGeneration
254
+ };
255
+ },
256
+ validateReplySource: (source) => {
257
+ const owner = this.locationOwner.currentRuntime?.currentOwnerToken;
258
+ const node = this.spotNodeRuntime?.meshNode(source.meshName)?.status();
259
+ if (owner === undefined || node === undefined
260
+ || owner.ownerId !== source.ownerId
261
+ || owner.leaseGeneration !== source.ownerLeaseGeneration
262
+ || node.lifecycleGeneration !== source.nodeGeneration) {
263
+ return false;
264
+ }
265
+ return (0, routing_id_1.routingIdsEqual)(node.routingId, (0, routing_id_1.decodeRoutingId)(source.nodeRid, source.nodeRidHex));
266
+ },
267
+ onMarker: (marker, actorId, index, context) => {
268
+ if (marker === 'message_follow_relay' && context !== undefined) {
269
+ this.options.providerResolver?.get?.(actor_transport_delivery_gate_1.ZLINK_INTERNAL_ACTOR_TRANSPORT_DELIVERY_GATE)?.recordMessageFollowRelay?.(actorId, context);
270
+ }
271
+ if (marker === 'message_follow_route_removed') {
272
+ this.serviceRelocation.completeActorJoinSourceCleanup(actorId);
273
+ }
274
+ this.publishActorHandoffEvent({ marker, actorId, index });
275
+ },
276
+ onRequestFrame: (actorId, index, requestSeq, flags) => {
277
+ this.publishActorHandoffEvent({
278
+ marker: 'handoff_request_frame',
279
+ actorId,
280
+ index,
281
+ requestSeq: requestSeq?.toString(),
282
+ flags
283
+ });
284
+ },
285
+ onMessageFollowRelayed: async (actorId, targetActorRef, context, origin, queuedMessages, queuedBytes) => {
286
+ try {
287
+ const objectGeneration = BigInt(context.objectGeneration);
288
+ if (targetActorRef.objectGeneration !== objectGeneration) {
289
+ throw new Error(`Actor Message Follow changed object generation for '${actorId}'.`);
290
+ }
291
+ const sent = await this.spotNodeRuntime?.sendMessageFollowNotification((0, actor_message_follow_context_1.messageFollowOwnerNodeRid)(context.sourceOwner), origin.sourceNodeRid, {
292
+ source: {
293
+ kind: 'actor',
294
+ actor: {
295
+ actorId,
296
+ generation: objectGeneration,
297
+ nodeRid: (0, actor_message_follow_context_1.messageFollowOwnerNodeRid)(context.sourceOwner)
298
+ },
299
+ targetNodeRid: (0, actor_message_follow_context_1.messageFollowOwnerNodeRid)(context.sourceOwner),
300
+ targetNodeGeneration: BigInt(context.sourceOwner.nodeGeneration),
301
+ authorityOwnerGeneration: BigInt(context.sourceOwner.authorityOwnerGeneration),
302
+ ownerLeaseGeneration: BigInt(context.sourceOwner.ownerLeaseGeneration)
303
+ },
304
+ target: {
305
+ kind: 'actor',
306
+ actor: {
307
+ actorId,
308
+ generation: objectGeneration,
309
+ nodeRid: (0, actor_message_follow_context_1.messageFollowOwnerNodeRid)(context.targetOwner)
310
+ },
311
+ targetNodeRid: (0, actor_message_follow_context_1.messageFollowOwnerNodeRid)(context.targetOwner),
312
+ targetNodeGeneration: BigInt(context.targetOwner.nodeGeneration),
313
+ authorityOwnerGeneration: BigInt(context.targetOwner.authorityOwnerGeneration),
314
+ ownerLeaseGeneration: BigInt(context.targetOwner.ownerLeaseGeneration)
315
+ },
316
+ hopCount: context.hopCount,
317
+ queuedMessages,
318
+ queuedBytes,
319
+ originalOperation: origin.originalOperation,
320
+ originalReplyRouteId: origin.originalReplyRouteId
321
+ });
322
+ if (sent !== true) {
323
+ throw new Error(`Actor Message Follow source runtime '${context.sourceOwner.nodeRid}' is unavailable.`);
324
+ }
325
+ return true;
326
+ }
327
+ catch (error) {
328
+ this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('actor Message Follow notification', error);
329
+ return false;
330
+ }
331
+ },
332
+ isStaleActorRef: (actorId, actorRef) => {
333
+ const state = this.actorManager?.getState(actorId);
334
+ const current = state?.nativeActorRef;
335
+ if (actorRef === undefined)
336
+ return state?.remoteActorPacketTarget !== undefined;
337
+ return current !== undefined && (current.generation !== actorRef.objectGeneration ||
338
+ !(0, routing_id_1.routingIdsEqual)(current.nodeRid, actorRef.nodeRid));
339
+ },
340
+ isCurrentHandoffTarget: (actorId, spotId) => {
341
+ const currentSpotId = this.actorManager?.getState(actorId)?.spotId;
342
+ return currentSpotId !== undefined && String(currentSpotId) === spotId;
343
+ },
344
+ isCurrentActorRef: (actorId, actorRef) => {
345
+ const current = this.actorManager?.getState(actorId)?.nativeActorRef;
346
+ return current !== undefined
347
+ && current.generation === actorRef.objectGeneration
348
+ && (0, routing_id_1.routingIdsEqual)(current.nodeRid, actorRef.nodeRid);
349
+ },
350
+ currentOwnerFence: (actorId) => {
351
+ const state = this.actorManager?.getState(actorId);
352
+ const current = state?.nativeActorRef;
353
+ const owner = this.locationOwner.currentRuntime?.currentOwnerToken;
354
+ const node = state?.meshName === undefined
355
+ ? undefined
356
+ : this.spotNodeRuntime?.meshNode(state.meshName)?.status();
357
+ if (state === undefined || current === undefined || owner === undefined
358
+ || node === undefined || state.locationGeneration === undefined
359
+ || state.ownerLeaseGeneration === undefined
360
+ || !(0, routing_id_1.routingIdsEqual)(node.routingId, current.nodeRid)) {
361
+ return undefined;
362
+ }
363
+ return (0, actor_message_follow_context_1.ownerFence)({
364
+ ownerId: owner.ownerId,
365
+ ownerLeaseGeneration: state.ownerLeaseGeneration,
366
+ nodeRid: String(current.nodeRid),
367
+ nodeRidHex: (0, routing_id_1.encodeRoutingIdStorageHex)(current.nodeRid),
368
+ nodeGeneration: node.lifecycleGeneration,
369
+ authorityOwnerGeneration: state.locationGeneration
370
+ });
371
+ }
372
+ });
373
+ this.actorTransferRegistry = new actors_2.ZLinkActorTransferRegistry(options.registration.spotNodes, options.providerResolver, options.registration.messageSerializers);
374
+ this.boundSessionFactory = new streams_1.DefaultZLinkBoundSessionFactory(this.streamBindingRuntime);
375
+ this.boundSessionRelay = new bound_session_relay_1.ZLinkBoundSessionRelay({
376
+ requestTimeoutMs: options.registration.requestTimeoutMs,
377
+ sessionRelocationSealTimeoutMs: options.registration.locations.options.sessionRelocationSealTimeoutMs
378
+ ?? Locations_1.zlinkDefaultLocationOptions.sessionRelocationSealTimeoutMs,
379
+ routeTransport: this.routeTransport,
380
+ streamBindingRuntime: () => this.streamBindingRuntime,
381
+ meshRouters: this.meshRouters,
382
+ actorManager: () => this.actorManager,
383
+ spotManager: () => this.spotManager,
384
+ spotNodeRuntime: () => this.spotNodeRuntime,
385
+ detachedTaskRunner: this.detachedTaskRunner(),
386
+ actorSessionNode: (actorId) => {
387
+ const state = this.actorManager?.getState(actorId);
388
+ const meshName = state?.meshName
389
+ ?? (state?.actorType === undefined
390
+ ? undefined
391
+ : this.meshRouters.actorMeshName(state.actorType));
392
+ const runtime = this.spotNodeRuntime;
393
+ const node = meshName === undefined || typeof runtime?.meshNode !== 'function'
394
+ ? runtime?.primaryMeshNode
395
+ : runtime.meshNode(meshName);
396
+ return node === undefined
397
+ ? undefined
398
+ : (0, backend_1.meshActorSessionNodeAdapter)(node, meshName === undefined || typeof runtime?.meshCompletionTable !== 'function'
399
+ ? runtime?.primaryMeshCompletions
400
+ : runtime.meshCompletionTable(meshName));
401
+ },
402
+ actorLocationResolver: () => this.createActorLocationResolver(),
403
+ authorityStore: () => this.locationOwner.currentStores?.locationStore,
404
+ flowCreationEnabled: () => this.flowCreationEnabled(),
405
+ destroyedActorRefs: this.destroyedActorRefs,
406
+ errorSink: () => this.errorSink ?? this.preStartErrorSink,
407
+ boundSessionFactory: (actorId) => {
408
+ const factory = this.createActorManagerOptions().boundSessionFactory;
409
+ if (factory === undefined) {
410
+ throw new Error('Bound session factory is not configured.');
411
+ }
412
+ return factory(actorId);
413
+ }
414
+ });
415
+ this.entryActorRuntime = new entry_actor_runtime_1.ZLinkEntryActorRuntimeService({
416
+ actorManager: () => this.actorManager,
417
+ spotManager: () => this.spotManager,
418
+ spotNodeRuntime: () => this.spotNodeRuntime,
419
+ streamBindingRuntime: this.streamBindingRuntime,
420
+ boundSessionRelay: this.boundSessionRelay,
421
+ reportPostCommitError: (error) => (this.errorSink ?? this.preStartErrorSink).reportRuntimeTaskException('entry actor commit', error),
422
+ shutdownSignal: () => this.executionState?.abortController.signal
423
+ });
424
+ this.actorTransferRuntime = new actor_transfer_runtime_1.ZLinkActorTransferRuntime({
425
+ routeTransport: this.routeTransport,
426
+ messageSerializers: options.registration.messageSerializers,
427
+ spotManager: () => this.spotManager,
428
+ actorManager: () => this.actorManager,
429
+ primaryMeshNode: () => this.requirePrimaryMeshNode(),
430
+ notifyEntrySpotActorLeft: (actor, signal) => this.spotNodeRuntime?.notifyPrimaryEntrySpotActorLeft(actor, signal) ?? Promise.resolve(),
431
+ restoreEntrySpotActorJoined: (actor, signal) => this.spotNodeRuntime?.notifyPrimaryEntrySpotActorJoined(actor, signal) ?? Promise.resolve(),
432
+ locationLifecycle: () => this.locationOwner.currentLifecycle,
433
+ spotRouteResolver: () => this.createLocationSpotRouteResolver(),
434
+ actorHandoff: this.actorHandoff,
435
+ actorTransferRegistry: this.actorTransferRegistry,
436
+ authorityStore: () => this.locationOwner.currentStores?.locationStore,
437
+ currentOwner: () => this.locationOwner.currentRuntime?.currentOwnerToken,
438
+ relocationStore: () => this.options.registration.locations.relocationStoreInstance,
439
+ liveDescriptors: (meshName, signal) => {
440
+ const runtime = this.locationOwner.currentRuntime;
441
+ if (runtime === undefined) {
442
+ throw new Error('Session owner liveness is unavailable without a Location runtime.');
443
+ }
444
+ return runtime.listLiveMeshNodes(meshName, signal);
445
+ },
446
+ sessionRelocationWire: () => this.serviceRelocation,
447
+ clearRemoteActorPacketTarget: (actorId) => this.boundSessionRelay.clearRemoteActorPacketTarget(actorId),
448
+ prepareApplicationJob: async (preparationSignal) => {
449
+ const runtimeSignal = this.executionState?.abortController.signal;
450
+ const signal = runtimeSignal === undefined
451
+ ? preparationSignal
452
+ : AbortSignal.any([runtimeSignal, preparationSignal]);
453
+ const permit = await this.applicationJobQueue.acquire(signal);
454
+ let state = 'ready';
455
+ let closedReason;
456
+ let abort;
457
+ const cancel = (reason) => {
458
+ if (state !== 'ready')
459
+ return;
460
+ state = 'closed';
461
+ closedReason = reason;
462
+ if (abort !== undefined)
463
+ signal.removeEventListener('abort', abort);
464
+ permit.releaseAfterInternalProcessing();
465
+ };
466
+ try {
467
+ if (signal.aborted) {
468
+ cancel(signal.reason);
469
+ throw signal.reason;
470
+ }
471
+ permit.markApplicationQueued();
472
+ abort = () => cancel(signal.reason);
473
+ signal.addEventListener('abort', abort, { once: true });
474
+ }
475
+ catch (error) {
476
+ cancel(error);
477
+ throw error;
478
+ }
479
+ return {
480
+ run: async (operation) => {
481
+ if (state !== 'ready') {
482
+ throw closedReason ?? new Error('Prepared application job is no longer runnable.');
483
+ }
484
+ state = 'running';
485
+ signal.removeEventListener('abort', abort);
486
+ try {
487
+ return await (0, application_job_queue_scope_1.runWithApplicationJobPermit)(permit, operation);
488
+ }
489
+ finally {
490
+ state = 'closed';
491
+ }
492
+ },
493
+ cancel
494
+ };
495
+ },
496
+ reportPostCommitError: (error) => (this.errorSink ?? this.preStartErrorSink).reportRuntimeTaskException('source actor departure', error),
497
+ onSourceDepartureCompleted: (actorId) => this.publishActorHandoffEvent({ marker: 'source_cleanup', actorId }),
498
+ shutdownSignal: () => this.executionState?.abortController.signal,
499
+ metrics: this.metrics
500
+ });
501
+ this.serviceRelocation = new service_relocation_host_runtime_1.ZLinkHostServiceRelocationRuntime({
502
+ registration: options.registration,
503
+ providerResolver: options.providerResolver,
504
+ locationStore: () => this.locationOwner.currentStores?.locationStore,
505
+ currentOwner: () => this.locationOwner.currentRuntime?.currentOwnerToken,
506
+ liveDescriptors: (meshName, signal) => this.locationOwner.currentRuntime?.listLiveMeshNodes(meshName, signal)
507
+ ?? Promise.resolve([]),
508
+ localDescriptor: (meshName) => this.spotNodeRuntime?.meshNodeDescriptor(meshName),
509
+ meshNode: (meshName) => this.spotNodeRuntime?.meshNode(meshName),
510
+ completions: (meshName) => this.spotNodeRuntime?.meshCompletionTable(meshName),
511
+ spotManager: () => this.spotManager,
512
+ spotNodeRuntime: () => this.spotNodeRuntime,
513
+ actorManager: () => this.actorManager,
514
+ actorTransfer: this.actorTransferRuntime,
515
+ boundSessionRelocation: {
516
+ receiveSeal: (value, signal) => this.boundSessionRelay.boundSessions.receiveServiceWireSessionRelocationSeal(value, signal),
517
+ receiveRoute: value => this.boundSessionRelay.boundSessions.receiveServiceWireSessionRelocationRoute(value),
518
+ clear: () => this.boundSessionRelay.boundSessions.clearServiceWireSessionRelocations()
519
+ },
520
+ trackInstanceSpot: (input) => this.locationOwner.currentLifecycle?.trackInstanceSpot(input),
521
+ invalidateActorRoute: (actorId) => this.actorClientLocationResolver?.invalidateActorRoute(actorId),
522
+ reconcileStatefulAuthorityRoutes: (signal) => this.statefulAuthorityRoutes?.reconcile(signal) ?? Promise.resolve(),
523
+ runtimeEventPublisher: this.runtimeEventPublisher,
524
+ metrics: this.metrics
525
+ });
526
+ this.actorTransferAuthorityRuntime = new actor_transfer_authority_runtime_1.ZLinkActorTransferAuthorityRuntime({
527
+ store: () => this.locationOwner.actorTransferStore(),
528
+ recoveryOwnerId: () => this.locationOwner.currentRuntime?.ownerId,
529
+ recoveryLeaseTtlMs: {
530
+ ...Locations_1.zlinkDefaultLocationOptions,
531
+ ...options.registration.locations.options
532
+ }.ownerLeaseTtlMs
533
+ });
534
+ this.routeMeshCoordinator = new route_mesh_runtime_1.ZLinkRouteMeshRuntimeCoordinator({
535
+ meshNames: [...options.registration.spotNodes.keys()],
536
+ meshOptions: options.registration.spotNodes,
537
+ meshNode: (meshName) => this.spotNodeRuntime?.meshNode(meshName),
538
+ meshNodeDescriptor: (meshName) => this.spotNodeRuntime?.meshNodeDescriptor(meshName),
539
+ localPlacementCounts: (meshName) => {
540
+ const spotManager = this.spotManager;
541
+ const actorManager = this.actorManager;
542
+ if (spotManager === undefined || actorManager === undefined)
543
+ return undefined;
544
+ return {
545
+ activeActorCount: actorManager.activeActorCount(meshName),
546
+ activeSpotCount: spotManager.activeSpotCount(meshName)
547
+ };
548
+ },
549
+ isLocationStoreHealthy: () => {
550
+ if (!hasConfiguredLocationStore(options.registration)) {
551
+ return true;
552
+ }
553
+ const runtime = this.locationOwner.currentRuntime;
554
+ return runtime !== undefined
555
+ && runtime.ownerLeaseUsable
556
+ && runtime.lastError === undefined;
557
+ },
558
+ hostState: () => this.runtimeState,
559
+ admission: this.admission,
560
+ publishRetiring: (meshName, signal) => this.publishMeshRetiring(meshName, signal),
561
+ rollbackRetiring: (meshName, signal) => this.publishMeshServing(meshName, signal),
562
+ publishDraining: (meshName, signal) => this.publishMeshDraining(meshName, signal),
563
+ publishHostDraining: (signal) => this.publishHostDraining(signal),
564
+ drainResources: (meshName, signal, stopStartingSignal) => this.performMeshDrain(meshName, signal, stopStartingSignal),
565
+ shutdownResources: (meshName, signal) => this.performMeshShutdown(meshName, signal),
566
+ cleanupHostResources: (signal) => this.cleanupOwnerForDrain(signal),
567
+ forceStopResources: (meshName) => this.forceStopMesh(meshName)
568
+ });
569
+ this.metricRegistrations.push(this.metrics.registerHostState(() => runtimeStateMetricName(this.runtimeState)), this.metrics.registerHostCapacity(() => this.capacityStatus.snapshot(this.context?.getCoreHwmBudgetSnapshot())), this.metrics.registerApplicationJobQueuePressure(() => this.applicationJobQueue.snapshot()), this.metrics.registerMeshSnapshots(() => this.runtimeMetricMeshSnapshots()));
570
+ this.routeMeshRuntime = this.routeMeshCoordinator;
571
+ }
572
+ get isStarted() {
573
+ return this.executionState !== undefined;
574
+ }
575
+ get status() {
576
+ return {
577
+ state: this.runtimeState,
578
+ isReady: (0, runtime_state_projections_1.runtimeStateIsReady)(this.runtimeState),
579
+ acceptingWork: (0, runtime_state_projections_1.runtimeAcceptsWork)(this.runtimeState, this.admission.acceptsNewWork),
580
+ capacity: this.capacityStatus.snapshot(this.context?.getCoreHwmBudgetSnapshot()),
581
+ safeToShutdown: this.serviceRelocation.isSafeToShutdown(),
582
+ deadline: this.runtimeDeadline,
583
+ relocationResult: this.runtimeRelocationResult,
584
+ terminationResult: this.runtimeTerminationResult,
585
+ sequence: this.runtimeSequence,
586
+ observedAt: new Date()
587
+ };
588
+ }
589
+ observe(signal) {
590
+ const queue = new runtime_observation_queue_1.RuntimeEventQueue(undefined, signal);
591
+ this.runtimeObservers.add(queue);
592
+ queue.onClose(() => this.runtimeObservers.delete(queue));
593
+ return queue;
594
+ }
595
+ resetCapacityMetrics() {
596
+ const context = this.context;
597
+ if (context === undefined) {
598
+ throw new Error('Capacity metrics reset requires a started Framework runtime.');
599
+ }
600
+ this.capacityStatus.reset(() => context.resetCoreHwmBudgetMetrics());
601
+ }
602
+ relocate(options) {
603
+ const effectiveTargetApplicationVersion = validateRelocationOptions(options, this.options.registration.applicationVersion);
604
+ const deadlineMs = options.deadlineMs ?? 30_000;
605
+ if (!Number.isFinite(deadlineMs) || deadlineMs <= 0) {
606
+ return Promise.reject(new RangeError('Relocation deadlineMs must be greater than zero.'));
607
+ }
608
+ if (this.runtimeRelocationResult?.outcome === contracts_1.ZLinkFrameworkRelocationOutcome.Relocated) {
609
+ return Promise.resolve(this.runtimeRelocationResult);
610
+ }
611
+ if (this.shutdownOperation !== undefined) {
612
+ return Promise.resolve({
613
+ mode: options.mode,
614
+ effectiveTargetApplicationVersion,
615
+ outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
616
+ reason: contracts_1.ZLinkFrameworkRelocationReason.ShutdownRequested
617
+ });
618
+ }
619
+ const operationKey = `${options.mode}:${effectiveTargetApplicationVersion}`;
620
+ if (this.relocationOperation !== undefined) {
621
+ if (this.relocationOperationKey === operationKey) {
622
+ return waitForRuntimeOperation(this.relocationOperation, options.signal);
623
+ }
624
+ return Promise.resolve({
625
+ mode: options.mode,
626
+ effectiveTargetApplicationVersion,
627
+ outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
628
+ reason: contracts_1.ZLinkFrameworkRelocationReason.OperationInProgress
629
+ });
630
+ }
631
+ if (this.runtimeState !== contracts_1.ZLinkFrameworkRuntimeState.Serving) {
632
+ return Promise.resolve({
633
+ mode: options.mode,
634
+ effectiveTargetApplicationVersion,
635
+ outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
636
+ reason: this.runtimeState === contracts_1.ZLinkFrameworkRuntimeState.Relocating
637
+ ? contracts_1.ZLinkFrameworkRelocationReason.OperationInProgress
638
+ : contracts_1.ZLinkFrameworkRelocationReason.RuntimeNotReady
639
+ });
640
+ }
641
+ if (hasUnsupportedManualTopology(this.options.registration)) {
642
+ return Promise.resolve({
643
+ mode: options.mode,
644
+ effectiveTargetApplicationVersion,
645
+ outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
646
+ reason: contracts_1.ZLinkFrameworkRelocationReason.ManualTopologyUnsupported
647
+ });
648
+ }
649
+ this.runtimeDeadline = new Date(Date.now() + deadlineMs);
650
+ this.relocationTargetApplicationVersion = effectiveTargetApplicationVersion;
651
+ this.relocationOperationKey = operationKey;
652
+ this.relocationOperationStartedAt = performance.now();
653
+ this.relocationStopStarting = new AbortController();
654
+ this.relocationOperation = this.runRelocation(options.mode, effectiveTargetApplicationVersion, deadlineMs, this.relocationStopStarting.signal);
655
+ return waitForRuntimeOperation(this.relocationOperation, options.signal);
656
+ }
657
+ shutdown(options) {
658
+ const deadlineMs = options?.deadlineMs ?? 30_000;
659
+ if (!Number.isFinite(deadlineMs) || deadlineMs <= 0) {
660
+ return Promise.reject(new RangeError('Shutdown deadlineMs must be greater than zero.'));
661
+ }
662
+ if (this.shutdownOperation === undefined) {
663
+ this.runtimeDeadline = new Date(Date.now() + deadlineMs);
664
+ this.relocationStopStarting?.abort(new Error('Shutdown requested.'));
665
+ this.shutdownOperationStartedAt = performance.now();
666
+ this.shutdownOperation = this.runShutdown(deadlineMs);
667
+ }
668
+ return waitForRuntimeOperation(this.shutdownOperation, options?.signal);
669
+ }
670
+ async runRelocation(mode, effectiveTargetApplicationVersion, deadlineMs, stopStartingSignal) {
671
+ if (!this.isStarted) {
672
+ return this.completeRelocation(blockedRelocation(mode, effectiveTargetApplicationVersion, contracts_1.ZLinkFrameworkRelocationReason.RuntimeNotReady));
673
+ }
674
+ const deadlineAtMs = performance.now() + deadlineMs;
675
+ const remainingDeadlineMs = () => Math.max(1, deadlineAtMs - performance.now());
676
+ try {
677
+ // Runtime weight changes publish a newer descriptor asynchronously. A
678
+ // maintenance operation must observe that publication before it writes
679
+ // Retiring/Draining, otherwise two descriptor revisions can race and
680
+ // make a valid drain look like a Store failure.
681
+ await this.spotNodeRuntime?.waitForRuntimeWeightPublication();
682
+ const blocker = await this.preflightAutomaticPeerReadiness(deadlineAtMs, effectiveTargetApplicationVersion);
683
+ if (blocker !== undefined) {
684
+ return this.resetBlockedRelocation(blockedRelocation(mode, effectiveTargetApplicationVersion, blocker));
685
+ }
686
+ const descriptorPreparation = await this.routeMeshCoordinator.prepareHostRetire(remainingDeadlineMs());
687
+ if (descriptorPreparation !== 'prepared') {
688
+ return this.resetBlockedRelocation(blockedRelocation(mode, effectiveTargetApplicationVersion, descriptorPreparation === 'deadline_exceeded'
689
+ ? contracts_1.ZLinkFrameworkRelocationReason.DeadlineExceeded
690
+ : contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable));
691
+ }
692
+ this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Relocating);
693
+ const drained = await this.routeMeshCoordinator.relocateHost(remainingDeadlineMs(), stopStartingSignal);
694
+ if (drained.kind === 'forceStopped') {
695
+ return this.resetBlockedRelocation(blockedRelocation(mode, effectiveTargetApplicationVersion, stopStartingSignal.aborted
696
+ ? contracts_1.ZLinkFrameworkRelocationReason.ShutdownRequested
697
+ : drained.error instanceof service_relocation_host_runtime_1.ZLinkRelocationStateIncompatibleError
698
+ ? contracts_1.ZLinkFrameworkRelocationReason.StateIncompatible
699
+ : relocationReason(drained.reason)));
700
+ }
701
+ await this.publishHostRelocated();
702
+ return this.completeRelocation({
703
+ mode,
704
+ effectiveTargetApplicationVersion,
705
+ outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Relocated,
706
+ reason: contracts_1.ZLinkFrameworkRelocationReason.None
707
+ });
708
+ }
709
+ catch (error) {
710
+ const result = blockedRelocation(mode, effectiveTargetApplicationVersion, stopStartingSignal.aborted
711
+ ? contracts_1.ZLinkFrameworkRelocationReason.ShutdownRequested
712
+ : (0, abort_1.isDeadlineExceededError)(error)
713
+ ? contracts_1.ZLinkFrameworkRelocationReason.DeadlineExceeded
714
+ : error instanceof service_relocation_host_runtime_1.ZLinkRelocationStateIncompatibleError
715
+ ? contracts_1.ZLinkFrameworkRelocationReason.StateIncompatible
716
+ : contracts_1.ZLinkFrameworkRelocationReason.RelocationFailed);
717
+ return error instanceof route_mesh_runtime_1.ZLinkRetiringRollbackError
718
+ ? this.completeRelocation(result)
719
+ : this.resetBlockedRelocation(result);
720
+ }
721
+ }
722
+ async runShutdown(deadlineMs) {
723
+ const deadlineAtMs = performance.now() + deadlineMs;
724
+ try {
725
+ this.admission.close();
726
+ this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Draining);
727
+ if (this.relocationOperation !== undefined
728
+ && this.relocationStopStarting?.signal.aborted === true) {
729
+ await this.relocationOperation;
730
+ }
731
+ // Seal application admission before the public status reports that the
732
+ // host no longer accepts work. This prevents status polling from racing
733
+ // with the coordinator's synchronous seal step.
734
+ const unscopedStreamDrain = this.streamRuntime?.notifyUnscopedServerDrain();
735
+ const shutdown = this.routeMeshCoordinator.shutdownHost(this.runtimeDeadline, undefined, Math.max(0, deadlineAtMs - performance.now()));
736
+ const drain = await shutdown;
737
+ await unscopedStreamDrain;
738
+ await this.stop();
739
+ if (drain.kind === 'forceStopped') {
740
+ return this.completeTermination({
741
+ outcome: contracts_1.ZLinkFrameworkTerminationOutcome.ForceStopped,
742
+ reason: drain.reason === 'deadline_exceeded'
743
+ ? contracts_1.ZLinkFrameworkTerminationReason.DeadlineExceeded
744
+ : contracts_1.ZLinkFrameworkTerminationReason.TeardownFailed
745
+ });
746
+ }
747
+ if (performance.now() >= deadlineAtMs) {
748
+ throw (0, abort_1.createDeadlineExceededError)('Shutdown resource cleanup exceeded its deadline.');
749
+ }
750
+ return this.completeTermination({
751
+ outcome: contracts_1.ZLinkFrameworkTerminationOutcome.Stopped,
752
+ reason: contracts_1.ZLinkFrameworkTerminationReason.None
753
+ });
754
+ }
755
+ catch (error) {
756
+ await this.stop().catch(() => undefined);
757
+ return this.completeTermination({
758
+ outcome: contracts_1.ZLinkFrameworkTerminationOutcome.ForceStopped,
759
+ reason: (0, abort_1.isDeadlineExceededError)(error)
760
+ ? contracts_1.ZLinkFrameworkTerminationReason.DeadlineExceeded
761
+ : contracts_1.ZLinkFrameworkTerminationReason.TeardownFailed
762
+ });
763
+ }
764
+ }
765
+ resetBlockedRelocation(result) {
766
+ this.recordRelocationResult(result);
767
+ if (this.runtimeState === contracts_1.ZLinkFrameworkRuntimeState.Relocating) {
768
+ this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Serving);
769
+ }
770
+ this.runtimeDeadline = undefined;
771
+ this.relocationTargetApplicationVersion = undefined;
772
+ this.relocationStopStarting = undefined;
773
+ this.relocationOperation = undefined;
774
+ this.relocationOperationKey = undefined;
775
+ this.relocationOperationStartedAt = undefined;
776
+ return result;
777
+ }
778
+ completeRelocation(result) {
779
+ this.runtimeRelocationResult = result;
780
+ this.runtimeDeadline = undefined;
781
+ this.recordRelocationResult(result);
782
+ this.setRuntimeState(result.outcome === contracts_1.ZLinkFrameworkRelocationOutcome.Relocated
783
+ ? contracts_1.ZLinkFrameworkRuntimeState.Relocated
784
+ : contracts_1.ZLinkFrameworkRuntimeState.Error);
785
+ return result;
786
+ }
787
+ recordRelocationResult(result) {
788
+ if (this.relocationOperationStartedAt !== undefined) {
789
+ this.metrics.duration('zlink.host.relocation.duration', Math.max(0, performance.now() - this.relocationOperationStartedAt) / 1000, {
790
+ mode: relocationModeMetricName(result.mode),
791
+ outcome: result.outcome === contracts_1.ZLinkFrameworkRelocationOutcome.Relocated
792
+ ? 'relocated'
793
+ : 'blocked'
794
+ });
795
+ }
796
+ if (result.outcome === contracts_1.ZLinkFrameworkRelocationOutcome.Blocked) {
797
+ this.metrics.count('zlink.host.relocation.blocked', 1, {
798
+ mode: relocationModeMetricName(result.mode),
799
+ reason: relocationReasonMetricName(result.reason)
800
+ });
801
+ }
802
+ void this.runtimeEventPublisher.publish({
803
+ sourceName: 'zlink.runtime.host',
804
+ timestamp: new Date(),
805
+ identifier: 'zlink.runtime.host.relocation_changed',
806
+ mode: result.mode,
807
+ effectiveTargetApplicationVersion: result.effectiveTargetApplicationVersion,
808
+ outcome: result.outcome,
809
+ reason: result.reason
810
+ });
811
+ }
812
+ completeTermination(result) {
813
+ this.runtimeTerminationResult = result;
814
+ this.runtimeDeadline = undefined;
815
+ if (this.shutdownOperationStartedAt !== undefined) {
816
+ this.metrics.duration('zlink.host.shutdown.duration', Math.max(0, performance.now() - this.shutdownOperationStartedAt) / 1000, {
817
+ outcome: result.outcome === contracts_1.ZLinkFrameworkTerminationOutcome.Stopped
818
+ ? 'stopped'
819
+ : 'force_stopped'
820
+ });
821
+ }
822
+ if (result.outcome === contracts_1.ZLinkFrameworkTerminationOutcome.ForceStopped) {
823
+ this.metrics.count('zlink.host.shutdown.forced', 1, {
824
+ reason: terminationReasonMetricName(result.reason)
825
+ });
826
+ }
827
+ void this.runtimeEventPublisher.publish({
828
+ sourceName: 'zlink.runtime.host',
829
+ timestamp: new Date(),
830
+ identifier: 'zlink.runtime.host.termination_changed',
831
+ outcome: result.outcome,
832
+ reason: result.reason
833
+ });
834
+ this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Stopped);
835
+ return result;
836
+ }
837
+ setRuntimeState(state) {
838
+ if (this.runtimeState === state)
839
+ return;
840
+ this.runtimeState = state;
841
+ this.runtimeSequence += 1n;
842
+ this.notifyTopologyHostStateChanged();
843
+ const status = this.status;
844
+ for (const observer of this.runtimeObservers) {
845
+ if (state === contracts_1.ZLinkFrameworkRuntimeState.Stopped) {
846
+ observer.seal(status, this.runtimeObservationSource);
847
+ }
848
+ else {
849
+ observer.push(status, this.runtimeObservationSource);
850
+ }
851
+ }
852
+ if (state === contracts_1.ZLinkFrameworkRuntimeState.Stopped) {
853
+ this.runtimeObservers.clear();
854
+ }
855
+ }
856
+ notifyTopologyHostStateChanged() {
857
+ const callbacks = [
858
+ () => this.routeMeshCoordinator.hostStateChanged(),
859
+ () => this.clientServerRuntime
860
+ .hostStateChanged(),
861
+ () => this.fanoutRuntime
862
+ .hostStateChanged()
863
+ ];
864
+ for (const callback of callbacks) {
865
+ try {
866
+ callback();
867
+ }
868
+ catch (error) {
869
+ try {
870
+ this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('topology lifecycle observation', error);
871
+ }
872
+ catch {
873
+ // Monitoring must not change the host lifecycle result.
874
+ }
875
+ }
876
+ }
877
+ }
878
+ stopTopologyObservers() {
879
+ const callbacks = [
880
+ () => this.routeMeshCoordinator.stopObservers(),
881
+ () => this.clientServerRuntime
882
+ .stopObservers(),
883
+ () => this.fanoutRuntime
884
+ .stopObservers()
885
+ ];
886
+ for (const callback of callbacks) {
887
+ try {
888
+ callback();
889
+ }
890
+ catch (error) {
891
+ try {
892
+ this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('topology observer shutdown', error);
893
+ }
894
+ catch {
895
+ // Monitoring must not change the host lifecycle result.
896
+ }
897
+ }
898
+ }
899
+ }
900
+ publishActorHandoffEvent(event) {
901
+ void this.runtimeEventPublisher.publish({
902
+ sourceName: 'zlink.framework.actor-handoff',
903
+ timestamp: new Date(),
904
+ ...event
905
+ });
906
+ }
907
+ get locationRuntimeQuery() {
908
+ return this.ensureLocationRuntime();
909
+ }
910
+ /**
911
+ * Runtime toggle (ZLinkMessageFlowControl): flip the shared live-mode cell so every
912
+ * surface starts/stops tracing without a restart. Do not call this synchronous
913
+ * bridge from a framework execution context such as a handler or callback; use
914
+ * setMessageFlowModeAsync there.
915
+ */
916
+ setMessageFlowMode(mode) {
917
+ void this.setMessageFlowModeAsync(mode);
918
+ }
919
+ setMessageFlowModeAsync(mode) {
920
+ this.messageFlowModeCell.mode = (0, DiagnosticsValidation_1.requireMessageFlowLogMode)(mode);
921
+ return Promise.resolve();
922
+ }
923
+ messageFlowMode() {
924
+ return this.messageFlowModeCell.mode;
925
+ }
926
+ get context() {
927
+ return this.executionState?.context;
928
+ }
929
+ get taskRunner() {
930
+ return this.executionState?.taskRunner;
931
+ }
932
+ get errorSink() {
933
+ return this.executionState?.errorSink;
934
+ }
935
+ async start() {
936
+ await this.runLifecycle(() => this.startCore());
937
+ }
938
+ async startCore() {
939
+ if (this.executionState !== undefined) {
940
+ return;
941
+ }
942
+ this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Preparing);
943
+ this.lifecycleSink?.push('framework:start');
944
+ const channelAdapter = this.backendAdapterFactory.createChannelAdapter();
945
+ const context = channelAdapter.createContext();
946
+ const coreHwm = this.options.registration.coreHwm;
947
+ if (coreHwm !== undefined) {
948
+ context.configureCoreHwm(coreHwm);
949
+ }
950
+ let channelRuntime;
951
+ let spotNodeRuntime;
952
+ let streamRuntime;
953
+ let startedLocationRuntime;
954
+ let statefulAuthorityRoutes;
955
+ try {
956
+ this.executionState = new execution_1.ZLinkFrameworkExecutionState(context);
957
+ // Seed the shared live-mode cell from the configured mode (default errorsOnly).
958
+ this.messageFlowModeCell.mode =
959
+ this.options.registration.dispatch?.diagnostics.messageFlow ??
960
+ 'errors';
961
+ const dispatchErrors = this.createDispatchErrorReporter(this.executionState.errorSink);
962
+ channelRuntime = new channels_1.ZLinkChannelRuntimeManager(this.options.registration, channelAdapter, context, this.options.providerResolver, this.createChannelRuntimeOptions());
963
+ this.channelRuntime = channelRuntime;
964
+ channelRuntime.prepareMeshDispatch(this.executionState.taskRunner);
965
+ spotNodeRuntime = new spots_1.ZLinkSpotNodeRuntimeManager(this.createSpotNodeRuntimeOptions(context, dispatchErrors));
966
+ await spotNodeRuntime.start();
967
+ this.spotNodeRuntime = spotNodeRuntime;
968
+ this.registerUserSpotHandlers?.(spotNodeRuntime);
969
+ channelRuntime.bindRouteMeshRouters();
970
+ // Start bound receivers before publishing Serving descriptors. A
971
+ // discovered ClientServer endpoint must already be able to dispatch.
972
+ this.executionState.listenerTasks.push(...channelRuntime.start(this.executionState.taskRunner));
973
+ const locationRuntime = await this.locationOwner.startForRuntime(this.meshRouters.primaryMeshName(), spotNodeRuntime, channelRuntime);
974
+ startedLocationRuntime = locationRuntime;
975
+ if (locationRuntime !== undefined) {
976
+ this.installOwnerLeaseRecoveryPublication(locationRuntime, spotNodeRuntime, channelRuntime);
977
+ }
978
+ const locationStore = this.locationOwner.currentStores?.locationStore;
979
+ if (locationStore !== undefined && locationRuntime?.ownerLeaseUsable !== false) {
980
+ await spotNodeRuntime.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Preparing, this.executionState.abortController.signal);
981
+ if (this.requiresStatefulAuthorityRuntime()) {
982
+ this.installLocationBackedAuthorities(locationStore, spotNodeRuntime);
983
+ statefulAuthorityRoutes = this.createStatefulAuthorityRoutes(locationStore, spotNodeRuntime);
984
+ await statefulAuthorityRoutes.start(this.executionState.abortController.signal);
985
+ this.statefulAuthorityRoutes = statefulAuthorityRoutes;
986
+ }
987
+ }
988
+ streamRuntime = new streams_1.ZLinkStreamRuntimeManager({
989
+ registration: this.options.registration,
990
+ backendAdapterFactory: this.backendAdapterFactory,
991
+ context,
992
+ bindingRuntime: this.streamBindingRuntime,
993
+ providerResolver: this.options.providerResolver,
994
+ dispatchErrors,
995
+ metrics: this.metrics,
996
+ applicationJobQueue: this.applicationJobQueue,
997
+ acceptNewSession: (meshName) => meshName === undefined
998
+ ? this.admission.acceptsNewWork
999
+ : this.admission.accepts(meshName),
1000
+ primaryMeshName: this.meshRouters.primaryMeshName(),
1001
+ nativeMeshNode: spotNodeRuntime.primaryMeshNode,
1002
+ meshCompletions: spotNodeRuntime.primaryMeshCompletions,
1003
+ nativeMeshNodeForName: (meshName) => spotNodeRuntime?.meshNode(meshName),
1004
+ meshCompletionsForName: (meshName) => spotNodeRuntime?.meshCompletionTable(meshName)
1005
+ });
1006
+ streamRuntime.start();
1007
+ this.streamRuntime = streamRuntime;
1008
+ if (locationRuntime === undefined || locationRuntime.ownerLeaseUsable) {
1009
+ await spotNodeRuntime.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Serving, this.executionState.abortController.signal);
1010
+ }
1011
+ this.routeMeshCoordinator.markServing();
1012
+ this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Serving);
1013
+ this.lifecycleSink?.push('framework:started');
1014
+ }
1015
+ catch (error) {
1016
+ await statefulAuthorityRoutes?.stop();
1017
+ await (0, runtime_shutdown_1.rollbackRuntimeStart)({
1018
+ context,
1019
+ startedLocationRuntime,
1020
+ streamRuntime,
1021
+ spotNodeRuntime,
1022
+ channelRuntime,
1023
+ ownedStores: registeredRuntimeStores(this.options.registration)
1024
+ });
1025
+ this.executionState = undefined;
1026
+ this.channelRuntime = undefined;
1027
+ this.spotNodeRuntime = undefined;
1028
+ this.streamRuntime = undefined;
1029
+ this.statefulAuthorityRoutes = undefined;
1030
+ this.removeOwnerLeaseRecoveryPublication();
1031
+ this.locationOwner.clearForStop();
1032
+ this.cachedLocationSpotRouteResolver = undefined;
1033
+ throw error;
1034
+ }
1035
+ }
1036
+ async stop() {
1037
+ await this.runLifecycle(() => this.stopCore());
1038
+ }
1039
+ runtimeMetricMeshSnapshots() {
1040
+ const snapshots = [];
1041
+ for (const [meshName, options] of this.options.registration.spotNodes) {
1042
+ let status;
1043
+ try {
1044
+ status = this.routeMeshCoordinator.snapshot(meshName);
1045
+ }
1046
+ catch {
1047
+ continue;
1048
+ }
1049
+ const descriptor = this.spotNodeRuntime?.meshNodeDescriptor(meshName);
1050
+ const hasManual = (options.router?.manualConnections?.length ?? 0) > 0
1051
+ || (options.router?.manualPeerConnections?.length ?? 0) > 0
1052
+ || (options.pubSub?.manualConnections?.length ?? 0) > 0;
1053
+ const hasDiscovery = hasConfiguredLocationStore(this.options.registration);
1054
+ const source = hasManual && hasDiscovery
1055
+ ? 'manual_and_redis'
1056
+ : hasManual ? 'manual' : 'redis';
1057
+ const emptyCapacity = { active: 0, reserved: 0, limit: 0 };
1058
+ snapshots.push({
1059
+ meshName,
1060
+ source,
1061
+ configuredPeers: status.peers.length,
1062
+ connectedPeers: status.peers.filter(peer => peer.state !== contracts_1.ZLinkPeerState.NotConnected).length,
1063
+ readyPeers: status.readyPeerCount,
1064
+ channels: status.channels.map(channel => ({
1065
+ channelName: channel.channelName,
1066
+ readyMembers: channel.readyTargetCount
1067
+ })),
1068
+ actorCapacity: descriptor?.populationCapacity.actors ?? emptyCapacity,
1069
+ spotCapacity: descriptor?.populationCapacity.spots ?? emptyCapacity,
1070
+ spotTypeCapacities: (descriptor?.populationCapacity.spotTypes ?? []).map(capacity => ({
1071
+ spotKind: capacity.objectKind === 'instance_spot' ? 'instance' : 'user',
1072
+ stableType: capacity.stableType,
1073
+ active: capacity.active,
1074
+ reserved: capacity.reserved,
1075
+ limit: capacity.limit
1076
+ })),
1077
+ activation: descriptor?.activationConcurrency ?? { active: 0, limit: 0 },
1078
+ instanceSpots: []
1079
+ });
1080
+ }
1081
+ return snapshots;
1082
+ }
1083
+ async stopCore() {
1084
+ const state = this.executionState;
1085
+ if (state === undefined) {
1086
+ return;
1087
+ }
1088
+ const channelRuntime = this.channelRuntime;
1089
+ const spotNodeRuntime = this.spotNodeRuntime;
1090
+ const streamRuntime = this.streamRuntime;
1091
+ const statefulAuthorityRoutes = this.statefulAuthorityRoutes;
1092
+ this.stopTopologyObservers();
1093
+ this.removeOwnerLeaseRecoveryPublication();
1094
+ const locationSnapshot = this.locationOwner.clearForStop();
1095
+ this.executionState = undefined;
1096
+ this.channelRuntime = undefined;
1097
+ this.spotNodeRuntime = undefined;
1098
+ this.streamRuntime = undefined;
1099
+ this.statefulAuthorityRoutes = undefined;
1100
+ this.cachedLocationSpotRouteResolver = undefined;
1101
+ this.lifecycleSink?.push('framework:stop');
1102
+ await statefulAuthorityRoutes?.stop();
1103
+ await (0, runtime_shutdown_1.stopRuntimeParts)({
1104
+ state,
1105
+ locationSnapshot,
1106
+ cleanupDeadline: this.runtimeDeadline,
1107
+ streamRuntime,
1108
+ spotNodeRuntime,
1109
+ channelRuntime,
1110
+ serviceRelocation: this.serviceRelocation,
1111
+ ownedStores: registeredRuntimeStores(this.options.registration)
1112
+ });
1113
+ this.lifecycleSink?.push('framework:stopped');
1114
+ if (this.shutdownOperation === undefined) {
1115
+ this.setRuntimeState(contracts_1.ZLinkFrameworkRuntimeState.Stopped);
1116
+ }
1117
+ }
1118
+ installOwnerLeaseRecoveryPublication(runtime, spotNodeRuntime, channelRuntime) {
1119
+ let publishing = false;
1120
+ let lastPublishedOwnerToken = runtime.currentOwnerToken;
1121
+ let recoveryRequired = false;
1122
+ let recoveringServices;
1123
+ let stoppingServices;
1124
+ let transportFence = Promise.resolve();
1125
+ const handler = () => {
1126
+ const ownerToken = runtime.currentOwnerToken;
1127
+ if (publishing
1128
+ || ownerToken === undefined
1129
+ || (ownerToken === lastPublishedOwnerToken && !recoveryRequired))
1130
+ return;
1131
+ if (runtime.ownerLeaseUsable === false)
1132
+ return;
1133
+ publishing = true;
1134
+ const signal = this.executionState?.abortController.signal;
1135
+ const recoverServices = async () => {
1136
+ if (stoppingServices !== undefined) {
1137
+ await stoppingServices;
1138
+ stoppingServices = undefined;
1139
+ }
1140
+ if (this.statefulAuthorityRoutes !== undefined)
1141
+ return;
1142
+ const store = this.locationOwner.currentStores?.locationStore;
1143
+ if (store === undefined || this.executionState === undefined)
1144
+ return;
1145
+ if (recoveringServices !== undefined)
1146
+ return await recoveringServices;
1147
+ recoveringServices = (async () => {
1148
+ if (this.requiresStatefulAuthorityRuntime()) {
1149
+ const routes = this.createStatefulAuthorityRoutes(store, spotNodeRuntime);
1150
+ await routes.start(this.executionState?.abortController.signal);
1151
+ this.statefulAuthorityRoutes = routes;
1152
+ }
1153
+ })();
1154
+ try {
1155
+ await recoveringServices;
1156
+ }
1157
+ finally {
1158
+ recoveringServices = undefined;
1159
+ }
1160
+ };
1161
+ void transportFence
1162
+ .then(() => spotNodeRuntime.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Preparing, signal))
1163
+ .then(() => recoverServices())
1164
+ .then(() => {
1165
+ const currentOwnerToken = runtime.currentOwnerToken;
1166
+ if (runtime.ownerLeaseUsable === false
1167
+ || currentOwnerToken === undefined
1168
+ || currentOwnerToken.ownerId !== ownerToken.ownerId
1169
+ || currentOwnerToken.leaseGeneration !== ownerToken.leaseGeneration) {
1170
+ throw new Error('Owner lease changed during recovery.');
1171
+ }
1172
+ return spotNodeRuntime.publishMeshNodeState(this.runtimeState, signal);
1173
+ })
1174
+ .then(() => spotNodeRuntime.startLocationAutoConnect(signal))
1175
+ .then(() => channelRuntime.reclaimLocationOwnerRows(signal))
1176
+ .then(() => this.locationOwner.currentLifecycle?.reclaimOwnerRows() ?? Promise.resolve())
1177
+ .then(() => {
1178
+ lastPublishedOwnerToken = ownerToken;
1179
+ recoveryRequired = false;
1180
+ publishing = false;
1181
+ }, error => {
1182
+ this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('owner lease recovery', error);
1183
+ publishing = false;
1184
+ });
1185
+ };
1186
+ this.ownerLeaseRecoveryRuntime = runtime;
1187
+ this.ownerLeaseRecoveryHandler = handler;
1188
+ const failureHandler = () => {
1189
+ recoveryRequired = true;
1190
+ if (runtime.ownerLeaseUsable)
1191
+ return;
1192
+ // A Store failure invalidates new ownership and discovery work, but it
1193
+ // must not tear down transports that were already established. The
1194
+ // auto-connect reconciler applies storeFailureGraceMs to the last
1195
+ // complete descriptor set; fencing here would bypass that contract and
1196
+ // make existing requests fail during the grace window.
1197
+ const routes = this.statefulAuthorityRoutes;
1198
+ if (routes === undefined)
1199
+ return;
1200
+ this.statefulAuthorityRoutes = undefined;
1201
+ stoppingServices = routes.stop();
1202
+ void stoppingServices.catch(error => this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('stateful authority route fencing', error));
1203
+ };
1204
+ this.ownerLeaseFailureHandler = failureHandler;
1205
+ runtime.addOwnerLeaseRenewedHandler(handler);
1206
+ if (typeof runtime.addOwnerLeaseRenewalFailedHandler === 'function') {
1207
+ runtime.addOwnerLeaseRenewalFailedHandler(failureHandler);
1208
+ }
1209
+ }
1210
+ createStatefulAuthorityRoutes(locationStore, spotNodeRuntime) {
1211
+ return new stateful_authority_route_runtime_1.ZLinkStatefulAuthorityRouteRuntime({
1212
+ store: locationStore,
1213
+ creationStore: locationStore,
1214
+ relocationStore: this.options.registration.locations.relocationStoreInstance,
1215
+ meshNodes: spotNodeRuntime.meshNodesByName,
1216
+ pollingIntervalMs: this.options.registration.locations.options.pollingIntervalMs
1217
+ ?? Locations_1.zlinkDefaultLocationOptions.pollingIntervalMs,
1218
+ pageSize: 1000,
1219
+ reportError: (error) => this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('stateful authority route reconciliation', error),
1220
+ onSpotRouteChanged: (spotId) => this.cachedLocationSpotRouteResolver?.invalidate?.(spotId)
1221
+ });
1222
+ }
1223
+ requiresStatefulAuthorityRuntime() {
1224
+ for (const options of this.options.registration.spotNodes.values()) {
1225
+ if (Object.keys(options.spotFactoryRegistrations ?? {}).length > 0
1226
+ || Object.keys(options.instanceSpotFactoryRegistrations ?? {}).length > 0
1227
+ || Object.keys(options.actorFactoryRegistrations ?? {}).length > 0) {
1228
+ return true;
1229
+ }
1230
+ }
1231
+ return false;
1232
+ }
1233
+ installLocationBackedAuthorities(locationStore, spotNodeRuntime) {
1234
+ for (const [meshName, node] of spotNodeRuntime.meshNodesByName) {
1235
+ const activationNode = node;
1236
+ const spotManager = this.spotManager;
1237
+ if (spotManager !== undefined) {
1238
+ this.registerInstanceApplicationLifecycle(meshName, activationNode, spotManager);
1239
+ }
1240
+ activationNode.registerAsyncInstanceActivationAuthority?.(new instance_activation_authority_1.ZLinkInstanceActivationAuthority({
1241
+ store: locationStore,
1242
+ relocationStore: this.options.registration.locations.relocationStoreInstance,
1243
+ meshName,
1244
+ owner: () => this.locationOwner.currentRuntime?.currentOwnerToken,
1245
+ metrics: this.metrics,
1246
+ onReady: (target, route) => {
1247
+ activationNode.registerInstanceIntent(target.stableType, route);
1248
+ this.locationOwner.currentLifecycle?.trackInstanceSpot({
1249
+ meshName,
1250
+ spotId: target.targetSpotId,
1251
+ stableType: target.stableType,
1252
+ nodeRid: route.targetNodeRid,
1253
+ nodeGeneration: route.targetNodeGeneration,
1254
+ objectGeneration: route.objectGeneration,
1255
+ authorityOwnerGeneration: route.authorityOwnerGeneration,
1256
+ ownerId: route.ownerId,
1257
+ ownerLeaseGeneration: route.leaseGeneration,
1258
+ storeVersion: route.storeVersion,
1259
+ deactivate: async () => {
1260
+ await spotManager?.close(meshName, target.targetSpotId);
1261
+ }
1262
+ });
1263
+ }
1264
+ }));
1265
+ }
1266
+ }
1267
+ removeOwnerLeaseRecoveryPublication() {
1268
+ if (this.ownerLeaseRecoveryRuntime !== undefined && this.ownerLeaseRecoveryHandler !== undefined) {
1269
+ this.ownerLeaseRecoveryRuntime.removeOwnerLeaseRenewedHandler(this.ownerLeaseRecoveryHandler);
1270
+ }
1271
+ if (this.ownerLeaseRecoveryRuntime !== undefined && this.ownerLeaseFailureHandler !== undefined) {
1272
+ if (typeof this.ownerLeaseRecoveryRuntime.removeOwnerLeaseRenewalFailedHandler === 'function') {
1273
+ this.ownerLeaseRecoveryRuntime.removeOwnerLeaseRenewalFailedHandler(this.ownerLeaseFailureHandler);
1274
+ }
1275
+ }
1276
+ this.ownerLeaseRecoveryRuntime = undefined;
1277
+ this.ownerLeaseRecoveryHandler = undefined;
1278
+ this.ownerLeaseFailureHandler = undefined;
1279
+ }
1280
+ async onApplicationBootstrap() {
1281
+ await this.start();
1282
+ }
1283
+ async onApplicationShutdown() {
1284
+ await this.shutdown();
1285
+ }
1286
+ async performMeshDrain(meshName, signal, stopStartingSignal) {
1287
+ await this.serviceRelocation.relocateMesh(meshName, this.relocationTargetApplicationVersion, signal, stopStartingSignal);
1288
+ }
1289
+ async performMeshShutdown(meshName, signal) {
1290
+ await this.spotManager?.drainForShutdown(meshName, signal, this.runtimeDeadline);
1291
+ await awaitWithDrainSignal(this.streamRuntime?.notifyServerDrain(meshName), signal);
1292
+ }
1293
+ async publishMeshRetiring(meshName, signal) {
1294
+ await this.spotNodeRuntime?.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Relocating, signal, meshName);
1295
+ }
1296
+ async publishMeshServing(meshName, signal) {
1297
+ await this.spotNodeRuntime?.reconcileAndPublishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Serving, meshName, signal);
1298
+ // A failed relocation rolls the local object barriers back before the
1299
+ // descriptor is published as Serving. Reconcile the durable authority
1300
+ // routes before returning so the next local request cannot observe the
1301
+ // brief window where the Location row is ready but the route cache still
1302
+ // reflects the failed capture.
1303
+ await this.statefulAuthorityRoutes?.reconcile(signal);
1304
+ }
1305
+ async publishMeshDraining(meshName, signal) {
1306
+ const node = this.spotNodeRuntime?.meshNode(meshName);
1307
+ if (node !== undefined) {
1308
+ await node.publishDraining?.();
1309
+ }
1310
+ await this.spotNodeRuntime?.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Draining, signal, meshName);
1311
+ }
1312
+ async preflightAutomaticPeerReadiness(deadlineAt, targetApplicationVersion) {
1313
+ // A host with no local stateful workload has nothing to move. The public
1314
+ // Relocate contract completes that case without requiring a replacement
1315
+ // target; the host drain still publishes its retiring state below.
1316
+ if (!this.hasLocalStatefulRelocationWork())
1317
+ return undefined;
1318
+ if (this.options.registration.spotNodes.size === 0)
1319
+ return undefined;
1320
+ const location = this.locationOwner.currentRuntime;
1321
+ if (location === undefined)
1322
+ return contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable;
1323
+ let storeUnavailable = false;
1324
+ while (performance.now() < deadlineAt) {
1325
+ try {
1326
+ if (await this.hasExactAutomaticPeerReadiness(location, targetApplicationVersion))
1327
+ return undefined;
1328
+ storeUnavailable = false;
1329
+ }
1330
+ catch {
1331
+ storeUnavailable = true;
1332
+ }
1333
+ await new Promise((resolve) => setTimeout(resolve, Math.min(this.options.registration.locations.options.pollingIntervalMs
1334
+ ?? Locations_1.zlinkDefaultLocationOptions.pollingIntervalMs, Math.max(1, deadlineAt - performance.now()))));
1335
+ }
1336
+ return storeUnavailable
1337
+ ? contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable
1338
+ : contracts_1.ZLinkFrameworkRelocationReason.TargetUnavailable;
1339
+ }
1340
+ hasLocalStatefulRelocationWork() {
1341
+ const spotManager = this.spotManager;
1342
+ if (spotManager !== undefined) {
1343
+ for (const meshName of this.options.registration.spotNodes.keys()) {
1344
+ if (spotManager.relocationActivations(meshName).length > 0)
1345
+ return true;
1346
+ }
1347
+ }
1348
+ return this.actorManager?.snapshotStates().some((state) => state.hasActorOrCreation) ?? false;
1349
+ }
1350
+ async hasExactAutomaticPeerReadiness(location, targetApplicationVersion) {
1351
+ for (const [meshName, registration] of this.options.registration.spotNodes) {
1352
+ if ((registration.router?.manualConnections?.length ?? 0) > 0
1353
+ || (registration.router?.manualPeerConnections?.length ?? 0) > 0) {
1354
+ continue;
1355
+ }
1356
+ const node = this.spotNodeRuntime?.meshNode(meshName);
1357
+ if (node === undefined)
1358
+ return false;
1359
+ const local = node.status();
1360
+ const localDescriptor = this.spotNodeRuntime?.meshNodeDescriptor(meshName);
1361
+ if (localDescriptor === undefined)
1362
+ return false;
1363
+ const descriptors = await location.listLiveMeshNodes(meshName);
1364
+ const peers = node.peers();
1365
+ if (!hasExactPeerReadiness(descriptors, {
1366
+ ...local,
1367
+ applicationVersion: targetApplicationVersion,
1368
+ maintenanceWave: localDescriptor.maintenanceWave
1369
+ }, peers))
1370
+ return false;
1371
+ }
1372
+ return true;
1373
+ }
1374
+ async publishHostRelocated() {
1375
+ await Promise.all([...this.options.registration.spotNodes.keys()].map(meshName => this.spotNodeRuntime?.publishMeshNodeState(contracts_1.ZLinkFrameworkRuntimeState.Relocated, undefined, meshName)));
1376
+ }
1377
+ async publishHostDraining(signal) {
1378
+ try {
1379
+ const runtime = this.locationOwner.currentRuntime;
1380
+ if (runtime !== undefined && !await runtime.publishDraining(signal)) {
1381
+ throw new Error('Draining descriptor publication returned false.');
1382
+ }
1383
+ }
1384
+ catch (error) {
1385
+ throw new ZLinkDrainingStatePublishError(error);
1386
+ }
1387
+ }
1388
+ async cleanupOwnerForDrain(signal) {
1389
+ const runtime = this.locationOwner.currentRuntime;
1390
+ if (runtime === undefined)
1391
+ return;
1392
+ try {
1393
+ await runtime.cleanupOwner(signal);
1394
+ }
1395
+ catch (error) {
1396
+ throw new locations_1.ZLinkOwnerCleanupError(error);
1397
+ }
1398
+ }
1399
+ async forceStopMesh(meshName) {
1400
+ await waitForForcedSessionNotification(this.streamRuntime?.notifyServerDrain(meshName));
1401
+ await this.spotManager?.drainForShutdown(meshName, undefined, this.runtimeDeadline);
1402
+ }
1403
+ registerInstanceApplicationLifecycle(meshName, node, spotManager) {
1404
+ const activationNode = node;
1405
+ activationNode.registerInstanceApplicationLifecycle?.({
1406
+ isMaterialized: (target) => spotManager.isInstanceMaterialized(meshName, target.stableType, target.targetSpotId),
1407
+ isMaterializing: (target) => spotManager.isInstanceMaterializing(meshName, target.targetSpotId),
1408
+ isClosing: (target) => spotManager.isInstanceClosing(meshName, target.targetSpotId),
1409
+ isIdleEvicting: (target) => spotManager.isInstanceSpotIdleEvicting(meshName, target.targetSpotId),
1410
+ beginIdleEviction: (target) => spotManager.beginInstanceSpotIdleEviction(meshName, target.targetSpotId),
1411
+ materialize: (target, objectGeneration) => spotManager.materializeInstance(meshName, target.stableType, target.targetSpotId, objectGeneration, this.executionState?.abortController.signal),
1412
+ discard: (target) => spotManager.discardInstance(meshName, target.targetSpotId),
1413
+ beginTerminal: (target) => spotManager.beginInstanceTerminal(meshName, target.targetSpotId, target.objectGeneration),
1414
+ completeTerminal: (target) => spotManager.completeInstanceTerminal(meshName, target.targetSpotId, target.objectGeneration)
1415
+ });
1416
+ }
1417
+ setActorManager(actorManager) {
1418
+ this.actorManager = actorManager;
1419
+ }
1420
+ setSpotManager(spotManager) {
1421
+ this.spotManager = spotManager;
1422
+ for (const [meshName, node] of this.spotNodeRuntime?.meshNodesByName ?? []) {
1423
+ this.registerInstanceApplicationLifecycle(meshName, node, spotManager);
1424
+ }
1425
+ }
1426
+ createActorManagerOptions() {
1427
+ this.ensureLocationRuntime();
1428
+ return {
1429
+ ...this.actorRuntimeOptionsFactory().createActorManagerOptions(),
1430
+ placementCreate: async (actorId, actorType, createOnly, call, signal) => {
1431
+ const placement = this.actorPlacement;
1432
+ if (placement === undefined) {
1433
+ throw new ConfigurationException_1.ZLinkConfigurationException('Actor placement runtime is not initialized.');
1434
+ }
1435
+ const requestPayload = (0, creation_payload_codec_1.encodeFrameworkCreationPayload)(call.request, this.options.registration.messageSerializers);
1436
+ return await placement.create(actorId, actorType, createOnly, call.meshName, requestPayload, call.timeoutMs, signal);
1437
+ }
1438
+ };
1439
+ }
1440
+ createActorClientOptions() {
1441
+ this.ensureLocationRuntime();
1442
+ const options = this.actorRuntimeOptionsFactory().createActorClientOptions();
1443
+ this.actorClientLocationResolver = options.locationResolver();
1444
+ return options;
1445
+ }
1446
+ createLocationHandleResolver() {
1447
+ this.ensureLocationRuntime();
1448
+ return this.locationOwner.createRefResolver(this.meshRouters.spotLocationMeshNames());
1449
+ }
1450
+ createSpotManagerOptions() {
1451
+ this.ensureLocationRuntime();
1452
+ return {
1453
+ ...new spot_runtime_options_factory_1.ZLinkSpotRuntimeOptionsFactory({
1454
+ registration: this.options.registration,
1455
+ channelTransport: this.channelTransport,
1456
+ routeTransport: this.routeTransport,
1457
+ addressTransport: this.spotAddressTransport,
1458
+ spotPublisherTransport: this.spotPublisherTransport,
1459
+ meshRouters: this.meshRouters,
1460
+ runtimeEventPublisher: this.runtimeEventPublisher,
1461
+ spotNodeRuntime: () => this.spotNodeRuntime,
1462
+ actorManager: () => this.actorManager,
1463
+ // User Spot visibility is published only by the generic authority
1464
+ // coordinator after application initialization. The legacy location
1465
+ // claim would expose a Creating object before that Ready barrier.
1466
+ locationLifecycle: () => undefined,
1467
+ releaseInstanceAuthority: (meshName, spotId, objectGeneration) => this.locationOwner.currentLifecycle?.releaseSpot(meshName, spotId, objectGeneration)
1468
+ ?? Promise.resolve(),
1469
+ beginInstanceIdleClosingAuthority: (meshName, spotId) => this.locationOwner.currentLifecycle?.beginInstanceSpotClosing(meshName, spotId)
1470
+ ?? Promise.resolve(undefined),
1471
+ beginInstanceClosingAuthority: (meshName, spotId) => this.locationOwner.currentLifecycle?.beginInstanceSpotClosing(meshName, spotId)
1472
+ ?? Promise.resolve(undefined),
1473
+ createLocationSpotRouteResolver: () => this.createLocationSpotRouteResolver(),
1474
+ boundSessionRelay: this.boundSessionRelay,
1475
+ actorHandoff: this.actorHandoff,
1476
+ dispatchErrorReporter: (errorSink) => this.createDispatchErrorReporter(errorSink),
1477
+ runtimeOrPreStartErrorSink: this.runtimeOrPreStartErrorSink,
1478
+ detachedTaskRunner: this.detachedTaskRunner(),
1479
+ metrics: this.metrics,
1480
+ admission: this.admission,
1481
+ statefulExecutionAllowed: () => {
1482
+ const locationRuntime = this.locationOwner.currentRuntime;
1483
+ if (locationRuntime !== undefined)
1484
+ return locationRuntime.ownerLeaseUsable;
1485
+ // A host configured with a Location Store must not execute stateful
1486
+ // timers while its lease runtime is unavailable. Hosts without a
1487
+ // Location Store have no owner lease to fence.
1488
+ return this.locationOwner.currentStores?.locationStore === undefined;
1489
+ }
1490
+ }).create(this.actorTransferRuntime),
1491
+ activationConcurrencyLimitProvider: (meshName) => this.options.registration.spotNodes.get(meshName)?.activationConcurrencyLimit ?? 128,
1492
+ onInstanceActivationConcurrencyChanged: (meshName) => {
1493
+ void this.spotNodeRuntime?.publishMeshNodeState(this.runtimeState, this.executionState?.abortController.signal, meshName).catch(() => undefined);
1494
+ }
1495
+ };
1496
+ }
1497
+ createPublicSpotManager(local) {
1498
+ const locationStore = this.locationOwner.locationStore();
1499
+ if (locationStore === undefined) {
1500
+ throw new ConfigurationException_1.ZLinkConfigurationException('User Spot creation requires a Location Store.');
1501
+ }
1502
+ this.actorPlacement ??= new actor_placement_coordinator_1.ZLinkActorPlacementCoordinator({
1503
+ store: locationStore,
1504
+ remoteCreate: (meshName, targetNodeRid, request, timeoutMs) => {
1505
+ const node = this.spotNodeRuntime?.meshNode(meshName);
1506
+ if (node === undefined) {
1507
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, `RouteMesh '${meshName}' has no local client node.`);
1508
+ }
1509
+ return node.requestActorCreate(targetNodeRid, request, timeoutMs);
1510
+ },
1511
+ decodeRemoteReply: payload => {
1512
+ const message = runtime_message_1.ZLinkBufferMessage.from(payload);
1513
+ try {
1514
+ return (0, payload_codec_1.decodeFrameworkPayloadMessage)(message, this.options.registration.messageSerializers);
1515
+ }
1516
+ finally {
1517
+ message.close();
1518
+ }
1519
+ },
1520
+ target: async (requestedMesh, stableType, signal, excludedNodeRids) => {
1521
+ const clientMeshes = [...this.options.registration.spotNodes]
1522
+ .filter(([, node]) => (0, spot_address_transport_1.hasObjectClientCapability)(node.objectRole))
1523
+ .map(([meshName]) => meshName);
1524
+ const meshes = requestedMesh === undefined ? clientMeshes : [requestedMesh];
1525
+ if (meshes.length === 0) {
1526
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, 'No object-client RouteMesh is configured.');
1527
+ }
1528
+ if (requestedMesh === undefined && meshes.length > 1) {
1529
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.MeshSelectionRequired, 'Multiple object-client RouteMeshes are configured; call inMesh(...).');
1530
+ }
1531
+ const meshName = meshes[0];
1532
+ if (!clientMeshes.includes(meshName)) {
1533
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, `RouteMesh '${meshName}' has no object-client role.`);
1534
+ }
1535
+ const meshNode = this.spotNodeRuntime?.meshNode(meshName);
1536
+ const descriptors = (await locationStore.listMeshNodes(meshName, undefined, signal)).items;
1537
+ const selected = await selectReadyLocationPlacementDescriptor(descriptors, meshNode, signal, descriptor => {
1538
+ const capability = descriptor.objectCapabilities.find(candidate => candidate.objectKind === 'actor'
1539
+ && candidate.stableType === stableType);
1540
+ const actors = descriptor.populationCapacity.actors;
1541
+ return descriptor.state === contracts_1.ZLinkFrameworkRuntimeState.Serving
1542
+ && descriptor.objectRole === 'server'
1543
+ && descriptor.placementWeight > 0
1544
+ && descriptor.entrySpotId !== undefined
1545
+ && excludedNodeRids?.has(String(descriptor.rid)) !== true
1546
+ && (actors.limit === 0 || actors.active + actors.reserved < actors.limit)
1547
+ && capability !== undefined;
1548
+ });
1549
+ if (selected === undefined)
1550
+ return undefined;
1551
+ const localStatus = meshNode?.status();
1552
+ return {
1553
+ meshName,
1554
+ nodeRid: selected.rid,
1555
+ nodeGeneration: selected.lifecycleGeneration,
1556
+ entrySpotId: selected.entrySpotId,
1557
+ owner: {
1558
+ ownerId: selected.ownerId,
1559
+ leaseGeneration: selected.leaseGeneration
1560
+ },
1561
+ isLocal: localStatus !== undefined
1562
+ && String(localStatus.routingId) === String(selected.rid)
1563
+ && localStatus.lifecycleGeneration === selected.lifecycleGeneration
1564
+ };
1565
+ }
1566
+ });
1567
+ const coordinator = new user_spot_creation_coordinator_1.ZLinkUserSpotCreationCoordinator({
1568
+ store: locationStore,
1569
+ publishReadyRoute: (meshName, route) => {
1570
+ this.cachedLocationSpotRouteResolver?.invalidate?.(route.spot.spotId);
1571
+ this.spotNodeRuntime?.meshNode(meshName)?.rememberSpotRoute?.(route);
1572
+ },
1573
+ forgetReadyRoute: (meshName, route) => {
1574
+ this.cachedLocationSpotRouteResolver?.invalidate?.(route.spot.spotId);
1575
+ this.spotNodeRuntime?.meshNode(meshName)?.forgetSpotRoute?.(route.spot, route.authorityOwnerGeneration, route.storeVersion);
1576
+ },
1577
+ remoteCreate: (meshName, targetNodeRid, request, timeoutMs) => {
1578
+ const node = this.spotNodeRuntime?.meshNode(meshName);
1579
+ if (node === undefined) {
1580
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, `RouteMesh '${meshName}' has no local client node.`);
1581
+ }
1582
+ return node.requestUserSpotCreate(targetNodeRid, request, timeoutMs);
1583
+ },
1584
+ decodeRemoteReply: payload => {
1585
+ const message = runtime_message_1.ZLinkBufferMessage.from(payload);
1586
+ try {
1587
+ return (0, payload_codec_1.decodeFrameworkPayloadMessage)(message, this.options.registration.messageSerializers);
1588
+ }
1589
+ finally {
1590
+ message.close();
1591
+ }
1592
+ },
1593
+ target: async (request, signal, excludedNodeRids) => {
1594
+ const clientMeshes = [...this.options.registration.spotNodes]
1595
+ .filter(([, node]) => (0, spot_address_transport_1.hasObjectClientCapability)(node.objectRole))
1596
+ .map(([meshName]) => meshName);
1597
+ const meshes = request.meshName === undefined ? clientMeshes : [request.meshName];
1598
+ if (meshes.length === 0) {
1599
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, 'No object-client RouteMesh is configured.');
1600
+ }
1601
+ if (request.meshName === undefined && meshes.length > 1) {
1602
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.MeshSelectionRequired, 'Multiple object-client RouteMeshes are configured; call inMesh(...).');
1603
+ }
1604
+ const meshName = meshes[0];
1605
+ if (!this.options.registration.spotNodes.has(meshName)) {
1606
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.MeshNotFound, `RouteMesh '${meshName}' is not configured.`);
1607
+ }
1608
+ if (!clientMeshes.includes(meshName)) {
1609
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, `RouteMesh '${meshName}' has no object-client role.`);
1610
+ }
1611
+ const meshNode = this.spotNodeRuntime?.meshNode(meshName);
1612
+ const descriptors = (await locationStore.listMeshNodes(meshName, undefined, signal)).items;
1613
+ const selected = await selectReadyLocationPlacementDescriptor(descriptors, meshNode, signal, descriptor => {
1614
+ const capability = descriptor.objectCapabilities.find(candidate => candidate.objectKind === 'user_spot'
1615
+ && candidate.stableType === request.stableType);
1616
+ const spotTypeCapacity = descriptor.populationCapacity.spotTypes.find(candidate => candidate.objectKind === 'user_spot'
1617
+ && candidate.stableType === request.stableType);
1618
+ const spots = descriptor.populationCapacity.spots;
1619
+ return descriptor.state === 1
1620
+ && descriptor.objectRole === 'server'
1621
+ && descriptor.placementWeight > 0
1622
+ && excludedNodeRids?.has(String(descriptor.rid)) !== true
1623
+ && (spots.limit === 0 || spots.active + spots.reserved < spots.limit)
1624
+ && capability !== undefined
1625
+ && (spotTypeCapacity === undefined
1626
+ || spotTypeCapacity.limit === 0
1627
+ || spotTypeCapacity.active + spotTypeCapacity.reserved
1628
+ < spotTypeCapacity.limit);
1629
+ });
1630
+ if (selected === undefined)
1631
+ return undefined;
1632
+ const localStatus = meshNode?.status();
1633
+ return {
1634
+ meshName,
1635
+ nodeRid: selected.rid,
1636
+ nodeGeneration: selected.lifecycleGeneration,
1637
+ owner: {
1638
+ ownerId: selected.ownerId,
1639
+ leaseGeneration: selected.leaseGeneration
1640
+ },
1641
+ isLocal: localStatus !== undefined
1642
+ && String(localStatus.routingId) === String(selected.rid)
1643
+ && localStatus.lifecycleGeneration === selected.lifecycleGeneration
1644
+ };
1645
+ }
1646
+ });
1647
+ const factories = new Map([...this.options.registration.spotNodes].map(([meshName, node]) => [
1648
+ meshName,
1649
+ new Map(Object.entries(node.spotFactoryRegistrations ?? {}))
1650
+ ]));
1651
+ const registerUserSpotHandlers = (runtime) => {
1652
+ for (const [meshName] of this.options.registration.spotNodes) {
1653
+ const node = runtime.meshNode(meshName);
1654
+ if (node === undefined)
1655
+ continue;
1656
+ node.registerUserSpotOperationHandler({
1657
+ create: async (record, signal) => {
1658
+ const coordinated = await coordinator.handleRemoteCreate(record, async (requestPayload, authority, createSignal) => {
1659
+ const selected = factories.get(meshName)?.get(record.stableType);
1660
+ if (selected === undefined) {
1661
+ throw new ConfigurationException_1.ZLinkConfigurationException(`User Spot factory '${record.stableType}' is not registered on RouteMesh '${meshName}'.`);
1662
+ }
1663
+ const request = (0, creation_payload_codec_1.decodeFrameworkCreationPayload)(requestPayload, this.options.registration.messageSerializers);
1664
+ local.beginUserSpotPublication(meshName, record.spotId);
1665
+ try {
1666
+ const result = await local.getOrCreateWithAuthority(meshName, selected.implementation, record.spotId, request, {
1667
+ stableType: record.stableType,
1668
+ objectGeneration: authority.objectGeneration,
1669
+ authorityOwnerGeneration: authority.authorityOwnerGeneration
1670
+ }, createSignal);
1671
+ return {
1672
+ ...result,
1673
+ publication: {
1674
+ publish: () => local.publishUserSpot(meshName, record.spotId),
1675
+ abort: () => local.abortUserSpotPublication(meshName, record.spotId)
1676
+ }
1677
+ };
1678
+ }
1679
+ catch (error) {
1680
+ local.abortUserSpotPublication(meshName, record.spotId);
1681
+ throw error;
1682
+ }
1683
+ }, async (cleanupSignal) => {
1684
+ await local.close(meshName, record.spotId, cleanupSignal);
1685
+ }, signal);
1686
+ const reply = coordinated.result.reply;
1687
+ let payload;
1688
+ if (reply !== undefined
1689
+ && coordinated.result.state !== contracts_1.ZLinkSpotCreateState.Existing) {
1690
+ const message = (0, payload_codec_1.encodeFrameworkPayloadMessage)(reply, this.options.registration.messageSerializers);
1691
+ try {
1692
+ payload = {
1693
+ packetName: 'ZLinkFrameworkUserSpotReply',
1694
+ contentType: 'application/octet-stream',
1695
+ payload: Buffer.from(message.data())
1696
+ };
1697
+ }
1698
+ finally {
1699
+ message.close();
1700
+ }
1701
+ }
1702
+ return {
1703
+ terminalResult: runtime_values_1.RequestResult.Ok,
1704
+ failureCode: 0,
1705
+ tail: {
1706
+ kind: 'userSpotCreate',
1707
+ createResult: coordinated.result.state === contracts_1.ZLinkSpotCreateState.Existing
1708
+ ? 'existing'
1709
+ : coordinated.result.state === contracts_1.ZLinkSpotCreateState.Created
1710
+ ? 'created'
1711
+ : 'rejected',
1712
+ spotId: String(coordinated.spot.spotId),
1713
+ objectGeneration: coordinated.spot.objectGeneration
1714
+ },
1715
+ ...(payload === undefined ? {} : { payload })
1716
+ };
1717
+ },
1718
+ createActor: async (record, signal) => {
1719
+ const actorPlacement = this.actorPlacement;
1720
+ const actors = this.actorManager;
1721
+ if (actorPlacement === undefined || actors === undefined) {
1722
+ throw new ConfigurationException_1.ZLinkConfigurationException('Actor placement target runtime is not initialized.');
1723
+ }
1724
+ return await actorPlacement.handleRemoteCreate(record, async (requestPayload, authority, createSignal) => {
1725
+ const request = (0, creation_payload_codec_1.decodeFrameworkCreationPayload)(requestPayload, this.options.registration.messageSerializers);
1726
+ const entrySpot = node.entrySpot().status();
1727
+ const nativeActorRef = node.restoreActorAuthority?.(record.actorId, record.stableType, authority.objectGeneration, authority.authorityOwnerGeneration, String(entrySpot.routingId), entrySpot.lifecycleGeneration, 1n);
1728
+ if (nativeActorRef === undefined) {
1729
+ throw new ConfigurationException_1.ZLinkConfigurationException('Remote Actor creation requires native authority restoration support.');
1730
+ }
1731
+ const local = await actors.createReservedActorResult(record.actorId, record.stableType, request, createSignal, nativeActorRef);
1732
+ if (local.status === 'rejected') {
1733
+ let reply;
1734
+ if (local.reply !== undefined) {
1735
+ const encoded = (0, payload_codec_1.encodeFrameworkPayloadMessage)(local.reply, this.options.registration.messageSerializers);
1736
+ try {
1737
+ reply = Buffer.from(encoded.data());
1738
+ }
1739
+ finally {
1740
+ encoded.close();
1741
+ }
1742
+ }
1743
+ return {
1744
+ result: 'rejected',
1745
+ ...(reply === undefined ? {} : { reply })
1746
+ };
1747
+ }
1748
+ if (local.actorRef.objectGeneration !== authority.objectGeneration
1749
+ || String(local.actorRef.nodeRid) !== record.reservation.targetNodeRid) {
1750
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorCreateFailed, `Actor '${record.actorId}' native authority does not match its placement reservation.`);
1751
+ }
1752
+ let reply;
1753
+ if (local.reply !== undefined) {
1754
+ const encoded = (0, payload_codec_1.encodeFrameworkPayloadMessage)(local.reply, this.options.registration.messageSerializers);
1755
+ try {
1756
+ reply = Buffer.from(encoded.data());
1757
+ }
1758
+ finally {
1759
+ encoded.close();
1760
+ }
1761
+ }
1762
+ return {
1763
+ result: 'created',
1764
+ actor: {
1765
+ ...local.actorRef,
1766
+ meshName
1767
+ },
1768
+ entrySpotId: String(entrySpot.routingId),
1769
+ entrySpotGeneration: entrySpot.lifecycleGeneration,
1770
+ ...(reply === undefined ? {} : { reply }),
1771
+ onPublished: () => actors.adoptCreatedAuthority(record.actorId, authority.authorityOwnerGeneration, authority.ownerLeaseGeneration)
1772
+ };
1773
+ }, signal);
1774
+ },
1775
+ close: async (record, signal) => {
1776
+ if (!local.hasActiveSpot(record.target.spotId)) {
1777
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `User Spot '${record.target.spotId}' is not materialized on its authority owner.`, true);
1778
+ }
1779
+ if (!local.canCloseUserSpot(meshName, record.target.spotId)) {
1780
+ return {
1781
+ terminalResult: runtime_values_1.RequestResult.Ok,
1782
+ failureCode: 0,
1783
+ tail: {
1784
+ kind: 'userSpotClose',
1785
+ closed: false
1786
+ }
1787
+ };
1788
+ }
1789
+ return {
1790
+ terminalResult: runtime_values_1.RequestResult.Ok,
1791
+ failureCode: 0,
1792
+ tail: {
1793
+ kind: 'userSpotClose',
1794
+ closed: await coordinator.handleRemoteClose(record, (spot, closeSignal) => local.close(spot.meshName, spot.spotId, closeSignal), signal)
1795
+ }
1796
+ };
1797
+ }
1798
+ });
1799
+ }
1800
+ };
1801
+ this.registerUserSpotHandlers = registerUserSpotHandlers;
1802
+ if (this.spotNodeRuntime !== undefined) {
1803
+ registerUserSpotHandlers(this.spotNodeRuntime);
1804
+ }
1805
+ return new spots_1.ZLinkPublicSpotManager({
1806
+ local,
1807
+ coordinator,
1808
+ factories,
1809
+ resolver: () => this.createLocationSpotRouteResolver(),
1810
+ forgetReadyRoute: (spot, snapshot) => {
1811
+ coordinator.forgetReadyRoute(spot.spotId, snapshot);
1812
+ },
1813
+ isLocalNode: (meshName, nodeRid) => {
1814
+ const status = this.spotNodeRuntime?.meshNode(meshName)?.status();
1815
+ return status !== undefined && String(status.routingId) === String(nodeRid);
1816
+ },
1817
+ remoteClose: (meshName, targetNodeRid, request, timeoutMs) => {
1818
+ const node = this.spotNodeRuntime?.meshNode(meshName);
1819
+ if (node === undefined) {
1820
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ObjectClientNotConfigured, `RouteMesh '${meshName}' has no local client node.`);
1821
+ }
1822
+ return node.requestUserSpotClose(targetNodeRid, request, timeoutMs);
1823
+ },
1824
+ defaultTimeoutMs: this.options.registration.requestTimeoutMs ?? 30_000,
1825
+ messageSerializers: this.options.registration.messageSerializers
1826
+ });
1827
+ }
1828
+ actorRuntimeOptionsFactory() {
1829
+ return new actor_runtime_options_factory_1.ZLinkActorRuntimeOptionsFactory({
1830
+ registration: this.options.registration,
1831
+ messageFlow: () => this.createDispatchErrorReporter(this.runtimeOrPreStartErrorSink).flow,
1832
+ routeTransport: this.routeTransport,
1833
+ streamBindingRuntime: this.streamBindingRuntime,
1834
+ providerResolver: this.options.providerResolver,
1835
+ spotManager: () => this.spotManager,
1836
+ actorManager: () => this.actorManager,
1837
+ primaryMeshNode: () => this.requirePrimaryMeshNode(),
1838
+ primaryMeshNodeOrUndefined: () => this.spotNodeRuntime?.primaryMeshNode,
1839
+ primaryMeshCompletions: () => this.spotNodeRuntime?.primaryMeshCompletions,
1840
+ meshNode: (meshName) => this.spotNodeRuntime?.meshNode(meshName),
1841
+ meshCompletions: (meshName) => this.spotNodeRuntime?.meshCompletionTable(meshName),
1842
+ notifyEntrySpotActorCreated: (nodeRid, actor, createRequest, signal) => this.spotNodeRuntime?.notifyEntrySpotActorCreated(nodeRid, actor, createRequest, signal)
1843
+ ?? Promise.resolve(undefined),
1844
+ locationLifecycle: () => this.locationOwner.currentLifecycle,
1845
+ primaryMeshName: () => this.meshRouters.primaryMeshName(),
1846
+ actorMeshName: (actorType) => this.meshRouters.actorMeshName(actorType),
1847
+ createLocationSpotRouteResolver: () => this.createLocationSpotRouteResolver(),
1848
+ createActorLocationResolver: () => this.createActorLocationResolver(),
1849
+ forgetDestroyedActorRef: (actorId) => this.destroyedActorRefs.delete(actorId),
1850
+ rememberDestroyedActorRef: (actorId, actorRef) => this.destroyedActorRefs.set(actorId, actorRef),
1851
+ invalidateActorRoute: (actorId) => this.actorClientLocationResolver?.invalidateActorRoute(actorId),
1852
+ publishActorAuthority: async (actorType, actorRef, ownerNodeGeneration, signal) => {
1853
+ const store = this.locationOwner.currentStores?.locationStore;
1854
+ if (store === undefined)
1855
+ return;
1856
+ const owner = this.locationOwner.currentRuntime?.currentOwnerToken;
1857
+ const meshName = this.meshRouters.actorMeshName(actorType);
1858
+ if (owner === undefined || meshName === undefined) {
1859
+ throw new ConfigurationException_1.ZLinkConfigurationException(`Actor '${actorRef.actorId}' authority requires an active owner and Actor RouteMesh.`);
1860
+ }
1861
+ const entrySpotId = this.spotNodeRuntime?.entrySpotIdForMesh(meshName);
1862
+ if (entrySpotId === undefined) {
1863
+ throw new ConfigurationException_1.ZLinkConfigurationException(`Actor '${actorRef.actorId}' authority requires its RouteMesh Entry Spot.`);
1864
+ }
1865
+ await (0, actors_2.publishInitialActorAuthority)(store, {
1866
+ actorType,
1867
+ actor: actorRef,
1868
+ meshName,
1869
+ ownerNodeGeneration,
1870
+ owner,
1871
+ spotId: entrySpotId,
1872
+ spotGeneration: ownerNodeGeneration,
1873
+ spotKind: contracts_1.ZLinkSpotKind.Entry
1874
+ }, signal);
1875
+ this.actorClientLocationResolver?.invalidateActorRoute(actorRef.actorId);
1876
+ },
1877
+ reportPostCommitError: (error) => this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('post-commit actor binding', error),
1878
+ reportBoundSessionSendError: (error) => this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('bound session one-way submit', error),
1879
+ actorHandoff: this.actorHandoff,
1880
+ actorTransferRuntime: this.actorTransferRuntime,
1881
+ actorJoinRelocation: this.serviceRelocation,
1882
+ actorTransferRegistry: this.actorTransferRegistry,
1883
+ shutdownSignal: () => this.executionState?.abortController.signal,
1884
+ metrics: this.metrics,
1885
+ admission: this.admission,
1886
+ actorPacketTargetForState: (actorId) => this.boundSessionRelay.actorPackets.actorPacketTargetForState(actorId),
1887
+ flowCreationEnabled: () => this.flowCreationEnabled(),
1888
+ traceBoundSessionSend: (actorId, packetName) => {
1889
+ const flow = this.createDispatchErrorReporter(this.runtimeOrPreStartErrorSink).flow;
1890
+ (0, diagnostics_1.flowIfEnabled)(flow, ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Sent)?.trace({
1891
+ outcome: ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Sent,
1892
+ surface: ZLinkDispatchOptions_1.ZLinkDispatchErrorSurface.SpotActor,
1893
+ messageKind: ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.ActorSend,
1894
+ packetName,
1895
+ actorId
1896
+ });
1897
+ }
1898
+ });
1899
+ }
1900
+ createChannelRuntimeOptions() {
1901
+ return new channel_runtime_options_factory_1.ZLinkChannelRuntimeOptionsFactory({
1902
+ monitoringAdapter: this.backendAdapterFactory.createMonitoringAdapter(),
1903
+ messageFlowModeCell: this.messageFlowModeCell,
1904
+ boundSessionRelay: this.boundSessionRelay,
1905
+ applicationJobQueue: this.applicationJobQueue,
1906
+ spotManager: () => this.spotManager,
1907
+ oneWayFailureSink: (error) => this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('channel one-way submit', error)
1908
+ }).create();
1909
+ }
1910
+ createSpotNodeRuntimeOptions(context, dispatchErrors) {
1911
+ const options = new spot_node_runtime_options_factory_1.ZLinkSpotNodeRuntimeOptionsFactory({
1912
+ registration: this.options.registration,
1913
+ backendAdapterFactory: this.backendAdapterFactory,
1914
+ context,
1915
+ channelTransport: this.channelTransport,
1916
+ routeTransport: this.routeTransport,
1917
+ spotPublisherTransport: this.spotPublisherTransport,
1918
+ meshRouters: this.meshRouters,
1919
+ providerResolver: this.options.providerResolver,
1920
+ dispatchErrors,
1921
+ runtimeEventPublisher: this.runtimeEventPublisher,
1922
+ entryActorRuntime: this.entryActorRuntime,
1923
+ actorTransferRuntime: this.actorTransferRuntime,
1924
+ boundSessionRelay: this.boundSessionRelay,
1925
+ actorHandoff: this.actorHandoff,
1926
+ detachedTaskRunner: this.detachedTaskRunner(),
1927
+ metrics: this.metrics,
1928
+ applicationJobQueue: this.applicationJobQueue,
1929
+ applicationJobReceiveFlowFailureSink: (error) => this.runtimeOrPreStartErrorSink.reportRuntimeTaskException('RouteMesh receive-flow configuration', error)
1930
+ }).create();
1931
+ return {
1932
+ ...options,
1933
+ peerAdmissionSealed: (meshName) => !this.admission.accepts(meshName),
1934
+ messageFollowReceiver: (record) => {
1935
+ if (record.source.kind === 'actor') {
1936
+ this.actorClientLocationResolver?.invalidateActorRouteIfMatches({
1937
+ actorId: record.source.actor.actorId,
1938
+ objectGeneration: record.source.actor.generation,
1939
+ targetNodeRid: record.source.targetNodeRid,
1940
+ targetNodeGeneration: record.source.targetNodeGeneration,
1941
+ authorityOwnerGeneration: record.source.authorityOwnerGeneration,
1942
+ ownerLeaseGeneration: record.source.ownerLeaseGeneration
1943
+ });
1944
+ return;
1945
+ }
1946
+ this.actorClientLocationResolver?.invalidateSpotRouteIfMatches({
1947
+ spotId: record.source.spot.spotId,
1948
+ objectGeneration: record.source.spot.generation,
1949
+ targetNodeRid: record.source.targetNodeRid,
1950
+ targetNodeGeneration: record.source.targetNodeGeneration,
1951
+ authorityOwnerGeneration: record.source.authorityOwnerGeneration,
1952
+ ownerLeaseGeneration: record.source.ownerLeaseGeneration
1953
+ });
1954
+ },
1955
+ meshRecordDispatcher: (meshName, owner, record) => this.dispatchMeshRecord(meshName, owner, record, this.executionState?.abortController.signal),
1956
+ instanceActivationConcurrencyProvider: (meshName) => {
1957
+ return this.spotManager?.instanceActivationConcurrency(meshName)
1958
+ ?? { active: 0, limit: this.options.registration.spotNodes.get(meshName)?.activationConcurrencyLimit ?? 128 };
1959
+ }
1960
+ };
1961
+ }
1962
+ async dispatchMeshRecord(meshName, owner, record, signal) {
1963
+ if (record.operationKind === service_runtime_contracts_1.OperationKind.ActorJoin) {
1964
+ if (this.spotManager === undefined) {
1965
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Actor join dispatch requires the Spot manager.');
1966
+ }
1967
+ return this.spotManager.dispatchMeshActorJoin(meshName, owner, record);
1968
+ }
1969
+ if (record.kind === service_runtime_contracts_1.ReceiveKind.ActorBinding) {
1970
+ if (record.kindData?.kind !== 'actorBinding') {
1971
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Actor binding record has no binding generation.');
1972
+ }
1973
+ const binding = record.kindData;
1974
+ const replyBindingFailure = (kind, message) => {
1975
+ const terminal = kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorGenerationStale
1976
+ ? { terminalResult: runtime_values_1.RequestResult.InvalidState, failureCode: 0 }
1977
+ : (0, framework_errors_internal_1.internalFrameworkWireReply)((0, framework_errors_internal_1.createInternalFrameworkException)(kind, message));
1978
+ if (record.replyFailure?.(terminal.terminalResult, terminal.failureCode)
1979
+ !== runtime_values_1.SubmitResult.Ok) {
1980
+ throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode Actor binding target '${binding.actor.actorId}' failure acknowledgement failed.`);
1981
+ }
1982
+ };
1983
+ const replyBindingSuccess = () => {
1984
+ if (record.reply(Buffer.alloc(0)) !== runtime_values_1.SubmitResult.Ok) {
1985
+ throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode Actor binding target '${binding.actor.actorId}' acknowledgement failed.`);
1986
+ }
1987
+ };
1988
+ const state = this.actorManager?.getState(binding.actor.actorId);
1989
+ const nativeActorRef = state?.nativeActorRef;
1990
+ if (state === undefined
1991
+ || nativeActorRef === undefined
1992
+ || nativeActorRef.actorId !== binding.actor.actorId
1993
+ || !(0, routing_id_1.routingIdsEqual)(nativeActorRef.nodeRid, binding.actor.nodeRid)) {
1994
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale, `Actor '${binding.actor.actorId}' binding target is no longer current.`);
1995
+ return;
1996
+ }
1997
+ if (nativeActorRef.generation !== binding.actor.generation) {
1998
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorGenerationStale, `Actor '${binding.actor.actorId}' binding object generation is stale.`);
1999
+ return;
2000
+ }
2001
+ const node = state.meshName === meshName
2002
+ ? this.spotNodeRuntime?.meshNode(meshName)
2003
+ : undefined;
2004
+ const localStatus = node?.status();
2005
+ // ownsLocation tracks local cleanup responsibility, not Actor authority.
2006
+ // A relocation target can exact-read committed authority without owning that cleanup.
2007
+ if (localStatus === undefined
2008
+ || !(0, routing_id_1.routingIdsEqual)(localStatus.routingId, binding.actor.nodeRid)
2009
+ || localStatus.lifecycleGeneration !== binding.actorNodeGeneration
2010
+ || state.locationGeneration !== binding.authorityOwnerGeneration
2011
+ || state.isMoving) {
2012
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale, `Actor '${binding.actor.actorId}' binding authority fence is stale.`);
2013
+ return;
2014
+ }
2015
+ const sessionOwnerIsLocal = (0, routing_id_1.routingIdsEqual)(localStatus.routingId, binding.sessionNodeRid) && localStatus.lifecycleGeneration === binding.sessionOwnerNodeGeneration;
2016
+ if (binding.transition === 'tombstone') {
2017
+ const actorRef = {
2018
+ actorId: binding.actor.actorId,
2019
+ objectGeneration: binding.actor.generation,
2020
+ meshName,
2021
+ nodeRid: binding.actor.nodeRid
2022
+ };
2023
+ if (sessionOwnerIsLocal) {
2024
+ await this.streamBindingRuntime.retireRemoteBinding(actorRef, binding.sessionRid, binding.bindingGeneration, signal);
2025
+ }
2026
+ state.retireBoundSessionBinding(binding);
2027
+ replyBindingSuccess();
2028
+ return;
2029
+ }
2030
+ const target = this.boundSessionRelay.boundSessions.resolveRemoteBoundSessionTarget(binding.sessionNodeRid, binding.sessionRid);
2031
+ if (target === undefined) {
2032
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale, `Actor '${binding.actor.actorId}' Session route is unavailable.`);
2033
+ return;
2034
+ }
2035
+ const installed = state.installBoundSessionBinding({
2036
+ ...target,
2037
+ sessionNodeRid: binding.sessionNodeRid,
2038
+ sessionRid: binding.sessionRid,
2039
+ sessionOwnerNodeGeneration: binding.sessionOwnerNodeGeneration,
2040
+ sessionOwnerId: binding.sessionOwnerId,
2041
+ sessionOwnerLeaseGeneration: binding.sessionOwnerLeaseGeneration,
2042
+ bindingGeneration: binding.bindingGeneration
2043
+ });
2044
+ if (!installed) {
2045
+ replyBindingFailure(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.ActorLocationStale, `Actor '${binding.actor.actorId}' Session binding generation is stale.`);
2046
+ return;
2047
+ }
2048
+ replyBindingSuccess();
2049
+ return Promise.resolve();
2050
+ }
2051
+ switch (record.kind) {
2052
+ case service_runtime_contracts_1.ReceiveKind.TransferControl:
2053
+ if (record.kindData?.kind !== 'transferControl') {
2054
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode transfer control record has no typed control payload.');
2055
+ }
2056
+ return this.actorTransferAuthorityRuntime.handle(meshName, record.kindData, signal);
2057
+ case service_runtime_contracts_1.ReceiveKind.ChannelSend:
2058
+ case service_runtime_contracts_1.ReceiveKind.ChannelRequest: {
2059
+ const channelRuntime = this.channelRuntime;
2060
+ if (channelRuntime === undefined) {
2061
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode channel dispatch requires the channel runtime.');
2062
+ }
2063
+ return this.admission.run(meshName, 'RouteMesh channel dispatch', () => channelRuntime.dispatchMeshChannel(meshName, record, signal));
2064
+ }
2065
+ case service_runtime_contracts_1.ReceiveKind.NodeSend:
2066
+ case service_runtime_contracts_1.ReceiveKind.NodeRequest: {
2067
+ if (await this.serviceRelocation.tryHandleControl(meshName, record, signal)) {
2068
+ return;
2069
+ }
2070
+ if (record.kind === service_runtime_contracts_1.ReceiveKind.NodeRequest && record.parts.length === 1) {
2071
+ const terminal = (0, actors_2.decodeRemoteActorSourceLeaveTerminal)(record.parts[0].data());
2072
+ if (terminal !== undefined) {
2073
+ if (await this.spotManager?.completeFormalSourceLeaveTerminal(terminal.actorId, terminal.transferId, terminal.succeeded) !== true) {
2074
+ throw new ConfigurationException_1.ZLinkConfigurationException(`Actor '${terminal.actorId}' has no matching formal transfer terminal gate.`);
2075
+ }
2076
+ if (record.reply(Buffer.alloc(0)) !== runtime_values_1.SubmitResult.Ok) {
2077
+ throw new ConfigurationException_1.ZLinkConfigurationException(`Actor '${terminal.actorId}' formal transfer terminal acknowledgement failed.`);
2078
+ }
2079
+ return Promise.resolve();
2080
+ }
2081
+ }
2082
+ const channelRuntime = this.channelRuntime;
2083
+ if (channelRuntime === undefined) {
2084
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode node-direct dispatch requires the channel runtime.');
2085
+ }
2086
+ return this.admission.run(meshName, 'RouteMesh node dispatch', () => channelRuntime.dispatchMeshRoute(meshName, record, signal));
2087
+ }
2088
+ case service_runtime_contracts_1.ReceiveKind.SpotSend:
2089
+ case service_runtime_contracts_1.ReceiveKind.SpotRequest:
2090
+ case service_runtime_contracts_1.ReceiveKind.SpotMulticast:
2091
+ return this.admission.run(meshName, 'RouteMesh Spot dispatch', () => this.dispatchMeshSpotRecord(meshName, owner, record));
2092
+ case service_runtime_contracts_1.ReceiveKind.InstanceSpotActivation:
2093
+ if (this.spotManager === undefined) {
2094
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Instance Spot dispatch requires the Spot manager.');
2095
+ }
2096
+ return this.admission.run(meshName, 'RouteMesh Instance Spot dispatch', () => this.spotManager.dispatchMeshInstance(meshName, owner, record));
2097
+ case service_runtime_contracts_1.ReceiveKind.SpotControl:
2098
+ if (this.spotManager === undefined) {
2099
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Spot control dispatch requires the Spot manager.');
2100
+ }
2101
+ return this.spotManager.dispatchMeshSpotControl(meshName, owner, record);
2102
+ case service_runtime_contracts_1.ReceiveKind.ActorSend:
2103
+ case service_runtime_contracts_1.ReceiveKind.ActorRequest:
2104
+ if (this.spotManager === undefined) {
2105
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Actor dispatch requires the Spot manager.');
2106
+ }
2107
+ return this.admission.run(meshName, 'RouteMesh Actor dispatch', () => this.spotManager.dispatchMeshActor(meshName, owner, record));
2108
+ case service_runtime_contracts_1.ReceiveKind.SendReady:
2109
+ return Promise.resolve();
2110
+ default:
2111
+ throw new ConfigurationException_1.ZLinkConfigurationException(`MeshNode record kind '${record.kind}' does not yet have a registered framework consumer.`);
2112
+ }
2113
+ }
2114
+ submitLocalMeshRoute(meshName, sourceNodeRid, parts) {
2115
+ const state = this.executionState;
2116
+ const channelRuntime = this.channelRuntime;
2117
+ if (state === undefined || channelRuntime === undefined || !this.admission.accepts(meshName)) {
2118
+ return { status: submission_result_1.ZLinkSubmitStatus.Shutdown };
2119
+ }
2120
+ if (!channelRuntime.canDispatchLocalMeshRoute(meshName)) {
2121
+ return { status: submission_result_1.ZLinkSubmitStatus.TargetNotFound };
2122
+ }
2123
+ const claim = this.admission.claim(meshName, 'RouteMesh local node dispatch');
2124
+ const ownedParts = [];
2125
+ try {
2126
+ for (const part of parts) {
2127
+ ownedParts.push(runtime_message_1.ZLinkBufferMessage.from(typeof part.data === 'function'
2128
+ ? part.data()
2129
+ : part));
2130
+ }
2131
+ }
2132
+ catch (error) {
2133
+ for (const part of ownedParts)
2134
+ part.close();
2135
+ claim.close();
2136
+ throw error;
2137
+ }
2138
+ try {
2139
+ state.taskRunner.runDetached('mesh-node-local-route-dispatch', async () => {
2140
+ try {
2141
+ const permit = await this.applicationJobQueue.acquire(state.abortController.signal);
2142
+ permit.markApplicationQueued();
2143
+ await (0, application_job_queue_scope_1.runWithApplicationJobPermit)(permit, () => channelRuntime.dispatchLocalMeshRoute(meshName, sourceNodeRid, ownedParts));
2144
+ }
2145
+ finally {
2146
+ for (const part of ownedParts)
2147
+ part.close();
2148
+ claim.close();
2149
+ }
2150
+ });
2151
+ }
2152
+ catch (error) {
2153
+ for (const part of ownedParts)
2154
+ part.close();
2155
+ claim.close();
2156
+ throw error;
2157
+ }
2158
+ return { status: submission_result_1.ZLinkSubmitStatus.Submitted };
2159
+ }
2160
+ async dispatchMeshSpotRecord(meshName, owner, record) {
2161
+ const envelope = (0, channel_envelope_1.decodeChannelEnvelope)(record.parts, undefined, this.flowCreationEnabled());
2162
+ if (envelope.packetName === actors_1.ZLINK_REMOTE_ACTOR_PACKET_RELAY_PACKET) {
2163
+ const payload = (0, channel_envelope_1.decodeChannelPayload)(envelope, { serializers: this.options.registration.messageSerializers });
2164
+ const context = {
2165
+ meshName,
2166
+ packetName: envelope.packetName,
2167
+ contentType: envelope.header.contentType,
2168
+ sourceNodeRid: String(record.sourceNodeRid ?? ''),
2169
+ metadata: (0, contracts_1.zlinkMessageMetadata)(envelope.header.metadata),
2170
+ correlationId: envelope.header.correlationId ?? undefined
2171
+ };
2172
+ try {
2173
+ const response = await this.boundSessionRelay.actorPackets
2174
+ .receiveRemoteActorPacketRelay(payload, context);
2175
+ if (record.kind === service_runtime_contracts_1.ReceiveKind.SpotRequest) {
2176
+ record.reply((0, channel_envelope_1.encodeChannelReplyParts)(envelope.header, response));
2177
+ }
2178
+ }
2179
+ catch (error) {
2180
+ if (record.kind !== service_runtime_contracts_1.ReceiveKind.SpotRequest) {
2181
+ throw error;
2182
+ }
2183
+ record.reply((0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error instanceof Error ? error.message : String(error)));
2184
+ }
2185
+ return;
2186
+ }
2187
+ if (await this.spotNodeRuntime?.dispatchEntrySpotRecord(meshName, owner, record) === true) {
2188
+ return;
2189
+ }
2190
+ if (this.spotManager === undefined) {
2191
+ throw new ConfigurationException_1.ZLinkConfigurationException('MeshNode Spot dispatch requires the Spot manager.');
2192
+ }
2193
+ await this.spotManager.dispatchMeshSpot(meshName, owner, record);
2194
+ }
2195
+ createDispatchErrorReporter(errorSink) {
2196
+ const existing = this.dispatchErrorReporters.get(errorSink);
2197
+ if (existing !== undefined) {
2198
+ return existing;
2199
+ }
2200
+ const reporter = new channels_1.ZLinkDispatchErrorReporter(undefined, undefined, errorSink, this.diagnosticsContext(), this.metrics);
2201
+ this.dispatchErrorReporters.set(errorSink, reporter);
2202
+ return reporter;
2203
+ }
2204
+ detachedTaskRunner() {
2205
+ return {
2206
+ runDetached: (taskName, callback) => {
2207
+ const runner = this.executionState?.taskRunner;
2208
+ if (runner !== undefined) {
2209
+ runner.runDetached(taskName, () => callback());
2210
+ return;
2211
+ }
2212
+ void callback().catch((error) => this.preStartErrorSink.reportRuntimeTaskException(taskName, error));
2213
+ }
2214
+ };
2215
+ }
2216
+ diagnosticsContext() {
2217
+ this.cachedDiagnosticsContext ??= (0, diagnostics_1.createDiagnosticsContext)(this.options.registration.dispatch, this.options.providerResolver, this.messageFlowModeCell);
2218
+ return this.cachedDiagnosticsContext;
2219
+ }
2220
+ flowCreationEnabled() {
2221
+ const mode = this.executionState === undefined
2222
+ ? this.options.registration.dispatch?.diagnostics.messageFlow ?? 'errors'
2223
+ : this.messageFlowModeCell.mode;
2224
+ return mode !== 'off';
2225
+ }
2226
+ runLifecycle(operation) {
2227
+ const current = (0, diagnostics_1.currentOrCreateFlow)('Lifecycle', false);
2228
+ const flow = current?.flowOrigin === 'Lifecycle'
2229
+ ? current
2230
+ : (0, diagnostics_1.createInboundFlow)(undefined, 'Lifecycle', this.flowCreationEnabled());
2231
+ return (0, diagnostics_1.runWithFlow)(flow, operation);
2232
+ }
2233
+ requirePrimaryMeshNode() {
2234
+ const node = this.spotNodeRuntime?.primaryMeshNode;
2235
+ if (node === undefined) {
2236
+ throw new Error('Primary Entry Spot node is not started.');
2237
+ }
2238
+ return node;
2239
+ }
2240
+ ensureLocationRuntime() {
2241
+ return this.locationOwner.ensureRuntime(this.meshRouters.primaryMeshName());
2242
+ }
2243
+ createLocationSpotRouteResolver() {
2244
+ if (this.cachedLocationSpotRouteResolver !== undefined) {
2245
+ return this.cachedLocationSpotRouteResolver;
2246
+ }
2247
+ this.ensureLocationRuntime();
2248
+ const legacy = this.locationOwner.createSpotRouteResolver(this.meshRouters.spotLocationMeshNames(), this.meshRouters.spotRouterChannelIdByMesh(), (spotId) => this.spotManager?.resolveLocalSpotRoute(spotId));
2249
+ const authority = this.locationOwner.currentStores?.locationStore;
2250
+ const resolver = authority === undefined
2251
+ ? legacy
2252
+ : new locations_1.ZLinkAuthoritySpotRouteResolver(authority, this.meshRouters.spotRouterChannelIdByMesh(), legacy, this.locationOwner.currentLeaseTracker, this.options.registration.locations.options.routeCacheMaxAgeMs, undefined, async (meshName, nodeRid, expectedLifecycleGeneration, signal) => {
2253
+ const descriptor = (await authority.listMeshNodes(meshName, undefined, signal)).items.find((candidate) => (0, routing_id_1.routingIdsEqual)(candidate.rid, nodeRid)
2254
+ && candidate.lifecycleGeneration === expectedLifecycleGeneration);
2255
+ return descriptor?.state;
2256
+ });
2257
+ this.cachedLocationSpotRouteResolver = resolver;
2258
+ this.locationOwner.setSpotRouteInvalidator(resolver === undefined ? undefined : spotId => resolver.invalidate?.(spotId));
2259
+ return resolver;
2260
+ }
2261
+ createActorLocationResolver() {
2262
+ return this.locationOwner.createActorLocationResolver(this.meshRouters.spotLocationMeshNames());
2263
+ }
2264
+ }
2265
+ exports.ZLinkFrameworkRuntimeHost = ZLinkFrameworkRuntimeHost;
2266
+ function hasUnsupportedManualTopology(registration) {
2267
+ if ([...registration.routeChannelOptions.values()].some((route) => (route.manualConnections?.length ?? 0) > 0)) {
2268
+ return true;
2269
+ }
2270
+ for (const node of registration.spotNodes.values()) {
2271
+ if ((node.router?.manualConnections?.length ?? 0) > 0
2272
+ || (node.router?.manualPeerConnections?.length ?? 0) > 0) {
2273
+ return true;
2274
+ }
2275
+ }
2276
+ for (const channel of registration.channels.values()) {
2277
+ if ((channel.client?.manualConnections?.length ?? 0) > 0
2278
+ || (channel.subscriber?.manualConnections?.length ?? 0) > 0) {
2279
+ return true;
2280
+ }
2281
+ if (channel.publisher !== undefined
2282
+ && !registration.locations.useInMemoryStores
2283
+ && registration.locations.storeInstance === undefined) {
2284
+ return true;
2285
+ }
2286
+ }
2287
+ return false;
2288
+ }
2289
+ function hasConfiguredLocationStore(registration) {
2290
+ return registration.locations.useInMemoryStores
2291
+ || registration.locations.storeInstance !== undefined;
2292
+ }
2293
+ function hasExactPeerReadiness(descriptors, local, peers) {
2294
+ const replacementDescriptors = descriptors.filter((descriptor) => !(String(descriptor.rid) === String(local.routingId)
2295
+ && descriptor.lifecycleGeneration === local.lifecycleGeneration)
2296
+ && descriptor.state === contracts_1.ZLinkFrameworkRuntimeState.Serving
2297
+ && local.applicationVersion !== undefined
2298
+ && descriptor.applicationVersion === local.applicationVersion
2299
+ && descriptor.objectRole === contracts_1.ZLinkObjectRole.Server
2300
+ && (local.maintenanceWave === undefined
2301
+ || descriptor.maintenanceWave !== local.maintenanceWave));
2302
+ return replacementDescriptors.length > 0
2303
+ && replacementDescriptors.some((descriptor) => peers.some((peer) => peer.routingId !== null
2304
+ && String(peer.routingId) === String(descriptor.rid)
2305
+ && peer.lifecycleGeneration === descriptor.lifecycleGeneration
2306
+ && peer.state === 3));
2307
+ }
2308
+ var actor_transfer_authority_runtime_2 = require("./actor-transfer-authority-runtime");
2309
+ Object.defineProperty(exports, "ZLinkActorTransferAuthorityRuntime", { enumerable: true, get: function () { return actor_transfer_authority_runtime_2.ZLinkActorTransferAuthorityRuntime; } });
2310
+ Object.defineProperty(exports, "transferIdString", { enumerable: true, get: function () { return actor_transfer_authority_runtime_2.transferIdString; } });
2311
+ var route_mesh_runtime_2 = require("./route-mesh-runtime");
2312
+ Object.defineProperty(exports, "ZLinkRetiringRollbackError", { enumerable: true, get: function () { return route_mesh_runtime_2.ZLinkRetiringRollbackError; } });
2313
+ Object.defineProperty(exports, "ZLinkRouteMeshRuntimeCoordinator", { enumerable: true, get: function () { return route_mesh_runtime_2.ZLinkRouteMeshRuntimeCoordinator; } });
2314
+ var service_relocation_host_runtime_2 = require("./service-relocation-host-runtime");
2315
+ Object.defineProperty(exports, "ZLinkRelocationStateIncompatibleError", { enumerable: true, get: function () { return service_relocation_host_runtime_2.ZLinkRelocationStateIncompatibleError; } });
2316
+ var spot_address_transport_2 = require("./spot-address-transport");
2317
+ Object.defineProperty(exports, "ZLinkHostSpotAddressTransport", { enumerable: true, get: function () { return spot_address_transport_2.ZLinkHostSpotAddressTransport; } });
2318
+ var user_spot_creation_coordinator_2 = require("./user-spot-creation-coordinator");
2319
+ Object.defineProperty(exports, "ZLinkUserSpotCreationCoordinator", { enumerable: true, get: function () { return user_spot_creation_coordinator_2.ZLinkUserSpotCreationCoordinator; } });
2320
+ async function waitForForcedSessionNotification(operation) {
2321
+ if (operation === undefined)
2322
+ return;
2323
+ let timeoutHandle;
2324
+ const timeout = new Promise((resolve) => {
2325
+ timeoutHandle = setTimeout(resolve, 100);
2326
+ });
2327
+ try {
2328
+ await Promise.race([operation.catch(() => undefined), timeout]);
2329
+ }
2330
+ finally {
2331
+ if (timeoutHandle !== undefined)
2332
+ clearTimeout(timeoutHandle);
2333
+ }
2334
+ }
2335
+ async function awaitWithDrainSignal(operation, signal) {
2336
+ if (operation === undefined)
2337
+ return;
2338
+ if (signal.aborted)
2339
+ throw signal.reason;
2340
+ await new Promise((resolve, reject) => {
2341
+ const onAbort = () => {
2342
+ reject(signal.reason);
2343
+ };
2344
+ signal.addEventListener('abort', onAbort, { once: true });
2345
+ void operation.then(() => {
2346
+ signal.removeEventListener('abort', onAbort);
2347
+ resolve();
2348
+ }, error => {
2349
+ signal.removeEventListener('abort', onAbort);
2350
+ reject(error);
2351
+ });
2352
+ });
2353
+ }
2354
+ class ZLinkDrainingStatePublishError extends Error {
2355
+ constructor(cause) {
2356
+ super('Failed to publish draining peer rows.', { cause });
2357
+ this.name = 'ZLinkDrainingStatePublishError';
2358
+ }
2359
+ }
2360
+ function resolveBackendAdapterFactory(internalOptions) {
2361
+ if (typeof internalOptions === 'object'
2362
+ && internalOptions !== null
2363
+ && 'backendAdapterFactory' in internalOptions) {
2364
+ const factory = internalOptions.backendAdapterFactory;
2365
+ if (factory !== undefined) {
2366
+ return factory;
2367
+ }
2368
+ }
2369
+ return new backend_1.ZLinkNodeBackendAdapterFactory();
2370
+ }
2371
+ function resolveStreamPayloadCodec(registration) {
2372
+ const codec = registration.codecs.streamCodecs.values().next().value;
2373
+ if (isStreamPayloadCodec(codec)) {
2374
+ return codec;
2375
+ }
2376
+ return undefined;
2377
+ }
2378
+ function runtimeStateMetricName(state) {
2379
+ switch (state) {
2380
+ case contracts_1.ZLinkFrameworkRuntimeState.Preparing: return 'preparing';
2381
+ case contracts_1.ZLinkFrameworkRuntimeState.Serving: return 'serving';
2382
+ case contracts_1.ZLinkFrameworkRuntimeState.Relocating: return 'relocating';
2383
+ case contracts_1.ZLinkFrameworkRuntimeState.Relocated: return 'relocated';
2384
+ case contracts_1.ZLinkFrameworkRuntimeState.Draining: return 'draining';
2385
+ case contracts_1.ZLinkFrameworkRuntimeState.Stopped: return 'stopped';
2386
+ case contracts_1.ZLinkFrameworkRuntimeState.Error: return 'error';
2387
+ }
2388
+ }
2389
+ function relocationModeMetricName(mode) {
2390
+ return mode === contracts_1.ZLinkFrameworkRelocationMode.RollingUpdate
2391
+ ? 'rolling_update'
2392
+ : 'planned_maintenance';
2393
+ }
2394
+ function relocationReasonMetricName(reason) {
2395
+ switch (reason) {
2396
+ case contracts_1.ZLinkFrameworkRelocationReason.None: return 'none';
2397
+ case contracts_1.ZLinkFrameworkRelocationReason.TargetUnavailable: return 'target_unavailable';
2398
+ case contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable: return 'store_unavailable';
2399
+ case contracts_1.ZLinkFrameworkRelocationReason.RelocationDisabled: return 'relocation_disabled';
2400
+ case contracts_1.ZLinkFrameworkRelocationReason.StateIncompatible: return 'state_incompatible';
2401
+ case contracts_1.ZLinkFrameworkRelocationReason.DeadlineExceeded: return 'deadline_exceeded';
2402
+ case contracts_1.ZLinkFrameworkRelocationReason.RelocationFailed: return 'relocation_failed';
2403
+ case contracts_1.ZLinkFrameworkRelocationReason.RuntimeNotReady: return 'runtime_not_ready';
2404
+ case contracts_1.ZLinkFrameworkRelocationReason.ManualTopologyUnsupported: return 'manual_topology_unsupported';
2405
+ case contracts_1.ZLinkFrameworkRelocationReason.ShutdownRequested: return 'shutdown_requested';
2406
+ case contracts_1.ZLinkFrameworkRelocationReason.OperationInProgress: return 'operation_in_progress';
2407
+ }
2408
+ }
2409
+ function terminationReasonMetricName(reason) {
2410
+ switch (reason) {
2411
+ case contracts_1.ZLinkFrameworkTerminationReason.None: return 'none';
2412
+ case contracts_1.ZLinkFrameworkTerminationReason.DeadlineExceeded: return 'deadline_exceeded';
2413
+ case contracts_1.ZLinkFrameworkTerminationReason.TeardownFailed: return 'teardown_failed';
2414
+ }
2415
+ }
2416
+ function isStreamPayloadCodec(codec) {
2417
+ return typeof codec === 'object'
2418
+ && codec !== null
2419
+ && typeof codec.encode === 'function';
2420
+ }
2421
+ function selectLocationPlacementDescriptor(descriptors) {
2422
+ const total = descriptors.reduce((sum, descriptor) => sum + BigInt(descriptor.placementWeight), 0n);
2423
+ if (total === 0n)
2424
+ return undefined;
2425
+ let point = randomBigIntBelow(total);
2426
+ for (const descriptor of descriptors) {
2427
+ const weight = BigInt(descriptor.placementWeight);
2428
+ if (point < weight)
2429
+ return descriptor;
2430
+ point -= weight;
2431
+ }
2432
+ return descriptors.at(-1);
2433
+ }
2434
+ async function selectReadyLocationPlacementDescriptor(descriptors, node, signal, isEligible) {
2435
+ const eligible = descriptors.filter(isEligible);
2436
+ if (eligible.length === 0)
2437
+ return undefined;
2438
+ for (;;) {
2439
+ const localStatus = node?.status();
2440
+ const selected = selectLocationPlacementDescriptor(eligible.filter(descriptor => isPlacementTargetReady(node, localStatus, descriptor)));
2441
+ if (selected !== undefined)
2442
+ return selected;
2443
+ try {
2444
+ await waitForPlacementReadiness(signal);
2445
+ }
2446
+ catch {
2447
+ return undefined;
2448
+ }
2449
+ }
2450
+ }
2451
+ function isPlacementTargetReady(node, localStatus, descriptor) {
2452
+ if (node === undefined)
2453
+ return true;
2454
+ if (localStatus !== undefined
2455
+ && String(localStatus.routingId) === String(descriptor.rid)
2456
+ && localStatus.lifecycleGeneration === descriptor.lifecycleGeneration) {
2457
+ return true;
2458
+ }
2459
+ return node.isPeerRouteReady?.(descriptor.rid, descriptor.lifecycleGeneration) ?? true;
2460
+ }
2461
+ function waitForPlacementReadiness(signal) {
2462
+ if (signal?.aborted === true)
2463
+ return Promise.reject(signal.reason);
2464
+ return new Promise((resolve, reject) => {
2465
+ const timer = setTimeout(() => {
2466
+ signal?.removeEventListener('abort', abort);
2467
+ resolve();
2468
+ }, 10);
2469
+ const abort = () => {
2470
+ clearTimeout(timer);
2471
+ signal?.removeEventListener('abort', abort);
2472
+ reject(signal?.reason);
2473
+ };
2474
+ signal?.addEventListener('abort', abort, { once: true });
2475
+ });
2476
+ }
2477
+ function randomBigIntBelow(exclusiveUpperBound) {
2478
+ if (exclusiveUpperBound <= 0n) {
2479
+ throw new RangeError('Random selection upper bound must be positive.');
2480
+ }
2481
+ const bitLength = exclusiveUpperBound.toString(2).length;
2482
+ const byteLength = Math.ceil(bitLength / 8);
2483
+ const highBitMask = 0xff >> (byteLength * 8 - bitLength);
2484
+ for (;;) {
2485
+ const bytes = (0, node_crypto_1.randomBytes)(byteLength);
2486
+ bytes[0] = bytes[0] & highBitMask;
2487
+ const value = BigInt(`0x${bytes.toString('hex')}`);
2488
+ if (value < exclusiveUpperBound)
2489
+ return value;
2490
+ }
2491
+ }
2492
+ function relocationReason(reason) {
2493
+ switch (reason) {
2494
+ case 'deadline_exceeded': return contracts_1.ZLinkFrameworkRelocationReason.DeadlineExceeded;
2495
+ case 'store_unavailable': return contracts_1.ZLinkFrameworkRelocationReason.StoreUnavailable;
2496
+ case 'target_unavailable': return contracts_1.ZLinkFrameworkRelocationReason.TargetUnavailable;
2497
+ default: return contracts_1.ZLinkFrameworkRelocationReason.RelocationFailed;
2498
+ }
2499
+ }
2500
+ function rewriteAuthorityPayloadForOwner(payload, owner) {
2501
+ const applicationPayload = (0, service_relocation_runtime_1.serviceRelocationAuthorityApplicationPayload)(payload);
2502
+ const rewritten = (0, actors_2.isActorAuthorityPayload)(applicationPayload)
2503
+ ? (0, actors_2.rewriteActorAuthorityOwner)(applicationPayload, owner)
2504
+ : (0, service_authority_payload_codec_1.rewriteServiceAuthorityOwner)(applicationPayload, owner) ?? applicationPayload;
2505
+ return (0, service_relocation_runtime_1.replaceServiceRelocationAuthorityApplicationPayload)(payload, rewritten);
2506
+ }
2507
+ function validateRelocationOptions(options, sourceApplicationVersion) {
2508
+ if (options === undefined) {
2509
+ throw new TypeError('Relocation mode is required.');
2510
+ }
2511
+ const mode = options.mode;
2512
+ if (mode !== contracts_1.ZLinkFrameworkRelocationMode.PlannedMaintenance
2513
+ && mode !== contracts_1.ZLinkFrameworkRelocationMode.RollingUpdate) {
2514
+ throw new TypeError('Relocation mode is required.');
2515
+ }
2516
+ if (options.mode === contracts_1.ZLinkFrameworkRelocationMode.PlannedMaintenance) {
2517
+ if (options.targetApplicationVersion !== undefined) {
2518
+ throw new TypeError('PlannedMaintenance relocation cannot define targetApplicationVersion.');
2519
+ }
2520
+ return sourceApplicationVersion;
2521
+ }
2522
+ if (typeof options.targetApplicationVersion !== 'bigint'
2523
+ || options.targetApplicationVersion <= sourceApplicationVersion) {
2524
+ throw new TypeError('RollingUpdate relocation requires a targetApplicationVersion greater than the source version.');
2525
+ }
2526
+ return options.targetApplicationVersion;
2527
+ }
2528
+ function blockedRelocation(mode, effectiveTargetApplicationVersion, reason) {
2529
+ return {
2530
+ mode,
2531
+ effectiveTargetApplicationVersion,
2532
+ outcome: contracts_1.ZLinkFrameworkRelocationOutcome.Blocked,
2533
+ reason
2534
+ };
2535
+ }
2536
+ function waitForRuntimeOperation(operation, signal) {
2537
+ if (signal === undefined)
2538
+ return operation;
2539
+ signal.throwIfAborted();
2540
+ return new Promise((resolve, reject) => {
2541
+ const aborted = () => reject(signal.reason);
2542
+ signal.addEventListener('abort', aborted, { once: true });
2543
+ operation.then(resolve, reject).finally(() => signal.removeEventListener('abort', aborted));
2544
+ });
2545
+ }
2546
+ function registeredRuntimeStores(registration) {
2547
+ const stores = [
2548
+ registration.locations.storeInstance,
2549
+ registration.locations.relocationStoreInstance
2550
+ ];
2551
+ return stores.filter((store) => store !== undefined);
2552
+ }