@agentshouse/mdruntime 0.1.0-cff8ba8fa2542 → 0.1.0-cffcba9cd9c2f

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 (327) hide show
  1. package/README.md +24 -11
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +309 -0
  5. package/dist/actions.d.ts +20 -0
  6. package/dist/actions.d.ts.map +1 -0
  7. package/dist/actions.js +251 -0
  8. package/dist/adapter.d.ts +195 -88
  9. package/dist/adapter.d.ts.map +1 -1
  10. package/dist/attached-model.d.ts +7 -10
  11. package/dist/attached-model.d.ts.map +1 -1
  12. package/dist/attached-model.js +40 -28
  13. package/dist/attempt.d.ts +16 -0
  14. package/dist/attempt.d.ts.map +1 -0
  15. package/dist/attempt.js +70 -0
  16. package/dist/binary.d.ts +18 -0
  17. package/dist/binary.d.ts.map +1 -0
  18. package/dist/binary.js +8 -0
  19. package/dist/bootstrap.d.ts +37 -5
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +324 -51
  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 +13 -14
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +17 -56
  31. package/dist/change.d.ts +46 -0
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +36 -0
  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 +56 -18
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +164 -23
  40. package/dist/collection.d.ts +31 -14
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +61 -55
  43. package/dist/compile.d.ts +16 -0
  44. package/dist/compile.d.ts.map +1 -0
  45. package/dist/compile.js +711 -0
  46. package/dist/connection.d.ts +8 -103
  47. package/dist/connection.d.ts.map +1 -1
  48. package/dist/connection.js +103 -2076
  49. package/dist/context.d.ts +2 -0
  50. package/dist/context.d.ts.map +1 -0
  51. package/dist/context.js +7 -0
  52. package/dist/conversation-live.d.ts +135 -0
  53. package/dist/conversation-live.d.ts.map +1 -0
  54. package/dist/conversation-live.js +247 -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 +67 -44
  59. package/dist/conversation.d.ts.map +1 -1
  60. package/dist/conversation.js +1010 -549
  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 +177 -0
  70. package/dist/durability.d.ts +19 -1
  71. package/dist/durability.d.ts.map +1 -1
  72. package/dist/durability.js +5 -0
  73. package/dist/entry.d.ts +20 -0
  74. package/dist/entry.d.ts.map +1 -0
  75. package/dist/entry.js +161 -0
  76. package/dist/expectation.d.ts +23 -0
  77. package/dist/expectation.d.ts.map +1 -0
  78. package/dist/expectation.js +92 -0
  79. package/dist/failure.d.ts +14 -0
  80. package/dist/failure.d.ts.map +1 -0
  81. package/dist/failure.js +22 -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 +28 -3
  92. package/dist/host.d.ts.map +1 -1
  93. package/dist/host.js +149 -26
  94. package/dist/identity.d.ts +3 -0
  95. package/dist/identity.d.ts.map +1 -1
  96. package/dist/identity.js +13 -1
  97. package/dist/index.d.ts +39 -10
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +16 -0
  100. package/dist/install.d.ts +55 -0
  101. package/dist/install.d.ts.map +1 -0
  102. package/dist/install.js +543 -0
  103. package/dist/job.d.ts +5 -0
  104. package/dist/job.d.ts.map +1 -0
  105. package/dist/job.js +7 -0
  106. package/dist/lifecycle.d.ts +7 -0
  107. package/dist/lifecycle.d.ts.map +1 -0
  108. package/dist/lifecycle.js +271 -0
  109. package/dist/listing.d.ts +52 -0
  110. package/dist/listing.d.ts.map +1 -0
  111. package/dist/listing.js +168 -0
  112. package/dist/live.d.ts +23 -0
  113. package/dist/live.d.ts.map +1 -0
  114. package/dist/live.js +165 -0
  115. package/dist/locks.d.ts +9 -0
  116. package/dist/locks.d.ts.map +1 -0
  117. package/dist/locks.js +62 -0
  118. package/dist/log.d.ts +1 -0
  119. package/dist/log.d.ts.map +1 -1
  120. package/dist/lost.d.ts +5 -0
  121. package/dist/lost.d.ts.map +1 -0
  122. package/dist/lost.js +61 -0
  123. package/dist/media.d.ts +8 -0
  124. package/dist/media.d.ts.map +1 -0
  125. package/dist/media.js +218 -0
  126. package/dist/memory.d.ts +25 -8
  127. package/dist/memory.d.ts.map +1 -1
  128. package/dist/memory.js +296 -93
  129. package/dist/messages.d.ts +49 -0
  130. package/dist/messages.d.ts.map +1 -0
  131. package/dist/messages.js +148 -0
  132. package/dist/model.d.ts +16 -9
  133. package/dist/model.d.ts.map +1 -1
  134. package/dist/model.js +9 -15
  135. package/dist/models.d.ts +10 -0
  136. package/dist/models.d.ts.map +1 -0
  137. package/dist/models.js +170 -0
  138. package/dist/name.d.ts +4 -0
  139. package/dist/name.d.ts.map +1 -0
  140. package/dist/name.js +122 -0
  141. package/dist/observation.d.ts +22 -4
  142. package/dist/observation.d.ts.map +1 -1
  143. package/dist/observation.js +127 -26
  144. package/dist/open.d.ts +2 -0
  145. package/dist/open.d.ts.map +1 -0
  146. package/dist/open.js +1 -0
  147. package/dist/opened.d.ts +22 -0
  148. package/dist/opened.d.ts.map +1 -0
  149. package/dist/opened.js +107 -0
  150. package/dist/opening.d.ts +4 -0
  151. package/dist/opening.d.ts.map +1 -0
  152. package/dist/opening.js +59 -0
  153. package/dist/outcome.d.ts +75 -5
  154. package/dist/outcome.d.ts.map +1 -1
  155. package/dist/outcome.js +84 -1
  156. package/dist/overlay.d.ts +17 -5
  157. package/dist/overlay.d.ts.map +1 -1
  158. package/dist/overlay.js +168 -190
  159. package/dist/parts.d.ts +11 -0
  160. package/dist/parts.d.ts.map +1 -0
  161. package/dist/parts.js +21 -0
  162. package/dist/paths.d.ts +2 -1
  163. package/dist/paths.d.ts.map +1 -1
  164. package/dist/paths.js +26 -16
  165. package/dist/preparation.d.ts +20 -0
  166. package/dist/preparation.d.ts.map +1 -0
  167. package/dist/preparation.js +233 -0
  168. package/dist/queries.d.ts +16 -0
  169. package/dist/queries.d.ts.map +1 -0
  170. package/dist/queries.js +272 -0
  171. package/dist/query.d.ts +51 -181
  172. package/dist/query.d.ts.map +1 -1
  173. package/dist/query.js +3 -431
  174. package/dist/questions.d.ts +34 -0
  175. package/dist/questions.d.ts.map +1 -0
  176. package/dist/questions.js +122 -0
  177. package/dist/queue.d.ts +32 -0
  178. package/dist/queue.d.ts.map +1 -0
  179. package/dist/queue.js +402 -0
  180. package/dist/reach.d.ts +21 -5
  181. package/dist/reach.d.ts.map +1 -1
  182. package/dist/reach.js +306 -96
  183. package/dist/react.d.ts +43 -19
  184. package/dist/react.d.ts.map +1 -1
  185. package/dist/react.js +22 -21
  186. package/dist/read.d.ts +7 -0
  187. package/dist/read.d.ts.map +1 -0
  188. package/dist/read.js +17 -0
  189. package/dist/readiness.d.ts +49 -0
  190. package/dist/readiness.d.ts.map +1 -0
  191. package/dist/readiness.js +27 -0
  192. package/dist/reads.d.ts +37 -0
  193. package/dist/reads.d.ts.map +1 -0
  194. package/dist/reads.js +174 -0
  195. package/dist/recovery.d.ts +26 -0
  196. package/dist/recovery.d.ts.map +1 -0
  197. package/dist/recovery.js +232 -0
  198. package/dist/refresh.d.ts +20 -7
  199. package/dist/refresh.d.ts.map +1 -1
  200. package/dist/refresh.js +155 -59
  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 +53 -33
  205. package/dist/replica.d.ts.map +1 -1
  206. package/dist/replica.js +361 -164
  207. package/dist/room-draft.d.ts +59 -12
  208. package/dist/room-draft.d.ts.map +1 -1
  209. package/dist/room-draft.js +299 -90
  210. package/dist/room-drafts.d.ts +24 -0
  211. package/dist/room-drafts.d.ts.map +1 -0
  212. package/dist/room-drafts.js +217 -0
  213. package/dist/rows.d.ts +32 -34
  214. package/dist/rows.d.ts.map +1 -1
  215. package/dist/rows.js +67 -87
  216. package/dist/runtime.d.ts +32 -0
  217. package/dist/runtime.d.ts.map +1 -0
  218. package/dist/runtime.js +1 -0
  219. package/dist/save.d.ts +74 -5
  220. package/dist/save.d.ts.map +1 -1
  221. package/dist/save.js +914 -188
  222. package/dist/saves.d.ts +32 -0
  223. package/dist/saves.d.ts.map +1 -0
  224. package/dist/saves.js +679 -0
  225. package/dist/search.d.ts +15 -54
  226. package/dist/search.d.ts.map +1 -1
  227. package/dist/search.js +10 -121
  228. package/dist/seed.d.ts +25 -0
  229. package/dist/seed.d.ts.map +1 -0
  230. package/dist/seed.js +145 -0
  231. package/dist/shared.d.ts +10 -0
  232. package/dist/shared.d.ts.map +1 -0
  233. package/dist/shared.js +339 -0
  234. package/dist/shown.d.ts +32 -0
  235. package/dist/shown.d.ts.map +1 -0
  236. package/dist/shown.js +299 -0
  237. package/dist/socket/admission.d.ts +7 -0
  238. package/dist/socket/admission.d.ts.map +1 -0
  239. package/dist/socket/admission.js +39 -0
  240. package/dist/socket/answers.d.ts +6 -0
  241. package/dist/socket/answers.d.ts.map +1 -0
  242. package/dist/socket/answers.js +20 -0
  243. package/dist/socket/lanes.d.ts +20 -0
  244. package/dist/socket/lanes.d.ts.map +1 -0
  245. package/dist/socket/lanes.js +77 -0
  246. package/dist/socket/reads.d.ts +10 -0
  247. package/dist/socket/reads.d.ts.map +1 -0
  248. package/dist/socket/reads.js +31 -0
  249. package/dist/socket/rooms.d.ts +41 -0
  250. package/dist/socket/rooms.d.ts.map +1 -0
  251. package/dist/socket/rooms.js +90 -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 +69 -0
  256. package/dist/socket.d.ts.map +1 -0
  257. package/dist/socket.js +175 -0
  258. package/dist/source.d.ts +61 -0
  259. package/dist/source.d.ts.map +1 -0
  260. package/dist/source.js +82 -0
  261. package/dist/status.d.ts +7 -4
  262. package/dist/status.d.ts.map +1 -1
  263. package/dist/status.js +3 -15
  264. package/dist/store/fences.d.ts +16 -0
  265. package/dist/store/fences.d.ts.map +1 -0
  266. package/dist/store/fences.js +26 -0
  267. package/dist/store/installs.d.ts +30 -0
  268. package/dist/store/installs.d.ts.map +1 -0
  269. package/dist/store/installs.js +34 -0
  270. package/dist/store/readiness.d.ts +10 -0
  271. package/dist/store/readiness.d.ts.map +1 -0
  272. package/dist/store/readiness.js +52 -0
  273. package/dist/store/records.d.ts +210 -0
  274. package/dist/store/records.d.ts.map +1 -0
  275. package/dist/store/records.js +428 -0
  276. package/dist/store/room-held.d.ts +8 -0
  277. package/dist/store/room-held.d.ts.map +1 -0
  278. package/dist/store/room-held.js +17 -0
  279. package/dist/store/space.d.ts +11 -0
  280. package/dist/store/space.d.ts.map +1 -0
  281. package/dist/store/space.js +41 -0
  282. package/dist/store/watchers.d.ts +17 -0
  283. package/dist/store/watchers.d.ts.map +1 -0
  284. package/dist/store/watchers.js +56 -0
  285. package/dist/store/writes.d.ts +24 -0
  286. package/dist/store/writes.d.ts.map +1 -0
  287. package/dist/store/writes.js +125 -0
  288. package/dist/store.d.ts +106 -92
  289. package/dist/store.d.ts.map +1 -1
  290. package/dist/store.js +142 -385
  291. package/dist/stored.d.ts +156 -0
  292. package/dist/stored.d.ts.map +1 -0
  293. package/dist/stored.js +649 -0
  294. package/dist/surface.d.ts +88 -0
  295. package/dist/surface.d.ts.map +1 -0
  296. package/dist/surface.js +224 -0
  297. package/dist/sync.d.ts +19 -0
  298. package/dist/sync.d.ts.map +1 -0
  299. package/dist/sync.js +530 -0
  300. package/dist/tables.d.ts +412 -0
  301. package/dist/tables.d.ts.map +1 -0
  302. package/dist/tables.js +737 -0
  303. package/dist/tallies.d.ts +18 -0
  304. package/dist/tallies.d.ts.map +1 -0
  305. package/dist/tallies.js +129 -0
  306. package/dist/transfer.d.ts +0 -5
  307. package/dist/transfer.d.ts.map +1 -1
  308. package/dist/turn.d.ts +9 -0
  309. package/dist/turn.d.ts.map +1 -0
  310. package/dist/turn.js +75 -0
  311. package/dist/validation.d.ts +29 -0
  312. package/dist/validation.d.ts.map +1 -0
  313. package/dist/validation.js +104 -0
  314. package/dist/windows.d.ts +11 -0
  315. package/dist/windows.d.ts.map +1 -0
  316. package/dist/windows.js +16 -0
  317. package/dist/wire.d.ts +189 -37
  318. package/dist/wire.d.ts.map +1 -1
  319. package/dist/wire.js +77 -33
  320. package/package.json +27 -15
  321. package/AGENTS.md +0 -231
  322. package/dist/attachment.d.ts +0 -3
  323. package/dist/attachment.d.ts.map +0 -1
  324. package/dist/attachment.js +0 -8
  325. package/dist/read-side.d.ts +0 -18
  326. package/dist/read-side.d.ts.map +0 -1
  327. package/dist/read-side.js +0 -377
@@ -0,0 +1,217 @@
1
+ import { plain } from '@agentshouse/mdmodel';
2
+ import { changeSet } from './change-set.js';
3
+ import { collectionOf } from './collection.js';
4
+ import { runtimeError, uncaught } from './failure.js';
5
+ import { roomDraftRevision } from './identity.js';
6
+ import { normalize } from './paths.js';
7
+ import { slicing } from './replica.js';
8
+ import { binaryBase, gatheredParts, held, heldFile, readParts, staleWrite, underneath, } from './room-draft.js';
9
+ import { stepped } from './turn.js';
10
+ const ROOM_DRAFTS = 'room-drafts';
11
+ const presentationTopic = (app) => `presentation\u0000${app}`;
12
+ export async function visibleOf(store, locator, paths) {
13
+ const kept = await store.record(locator);
14
+ if (kept === undefined)
15
+ return undefined;
16
+ const local = await store.open();
17
+ const slice = await stepped(slicing(await local.entries(kept.key, 'visible', paths), paths));
18
+ return { ...slice, collection: collectionOf(slice.documents, store.composed(kept)) };
19
+ }
20
+ function roomDraftOf(record, visible) {
21
+ return structuredClone({
22
+ room: record.locator,
23
+ path: record.path,
24
+ revision: record.revision,
25
+ parts: record.parts,
26
+ changedUnderneath: underneath(record.parts, record.path, visible),
27
+ returned: record.returned,
28
+ });
29
+ }
30
+ async function roomDraftsOf(store, records) {
31
+ const rooms = new Map();
32
+ for (const record of records) {
33
+ const paths = rooms.get(record.locator) ?? [];
34
+ paths.push(record.path);
35
+ rooms.set(record.locator, paths);
36
+ }
37
+ const layers = new Map();
38
+ for (const [locator, paths] of rooms) {
39
+ layers.set(locator, await visibleOf(store, locator, paths));
40
+ }
41
+ return records.map((record) => roomDraftOf(record, layers.get(record.locator)));
42
+ }
43
+ function inOrder(records) {
44
+ return [...records].sort((left, right) => {
45
+ if (left.locator !== right.locator)
46
+ return left.locator < right.locator ? -1 : 1;
47
+ if (left.path !== right.path)
48
+ return left.path < right.path ? -1 : 1;
49
+ return 0;
50
+ });
51
+ }
52
+ async function snapshotRoomDrafts(store) {
53
+ return roomDraftsOf(store, inOrder(await store.drafts()));
54
+ }
55
+ export function publishRoomDrafts({ store, socket }, waitingOnly, touched = null) {
56
+ const unwatched = () => socket.closed() || store.watching(ROOM_DRAFTS).length === 0;
57
+ if (unwatched())
58
+ return Promise.resolve();
59
+ return store.publication(async () => {
60
+ if (unwatched())
61
+ return;
62
+ const records = await store.drafts();
63
+ if (socket.closed())
64
+ return;
65
+ if (touched !== null &&
66
+ !records.some((record) => touched.some(({ locator, path }) => locator === record.locator && (path === null || path === record.path)))) {
67
+ return;
68
+ }
69
+ const value = await roomDraftsOf(store, inOrder(records));
70
+ if (socket.closed())
71
+ return;
72
+ const answered = store.watching(ROOM_DRAFTS, waitingOnly ? 'waiting' : 'all');
73
+ for (const watcher of answered)
74
+ watcher.answer(value);
75
+ });
76
+ }
77
+ async function presentationOf(store, app) {
78
+ const value = await (await store.open()).presentation(app);
79
+ return value === undefined ? null : structuredClone(value);
80
+ }
81
+ export function emitPresentation({ store, socket }, app) {
82
+ const topic = presentationTopic(app);
83
+ const listening = () => store.watching(topic, 'ready');
84
+ if (socket.closed() || listening().length === 0)
85
+ return Promise.resolve();
86
+ return store.publication(async () => {
87
+ if (socket.closed() || listening().length === 0)
88
+ return;
89
+ const value = await presentationOf(store, app);
90
+ if (socket.closed())
91
+ return;
92
+ for (const watcher of listening())
93
+ watcher.answer(value);
94
+ });
95
+ }
96
+ async function writtenRoomDraft({ store }, room, path, revision, input, next) {
97
+ const parts = readParts(input, path);
98
+ if (path === '' || normalize(path) !== path)
99
+ throw runtimeError('room-draft-malformed', `room-draft-malformed at ${path}: a path inside the Room, such as notes/a.md`);
100
+ const local = await store.open();
101
+ const current = await store.draft(room, path);
102
+ if ((current?.revision ?? null) !== revision) {
103
+ return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
104
+ }
105
+ const file = parts.file === undefined
106
+ ? undefined
107
+ : await heldFile(parts.file.blob, parts.file.base === undefined
108
+ ? binaryBase(await visibleOf(store, room, [path]), path)
109
+ : parts.file.base);
110
+ const record = {
111
+ locator: room,
112
+ path,
113
+ revision: next,
114
+ parts: held(current?.parts, parts, file),
115
+ returned: current?.returned ?? null,
116
+ };
117
+ await local.keepRoomDraft(record, parts.file === undefined || file === undefined
118
+ ? []
119
+ : [{ key: file.localId, blob: parts.file.blob }]);
120
+ await store.changed(changeSet(room, { drafts: [path] }));
121
+ return { outcome: 'written', roomDraft: (await roomDraftsOf(store, [record]))[0] };
122
+ }
123
+ async function keptPresentation({ store }, app, value) {
124
+ await (await store.open()).present({ app, value });
125
+ await store.changed(changeSet('', { presentation: app }));
126
+ }
127
+ export function roomDraftSurface(runtime) {
128
+ const { store } = runtime;
129
+ return {
130
+ list() {
131
+ return store
132
+ .exclusive(async () => {
133
+ await store.open();
134
+ return snapshotRoomDrafts(store);
135
+ })
136
+ .then((listed) => {
137
+ publishRoomDrafts(runtime, true);
138
+ return listed;
139
+ });
140
+ },
141
+ async read(room, path) {
142
+ const record = await store.draft(room, path);
143
+ return record === undefined ? null : (await roomDraftsOf(store, [record]))[0];
144
+ },
145
+ write(room, path, revision, input, next = roomDraftRevision()) {
146
+ if (typeof next !== 'string' || next === '')
147
+ return Promise.reject(runtimeError('room-draft-malformed'));
148
+ return store.gathered(`room-draft\u0000${room}\u0000${path}`, { revision, input, next }, (earlier, later) => {
149
+ if (later.revision !== earlier.next)
150
+ return null;
151
+ const parts = gatheredParts(earlier.input, later.input);
152
+ return parts === null
153
+ ? null
154
+ : { revision: earlier.revision, input: parts, next: later.next };
155
+ }, (written) => writtenRoomDraft(runtime, room, path, written.revision, written.input, written.next));
156
+ },
157
+ discard(room, path, revision) {
158
+ return store.exclusive(async () => {
159
+ const local = await store.open();
160
+ const current = await store.draft(room, path);
161
+ if (current === undefined || current.revision !== revision) {
162
+ return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
163
+ }
164
+ await local.discardRoomDraft(room, path);
165
+ await store.changed(changeSet(room, { drafts: [path] }));
166
+ return { outcome: 'written', roomDraft: null };
167
+ });
168
+ },
169
+ };
170
+ }
171
+ export function presentationSurface(runtime) {
172
+ const { store } = runtime;
173
+ return {
174
+ read(app) {
175
+ return store.exclusive(() => presentationOf(store, app));
176
+ },
177
+ write(app, value) {
178
+ return store.exclusive(() => keptPresentation(runtime, app, structuredClone(value)));
179
+ },
180
+ edit(app, members) {
181
+ return store.gathered(`presentation\u0000${app}`, structuredClone(members), (earlier, later) => ({ ...earlier, ...later }), async (edited) => {
182
+ const kept = await (await store.open()).presentation(app);
183
+ await keptPresentation(runtime, app, Object.fromEntries([
184
+ ...Object.entries(plain(kept) ? kept : {}).filter(([member]) => !Object.hasOwn(edited, member)),
185
+ ...Object.entries(edited).filter(([, value]) => value !== null),
186
+ ]));
187
+ });
188
+ },
189
+ };
190
+ }
191
+ export function watchRoomDrafts({ store, socket }, deliver) {
192
+ const watcher = store.watch(ROOM_DRAFTS, deliver);
193
+ const unwatched = () => socket.closed() || !watcher.held();
194
+ void store
195
+ .exclusive(async () => {
196
+ await store.open();
197
+ })
198
+ .then(() => store.publication(async () => {
199
+ if (unwatched())
200
+ return;
201
+ const value = await snapshotRoomDrafts(store);
202
+ if (!unwatched())
203
+ watcher.answer(value);
204
+ }), uncaught);
205
+ return watcher.stop;
206
+ }
207
+ export function watchPresentation({ store, socket }, app, deliver) {
208
+ const watcher = store.watch(presentationTopic(app), deliver);
209
+ void store
210
+ .exclusive(async () => {
211
+ const value = await presentationOf(store, app);
212
+ if (!socket.closed() && watcher.held())
213
+ watcher.answer(value);
214
+ })
215
+ .catch(uncaught);
216
+ return watcher.stop;
217
+ }
package/dist/rows.d.ts CHANGED
@@ -1,41 +1,39 @@
1
- import { type Document } from '@agentshouse/mdmodel';
2
- import type { HeadChange } from './adapter.js';
1
+ import { type HeldValue } from '@agentshouse/mdmodel';
2
+ import type { SavedFacts } from './adapter.js';
3
3
  import { type Composition } from './collection.js';
4
- type Fields = Readonly<Record<string, unknown>>;
5
- export type DocumentRow = {
6
- key: string;
7
- kind: 'document';
8
- room: string;
9
- path: string;
10
- type: string | null;
11
- fields: Fields;
12
- values: Fields;
13
- sizes: Readonly<Record<string, number>>;
14
- directories: readonly string[];
15
- body: string;
16
- change: HeadChange | null;
4
+ type LinkKind = 'field' | 'link';
5
+ type HeldLink = {
6
+ readonly kind: LinkKind;
7
+ readonly keys: string;
8
+ readonly places: string;
9
+ readonly target: string;
10
+ readonly field: string;
17
11
  };
18
- export type BodyRow = {
19
- key: string;
20
- kind: 'body';
21
- room: string;
22
- path: string;
23
- preamble: string;
24
- sections: Readonly<Record<string, string>>;
25
- markdown: string;
12
+ export type Described = {
13
+ readonly type: string | null;
14
+ readonly declared: string | null;
15
+ readonly queried: boolean;
16
+ readonly folder: string;
17
+ readonly fields: string | null;
18
+ readonly links: string | null;
26
19
  };
27
- export type ReferenceRow = {
28
- key: string;
29
- kind: 'reference';
30
- room: string;
31
- source: string;
32
- target: string;
33
- field: string;
34
- path: string;
35
- type: string;
20
+ export type Held = {
21
+ readonly type: string | null;
22
+ readonly fields: Readonly<Record<string, unknown>> | null;
23
+ readonly links: readonly string[];
24
+ };
25
+ export type Derived = {
26
+ readonly values: readonly HeldValue[];
27
+ readonly links: readonly HeldLink[];
36
28
  };
37
- export type Row = DocumentRow | BodyRow | ReferenceRow;
38
29
  export declare function documentKey(room: string, path: string): string;
39
- export declare function rowsOf(room: string, path: string, document: Document | null, composition: Composition, change: HeadChange | null): readonly Row[];
30
+ export declare function roomOfKey(key: string): string;
31
+ export declare function pathOfKey(key: string): string;
32
+ export declare function markdownPath(path: string): boolean;
33
+ export declare function folderOf(path: string): string;
34
+ export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
35
+ export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
36
+ export declare function heldOf(path: string, content: string | null, facts: SavedFacts | null): Held;
37
+ export declare function derived(path: string, held: Held, composition: Composition): Derived;
40
38
  export {};
41
39
  //# sourceMappingURL=rows.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAa,KAAK,WAAW,EAAE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1
- import { target } from '@agentshouse/mdmodel';
2
- import { governing } from './collection.js';
3
- import { definitionOf, referenceField } from './model.js';
1
+ import { byCodePoint, documentFacts, indexed, parse } from '@agentshouse/mdmodel';
2
+ import { definitionsAt, governing } from './collection.js';
4
3
  function keyOf(...parts) {
5
4
  return `${parts.join('\u0000')}\u0000`;
6
5
  }
7
6
  export function documentKey(room, path) {
8
7
  return keyOf('d', room, path);
9
8
  }
10
- function targetOf(path, value) {
11
- return typeof value === 'string' ? target(path, value) : null;
9
+ export function roomOfKey(key) {
10
+ return key.split('\u0000')[1];
12
11
  }
13
- function resolved(path, value) {
14
- if (value === null)
15
- return null;
16
- if (!Array.isArray(value))
17
- return targetOf(path, value) ?? undefined;
18
- return value.map((item) => targetOf(path, item)).filter((item) => item !== null);
12
+ export function pathOfKey(key) {
13
+ return key.split('\u0000')[2];
19
14
  }
20
- function directoriesOf(path) {
21
- const parts = path.split('/').slice(0, -1);
22
- return ['', ...parts.map((_, index) => parts.slice(0, index + 1).join('/'))];
15
+ export function markdownPath(path) {
16
+ return path.endsWith('.md');
23
17
  }
24
- export function rowsOf(room, path, document, composition, change) {
25
- const key = documentKey(room, path);
26
- const body = keyOf('b', room, path);
27
- if (document === null || !path.endsWith('.md')) {
28
- return [
29
- {
30
- key,
31
- kind: 'document',
32
- room,
33
- path,
34
- type: null,
35
- fields: {},
36
- values: {},
37
- sizes: {},
38
- directories: directoriesOf(path),
39
- body,
40
- change,
41
- },
42
- ];
43
- }
44
- const type = document.type ?? 'any';
45
- const definition = definitionOf(governing(composition, path), document.type);
46
- const values = {};
47
- const sizes = {};
48
- const references = [];
49
- for (const [name, value] of Object.entries(document.fields)) {
50
- const reference = referenceField(definition?.fields[name]);
51
- const compared = reference ? resolved(path, value) : value;
52
- if (compared !== undefined)
53
- values[name] = compared;
54
- if (Array.isArray(value))
55
- sizes[name] = value.length;
56
- if (!reference)
57
- continue;
58
- const targets = [compared].flat().filter((found) => typeof found === 'string');
59
- for (const found of new Set(targets)) {
60
- references.push({
61
- key: keyOf('r', room, path, name, found),
62
- kind: 'reference',
63
- room,
64
- source: key,
65
- target: documentKey(room, found),
66
- field: name,
67
- path,
68
- type,
69
- });
70
- }
71
- }
72
- return [
73
- {
74
- key,
75
- kind: 'document',
76
- room,
77
- path,
78
- type,
79
- fields: document.fields,
80
- values,
81
- sizes,
82
- directories: directoriesOf(path),
83
- body,
84
- change,
85
- },
86
- {
87
- key: body,
88
- kind: 'body',
89
- room,
90
- path,
91
- preamble: document.preamble,
92
- sections: document.sections,
93
- markdown: document.content,
94
- },
95
- ...references,
96
- ];
18
+ export function folderOf(path) {
19
+ return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
20
+ }
21
+ function byKey(_key, value) {
22
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
23
+ return value;
24
+ return Object.fromEntries(Object.entries(value).sort(([one], [other]) => byCodePoint(one, other)));
25
+ }
26
+ function fieldsText(fields) {
27
+ return JSON.stringify(fields, byKey);
28
+ }
29
+ export function writtenFacts(path, content, composition) {
30
+ const model = governing(composition, path);
31
+ const facts = documentFacts(path, parse(content, path, definitionsAt(composition, path)), {
32
+ types: model.status === 'unavailable' ? {} : model.types,
33
+ });
34
+ return facts === null
35
+ ? null
36
+ : { ...facts, fields: JSON.parse(fieldsText(facts.fields)) };
37
+ }
38
+ export function described(path, content, facts) {
39
+ const folder = folderOf(path);
40
+ const unread = { type: null, fields: null, links: null, folder };
41
+ if (content === null)
42
+ return { ...unread, declared: null, queried: true };
43
+ if (facts === null)
44
+ return { ...unread, declared: null, queried: !markdownPath(path) };
45
+ const links = JSON.stringify(facts.links);
46
+ if (!markdownPath(path))
47
+ return { ...unread, declared: facts.type, queried: true, links };
48
+ return {
49
+ type: facts.type,
50
+ declared: facts.type,
51
+ queried: true,
52
+ folder,
53
+ fields: fieldsText(facts.fields),
54
+ links,
55
+ };
56
+ }
57
+ export function heldOf(path, content, facts) {
58
+ if (content === null || facts === null)
59
+ return { type: null, fields: null, links: [] };
60
+ return markdownPath(path)
61
+ ? { type: facts.type, fields: facts.fields, links: facts.links }
62
+ : { type: null, fields: null, links: facts.links };
63
+ }
64
+ export function derived(path, held, composition) {
65
+ const stored = held.links.map((target) => ({
66
+ kind: 'link',
67
+ keys: '',
68
+ places: '',
69
+ target,
70
+ field: '',
71
+ }));
72
+ if (held.type === null || held.fields === null)
73
+ return { values: [], links: stored };
74
+ const definition = definitionsAt(composition, path)(held.type);
75
+ const { values, links: fields } = indexed(path, held.fields, definition);
76
+ return { values, links: [...fields, ...stored] };
97
77
  }
@@ -0,0 +1,32 @@
1
+ import type { RoomDeclaration, TypedPath } from './adapter.js';
2
+ import type { RuntimeShell } from './durability.js';
3
+ import type { LiveConversations } from './conversation-live.js';
4
+ import type { WriteRule } from './declaration.js';
5
+ import type { FiguresRead } from './figures.js';
6
+ import type { LiveQueries } from './live.js';
7
+ import type { Log } from './log.js';
8
+ import type { ModelState } from './model.js';
9
+ import type { ReadAnswers } from './reads.js';
10
+ import type { Recovery } from './recovery.js';
11
+ import type { RuntimeSocket } from './socket.js';
12
+ import type { HeldCover, Store } from './store.js';
13
+ import type { schemaTypes } from './attached-model.js';
14
+ export type Runtime = {
15
+ readonly store: Store;
16
+ readonly socket: RuntimeSocket;
17
+ readonly journal: Log;
18
+ readonly recovery: Recovery;
19
+ readonly shell: RuntimeShell;
20
+ readonly localSaves: boolean;
21
+ readonly roomTypes: Parameters<typeof schemaTypes>[1];
22
+ readonly builtIn: ModelState;
23
+ readonly typedPaths: readonly TypedPath[];
24
+ readonly writeRule: (declaration: RoomDeclaration) => WriteRule;
25
+ readonly usableWhenHeld: readonly string[];
26
+ readonly build: string;
27
+ readonly conversations: LiveConversations;
28
+ readonly liveQueries: LiveQueries<HeldCover>;
29
+ readonly figures: FiguresRead;
30
+ readonly lastAnswers: ReadAnswers;
31
+ };
32
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src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AAS,SAAS,EAAE,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,eAAe,KAAK,SAAS,CAAC;IAChE,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAC7C,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/dist/save.d.ts CHANGED
@@ -1,33 +1,102 @@
1
+ import { type Validation } from '@agentshouse/mdmodel';
1
2
  import type { ProviderLimit } from './adapter.js';
2
3
  import { type Change, type ChangeBatch, type Precondition, type WrittenBy } from './change.js';
3
4
  import { type Composition } from './collection.js';
5
+ import type { WriteRule } from './declaration.js';
6
+ import { type Layer } from './overlay.js';
4
7
  import type { VisibleLayer } from './replica.js';
5
8
  import type { ChangedPart } from './room-draft.js';
6
9
  export type SaveRefusal = {
7
- rule: string;
10
+ code: string;
11
+ retryable: boolean;
8
12
  file?: string;
9
13
  location?: string;
10
14
  referrers?: readonly string[];
11
15
  parts?: readonly ChangedPart[];
12
16
  };
13
17
  export type SaveInput = {
18
+ local: boolean;
14
19
  composition: Composition;
15
20
  baseRoomVersion: string;
16
- operations: import('./adapter.js').OperationScopes;
17
- providerOwnedPaths: readonly string[];
21
+ rule: WriteRule;
18
22
  providerLimits: readonly ProviderLimit[];
19
23
  visible: VisibleLayer;
24
+ folders: ReadonlySet<string>;
25
+ handle: string;
20
26
  changes: readonly Change[];
21
27
  bases: readonly Precondition[];
28
+ queued?: ReadonlySet<string>;
22
29
  writtenBy?: WrittenBy;
30
+ unmodeled: boolean;
31
+ validate: Validator;
32
+ };
33
+ export type Validator = (resulting: Layer, touched: readonly string[]) => Promise<Validation>;
34
+ type Refusing = {
35
+ kind: 'refused';
36
+ refusal: SaveRefusal;
23
37
  };
24
38
  export type BatchResult = {
25
39
  kind: 'batch';
26
40
  batch: ChangeBatch;
41
+ } | Refusing;
42
+ export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
43
+ export declare function leavingRewritten(batch: ChangeBatch, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
44
+ export declare function rewriting(batch: ChangeBatch, locator: string): boolean;
45
+ export declare function effectiveIn(batch: ChangeBatch, locator: string, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
46
+ export declare function queuedDocuments(queue: readonly ChangeBatch[]): ReadonlySet<string>;
47
+ export type Requeued = {
48
+ kind: 'requeued';
49
+ queue: readonly ChangeBatch[];
50
+ changes: readonly Change[];
51
+ queued: ReadonlySet<string>;
52
+ withdrawn: ReadonlyMap<string, ChangeBatch | null>;
53
+ owners: ReadonlySet<string>;
54
+ } | {
55
+ kind: 'refused';
56
+ refusal: SaveRefusal;
57
+ };
58
+ export type Joining = {
59
+ kind: 'joined';
60
+ batch: ChangeBatch;
61
+ queue: readonly ChangeBatch[];
27
62
  } | {
28
63
  kind: 'refused';
29
64
  refusal: SaveRefusal;
30
65
  };
31
- export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): ChangeBatch;
32
- export declare function buildBatch(input: SaveInput): BatchResult;
66
+ type VisibleOver = (queue: readonly ChangeBatch[]) => Generator<number, VisibleLayer, void>;
67
+ export declare function requeuing(queue: readonly ChangeBatch[], changes: readonly Change[], visible: VisibleLayer, changeable: (batch: ChangeBatch) => boolean, state: VisibleOver): Generator<number, Requeued, void>;
68
+ export declare function joined(queue: readonly ChangeBatch[], owner: ChangeBatch, extra: ChangeBatch, composition: Composition): Joining;
69
+ export declare function limiting(queue: readonly ChangeBatch[], batch: ChangeBatch, limits: readonly ProviderLimit[], state: VisibleOver): Generator<number, SaveRefusal | null, void>;
70
+ export declare const MOVE_DOCUMENTS = "move-documents";
71
+ export type MoveSide = {
72
+ room: string;
73
+ handle: string;
74
+ baseRoomVersion: string;
75
+ composition: Composition;
76
+ rule: WriteRule;
77
+ visible: VisibleLayer;
78
+ folders: ReadonlySet<string>;
79
+ queued: ReadonlySet<string>;
80
+ unmodeled: boolean;
81
+ validate: Validator;
82
+ };
83
+ export type MoveInput = {
84
+ source: MoveSide;
85
+ destination: MoveSide;
86
+ moves: readonly {
87
+ readonly path: string;
88
+ readonly to: string;
89
+ }[];
90
+ providerLimits: readonly ProviderLimit[];
91
+ local: boolean;
92
+ writtenBy?: WrittenBy;
93
+ };
94
+ export type MoveResult = {
95
+ kind: 'moved';
96
+ leaving: ChangeBatch;
97
+ arriving: ChangeBatch;
98
+ } | Refusing;
99
+ export declare function buildMove(input: MoveInput): Promise<MoveResult>;
100
+ export declare function buildBatch(input: SaveInput): Promise<BatchResult>;
101
+ export {};
33
102
  //# sourceMappingURL=save.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,SAAS,WAAW,EA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