@agentshouse/mdruntime 0.1.0-cef5833f6c689 → 0.1.0-cf04ede9fb796

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 (247) hide show
  1. package/README.md +1 -1
  2. package/dist/acceptance.d.ts +6 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +389 -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 +24 -21
  9. package/dist/adapter.d.ts.map +1 -1
  10. package/dist/attached-model.d.ts +3 -10
  11. package/dist/attached-model.d.ts.map +1 -1
  12. package/dist/attached-model.js +21 -56
  13. package/dist/bootstrap.d.ts +8 -4
  14. package/dist/bootstrap.d.ts.map +1 -1
  15. package/dist/bootstrap.js +207 -76
  16. package/dist/cell.d.ts +6 -0
  17. package/dist/cell.d.ts.map +1 -0
  18. package/dist/cell.js +9 -0
  19. package/dist/change.d.ts +1 -0
  20. package/dist/change.d.ts.map +1 -1
  21. package/dist/chat-types.d.ts +5 -0
  22. package/dist/chat-types.d.ts.map +1 -0
  23. package/dist/chat-types.js +13 -0
  24. package/dist/client.d.ts +15 -1
  25. package/dist/client.d.ts.map +1 -1
  26. package/dist/client.js +3 -0
  27. package/dist/compile.d.ts +5 -0
  28. package/dist/compile.d.ts.map +1 -1
  29. package/dist/compile.js +189 -61
  30. package/dist/connection.d.ts +5 -141
  31. package/dist/connection.d.ts.map +1 -1
  32. package/dist/connection.js +101 -5175
  33. package/dist/conversation-live.d.ts +136 -0
  34. package/dist/conversation-live.d.ts.map +1 -0
  35. package/dist/conversation-live.js +248 -0
  36. package/dist/conversation-row.d.ts +33 -0
  37. package/dist/conversation-row.d.ts.map +1 -0
  38. package/dist/conversation-row.js +53 -0
  39. package/dist/conversation.d.ts +29 -34
  40. package/dist/conversation.d.ts.map +1 -1
  41. package/dist/conversation.js +838 -821
  42. package/dist/discovery.d.ts +10 -0
  43. package/dist/discovery.d.ts.map +1 -0
  44. package/dist/discovery.js +175 -0
  45. package/dist/durability.d.ts +15 -0
  46. package/dist/durability.d.ts.map +1 -1
  47. package/dist/entry.d.ts.map +1 -1
  48. package/dist/entry.js +4 -3
  49. package/dist/figures.d.ts +49 -0
  50. package/dist/figures.d.ts.map +1 -0
  51. package/dist/figures.js +197 -0
  52. package/dist/holdings.d.ts +29 -0
  53. package/dist/holdings.d.ts.map +1 -0
  54. package/dist/holdings.js +95 -0
  55. package/dist/host.d.ts +1 -0
  56. package/dist/host.d.ts.map +1 -1
  57. package/dist/host.js +11 -4
  58. package/dist/index.d.ts +20 -6
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +5 -1
  61. package/dist/install.d.ts +56 -0
  62. package/dist/install.d.ts.map +1 -0
  63. package/dist/install.js +556 -0
  64. package/dist/job.d.ts +20 -1
  65. package/dist/job.d.ts.map +1 -1
  66. package/dist/job.js +26 -0
  67. package/dist/lifecycle.d.ts +7 -0
  68. package/dist/lifecycle.d.ts.map +1 -0
  69. package/dist/lifecycle.js +268 -0
  70. package/dist/listing.d.ts +53 -0
  71. package/dist/listing.d.ts.map +1 -0
  72. package/dist/listing.js +176 -0
  73. package/dist/live.d.ts +4 -4
  74. package/dist/live.d.ts.map +1 -1
  75. package/dist/live.js +53 -15
  76. package/dist/locks.d.ts +9 -0
  77. package/dist/locks.d.ts.map +1 -0
  78. package/dist/locks.js +61 -0
  79. package/dist/log.d.ts +1 -0
  80. package/dist/log.d.ts.map +1 -1
  81. package/dist/lost.d.ts +5 -0
  82. package/dist/lost.d.ts.map +1 -0
  83. package/dist/lost.js +61 -0
  84. package/dist/memory.d.ts +3 -1
  85. package/dist/memory.d.ts.map +1 -1
  86. package/dist/memory.js +43 -3
  87. package/dist/messages.d.ts +25 -1
  88. package/dist/messages.d.ts.map +1 -1
  89. package/dist/messages.js +82 -3
  90. package/dist/model.d.ts +1 -7
  91. package/dist/model.d.ts.map +1 -1
  92. package/dist/model.js +0 -6
  93. package/dist/models.d.ts +14 -0
  94. package/dist/models.d.ts.map +1 -0
  95. package/dist/models.js +195 -0
  96. package/dist/opening.d.ts +4 -0
  97. package/dist/opening.d.ts.map +1 -0
  98. package/dist/opening.js +57 -0
  99. package/dist/outcome.d.ts +4 -1
  100. package/dist/outcome.d.ts.map +1 -1
  101. package/dist/outcome.js +3 -0
  102. package/dist/overlay.d.ts +1 -0
  103. package/dist/overlay.d.ts.map +1 -1
  104. package/dist/overlay.js +11 -0
  105. package/dist/parts.d.ts +60 -0
  106. package/dist/parts.d.ts.map +1 -0
  107. package/dist/parts.js +126 -0
  108. package/dist/paths.d.ts +1 -0
  109. package/dist/paths.d.ts.map +1 -1
  110. package/dist/paths.js +22 -0
  111. package/dist/preparation.d.ts +20 -0
  112. package/dist/preparation.d.ts.map +1 -0
  113. package/dist/preparation.js +226 -0
  114. package/dist/queries.d.ts +16 -0
  115. package/dist/queries.d.ts.map +1 -0
  116. package/dist/queries.js +272 -0
  117. package/dist/query.d.ts +10 -1
  118. package/dist/query.d.ts.map +1 -1
  119. package/dist/questions.d.ts +34 -0
  120. package/dist/questions.d.ts.map +1 -0
  121. package/dist/questions.js +122 -0
  122. package/dist/reach.d.ts +8 -6
  123. package/dist/reach.d.ts.map +1 -1
  124. package/dist/reach.js +159 -100
  125. package/dist/react.d.ts +7 -1
  126. package/dist/react.d.ts.map +1 -1
  127. package/dist/read.d.ts +7 -0
  128. package/dist/read.d.ts.map +1 -0
  129. package/dist/read.js +17 -0
  130. package/dist/readiness.d.ts +0 -1
  131. package/dist/readiness.d.ts.map +1 -1
  132. package/dist/reads.d.ts +37 -0
  133. package/dist/reads.d.ts.map +1 -0
  134. package/dist/reads.js +171 -0
  135. package/dist/recovery.d.ts.map +1 -1
  136. package/dist/recovery.js +9 -1
  137. package/dist/refresh.d.ts +1 -1
  138. package/dist/refresh.d.ts.map +1 -1
  139. package/dist/refresh.js +8 -20
  140. package/dist/refusal.d.ts +5 -0
  141. package/dist/refusal.d.ts.map +1 -0
  142. package/dist/refusal.js +56 -0
  143. package/dist/replica.d.ts +7 -7
  144. package/dist/replica.d.ts.map +1 -1
  145. package/dist/replica.js +50 -18
  146. package/dist/room-drafts.d.ts +24 -0
  147. package/dist/room-drafts.d.ts.map +1 -0
  148. package/dist/room-drafts.js +216 -0
  149. package/dist/rows.d.ts +14 -5
  150. package/dist/rows.d.ts.map +1 -1
  151. package/dist/rows.js +50 -58
  152. package/dist/runtime.d.ts +43 -0
  153. package/dist/runtime.d.ts.map +1 -0
  154. package/dist/runtime.js +1 -0
  155. package/dist/save.d.ts +5 -1
  156. package/dist/save.d.ts.map +1 -1
  157. package/dist/save.js +19 -13
  158. package/dist/saves.d.ts +70 -0
  159. package/dist/saves.d.ts.map +1 -0
  160. package/dist/saves.js +1008 -0
  161. package/dist/seed.d.ts +11 -2
  162. package/dist/seed.d.ts.map +1 -1
  163. package/dist/seed.js +71 -0
  164. package/dist/shared.d.ts +1 -1
  165. package/dist/shared.d.ts.map +1 -1
  166. package/dist/shared.js +9 -5
  167. package/dist/shown.d.ts +31 -0
  168. package/dist/shown.d.ts.map +1 -0
  169. package/dist/shown.js +295 -0
  170. package/dist/socket/admission.d.ts +7 -0
  171. package/dist/socket/admission.d.ts.map +1 -0
  172. package/dist/socket/admission.js +39 -0
  173. package/dist/socket/answers.d.ts +6 -0
  174. package/dist/socket/answers.d.ts.map +1 -0
  175. package/dist/socket/answers.js +20 -0
  176. package/dist/socket/lanes.d.ts +20 -0
  177. package/dist/socket/lanes.d.ts.map +1 -0
  178. package/dist/socket/lanes.js +77 -0
  179. package/dist/socket/reads.d.ts +10 -0
  180. package/dist/socket/reads.d.ts.map +1 -0
  181. package/dist/socket/reads.js +31 -0
  182. package/dist/socket/rooms.d.ts +44 -0
  183. package/dist/socket/rooms.d.ts.map +1 -0
  184. package/dist/socket/rooms.js +90 -0
  185. package/dist/socket/session.d.ts +39 -0
  186. package/dist/socket/session.d.ts.map +1 -0
  187. package/dist/socket/session.js +23 -0
  188. package/dist/socket.d.ts +70 -0
  189. package/dist/socket.d.ts.map +1 -0
  190. package/dist/socket.js +175 -0
  191. package/dist/source.d.ts +61 -0
  192. package/dist/source.d.ts.map +1 -0
  193. package/dist/source.js +81 -0
  194. package/dist/status.d.ts +0 -2
  195. package/dist/status.d.ts.map +1 -1
  196. package/dist/status.js +0 -6
  197. package/dist/store/fences.d.ts +16 -0
  198. package/dist/store/fences.d.ts.map +1 -0
  199. package/dist/store/fences.js +26 -0
  200. package/dist/store/installs.d.ts +30 -0
  201. package/dist/store/installs.d.ts.map +1 -0
  202. package/dist/store/installs.js +34 -0
  203. package/dist/store/readiness.d.ts +10 -0
  204. package/dist/store/readiness.d.ts.map +1 -0
  205. package/dist/store/readiness.js +52 -0
  206. package/dist/store/records.d.ts +212 -0
  207. package/dist/store/records.d.ts.map +1 -0
  208. package/dist/store/records.js +431 -0
  209. package/dist/store/room-held.d.ts +8 -0
  210. package/dist/store/room-held.d.ts.map +1 -0
  211. package/dist/store/room-held.js +17 -0
  212. package/dist/store/space.d.ts +11 -0
  213. package/dist/store/space.d.ts.map +1 -0
  214. package/dist/store/space.js +43 -0
  215. package/dist/store/watchers.d.ts +17 -0
  216. package/dist/store/watchers.d.ts.map +1 -0
  217. package/dist/store/watchers.js +57 -0
  218. package/dist/store/writes.d.ts +24 -0
  219. package/dist/store/writes.d.ts.map +1 -0
  220. package/dist/store/writes.js +125 -0
  221. package/dist/store.d.ts +107 -152
  222. package/dist/store.d.ts.map +1 -1
  223. package/dist/store.js +143 -394
  224. package/dist/stored.d.ts +58 -64
  225. package/dist/stored.d.ts.map +1 -1
  226. package/dist/stored.js +253 -147
  227. package/dist/surface.d.ts +88 -0
  228. package/dist/surface.d.ts.map +1 -0
  229. package/dist/surface.js +223 -0
  230. package/dist/sync.d.ts +19 -0
  231. package/dist/sync.d.ts.map +1 -0
  232. package/dist/sync.js +532 -0
  233. package/dist/tables.d.ts +114 -49
  234. package/dist/tables.d.ts.map +1 -1
  235. package/dist/tables.js +203 -49
  236. package/dist/tallies.d.ts +18 -0
  237. package/dist/tallies.d.ts.map +1 -0
  238. package/dist/tallies.js +129 -0
  239. package/dist/validation.d.ts.map +1 -1
  240. package/dist/validation.js +4 -4
  241. package/dist/wire.d.ts +16 -1
  242. package/dist/wire.d.ts.map +1 -1
  243. package/dist/wire.js +6 -0
  244. package/package.json +2 -2
  245. package/dist/fence.d.ts +0 -6
  246. package/dist/fence.d.ts.map +0 -1
  247. package/dist/fence.js +0 -10
package/dist/replica.js CHANGED
@@ -3,7 +3,9 @@ import { immutable, landing } from './change.js';
3
3
  import { collectionOf } from './collection.js';
4
4
  import { storedModel } from './model.js';
5
5
  import { acceptedBinaries, overlaying } from './overlay.js';
6
+ import { writtenFacts } from './rows.js';
6
7
  import { effectiveIn, rewriting } from './save.js';
8
+ import { guarding } from './shared.js';
7
9
  import { ROW_WEIGHT } from './turn.js';
8
10
  export function compositionOf(record, builtIn, typedPaths) {
9
11
  return {
@@ -36,7 +38,7 @@ function strict(values, held) {
36
38
  throw new UnreadPath(property);
37
39
  }
38
40
  };
39
- return new Proxy(values, {
41
+ return guarding(values, {
40
42
  get(target, property, receiver) {
41
43
  guard(property);
42
44
  return Reflect.get(target, property, receiver);
@@ -59,9 +61,13 @@ export function* slicing(entries, paths) {
59
61
  const binaries = {};
60
62
  const revisions = {};
61
63
  const fileIds = {};
64
+ const created = {};
62
65
  const changes = {};
63
66
  const written = {};
67
+ const facts = {};
64
68
  for (const entry of entries) {
69
+ if (entry.facts !== null)
70
+ facts[entry.path] = entry.facts;
65
71
  if (entry.binary !== null)
66
72
  binaries[entry.path] = entry.binary;
67
73
  else if (entry.content !== null)
@@ -70,6 +76,8 @@ export function* slicing(entries, paths) {
70
76
  revisions[entry.path] = entry.revision;
71
77
  if (entry.fileId !== null)
72
78
  fileIds[entry.path] = entry.fileId;
79
+ if (entry.created !== null)
80
+ created[entry.path] = entry.created;
73
81
  if (entry.change !== null)
74
82
  changes[entry.path] = entry.change;
75
83
  if (entry.written !== null)
@@ -81,8 +89,10 @@ export function* slicing(entries, paths) {
81
89
  binaries: strict(binaries, held),
82
90
  revisions: strict(revisions, held),
83
91
  fileIds: strict(fileIds, held),
92
+ created: strict(created, held),
84
93
  changes: strict(changes, held),
85
94
  written: strict(written, held),
95
+ facts: strict(facts, held),
86
96
  held,
87
97
  };
88
98
  }
@@ -94,10 +104,10 @@ export function entryAt(layer, path) {
94
104
  return {
95
105
  path,
96
106
  content: content ?? null,
97
- outline: null,
98
107
  binary: binary ?? null,
99
108
  revision: layer.revisions[path] ?? null,
100
109
  fileId: layer.fileIds[path] ?? null,
110
+ created: layer.created[path] ?? null,
101
111
  change: layer.changes[path] ?? null,
102
112
  written: layer.written?.[path] ?? null,
103
113
  };
@@ -106,8 +116,9 @@ export function* slicingWith(slice, set, removed) {
106
116
  const entries = new Map();
107
117
  for (const path of slice.held) {
108
118
  const entry = entryAt(slice, path);
109
- if (entry !== null)
110
- entries.set(path, { ...entry, type: null });
119
+ if (entry !== null) {
120
+ entries.set(path, { ...entry, type: null, facts: slice.facts[path] ?? null });
121
+ }
111
122
  yield ROW_WEIGHT;
112
123
  }
113
124
  for (const path of removed)
@@ -171,21 +182,28 @@ export function* replaying(confirmed, queue, locator, composition) {
171
182
  export function* overlayOf(visible, touched) {
172
183
  const rows = [];
173
184
  for (const path of touched) {
174
- yield ROW_WEIGHT;
175
185
  const entry = entryAt(visible, path);
186
+ yield ROW_WEIGHT + (entry?.content?.length ?? 0);
187
+ const text = entry?.binary === null ? entry.content : null;
176
188
  rows.push(entry === null
177
189
  ? {
178
190
  path,
179
191
  present: false,
180
192
  content: null,
181
- outline: null,
182
193
  binary: null,
183
194
  revision: null,
184
195
  fileId: null,
196
+ created: null,
185
197
  change: null,
186
198
  written: null,
199
+ facts: null,
187
200
  }
188
- : { ...entry, written: null, present: true });
201
+ : {
202
+ ...entry,
203
+ written: null,
204
+ present: true,
205
+ facts: text === null ? null : writtenFacts(path, text, visible.collection.composition),
206
+ });
189
207
  }
190
208
  return rows;
191
209
  }
@@ -350,17 +368,20 @@ export function returnedPaths(submitted, accepted) {
350
368
  }
351
369
  return paths;
352
370
  }
353
- export function* returning(confirmed, submitted, accepted, writtenAt) {
371
+ export function* returning(confirmed, submitted, accepted, writtenAt, composition) {
354
372
  const documents = new Map();
355
373
  const binaries = new Map();
356
374
  const revisions = new Map();
357
375
  const fileIds = new Map();
376
+ const created = new Map();
358
377
  const changes = new Map();
359
378
  const written = new Map();
379
+ const facts = new Map();
360
380
  const read = (changed, held, path) => (changed.has(path) ? changed.get(path) : held[path]);
361
381
  for (const [path, content] of Object.entries(accepted.documents)) {
362
- yield ROW_WEIGHT;
382
+ yield ROW_WEIGHT + content.length;
363
383
  documents.set(path, content);
384
+ facts.set(path, writtenFacts(path, content, composition));
364
385
  fileIds.set(path, undefined);
365
386
  written.set(path, writtenAt);
366
387
  }
@@ -383,49 +404,60 @@ export function* returning(confirmed, submitted, accepted, writtenAt) {
383
404
  written.set(path, undefined);
384
405
  }
385
406
  for (const change of submitted.changes) {
386
- if (change.kind === 'arrival' && 'binary' in change) {
387
- if (accepted.revisions[change.path] !== undefined) {
407
+ if (change.kind === 'arrival') {
408
+ if (accepted.revisions[change.path] === undefined)
409
+ continue;
410
+ created.set(change.path, change.created);
411
+ if ('binary' in change)
388
412
  binaries.set(change.path, { state: 'accepted', ...change.binary });
389
- }
390
413
  continue;
391
414
  }
392
- if (change.kind !== 'move')
415
+ if (change.kind !== 'move' || accepted.revisions[change.to] === undefined)
393
416
  continue;
417
+ created.set(change.to, read(created, confirmed.created, change.path));
418
+ created.set(change.path, undefined);
394
419
  const moved = read(binaries, confirmed.binaries, change.path);
395
- if (moved === undefined || accepted.revisions[change.to] === undefined)
420
+ if (moved === undefined)
396
421
  continue;
397
422
  binaries.set(change.to, moved);
398
423
  binaries.set(change.path, undefined);
399
424
  }
400
425
  for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {}))
401
426
  binaries.set(path, binary);
402
- for (const path of accepted.removals)
427
+ for (const path of accepted.removals) {
403
428
  binaries.set(path, undefined);
429
+ created.set(path, undefined);
430
+ }
404
431
  const paths = new Set([
405
432
  ...documents.keys(),
406
433
  ...binaries.keys(),
407
434
  ...revisions.keys(),
408
435
  ...fileIds.keys(),
436
+ ...created.keys(),
409
437
  ...changes.keys(),
410
438
  ...written.keys(),
411
439
  ]);
412
440
  const set = [];
413
441
  const removed = [];
414
442
  for (const path of paths) {
415
- yield ROW_WEIGHT;
416
443
  const content = read(documents, confirmed.documents, path);
417
444
  const binary = read(binaries, confirmed.binaries, path);
445
+ yield ROW_WEIGHT;
418
446
  if (content === undefined && binary === undefined) {
419
447
  removed.push(path);
420
448
  continue;
421
449
  }
450
+ const text = binary === undefined ? (content ?? null) : null;
451
+ const fresh = confirmed.documents[path] === undefined && confirmed.binaries[path] === undefined;
422
452
  set.push({
423
453
  path,
424
- content: binary === undefined ? (content ?? null) : null,
425
- outline: null,
454
+ content: text,
455
+ facts: text === null ? null : (read(facts, confirmed.facts, path) ?? null),
426
456
  binary: binary ?? null,
427
457
  revision: read(revisions, confirmed.revisions, path) ?? null,
428
458
  fileId: read(fileIds, confirmed.fileIds, path) ?? null,
459
+ created: read(created, confirmed.created, path) ??
460
+ (fresh ? (read(changes, confirmed.changes, path)?.time ?? null) : null),
429
461
  change: read(changes, confirmed.changes, path) ?? null,
430
462
  written: read(written, confirmed.written, path) ?? null,
431
463
  });
@@ -0,0 +1,24 @@
1
+ import { type ChangeSet } from './change-set.js';
2
+ import { type VisibleLayer } from './replica.js';
3
+ import { type RoomDraft, type RoomDraftWrite } from './room-draft.js';
4
+ import type { Runtime } from './runtime.js';
5
+ import type { Store } from './store.js';
6
+ export type RoomDraftSurface = {
7
+ list(): Promise<readonly RoomDraft[]>;
8
+ read(room: string, path: string): Promise<RoomDraft | null>;
9
+ write(room: string, path: string, revision: string | null, parts: unknown, next?: string): Promise<RoomDraftWrite>;
10
+ discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
11
+ };
12
+ export type PresentationSurface = {
13
+ read(app: string): Promise<unknown>;
14
+ write(app: string, value: unknown): Promise<void>;
15
+ edit(app: string, members: Readonly<Record<string, unknown>>): Promise<void>;
16
+ };
17
+ export declare function visibleOf(store: Store, locator: string, paths: readonly string[]): Promise<VisibleLayer | undefined>;
18
+ export declare function publishRoomDrafts({ store, socket }: Runtime, waitingOnly: boolean, touched?: ChangeSet['documents'] | null): Promise<void>;
19
+ export declare function emitPresentation({ store, socket }: Runtime, app: string): Promise<void>;
20
+ export declare function roomDraftSurface(runtime: Runtime): RoomDraftSurface;
21
+ export declare function presentationSurface(runtime: Runtime): PresentationSurface;
22
+ export declare function watchRoomDrafts({ store, socket }: Runtime, deliver: (value: unknown) => void): () => void;
23
+ export declare function watchPresentation({ store, socket }: Runtime, app: string, deliver: (value: unknown) => void): () => void;
24
+ //# sourceMappingURL=room-drafts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-drafts.d.ts","sourceRoot":"","sources":["../src/room-drafts.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5D,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAQL,KAAK,SAAS,EAEd,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,IAAI,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;IACtC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAC5D,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,IAAI,EAA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AAmB,CA0BzE;AAED,wBAAgB,eAAe,CAC7B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAChC,MAAM,IAAI,CAiBZ;AAED,wBAAgB,iBAAiB,CAC/B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAChC,MAAM,IAAI,CASZ"}
@@ -0,0 +1,216 @@
1
+ import { plain } from '@agentshouse/mdmodel';
2
+ import { changeSet } from './change-set.js';
3
+ import { collectionOf } from './collection.js';
4
+ import { runtimeError } 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] ?? null));
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] ?? null };
122
+ }
123
+ async function keptPresentation({ store }, app, next) {
124
+ const local = await store.open();
125
+ const stored = next(await local.presentation(app));
126
+ await local.present({ app, value: stored });
127
+ await store.changed(changeSet('', { presentation: app }));
128
+ }
129
+ export function roomDraftSurface(runtime) {
130
+ const { store } = runtime;
131
+ return {
132
+ list() {
133
+ return store
134
+ .exclusive(async () => {
135
+ await store.open();
136
+ return snapshotRoomDrafts(store);
137
+ })
138
+ .then((listed) => {
139
+ publishRoomDrafts(runtime, true);
140
+ return listed;
141
+ });
142
+ },
143
+ async read(room, path) {
144
+ const record = await store.draft(room, path);
145
+ return record === undefined ? null : ((await roomDraftsOf(store, [record]))[0] ?? null);
146
+ },
147
+ write(room, path, revision, input, next = roomDraftRevision()) {
148
+ if (typeof next !== 'string' || next === '')
149
+ return Promise.reject(runtimeError('room-draft-malformed'));
150
+ return store.gathered(`room-draft\u0000${room}\u0000${path}`, { revision, input, next }, (earlier, later) => {
151
+ if (later.revision !== earlier.next)
152
+ return null;
153
+ const parts = gatheredParts(earlier.input, later.input);
154
+ return parts === null
155
+ ? null
156
+ : { revision: earlier.revision, input: parts, next: later.next };
157
+ }, (written) => writtenRoomDraft(runtime, room, path, written.revision, written.input, written.next));
158
+ },
159
+ discard(room, path, revision) {
160
+ return store.exclusive(async () => {
161
+ const local = await store.open();
162
+ const current = await store.draft(room, path);
163
+ if (current === undefined || current.revision !== revision) {
164
+ return staleWrite(current === undefined ? null : ((await roomDraftsOf(store, [current]))[0] ?? null));
165
+ }
166
+ await local.discardRoomDraft(room, path);
167
+ await store.changed(changeSet(room, { drafts: [path] }));
168
+ return { outcome: 'written', roomDraft: null };
169
+ });
170
+ },
171
+ };
172
+ }
173
+ export function presentationSurface(runtime) {
174
+ const { store } = runtime;
175
+ return {
176
+ read(app) {
177
+ return store.exclusive(() => presentationOf(store, app));
178
+ },
179
+ write(app, value) {
180
+ return store.exclusive(() => keptPresentation(runtime, app, () => structuredClone(value)));
181
+ },
182
+ edit(app, members) {
183
+ return store.gathered(`presentation\u0000${app}`, structuredClone(members), (earlier, later) => ({ ...earlier, ...later }), (edited) => keptPresentation(runtime, app, (kept) => 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
+ export function watchRoomDrafts({ store, socket }, deliver) {
191
+ const watcher = store.watch(ROOM_DRAFTS, deliver);
192
+ const unwatched = () => socket.closed() || !watcher.held();
193
+ void store
194
+ .exclusive(async () => {
195
+ await store.open();
196
+ })
197
+ .then(() => store.publication(async () => {
198
+ if (unwatched())
199
+ return;
200
+ const value = await snapshotRoomDrafts(store);
201
+ if (!unwatched())
202
+ watcher.answer(value);
203
+ }), () => { });
204
+ return watcher.stop;
205
+ }
206
+ export function watchPresentation({ store, socket }, app, deliver) {
207
+ const watcher = store.watch(presentationTopic(app), deliver);
208
+ void store
209
+ .exclusive(async () => {
210
+ const value = await presentationOf(store, app);
211
+ if (!socket.closed() && watcher.held())
212
+ watcher.answer(value);
213
+ })
214
+ .catch(() => { });
215
+ return watcher.stop;
216
+ }
package/dist/rows.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { type HeldValue, type Outline } from '@agentshouse/mdmodel';
1
+ import { type HeldValue } from '@agentshouse/mdmodel';
2
+ import type { SavedFacts } from './adapter.js';
2
3
  import { type Composition } from './collection.js';
3
- type LinkKind = 'field' | 'section' | 'body';
4
+ type LinkKind = 'field' | 'link';
4
5
  type HeldLink = {
5
6
  readonly kind: LinkKind;
6
7
  readonly keys: string;
@@ -14,8 +15,14 @@ export type Described = {
14
15
  readonly queried: boolean;
15
16
  readonly folder: string;
16
17
  readonly fields: string | null;
18
+ readonly links: string | null;
17
19
  };
18
- export type Derived = Described & {
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 = {
19
26
  readonly values: readonly HeldValue[];
20
27
  readonly links: readonly HeldLink[];
21
28
  };
@@ -24,7 +31,9 @@ export declare function roomOfKey(key: string): string;
24
31
  export declare function pathOfKey(key: string): string;
25
32
  export declare function markdownPath(path: string): boolean;
26
33
  export declare function folderOf(path: string): string;
27
- export declare function described(path: string, content: string | null, outlined: Outline | null): Described;
28
- export declare function derived(path: string, content: string | null, outlined: Outline | null, composition: Composition): Derived;
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;
29
38
  export {};
30
39
  //# sourceMappingURL=rows.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,OAAO,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAa,KAAK,WAAW,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, documentFacts, indexed, parse } from '@agentshouse/mdmodel';
2
2
  import { governing } from './collection.js';
3
3
  import { definitionOf } from './model.js';
4
4
  function keyOf(...parts) {
@@ -19,68 +19,60 @@ export function markdownPath(path) {
19
19
  export function folderOf(path) {
20
20
  return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
21
21
  }
22
- function bodyOf(targets) {
23
- return targets.map((target) => ({ kind: 'body', keys: '', places: '', target, field: '' }));
22
+ function byKey(_key, value) {
23
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
24
+ return value;
25
+ return Object.fromEntries(Object.entries(value).sort(([one], [other]) => byCodePoint(one, other)));
24
26
  }
25
- function typedRows(path, content, document, composition, body) {
26
- const definition = definitionOf(governing(composition, path), document.type);
27
- const { values, links: fields } = indexed(path, document.fields, definition);
28
- const links = [...fields];
29
- if (definition !== undefined && content !== null) {
30
- const sectioned = new Set();
31
- for (const { target: reached } of sectionReferences(path, content, definition)) {
32
- if (reached === null || sectioned.has(reached))
33
- continue;
34
- sectioned.add(reached);
35
- links.push({ kind: 'section', keys: '', places: '', target: reached, field: '' });
36
- }
37
- }
38
- return { values, links: [...links, ...body] };
27
+ function fieldsText(fields) {
28
+ return JSON.stringify(fields, byKey);
39
29
  }
40
- function readOf(path, declared, document) {
30
+ export function writtenFacts(path, content, composition) {
31
+ const model = governing(composition, path);
32
+ const facts = documentFacts(path, parse(content, path), {
33
+ types: model.status === 'unavailable' ? {} : model.types,
34
+ });
35
+ return facts === null
36
+ ? null
37
+ : { ...facts, fields: JSON.parse(fieldsText(facts.fields)) };
38
+ }
39
+ export function described(path, content, facts) {
41
40
  const folder = folderOf(path);
42
- const unread = { fields: null, folder, type: null };
43
- if (!markdownPath(path) || document === null) {
44
- return { described: { ...unread, declared, queried: !markdownPath(path) }, document: null };
45
- }
41
+ const unread = { type: null, fields: null, links: null, folder };
42
+ if (content === null)
43
+ return { ...unread, declared: null, queried: true };
44
+ if (facts === null)
45
+ return { ...unread, declared: null, queried: !markdownPath(path) };
46
+ const links = JSON.stringify(facts.links);
47
+ if (!markdownPath(path))
48
+ return { ...unread, declared: facts.type, queried: true, links };
46
49
  return {
47
- described: {
48
- type: document.type ?? 'any',
49
- declared,
50
- queried: true,
51
- folder,
52
- fields: JSON.stringify(document.fields),
53
- },
54
- document,
50
+ type: facts.type,
51
+ declared: facts.type,
52
+ queried: true,
53
+ folder,
54
+ fields: fieldsText(facts.fields),
55
+ links,
55
56
  };
56
57
  }
57
- function read(path, content, outlined) {
58
- const held = content === null ? outlined : outline(content, path);
59
- if (held === null) {
60
- return {
61
- described: {
62
- fields: null,
63
- folder: folderOf(path),
64
- type: null,
65
- declared: null,
66
- queried: true,
67
- },
68
- document: null,
69
- links: [],
70
- };
71
- }
72
- const type = held.type === null || held.type === 'any' ? undefined : held.type;
73
- const document = held.fields === null ? null : { type, fields: held.fields };
74
- return { ...readOf(path, held.type, document), links: held.links };
75
- }
76
- export function described(path, content, outlined) {
77
- return read(path, content, outlined).described;
58
+ export function heldOf(path, content, facts) {
59
+ if (content === null || facts === null)
60
+ return { type: null, fields: null, links: [] };
61
+ return markdownPath(path)
62
+ ? { type: facts.type, fields: facts.fields, links: facts.links }
63
+ : { type: null, fields: null, links: facts.links };
78
64
  }
79
- export function derived(path, content, outlined, composition) {
80
- const { described: columns, document, links } = read(path, content, outlined);
81
- const body = bodyOf(links);
82
- if (document !== null) {
83
- return { ...columns, ...typedRows(path, content, document, composition, body) };
84
- }
85
- return { ...columns, values: [], links: markdownPath(path) ? [] : body };
65
+ export function derived(path, held, composition) {
66
+ const stored = held.links.map((target) => ({
67
+ kind: 'link',
68
+ keys: '',
69
+ places: '',
70
+ target,
71
+ field: '',
72
+ }));
73
+ if (held.type === null || held.fields === null)
74
+ return { values: [], links: stored };
75
+ const definition = definitionOf(governing(composition, path), held.type);
76
+ const { values, links: fields } = indexed(path, held.fields, definition);
77
+ return { values, links: [...fields, ...stored] };
86
78
  }
@@ -0,0 +1,43 @@
1
+ import type { Authorization, DiscoveredRoom, PathRule, ScopedRefusal, TypedPath } from './adapter.js';
2
+ import type { ChangeSet } from './change-set.js';
3
+ import type { ChangeBatch } from './change.js';
4
+ import type { RuntimeShell } from './durability.js';
5
+ import type { LiveConversations } from './conversation-live.js';
6
+ import type { FiguresRead } from './figures.js';
7
+ import type { Withheld } from './install.js';
8
+ import type { LiveQueries } from './live.js';
9
+ import type { Log } from './log.js';
10
+ import type { ModelState } from './model.js';
11
+ import type { ReadAnswers } from './reads.js';
12
+ import type { Recovery } from './recovery.js';
13
+ import type { ReplicaRecord } from './replica.js';
14
+ import type { RuntimeSocket, RoomDeclaration } from './socket.js';
15
+ import type { CycleProgress } from './status.js';
16
+ import type { Settling } from './saves.js';
17
+ import type { HeldCover, RuntimeStore, Store, Work } from './store.js';
18
+ import type { schemaTypes } from './attached-model.js';
19
+ export type Runtime = {
20
+ readonly store: Store;
21
+ readonly socket: RuntimeSocket;
22
+ readonly journal: Log;
23
+ readonly recovery: Recovery;
24
+ readonly shell: RuntimeShell;
25
+ readonly localSaves: boolean;
26
+ readonly roomTypes: Parameters<typeof schemaTypes>[1];
27
+ readonly builtIn: ModelState;
28
+ readonly typedPaths: readonly TypedPath[];
29
+ readonly pathRule: PathRule;
30
+ readonly usableWhenHeld: readonly string[];
31
+ readonly build: string;
32
+ readonly conversations: LiveConversations;
33
+ readonly liveQueries: LiveQueries<HeldCover>;
34
+ readonly figures: FiguresRead;
35
+ readonly lastAnswers: ReadAnswers;
36
+ settle(local: RuntimeStore, locator: string, work: Work, record: ReplicaRecord, queue: readonly ChangeBatch[], settling?: Settling): Promise<ChangeSet>;
37
+ scoped(result: ScopedRefusal, room: RoomDeclaration, local: RuntimeStore): Promise<void>;
38
+ submitLater(locator: string): void;
39
+ unpair(local: RuntimeStore): Promise<void>;
40
+ advanced(room: DiscoveredRoom, local: RuntimeStore, authorized: Authorization): Promise<Withheld | null>;
41
+ withhold(withheld: Withheld, room: DiscoveredRoom, local: RuntimeStore, progress: CycleProgress): Promise<void>;
42
+ };
43
+ //# sourceMappingURL=runtime.d.ts.map