@agentshouse/mdruntime 0.1.0-cd0f0e6405606 → 0.1.0-cd179f56b78b5

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 (436) hide show
  1. package/README.md +24 -19
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +328 -0
  5. package/dist/act-lanes.d.ts +30 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +225 -0
  8. package/dist/actions.d.ts +26 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +341 -0
  11. package/dist/adapter.d.ts +323 -130
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +6 -10
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +35 -41
  16. package/dist/{binary.d.ts → attachment.d.ts} +8 -9
  17. package/dist/attachment.d.ts.map +1 -0
  18. package/dist/attachment.js +15 -0
  19. package/dist/authored.d.ts +88 -0
  20. package/dist/authored.d.ts.map +1 -0
  21. package/dist/authored.js +345 -0
  22. package/dist/bootstrap.d.ts +30 -11
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +309 -113
  25. package/dist/cell.d.ts +6 -0
  26. package/dist/cell.d.ts.map +1 -0
  27. package/dist/cell.js +9 -0
  28. package/dist/chain.d.ts +12 -0
  29. package/dist/chain.d.ts.map +1 -0
  30. package/dist/chain.js +67 -0
  31. package/dist/change-set.d.ts +13 -16
  32. package/dist/change-set.d.ts.map +1 -1
  33. package/dist/change-set.js +17 -89
  34. package/dist/change.d.ts +36 -1
  35. package/dist/change.d.ts.map +1 -1
  36. package/dist/change.js +17 -3
  37. package/dist/chat-types.d.ts +3 -0
  38. package/dist/chat-types.d.ts.map +1 -0
  39. package/dist/chat-types.js +11 -0
  40. package/dist/client.d.ts +55 -29
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +89 -26
  43. package/dist/collection.d.ts +34 -22
  44. package/dist/collection.d.ts.map +1 -1
  45. package/dist/collection.js +57 -350
  46. package/dist/column.d.ts +5 -0
  47. package/dist/column.d.ts.map +1 -0
  48. package/dist/column.js +9 -0
  49. package/dist/compile.d.ts +19 -0
  50. package/dist/compile.d.ts.map +1 -0
  51. package/dist/compile.js +755 -0
  52. package/dist/connection.d.ts +7 -137
  53. package/dist/connection.d.ts.map +1 -1
  54. package/dist/connection.js +114 -3613
  55. package/dist/context.d.ts +2 -0
  56. package/dist/context.d.ts.map +1 -0
  57. package/dist/{chat/context.js → context.js} +2 -5
  58. package/dist/conversation-live.d.ts +150 -0
  59. package/dist/conversation-live.d.ts.map +1 -0
  60. package/dist/conversation-live.js +260 -0
  61. package/dist/conversation-row.d.ts +52 -0
  62. package/dist/conversation-row.d.ts.map +1 -0
  63. package/dist/conversation-row.js +76 -0
  64. package/dist/conversation.d.ts +86 -51
  65. package/dist/conversation.d.ts.map +1 -1
  66. package/dist/conversation.js +1048 -805
  67. package/dist/declaration.d.ts +10 -0
  68. package/dist/declaration.d.ts.map +1 -0
  69. package/dist/declaration.js +24 -0
  70. package/dist/digest.d.ts +7 -0
  71. package/dist/digest.d.ts.map +1 -0
  72. package/dist/digest.js +113 -0
  73. package/dist/discovery.d.ts +12 -0
  74. package/dist/discovery.d.ts.map +1 -0
  75. package/dist/discovery.js +175 -0
  76. package/dist/download.d.ts +6 -0
  77. package/dist/download.d.ts.map +1 -0
  78. package/dist/download.js +42 -0
  79. package/dist/durability.d.ts +21 -4
  80. package/dist/durability.d.ts.map +1 -1
  81. package/dist/durability.js +12 -0
  82. package/dist/entry.d.ts +29 -2
  83. package/dist/entry.d.ts.map +1 -1
  84. package/dist/entry.js +121 -40
  85. package/dist/expectation.d.ts +26 -13
  86. package/dist/expectation.d.ts.map +1 -1
  87. package/dist/expectation.js +72 -19
  88. package/dist/failure.d.ts +3 -0
  89. package/dist/failure.d.ts.map +1 -1
  90. package/dist/failure.js +8 -0
  91. package/dist/figures.d.ts +49 -0
  92. package/dist/figures.d.ts.map +1 -0
  93. package/dist/figures.js +199 -0
  94. package/dist/file.d.ts +2 -19
  95. package/dist/file.d.ts.map +1 -1
  96. package/dist/file.js +8 -122
  97. package/dist/holdings.d.ts +29 -0
  98. package/dist/holdings.d.ts.map +1 -0
  99. package/dist/holdings.js +95 -0
  100. package/dist/host.d.ts +25 -8
  101. package/dist/host.d.ts.map +1 -1
  102. package/dist/host.js +161 -57
  103. package/dist/house-query.d.ts +24 -0
  104. package/dist/house-query.d.ts.map +1 -0
  105. package/dist/house-query.js +102 -0
  106. package/dist/identity.d.ts +1 -3
  107. package/dist/identity.d.ts.map +1 -1
  108. package/dist/identity.js +1 -7
  109. package/dist/index.d.ts +50 -17
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +25 -5
  112. package/dist/install.d.ts +60 -0
  113. package/dist/install.d.ts.map +1 -0
  114. package/dist/install.js +537 -0
  115. package/dist/lifecycle.d.ts +7 -0
  116. package/dist/lifecycle.d.ts.map +1 -0
  117. package/dist/lifecycle.js +292 -0
  118. package/dist/listing.d.ts +60 -0
  119. package/dist/listing.d.ts.map +1 -0
  120. package/dist/listing.js +168 -0
  121. package/dist/live.d.ts +39 -0
  122. package/dist/live.d.ts.map +1 -0
  123. package/dist/live.js +223 -0
  124. package/dist/loaded.d.ts +7 -0
  125. package/dist/loaded.d.ts.map +1 -0
  126. package/dist/loaded.js +46 -0
  127. package/dist/locks.d.ts +7 -0
  128. package/dist/locks.d.ts.map +1 -0
  129. package/dist/locks.js +34 -0
  130. package/dist/lost.d.ts +5 -0
  131. package/dist/lost.d.ts.map +1 -0
  132. package/dist/lost.js +49 -0
  133. package/dist/media.d.ts +24 -0
  134. package/dist/media.d.ts.map +1 -0
  135. package/dist/media.js +365 -0
  136. package/dist/memory.d.ts +22 -8
  137. package/dist/memory.d.ts.map +1 -1
  138. package/dist/memory.js +317 -123
  139. package/dist/messages.d.ts +67 -0
  140. package/dist/messages.d.ts.map +1 -0
  141. package/dist/messages.js +180 -0
  142. package/dist/modal.d.ts +2 -0
  143. package/dist/modal.d.ts.map +1 -0
  144. package/dist/modal.js +11 -0
  145. package/dist/model.d.ts +15 -15
  146. package/dist/model.d.ts.map +1 -1
  147. package/dist/model.js +11 -22
  148. package/dist/models.d.ts +10 -0
  149. package/dist/models.d.ts.map +1 -0
  150. package/dist/models.js +153 -0
  151. package/dist/name.d.ts +3 -0
  152. package/dist/name.d.ts.map +1 -0
  153. package/dist/name.js +118 -0
  154. package/dist/observation.d.ts +40 -10
  155. package/dist/observation.d.ts.map +1 -1
  156. package/dist/observation.js +265 -44
  157. package/dist/online.d.ts +7 -0
  158. package/dist/online.d.ts.map +1 -0
  159. package/dist/online.js +29 -0
  160. package/dist/opened.d.ts +22 -0
  161. package/dist/opened.d.ts.map +1 -0
  162. package/dist/opened.js +107 -0
  163. package/dist/opening.d.ts +4 -0
  164. package/dist/opening.d.ts.map +1 -0
  165. package/dist/opening.js +71 -0
  166. package/dist/outcome.d.ts +68 -13
  167. package/dist/outcome.d.ts.map +1 -1
  168. package/dist/outcome.js +74 -5
  169. package/dist/overlay.d.ts +24 -12
  170. package/dist/overlay.d.ts.map +1 -1
  171. package/dist/overlay.js +165 -171
  172. package/dist/page-metadata.d.ts +8 -0
  173. package/dist/page-metadata.d.ts.map +1 -0
  174. package/dist/page-metadata.js +19 -0
  175. package/dist/parts.d.ts +6 -0
  176. package/dist/parts.d.ts.map +1 -0
  177. package/dist/parts.js +36 -0
  178. package/dist/paths.d.ts +2 -0
  179. package/dist/paths.d.ts.map +1 -1
  180. package/dist/paths.js +26 -0
  181. package/dist/preparation.d.ts +46 -0
  182. package/dist/preparation.d.ts.map +1 -0
  183. package/dist/preparation.js +344 -0
  184. package/dist/presence.d.ts +58 -0
  185. package/dist/presence.d.ts.map +1 -0
  186. package/dist/presence.js +231 -0
  187. package/dist/queries.d.ts +16 -0
  188. package/dist/queries.d.ts.map +1 -0
  189. package/dist/queries.js +330 -0
  190. package/dist/query.d.ts +23 -209
  191. package/dist/query.d.ts.map +1 -1
  192. package/dist/query.js +3 -493
  193. package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
  194. package/dist/questions.d.ts.map +1 -0
  195. package/dist/{chat/questions.js → questions.js} +14 -8
  196. package/dist/queue.d.ts +40 -0
  197. package/dist/queue.d.ts.map +1 -0
  198. package/dist/queue.js +480 -0
  199. package/dist/reach.d.ts +31 -11
  200. package/dist/reach.d.ts.map +1 -1
  201. package/dist/reach.js +451 -116
  202. package/dist/react.d.ts +27 -3
  203. package/dist/react.d.ts.map +1 -1
  204. package/dist/react.js +33 -1
  205. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  206. package/dist/read.d.ts.map +1 -0
  207. package/dist/{chat/read.js → read.js} +4 -0
  208. package/dist/readiness.d.ts +36 -21
  209. package/dist/readiness.d.ts.map +1 -1
  210. package/dist/readiness.js +20 -18
  211. package/dist/reads.d.ts +38 -10
  212. package/dist/reads.d.ts.map +1 -1
  213. package/dist/reads.js +174 -83
  214. package/dist/recovery.d.ts +6 -2
  215. package/dist/recovery.d.ts.map +1 -1
  216. package/dist/recovery.js +67 -9
  217. package/dist/refresh.d.ts +18 -15
  218. package/dist/refresh.d.ts.map +1 -1
  219. package/dist/refresh.js +145 -60
  220. package/dist/refusal.d.ts +5 -0
  221. package/dist/refusal.d.ts.map +1 -0
  222. package/dist/refusal.js +55 -0
  223. package/dist/replica.d.ts +45 -38
  224. package/dist/replica.d.ts.map +1 -1
  225. package/dist/replica.js +321 -207
  226. package/dist/retried.d.ts +30 -0
  227. package/dist/retried.d.ts.map +1 -0
  228. package/dist/retried.js +72 -0
  229. package/dist/room-draft.d.ts +56 -14
  230. package/dist/room-draft.d.ts.map +1 -1
  231. package/dist/room-draft.js +424 -126
  232. package/dist/room-drafts.d.ts +24 -0
  233. package/dist/room-drafts.d.ts.map +1 -0
  234. package/dist/room-drafts.js +222 -0
  235. package/dist/room-list.d.ts +10 -0
  236. package/dist/room-list.d.ts.map +1 -0
  237. package/dist/room-list.js +47 -0
  238. package/dist/rows.d.ts +40 -32
  239. package/dist/rows.d.ts.map +1 -1
  240. package/dist/rows.js +72 -123
  241. package/dist/run-tables.d.ts +25 -0
  242. package/dist/run-tables.d.ts.map +1 -0
  243. package/dist/run-tables.js +98 -0
  244. package/dist/running.d.ts +5 -0
  245. package/dist/running.d.ts.map +1 -0
  246. package/dist/running.js +10 -0
  247. package/dist/runs.d.ts +27 -0
  248. package/dist/runs.d.ts.map +1 -0
  249. package/dist/runs.js +92 -0
  250. package/dist/runtime.d.ts +37 -0
  251. package/dist/runtime.d.ts.map +1 -0
  252. package/dist/runtime.js +1 -0
  253. package/dist/save.d.ts +44 -50
  254. package/dist/save.d.ts.map +1 -1
  255. package/dist/save.js +666 -289
  256. package/dist/saves.d.ts +34 -0
  257. package/dist/saves.d.ts.map +1 -0
  258. package/dist/saves.js +463 -0
  259. package/dist/search.d.ts +12 -95
  260. package/dist/search.d.ts.map +1 -1
  261. package/dist/search.js +10 -266
  262. package/dist/seed.d.ts +11 -2
  263. package/dist/seed.d.ts.map +1 -1
  264. package/dist/seed.js +71 -1
  265. package/dist/selector.d.ts +3 -0
  266. package/dist/selector.d.ts.map +1 -0
  267. package/dist/selector.js +22 -0
  268. package/dist/shared.d.ts +5 -9
  269. package/dist/shared.d.ts.map +1 -1
  270. package/dist/shared.js +66 -121
  271. package/dist/shown.d.ts +35 -0
  272. package/dist/shown.d.ts.map +1 -0
  273. package/dist/shown.js +326 -0
  274. package/dist/socket/admission.d.ts +7 -0
  275. package/dist/socket/admission.d.ts.map +1 -0
  276. package/dist/socket/admission.js +39 -0
  277. package/dist/socket/answers.d.ts +6 -0
  278. package/dist/socket/answers.d.ts.map +1 -0
  279. package/dist/socket/answers.js +20 -0
  280. package/dist/socket/lanes.d.ts +28 -0
  281. package/dist/socket/lanes.d.ts.map +1 -0
  282. package/dist/socket/lanes.js +103 -0
  283. package/dist/socket/reads.d.ts +10 -0
  284. package/dist/socket/reads.d.ts.map +1 -0
  285. package/dist/socket/reads.js +31 -0
  286. package/dist/socket/session.d.ts +41 -0
  287. package/dist/socket/session.d.ts.map +1 -0
  288. package/dist/socket/session.js +26 -0
  289. package/dist/socket.d.ts +70 -0
  290. package/dist/socket.d.ts.map +1 -0
  291. package/dist/socket.js +172 -0
  292. package/dist/source.d.ts +78 -0
  293. package/dist/source.d.ts.map +1 -0
  294. package/dist/source.js +121 -0
  295. package/dist/status.d.ts +4 -5
  296. package/dist/status.d.ts.map +1 -1
  297. package/dist/status.js +3 -7
  298. package/dist/store/installs.d.ts +30 -0
  299. package/dist/store/installs.d.ts.map +1 -0
  300. package/dist/store/installs.js +40 -0
  301. package/dist/store/readiness.d.ts +11 -0
  302. package/dist/store/readiness.d.ts.map +1 -0
  303. package/dist/store/readiness.js +68 -0
  304. package/dist/store/records.d.ts +234 -0
  305. package/dist/store/records.d.ts.map +1 -0
  306. package/dist/store/records.js +474 -0
  307. package/dist/store/room-held.d.ts +8 -0
  308. package/dist/store/room-held.d.ts.map +1 -0
  309. package/dist/store/room-held.js +17 -0
  310. package/dist/store/rooms-shown.d.ts +8 -0
  311. package/dist/store/rooms-shown.d.ts.map +1 -0
  312. package/dist/store/rooms-shown.js +13 -0
  313. package/dist/store/space.d.ts +11 -0
  314. package/dist/store/space.d.ts.map +1 -0
  315. package/dist/store/space.js +41 -0
  316. package/dist/store/watchers.d.ts +17 -0
  317. package/dist/store/watchers.d.ts.map +1 -0
  318. package/dist/store/watchers.js +56 -0
  319. package/dist/store/writes.d.ts +24 -0
  320. package/dist/store/writes.d.ts.map +1 -0
  321. package/dist/store/writes.js +125 -0
  322. package/dist/store.d.ts +115 -163
  323. package/dist/store.d.ts.map +1 -1
  324. package/dist/store.js +166 -750
  325. package/dist/stored.d.ts +181 -0
  326. package/dist/stored.d.ts.map +1 -0
  327. package/dist/stored.js +807 -0
  328. package/dist/surface.d.ts +100 -0
  329. package/dist/surface.d.ts.map +1 -0
  330. package/dist/surface.js +258 -0
  331. package/dist/sync.d.ts +21 -0
  332. package/dist/sync.d.ts.map +1 -0
  333. package/dist/sync.js +557 -0
  334. package/dist/tables.d.ts +400 -0
  335. package/dist/tables.d.ts.map +1 -0
  336. package/dist/tables.js +520 -0
  337. package/dist/tallies.d.ts +18 -0
  338. package/dist/tallies.d.ts.map +1 -0
  339. package/dist/tallies.js +128 -0
  340. package/dist/transfer.d.ts +0 -5
  341. package/dist/transfer.d.ts.map +1 -1
  342. package/dist/turn.d.ts +2 -2
  343. package/dist/turn.d.ts.map +1 -1
  344. package/dist/turn.js +34 -23
  345. package/dist/validation.d.ts +31 -0
  346. package/dist/validation.d.ts.map +1 -0
  347. package/dist/validation.js +144 -0
  348. package/dist/windows.d.ts +1 -16
  349. package/dist/windows.d.ts.map +1 -1
  350. package/dist/windows.js +2 -79
  351. package/dist/wire.d.ts +99 -11
  352. package/dist/wire.d.ts.map +1 -1
  353. package/dist/wire.js +40 -13
  354. package/package.json +20 -20
  355. package/AGENTS.md +0 -299
  356. package/dist/attempt.d.ts +0 -16
  357. package/dist/attempt.d.ts.map +0 -1
  358. package/dist/attempt.js +0 -70
  359. package/dist/binary.d.ts.map +0 -1
  360. package/dist/binary.js +0 -8
  361. package/dist/chat/acts.d.ts +0 -33
  362. package/dist/chat/acts.d.ts.map +0 -1
  363. package/dist/chat/acts.js +0 -36
  364. package/dist/chat/context.d.ts +0 -3
  365. package/dist/chat/context.d.ts.map +0 -1
  366. package/dist/chat/earlier.d.ts +0 -10
  367. package/dist/chat/earlier.d.ts.map +0 -1
  368. package/dist/chat/earlier.js +0 -54
  369. package/dist/chat/input.d.ts +0 -9
  370. package/dist/chat/input.d.ts.map +0 -1
  371. package/dist/chat/input.js +0 -99
  372. package/dist/chat/kit.d.ts +0 -61
  373. package/dist/chat/kit.d.ts.map +0 -1
  374. package/dist/chat/kit.js +0 -123
  375. package/dist/chat/lasting.d.ts +0 -6
  376. package/dist/chat/lasting.d.ts.map +0 -1
  377. package/dist/chat/lasting.js +0 -19
  378. package/dist/chat/list.d.ts +0 -27
  379. package/dist/chat/list.d.ts.map +0 -1
  380. package/dist/chat/list.js +0 -99
  381. package/dist/chat/markdown.d.ts +0 -21
  382. package/dist/chat/markdown.d.ts.map +0 -1
  383. package/dist/chat/markdown.js +0 -246
  384. package/dist/chat/message.d.ts +0 -6
  385. package/dist/chat/message.d.ts.map +0 -1
  386. package/dist/chat/message.js +0 -192
  387. package/dist/chat/messages.d.ts +0 -22
  388. package/dist/chat/messages.d.ts.map +0 -1
  389. package/dist/chat/messages.js +0 -171
  390. package/dist/chat/name.d.ts +0 -6
  391. package/dist/chat/name.d.ts.map +0 -1
  392. package/dist/chat/name.js +0 -37
  393. package/dist/chat/opened.d.ts +0 -11
  394. package/dist/chat/opened.d.ts.map +0 -1
  395. package/dist/chat/opened.js +0 -17
  396. package/dist/chat/overlay.d.ts +0 -31
  397. package/dist/chat/overlay.d.ts.map +0 -1
  398. package/dist/chat/overlay.js +0 -97
  399. package/dist/chat/parts.d.ts +0 -57
  400. package/dist/chat/parts.d.ts.map +0 -1
  401. package/dist/chat/parts.js +0 -119
  402. package/dist/chat/pieces.d.ts +0 -62
  403. package/dist/chat/pieces.d.ts.map +0 -1
  404. package/dist/chat/pieces.js +0 -1110
  405. package/dist/chat/process.d.ts +0 -20
  406. package/dist/chat/process.d.ts.map +0 -1
  407. package/dist/chat/process.js +0 -32
  408. package/dist/chat/provider.d.ts +0 -63
  409. package/dist/chat/provider.d.ts.map +0 -1
  410. package/dist/chat/provider.js +0 -630
  411. package/dist/chat/question.d.ts +0 -9
  412. package/dist/chat/question.d.ts.map +0 -1
  413. package/dist/chat/question.js +0 -69
  414. package/dist/chat/questions.d.ts.map +0 -1
  415. package/dist/chat/read.d.ts.map +0 -1
  416. package/dist/chat/ready.d.ts +0 -34
  417. package/dist/chat/ready.d.ts.map +0 -1
  418. package/dist/chat/ready.js +0 -91
  419. package/dist/chat/steady.d.ts +0 -3
  420. package/dist/chat/steady.d.ts.map +0 -1
  421. package/dist/chat/steady.js +0 -26
  422. package/dist/chat/style.d.ts +0 -4
  423. package/dist/chat/style.d.ts.map +0 -1
  424. package/dist/chat/style.js +0 -302
  425. package/dist/chat.d.ts +0 -14
  426. package/dist/chat.d.ts.map +0 -1
  427. package/dist/chat.js +0 -8
  428. package/dist/fence.d.ts +0 -6
  429. package/dist/fence.d.ts.map +0 -1
  430. package/dist/fence.js +0 -10
  431. package/dist/log.d.ts +0 -5
  432. package/dist/log.d.ts.map +0 -1
  433. package/dist/log.js +0 -14
  434. package/dist/read-side.d.ts +0 -27
  435. package/dist/read-side.d.ts.map +0 -1
  436. package/dist/read-side.js +0 -824
package/README.md CHANGED
@@ -12,14 +12,14 @@ npm install @agentshouse/mdruntime
12
12
 
13
13
  ## Entries
14
14
 
15
- | Entry | For |
16
- | ------------------------------- | ----------------------------------------------------------- |
17
- | `@agentshouse/mdruntime/client` | The host's client: `connectMdRuntime(port)` |
18
- | `@agentshouse/mdruntime/host` | The host that serves a Runtime: `serveMdRuntime` |
19
- | `@agentshouse/mdruntime` | Shared types |
20
- | `@agentshouse/mdruntime/memory` | Tests: `createMemoryAdapter`, an in-memory Adapter |
21
- | `@agentshouse/mdruntime/react` | React over the client: `useObserve`, `useSave` |
22
- | `@agentshouse/mdruntime/chat` | The Chat: `Chat`, `mountChat`, its parts and `ChatProvider` |
15
+ | Entry | For |
16
+ | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
+ | `@agentshouse/mdruntime/client` | The host's client: `connectMdRuntime(port)` |
18
+ | `@agentshouse/mdruntime/host` | The host that serves a Runtime: `serveMdRuntime` |
19
+ | `@agentshouse/mdruntime` | Shared types |
20
+ | `@agentshouse/mdruntime/memory` | Tests: `createMemoryAdapter`, an in-memory Adapter |
21
+ | `@agentshouse/mdruntime/tables` | The host's database: `formatted` lays it out for a device format, keeping the Authored store's tables and creating any it lacks, and `answerRuntime` answers it |
22
+ | `@agentshouse/mdruntime/react` | React over the client: `useObserve`, `useSave`; `useExpected`, a reader of an expectation store; `useLane`, a reader of an act lane |
23
23
 
24
24
  ## Usage
25
25
 
@@ -33,21 +33,26 @@ const rooms = await runtime.rooms();
33
33
  const notes = await runtime.query({ types: ['note'], select: 'all', limit: 20 });
34
34
  ```
35
35
 
36
- `observe('storage-loss')` reports `null` or the stable code
37
- `storage-loss` when unsynchronized Room Drafts and Pending Changes were lost.
38
- The host supplies the user-facing wording.
36
+ `observe('storage-loss')` reports `null`, the stable code `storage-loss` when
37
+ unsynchronized Room Drafts and Pending Changes were lost, or `visit` while the host holds
38
+ the database in memory, which ends with the visit; the readiness `persistence` answer is then
39
+ `memory`. The host supplies the user-facing wording.
39
40
 
40
- Place the ready chat, themed by CSS custom properties, docked at a third of the
41
- window; outside React, `mountChat(element, { client: runtime })` places the same:
41
+ In House the bridge object the page holds as `window.houseBridge` places the Chat, which
42
+ House serves with the page: install and bundle nothing for it. Mount it in an element it
43
+ fills, where it lays out the User's chats by the element's width, themed by CSS custom
44
+ properties on that element, or as the Chat button, House's dot that opens it in a sheet:
42
45
 
43
- ```tsx
44
- import { Chat } from '@agentshouse/mdruntime/chat';
45
-
46
- <Chat client={runtime} width="1/3" showChats style={{ '--chat-accent': '#2a6cf0' }} />;
46
+ ```ts
47
+ const chat = await window.houseBridge.chat.mount(element, { conversation });
48
+ element.style.setProperty('--chat-accent', '#2a6cf0');
49
+ chat.update({ conversation: null, agent });
50
+ const button = await window.houseBridge.chat.mountButton({});
51
+ button.open({ agent });
47
52
  ```
48
53
 
49
- The rules an App's agent follows, including Local Query, Local Search, Room
50
- Draft, Save and the Chat, are in [`AGENTS.md`](AGENTS.md).
54
+ The rules an App's agent follows, including Local Query, search, Room Draft, Save and the
55
+ Chat, are the `apps/` pages of House's Guide, which House's `guide` tool opens.
51
56
 
52
57
  ## License
53
58
 
@@ -0,0 +1,3 @@
1
+ import type { Runtime } from './runtime.js';
2
+ export declare function submitLater(runtime: Runtime, locator: string): void;
3
+ //# sourceMappingURL=acceptance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acceptance.d.ts","sourceRoot":"","sources":["../src/acceptance.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA0Y5C,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,QAK5D"}
@@ -0,0 +1,328 @@
1
+ import { refusalError } from './failure.js';
2
+ import { changeSet } from './change-set.js';
3
+ import { declared } from './declaration.js';
4
+ import { leaving as leavingIn, partnerOf } from './change.js';
5
+ import { olderThan, showing } from './install.js';
6
+ import { scoped } from './models.js';
7
+ import { answered, settle } from './queue.js';
8
+ import { refuse } from './refusal.js';
9
+ import { writtenDocuments } from './overlay.js';
10
+ import { returnedPaths, returning, slicing, touchedBy, } from './replica.js';
11
+ import { batchFile } from './saves.js';
12
+ import { rest, roomUnreadable, statusShown } from './shown.js';
13
+ import { advanced, withhold } from './sync.js';
14
+ import { unconfirmed } from './transfer.js';
15
+ import { stepped } from './turn.js';
16
+ async function mark(runtime, local, locator, batch, submission, lost) {
17
+ const { store, socket, presence } = runtime;
18
+ const partner = partnerOf(batch, locator);
19
+ for (const held of partner === null ? [locator] : [locator, partner]) {
20
+ const { state, room } = await local.pending(held, batch.id);
21
+ if (!socket.continuing() ||
22
+ state === undefined ||
23
+ (JSON.stringify(state.submission) === JSON.stringify(submission) && state.lost === lost)) {
24
+ continue;
25
+ }
26
+ await local.submit(held, batch.id, submission, lost);
27
+ if (presence.lost(held))
28
+ continue;
29
+ if (room)
30
+ store.changed(changeSet(held, { queue: true }));
31
+ }
32
+ statusShown(runtime);
33
+ }
34
+ async function keepUpload({ socket, presence }, local, locator, identifier, upload) {
35
+ if (!socket.continuing())
36
+ throw new Error();
37
+ await local.keepUpload(locator, identifier, upload);
38
+ if (presence.lost(locator))
39
+ throw new Error();
40
+ if (!socket.continuing())
41
+ throw new Error();
42
+ }
43
+ function restands(adoptions) {
44
+ return adoptions.flatMap((one) => (one === null || !('record' in one) ? [] : [one]));
45
+ }
46
+ async function adoption(runtime, room, current, local, submitted, accepted) {
47
+ const { store, socket } = runtime;
48
+ if (!socket.continuing())
49
+ return unconfirmed;
50
+ if (current === undefined || !current.queue.some((batch) => batch.id === submitted.id)) {
51
+ return null;
52
+ }
53
+ const held = current.record.roomVersion;
54
+ let record = current.record;
55
+ let adopted;
56
+ if (!socket.reads.reached(room.locator, held, accepted.roomVersion) &&
57
+ !olderThan(runtime, room.locator, accepted.roomVersion, held)) {
58
+ const paths = [...returnedPaths(submitted, accepted)];
59
+ const confirmedLayer = await stepped(slicing(await local.entries(record.key, 'confirmed', paths), paths));
60
+ adopted = await stepped(returning(confirmedLayer, submitted, accepted, accepted.roomVersion, store.composed(record)));
61
+ record = {
62
+ ...record,
63
+ roomVersion: socket.follows(room.locator, held, accepted.roomVersion)
64
+ ? accepted.roomVersion
65
+ : held,
66
+ };
67
+ }
68
+ const reached = record.roomVersion;
69
+ return {
70
+ locator: room.locator,
71
+ record,
72
+ accepted: submitted.id,
73
+ ...(adopted === undefined ? {} : { adopted }),
74
+ after() {
75
+ showing(runtime, room.locator, accepted.roomVersion, reached);
76
+ runtime.presence.readable(room.locator);
77
+ },
78
+ };
79
+ }
80
+ async function adopted(runtime, room, local, submitted, accepted) {
81
+ let kept = true;
82
+ await settle(runtime, [room.locator], async (held) => {
83
+ const adopting = await adoption(runtime, room, held.get(room.locator)?.replica, local, submitted, accepted);
84
+ kept = adopting !== unconfirmed;
85
+ return restands([adopting]);
86
+ });
87
+ return kept;
88
+ }
89
+ async function adoptedMove(runtime, room, partner, local, submitted, accepted) {
90
+ const other = runtime.presence.room(partner);
91
+ let kept = true;
92
+ await settle(runtime, [room.locator, partner], async (held) => {
93
+ const left = await adoption(runtime, room, held.get(room.locator)?.replica, local, submitted, accepted);
94
+ const there = held.get(partner)?.replica;
95
+ const arriving = there?.queue.find((batch) => batch.id === submitted.id);
96
+ const arrived = other === undefined || arriving === undefined || accepted.destination === undefined
97
+ ? null
98
+ : await adoption(runtime, other, there, local, arriving, {
99
+ kind: 'accepted',
100
+ ...accepted.destination,
101
+ });
102
+ kept = left !== unconfirmed;
103
+ return restands([left, arrived]);
104
+ });
105
+ submitLater(runtime, partner);
106
+ return kept;
107
+ }
108
+ async function writtenOf({ store }, local, locator, batch) {
109
+ const record = (await store.record(locator));
110
+ const paths = [...touchedBy([batch])];
111
+ const confirmed = await stepped(slicing(await local.entries(record.key, 'confirmed', paths), paths));
112
+ return stepped(writtenDocuments(confirmed, batch, store.composed(record)));
113
+ }
114
+ const STALE_BASES = new Set(['base_revision_stale', 'merge_conflict']);
115
+ function staleOnly(fields) {
116
+ const { conflicts } = fields;
117
+ return (Array.isArray(conflicts) &&
118
+ conflicts.length > 0 &&
119
+ conflicts.every((conflict) => typeof conflict === 'object' &&
120
+ conflict !== null &&
121
+ STALE_BASES.has(conflict.code)));
122
+ }
123
+ function rebuilt(sent, again) {
124
+ return (again.every((document) => document === null || !document.stale) &&
125
+ JSON.stringify(again) !== JSON.stringify(sent));
126
+ }
127
+ async function behindIn({ store }, locator, batch) {
128
+ const local = await store.open();
129
+ const [order, { room }] = await Promise.all([
130
+ local.order(locator),
131
+ local.pending(locator, batch.id),
132
+ ]);
133
+ return room ? order.indexOf(batch.id) > 0 : order.length > 0;
134
+ }
135
+ async function submitRoom(runtime, room, local, authorized, progress, signal) {
136
+ const { store, socket, presence } = runtime;
137
+ while (socket.continuing() &&
138
+ socket.session.now().authorization !== undefined &&
139
+ !signal.aborted) {
140
+ const headId = (await local.order(room.locator)).find((id) => store.conflicted.of(room.locator, id) === undefined);
141
+ if (headId === undefined)
142
+ return 'done';
143
+ const [head, pending] = await Promise.all([
144
+ local.batch(room.locator, headId),
145
+ local.pending(room.locator, headId),
146
+ ]);
147
+ if (head === null || !pending.room)
148
+ return 'done';
149
+ const { state } = pending;
150
+ const partner = partnerOf(head, room.locator);
151
+ if (partner !== null && !leavingIn(head, room.locator)) {
152
+ submitLater(runtime, partner);
153
+ return 'done';
154
+ }
155
+ if (partner !== null && (await behindIn(runtime, partner, head))) {
156
+ progress.complete = false;
157
+ return 'done';
158
+ }
159
+ const { submission, lost: earlier } = state ?? {
160
+ submission: { state: 'waiting' },
161
+ lost: false,
162
+ };
163
+ if (submission.state === 'reset' && Date.now() < Date.parse(submission.reset)) {
164
+ progress.complete = false;
165
+ return { at: Date.parse(submission.reset) };
166
+ }
167
+ if (socket.writesHeld()) {
168
+ progress.complete = false;
169
+ return 'done';
170
+ }
171
+ const lost = earlier || submission.state === 'submitted';
172
+ let result;
173
+ const written = await writtenOf(runtime, local, room.locator, head);
174
+ await store.exclusive(() => mark(runtime, local, room.locator, head, { state: 'submitted' }, lost));
175
+ if (socket.session.now().paused || presence.lost(room.locator))
176
+ return 'done';
177
+ if (signal.aborted || socket.writesHeld()) {
178
+ await store.exclusive(() => mark(runtime, local, room.locator, head, submission, earlier));
179
+ if (signal.aborted)
180
+ return 'done';
181
+ progress.complete = false;
182
+ return 'done';
183
+ }
184
+ const opensBefore = socket.session.now().openSignals;
185
+ const answeredHere = socket.awaitingAnswer(room.locator);
186
+ const answeredThere = partner === null ? () => { } : socket.awaitingAnswer(partner);
187
+ const heard = () => {
188
+ answeredHere();
189
+ answeredThere();
190
+ };
191
+ try {
192
+ result = await socket.mutate(authorized, {
193
+ locator: room.locator,
194
+ changeBatch: head,
195
+ written,
196
+ file: batchFile(store, head),
197
+ ...(state?.upload === undefined ? {} : { upload: state.upload }),
198
+ }, (upload) => store.exclusive(() => keepUpload(runtime, local, room.locator, head.id, upload)));
199
+ }
200
+ catch (error) {
201
+ runtime.retries.failed('sending', submitting(room.locator), error);
202
+ heard();
203
+ progress.complete = false;
204
+ if (socket.continuing())
205
+ progress.reachable = false;
206
+ return 'again';
207
+ }
208
+ if (signal.aborted) {
209
+ heard();
210
+ return 'done';
211
+ }
212
+ if (result.kind !== 'accepted' || !socket.continuing())
213
+ heard();
214
+ if (!socket.continuing())
215
+ return 'done';
216
+ if (result.kind === 'accepted')
217
+ runtime.retries.succeeded('sending', submitting(room.locator));
218
+ if (result.kind === 'transport-uncertainty') {
219
+ runtime.retries.uncertain('sending', submitting(room.locator), result);
220
+ progress.complete = false;
221
+ progress.reachable = false;
222
+ return 'again';
223
+ }
224
+ if (result.kind === 'room-not-readable') {
225
+ progress.complete = false;
226
+ roomUnreadable(runtime, (presence.room(result.locator) ?? room).locator);
227
+ return 'done';
228
+ }
229
+ if (result.kind === 'revoked-authorization') {
230
+ await refuse(runtime, 'revoked-authorization');
231
+ return 'done';
232
+ }
233
+ if (result.kind === 'scoped-refusal') {
234
+ await scoped(runtime, result, room.locator, declared(room));
235
+ progress.complete = false;
236
+ return 'done';
237
+ }
238
+ if (result.kind === 'write-halted') {
239
+ await store.exclusive(() => mark(runtime, local, room.locator, head, { state: 'waiting' }, lost));
240
+ if (!socket.haltedSince(opensBefore))
241
+ continue;
242
+ progress.complete = false;
243
+ return 'done';
244
+ }
245
+ const other = partner === null ? undefined : presence.room(partner);
246
+ if (result.kind === 'retryable-refusal') {
247
+ runtime.retries.failed('sending', submitting(room.locator), refusalError(result));
248
+ const reset = result.reset;
249
+ progress.complete = false;
250
+ await store.exclusive(() => mark(runtime, local, room.locator, head, reset === undefined ? { state: 'waiting' } : { state: 'reset', reset }, lost));
251
+ return reset === undefined ? 'again' : { at: Date.parse(reset) };
252
+ }
253
+ if (result.kind === 'conflicted' && partner === null && staleOnly(result.fields)) {
254
+ const here = await advanced(runtime, room, local, authorized);
255
+ if (here === null && rebuilt(written, await writtenOf(runtime, local, room.locator, head))) {
256
+ await store.exclusive(() => mark(runtime, local, room.locator, head, { state: 'waiting' }, lost));
257
+ continue;
258
+ }
259
+ }
260
+ if (result.kind === 'conflicted' || result.kind === 'rejected') {
261
+ const refreshed = async () => ({
262
+ there: other === undefined ? null : await advanced(runtime, other, local, authorized),
263
+ here: await advanced(runtime, room, local, authorized),
264
+ });
265
+ const judged = result.kind === 'conflicted' && other !== undefined ? await refreshed() : null;
266
+ if (judged !== null && (judged.there !== null || judged.here !== null)) {
267
+ await store.exclusive(() => mark(runtime, local, room.locator, head, { state: 'waiting' }, lost));
268
+ if (other !== undefined && judged.there !== null) {
269
+ await withhold(runtime, judged.there, other, local, progress);
270
+ }
271
+ if (judged.here !== null)
272
+ await withhold(runtime, judged.here, room, local, progress);
273
+ return 'done';
274
+ }
275
+ await answered(runtime, room.locator, head, result);
276
+ const { there, here } = judged ?? (await refreshed());
277
+ if (other !== undefined && there !== null) {
278
+ await withhold(runtime, there, other, local, progress);
279
+ }
280
+ if (here !== null) {
281
+ await withhold(runtime, here, room, local, progress);
282
+ return 'done';
283
+ }
284
+ continue;
285
+ }
286
+ const kept = await (partner === null
287
+ ? adopted(runtime, room, local, head, result)
288
+ : adoptedMove(runtime, room, partner, local, head, result)).finally(heard);
289
+ if (!kept) {
290
+ progress.complete = false;
291
+ return 'done';
292
+ }
293
+ }
294
+ return 'done';
295
+ }
296
+ function submitting(locator) {
297
+ return `submit ${locator}`;
298
+ }
299
+ export function submitLater(runtime, locator) {
300
+ if (runtime.localSaves)
301
+ return;
302
+ void runtime.recovery.attempt(submitting(locator), (signal) => submitPass(runtime, locator, signal));
303
+ }
304
+ async function submitPass(runtime, locator, signal) {
305
+ const { store, socket, presence } = runtime;
306
+ const room = presence.room(locator);
307
+ if (!socket.continuing() || socket.stopping() || room === undefined) {
308
+ return 'done';
309
+ }
310
+ const progress = { complete: true, reachable: true };
311
+ let next;
312
+ try {
313
+ await socket.authorize();
314
+ const { authorization } = socket.session.now();
315
+ if (authorization === undefined)
316
+ return 'done';
317
+ next = await submitRoom(runtime, room, await store.open(), authorization, progress, signal);
318
+ }
319
+ catch (error) {
320
+ runtime.retries.failed('sending', submitting(locator), error);
321
+ progress.reachable = false;
322
+ next = 'again';
323
+ }
324
+ if (signal.aborted)
325
+ return 'done';
326
+ await rest(runtime, progress);
327
+ return next === 'again' && !socket.isOpen() ? 'done' : next;
328
+ }
@@ -0,0 +1,30 @@
1
+ import { type Expected, type Expecting } from './expectation.js';
2
+ export type Ended = 'accepted' | 'refused' | 'unanswered' | 'unsent';
3
+ export type Send<O> = {
4
+ (name: string, input: unknown, sending: (operation: string) => Promise<O>): Promise<O>;
5
+ expect(expected: Expected): void;
6
+ };
7
+ export type LaneShown<O> = {
8
+ readonly busy: boolean;
9
+ readonly drawn: boolean;
10
+ readonly ended: O | null;
11
+ };
12
+ export type Lane<O> = {
13
+ run(steps: (send: Send<O>) => Promise<O>, expected?: Expected): Promise<O>;
14
+ shown(): LaneShown<O>;
15
+ subscribe(listener: () => void): () => void;
16
+ forget(): void;
17
+ };
18
+ export type Acting<O> = {
19
+ open(): Lane<O>;
20
+ };
21
+ export type ActingRules<O> = {
22
+ readonly store: Pick<Expecting, 'begin' | 'expect' | 'drop'>;
23
+ readonly uncertain: O;
24
+ ending(outcome: O): Ended;
25
+ acted?(): void;
26
+ mint?(): string;
27
+ settles?(operation: string): Promise<boolean>;
28
+ };
29
+ export declare function acting<O>(rules: ActingRules<O>): Acting<O>;
30
+ //# sourceMappingURL=act-lanes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"act-lanes.d.ts","sourceRoot":"","sources":["../src/act-lanes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG/E,MAAM,MAAM,KAAK,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,GAAG,QAAQ,CAAC;AAErE,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IACpB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvF,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IACpB,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3E,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IACtB,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,MAAM,IAAI,IAAI,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI;IACtB,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC,CAAC;IAC7D,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;IACtB,MAAM,CAAC,OAAO,EAAE,CAAC,GAAG,KAAK,CAAC;IAC1B,KAAK,CAAC,IAAI,IAAI,CAAC;IACf,IAAI,CAAC,IAAI,MAAM,CAAC;IAChB,OAAO,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/C,CAAC;AAUF,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CA6N1D"}
@@ -0,0 +1,225 @@
1
+ import { expectedList } from './expectation.js';
2
+ import { changeBatchIdentity } from './identity.js';
3
+ const IDLE = { busy: false, drawn: false, ended: null };
4
+ export function acting(rules) {
5
+ const { store, uncertain, ending, settles } = rules;
6
+ const mint = rules.mint ?? (() => changeBatchIdentity());
7
+ const identities = new Map();
8
+ const waiting = new Map();
9
+ const settling = new Map();
10
+ const blobs = new WeakMap();
11
+ let counted = 0;
12
+ let touches = 0;
13
+ const requestOf = (name, input) => {
14
+ const carried = [];
15
+ const json = JSON.stringify(input, (_key, value) => {
16
+ if (!(value instanceof Blob))
17
+ return value;
18
+ let one = blobs.get(value);
19
+ if (one === undefined) {
20
+ counted += 1;
21
+ one = counted;
22
+ blobs.set(value, one);
23
+ }
24
+ carried.push(one);
25
+ return null;
26
+ });
27
+ return `${name}\u0000${json}\u0000${carried.join(',')}`;
28
+ };
29
+ const identityOf = (request) => {
30
+ const held = identities.get(request);
31
+ if (held !== undefined)
32
+ return held;
33
+ const fresh = { operation: mint(), touched: 0, flying: 0 };
34
+ identities.set(request, fresh);
35
+ return fresh;
36
+ };
37
+ const settled = (act, ended, calls) => {
38
+ const released = new Map();
39
+ for (const { request, identity, ended: answered } of calls) {
40
+ const heard = answered === 'accepted' || answered === 'refused';
41
+ if (ended === 'accepted' && heard)
42
+ released.set(request, identity.touched);
43
+ else {
44
+ touches += 1;
45
+ identity.touched = touches;
46
+ identities.set(request, identity);
47
+ }
48
+ }
49
+ if (ended === 'refused' || ended === 'unsent')
50
+ store.drop(act);
51
+ for (const { request, ended: answered } of calls) {
52
+ const earlier = waiting.get(request);
53
+ if (answered === 'unsent' && earlier !== undefined)
54
+ continue;
55
+ if (earlier !== undefined && earlier !== act)
56
+ store.drop(earlier);
57
+ if (ended === 'unanswered')
58
+ waiting.set(request, act);
59
+ else
60
+ waiting.delete(request);
61
+ }
62
+ if (ended === 'accepted' || calls.some((one) => one.ended === 'accepted'))
63
+ rules.acted?.();
64
+ return released;
65
+ };
66
+ const release = (released) => {
67
+ for (const [request, touched] of released) {
68
+ const held = identities.get(request);
69
+ if (held !== undefined && held.touched === touched && held.flying === 0) {
70
+ identities.delete(request);
71
+ }
72
+ }
73
+ };
74
+ return {
75
+ open() {
76
+ const listeners = new Set();
77
+ const releasing = new Map();
78
+ let tail = Promise.resolve();
79
+ let pressed = 0;
80
+ let drawing = 0;
81
+ let ended = null;
82
+ let held = null;
83
+ let presses = 0;
84
+ let shown = IDLE;
85
+ const show = () => {
86
+ const busy = pressed > 0;
87
+ const drawn = drawing > 0;
88
+ if (shown.busy === busy && shown.drawn === drawn && shown.ended === ended)
89
+ return;
90
+ shown = { busy, drawn, ended };
91
+ for (const listener of listeners)
92
+ listener();
93
+ };
94
+ const awaiting = (outcome, operations, heard, again) => new Promise((resolve) => {
95
+ const forgotten = () => {
96
+ for (const operation of operations)
97
+ if (settling.get(operation) === record)
98
+ settling.delete(operation);
99
+ };
100
+ const record = {
101
+ supersede() {
102
+ if (held !== record)
103
+ return;
104
+ held = null;
105
+ forgotten();
106
+ resolve(outcome);
107
+ },
108
+ };
109
+ held = record;
110
+ for (const operation of operations)
111
+ settling.set(operation, record);
112
+ const answers = operations.map((operation) => heard(operation).then((answered) => {
113
+ if (!answered)
114
+ record.supersede();
115
+ return answered;
116
+ }));
117
+ void Promise.all(answers).then(() => {
118
+ if (held !== record)
119
+ return;
120
+ held = null;
121
+ forgotten();
122
+ resolve(again());
123
+ }, () => record.supersede());
124
+ });
125
+ const attempt = (steps, expected, press) => {
126
+ const act = store.begin();
127
+ let drew = false;
128
+ const expect = (more) => {
129
+ if (expectedList(more).length === 0)
130
+ return;
131
+ store.expect(act, more);
132
+ if (drew)
133
+ return;
134
+ drew = true;
135
+ drawing += 1;
136
+ show();
137
+ };
138
+ pressed += 1;
139
+ expect(expected);
140
+ show();
141
+ const calls = [];
142
+ const send = Object.assign(async (name, input, sending) => {
143
+ const request = requestOf(name, input);
144
+ const identity = identityOf(request);
145
+ settling.get(identity.operation)?.supersede();
146
+ const called = { request, identity, ended: null };
147
+ calls.push(called);
148
+ touches += 1;
149
+ identity.touched = touches;
150
+ identity.flying += 1;
151
+ let outcome;
152
+ try {
153
+ outcome = await sending(identity.operation);
154
+ }
155
+ catch {
156
+ outcome = uncertain;
157
+ }
158
+ finally {
159
+ identity.flying -= 1;
160
+ }
161
+ called.ended = ending(outcome);
162
+ return outcome;
163
+ }, { expect });
164
+ const end = (outcome, how) => {
165
+ for (const [request, touched] of settled(act, how, calls))
166
+ releasing.set(request, touched);
167
+ pressed -= 1;
168
+ if (drew)
169
+ drawing -= 1;
170
+ ended = outcome;
171
+ if (pressed === 0) {
172
+ release(releasing);
173
+ releasing.clear();
174
+ }
175
+ show();
176
+ };
177
+ const turn = tail.then(async () => {
178
+ ended = null;
179
+ show();
180
+ let outcome;
181
+ try {
182
+ outcome = await steps(send);
183
+ }
184
+ catch (error) {
185
+ end(uncertain, 'unanswered');
186
+ throw error;
187
+ }
188
+ const how = ending(outcome);
189
+ end(outcome, how);
190
+ return { outcome, how };
191
+ });
192
+ tail = turn.catch(() => undefined);
193
+ return turn.then(({ outcome, how }) => {
194
+ const lost = calls.flatMap(({ identity, ended: answered }) => answered === 'unanswered' ? [identity.operation] : []);
195
+ if (how !== 'unanswered' || lost.length === 0 || settles === undefined)
196
+ return outcome;
197
+ if (press !== presses)
198
+ return outcome;
199
+ return awaiting(outcome, lost, settles, () => attempt(steps, expected, press));
200
+ });
201
+ };
202
+ const run = (steps, expected = null) => {
203
+ held?.supersede();
204
+ presses += 1;
205
+ return attempt(steps, expected, presses);
206
+ };
207
+ return {
208
+ run,
209
+ shown: () => shown,
210
+ subscribe(listener) {
211
+ listeners.add(listener);
212
+ return () => {
213
+ listeners.delete(listener);
214
+ };
215
+ },
216
+ forget() {
217
+ if (pressed > 0 || ended === null)
218
+ return;
219
+ ended = null;
220
+ show();
221
+ },
222
+ };
223
+ },
224
+ };
225
+ }