@agentshouse/mdruntime 0.1.0-cfe148b32e3d8 → 0.1.0-cfe9798bf3c30

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 (442) hide show
  1. package/README.md +24 -20
  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 +279 -121
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +4 -11
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +33 -49
  16. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  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 +347 -0
  22. package/dist/bootstrap.d.ts +17 -16
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +269 -158
  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 +3 -2
  29. package/dist/chain.d.ts.map +1 -1
  30. package/dist/chain.js +5 -2
  31. package/dist/change-set.d.ts +4 -0
  32. package/dist/change-set.d.ts.map +1 -1
  33. package/dist/change-set.js +6 -0
  34. package/dist/change.d.ts +7 -2
  35. package/dist/change.d.ts.map +1 -1
  36. package/dist/change.js +7 -2
  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 +52 -29
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +65 -28
  43. package/dist/collection.d.ts +33 -7
  44. package/dist/collection.d.ts.map +1 -1
  45. package/dist/collection.js +50 -21
  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 +10 -7
  50. package/dist/compile.d.ts.map +1 -1
  51. package/dist/compile.js +349 -315
  52. package/dist/connection.d.ts +6 -141
  53. package/dist/connection.d.ts.map +1 -1
  54. package/dist/connection.js +117 -5016
  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 +83 -54
  65. package/dist/conversation.d.ts.map +1 -1
  66. package/dist/conversation.js +1044 -825
  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/discovery.d.ts +12 -0
  71. package/dist/discovery.d.ts.map +1 -0
  72. package/dist/discovery.js +175 -0
  73. package/dist/download.d.ts +6 -0
  74. package/dist/download.d.ts.map +1 -0
  75. package/dist/download.js +42 -0
  76. package/dist/durability.d.ts +20 -5
  77. package/dist/durability.d.ts.map +1 -1
  78. package/dist/durability.js +12 -0
  79. package/dist/entry.d.ts +28 -3
  80. package/dist/entry.d.ts.map +1 -1
  81. package/dist/entry.js +120 -33
  82. package/dist/expectation.d.ts +26 -13
  83. package/dist/expectation.d.ts.map +1 -1
  84. package/dist/expectation.js +72 -19
  85. package/dist/failure.d.ts +3 -0
  86. package/dist/failure.d.ts.map +1 -1
  87. package/dist/failure.js +8 -0
  88. package/dist/figures.d.ts +49 -0
  89. package/dist/figures.d.ts.map +1 -0
  90. package/dist/figures.js +199 -0
  91. package/dist/file.d.ts +2 -11
  92. package/dist/file.d.ts.map +1 -1
  93. package/dist/file.js +7 -4
  94. package/dist/holdings.d.ts +29 -0
  95. package/dist/holdings.d.ts.map +1 -0
  96. package/dist/holdings.js +95 -0
  97. package/dist/host.d.ts +25 -8
  98. package/dist/host.d.ts.map +1 -1
  99. package/dist/host.js +155 -59
  100. package/dist/house-query.d.ts +24 -0
  101. package/dist/house-query.d.ts.map +1 -0
  102. package/dist/house-query.js +102 -0
  103. package/dist/identity.d.ts +1 -2
  104. package/dist/identity.d.ts.map +1 -1
  105. package/dist/identity.js +1 -4
  106. package/dist/index.d.ts +49 -19
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +25 -8
  109. package/dist/install.d.ts +60 -0
  110. package/dist/install.d.ts.map +1 -0
  111. package/dist/install.js +537 -0
  112. package/dist/lifecycle.d.ts +7 -0
  113. package/dist/lifecycle.d.ts.map +1 -0
  114. package/dist/lifecycle.js +292 -0
  115. package/dist/listing.d.ts +60 -0
  116. package/dist/listing.d.ts.map +1 -0
  117. package/dist/listing.js +168 -0
  118. package/dist/live.d.ts +23 -6
  119. package/dist/live.d.ts.map +1 -1
  120. package/dist/live.js +138 -38
  121. package/dist/loaded.d.ts +7 -0
  122. package/dist/loaded.d.ts.map +1 -0
  123. package/dist/loaded.js +46 -0
  124. package/dist/locks.d.ts +7 -0
  125. package/dist/locks.d.ts.map +1 -0
  126. package/dist/locks.js +34 -0
  127. package/dist/lost.d.ts +5 -0
  128. package/dist/lost.d.ts.map +1 -0
  129. package/dist/lost.js +49 -0
  130. package/dist/media.d.ts +24 -0
  131. package/dist/media.d.ts.map +1 -0
  132. package/dist/media.js +365 -0
  133. package/dist/memory.d.ts +21 -8
  134. package/dist/memory.d.ts.map +1 -1
  135. package/dist/memory.js +299 -110
  136. package/dist/messages.d.ts +44 -5
  137. package/dist/messages.d.ts.map +1 -1
  138. package/dist/messages.js +129 -39
  139. package/dist/modal.d.ts +2 -0
  140. package/dist/modal.d.ts.map +1 -0
  141. package/dist/modal.js +11 -0
  142. package/dist/model.d.ts +15 -15
  143. package/dist/model.d.ts.map +1 -1
  144. package/dist/model.js +11 -22
  145. package/dist/models.d.ts +10 -0
  146. package/dist/models.d.ts.map +1 -0
  147. package/dist/models.js +153 -0
  148. package/dist/name.d.ts +0 -1
  149. package/dist/name.d.ts.map +1 -1
  150. package/dist/name.js +3 -7
  151. package/dist/observation.d.ts +31 -13
  152. package/dist/observation.d.ts.map +1 -1
  153. package/dist/observation.js +219 -82
  154. package/dist/online.d.ts +7 -0
  155. package/dist/online.d.ts.map +1 -0
  156. package/dist/online.js +29 -0
  157. package/dist/opened.d.ts +6 -6
  158. package/dist/opened.d.ts.map +1 -1
  159. package/dist/opened.js +7 -7
  160. package/dist/opening.d.ts +4 -0
  161. package/dist/opening.d.ts.map +1 -0
  162. package/dist/opening.js +71 -0
  163. package/dist/outcome.d.ts +46 -15
  164. package/dist/outcome.d.ts.map +1 -1
  165. package/dist/outcome.js +52 -5
  166. package/dist/overlay.d.ts +24 -8
  167. package/dist/overlay.d.ts.map +1 -1
  168. package/dist/overlay.js +143 -48
  169. package/dist/page-metadata.d.ts +8 -0
  170. package/dist/page-metadata.d.ts.map +1 -0
  171. package/dist/page-metadata.js +19 -0
  172. package/dist/parts.d.ts +6 -0
  173. package/dist/parts.d.ts.map +1 -0
  174. package/dist/parts.js +36 -0
  175. package/dist/paths.d.ts +2 -0
  176. package/dist/paths.d.ts.map +1 -1
  177. package/dist/paths.js +26 -0
  178. package/dist/preparation.d.ts +46 -0
  179. package/dist/preparation.d.ts.map +1 -0
  180. package/dist/preparation.js +344 -0
  181. package/dist/presence.d.ts +58 -0
  182. package/dist/presence.d.ts.map +1 -0
  183. package/dist/presence.js +231 -0
  184. package/dist/queries.d.ts +16 -0
  185. package/dist/queries.d.ts.map +1 -0
  186. package/dist/queries.js +330 -0
  187. package/dist/query.d.ts +20 -210
  188. package/dist/query.d.ts.map +1 -1
  189. package/dist/query.js +3 -505
  190. package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
  191. package/dist/questions.d.ts.map +1 -0
  192. package/dist/{chat/questions.js → questions.js} +14 -8
  193. package/dist/queue.d.ts +40 -0
  194. package/dist/queue.d.ts.map +1 -0
  195. package/dist/queue.js +480 -0
  196. package/dist/reach.d.ts +31 -13
  197. package/dist/reach.d.ts.map +1 -1
  198. package/dist/reach.js +382 -135
  199. package/dist/react.d.ts +27 -3
  200. package/dist/react.d.ts.map +1 -1
  201. package/dist/react.js +33 -1
  202. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  203. package/dist/read.d.ts.map +1 -0
  204. package/dist/{chat/read.js → read.js} +4 -0
  205. package/dist/readiness.d.ts +28 -28
  206. package/dist/readiness.d.ts.map +1 -1
  207. package/dist/readiness.js +20 -18
  208. package/dist/reads.d.ts +38 -10
  209. package/dist/reads.d.ts.map +1 -1
  210. package/dist/reads.js +174 -85
  211. package/dist/recovery.d.ts +4 -0
  212. package/dist/recovery.d.ts.map +1 -1
  213. package/dist/recovery.js +59 -2
  214. package/dist/reference-forms.d.ts +4 -0
  215. package/dist/reference-forms.d.ts.map +1 -0
  216. package/dist/reference-forms.js +74 -0
  217. package/dist/refresh.d.ts +10 -5
  218. package/dist/refresh.d.ts.map +1 -1
  219. package/dist/refresh.js +92 -34
  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 +13 -25
  224. package/dist/replica.d.ts.map +1 -1
  225. package/dist/replica.js +71 -40
  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 +53 -13
  230. package/dist/room-draft.d.ts.map +1 -1
  231. package/dist/room-draft.js +405 -115
  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 +28 -17
  239. package/dist/rows.d.ts.map +1 -1
  240. package/dist/rows.js +64 -159
  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 +43 -84
  254. package/dist/save.d.ts.map +1 -1
  255. package/dist/save.js +342 -232
  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 -63
  260. package/dist/search.d.ts.map +1 -1
  261. package/dist/search.js +9 -52
  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 +1 -7
  269. package/dist/shared.d.ts.map +1 -1
  270. package/dist/shared.js +13 -105
  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 +72 -0
  293. package/dist/source.d.ts.map +1 -0
  294. package/dist/source.js +116 -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 +114 -157
  323. package/dist/store.d.ts.map +1 -1
  324. package/dist/store.js +174 -400
  325. package/dist/stored.d.ts +96 -60
  326. package/dist/stored.d.ts.map +1 -1
  327. package/dist/stored.js +531 -291
  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 +163 -104
  335. package/dist/tables.d.ts.map +1 -1
  336. package/dist/tables.js +277 -332
  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/validation.d.ts +5 -4
  343. package/dist/validation.d.ts.map +1 -1
  344. package/dist/validation.js +87 -105
  345. package/dist/windows.d.ts +1 -12
  346. package/dist/windows.d.ts.map +1 -1
  347. package/dist/windows.js +2 -75
  348. package/dist/wire.d.ts +92 -16
  349. package/dist/wire.d.ts.map +1 -1
  350. package/dist/wire.js +38 -14
  351. package/package.json +13 -19
  352. package/AGENTS.md +0 -317
  353. package/dist/attempt.d.ts +0 -16
  354. package/dist/attempt.d.ts.map +0 -1
  355. package/dist/attempt.js +0 -70
  356. package/dist/binary.d.ts.map +0 -1
  357. package/dist/binary.js +0 -8
  358. package/dist/chat/acts.d.ts +0 -33
  359. package/dist/chat/acts.d.ts.map +0 -1
  360. package/dist/chat/acts.js +0 -36
  361. package/dist/chat/context.d.ts +0 -3
  362. package/dist/chat/context.d.ts.map +0 -1
  363. package/dist/chat/earlier.d.ts +0 -10
  364. package/dist/chat/earlier.d.ts.map +0 -1
  365. package/dist/chat/earlier.js +0 -54
  366. package/dist/chat/house.d.ts +0 -25
  367. package/dist/chat/house.d.ts.map +0 -1
  368. package/dist/chat/house.js +0 -38
  369. package/dist/chat/input.d.ts +0 -11
  370. package/dist/chat/input.d.ts.map +0 -1
  371. package/dist/chat/input.js +0 -92
  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 -28
  379. package/dist/chat/list.d.ts.map +0 -1
  380. package/dist/chat/list.js +0 -103
  381. package/dist/chat/markdown.d.ts +0 -20
  382. package/dist/chat/markdown.d.ts.map +0 -1
  383. package/dist/chat/markdown.js +0 -229
  384. package/dist/chat/message.d.ts +0 -7
  385. package/dist/chat/message.d.ts.map +0 -1
  386. package/dist/chat/message.js +0 -254
  387. package/dist/chat/messages.d.ts +0 -35
  388. package/dist/chat/messages.d.ts.map +0 -1
  389. package/dist/chat/messages.js +0 -210
  390. package/dist/chat/name.d.ts +0 -7
  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 -12
  394. package/dist/chat/opened.d.ts.map +0 -1
  395. package/dist/chat/opened.js +0 -19
  396. package/dist/chat/overlay.d.ts +0 -32
  397. package/dist/chat/overlay.d.ts.map +0 -1
  398. package/dist/chat/overlay.js +0 -103
  399. package/dist/chat/parts.d.ts +0 -58
  400. package/dist/chat/parts.d.ts.map +0 -1
  401. package/dist/chat/parts.js +0 -120
  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 -70
  409. package/dist/chat/provider.d.ts.map +0 -1
  410. package/dist/chat/provider.js +0 -635
  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 -37
  417. package/dist/chat/ready.d.ts.map +0 -1
  418. package/dist/chat/ready.js +0 -93
  419. package/dist/chat/room-file.d.ts +0 -8
  420. package/dist/chat/room-file.d.ts.map +0 -1
  421. package/dist/chat/room-file.js +0 -72
  422. package/dist/chat/steady.d.ts +0 -3
  423. package/dist/chat/steady.d.ts.map +0 -1
  424. package/dist/chat/steady.js +0 -26
  425. package/dist/chat/style.d.ts +0 -4
  426. package/dist/chat/style.d.ts.map +0 -1
  427. package/dist/chat/style.js +0 -307
  428. package/dist/chat.d.ts +0 -15
  429. package/dist/chat.d.ts.map +0 -1
  430. package/dist/chat.js +0 -8
  431. package/dist/fence.d.ts +0 -6
  432. package/dist/fence.d.ts.map +0 -1
  433. package/dist/fence.js +0 -10
  434. package/dist/fulltext.d.ts +0 -27
  435. package/dist/fulltext.d.ts.map +0 -1
  436. package/dist/fulltext.js +0 -368
  437. package/dist/log.d.ts +0 -5
  438. package/dist/log.d.ts.map +0 -1
  439. package/dist/log.js +0 -14
  440. package/dist/words.d.ts +0 -19
  441. package/dist/words.d.ts.map +0 -1
  442. package/dist/words.js +0 -150
@@ -0,0 +1,71 @@
1
+ import { conversationsOpened } from './conversation.js';
2
+ import { detectStorageLoss, nextGeneration, refusedForSpace } from './durability.js';
3
+ import { uncaught } from './failure.js';
4
+ import { sweep } from './install.js';
5
+ import { eraseFenced } from './lost.js';
6
+ import { prepare } from './preparation.js';
7
+ import { unpair } from './queue.js';
8
+ import { runsOpened } from './runs.js';
9
+ import { emitRooms, emitStorageLoss, statusShown } from './shown.js';
10
+ export async function open(runtime, opened) {
11
+ const { store, socket, shell, conversations, build } = runtime;
12
+ if (socket.closed())
13
+ throw new Error('runtime closed');
14
+ const interrupted = await opened.fences();
15
+ const kept = shell.generation;
16
+ const storedGeneration = await opened.generation();
17
+ const loss = detectStorageLoss(storedGeneration, kept);
18
+ const generation = nextGeneration(storedGeneration, kept);
19
+ if (generation !== storedGeneration)
20
+ await opened.rememberGeneration(generation);
21
+ if (generation !== kept)
22
+ await shell.keepGeneration(generation);
23
+ if (loss !== null) {
24
+ store.device.set({ storageLoss: loss });
25
+ emitStorageLoss(runtime);
26
+ }
27
+ const held = await opened.opened();
28
+ store.device.set({
29
+ completedWhenOpened: (await opened.facts(['lastCompleted'])).lastCompleted !== null,
30
+ });
31
+ try {
32
+ await opened.demote();
33
+ await store.ask({ kind: 'read.builds', build });
34
+ for (const key of held.orphans)
35
+ await opened.release(key);
36
+ }
37
+ catch (error) {
38
+ if (!refusedForSpace(error))
39
+ throw error;
40
+ }
41
+ if (held.erasing || held.orphans.length > 0)
42
+ queueMicrotask(() => sweep(runtime));
43
+ await conversationsOpened(conversations, opened);
44
+ await runsOpened(runtime);
45
+ if (interrupted.length > 0) {
46
+ queueMicrotask(() => {
47
+ void eraseFenced(runtime, interrupted).catch(uncaught);
48
+ });
49
+ }
50
+ await factsKept(runtime, opened);
51
+ statusShown(runtime);
52
+ prepare(runtime);
53
+ emitRooms(runtime);
54
+ void unpair(runtime).catch(uncaught);
55
+ return opened;
56
+ }
57
+ async function factsKept({ socket, adopt }, opened) {
58
+ const { session } = socket;
59
+ const { unstored } = session.now();
60
+ if (unstored !== null) {
61
+ queueMicrotask(() => {
62
+ void adopt(unstored).catch(uncaught);
63
+ });
64
+ return;
65
+ }
66
+ const { capabilities, queriesOnly } = await opened.facts(['capabilities', 'queriesOnly']);
67
+ if (queriesOnly.length > 0 && !session.now().roomsNamed)
68
+ session.set({ queriesOnly });
69
+ if (capabilities.length > 0)
70
+ socket.readyFromStore();
71
+ }
package/dist/outcome.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { ActionResult, AdapterFailure, BinaryLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
1
+ import type { ActionResult, AdapterFailure, AttachResult, AttachmentCopy, AttachmentLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
2
2
  import type { ChangeBatch } from './change.js';
3
- import type { KeptBinary, KeptResult } from './opened.js';
3
+ import type { Attempt, Retries } from './retried.js';
4
+ import type { KeptAttachment, KeptResult } from './opened.js';
4
5
  type Refused<Kind extends string> = ProviderRefusal & {
5
6
  kind: Kind;
6
7
  };
@@ -13,23 +14,47 @@ export type CallResult = {
13
14
  kind: 'action';
14
15
  result: unknown;
15
16
  at?: RoomVersionAt;
16
- } | Refused<'rejected'> | Refused<'undeclared'> | Failure;
17
+ } | (Refused<'rejected'> & {
18
+ reset?: string;
19
+ }) | Refused<'undeclared'> | Failure;
17
20
  export type HistoryAnswer = Exclude<HistoryResult, {
18
21
  kind: Failure['kind'];
19
22
  }> | Failure;
20
- type BinaryRefusal = Refused<'rejected'> | Refused<'absent'> | Failure;
21
- export type BinaryAnswer = {
23
+ type AttachmentRefusal = Refused<'rejected'> | Refused<'absent'> | Failure;
24
+ export type AttachmentAnswer = {
22
25
  kind: 'binary';
23
26
  stream: ReadableStream<Uint8Array>;
24
27
  byteLength: number;
25
28
  mediaType: string;
26
- } | BinaryRefusal;
27
- export type HeldBinaryAnswer = KeptBinary | BinaryRefusal;
28
- export type BinaryLinkAnswer = {
29
+ } | AttachmentRefusal;
30
+ export type HeldAttachmentAnswer = KeptAttachment | AttachmentRefusal;
31
+ export type AttachmentLinkAnswer = {
29
32
  kind: 'link';
30
33
  url: string;
31
34
  name: string;
35
+ mediaType: string;
32
36
  } | Refused<'rejected'> | Refused<'absent'> | Failure;
37
+ export type ShownLinkAnswer = Extract<AttachmentLinkAnswer, {
38
+ kind: 'link';
39
+ }> & {
40
+ copies: readonly AttachmentCopy[];
41
+ };
42
+ type ShownRefusal = Exclude<AttachmentLinkAnswer, {
43
+ kind: 'link';
44
+ }>;
45
+ export type HeldShownAnswer = KeptAttachment | ShownLinkAnswer | ShownRefusal;
46
+ export type ShownAnswer = AttachmentAnswer | ShownLinkAnswer | ShownRefusal;
47
+ export type AttachAnswer = {
48
+ kind: 'attached';
49
+ path: string;
50
+ } | Offline | Refused<'rejected'> | Failure;
51
+ export type ConversationAttachAnswer = {
52
+ kind: 'attached';
53
+ link: string;
54
+ } | Offline | Refused<'rejected'> | Refused<'undeclared'> | Failure;
55
+ export type DownloadAnswer = {
56
+ kind: 'started';
57
+ } | Refused<'rejected'> | Refused<'absent'> | Refused<'blocked'> | Failure;
33
58
  export type Resolution = {
34
59
  readonly kind: 'document';
35
60
  readonly room: string;
@@ -43,9 +68,15 @@ export type Resolution = {
43
68
  export declare const UNREADABLE: Refused<'unreadable'>;
44
69
  export declare const LOCKED_UNREADABLE: Refused<'unreadable'>;
45
70
  export declare const ABSENT_TARGET: Refused<'absent'>;
46
- export declare function absentBinary(path: string): Refused<'absent'>;
47
- export declare function binaryAnswer(result: KeptResult): HeldBinaryAnswer;
48
- export declare function binaryLinkAnswer(result: BinaryLinkResult): BinaryLinkAnswer;
71
+ export declare function absentAttachment(path: string): Refused<'absent'>;
72
+ export declare function declaredType(blob: Blob): string;
73
+ export declare function attachmentBlob(binary: Extract<AttachmentAnswer, {
74
+ kind: 'binary';
75
+ }>): Promise<Blob>;
76
+ export declare function attachmentAnswer(result: KeptResult): HeldAttachmentAnswer;
77
+ export declare function attachmentLinkAnswer(result: AttachmentLinkResult, held?: string): AttachmentLinkAnswer;
78
+ export declare function attachAnswer(result: AttachResult): AttachAnswer;
79
+ export declare function linkedAnswer(result: AttachResult): ConversationAttachAnswer;
49
80
  export declare const ROOM_LOCKED = "room-locked";
50
81
  export declare function lockedRoom(locator: string): Refused<'room-locked'> & {
51
82
  locator: string;
@@ -54,8 +85,9 @@ export type Offline = {
54
85
  readonly kind: 'offline';
55
86
  };
56
87
  export declare const OFFLINE: Offline;
88
+ export declare function answeredResult(value: unknown): boolean;
57
89
  export declare const UNCERTAIN: Failure;
58
- export declare function undeclared(name: string): CallResult;
90
+ export declare function undeclared(name: string): Refused<'undeclared'>;
59
91
  export declare function failure(result: AdapterFailure): Failure;
60
92
  export declare function calledResult(result: ActionResult): CallResult;
61
93
  export declare function historyAnswer(result: HistoryResult): HistoryAnswer;
@@ -69,9 +101,8 @@ export type QueueEntry = {
69
101
  readonly batch: ChangeBatch;
70
102
  } & (Submission | {
71
103
  readonly state: 'local';
72
- } | {
73
- readonly state: 'accepted';
74
- readonly roomVersion: string;
75
104
  });
105
+ export declare const UNANSWERED: ActionResult;
106
+ export declare function handedOutcome(retries: Retries, attempt: Attempt | undefined, result: ActionResult): CallResult;
76
107
  export {};
77
108
  //# sourceMappingURL=outcome.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../src/outcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE1D,KAAK,OAAO,CAAC,IAAI,SAAS,MAAM,IAAI,eAAe,GAAG;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC;AAErE,MAAM,MAAM,OAAO,GACf,OAAO,CAAC,uBAAuB,CAAC,GAChC,OAAO,CAAC,uBAAuB,CAAC,GAChC,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,GACpD,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,GAC9C,aAAa,CAAC;AAElB,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,EAAE,CAAC,EAAE,aAAa,CAAA;CAAE,GACvD,OAAO,CAAC,UAAU,CAAC,GACnB,OAAO,CAAC,YAAY,CAAC,GACrB,OAAO,CAAC;AAEZ,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,EAAE;IAAE,IAAI,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UAAU,GACV;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAC9B,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,YAAgD,CAAC;AAE1E,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,MAAM,EAAE,YAAY,GACnB,UAAU,CAUZ"}
package/dist/outcome.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { MEDIA_TYPES } from '@agentshouse/mdmodel';
2
+ import { refusalError } from './failure.js';
1
3
  export const UNREADABLE = {
2
4
  kind: 'unreadable',
3
5
  code: 'room-not-readable',
@@ -16,20 +18,51 @@ export const ABSENT_TARGET = {
16
18
  fields: {},
17
19
  retryable: false,
18
20
  };
19
- export function absentBinary(path) {
20
- return { kind: 'absent', code: 'binary-file-absent', fields: { path }, retryable: false };
21
+ export function absentAttachment(path) {
22
+ return { kind: 'absent', code: 'attachment-absent', fields: { path }, retryable: false };
21
23
  }
22
- export function binaryAnswer(result) {
24
+ export function declaredType(blob) {
25
+ return blob.type === '' ? MEDIA_TYPES.octetStream : blob.type;
26
+ }
27
+ export function attachmentBlob(binary) {
28
+ return new Response(binary.stream, { headers: { 'content-type': binary.mediaType } }).blob();
29
+ }
30
+ export function attachmentAnswer(result) {
23
31
  return result.kind === 'binary' || result.kind === 'rejected' ? result : failure(result);
24
32
  }
25
- export function binaryLinkAnswer(result) {
26
- return result.kind === 'link' || result.kind === 'rejected' ? result : failure(result);
33
+ export function attachmentLinkAnswer(result, held) {
34
+ if (result.kind === 'link') {
35
+ return {
36
+ kind: 'link',
37
+ url: result.url,
38
+ name: result.name,
39
+ mediaType: result.mediaType ?? held ?? MEDIA_TYPES.octetStream,
40
+ };
41
+ }
42
+ return result.kind === 'rejected' ? result : failure(result);
43
+ }
44
+ export function attachAnswer(result) {
45
+ if (result.kind === 'attached')
46
+ return { kind: 'attached', path: result.path };
47
+ if (result.kind === 'linked')
48
+ return UNCERTAIN;
49
+ return result.kind === 'rejected' ? result : failure(result);
50
+ }
51
+ export function linkedAnswer(result) {
52
+ if (result.kind === 'linked')
53
+ return { kind: 'attached', link: result.link };
54
+ if (result.kind === 'attached')
55
+ return UNCERTAIN;
56
+ return result.kind === 'rejected' ? result : failure(result);
27
57
  }
28
58
  export const ROOM_LOCKED = 'room-locked';
29
59
  export function lockedRoom(locator) {
30
60
  return { kind: ROOM_LOCKED, locator, code: ROOM_LOCKED, fields: {}, retryable: true };
31
61
  }
32
62
  export const OFFLINE = { kind: 'offline' };
63
+ export function answeredResult(value) {
64
+ return typeof value === 'object' && value !== null && !('pending' in value);
65
+ }
33
66
  export const UNCERTAIN = {
34
67
  kind: 'transport-uncertainty',
35
68
  code: 'transport-uncertainty',
@@ -65,3 +98,17 @@ export function historyAnswer(result) {
65
98
  ? result
66
99
  : failure(result);
67
100
  }
101
+ export const UNANSWERED = { kind: 'transport-uncertainty' };
102
+ export function handedOutcome(retries, attempt, result) {
103
+ if (attempt !== undefined) {
104
+ const { step, instance } = attempt;
105
+ if (result.kind === 'action')
106
+ retries.succeeded(step, instance);
107
+ else if (result.kind === 'transport-uncertainty')
108
+ retries.uncertain(step, instance, result);
109
+ else if (result.kind === 'rejected' && result.retryable) {
110
+ retries.failed(step, instance, refusalError(result));
111
+ }
112
+ }
113
+ return calledResult(result);
114
+ }
package/dist/overlay.d.ts CHANGED
@@ -1,13 +1,16 @@
1
- import type { BinaryFile, HeadChange } from './adapter.js';
2
- import type { ChangeBatch } from './change.js';
1
+ import { type ApplyResult, type Refusal as ModelRefusal } from '@agentshouse/mdmodel';
2
+ import type { Attachment, HeadChange } from './adapter.js';
3
+ import { type Composition } from './collection.js';
4
+ import { type ChangeBatch } from './change.js';
3
5
  export type Heads = {
4
6
  revisions: Readonly<Record<string, string>>;
5
7
  fileIds: Readonly<Record<string, string>>;
8
+ created: Readonly<Record<string, string>>;
6
9
  changes: Readonly<Record<string, HeadChange>>;
7
10
  };
8
- export type HeldBinary = ({
11
+ export type HeldAttachment = ({
9
12
  readonly state: 'accepted';
10
- } & BinaryFile) | {
13
+ } & Attachment) | {
11
14
  readonly state: 'pending';
12
15
  readonly localId: string;
13
16
  readonly byteLength: number;
@@ -16,10 +19,23 @@ export type HeldBinary = ({
16
19
  };
17
20
  export type Layer = Heads & {
18
21
  documents: Readonly<Record<string, string>>;
19
- binaries: Readonly<Record<string, HeldBinary>>;
22
+ binaries: Readonly<Record<string, HeldAttachment>>;
20
23
  };
21
- export declare function acceptedBinaries(files: Readonly<Record<string, BinaryFile>>): Generator<readonly [string, HeldBinary]>;
22
- export declare function sameBinary(left: HeldBinary | undefined, right: HeldBinary | undefined): boolean;
24
+ export declare function acceptedAttachments(files: Readonly<Record<string, Attachment>>): Generator<readonly [string, HeldAttachment]>;
25
+ export declare function sameAttachment(left: HeldAttachment | undefined, right: HeldAttachment | undefined): boolean;
23
26
  export declare function sameChange(left: HeadChange | undefined, right: HeadChange | undefined): boolean;
24
- export declare function overlaying(base: Layer, queue: readonly ChangeBatch[], unapplied?: () => void): Generator<number, Layer, void>;
27
+ export declare function composed(path: string, fields: Readonly<Record<string, unknown>>, sections: Readonly<Record<string, string>>, composition: Composition): ApplyResult;
28
+ export declare function overlaying(base: Layer, queue: readonly ChangeBatch[], composition: Composition, unapplied?: () => void): Generator<number, Layer, void>;
29
+ export type WrittenDocument = {
30
+ readonly stale: true;
31
+ readonly refusal?: ModelRefusal;
32
+ } | {
33
+ readonly stale: false;
34
+ readonly content: string;
35
+ readonly base: string | null;
36
+ readonly created: boolean;
37
+ };
38
+ export type Written = readonly (WrittenDocument | null)[];
39
+ export declare function unreadDocuments(batch: ChangeBatch, base: string): Written;
40
+ export declare function writtenDocuments(base: Layer, batch: ChangeBatch, composition: Composition): Generator<number, Written, void>;
25
41
  //# sourceMappingURL=overlay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../src/overlay.ts"],"names":[],"mappings":"AAOA,OAAO,KA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AQ,CAAC,OAAO,CAAC,EAAE,YAAY,CAAA;CAAE,GACzD;IACE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEN,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,eAAe,GAAG,IAAI,CAAC,EAAE,CAAC;AAmB1D,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAQzE;AAED,wBAAiB,gBAAgB,CAC/B,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,WAAW,EAClB,WAAW,EAAE,WAAW,GACvB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAoClC"}
package/dist/overlay.js CHANGED
@@ -1,11 +1,13 @@
1
- import { apply, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
1
+ import { apply, create, documentValue, parse, serialize, TYPE_FIELD, } from '@agentshouse/mdmodel';
2
+ import { definitionsAt } from './collection.js';
3
+ import { departure, isPart, } from './change.js';
2
4
  import { drafted, entriesIn, settling } from './shared.js';
3
5
  import { ROW_WEIGHT } from './turn.js';
4
- export function* acceptedBinaries(files) {
6
+ export function* acceptedAttachments(files) {
5
7
  for (const [path, file] of entriesIn(files))
6
8
  yield [path, { state: 'accepted', ...file }];
7
9
  }
8
- export function sameBinary(left, right) {
10
+ export function sameAttachment(left, right) {
9
11
  if (left === undefined || right === undefined)
10
12
  return left === right;
11
13
  return (left.state === right.state &&
@@ -24,10 +26,6 @@ export function sameChange(left, right) {
24
26
  left.author?.id === right.author?.id &&
25
27
  left.author?.name === right.author?.name);
26
28
  }
27
- const EMPTY_FRONTMATTER = '---\n---\n';
28
- function isPart(change) {
29
- return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
30
- }
31
29
  function at(path, name) {
32
30
  return `${path} ${name}`;
33
31
  }
@@ -53,16 +51,21 @@ function* priorsOf(preconditions) {
53
51
  preamble: (path) => preambles.get(path) ?? '',
54
52
  };
55
53
  }
56
- function compose(fields, sections) {
57
- const body = Object.entries(sections)
58
- .map(([name, value]) => `\n## ${name}\n${value}`)
59
- .join('');
60
- const skeleton = `${EMPTY_FRONTMATTER}${body}`;
61
- const opened = parse(skeleton);
62
- if (!opened.ok)
63
- return skeleton;
64
- const next = apply(opened.document, Object.entries(fields).flatMap(([name, value]) => frontmatterValue(value) ? [{ kind: 'field', name, value, prior: undefined }] : []));
65
- return serialize(next.outcome === 'applied' ? next.document : opened.document);
54
+ export function composed(path, fields, sections, composition) {
55
+ const declared = fields[TYPE_FIELD];
56
+ const type = typeof declared === 'string' && declared !== '' ? declared : undefined;
57
+ const definition = definitionsAt(composition, path)(type);
58
+ return apply(create(type, definition), [
59
+ ...Object.entries(fields).flatMap(([name, value]) => (name !== TYPE_FIELD || type === undefined) && documentValue(value)
60
+ ? [{ kind: 'field', name, value, prior: undefined }]
61
+ : []),
62
+ ...Object.entries(sections).map(([name, value]) => ({
63
+ kind: 'section',
64
+ name,
65
+ value,
66
+ prior: undefined,
67
+ })),
68
+ ], definition);
66
69
  }
67
70
  function edited(change, priors) {
68
71
  if (change.kind === 'field')
@@ -81,26 +84,28 @@ function edited(change, priors) {
81
84
  prior: priors.section(change.path, change.name),
82
85
  };
83
86
  }
84
- function edit(staged, changes, priors) {
87
+ function edit(staged, changes, priors, composition) {
85
88
  const path = changes[0].path;
86
89
  delete staged.revisions[path];
87
90
  const text = staged.documents[path];
88
91
  if (text === undefined)
89
92
  return changes.length;
90
- const parsed = parse(text, path);
93
+ const definitions = definitionsAt(composition, path);
94
+ const parsed = parse(text, path, definitions);
91
95
  if (!parsed.ok)
92
96
  return changes.length;
97
+ const definition = definitions(parsed.document.type);
93
98
  const wanted = changes.map((change) => edited(change, priors));
94
- const first = apply(parsed.document, wanted);
99
+ const first = apply(parsed.document, wanted, definition);
95
100
  if (first.outcome === 'refuse')
96
- return changes.length;
101
+ return { refusal: first.refusal };
97
102
  if (first.outcome === 'applied') {
98
103
  staged.documents[path] = serialize(first.document);
99
104
  return 0;
100
105
  }
101
106
  const stale = new Set(first.stale);
102
107
  const kept = wanted.filter((_, at) => !stale.has(at));
103
- const rest = apply(parsed.document, kept);
108
+ const rest = apply(parsed.document, kept, definition);
104
109
  if (rest.outcome !== 'applied')
105
110
  return changes.length;
106
111
  staged.documents[path] = serialize(rest.document);
@@ -125,16 +130,21 @@ function relocate(staged, from, to) {
125
130
  function moveHead(heads, from, to) {
126
131
  const revision = heads.revisions[from];
127
132
  const fileId = heads.fileIds[from];
133
+ const created = heads.created[from];
128
134
  const change = heads.changes[from];
129
135
  delete heads.revisions[from];
130
136
  delete heads.fileIds[from];
137
+ delete heads.created[from];
131
138
  delete heads.changes[from];
132
139
  delete heads.fileIds[to];
140
+ delete heads.created[to];
133
141
  delete heads.changes[to];
134
142
  if (revision !== undefined)
135
143
  heads.revisions[to] = revision;
136
144
  if (fileId !== undefined)
137
145
  heads.fileIds[to] = fileId;
146
+ if (created !== undefined)
147
+ heads.created[to] = created;
138
148
  if (change !== undefined)
139
149
  heads.changes[to] = change;
140
150
  }
@@ -142,14 +152,24 @@ function erase(staged, path) {
142
152
  delete staged.documents[path];
143
153
  delete staged.revisions[path];
144
154
  delete staged.fileIds[path];
155
+ delete staged.created[path];
145
156
  delete staged.changes[path];
146
157
  delete staged.binaries[path];
147
158
  }
148
- function stage(staged, change) {
159
+ function stage(staged, change, composition) {
149
160
  if (change.kind === 'create') {
150
- staged.documents[change.path] =
151
- 'content' in change ? change.content : compose(change.fields, change.sections);
161
+ if ('content' in change)
162
+ staged.documents[change.path] = change.content;
163
+ else {
164
+ const next = composed(change.path, change.fields, change.sections, composition);
165
+ if (next.outcome === 'refuse')
166
+ return { refusal: next.refusal };
167
+ if (next.outcome === 'stale')
168
+ throw new Error(`the creation of ${change.path} writes no document`);
169
+ staged.documents[change.path] = serialize(next.document);
170
+ }
152
171
  delete staged.fileIds[change.path];
172
+ delete staged.created[change.path];
153
173
  delete staged.changes[change.path];
154
174
  return true;
155
175
  }
@@ -194,46 +214,121 @@ function arrive(heads, change) {
194
214
  heads.revisions[change.path] = change.revision;
195
215
  if (change.fileId !== undefined)
196
216
  heads.fileIds[change.path] = change.fileId;
217
+ if (change.created !== undefined)
218
+ heads.created[change.path] = change.created;
197
219
  if (change.change !== undefined)
198
220
  heads.changes[change.path] = change.change;
199
221
  }
200
- export function* overlaying(base, queue, unapplied) {
201
- const staged = {
222
+ function* stagedBatch(staged, batch, composition, settled) {
223
+ const priors = yield* priorsOf(batch.preconditions);
224
+ for (let index = 0; index < batch.changes.length; index += 1) {
225
+ const change = batch.changes[index];
226
+ if (!isPart(change)) {
227
+ const staging = stage(staged, change, composition);
228
+ if (typeof staging === 'boolean')
229
+ settled(index, change.path, staging ? 0 : 1);
230
+ else
231
+ settled(index, change.path, 1, staging.refusal);
232
+ yield ROW_WEIGHT;
233
+ continue;
234
+ }
235
+ const run = [change];
236
+ while (index + 1 < batch.changes.length) {
237
+ const next = batch.changes[index + 1];
238
+ if (!isPart(next) || next.path !== change.path)
239
+ break;
240
+ run.push(next);
241
+ index += 1;
242
+ }
243
+ const text = staged.documents[change.path] ?? '';
244
+ const edited = edit(staged, run, priors, composition);
245
+ if (typeof edited === 'number')
246
+ settled(index, change.path, edited);
247
+ else
248
+ settled(index, change.path, run.length, edited.refusal);
249
+ yield ROW_WEIGHT + text.length;
250
+ }
251
+ }
252
+ function stagedOf(base) {
253
+ return {
202
254
  documents: drafted(base.documents),
203
255
  binaries: drafted(base.binaries),
204
256
  revisions: drafted(base.revisions),
205
257
  fileIds: drafted(base.fileIds),
258
+ created: drafted(base.created),
206
259
  changes: drafted(base.changes),
207
260
  };
261
+ }
262
+ export function* overlaying(base, queue, composition, unapplied) {
263
+ const staged = stagedOf(base);
208
264
  for (const batch of queue) {
209
- const priors = yield* priorsOf(batch.preconditions);
210
- for (let index = 0; index < batch.changes.length; index += 1) {
211
- const change = batch.changes[index];
212
- if (!isPart(change)) {
213
- if (!stage(staged, change))
214
- unapplied?.();
215
- yield ROW_WEIGHT;
216
- continue;
217
- }
218
- const run = [change];
219
- while (index + 1 < batch.changes.length) {
220
- const next = batch.changes[index + 1];
221
- if (!isPart(next) || next.path !== change.path)
222
- break;
223
- run.push(next);
224
- index += 1;
225
- }
226
- const text = staged.documents[change.path] ?? '';
227
- for (let left = edit(staged, run, priors); left > 0; left -= 1)
265
+ yield* stagedBatch(staged, batch, composition, (_index, _path, left) => {
266
+ for (let count = left; count > 0; count -= 1)
228
267
  unapplied?.();
229
- yield ROW_WEIGHT + text.length;
230
- }
268
+ });
231
269
  }
232
270
  return {
233
271
  documents: yield* settling(staged.documents),
234
272
  binaries: yield* settling(staged.binaries),
235
273
  revisions: yield* settling(staged.revisions),
236
274
  fileIds: yield* settling(staged.fileIds),
275
+ created: yield* settling(staged.created),
237
276
  changes: yield* settling(staged.changes),
238
277
  };
239
278
  }
279
+ function writesText(change) {
280
+ return isPart(change) || change.kind === 'create' || change.kind === 'replace';
281
+ }
282
+ function textWrites(changes) {
283
+ const identities = changes.map((_, index) => departure(changes, index));
284
+ const created = new Set(changes.flatMap((change, index) => (change.kind === 'create' ? [identities[index]] : [])));
285
+ const last = new Map(changes.flatMap((change, index) => writesText(change) ? [[identities[index], index]] : []));
286
+ return { identities, created, last };
287
+ }
288
+ export function unreadDocuments(batch, base) {
289
+ const { identities, created, last } = textWrites(batch.changes);
290
+ return batch.changes.map((_, index) => {
291
+ const identity = identities[index];
292
+ if (last.get(identity) !== index)
293
+ return null;
294
+ const made = created.has(identity);
295
+ return { stale: false, content: '', base: made ? null : base, created: made };
296
+ });
297
+ }
298
+ export function* writtenDocuments(base, batch, composition) {
299
+ const { changes } = batch;
300
+ const { identities, created, last } = textWrites(changes);
301
+ const read = new Map(batch.preconditions.flatMap((precondition) => precondition.kind === 'revision' ? [[precondition.path, precondition.revision]] : []));
302
+ const stale = new Set();
303
+ const refused = new Map();
304
+ const texts = new Map();
305
+ const staged = stagedOf(base);
306
+ yield* stagedBatch(staged, batch, composition, (index, path, unapplied, refusal) => {
307
+ if (!writesText(changes[index]))
308
+ return;
309
+ const identity = identities[index];
310
+ if (unapplied > 0)
311
+ stale.add(identity);
312
+ if (refusal !== undefined && !refused.has(identity))
313
+ refused.set(identity, refusal);
314
+ const text = staged.documents[path];
315
+ if (text !== undefined)
316
+ texts.set(index, text);
317
+ });
318
+ return changes.map((_, index) => {
319
+ const identity = identities[index];
320
+ if (last.get(identity) !== index)
321
+ return null;
322
+ const content = texts.get(index);
323
+ if (content === undefined || stale.has(identity)) {
324
+ const refusal = refused.get(identity);
325
+ return refusal === undefined ? { stale: true } : { stale: true, refusal };
326
+ }
327
+ return {
328
+ stale: false,
329
+ content,
330
+ base: read.get(changes[index].path) ?? read.get(identity) ?? base.revisions[identity] ?? null,
331
+ created: created.has(identity),
332
+ };
333
+ });
334
+ }
@@ -0,0 +1,8 @@
1
+ export declare const PAGE_METADATA_WORDS: {
2
+ readonly heading: 'Page metadata';
3
+ readonly app: 'App';
4
+ readonly address: 'Address';
5
+ readonly queries: 'Local Queries';
6
+ };
7
+ export declare function pageMetadataBlock(app: string, address: string, queries: readonly unknown[]): string;
8
+ //# sourceMappingURL=page-metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-metadata.d.ts","sourceRoot":"","sources":["../src/page-metadata.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;aAC9B,OAAO,EAAE,eAAe;aACxB,GAAG,EAAE,KAAK;aACV,OAAO,EAAE,SAAS;aAClB,OAAO,EAAE,eAAe;CAChB,CAAC;AAIX,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS,OAAO,EAAE,GAC1B,MAAM,CAUR"}
@@ -0,0 +1,19 @@
1
+ import { queryKey } from '@agentshouse/mdmodel';
2
+ export const PAGE_METADATA_WORDS = {
3
+ heading: 'Page metadata',
4
+ app: 'App',
5
+ address: 'Address',
6
+ queries: 'Local Queries',
7
+ };
8
+ const PAGE_METADATA_QUERIES = 10;
9
+ export function pageMetadataBlock(app, address, queries) {
10
+ const held = [...new Set(queries.map(queryKey))];
11
+ return [
12
+ PAGE_METADATA_WORDS.heading,
13
+ `${PAGE_METADATA_WORDS.app}: ${app}`,
14
+ `${PAGE_METADATA_WORDS.address}: ${address}`,
15
+ ...(held.length === 0 || held.length > PAGE_METADATA_QUERIES
16
+ ? []
17
+ : [`${PAGE_METADATA_WORDS.queries}:`, ...held]),
18
+ ].join('\n');
19
+ }