@agentshouse/mdruntime 0.1.0-caee7332d2235 → 0.1.0-caf080a9a9c60

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 (394) hide show
  1. package/README.md +19 -16
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +318 -0
  5. package/dist/act-lanes.d.ts +29 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +177 -0
  8. package/dist/actions.d.ts +25 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +261 -0
  11. package/dist/adapter.d.ts +162 -122
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +7 -10
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +40 -41
  16. package/dist/binary.d.ts +0 -5
  17. package/dist/binary.d.ts.map +1 -1
  18. package/dist/binary.js +1 -1
  19. package/dist/bootstrap.d.ts +30 -11
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +309 -113
  22. package/dist/cell.d.ts +6 -0
  23. package/dist/cell.d.ts.map +1 -0
  24. package/dist/cell.js +9 -0
  25. package/dist/chain.d.ts +12 -0
  26. package/dist/chain.d.ts.map +1 -0
  27. package/dist/chain.js +64 -0
  28. package/dist/change-set.d.ts +10 -16
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +17 -94
  31. package/dist/change.d.ts +32 -1
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +14 -3
  34. package/dist/chat-types.d.ts +5 -0
  35. package/dist/chat-types.d.ts.map +1 -0
  36. package/dist/chat-types.js +13 -0
  37. package/dist/client.d.ts +33 -19
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +112 -21
  40. package/dist/collection.d.ts +29 -22
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +47 -354
  43. package/dist/compile.d.ts +18 -0
  44. package/dist/compile.d.ts.map +1 -0
  45. package/dist/compile.js +724 -0
  46. package/dist/connection.d.ts +7 -137
  47. package/dist/connection.d.ts.map +1 -1
  48. package/dist/connection.js +111 -3623
  49. package/dist/context.d.ts +2 -0
  50. package/dist/context.d.ts.map +1 -0
  51. package/dist/{chat/context.js → context.js} +1 -4
  52. package/dist/conversation-live.d.ts +138 -0
  53. package/dist/conversation-live.d.ts.map +1 -0
  54. package/dist/conversation-live.js +249 -0
  55. package/dist/conversation-row.d.ts +33 -0
  56. package/dist/conversation-row.d.ts.map +1 -0
  57. package/dist/conversation-row.js +53 -0
  58. package/dist/conversation.d.ts +66 -49
  59. package/dist/conversation.d.ts.map +1 -1
  60. package/dist/conversation.js +962 -799
  61. package/dist/declaration.d.ts +10 -0
  62. package/dist/declaration.d.ts.map +1 -0
  63. package/dist/declaration.js +24 -0
  64. package/dist/digest.d.ts +7 -0
  65. package/dist/digest.d.ts.map +1 -0
  66. package/dist/digest.js +113 -0
  67. package/dist/discovery.d.ts +10 -0
  68. package/dist/discovery.d.ts.map +1 -0
  69. package/dist/discovery.js +153 -0
  70. package/dist/durability.d.ts +19 -4
  71. package/dist/durability.d.ts.map +1 -1
  72. package/dist/durability.js +5 -0
  73. package/dist/entry.d.ts +5 -2
  74. package/dist/entry.d.ts.map +1 -1
  75. package/dist/entry.js +33 -29
  76. package/dist/expectation.d.ts +26 -13
  77. package/dist/expectation.d.ts.map +1 -1
  78. package/dist/expectation.js +72 -19
  79. package/dist/failure.d.ts +3 -0
  80. package/dist/failure.d.ts.map +1 -1
  81. package/dist/failure.js +6 -0
  82. package/dist/figures.d.ts +49 -0
  83. package/dist/figures.d.ts.map +1 -0
  84. package/dist/figures.js +197 -0
  85. package/dist/file.d.ts +2 -19
  86. package/dist/file.d.ts.map +1 -1
  87. package/dist/file.js +7 -122
  88. package/dist/holdings.d.ts +29 -0
  89. package/dist/holdings.d.ts.map +1 -0
  90. package/dist/holdings.js +95 -0
  91. package/dist/host.d.ts +20 -8
  92. package/dist/host.d.ts.map +1 -1
  93. package/dist/host.js +103 -45
  94. package/dist/identity.d.ts +0 -2
  95. package/dist/identity.d.ts.map +1 -1
  96. package/dist/identity.js +0 -6
  97. package/dist/index.d.ts +39 -15
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +18 -4
  100. package/dist/install.d.ts +54 -0
  101. package/dist/install.d.ts.map +1 -0
  102. package/dist/install.js +539 -0
  103. package/dist/lifecycle.d.ts +7 -0
  104. package/dist/lifecycle.d.ts.map +1 -0
  105. package/dist/lifecycle.js +279 -0
  106. package/dist/listing.d.ts +48 -0
  107. package/dist/listing.d.ts.map +1 -0
  108. package/dist/listing.js +139 -0
  109. package/dist/live.d.ts +23 -0
  110. package/dist/live.d.ts.map +1 -0
  111. package/dist/live.js +165 -0
  112. package/dist/locks.d.ts +7 -0
  113. package/dist/locks.d.ts.map +1 -0
  114. package/dist/locks.js +33 -0
  115. package/dist/log.d.ts +1 -0
  116. package/dist/log.d.ts.map +1 -1
  117. package/dist/lost.d.ts +5 -0
  118. package/dist/lost.d.ts.map +1 -0
  119. package/dist/lost.js +50 -0
  120. package/dist/media.d.ts +8 -0
  121. package/dist/media.d.ts.map +1 -0
  122. package/dist/media.js +218 -0
  123. package/dist/memory.d.ts +17 -7
  124. package/dist/memory.d.ts.map +1 -1
  125. package/dist/memory.js +272 -118
  126. package/dist/messages.d.ts +49 -0
  127. package/dist/messages.d.ts.map +1 -0
  128. package/dist/messages.js +150 -0
  129. package/dist/model.d.ts +8 -11
  130. package/dist/model.d.ts.map +1 -1
  131. package/dist/model.js +6 -23
  132. package/dist/models.d.ts +10 -0
  133. package/dist/models.d.ts.map +1 -0
  134. package/dist/models.js +156 -0
  135. package/dist/name.d.ts +4 -0
  136. package/dist/name.d.ts.map +1 -0
  137. package/dist/name.js +122 -0
  138. package/dist/observation.d.ts +15 -2
  139. package/dist/observation.d.ts.map +1 -1
  140. package/dist/observation.js +98 -14
  141. package/dist/opened.d.ts +22 -0
  142. package/dist/opened.d.ts.map +1 -0
  143. package/dist/opened.js +107 -0
  144. package/dist/opening.d.ts +4 -0
  145. package/dist/opening.d.ts.map +1 -0
  146. package/dist/opening.js +59 -0
  147. package/dist/outcome.d.ts +47 -9
  148. package/dist/outcome.d.ts.map +1 -1
  149. package/dist/outcome.js +56 -2
  150. package/dist/overlay.d.ts +7 -5
  151. package/dist/overlay.d.ts.map +1 -1
  152. package/dist/overlay.js +69 -169
  153. package/dist/page-metadata.d.ts +8 -0
  154. package/dist/page-metadata.d.ts.map +1 -0
  155. package/dist/page-metadata.js +19 -0
  156. package/dist/parts.d.ts +3 -0
  157. package/dist/parts.d.ts.map +1 -0
  158. package/dist/parts.js +10 -0
  159. package/dist/paths.d.ts +2 -0
  160. package/dist/paths.d.ts.map +1 -1
  161. package/dist/paths.js +26 -0
  162. package/dist/preparation.d.ts +20 -0
  163. package/dist/preparation.d.ts.map +1 -0
  164. package/dist/preparation.js +233 -0
  165. package/dist/presence.d.ts +52 -0
  166. package/dist/presence.d.ts.map +1 -0
  167. package/dist/presence.js +220 -0
  168. package/dist/queries.d.ts +16 -0
  169. package/dist/queries.d.ts.map +1 -0
  170. package/dist/queries.js +285 -0
  171. package/dist/query.d.ts +21 -207
  172. package/dist/query.d.ts.map +1 -1
  173. package/dist/query.js +3 -493
  174. package/dist/{chat/questions.d.ts → questions.d.ts} +5 -7
  175. package/dist/questions.d.ts.map +1 -0
  176. package/dist/{chat/questions.js → questions.js} +11 -7
  177. package/dist/queue.d.ts +40 -0
  178. package/dist/queue.d.ts.map +1 -0
  179. package/dist/queue.js +465 -0
  180. package/dist/reach.d.ts +20 -9
  181. package/dist/reach.d.ts.map +1 -1
  182. package/dist/reach.js +306 -111
  183. package/dist/react.d.ts +15 -2
  184. package/dist/react.d.ts.map +1 -1
  185. package/dist/react.js +33 -1
  186. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  187. package/dist/read.d.ts.map +1 -0
  188. package/dist/{chat/read.js → read.js} +4 -0
  189. package/dist/readiness.d.ts +13 -17
  190. package/dist/readiness.d.ts.map +1 -1
  191. package/dist/readiness.js +2 -8
  192. package/dist/reads.d.ts +38 -10
  193. package/dist/reads.d.ts.map +1 -1
  194. package/dist/reads.js +163 -83
  195. package/dist/recovery.d.ts +5 -2
  196. package/dist/recovery.d.ts.map +1 -1
  197. package/dist/recovery.js +65 -8
  198. package/dist/refresh.d.ts +18 -15
  199. package/dist/refresh.d.ts.map +1 -1
  200. package/dist/refresh.js +145 -79
  201. package/dist/refusal.d.ts +5 -0
  202. package/dist/refusal.d.ts.map +1 -0
  203. package/dist/refusal.js +57 -0
  204. package/dist/replica.d.ts +50 -39
  205. package/dist/replica.d.ts.map +1 -1
  206. package/dist/replica.js +319 -208
  207. package/dist/retried.d.ts +30 -0
  208. package/dist/retried.d.ts.map +1 -0
  209. package/dist/retried.js +72 -0
  210. package/dist/room-draft.d.ts +28 -11
  211. package/dist/room-draft.d.ts.map +1 -1
  212. package/dist/room-draft.js +194 -117
  213. package/dist/room-drafts.d.ts +24 -0
  214. package/dist/room-drafts.d.ts.map +1 -0
  215. package/dist/room-drafts.js +217 -0
  216. package/dist/rows.d.ts +31 -31
  217. package/dist/rows.d.ts.map +1 -1
  218. package/dist/rows.js +60 -125
  219. package/dist/runtime.d.ts +36 -0
  220. package/dist/runtime.d.ts.map +1 -0
  221. package/dist/runtime.js +1 -0
  222. package/dist/save.d.ts +43 -50
  223. package/dist/save.d.ts.map +1 -1
  224. package/dist/save.js +661 -228
  225. package/dist/saves.d.ts +32 -0
  226. package/dist/saves.d.ts.map +1 -0
  227. package/dist/saves.js +413 -0
  228. package/dist/search.d.ts +12 -95
  229. package/dist/search.d.ts.map +1 -1
  230. package/dist/search.js +10 -266
  231. package/dist/seed.d.ts +11 -2
  232. package/dist/seed.d.ts.map +1 -1
  233. package/dist/seed.js +71 -1
  234. package/dist/shared.d.ts +4 -9
  235. package/dist/shared.d.ts.map +1 -1
  236. package/dist/shared.js +61 -120
  237. package/dist/shown.d.ts +32 -0
  238. package/dist/shown.d.ts.map +1 -0
  239. package/dist/shown.js +290 -0
  240. package/dist/socket/admission.d.ts +7 -0
  241. package/dist/socket/admission.d.ts.map +1 -0
  242. package/dist/socket/admission.js +39 -0
  243. package/dist/socket/answers.d.ts +6 -0
  244. package/dist/socket/answers.d.ts.map +1 -0
  245. package/dist/socket/answers.js +20 -0
  246. package/dist/socket/lanes.d.ts +21 -0
  247. package/dist/socket/lanes.d.ts.map +1 -0
  248. package/dist/socket/lanes.js +80 -0
  249. package/dist/socket/reads.d.ts +10 -0
  250. package/dist/socket/reads.d.ts.map +1 -0
  251. package/dist/socket/reads.js +31 -0
  252. package/dist/socket/session.d.ts +38 -0
  253. package/dist/socket/session.d.ts.map +1 -0
  254. package/dist/socket/session.js +23 -0
  255. package/dist/socket.d.ts +68 -0
  256. package/dist/socket.d.ts.map +1 -0
  257. package/dist/socket.js +171 -0
  258. package/dist/source.d.ts +54 -0
  259. package/dist/source.d.ts.map +1 -0
  260. package/dist/source.js +82 -0
  261. package/dist/status.d.ts +4 -5
  262. package/dist/status.d.ts.map +1 -1
  263. package/dist/status.js +3 -7
  264. package/dist/store/installs.d.ts +30 -0
  265. package/dist/store/installs.d.ts.map +1 -0
  266. package/dist/store/installs.js +34 -0
  267. package/dist/store/readiness.d.ts +10 -0
  268. package/dist/store/readiness.d.ts.map +1 -0
  269. package/dist/store/readiness.js +52 -0
  270. package/dist/store/records.d.ts +212 -0
  271. package/dist/store/records.d.ts.map +1 -0
  272. package/dist/store/records.js +430 -0
  273. package/dist/store/room-held.d.ts +8 -0
  274. package/dist/store/room-held.d.ts.map +1 -0
  275. package/dist/store/room-held.js +17 -0
  276. package/dist/store/space.d.ts +11 -0
  277. package/dist/store/space.d.ts.map +1 -0
  278. package/dist/store/space.js +41 -0
  279. package/dist/store/watchers.d.ts +17 -0
  280. package/dist/store/watchers.d.ts.map +1 -0
  281. package/dist/store/watchers.js +56 -0
  282. package/dist/store/writes.d.ts +24 -0
  283. package/dist/store/writes.d.ts.map +1 -0
  284. package/dist/store/writes.js +125 -0
  285. package/dist/store.d.ts +111 -166
  286. package/dist/store.d.ts.map +1 -1
  287. package/dist/store.js +158 -797
  288. package/dist/stored.d.ts +156 -0
  289. package/dist/stored.d.ts.map +1 -0
  290. package/dist/stored.js +649 -0
  291. package/dist/surface.d.ts +88 -0
  292. package/dist/surface.d.ts.map +1 -0
  293. package/dist/surface.js +223 -0
  294. package/dist/sync.d.ts +19 -0
  295. package/dist/sync.d.ts.map +1 -0
  296. package/dist/sync.js +540 -0
  297. package/dist/tables.d.ts +412 -0
  298. package/dist/tables.d.ts.map +1 -0
  299. package/dist/tables.js +737 -0
  300. package/dist/tallies.d.ts +18 -0
  301. package/dist/tallies.d.ts.map +1 -0
  302. package/dist/tallies.js +129 -0
  303. package/dist/transfer.d.ts +0 -5
  304. package/dist/transfer.d.ts.map +1 -1
  305. package/dist/turn.d.ts +1 -1
  306. package/dist/turn.d.ts.map +1 -1
  307. package/dist/turn.js +31 -20
  308. package/dist/validation.d.ts +29 -0
  309. package/dist/validation.d.ts.map +1 -0
  310. package/dist/validation.js +104 -0
  311. package/dist/windows.d.ts +1 -16
  312. package/dist/windows.d.ts.map +1 -1
  313. package/dist/windows.js +2 -79
  314. package/dist/wire.d.ts +72 -8
  315. package/dist/wire.d.ts.map +1 -1
  316. package/dist/wire.js +24 -5
  317. package/package.json +19 -19
  318. package/AGENTS.md +0 -299
  319. package/dist/attempt.d.ts +0 -16
  320. package/dist/attempt.d.ts.map +0 -1
  321. package/dist/attempt.js +0 -70
  322. package/dist/chat/acts.d.ts +0 -33
  323. package/dist/chat/acts.d.ts.map +0 -1
  324. package/dist/chat/acts.js +0 -36
  325. package/dist/chat/context.d.ts +0 -3
  326. package/dist/chat/context.d.ts.map +0 -1
  327. package/dist/chat/earlier.d.ts +0 -10
  328. package/dist/chat/earlier.d.ts.map +0 -1
  329. package/dist/chat/earlier.js +0 -54
  330. package/dist/chat/input.d.ts +0 -9
  331. package/dist/chat/input.d.ts.map +0 -1
  332. package/dist/chat/input.js +0 -99
  333. package/dist/chat/kit.d.ts +0 -61
  334. package/dist/chat/kit.d.ts.map +0 -1
  335. package/dist/chat/kit.js +0 -123
  336. package/dist/chat/lasting.d.ts +0 -6
  337. package/dist/chat/lasting.d.ts.map +0 -1
  338. package/dist/chat/lasting.js +0 -19
  339. package/dist/chat/list.d.ts +0 -27
  340. package/dist/chat/list.d.ts.map +0 -1
  341. package/dist/chat/list.js +0 -99
  342. package/dist/chat/markdown.d.ts +0 -21
  343. package/dist/chat/markdown.d.ts.map +0 -1
  344. package/dist/chat/markdown.js +0 -246
  345. package/dist/chat/message.d.ts +0 -6
  346. package/dist/chat/message.d.ts.map +0 -1
  347. package/dist/chat/message.js +0 -192
  348. package/dist/chat/messages.d.ts +0 -22
  349. package/dist/chat/messages.d.ts.map +0 -1
  350. package/dist/chat/messages.js +0 -171
  351. package/dist/chat/name.d.ts +0 -6
  352. package/dist/chat/name.d.ts.map +0 -1
  353. package/dist/chat/name.js +0 -37
  354. package/dist/chat/opened.d.ts +0 -11
  355. package/dist/chat/opened.d.ts.map +0 -1
  356. package/dist/chat/opened.js +0 -17
  357. package/dist/chat/overlay.d.ts +0 -31
  358. package/dist/chat/overlay.d.ts.map +0 -1
  359. package/dist/chat/overlay.js +0 -97
  360. package/dist/chat/parts.d.ts +0 -57
  361. package/dist/chat/parts.d.ts.map +0 -1
  362. package/dist/chat/parts.js +0 -119
  363. package/dist/chat/pieces.d.ts +0 -62
  364. package/dist/chat/pieces.d.ts.map +0 -1
  365. package/dist/chat/pieces.js +0 -1110
  366. package/dist/chat/process.d.ts +0 -20
  367. package/dist/chat/process.d.ts.map +0 -1
  368. package/dist/chat/process.js +0 -32
  369. package/dist/chat/provider.d.ts +0 -63
  370. package/dist/chat/provider.d.ts.map +0 -1
  371. package/dist/chat/provider.js +0 -630
  372. package/dist/chat/question.d.ts +0 -9
  373. package/dist/chat/question.d.ts.map +0 -1
  374. package/dist/chat/question.js +0 -69
  375. package/dist/chat/questions.d.ts.map +0 -1
  376. package/dist/chat/read.d.ts.map +0 -1
  377. package/dist/chat/ready.d.ts +0 -34
  378. package/dist/chat/ready.d.ts.map +0 -1
  379. package/dist/chat/ready.js +0 -91
  380. package/dist/chat/steady.d.ts +0 -3
  381. package/dist/chat/steady.d.ts.map +0 -1
  382. package/dist/chat/steady.js +0 -26
  383. package/dist/chat/style.d.ts +0 -4
  384. package/dist/chat/style.d.ts.map +0 -1
  385. package/dist/chat/style.js +0 -302
  386. package/dist/chat.d.ts +0 -14
  387. package/dist/chat.d.ts.map +0 -1
  388. package/dist/chat.js +0 -8
  389. package/dist/fence.d.ts +0 -6
  390. package/dist/fence.d.ts.map +0 -1
  391. package/dist/fence.js +0 -10
  392. package/dist/read-side.d.ts +0 -27
  393. package/dist/read-side.d.ts.map +0 -1
  394. package/dist/read-side.js +0 -826
@@ -0,0 +1,261 @@
1
+ import { roomTarget, target } from '@agentshouse/mdmodel';
2
+ import { CATCHING_UP, resendConversations } from './conversation.js';
3
+ import { listingNow } from './listing.js';
4
+ import { locked, lockedRooms } from './locks.js';
5
+ import { scoped } from './models.js';
6
+ import { ABSENT_TARGET, failure, historyAnswer, LOCKED_UNREADABLE, lockedRoom, handedOutcome, UNANSWERED, undeclared, UNCERTAIN, UNREADABLE, } from './outcome.js';
7
+ import { refuse } from './refusal.js';
8
+ function operationOf(input) {
9
+ const operation = input?.operation_id;
10
+ return typeof operation === 'string' ? operation : null;
11
+ }
12
+ export async function readHistory(runtime, locator, path, query = {}) {
13
+ const { store, socket, presence, journal } = runtime;
14
+ const { session } = socket;
15
+ if (socket.closed() || session.now().refusal !== null)
16
+ return UNCERTAIN;
17
+ await socket.firstDiscovery;
18
+ if (!session.now().roomsNamed)
19
+ return UNCERTAIN;
20
+ try {
21
+ await socket.authorize();
22
+ }
23
+ catch {
24
+ return UNCERTAIN;
25
+ }
26
+ const { closed, authorization, refusal } = session.now();
27
+ if (closed || authorization === undefined || refusal !== null)
28
+ return UNCERTAIN;
29
+ const since = presence.losses();
30
+ const transfer = ['transfer', 'history', locator, path];
31
+ if (query.revision !== undefined)
32
+ transfer.push(query.revision);
33
+ if (query.pageToken !== undefined)
34
+ transfer.push(query.pageToken);
35
+ journal.record(transfer.join(' '));
36
+ try {
37
+ const result = await socket.history(authorization, {
38
+ locator,
39
+ path,
40
+ ...(query.revision === undefined ? {} : { revision: query.revision }),
41
+ ...(query.pageToken === undefined ? {} : { pageToken: query.pageToken }),
42
+ });
43
+ journal.record(`outcome history ${result.kind}`);
44
+ if (presence.lostSince(locator, since))
45
+ return failure({ kind: 'room-not-readable', locator });
46
+ if (result.kind === 'scoped-refusal') {
47
+ const room = await store.record(result.locator);
48
+ if (room !== undefined)
49
+ await scoped(runtime, result, room.locator, room.declaration);
50
+ }
51
+ if (result.kind === 'revoked-authorization')
52
+ await refuse(runtime, 'revoked-authorization');
53
+ return historyAnswer(result);
54
+ }
55
+ catch {
56
+ journal.record('outcome history transport-uncertainty');
57
+ return UNCERTAIN;
58
+ }
59
+ }
60
+ export async function located(runtime, room, path, destination) {
61
+ const crossing = roomTarget(destination);
62
+ const listing = await listingNow(runtime);
63
+ if (crossing === null) {
64
+ const named = target(path, destination);
65
+ return named === null || !listing.has(room) ? null : { room, path: named };
66
+ }
67
+ const held = [...listing.values()].find((listed) => listed.handle === crossing.handle);
68
+ return held === undefined ? null : { room: held.locator, path: crossing.path };
69
+ }
70
+ export async function resolveReference(runtime, room, path, destination) {
71
+ const { store } = runtime;
72
+ if (roomTarget(destination) === null && target(path, destination) === null) {
73
+ return ABSENT_TARGET;
74
+ }
75
+ const at = await located(runtime, room, path, destination);
76
+ if (at === null)
77
+ return UNREADABLE;
78
+ if (await locked(runtime, at.room))
79
+ return LOCKED_UNREADABLE;
80
+ const held = await store.record(at.room);
81
+ if (held !== undefined &&
82
+ (await (await store.open()).entries(held.key, 'visible', [at.path])).length > 0) {
83
+ return { kind: 'document', ...at };
84
+ }
85
+ const history = await readHistory(runtime, at.room, at.path);
86
+ if (history.kind === 'no-history' || history.kind === 'revision')
87
+ return ABSENT_TARGET;
88
+ if (history.kind !== 'history')
89
+ return history;
90
+ const [last] = history.revisions;
91
+ if (last === undefined)
92
+ return ABSENT_TARGET;
93
+ return history.deleted === true
94
+ ? { kind: 'deleted', ...at, revision: last }
95
+ : { kind: 'document', ...at };
96
+ }
97
+ async function declaredAction({ store }, name) {
98
+ for (const capability of (await (await store.open()).facts()).capabilities) {
99
+ for (const action of capability.actions ?? []) {
100
+ if (action.name === name)
101
+ return action;
102
+ }
103
+ }
104
+ return undefined;
105
+ }
106
+ async function calledRooms(runtime, name, input) {
107
+ const member = (await declaredAction(runtime, name))?.room;
108
+ if (member === undefined || input === null || typeof input !== 'object')
109
+ return [];
110
+ const named = input[member];
111
+ return (Array.isArray(named) ? named : [named]).filter((room) => typeof room === 'string');
112
+ }
113
+ export async function invokeAction(runtime, name, input, { dispatching, attempt } = {}) {
114
+ const { store, socket, journal, retries } = runtime;
115
+ const { session } = socket;
116
+ await socket.ready;
117
+ if (socket.closed() || session.now().refusal !== null) {
118
+ return handedOutcome(retries, attempt, UNANSWERED);
119
+ }
120
+ if ((await declaredAction(runtime, name)) === undefined)
121
+ return undeclared(name);
122
+ try {
123
+ await socket.authorize();
124
+ }
125
+ catch {
126
+ return handedOutcome(retries, attempt, UNANSWERED);
127
+ }
128
+ const { closed, authorization, refusal } = session.now();
129
+ if (closed || authorization === undefined || refusal !== null) {
130
+ return handedOutcome(retries, attempt, UNANSWERED);
131
+ }
132
+ await dispatching?.();
133
+ journal.record(`transfer action ${name}`);
134
+ try {
135
+ const result = await socket.action(authorization, { name, input });
136
+ if (result.kind === 'scoped-refusal') {
137
+ const room = await store.record(result.locator);
138
+ if (room !== undefined)
139
+ await scoped(runtime, result, room.locator, room.declaration);
140
+ }
141
+ if (result.kind === 'revoked-authorization')
142
+ await refuse(runtime, 'revoked-authorization');
143
+ journal.record(`outcome action ${result.kind}`);
144
+ if (result.kind === 'rejected')
145
+ journal.record(`refusal rejected ${result.code}`);
146
+ return handedOutcome(retries, attempt, result);
147
+ }
148
+ catch (error) {
149
+ journal.record('outcome action transport-uncertainty');
150
+ return handedOutcome(retries, attempt, { kind: 'transport-uncertainty', failure: error });
151
+ }
152
+ }
153
+ export async function readConversationHistory(runtime, request) {
154
+ const { socket, journal, retries } = runtime;
155
+ const caught = { step: 'conversations', instance: CATCHING_UP };
156
+ await socket.ready;
157
+ const stream = socket.conversations();
158
+ if (socket.closed() || socket.session.now().refusal !== null || stream?.history === undefined) {
159
+ return handedOutcome(retries, caught, UNANSWERED);
160
+ }
161
+ journal.record('transfer conversation history');
162
+ try {
163
+ const result = await stream.history(request);
164
+ if (result.kind === 'revoked-authorization')
165
+ await refuse(runtime, 'revoked-authorization');
166
+ journal.record(`outcome conversation history ${result.kind}`);
167
+ return handedOutcome(retries, caught, result);
168
+ }
169
+ catch (error) {
170
+ journal.record('outcome conversation history transport-uncertainty');
171
+ return handedOutcome(retries, caught, { kind: 'transport-uncertainty', failure: error });
172
+ }
173
+ }
174
+ function unsettled(result) {
175
+ if (result.kind === 'action')
176
+ return false;
177
+ return result.retryable && (result.kind !== 'rejected' || result.reset === undefined);
178
+ }
179
+ function numberedCall(runtime, name, input, operation, dispatching) {
180
+ return invokeAction(runtime, name, input, {
181
+ dispatching,
182
+ attempt: { step: 'sending', instance: `action ${operation}` },
183
+ });
184
+ }
185
+ async function recoveredAction(runtime, name, input, attempt) {
186
+ const { store, socket, recovery } = runtime;
187
+ const { lanes } = socket;
188
+ const operation = operationOf(input);
189
+ if (operation === null)
190
+ return invokeAction(runtime, name, input, { attempt });
191
+ const dispatching = async () => (await store.open()).keepCall({ operation, name, input });
192
+ lanes.call(operation);
193
+ try {
194
+ let result = await numberedCall(runtime, name, input, operation, dispatching);
195
+ if (unsettled(result)) {
196
+ await recovery.attempt(`action ${operation}`, async () => {
197
+ if (socket.closed() || socket.session.now().refusal !== null)
198
+ return 'done';
199
+ if (!socket.isOpen())
200
+ return 'again';
201
+ result = await numberedCall(runtime, name, input, operation, dispatching);
202
+ return unsettled(result) ? 'again' : 'done';
203
+ }, { again: true });
204
+ }
205
+ if (!unsettled(result))
206
+ await (await store.open()).dropCall(operation);
207
+ return result;
208
+ }
209
+ finally {
210
+ lanes.called(operation);
211
+ }
212
+ }
213
+ export async function called(runtime, name, input, attempt) {
214
+ await runtime.socket.ready;
215
+ const lockedNow = await lockedRooms(runtime);
216
+ const room = (await calledRooms(runtime, name, input)).find((one) => lockedNow.includes(one));
217
+ return room === undefined ? recoveredAction(runtime, name, input, attempt) : lockedRoom(room);
218
+ }
219
+ export async function resendCalls(runtime, signal) {
220
+ const { store, socket } = runtime;
221
+ const { lanes } = socket;
222
+ if (!socket.isOpen() || socket.closed() || socket.stopping())
223
+ return 'done';
224
+ const local = await store.open();
225
+ for (const held of await local.calls()) {
226
+ if (lanes.calling(held.operation))
227
+ continue;
228
+ if (socket.closed() || signal.aborted)
229
+ return 'done';
230
+ lanes.call(held.operation);
231
+ try {
232
+ if (unsettled(await numberedCall(runtime, held.name, held.input, held.operation))) {
233
+ return 'again';
234
+ }
235
+ await local.dropCall(held.operation);
236
+ }
237
+ finally {
238
+ lanes.called(held.operation);
239
+ }
240
+ }
241
+ return 'done';
242
+ }
243
+ async function resendPass({ socket, conversations }, signal) {
244
+ if (!socket.continuing() || !socket.isOpen() || socket.stopping())
245
+ return 'done';
246
+ const reading = { complete: true, reachable: true };
247
+ try {
248
+ await resendConversations(conversations, reading);
249
+ }
250
+ catch {
251
+ reading.reachable = false;
252
+ }
253
+ if (signal.aborted)
254
+ return 'done';
255
+ return reading.reachable && reading.complete ? 'done' : 'again';
256
+ }
257
+ export function resendLater(runtime) {
258
+ if (!runtime.socket.isOpen())
259
+ return;
260
+ void runtime.recovery.attempt('resend', (signal) => resendPass(runtime, signal), { again: true });
261
+ }