@moltzap/client 2026.812.0 → 2026.902.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 (392) hide show
  1. package/LICENSE +202 -21
  2. package/NOTICE +19 -0
  3. package/README.md +50 -0
  4. package/bin/moltzapd +9 -0
  5. package/dist/client-runtime.d.ts +10 -0
  6. package/dist/client-runtime.d.ts.map +1 -0
  7. package/dist/client-runtime.js +218 -0
  8. package/dist/client-runtime.js.map +1 -0
  9. package/dist/contract.d.ts +338 -0
  10. package/dist/contract.d.ts.map +1 -0
  11. package/dist/contract.js +213 -0
  12. package/dist/contract.js.map +1 -0
  13. package/dist/contract.types-check.d.ts +99 -0
  14. package/dist/contract.types-check.d.ts.map +1 -0
  15. package/dist/contract.types-check.js +7 -0
  16. package/dist/contract.types-check.js.map +1 -0
  17. package/dist/daemon/configuration.d.ts +46 -0
  18. package/dist/daemon/configuration.d.ts.map +1 -0
  19. package/dist/daemon/configuration.js +69 -0
  20. package/dist/daemon/configuration.js.map +1 -0
  21. package/dist/daemon/management.d.ts +23 -0
  22. package/dist/daemon/management.d.ts.map +1 -0
  23. package/dist/daemon/management.js +489 -0
  24. package/dist/daemon/management.js.map +1 -0
  25. package/dist/daemon/registration.d.ts +72 -0
  26. package/dist/daemon/registration.d.ts.map +1 -0
  27. package/dist/daemon/registration.js +109 -0
  28. package/dist/daemon/registration.js.map +1 -0
  29. package/dist/daemon/runtime/activation.d.ts +95 -0
  30. package/dist/daemon/runtime/activation.d.ts.map +1 -0
  31. package/dist/daemon/runtime/activation.js +99 -0
  32. package/dist/daemon/runtime/activation.js.map +1 -0
  33. package/dist/daemon/runtime/controller.d.ts +34 -0
  34. package/dist/daemon/runtime/controller.d.ts.map +1 -0
  35. package/dist/daemon/runtime/controller.js +106 -0
  36. package/dist/daemon/runtime/controller.js.map +1 -0
  37. package/dist/daemon/runtime/history-export.d.ts +23 -0
  38. package/dist/daemon/runtime/history-export.d.ts.map +1 -0
  39. package/dist/daemon/runtime/history-export.js +47 -0
  40. package/dist/daemon/runtime/history-export.js.map +1 -0
  41. package/dist/daemon/runtime/index.d.ts +24 -0
  42. package/dist/daemon/runtime/index.d.ts.map +1 -0
  43. package/dist/daemon/runtime/index.js +65 -0
  44. package/dist/daemon/runtime/index.js.map +1 -0
  45. package/dist/daemon/runtime/protocol.d.ts +63 -0
  46. package/dist/daemon/runtime/protocol.d.ts.map +1 -0
  47. package/dist/daemon/runtime/protocol.js +133 -0
  48. package/dist/daemon/runtime/protocol.js.map +1 -0
  49. package/dist/endpoint/addressing/index.d.ts +39 -0
  50. package/dist/endpoint/addressing/index.d.ts.map +1 -0
  51. package/dist/endpoint/addressing/index.js +114 -0
  52. package/dist/endpoint/addressing/index.js.map +1 -0
  53. package/dist/endpoint/engine-dissemination.d.ts +11 -0
  54. package/dist/endpoint/engine-dissemination.d.ts.map +1 -0
  55. package/dist/endpoint/engine-dissemination.js +71 -0
  56. package/dist/endpoint/engine-dissemination.js.map +1 -0
  57. package/dist/endpoint/engine-durability.d.ts +69 -0
  58. package/dist/endpoint/engine-durability.d.ts.map +1 -0
  59. package/dist/endpoint/engine-durability.js +210 -0
  60. package/dist/endpoint/engine-durability.js.map +1 -0
  61. package/dist/endpoint/engine-send.d.ts +50 -0
  62. package/dist/endpoint/engine-send.d.ts.map +1 -0
  63. package/dist/endpoint/engine-send.js +422 -0
  64. package/dist/endpoint/engine-send.js.map +1 -0
  65. package/dist/endpoint/engine-types.d.ts +132 -0
  66. package/dist/endpoint/engine-types.d.ts.map +1 -0
  67. package/dist/endpoint/engine-types.js +13 -0
  68. package/dist/endpoint/engine-types.js.map +1 -0
  69. package/dist/endpoint/engine.d.ts +14 -0
  70. package/dist/endpoint/engine.d.ts.map +1 -0
  71. package/dist/endpoint/engine.js +280 -0
  72. package/dist/endpoint/engine.js.map +1 -0
  73. package/dist/endpoint/protocol/evidence.d.ts +37 -0
  74. package/dist/endpoint/protocol/evidence.d.ts.map +1 -0
  75. package/dist/endpoint/protocol/evidence.js +80 -0
  76. package/dist/endpoint/protocol/evidence.js.map +1 -0
  77. package/dist/endpoint/protocol/index.d.ts +26 -0
  78. package/dist/endpoint/protocol/index.d.ts.map +1 -0
  79. package/dist/endpoint/protocol/index.js +543 -0
  80. package/dist/endpoint/protocol/index.js.map +1 -0
  81. package/dist/endpoint/recovery/barrier.d.ts +23 -0
  82. package/dist/endpoint/recovery/barrier.d.ts.map +1 -0
  83. package/dist/endpoint/recovery/barrier.js +47 -0
  84. package/dist/endpoint/recovery/barrier.js.map +1 -0
  85. package/dist/endpoint/recovery/index.d.ts +29 -0
  86. package/dist/endpoint/recovery/index.d.ts.map +1 -0
  87. package/dist/endpoint/recovery/index.js +489 -0
  88. package/dist/endpoint/recovery/index.js.map +1 -0
  89. package/dist/endpoint/recovery/reanchor/empty.d.ts +22 -0
  90. package/dist/endpoint/recovery/reanchor/empty.d.ts.map +1 -0
  91. package/dist/endpoint/recovery/reanchor/empty.js +163 -0
  92. package/dist/endpoint/recovery/reanchor/empty.js.map +1 -0
  93. package/dist/endpoint/recovery/reanchor/index.d.ts +30 -0
  94. package/dist/endpoint/recovery/reanchor/index.d.ts.map +1 -0
  95. package/dist/endpoint/recovery/reanchor/index.js +479 -0
  96. package/dist/endpoint/recovery/reanchor/index.js.map +1 -0
  97. package/dist/endpoint/recovery/state.d.ts +130 -0
  98. package/dist/endpoint/recovery/state.d.ts.map +1 -0
  99. package/dist/endpoint/recovery/state.js +296 -0
  100. package/dist/endpoint/recovery/state.js.map +1 -0
  101. package/dist/endpoint/recovery/store-evidence.d.ts +17 -0
  102. package/dist/endpoint/recovery/store-evidence.d.ts.map +1 -0
  103. package/dist/endpoint/recovery/store-evidence.js +79 -0
  104. package/dist/endpoint/recovery/store-evidence.js.map +1 -0
  105. package/dist/endpoint/recovery/store.d.ts +56 -0
  106. package/dist/endpoint/recovery/store.d.ts.map +1 -0
  107. package/dist/endpoint/recovery/store.js +499 -0
  108. package/dist/endpoint/recovery/store.js.map +1 -0
  109. package/dist/endpoint/representation-canonical.d.ts +17 -0
  110. package/dist/endpoint/representation-canonical.d.ts.map +1 -0
  111. package/dist/endpoint/representation-canonical.js +48 -0
  112. package/dist/endpoint/representation-canonical.js.map +1 -0
  113. package/dist/endpoint/representation-codec.d.ts +51 -0
  114. package/dist/endpoint/representation-codec.d.ts.map +1 -0
  115. package/dist/endpoint/representation-codec.js +159 -0
  116. package/dist/endpoint/representation-codec.js.map +1 -0
  117. package/dist/endpoint/representation-schemas.d.ts +1831 -0
  118. package/dist/endpoint/representation-schemas.d.ts.map +1 -0
  119. package/dist/endpoint/representation-schemas.js +195 -0
  120. package/dist/endpoint/representation-schemas.js.map +1 -0
  121. package/dist/endpoint/representation-verification.d.ts +79 -0
  122. package/dist/endpoint/representation-verification.d.ts.map +1 -0
  123. package/dist/endpoint/representation-verification.js +420 -0
  124. package/dist/endpoint/representation-verification.js.map +1 -0
  125. package/dist/endpoint/representation.d.ts +6 -0
  126. package/dist/endpoint/representation.d.ts.map +1 -0
  127. package/dist/endpoint/representation.js +8 -0
  128. package/dist/endpoint/representation.js.map +1 -0
  129. package/dist/endpoint/router-worker/index.d.ts +16 -0
  130. package/dist/endpoint/router-worker/index.d.ts.map +1 -0
  131. package/dist/endpoint/router-worker/index.js +547 -0
  132. package/dist/endpoint/router-worker/index.js.map +1 -0
  133. package/dist/endpoint/router-worker/types.d.ts +183 -0
  134. package/dist/endpoint/router-worker/types.d.ts.map +1 -0
  135. package/dist/endpoint/router-worker/types.js +31 -0
  136. package/dist/endpoint/router-worker/types.js.map +1 -0
  137. package/dist/endpoint/store/anchors.d.ts +83 -0
  138. package/dist/endpoint/store/anchors.d.ts.map +1 -0
  139. package/dist/endpoint/store/anchors.js +471 -0
  140. package/dist/endpoint/store/anchors.js.map +1 -0
  141. package/dist/endpoint/store/database/index.d.ts +6 -0
  142. package/dist/endpoint/store/database/index.d.ts.map +1 -0
  143. package/dist/endpoint/store/database/index.js +6 -0
  144. package/dist/endpoint/store/database/index.js.map +1 -0
  145. package/dist/endpoint/store/database/schema.d.ts +44 -0
  146. package/dist/endpoint/store/database/schema.d.ts.map +1 -0
  147. package/dist/endpoint/store/database/schema.js +345 -0
  148. package/dist/endpoint/store/database/schema.js.map +1 -0
  149. package/dist/endpoint/store/database/values.d.ts +119 -0
  150. package/dist/endpoint/store/database/values.d.ts.map +1 -0
  151. package/dist/endpoint/store/database/values.js +194 -0
  152. package/dist/endpoint/store/database/values.js.map +1 -0
  153. package/dist/endpoint/store/deliveries.d.ts +38 -0
  154. package/dist/endpoint/store/deliveries.d.ts.map +1 -0
  155. package/dist/endpoint/store/deliveries.js +124 -0
  156. package/dist/endpoint/store/deliveries.js.map +1 -0
  157. package/dist/endpoint/store/dissemination.d.ts +27 -0
  158. package/dist/endpoint/store/dissemination.d.ts.map +1 -0
  159. package/dist/endpoint/store/dissemination.js +139 -0
  160. package/dist/endpoint/store/dissemination.js.map +1 -0
  161. package/dist/endpoint/store/index.d.ts +15 -0
  162. package/dist/endpoint/store/index.d.ts.map +1 -0
  163. package/dist/endpoint/store/index.js +76 -0
  164. package/dist/endpoint/store/index.js.map +1 -0
  165. package/dist/endpoint/store/management.d.ts +42 -0
  166. package/dist/endpoint/store/management.d.ts.map +1 -0
  167. package/dist/endpoint/store/management.js +259 -0
  168. package/dist/endpoint/store/management.js.map +1 -0
  169. package/dist/endpoint/store/outbound.d.ts +62 -0
  170. package/dist/endpoint/store/outbound.d.ts.map +1 -0
  171. package/dist/endpoint/store/outbound.js +278 -0
  172. package/dist/endpoint/store/outbound.js.map +1 -0
  173. package/dist/endpoint/store/records.d.ts +56 -0
  174. package/dist/endpoint/store/records.d.ts.map +1 -0
  175. package/dist/endpoint/store/records.js +352 -0
  176. package/dist/endpoint/store/records.js.map +1 -0
  177. package/dist/endpoint/store/rows/index.d.ts +138 -0
  178. package/dist/endpoint/store/rows/index.d.ts.map +1 -0
  179. package/dist/endpoint/store/rows/index.js +307 -0
  180. package/dist/endpoint/store/rows/index.js.map +1 -0
  181. package/dist/endpoint/store/types.d.ts +223 -0
  182. package/dist/endpoint/store/types.d.ts.map +1 -0
  183. package/dist/endpoint/store/types.js +15 -0
  184. package/dist/endpoint/store/types.js.map +1 -0
  185. package/dist/endpoint/store.d.ts +10 -0
  186. package/dist/endpoint/store.d.ts.map +1 -0
  187. package/dist/endpoint/store.js +6 -0
  188. package/dist/endpoint/store.js.map +1 -0
  189. package/dist/harness-mcp-contract.d.ts +101 -0
  190. package/dist/harness-mcp-contract.d.ts.map +1 -0
  191. package/dist/harness-mcp-contract.js +61 -0
  192. package/dist/harness-mcp-contract.js.map +1 -0
  193. package/dist/{harness-mcp-server.d.ts → harness-mcp-http.d.ts} +9 -8
  194. package/dist/harness-mcp-http.d.ts.map +1 -0
  195. package/dist/{harness-mcp-server.js → harness-mcp-http.js} +38 -60
  196. package/dist/harness-mcp-http.js.map +1 -0
  197. package/dist/harness-mcp-subscription.d.ts +12 -7
  198. package/dist/harness-mcp-subscription.d.ts.map +1 -1
  199. package/dist/harness-mcp-subscription.js +113 -100
  200. package/dist/harness-mcp-subscription.js.map +1 -1
  201. package/dist/harness-mcp-wire.d.ts +24 -49
  202. package/dist/harness-mcp-wire.d.ts.map +1 -1
  203. package/dist/harness-mcp-wire.js +381 -124
  204. package/dist/harness-mcp-wire.js.map +1 -1
  205. package/dist/index.d.ts +4 -10
  206. package/dist/index.d.ts.map +1 -1
  207. package/dist/index.js +6 -10
  208. package/dist/index.js.map +1 -1
  209. package/dist/management-runtime.d.ts +217 -0
  210. package/dist/management-runtime.d.ts.map +1 -0
  211. package/dist/management-runtime.js +127 -0
  212. package/dist/management-runtime.js.map +1 -0
  213. package/dist/server.d.ts +16 -0
  214. package/dist/server.d.ts.map +1 -0
  215. package/dist/server.js +46 -0
  216. package/dist/server.js.map +1 -0
  217. package/dist/server.types-check.d.ts +23 -0
  218. package/dist/server.types-check.d.ts.map +1 -0
  219. package/dist/server.types-check.js +7 -0
  220. package/dist/server.types-check.js.map +1 -0
  221. package/package.json +24 -52
  222. package/dist/agent-client.d.ts +0 -5
  223. package/dist/agent-client.d.ts.map +0 -1
  224. package/dist/agent-client.js +0 -3
  225. package/dist/agent-client.js.map +0 -1
  226. package/dist/auth.d.ts +0 -37
  227. package/dist/auth.d.ts.map +0 -1
  228. package/dist/auth.js +0 -79
  229. package/dist/auth.js.map +0 -1
  230. package/dist/bounded-map.d.ts +0 -32
  231. package/dist/bounded-map.d.ts.map +0 -1
  232. package/dist/bounded-map.js +0 -79
  233. package/dist/bounded-map.js.map +0 -1
  234. package/dist/channel-base/format-cross-conv.d.ts +0 -43
  235. package/dist/channel-base/format-cross-conv.d.ts.map +0 -1
  236. package/dist/channel-base/format-cross-conv.js +0 -65
  237. package/dist/channel-base/format-cross-conv.js.map +0 -1
  238. package/dist/channel-base/format-group-block.d.ts +0 -48
  239. package/dist/channel-base/format-group-block.d.ts.map +0 -1
  240. package/dist/channel-base/format-group-block.js +0 -62
  241. package/dist/channel-base/format-group-block.js.map +0 -1
  242. package/dist/channel-base/index.d.ts +0 -12
  243. package/dist/channel-base/index.d.ts.map +0 -1
  244. package/dist/channel-base/index.js +0 -16
  245. package/dist/channel-base/index.js.map +0 -1
  246. package/dist/channel-core-enrichment.d.ts +0 -38
  247. package/dist/channel-core-enrichment.d.ts.map +0 -1
  248. package/dist/channel-core-enrichment.js +0 -217
  249. package/dist/channel-core-enrichment.js.map +0 -1
  250. package/dist/channel-core-test-support.d.ts +0 -75
  251. package/dist/channel-core-test-support.d.ts.map +0 -1
  252. package/dist/channel-core-test-support.js +0 -74
  253. package/dist/channel-core-test-support.js.map +0 -1
  254. package/dist/channel-core.d.ts +0 -306
  255. package/dist/channel-core.d.ts.map +0 -1
  256. package/dist/channel-core.js +0 -365
  257. package/dist/channel-core.js.map +0 -1
  258. package/dist/config.d.ts +0 -33
  259. package/dist/config.d.ts.map +0 -1
  260. package/dist/config.js +0 -51
  261. package/dist/config.js.map +0 -1
  262. package/dist/config.test-utils.d.ts +0 -24
  263. package/dist/config.test-utils.d.ts.map +0 -1
  264. package/dist/config.test-utils.js +0 -57
  265. package/dist/config.test-utils.js.map +0 -1
  266. package/dist/harness/client-runtime.d.ts +0 -31
  267. package/dist/harness/client-runtime.d.ts.map +0 -1
  268. package/dist/harness/client-runtime.js +0 -121
  269. package/dist/harness/client-runtime.js.map +0 -1
  270. package/dist/harness/index.d.ts +0 -5
  271. package/dist/harness/index.d.ts.map +0 -1
  272. package/dist/harness/index.js +0 -5
  273. package/dist/harness/index.js.map +0 -1
  274. package/dist/harness/runtime.d.ts +0 -301
  275. package/dist/harness/runtime.d.ts.map +0 -1
  276. package/dist/harness/runtime.js +0 -165
  277. package/dist/harness/runtime.js.map +0 -1
  278. package/dist/harness-client.d.ts +0 -47
  279. package/dist/harness-client.d.ts.map +0 -1
  280. package/dist/harness-client.js +0 -76
  281. package/dist/harness-client.js.map +0 -1
  282. package/dist/harness-context-projection.d.ts +0 -35
  283. package/dist/harness-context-projection.d.ts.map +0 -1
  284. package/dist/harness-context-projection.js +0 -123
  285. package/dist/harness-context-projection.js.map +0 -1
  286. package/dist/harness-mcp-server.d.ts.map +0 -1
  287. package/dist/harness-mcp-server.js.map +0 -1
  288. package/dist/local-paths.d.ts +0 -11
  289. package/dist/local-paths.d.ts.map +0 -1
  290. package/dist/local-paths.js +0 -21
  291. package/dist/local-paths.js.map +0 -1
  292. package/dist/message-rendering.d.ts +0 -4
  293. package/dist/message-rendering.d.ts.map +0 -1
  294. package/dist/message-rendering.js +0 -8
  295. package/dist/message-rendering.js.map +0 -1
  296. package/dist/moltzapd-catalog.d.ts +0 -35
  297. package/dist/moltzapd-catalog.d.ts.map +0 -1
  298. package/dist/moltzapd-catalog.js +0 -117
  299. package/dist/moltzapd-catalog.js.map +0 -1
  300. package/dist/moltzapd-child-ipc.d.ts +0 -26
  301. package/dist/moltzapd-child-ipc.d.ts.map +0 -1
  302. package/dist/moltzapd-child-ipc.js +0 -31
  303. package/dist/moltzapd-child-ipc.js.map +0 -1
  304. package/dist/moltzapd-child.d.ts +0 -55
  305. package/dist/moltzapd-child.d.ts.map +0 -1
  306. package/dist/moltzapd-child.js +0 -225
  307. package/dist/moltzapd-child.js.map +0 -1
  308. package/dist/moltzapd-main.d.ts +0 -3
  309. package/dist/moltzapd-main.d.ts.map +0 -1
  310. package/dist/moltzapd-main.js +0 -18
  311. package/dist/moltzapd-main.js.map +0 -1
  312. package/dist/moltzapd-registration.d.ts +0 -40
  313. package/dist/moltzapd-registration.d.ts.map +0 -1
  314. package/dist/moltzapd-registration.js +0 -59
  315. package/dist/moltzapd-registration.js.map +0 -1
  316. package/dist/moltzapd.d.ts +0 -85
  317. package/dist/moltzapd.d.ts.map +0 -1
  318. package/dist/moltzapd.js +0 -150
  319. package/dist/moltzapd.js.map +0 -1
  320. package/dist/notification/__tests__/subscribe-signatures.types-check.d.ts +0 -53
  321. package/dist/notification/__tests__/subscribe-signatures.types-check.d.ts.map +0 -1
  322. package/dist/notification/__tests__/subscribe-signatures.types-check.js +0 -29
  323. package/dist/notification/__tests__/subscribe-signatures.types-check.js.map +0 -1
  324. package/dist/notification/errors.d.ts +0 -41
  325. package/dist/notification/errors.d.ts.map +0 -1
  326. package/dist/notification/errors.js +0 -24
  327. package/dist/notification/errors.js.map +0 -1
  328. package/dist/notification/index.d.ts +0 -6
  329. package/dist/notification/index.d.ts.map +0 -1
  330. package/dist/notification/index.js +0 -6
  331. package/dist/notification/index.js.map +0 -1
  332. package/dist/notification/stream.d.ts +0 -75
  333. package/dist/notification/stream.d.ts.map +0 -1
  334. package/dist/notification/stream.js +0 -30
  335. package/dist/notification/stream.js.map +0 -1
  336. package/dist/notification/trace.d.ts +0 -10
  337. package/dist/notification/trace.d.ts.map +0 -1
  338. package/dist/notification/trace.js +0 -34
  339. package/dist/notification/trace.js.map +0 -1
  340. package/dist/pagination.d.ts +0 -52
  341. package/dist/pagination.d.ts.map +0 -1
  342. package/dist/pagination.js +0 -51
  343. package/dist/pagination.js.map +0 -1
  344. package/dist/presentation/index.d.ts +0 -3
  345. package/dist/presentation/index.d.ts.map +0 -1
  346. package/dist/presentation/index.js +0 -3
  347. package/dist/presentation/index.js.map +0 -1
  348. package/dist/presentation/state.d.ts +0 -77
  349. package/dist/presentation/state.d.ts.map +0 -1
  350. package/dist/presentation/state.js +0 -211
  351. package/dist/presentation/state.js.map +0 -1
  352. package/dist/profile.d.ts +0 -106
  353. package/dist/profile.d.ts.map +0 -1
  354. package/dist/profile.js +0 -171
  355. package/dist/profile.js.map +0 -1
  356. package/dist/service-event-trace.d.ts +0 -15
  357. package/dist/service-event-trace.d.ts.map +0 -1
  358. package/dist/service-event-trace.js +0 -35
  359. package/dist/service-event-trace.js.map +0 -1
  360. package/dist/service.d.ts +0 -228
  361. package/dist/service.d.ts.map +0 -1
  362. package/dist/service.js +0 -485
  363. package/dist/service.js.map +0 -1
  364. package/dist/test-utils/channel-service-fixture.d.ts +0 -53
  365. package/dist/test-utils/channel-service-fixture.d.ts.map +0 -1
  366. package/dist/test-utils/channel-service-fixture.js +0 -178
  367. package/dist/test-utils/channel-service-fixture.js.map +0 -1
  368. package/dist/test-utils/fake-service.d.ts +0 -82
  369. package/dist/test-utils/fake-service.d.ts.map +0 -1
  370. package/dist/test-utils/fake-service.js +0 -108
  371. package/dist/test-utils/fake-service.js.map +0 -1
  372. package/dist/test-utils/harness.d.ts +0 -27
  373. package/dist/test-utils/harness.d.ts.map +0 -1
  374. package/dist/test-utils/harness.js +0 -33
  375. package/dist/test-utils/harness.js.map +0 -1
  376. package/dist/test-utils/ids.d.ts +0 -21
  377. package/dist/test-utils/ids.d.ts.map +0 -1
  378. package/dist/test-utils/ids.js +0 -68
  379. package/dist/test-utils/ids.js.map +0 -1
  380. package/dist/test-utils/index.d.ts +0 -56
  381. package/dist/test-utils/index.d.ts.map +0 -1
  382. package/dist/test-utils/index.js +0 -67
  383. package/dist/test-utils/index.js.map +0 -1
  384. package/dist/test-utils/process/reserve-port.d.ts +0 -20
  385. package/dist/test-utils/process/reserve-port.d.ts.map +0 -1
  386. package/dist/test-utils/process/reserve-port.js +0 -41
  387. package/dist/test-utils/process/reserve-port.js.map +0 -1
  388. package/dist/test-utils/standalone-provisioning.d.ts +0 -22
  389. package/dist/test-utils/standalone-provisioning.d.ts.map +0 -1
  390. package/dist/test-utils/standalone-provisioning.js +0 -17
  391. package/dist/test-utils/standalone-provisioning.js.map +0 -1
  392. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,306 +0,0 @@
1
- /**
2
- * Channel core: serialized inbound turn delivery over a MoltZapService.
3
- * Owns the inbound queue, same-conversation coalescing, the interceptor
4
- * gate, the per-turn timeout, and channel teardown. Enriched adapter delivery
5
- * uses channel-core-enrichment.ts; raw daemon delivery receives the coalesced
6
- * Message batch without reading or committing presentation context.
7
- */
8
- import { Effect } from "effect";
9
- import type { ConversationId } from "@moltzap/protocol/conversation";
10
- import type { Message } from "@moltzap/protocol/message";
11
- import type { CrossConversationEntry, CrossConvMessage, ServiceRpcError } from "./service.js";
12
- /** Projects MCP-reconstructed context through the channel-owned presentation. */
13
- export { projectHarnessTurn } from "./channel-core-enrichment.js";
14
- /** Describes enriched sender. */
15
- interface EnrichedSender {
16
- id: string;
17
- name: string;
18
- }
19
- /** Describes enriched conversation meta. */
20
- export interface EnrichedConversationMeta {
21
- type: "dm" | "group";
22
- name?: string;
23
- /** "type:id" strings (e.g. "agent:uuid"). */
24
- participants: string[];
25
- }
26
- /** Describes context blocks. */
27
- export interface ContextBlocks {
28
- groupMetadata?: EnrichedConversationMeta;
29
- crossConversation?: CrossConversationEntry[];
30
- crossConversationMessages?: CrossConvMessage[];
31
- }
32
- /** Describes enriched inbound message. */
33
- export interface EnrichedInboundMessage {
34
- id: string;
35
- conversationId: ConversationId;
36
- sender: EnrichedSender;
37
- /** Text parts joined with newlines. Non-text parts dropped. */
38
- text: string;
39
- isFromMe: boolean;
40
- createdAt: string;
41
- conversationMeta?: EnrichedConversationMeta;
42
- contextBlocks: ContextBlocks;
43
- /**
44
- * Present when multiple queued messages from the same conversation were
45
- * coalesced into this single turn. Includes the primary message first.
46
- */
47
- coalescedMessages?: ReadonlyArray<{
48
- id: string;
49
- sender: EnrichedSender;
50
- text: string;
51
- createdAt: string;
52
- }>;
53
- }
54
- /** The subset of MoltZapService that MoltZapChannelCore needs. */
55
- export interface ChannelService {
56
- readonly ownAgentId?: string;
57
- on(event: "message", handler: (payload: {
58
- message: Message;
59
- }) => void): void;
60
- on(event: "disconnect", handler: () => void): void;
61
- connect(): Effect.Effect<unknown, ServiceRpcError>;
62
- /**
63
- * Effectful teardown for scoped process owners, which need the service's
64
- * transports closed before the scope's release completes. Services that
65
- * only offer the fire-and-forget {@link ChannelService.close} omit it.
66
- */
67
- shutdown?(): Effect.Effect<void>;
68
- close(): void;
69
- send(conversationId: ConversationId, text: string): Effect.Effect<void, ServiceRpcError>;
70
- getConversation(convId: string): {
71
- type: string;
72
- name?: string;
73
- participants: string[];
74
- } | undefined;
75
- getAgentName(agentId: string): string | undefined;
76
- resolveAgentName(agentId: string): Effect.Effect<string>;
77
- peekContextEntries(currentConvId: string, opts?: {
78
- maxConversations?: number;
79
- maxMessagesPerConv?: number;
80
- }): {
81
- entries: CrossConversationEntry[];
82
- commit: () => void;
83
- };
84
- peekFullMessages(currentConvId: string): {
85
- messages: CrossConvMessage[];
86
- commit: () => void;
87
- };
88
- }
89
- /** Configures channel core. */
90
- export interface ChannelCoreOptions {
91
- service: ChannelService;
92
- /**
93
- * Wall-clock bound on one handler invocation. On expiry the turn is
94
- * abandoned and the consumer keeps draining.
95
- *
96
- * Unset means unbounded, which is the safe default for runtimes whose
97
- * turns legitimately run for minutes: nothing else can interrupt the
98
- * handler, so a bound that is too tight silently drops real work. The
99
- * cost of leaving it unset is that a hung handler stalls the serial
100
- * drain forever — set it for runtimes that can wedge.
101
- *
102
- * The bound covers the handler only. Enrichment and
103
- * {@link ChannelCoreOptions.inboundInterceptor} run outside it.
104
- */
105
- turnTimeoutMs?: number;
106
- /**
107
- * Endpoint-side gate consulted once per coalesced turn before the selected
108
- * handler. The enriched path performs enrichment before the gate; the raw
109
- * path deliberately does not enrich. Unset is passthrough.
110
- */
111
- inboundInterceptor?: InboundInterceptor;
112
- }
113
- /**
114
- * Handler invoked for every enriched inbound message. Returns an Effect so the
115
- * error channel is part of the type — callers fail with a tagged error and the
116
- * consumer fiber logs it instead of dropping it on the floor like a Promise
117
- * rejection would.
118
- */
119
- export type InboundHandler<E = unknown> = (msg: EnrichedInboundMessage) => Effect.Effect<void, E>;
120
- /**
121
- * Handler for one coalesced raw inbound turn. The existing Message values are
122
- * delivered in arrival order after the inbound interceptor admits the batch.
123
- * Raw delivery does not enrich messages or read and commit presentation
124
- * context.
125
- */
126
- export type RawInboundHandler<E = unknown> = (messages: readonly Message[]) => Effect.Effect<void, E>;
127
- /**
128
- * Verdict an {@link InboundInterceptor} returns for one coalesced turn.
129
- *
130
- * The union is closed at deliver and drop on purpose: there is no hold or
131
- * delay verdict. An interceptor is an Effect, so pacing is expressed by
132
- * suspending inside it — an ambient Clock sleep, a semaphore, a gate the
133
- * embedder opens later — and the verdict says only whether the turn runs. A
134
- * hold verdict would ask the core to park this turn and start the next one,
135
- * which is the multi-turn concurrency the single consumer fiber exists to
136
- * prevent.
137
- */
138
- export type InboundInterceptDecision = {
139
- readonly _tag: "deliver";
140
- } | {
141
- readonly _tag: "drop";
142
- readonly reason?: string;
143
- };
144
- /**
145
- * Gate the embedder installs between coalescing and the selected handler. The
146
- * enriched handler path performs enrichment before consulting the gate; the
147
- * raw handler path does not enrich. The gate receives the newest message of
148
- * the coalesced batch — a gate deciding whether a turn is still worth running
149
- * cares about the latest thing said — and its verdict governs the whole batch.
150
- *
151
- * It runs on the single consumer fiber, so suspending inside it delays this
152
- * turn and every message queued behind it, and `turnTimeoutMs` does not bound
153
- * that suspension. An interceptor that never resumes stalls the drain
154
- * permanently.
155
- *
156
- * A defect, a failure, or a synchronous throw delivers. An embedder bug in a
157
- * gate must not silently black-hole a production channel: a channel that
158
- * over-delivers announces itself, one that has gone quiet looks like a network
159
- * problem for hours.
160
- */
161
- export type InboundInterceptor = (message: Message) => Effect.Effect<InboundInterceptDecision>;
162
- /**
163
- * Wraps a `MoltZapService` with one-turn-at-a-time inbound delivery and a send
164
- * helper. Adapter handlers receive enriched messages. A daemon handler may
165
- * instead receive the admitted coalesced raw Message batch. One core per
166
- * service — `getContextEntries()` is side-effectful (advances
167
- * per-conversation markers), so a second core would consume entries the first
168
- * expected.
169
- *
170
- * Turn-taking is entirely endpoint-local: the server delivers every message
171
- * it accepts, and this core decides when the runtime sees them.
172
- *
173
- * Inbound path from wire bytes to user handler:.
174
- *
175
- * ```mermaid
176
- * sequenceDiagram
177
- * participant server
178
- * participant ws as MoltZapAgentClient
179
- * participant svc as MoltZapService
180
- * participant core as MoltZapChannelCore
181
- * participant raw as RawInboundHandler
182
- * participant enriched as InboundHandler
183
- *
184
- * server->>ws: agent/message/received notification
185
- * ws->>svc: subscribers.dispatch — fanout(message)
186
- * svc->>core: message listener
187
- * Note over core: dedup via recordMessageIdIfNew, drop when stopped or no handler is installed, then Queue.unsafeOffer(inboundQueue, message)
188
- * Note over core: consumer fiber — Queue.take
189
- * Note over core: takeCoalescedConversationMessages drains same-conv backlog into one turn
190
- * alt raw daemon handler
191
- * Note over core: inboundInterceptor — deliver or drop this batch
192
- * core->>raw: rawInboundHandler(messages)
193
- * raw-->>core: Effect.void
194
- * else enriched adapter handler
195
- * Note over core: enrichMessage — sender name, conversation, context entries
196
- * Note over core: inboundInterceptor — deliver or drop this turn
197
- * core->>enriched: inboundHandler(enriched)
198
- * enriched-->>core: Effect.void
199
- * Note over core: completed handler commits presentation context
200
- * end
201
- * Note over core: handler exceeds turnTimeoutMs — turn abandoned, drain continues
202
- * ```
203
- *
204
- * The single consumer fiber awaits the handler inline, so at most one turn
205
- * runs at a time and messages that arrive mid-turn wait in the queue.
206
- */
207
- export declare class MoltZapChannelCore {
208
- private readonly service;
209
- private readonly turnTimeoutMs?;
210
- private readonly inboundInterceptor?;
211
- private connected;
212
- private stopped;
213
- private inboundHandler;
214
- /**
215
- * Inbound messages with an installed handler enqueue synchronously; a single
216
- * forked consumer fiber serialises delivery so handlers execute
217
- * one-at-a-time in arrival order.
218
- */
219
- private readonly inboundQueue;
220
- private readonly consumerFiber;
221
- private readonly disconnectHandlers;
222
- constructor(opts: ChannelCoreOptions);
223
- private registerMessageListener;
224
- private startConsumerFiber;
225
- private logInboundFailure;
226
- private registerConnectionListeners;
227
- /**
228
- * Replaces any previous handler.
229
- * @param handler Handler invoked for matching requests.
230
- */
231
- onInbound<E>(handler: InboundHandler<E>): void;
232
- /**
233
- * Replaces any previous handler with a raw coalesced-turn handler. The
234
- * admitted batch passes the interceptor and reaches the handler without
235
- * enrichment or presentation-context commits.
236
- * @param handler Handler invoked for each admitted raw batch.
237
- */
238
- onRawInbound<E>(handler: RawInboundHandler<E>): void;
239
- onDisconnect(handler: () => void): void;
240
- private fanout;
241
- connect(): Effect.Effect<void, ServiceRpcError>;
242
- /**
243
- * Tear the channel down, resolving only once the service's own transports
244
- * are closed. A scoped owner releases this before its process exits, so
245
- * fire-and-forget teardown would leave sockets open past the scope.
246
- *
247
- * Service shutdown runs concurrently with interrupting the consumer fiber
248
- * because an in-flight turn's finalizer can take arbitrarily long. Awaiting
249
- * the interrupt first would hold the transports open for exactly as long as
250
- * that finalizer runs.
251
- * @returns Completion of the channel-owned teardown.
252
- */
253
- disconnect(): Effect.Effect<void>;
254
- isConnected(): boolean;
255
- /**
256
- * Reply into a conversation.
257
- * @param conversationId Value supplied to the operation.
258
- * @param text Text to process.
259
- * @returns The send result.
260
- */
261
- sendReply(conversationId: ConversationId, text: string): Effect.Effect<void, ServiceRpcError>;
262
- private runInboundTurn;
263
- /**
264
- * Consult the interceptor for this turn, if one is installed.
265
- * @param messages The coalesced batch, primary first.
266
- * @returns Whether the handler runs for this batch.
267
- */
268
- private interceptTurn;
269
- /**
270
- * Apply a verdict, logging the drops at debug so a quiet channel can be
271
- * traced back to its gate.
272
- * @param newest Message the interceptor judged.
273
- * @param decision Verdict for the whole coalesced batch.
274
- * @returns Whether the handler runs.
275
- */
276
- private applyInterceptDecision;
277
- private logInterceptorFailure;
278
- /**
279
- * Await the user handler, bounded by `turnTimeoutMs` when it is set.
280
- * @param handler Installed inbound handler.
281
- * @param input Value delivered to the selected handler.
282
- * @param primary Message that opened this turn.
283
- * @returns Whether the handler ran to completion.
284
- */
285
- private awaitHandlerTurn;
286
- /**
287
- * Drain every queued message for the primary's conversation into one turn,
288
- * leaving other conversations queued in arrival order. Coalescing keeps a
289
- * burst in one conversation from costing one turn per message.
290
- * @param primary Message that opened this turn.
291
- * @returns The messages belonging to this turn, primary first.
292
- */
293
- private takeCoalescedConversationMessages;
294
- /**
295
- * Stateless enrichment helper. Falls back to `sender.id` if
296
- * `resolveAgentName` throws (e.g. Service not yet connected).
297
- * @param service Value supplied to the operation.
298
- * @param messageOrMessages Value supplied to the operation.
299
- * @returns The enriched message and its context-commit callback.
300
- */
301
- static enrichMessage(service: ChannelService, messageOrMessages: Message | readonly Message[]): Effect.Effect<{
302
- enriched: EnrichedInboundMessage;
303
- commitContext?: () => void;
304
- }>;
305
- }
306
- //# sourceMappingURL=channel-core.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"channel-core.d.ts","sourceRoot":"","sources":["../src/channel-core.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAA0B,MAAM,EAAwB,MAAM,QAAQ,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EAChB,MAAM,cAAc,CAAC;AAEtB,iFAAiF;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,iCAAiC;AACjC,UAAU,cAAc;I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C,iBAAiB;IAYzB,OAAO,CAAC,2BAA2B;IAOnC;;;OAGG;IACH,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAE7C;IAED;;;;;OAKG;IACH,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,IAAI,CAEnD;IAED,YAAY,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CAEtC;IAED,OAAO,CAAC,MAAM;IAed,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,CAkB9C;IAED;;;;;;;;;;OAUG;IACH,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAoBhC;IAED,WAAW,IAAI,OAAO,CAErB;IAED;;;;;OAKG;IACH,SAAS,CACP,cAAc,EAAE,cAAc,EAC9B,IAAI,EAAE,MAAM,GACX,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,CAEtC;IAED,OAAO,CAAC,cAAc;IAkCtB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IA4BrB;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB;IAiB9B,OAAO,CAAC,qBAAqB;IAe7B;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IA+BxB;;;;;;OAMG;IACH,OAAO,CAAC,iCAAiC;IAuBzC;;;;;;OAMG;IACH,MAAM,CAAC,aAAa,CAClB,OAAO,EAAE,cAAc,EACvB,iBAAiB,EAAE,OAAO,GAAG,SAAS,OAAO,EAAE,GAC9C,MAAM,CAAC,MAAM,CAAC;QACf,QAAQ,EAAE,sBAAsB,CAAC;QACjC,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;KAC5B,CAAC,CAED;CACF"}
@@ -1,365 +0,0 @@
1
- /**
2
- * Channel core: serialized inbound turn delivery over a MoltZapService.
3
- * Owns the inbound queue, same-conversation coalescing, the interceptor
4
- * gate, the per-turn timeout, and channel teardown. Enriched adapter delivery
5
- * uses channel-core-enrichment.ts; raw daemon delivery receives the coalesced
6
- * Message batch without reading or committing presentation context.
7
- */
8
- import { Cause, Chunk, Duration, Effect, Fiber, Option, Queue } from "effect";
9
- import { enrichChannelMessage } from "./channel-core-enrichment.js";
10
- /** Projects MCP-reconstructed context through the channel-owned presentation. */
11
- export { projectHarnessTurn } from "./channel-core-enrichment.js";
12
- function errorSummary(err) {
13
- if (err instanceof Error) {
14
- return {
15
- errorName: err.name,
16
- errorMessage: err.message,
17
- errorStack: err.stack,
18
- };
19
- }
20
- return {
21
- errorValue: String(err),
22
- };
23
- }
24
- function effectLogDebug(message, annotations) {
25
- return Effect.logDebug(message).pipe(Effect.annotateLogs(annotations));
26
- }
27
- function effectLogWarning(message, annotations) {
28
- return Effect.logWarning(message).pipe(Effect.annotateLogs(annotations));
29
- }
30
- function effectLogError(message, annotations) {
31
- return Effect.logError(message).pipe(Effect.annotateLogs(annotations));
32
- }
33
- function runBackgroundLog(effect) {
34
- Effect.runFork(effect);
35
- }
36
- /**
37
- * Wraps a `MoltZapService` with one-turn-at-a-time inbound delivery and a send
38
- * helper. Adapter handlers receive enriched messages. A daemon handler may
39
- * instead receive the admitted coalesced raw Message batch. One core per
40
- * service — `getContextEntries()` is side-effectful (advances
41
- * per-conversation markers), so a second core would consume entries the first
42
- * expected.
43
- *
44
- * Turn-taking is entirely endpoint-local: the server delivers every message
45
- * it accepts, and this core decides when the runtime sees them.
46
- *
47
- * Inbound path from wire bytes to user handler:.
48
- *
49
- * ```mermaid
50
- * sequenceDiagram
51
- * participant server
52
- * participant ws as MoltZapAgentClient
53
- * participant svc as MoltZapService
54
- * participant core as MoltZapChannelCore
55
- * participant raw as RawInboundHandler
56
- * participant enriched as InboundHandler
57
- *
58
- * server->>ws: agent/message/received notification
59
- * ws->>svc: subscribers.dispatch — fanout(message)
60
- * svc->>core: message listener
61
- * Note over core: dedup via recordMessageIdIfNew, drop when stopped or no handler is installed, then Queue.unsafeOffer(inboundQueue, message)
62
- * Note over core: consumer fiber — Queue.take
63
- * Note over core: takeCoalescedConversationMessages drains same-conv backlog into one turn
64
- * alt raw daemon handler
65
- * Note over core: inboundInterceptor — deliver or drop this batch
66
- * core->>raw: rawInboundHandler(messages)
67
- * raw-->>core: Effect.void
68
- * else enriched adapter handler
69
- * Note over core: enrichMessage — sender name, conversation, context entries
70
- * Note over core: inboundInterceptor — deliver or drop this turn
71
- * core->>enriched: inboundHandler(enriched)
72
- * enriched-->>core: Effect.void
73
- * Note over core: completed handler commits presentation context
74
- * end
75
- * Note over core: handler exceeds turnTimeoutMs — turn abandoned, drain continues
76
- * ```
77
- *
78
- * The single consumer fiber awaits the handler inline, so at most one turn
79
- * runs at a time and messages that arrive mid-turn wait in the queue.
80
- */
81
- export class MoltZapChannelCore {
82
- service;
83
- turnTimeoutMs;
84
- inboundInterceptor;
85
- connected = false;
86
- // Terminal stop: disconnect() interrupts the sole consumer fiber and it is
87
- // never restarted, while the service deliberately keeps message listeners
88
- // registered across close()/connect() cycles. Without this flag a
89
- // reconnected service would keep offering inbound messages into a queue
90
- // nothing drains — unbounded growth and silent non-delivery. Stopped means
91
- // stopped: inbound observed after disconnect() is dropped at the listener.
92
- stopped = false;
93
- inboundHandler = null;
94
- /**
95
- * Inbound messages with an installed handler enqueue synchronously; a single
96
- * forked consumer fiber serialises delivery so handlers execute
97
- * one-at-a-time in arrival order.
98
- */
99
- inboundQueue = Effect.runSync(Queue.unbounded());
100
- consumerFiber;
101
- disconnectHandlers = [];
102
- constructor(opts) {
103
- this.service = opts.service;
104
- if (opts.turnTimeoutMs !== undefined) {
105
- this.turnTimeoutMs = opts.turnTimeoutMs;
106
- }
107
- if (opts.inboundInterceptor !== undefined) {
108
- this.inboundInterceptor = opts.inboundInterceptor;
109
- }
110
- this.registerMessageListener();
111
- this.consumerFiber = this.startConsumerFiber();
112
- this.registerConnectionListeners();
113
- }
114
- registerMessageListener() {
115
- this.service.on("message", ({ message }) => {
116
- // A core with no handler — a daemon that owns the connection without
117
- // running a turn loop — observes messages it will never deliver.
118
- // Dropping here keeps the queue from holding work nothing consumes, and
119
- // makes the pre-registration window a definite drop rather than a race
120
- // between the consumer fiber and the embedder's onInbound call.
121
- if (this.stopped || this.inboundHandler === null) {
122
- return;
123
- }
124
- Queue.unsafeOffer(this.inboundQueue, message);
125
- });
126
- }
127
- startConsumerFiber() {
128
- const consumer = Effect.forever(Queue.take(this.inboundQueue).pipe(Effect.flatMap((message) => this.runInboundTurn(message).pipe(Effect.catchAllCause((cause) => this.logInboundFailure(message, cause))))));
129
- return Effect.runFork(consumer);
130
- }
131
- logInboundFailure(message, cause) {
132
- return effectLogError("MoltZapChannelCore: inbound handler failed", {
133
- messageId: message.id,
134
- conversationId: message.conversationId,
135
- causePretty: Cause.pretty(cause),
136
- ...errorSummary(Cause.squash(cause)),
137
- });
138
- }
139
- registerConnectionListeners() {
140
- this.service.on("disconnect", () => {
141
- this.connected = false;
142
- this.fanout(this.disconnectHandlers, "disconnect");
143
- });
144
- }
145
- /**
146
- * Replaces any previous handler.
147
- * @param handler Handler invoked for matching requests.
148
- */
149
- onInbound(handler) {
150
- this.inboundHandler = { _tag: "enriched", handler };
151
- }
152
- /**
153
- * Replaces any previous handler with a raw coalesced-turn handler. The
154
- * admitted batch passes the interceptor and reaches the handler without
155
- * enrichment or presentation-context commits.
156
- * @param handler Handler invoked for each admitted raw batch.
157
- */
158
- onRawInbound(handler) {
159
- this.inboundHandler = { _tag: "raw", handler };
160
- }
161
- onDisconnect(handler) {
162
- this.disconnectHandlers.push(handler);
163
- }
164
- fanout(handlers, label) {
165
- for (const h of handlers) {
166
- try {
167
- h();
168
- }
169
- catch (err) {
170
- runBackgroundLog(effectLogError(`MoltZapChannelCore: ${label} handler threw`, {
171
- err,
172
- label,
173
- }));
174
- }
175
- }
176
- }
177
- connect() {
178
- // A stopped core has no consumer fiber and its listener drops every
179
- // inbound message; reporting a successful connect here would hand the
180
- // embedder a healthy-looking channel that is permanently deaf. Stopped
181
- // is terminal — reconnecting means constructing a new core.
182
- if (this.stopped) {
183
- return Effect.dieMessage("MoltZapChannelCore.connect called after disconnect; a stopped core cannot be reconnected — construct a new core");
184
- }
185
- return this.service.connect().pipe(Effect.tap(() => Effect.sync(() => {
186
- this.connected = true;
187
- })), Effect.asVoid);
188
- }
189
- /**
190
- * Tear the channel down, resolving only once the service's own transports
191
- * are closed. A scoped owner releases this before its process exits, so
192
- * fire-and-forget teardown would leave sockets open past the scope.
193
- *
194
- * Service shutdown runs concurrently with interrupting the consumer fiber
195
- * because an in-flight turn's finalizer can take arbitrarily long. Awaiting
196
- * the interrupt first would hold the transports open for exactly as long as
197
- * that finalizer runs.
198
- * @returns Completion of the channel-owned teardown.
199
- */
200
- disconnect() {
201
- return Effect.gen(function* () {
202
- this.connected = false;
203
- this.stopped = true;
204
- // Interrupt the consumer fiber so any queued inbound messages are
205
- // dropped rather than delivered after the channel is torn down.
206
- const stopConsumer = Fiber.interrupt(this.consumerFiber);
207
- const shutdown = this.service.shutdown?.();
208
- if (shutdown === undefined) {
209
- this.service.close();
210
- yield* stopConsumer;
211
- return;
212
- }
213
- yield* Effect.all([stopConsumer, shutdown], {
214
- concurrency: 2,
215
- discard: true,
216
- });
217
- }.bind(this));
218
- }
219
- isConnected() {
220
- return this.connected;
221
- }
222
- /**
223
- * Reply into a conversation.
224
- * @param conversationId Value supplied to the operation.
225
- * @param text Text to process.
226
- * @returns The send result.
227
- */
228
- sendReply(conversationId, text) {
229
- return this.service.send(conversationId, text);
230
- }
231
- runInboundTurn(primary) {
232
- return Effect.gen(function* () {
233
- const messages = yield* this.takeCoalescedConversationMessages(primary);
234
- const registered = this.inboundHandler;
235
- if (registered === null) {
236
- return;
237
- }
238
- if (registered._tag === "raw") {
239
- if (!(yield* this.interceptTurn(messages))) {
240
- return;
241
- }
242
- yield* this.awaitHandlerTurn(registered.handler, messages, primary);
243
- return;
244
- }
245
- const { enriched, commitContext } = yield* MoltZapChannelCore.enrichMessage(this.service, messages);
246
- if (!(yield* this.interceptTurn(messages))) {
247
- return;
248
- }
249
- const completed = yield* this.awaitHandlerTurn(registered.handler, enriched, primary);
250
- // Context markers advance only for a turn the handler finished. A
251
- // dropped or abandoned one leaves its entries for the next turn.
252
- if (completed && commitContext) {
253
- commitContext();
254
- }
255
- }.bind(this));
256
- }
257
- /**
258
- * Consult the interceptor for this turn, if one is installed.
259
- * @param messages The coalesced batch, primary first.
260
- * @returns Whether the handler runs for this batch.
261
- */
262
- interceptTurn(messages) {
263
- const interceptor = this.inboundInterceptor;
264
- if (interceptor === undefined) {
265
- return Effect.succeed(true);
266
- }
267
- const newest =
268
- /* Safe because a coalesced batch always holds at least its primary. */ messages[messages.length - 1];
269
- // Suspended so an interceptor that throws before returning its Effect
270
- // becomes a defect this pipeline can fail open on, not one the consumer
271
- // fiber catches after the turn is already lost.
272
- return Effect.suspend(() => interceptor(newest)).pipe(Effect.flatMap((decision) => this.applyInterceptDecision(newest, decision)), Effect.catchAllCause((cause) =>
273
- // Interruption is teardown, not an interceptor bug: re-raise it so a
274
- // disconnected channel stops draining instead of delivering the turn.
275
- Cause.isInterruptedOnly(cause)
276
- ? Effect.failCause(cause)
277
- : this.logInterceptorFailure(newest, cause).pipe(Effect.as(true))));
278
- }
279
- /**
280
- * Apply a verdict, logging the drops at debug so a quiet channel can be
281
- * traced back to its gate.
282
- * @param newest Message the interceptor judged.
283
- * @param decision Verdict for the whole coalesced batch.
284
- * @returns Whether the handler runs.
285
- */
286
- applyInterceptDecision(newest, decision) {
287
- if (decision._tag === "deliver") {
288
- return Effect.succeed(true);
289
- }
290
- return effectLogDebug("MoltZapChannelCore: inbound turn dropped by interceptor", {
291
- messageId: newest.id,
292
- conversationId: newest.conversationId,
293
- ...(decision.reason !== undefined ? { reason: decision.reason } : {}),
294
- }).pipe(Effect.as(false));
295
- }
296
- logInterceptorFailure(newest, cause) {
297
- return effectLogWarning("MoltZapChannelCore: inbound interceptor failed, delivering anyway", {
298
- messageId: newest.id,
299
- conversationId: newest.conversationId,
300
- causePretty: Cause.pretty(cause),
301
- ...errorSummary(Cause.squash(cause)),
302
- });
303
- }
304
- /**
305
- * Await the user handler, bounded by `turnTimeoutMs` when it is set.
306
- * @param handler Installed inbound handler.
307
- * @param input Value delivered to the selected handler.
308
- * @param primary Message that opened this turn.
309
- * @returns Whether the handler ran to completion.
310
- */
311
- awaitHandlerTurn(handler, input, primary) {
312
- // The handler is user code returning an Effect — yield it directly so its
313
- // typed error channel propagates to the consumer fiber, which logs and
314
- // continues. Awaiting it inline preserves arrival-order delivery.
315
- const turn = handler(input);
316
- const timeoutMs = this.turnTimeoutMs;
317
- if (timeoutMs === undefined) {
318
- return turn.pipe(Effect.as(true));
319
- }
320
- return turn.pipe(Effect.timeoutOption(Duration.millis(timeoutMs)), Effect.tap((finished) => Option.isNone(finished)
321
- ? effectLogWarning("MoltZapChannelCore: inbound turn abandoned after timeout", {
322
- messageId: primary.id,
323
- conversationId: primary.conversationId,
324
- timeoutMs,
325
- })
326
- : Effect.void), Effect.map(Option.isSome));
327
- }
328
- /**
329
- * Drain every queued message for the primary's conversation into one turn,
330
- * leaving other conversations queued in arrival order. Coalescing keeps a
331
- * burst in one conversation from costing one turn per message.
332
- * @param primary Message that opened this turn.
333
- * @returns The messages belonging to this turn, primary first.
334
- */
335
- takeCoalescedConversationMessages(primary) {
336
- return Effect.sync(() => {
337
- const queued = Chunk.toReadonlyArray(Effect.runSync(Queue.takeAll(this.inboundQueue)));
338
- const sameConversation = [primary];
339
- const remaining = [];
340
- for (const queuedMessage of queued) {
341
- if (queuedMessage.conversationId === primary.conversationId) {
342
- sameConversation.push(queuedMessage);
343
- }
344
- else {
345
- remaining.push(queuedMessage);
346
- }
347
- }
348
- for (const remainingMessage of remaining) {
349
- Queue.unsafeOffer(this.inboundQueue, remainingMessage);
350
- }
351
- return sameConversation;
352
- });
353
- }
354
- /**
355
- * Stateless enrichment helper. Falls back to `sender.id` if
356
- * `resolveAgentName` throws (e.g. Service not yet connected).
357
- * @param service Value supplied to the operation.
358
- * @param messageOrMessages Value supplied to the operation.
359
- * @returns The enriched message and its context-commit callback.
360
- */
361
- static enrichMessage(service, messageOrMessages) {
362
- return enrichChannelMessage(service, messageOrMessages);
363
- }
364
- }
365
- //# sourceMappingURL=channel-core.js.map