@agentshouse/mdruntime 0.1.0-cba6f2439bb25 → 0.1.0-cbbae1fff01c6

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 (303) hide show
  1. package/README.md +10 -10
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +308 -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 +95 -103
  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 +12 -11
  14. package/dist/bootstrap.d.ts.map +1 -1
  15. package/dist/bootstrap.js +213 -89
  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/chain.d.ts +2 -1
  20. package/dist/chain.d.ts.map +1 -1
  21. package/dist/change-set.d.ts +4 -0
  22. package/dist/change-set.d.ts.map +1 -1
  23. package/dist/change-set.js +6 -0
  24. package/dist/change.d.ts +1 -0
  25. package/dist/change.d.ts.map +1 -1
  26. package/dist/change.js +4 -2
  27. package/dist/chat-types.d.ts +5 -0
  28. package/dist/chat-types.d.ts.map +1 -0
  29. package/dist/chat-types.js +13 -0
  30. package/dist/client.d.ts +24 -7
  31. package/dist/client.d.ts.map +1 -1
  32. package/dist/client.js +9 -5
  33. package/dist/collection.d.ts +23 -7
  34. package/dist/collection.d.ts.map +1 -1
  35. package/dist/collection.js +13 -19
  36. package/dist/compile.d.ts +6 -6
  37. package/dist/compile.d.ts.map +1 -1
  38. package/dist/compile.js +272 -332
  39. package/dist/connection.d.ts +5 -143
  40. package/dist/connection.d.ts.map +1 -1
  41. package/dist/connection.js +105 -5253
  42. package/dist/context.d.ts +2 -0
  43. package/dist/context.d.ts.map +1 -0
  44. package/dist/context.js +7 -0
  45. package/dist/conversation-live.d.ts +135 -0
  46. package/dist/conversation-live.d.ts.map +1 -0
  47. package/dist/conversation-live.js +247 -0
  48. package/dist/conversation-row.d.ts +33 -0
  49. package/dist/conversation-row.d.ts.map +1 -0
  50. package/dist/conversation-row.js +53 -0
  51. package/dist/conversation.d.ts +41 -47
  52. package/dist/conversation.d.ts.map +1 -1
  53. package/dist/conversation.js +874 -911
  54. package/dist/declaration.d.ts +10 -0
  55. package/dist/declaration.d.ts.map +1 -0
  56. package/dist/declaration.js +24 -0
  57. package/dist/discovery.d.ts +10 -0
  58. package/dist/discovery.d.ts.map +1 -0
  59. package/dist/discovery.js +148 -0
  60. package/dist/durability.d.ts +15 -1
  61. package/dist/durability.d.ts.map +1 -1
  62. package/dist/entry.d.ts +2 -2
  63. package/dist/entry.d.ts.map +1 -1
  64. package/dist/entry.js +17 -7
  65. package/dist/expectation.d.ts +4 -2
  66. package/dist/expectation.d.ts.map +1 -1
  67. package/dist/expectation.js +33 -11
  68. package/dist/failure.d.ts +1 -0
  69. package/dist/failure.d.ts.map +1 -1
  70. package/dist/failure.js +3 -0
  71. package/dist/figures.d.ts +49 -0
  72. package/dist/figures.d.ts.map +1 -0
  73. package/dist/figures.js +197 -0
  74. package/dist/holdings.d.ts +29 -0
  75. package/dist/holdings.d.ts.map +1 -0
  76. package/dist/holdings.js +95 -0
  77. package/dist/host.d.ts +20 -8
  78. package/dist/host.d.ts.map +1 -1
  79. package/dist/host.js +44 -34
  80. package/dist/identity.d.ts +0 -1
  81. package/dist/identity.d.ts.map +1 -1
  82. package/dist/identity.js +0 -3
  83. package/dist/index.d.ts +28 -8
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +10 -1
  86. package/dist/install.d.ts +54 -0
  87. package/dist/install.d.ts.map +1 -0
  88. package/dist/install.js +538 -0
  89. package/dist/job.d.ts +5 -0
  90. package/dist/job.d.ts.map +1 -0
  91. package/dist/job.js +7 -0
  92. package/dist/lifecycle.d.ts +7 -0
  93. package/dist/lifecycle.d.ts.map +1 -0
  94. package/dist/lifecycle.js +272 -0
  95. package/dist/listing.d.ts +48 -0
  96. package/dist/listing.d.ts.map +1 -0
  97. package/dist/listing.js +139 -0
  98. package/dist/live.d.ts +5 -4
  99. package/dist/live.d.ts.map +1 -1
  100. package/dist/live.js +64 -23
  101. package/dist/locks.d.ts +7 -0
  102. package/dist/locks.d.ts.map +1 -0
  103. package/dist/locks.js +33 -0
  104. package/dist/log.d.ts +1 -0
  105. package/dist/log.d.ts.map +1 -1
  106. package/dist/lost.d.ts +5 -0
  107. package/dist/lost.d.ts.map +1 -0
  108. package/dist/lost.js +50 -0
  109. package/dist/media.d.ts +2 -2
  110. package/dist/media.d.ts.map +1 -1
  111. package/dist/media.js +22 -12
  112. package/dist/memory.d.ts +14 -5
  113. package/dist/memory.d.ts.map +1 -1
  114. package/dist/memory.js +177 -85
  115. package/dist/messages.d.ts +24 -3
  116. package/dist/messages.d.ts.map +1 -1
  117. package/dist/messages.js +89 -31
  118. package/dist/model.d.ts +2 -11
  119. package/dist/model.d.ts.map +1 -1
  120. package/dist/model.js +0 -23
  121. package/dist/models.d.ts +10 -0
  122. package/dist/models.d.ts.map +1 -0
  123. package/dist/models.js +156 -0
  124. package/dist/observation.d.ts +2 -2
  125. package/dist/observation.d.ts.map +1 -1
  126. package/dist/observation.js +14 -14
  127. package/dist/opened.d.ts +1 -1
  128. package/dist/opened.d.ts.map +1 -1
  129. package/dist/opened.js +5 -5
  130. package/dist/opening.d.ts +4 -0
  131. package/dist/opening.d.ts.map +1 -0
  132. package/dist/opening.js +59 -0
  133. package/dist/outcome.d.ts +4 -4
  134. package/dist/outcome.d.ts.map +1 -1
  135. package/dist/outcome.js +3 -0
  136. package/dist/overlay.d.ts +3 -1
  137. package/dist/overlay.d.ts.map +1 -1
  138. package/dist/overlay.js +43 -21
  139. package/dist/parts.d.ts +11 -0
  140. package/dist/parts.d.ts.map +1 -0
  141. package/dist/parts.js +21 -0
  142. package/dist/paths.d.ts +1 -0
  143. package/dist/paths.d.ts.map +1 -1
  144. package/dist/paths.js +22 -0
  145. package/dist/preparation.d.ts +20 -0
  146. package/dist/preparation.d.ts.map +1 -0
  147. package/dist/preparation.js +233 -0
  148. package/dist/presence.d.ts +52 -0
  149. package/dist/presence.d.ts.map +1 -0
  150. package/dist/presence.js +220 -0
  151. package/dist/queries.d.ts +16 -0
  152. package/dist/queries.d.ts.map +1 -0
  153. package/dist/queries.js +270 -0
  154. package/dist/query.d.ts +14 -210
  155. package/dist/query.d.ts.map +1 -1
  156. package/dist/query.js +3 -505
  157. package/dist/questions.d.ts +34 -0
  158. package/dist/questions.d.ts.map +1 -0
  159. package/dist/questions.js +122 -0
  160. package/dist/queue.d.ts +40 -0
  161. package/dist/queue.d.ts.map +1 -0
  162. package/dist/queue.js +455 -0
  163. package/dist/reach.d.ts +15 -13
  164. package/dist/reach.d.ts.map +1 -1
  165. package/dist/reach.js +187 -140
  166. package/dist/react.d.ts +14 -2
  167. package/dist/react.d.ts.map +1 -1
  168. package/dist/react.js +10 -1
  169. package/dist/read.d.ts +7 -0
  170. package/dist/read.d.ts.map +1 -0
  171. package/dist/read.js +17 -0
  172. package/dist/readiness.d.ts +2 -16
  173. package/dist/readiness.d.ts.map +1 -1
  174. package/dist/readiness.js +4 -10
  175. package/dist/reads.d.ts +36 -10
  176. package/dist/reads.d.ts.map +1 -1
  177. package/dist/reads.js +160 -77
  178. package/dist/recovery.d.ts +1 -0
  179. package/dist/recovery.d.ts.map +1 -1
  180. package/dist/recovery.js +35 -1
  181. package/dist/refresh.d.ts +7 -5
  182. package/dist/refresh.d.ts.map +1 -1
  183. package/dist/refresh.js +35 -7
  184. package/dist/refusal.d.ts +5 -0
  185. package/dist/refusal.d.ts.map +1 -0
  186. package/dist/refusal.js +57 -0
  187. package/dist/replica.d.ts +11 -17
  188. package/dist/replica.d.ts.map +1 -1
  189. package/dist/replica.js +64 -34
  190. package/dist/room-draft.d.ts +7 -8
  191. package/dist/room-draft.d.ts.map +1 -1
  192. package/dist/room-draft.js +100 -103
  193. package/dist/room-drafts.d.ts +24 -0
  194. package/dist/room-drafts.d.ts.map +1 -0
  195. package/dist/room-drafts.js +217 -0
  196. package/dist/rows.d.ts +14 -21
  197. package/dist/rows.d.ts.map +1 -1
  198. package/dist/rows.js +49 -186
  199. package/dist/runtime.d.ts +34 -0
  200. package/dist/runtime.d.ts.map +1 -0
  201. package/dist/runtime.js +1 -0
  202. package/dist/save.d.ts +41 -86
  203. package/dist/save.d.ts.map +1 -1
  204. package/dist/save.js +239 -116
  205. package/dist/saves.d.ts +32 -0
  206. package/dist/saves.d.ts.map +1 -0
  207. package/dist/saves.js +413 -0
  208. package/dist/search.d.ts +12 -63
  209. package/dist/search.d.ts.map +1 -1
  210. package/dist/search.js +9 -52
  211. package/dist/seed.d.ts +11 -2
  212. package/dist/seed.d.ts.map +1 -1
  213. package/dist/seed.js +71 -1
  214. package/dist/shared.d.ts +1 -7
  215. package/dist/shared.d.ts.map +1 -1
  216. package/dist/shared.js +13 -105
  217. package/dist/shown.d.ts +32 -0
  218. package/dist/shown.d.ts.map +1 -0
  219. package/dist/shown.js +290 -0
  220. package/dist/socket/admission.d.ts +7 -0
  221. package/dist/socket/admission.d.ts.map +1 -0
  222. package/dist/socket/admission.js +39 -0
  223. package/dist/socket/answers.d.ts +6 -0
  224. package/dist/socket/answers.d.ts.map +1 -0
  225. package/dist/socket/answers.js +20 -0
  226. package/dist/socket/lanes.d.ts +20 -0
  227. package/dist/socket/lanes.d.ts.map +1 -0
  228. package/dist/socket/lanes.js +77 -0
  229. package/dist/socket/reads.d.ts +10 -0
  230. package/dist/socket/reads.d.ts.map +1 -0
  231. package/dist/socket/reads.js +31 -0
  232. package/dist/socket/session.d.ts +38 -0
  233. package/dist/socket/session.d.ts.map +1 -0
  234. package/dist/socket/session.js +23 -0
  235. package/dist/socket.d.ts +67 -0
  236. package/dist/socket.d.ts.map +1 -0
  237. package/dist/socket.js +170 -0
  238. package/dist/source.d.ts +61 -0
  239. package/dist/source.d.ts.map +1 -0
  240. package/dist/source.js +82 -0
  241. package/dist/status.d.ts +0 -6
  242. package/dist/status.d.ts.map +1 -1
  243. package/dist/status.js +0 -6
  244. package/dist/store/installs.d.ts +30 -0
  245. package/dist/store/installs.d.ts.map +1 -0
  246. package/dist/store/installs.js +34 -0
  247. package/dist/store/readiness.d.ts +10 -0
  248. package/dist/store/readiness.d.ts.map +1 -0
  249. package/dist/store/readiness.js +52 -0
  250. package/dist/store/records.d.ts +210 -0
  251. package/dist/store/records.d.ts.map +1 -0
  252. package/dist/store/records.js +428 -0
  253. package/dist/store/room-held.d.ts +8 -0
  254. package/dist/store/room-held.d.ts.map +1 -0
  255. package/dist/store/room-held.js +17 -0
  256. package/dist/store/space.d.ts +11 -0
  257. package/dist/store/space.d.ts.map +1 -0
  258. package/dist/store/space.js +41 -0
  259. package/dist/store/watchers.d.ts +17 -0
  260. package/dist/store/watchers.d.ts.map +1 -0
  261. package/dist/store/watchers.js +56 -0
  262. package/dist/store/writes.d.ts +24 -0
  263. package/dist/store/writes.d.ts.map +1 -0
  264. package/dist/store/writes.js +125 -0
  265. package/dist/store.d.ts +110 -157
  266. package/dist/store.d.ts.map +1 -1
  267. package/dist/store.js +162 -394
  268. package/dist/stored.d.ts +59 -38
  269. package/dist/stored.d.ts.map +1 -1
  270. package/dist/stored.js +287 -206
  271. package/dist/surface.d.ts +88 -0
  272. package/dist/surface.d.ts.map +1 -0
  273. package/dist/surface.js +223 -0
  274. package/dist/sync.d.ts +19 -0
  275. package/dist/sync.d.ts.map +1 -0
  276. package/dist/sync.js +521 -0
  277. package/dist/tables.d.ts +116 -56
  278. package/dist/tables.d.ts.map +1 -1
  279. package/dist/tables.js +214 -98
  280. package/dist/tallies.d.ts +18 -0
  281. package/dist/tallies.d.ts.map +1 -0
  282. package/dist/tallies.js +129 -0
  283. package/dist/transfer.d.ts +0 -5
  284. package/dist/transfer.d.ts.map +1 -1
  285. package/dist/validation.d.ts +3 -4
  286. package/dist/validation.d.ts.map +1 -1
  287. package/dist/validation.js +42 -100
  288. package/dist/windows.d.ts +1 -12
  289. package/dist/windows.d.ts.map +1 -1
  290. package/dist/windows.js +2 -75
  291. package/dist/wire.d.ts +21 -9
  292. package/dist/wire.d.ts.map +1 -1
  293. package/dist/wire.js +10 -4
  294. package/package.json +3 -2
  295. package/dist/fence.d.ts +0 -6
  296. package/dist/fence.d.ts.map +0 -1
  297. package/dist/fence.js +0 -10
  298. package/dist/fulltext.d.ts +0 -27
  299. package/dist/fulltext.d.ts.map +0 -1
  300. package/dist/fulltext.js +0 -370
  301. package/dist/words.d.ts +0 -19
  302. package/dist/words.d.ts.map +0 -1
  303. package/dist/words.js +0 -156
package/dist/bootstrap.js CHANGED
@@ -1,47 +1,34 @@
1
+ import { declared } from './declaration.js';
1
2
  import { transferIdentity } from './identity.js';
2
3
  import { advancement, pageEntries } from './refresh.js';
4
+ import { entriesIn } from './shared.js';
5
+ import { compositionOf } from './replica.js';
3
6
  import { unconfirmed } from './transfer.js';
4
7
  const NOTHING_PRIOR = () => Promise.resolve(new Map());
5
- async function pageOf(page) {
8
+ const PARTS_IN_FLIGHT = 6;
9
+ function textOf(page) {
10
+ let text = 0;
11
+ for (const [, content] of entriesIn(page.documents))
12
+ text += content.length;
13
+ return text;
14
+ }
15
+ async function pageOf(page, part) {
6
16
  return {
7
17
  entries: await pageEntries(page, [], page.roomVersion, NOTHING_PRIOR),
8
18
  folders: page.folders ?? [],
19
+ ...(part === undefined ? {} : { part }),
9
20
  };
10
21
  }
11
- function heldTogether(first, second) {
12
- if (first === null)
13
- return second;
14
- return {
15
- async files(after, limit) {
16
- const [left, right] = await Promise.all([
17
- first.files(after, limit),
18
- second.files(after, limit),
19
- ]);
20
- const merged = new Map([...left, ...right].map((file) => [file.path, file]));
21
- return [...merged.values()]
22
- .sort((one, other) => (one.path < other.path ? -1 : one.path > other.path ? 1 : 0))
23
- .slice(0, limit);
24
- },
25
- async contents(paths) {
26
- const [left, right] = await Promise.all([first.contents(paths), second.contents(paths)]);
27
- return new Map([...left, ...right]);
28
- },
29
- };
30
- }
31
- const NO_CONTENT = {
32
- files: () => Promise.resolve([]),
33
- contents: () => Promise.resolve(new Map()),
34
- };
35
- export async function bootstrapRoom(adapter, authorization, room, held, builtIn, remodel, continuing, staging, reuse) {
22
+ export async function bootstrapRoom(adapter, authorization, room, held, builtIn, typedPaths, remodel, continuing, staging) {
36
23
  if (staging.held(room.locator) !== null)
37
24
  await staging.abandon(room.locator);
38
- const begun = (pool) => started(adapter, authorization, room, held, builtIn, remodel, continuing, staging, pool);
39
- const first = await begun(reuse);
25
+ const begun = () => started(adapter, authorization, room, held, builtIn, typedPaths, remodel, continuing, staging);
26
+ const first = await begun();
40
27
  if (first.kind !== 'expired')
41
28
  return first;
42
29
  await staging.setAside(room.locator);
43
30
  try {
44
- const replacement = await begun(heldTogether(reuse, first.held));
31
+ const replacement = await begun();
45
32
  if (replacement.kind !== 'expired')
46
33
  return replacement;
47
34
  await staging.abandon(room.locator);
@@ -58,29 +45,25 @@ function dropped(ahead) {
58
45
  dropped(next);
59
46
  }, () => { });
60
47
  }
61
- function compositionFor(room, models, builtIn) {
62
- return {
63
- model: models.collection,
64
- selection: room.typedSelection === undefined
65
- ? null
66
- : { roots: room.typedSelection.roots, model: builtIn },
67
- };
68
- }
69
- async function started(adapter, authorization, room, held, builtIn, remodel, continuing, staging, pool) {
48
+ async function started(adapter, authorization, room, held, builtIn, typedPaths, remodel, continuing, staging) {
49
+ const mode = { paged: false };
70
50
  let outcome;
71
51
  try {
72
- outcome = await bundle(adapter, authorization, room, held, builtIn, remodel, continuing, staging, pool);
52
+ outcome = await bundle(adapter, authorization, room, held, builtIn, typedPaths, remodel, continuing, staging, mode);
73
53
  }
74
54
  catch (error) {
75
- await staging.abandon(room.locator).catch(() => { });
55
+ await stopped(staging, room.locator, mode).catch(() => { });
76
56
  throw error;
77
57
  }
78
58
  if (outcome.kind !== 'staged' && outcome.kind !== 'expired') {
79
- await staging.abandon(room.locator);
59
+ await stopped(staging, room.locator, mode);
80
60
  }
81
61
  return outcome;
82
62
  }
83
- async function bundle(adapter, authorization, room, held, builtIn, remodel, continuing, staging, pool) {
63
+ function stopped(staging, locator, mode) {
64
+ return mode.paged ? staging.abandon(locator) : staging.setAside(locator);
65
+ }
66
+ async function bundle(adapter, authorization, room, held, builtIn, typedPaths, remodel, continuing, staging, mode) {
84
67
  const locator = room.locator;
85
68
  const selection = room.replica.selection;
86
69
  const ending = new AbortController();
@@ -93,7 +76,6 @@ async function bundle(adapter, authorization, room, held, builtIn, remodel, cont
93
76
  ...(token === null
94
77
  ? { arriving: (bytes) => arriving.at(bytes) }
95
78
  : { pageToken: token }),
96
- ...(pool === null ? {} : { held: pool }),
97
79
  });
98
80
  const fetching = (token) => {
99
81
  const fetched = (async () => {
@@ -101,10 +83,9 @@ async function bundle(adapter, authorization, room, held, builtIn, remodel, cont
101
83
  const page = continuing() ? await asking(token) : unconfirmed;
102
84
  if (page.kind !== 'bootstrap')
103
85
  return { page, next: null, written: () => { } };
104
- const written = staging.queued(page.bytes ?? 0);
105
- arriving.part();
86
+ const written = staging.queued(textOf(page));
106
87
  const later = page.pageToken;
107
- if (later === undefined) {
88
+ if (later === undefined && page.parts === undefined) {
108
89
  downloaded();
109
90
  arriving.end();
110
91
  }
@@ -125,12 +106,19 @@ async function bundle(adapter, authorization, room, held, builtIn, remodel, cont
125
106
  if (!continuing())
126
107
  return unconfirmed;
127
108
  const page = fetched.page;
128
- if (page.kind === 'beyond-horizon') {
129
- const key = transfer?.key ?? null;
130
- return { kind: 'expired', held: key === null ? NO_CONTENT : staging.content(key), key };
131
- }
109
+ if (page.kind === 'beyond-horizon')
110
+ return { kind: 'expired', key: transfer?.key ?? null };
132
111
  if (page.kind !== 'bootstrap')
133
112
  return page;
113
+ if (transfer === null && page.parts !== undefined) {
114
+ const parted = await parts(page, page.parts);
115
+ if (parted.kind !== 'parted')
116
+ return parted;
117
+ transfer = parted.transfer;
118
+ continue;
119
+ }
120
+ if (transfer === null)
121
+ mode.paged = true;
134
122
  const models = remodel(page.models, transfer?.models ?? held);
135
123
  const staged = await staging.stage({
136
124
  locator,
@@ -142,13 +130,10 @@ async function bundle(adapter, authorization, room, held, builtIn, remodel, cont
142
130
  last: transfer !== null && !adapter.reached(locator, page.roomVersion, transfer.last)
143
131
  ? transfer.last
144
132
  : page.roomVersion,
145
- done: {
146
- parts: (transfer?.done.parts ?? 0) + 1,
147
- bytes: (transfer?.done.bytes ?? 0) + (page.bytes ?? 0),
148
- },
133
+ done: { bytes: (transfer?.done.bytes ?? 0) + (page.bytes ?? 0) },
149
134
  models,
150
135
  key: transfer?.key ?? null,
151
- }, await pageOf(page), compositionFor(room, models, builtIn));
136
+ }, await pageOf(page), compositionOf(models.collection, room.typedSelection, builtIn, typedPaths));
152
137
  if (staged === null)
153
138
  return unconfirmed;
154
139
  transfer = staged;
@@ -166,40 +151,179 @@ async function bundle(adapter, authorization, room, held, builtIn, remodel, cont
166
151
  }
167
152
  if (transfer === null)
168
153
  return unconfirmed;
169
- const installed = transfer;
170
- const composition = compositionFor(room, installed.models, builtIn);
171
- if (!(await staging.derive(locator, installed.key, composition)))
172
- return unconfirmed;
173
- await staging.turn(locator, 'replaying');
174
- if (!continuing())
175
- return unconfirmed;
176
- const record = {
177
- locator,
178
- name: room.name,
179
- handle: room.handle,
180
- operations: room.operations,
181
- replica: room.replica,
182
- model: installed.models.collection,
183
- typedSelection: room.typedSelection ?? null,
184
- providerOwnedPaths: room.providerOwnedPaths,
185
- roomVersion: installed.from,
186
- transfer: installed.transfer,
187
- inventory: installed.done,
188
- key: installed.key,
189
- };
190
- const due = [room.roomVersion, ...staging.announced(locator)];
191
- const last = installed.last;
192
- const reconciled = last === installed.from && due.every((version) => adapter.reached(locator, last, version))
193
- ? { kind: 'still-current' }
194
- : await advancement(adapter, authorization, record, remodel, continuing, await staging.refreshing(locator, record.key, composition));
195
- if (reconciled.kind === 'advanced' || reconciled.kind === 'still-current') {
196
- const refreshed = reconciled.kind === 'advanced';
197
- const result = refreshed ? reconciled.record : record;
198
- const refused = await staging.validate(result, refreshed ? 'refreshed' : 'confirmed');
199
- return refused ?? { kind: 'staged', record: result, refreshed };
154
+ return installed(transfer);
155
+ async function parts(head, listed) {
156
+ const models = remodel(head.models, held);
157
+ const composition = compositionOf(models.collection, room.typedSelection, builtIn, typedPaths);
158
+ const resumed = await staging.resume({
159
+ locator,
160
+ transfer: transferIdentity(),
161
+ selection,
162
+ from: head.roomVersion,
163
+ last: head.roomVersion,
164
+ done: { bytes: 0 },
165
+ models,
166
+ key: null,
167
+ }, listed, composition);
168
+ if (resumed === null)
169
+ return unconfirmed;
170
+ let staged = resumed.record ?? {
171
+ locator,
172
+ transfer: transferIdentity(),
173
+ selection,
174
+ from: head.roomVersion,
175
+ last: head.roomVersion,
176
+ done: { bytes: 0 },
177
+ models,
178
+ key: null,
179
+ };
180
+ const wanted = listed.filter((part) => !resumed.staged.has(part.id));
181
+ let arrived = staged.done.bytes;
182
+ const partial = new Map();
183
+ const report = () => {
184
+ let bytes = arrived;
185
+ for (const held of partial.values())
186
+ bytes += held;
187
+ arriving.at(bytes);
188
+ };
189
+ report();
190
+ const arrivals = [];
191
+ let woken = null;
192
+ let next = 0;
193
+ let flying = 0;
194
+ let halted = false;
195
+ let stopped = false;
196
+ let admitted = Promise.resolve();
197
+ const fetched = () => {
198
+ if ((next < wanted.length && !halted) || flying > 0)
199
+ return;
200
+ downloaded();
201
+ arriving.end();
202
+ };
203
+ const landed = (one) => {
204
+ flying -= 1;
205
+ if (stopped)
206
+ one.written();
207
+ else
208
+ arrivals.push(one);
209
+ woken?.();
210
+ ask();
211
+ fetched();
212
+ };
213
+ const fetch = async (part) => {
214
+ let written = () => { };
215
+ const admission = admitted.then(async () => {
216
+ await staging.unqueued();
217
+ written = staging.queued(part.bytes);
218
+ });
219
+ admitted = admission;
220
+ await admission;
221
+ const page = continuing()
222
+ ? await adapter.bootstrap(authorization, {
223
+ locator,
224
+ selection,
225
+ signal: ending.signal,
226
+ pageToken: part.id,
227
+ arriving: (bytes) => {
228
+ partial.set(part.id, Math.min(bytes, part.bytes));
229
+ report();
230
+ },
231
+ })
232
+ : unconfirmed;
233
+ landed({ part, page, written });
234
+ };
235
+ const ask = () => {
236
+ while (!stopped && !halted && flying < PARTS_IN_FLIGHT && next < wanted.length) {
237
+ const part = wanted[next];
238
+ next += 1;
239
+ flying += 1;
240
+ fetch(part).catch((error) => landed({ part, page: unconfirmed, written: () => { }, error }));
241
+ }
242
+ };
243
+ let failed = null;
244
+ ask();
245
+ fetched();
246
+ try {
247
+ for (;;) {
248
+ while (arrivals.length === 0) {
249
+ if (flying === 0 && (halted || next >= wanted.length))
250
+ break;
251
+ await new Promise((wake) => (woken = wake));
252
+ woken = null;
253
+ }
254
+ const one = arrivals.shift();
255
+ if (one === undefined)
256
+ break;
257
+ const { part, page, written, error } = one;
258
+ try {
259
+ if (error !== undefined)
260
+ throw error;
261
+ if (!continuing())
262
+ return unconfirmed;
263
+ if (page.kind !== 'bootstrap') {
264
+ halted = true;
265
+ failed ??= page.kind === 'beyond-horizon' ? unconfirmed : page;
266
+ continue;
267
+ }
268
+ partial.delete(part.id);
269
+ arrived += part.bytes;
270
+ report();
271
+ const kept = await staging.stage({ ...staged, done: { bytes: staged.done.bytes + part.bytes } }, await pageOf({ ...page, roomVersion: head.roomVersion }, part.id), composition);
272
+ if (kept === null)
273
+ return unconfirmed;
274
+ staged = kept;
275
+ }
276
+ finally {
277
+ written();
278
+ }
279
+ }
280
+ }
281
+ finally {
282
+ stopped = true;
283
+ for (const one of arrivals.splice(0))
284
+ one.written();
285
+ }
286
+ if (failed !== null)
287
+ return failed;
288
+ if (staged.key === null) {
289
+ const empty = await staging.stage(staged, { entries: [], folders: [] }, composition);
290
+ if (empty === null)
291
+ return unconfirmed;
292
+ staged = empty;
293
+ }
294
+ return { kind: 'parted', transfer: staged };
200
295
  }
201
- if (reconciled.kind === 'beyond-horizon') {
202
- return { kind: 'expired', held: staging.content(record.key), key: record.key };
296
+ async function installed(transfer) {
297
+ const composition = compositionOf(transfer.models.collection, room.typedSelection, builtIn, typedPaths);
298
+ if (!(await staging.derive(locator, transfer.key, composition)))
299
+ return unconfirmed;
300
+ await staging.turn(locator, 'replaying');
301
+ if (!continuing())
302
+ return unconfirmed;
303
+ const record = {
304
+ locator,
305
+ declaration: declared(room),
306
+ model: transfer.models.collection,
307
+ roomVersion: transfer.from,
308
+ transfer: transfer.transfer,
309
+ inventory: transfer.done,
310
+ key: transfer.key,
311
+ };
312
+ const last = transfer.last;
313
+ const refresh = adapter.refresh;
314
+ const reconciled = last === transfer.from &&
315
+ (staging.streamed || adapter.reached(locator, last, room.roomVersion))
316
+ ? { kind: 'still-current' }
317
+ : refresh === undefined
318
+ ? unconfirmed
319
+ : await advancement(refresh, authorization, record, remodel, continuing, await staging.refreshing(locator, record.key, composition));
320
+ if (reconciled.kind === 'advanced') {
321
+ return { kind: 'staged', record: reconciled.record, refreshed: true };
322
+ }
323
+ if (reconciled.kind === 'still-current')
324
+ return { kind: 'staged', record, refreshed: false };
325
+ if (reconciled.kind === 'beyond-horizon')
326
+ return { kind: 'expired', key: record.key };
327
+ return reconciled;
203
328
  }
204
- return reconciled;
205
329
  }
package/dist/cell.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export type Cell<T> = {
2
+ now(): T;
3
+ set(change: Partial<T>): void;
4
+ };
5
+ export declare function createCell<T extends object>(first: T): Cell<T>;
6
+ //# sourceMappingURL=cell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../src/cell.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IACpB,GAAG,IAAI,CAAC,CAAC;IACT,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAQ9D"}
package/dist/cell.js ADDED
@@ -0,0 +1,9 @@
1
+ export function createCell(first) {
2
+ let held = first;
3
+ return {
4
+ now: () => held,
5
+ set(change) {
6
+ held = { ...held, ...change };
7
+ },
8
+ };
9
+ }
package/dist/chain.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import type { DocumentQuery, GroupQuery } from '@agentshouse/mdmodel';
1
2
  import type { MdRuntimeClient } from './client.js';
2
- import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
3
+ import type { DocumentResult, GroupResult, PendingResult } from './query.js';
3
4
  type Rows = DocumentResult | GroupResult;
4
5
  export type WindowAnswer = Rows | PendingResult;
5
6
  export type WindowChain = {
@@ -1 +1 @@
1
- {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,UAAU,EACV,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,KAAK,IAAI,GAAG,cAAc,GAAG,WAAW,CAAC;AAEzC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,aAAa,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAaF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,aAAa,GAAG,UAAU,EACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAC7E,WAAW,CAkEb"}
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE7E,KAAK,IAAI,GAAG,cAAc,GAAG,WAAW,CAAC;AAEzC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,aAAa,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAaF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,aAAa,GAAG,UAAU,EACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAC7E,WAAW,CAkEb"}
@@ -12,6 +12,8 @@ export type ChangeSet = {
12
12
  queues: readonly string[];
13
13
  presentations: readonly string[];
14
14
  conversations: readonly string[];
15
+ unindexed: readonly string[];
16
+ due: readonly string[];
15
17
  };
16
18
  type Changed = {
17
19
  documents?: readonly string[] | null;
@@ -19,6 +21,8 @@ type Changed = {
19
21
  room?: boolean;
20
22
  queue?: boolean;
21
23
  presentation?: string;
24
+ unindexed?: boolean;
25
+ due?: boolean;
22
26
  };
23
27
  export declare function changeSet(locator: string, changed?: Changed): ChangeSet;
24
28
  export declare function conversationChangeSet(conversations: readonly string[]): ChangeSet;
@@ -1 +1 @@
1
- {"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,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ator] : [],
12
12
  presentations: changed.presentation === undefined ? [] : [changed.presentation],
13
13
  conversations: [],
14
+ unindexed: changed.unindexed ? [locator] : [],
15
+ due: changed.due ? [locator] : [],
14
16
  };
15
17
  }
16
18
  export function conversationChangeSet(conversations) {
@@ -21,6 +23,8 @@ export function conversationChangeSet(conversations) {
21
23
  queues: [],
22
24
  presentations: [],
23
25
  conversations: [...new Set(conversations)],
26
+ unindexed: [],
27
+ due: [],
24
28
  };
25
29
  }
26
30
  export function mergeChangeSets(sets) {
@@ -31,6 +35,8 @@ export function mergeChangeSets(sets) {
31
35
  queues: [...new Set(sets.flatMap((set) => set.queues))],
32
36
  presentations: [...new Set(sets.flatMap((set) => set.presentations))],
33
37
  conversations: [...new Set(sets.flatMap((set) => set.conversations))],
38
+ unindexed: [...new Set(sets.flatMap((set) => set.unindexed))],
39
+ due: [...new Set(sets.flatMap((set) => set.due))],
34
40
  };
35
41
  }
36
42
  export function touches(set, locator, path) {
package/dist/change.d.ts CHANGED
@@ -50,6 +50,7 @@ type Arriving = {
50
50
  readonly path: string;
51
51
  readonly revision?: string;
52
52
  readonly fileId?: string;
53
+ readonly created?: string;
53
54
  readonly change?: HeadChange;
54
55
  };
55
56
  export type RoomMove = {
@@ -1 +1 @@
1
- {"version":3,"file":"change.d.ts","sourceRoot":"","sources":["../src/change.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,MAAM,MAAM,GACd;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EA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O,CAAC,EAAE,QAAQ,CAAC;CAC7B,CAAC;AAUF,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAEzD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI5E;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEpE;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAS9F;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAO3E;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAOpF"}
package/dist/change.js CHANGED
@@ -22,7 +22,8 @@ export function leaving(batch, locator) {
22
22
  }
23
23
  export function landing(changes, index, path) {
24
24
  let at = path;
25
- for (const change of changes.slice(index + 1)) {
25
+ for (let next = index + 1; next < changes.length; next += 1) {
26
+ const change = changes[next];
26
27
  if (change.path !== at)
27
28
  continue;
28
29
  if (change.kind === 'remove')
@@ -34,7 +35,8 @@ export function landing(changes, index, path) {
34
35
  }
35
36
  export function departure(changes, index) {
36
37
  let at = changes[index].path;
37
- for (const change of changes.slice(0, index).reverse()) {
38
+ for (let earlier = index - 1; earlier >= 0; earlier -= 1) {
39
+ const change = changes[earlier];
38
40
  if (change.kind === 'move' && change.to === at)
39
41
  at = change.path;
40
42
  }
@@ -0,0 +1,5 @@
1
+ export declare const CHAT_TYPE = "chat";
2
+ export declare const CHAT_MESSAGE_TYPE = "chat-message";
3
+ export declare function keptFile(line: string): string | null;
4
+ export declare function keptLines(body: string): string[];
5
+ //# sourceMappingURL=chat-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-types.d.ts","sourceRoot":"","sources":["../src/chat-types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAMhD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEpD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAKhD"}
@@ -0,0 +1,13 @@
1
+ export const CHAT_TYPE = 'chat';
2
+ export const CHAT_MESSAGE_TYPE = 'chat-message';
3
+ const KEPT_LINE = /^\[([^\]\n]+)\]\(\1\)$/u;
4
+ const TOO_BIG_LINE = /^\[too big to keep: [^\n]*\]$/u;
5
+ export function keptFile(line) {
6
+ return KEPT_LINE.exec(line)?.[1] ?? null;
7
+ }
8
+ export function keptLines(body) {
9
+ const trimmed = body.replace(/\n+$/u, '');
10
+ const at = trimmed.lastIndexOf('\n\n');
11
+ const lines = (at === -1 ? trimmed : trimmed.slice(at + 2)).split('\n');
12
+ return lines.every((line) => keptFile(line) !== null || TOO_BIG_LINE.test(line)) ? lines : [];
13
+ }
package/dist/client.d.ts CHANGED
@@ -1,15 +1,26 @@
1
- import type { AppRoom, ConnectionRefusal, HistoryQuery, RoomSchemas, SavedParts, SavedRoomDraft, SaveResult } from './connection.js';
1
+ import type { DocumentQuery, GroupQuery } from '@agentshouse/mdmodel';
2
+ import type { HistoryQuery } from './actions.js';
3
+ import type { AppRoom } from './listing.js';
4
+ import type { ConnectionRefusal } from './socket.js';
5
+ import type { RoomSchemas } from './surface.js';
6
+ import type { SavedParts, SavedRoomDraft, SaveResult } from './saves.js';
2
7
  import type { Member, ServiceMode } from './adapter.js';
3
- import type { ChatDraft, ConversationAgent, ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
8
+ import type { UnsentWork } from './durability.js';
9
+ import type { ChatDraft, ConversationAgent, ConversationAnswer, ConversationEntry, ConversationOptions, ConversationRead, ConversationView } from './conversation.js';
4
10
  import { type Observation } from './observation.js';
5
11
  import type { AttachAnswer, BinaryAnswer, CallResult, DownloadAnswer, HistoryAnswer, Offline, QueueEntry, Resolution } from './outcome.js';
6
- import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
12
+ import type { FiguresResult } from './figures.js';
13
+ import type { Holdings } from './holdings.js';
14
+ import type { DocumentResult, GroupResult, PendingResult } from './query.js';
7
15
  import type { RoomDraft, RoomDraftParts, RoomDraftWrite } from './room-draft.js';
8
16
  import type { SearchRequest, SearchResult } from './search.js';
9
17
  import type { Readiness } from './readiness.js';
18
+ import type { ObservedRead } from './reads.js';
10
19
  import type { SyncStatus } from './status.js';
11
20
  import { type RuntimePort } from './wire.js';
21
+ export type BuildFile = (name: string) => Promise<Blob | null>;
12
22
  export type MdRuntimeClient = {
23
+ buildFile(name: string): Promise<Blob | null>;
13
24
  rooms(): Promise<readonly AppRoom[]>;
14
25
  query: {
15
26
  (query: DocumentQuery): Promise<DocumentResult | PendingResult>;
@@ -32,13 +43,12 @@ export type MdRuntimeClient = {
32
43
  };
33
44
  conversation: {
34
45
  list(): Promise<readonly ConversationEntry[]>;
35
- read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;
46
+ read(conversation: string, options?: ConversationRead): Promise<ConversationView>;
36
47
  create(input: unknown): Promise<CallResult>;
37
48
  send(conversation: string, operation?: string, draft?: ChatDraft): Promise<CallResult | Offline>;
38
- answer(conversation: string, answer: unknown): Promise<CallResult>;
49
+ answer(conversation: string, answer: ConversationAnswer): Promise<CallResult>;
39
50
  interrupt(conversation: string): Promise<CallResult>;
40
51
  kill(conversation: string): Promise<CallResult>;
41
- cancel(conversation: string, turn: string): Promise<CallResult>;
42
52
  delete(conversation: string): Promise<CallResult>;
43
53
  };
44
54
  chatDraft: {
@@ -59,6 +69,9 @@ export type MdRuntimeClient = {
59
69
  persistence(): Promise<boolean>;
60
70
  retry(): Promise<void>;
61
71
  cleanUp(): Promise<number>;
72
+ unsent(): Promise<readonly UnsentWork[]>;
73
+ reset(): Promise<void>;
74
+ readAgain(): Promise<void>;
62
75
  observe: {
63
76
  (topic: 'deployment-facts'): Promise<Observation<unknown>>;
64
77
  (topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
@@ -68,6 +81,7 @@ export type MdRuntimeClient = {
68
81
  (topic: 'sync-status'): Promise<Observation<SyncStatus>>;
69
82
  (topic: 'service-mode'): Promise<Observation<ServiceMode>>;
70
83
  (topic: 'member'): Promise<Observation<Member | null>>;
84
+ (topic: 'authority-changes'): Promise<Observation<number>>;
71
85
  (topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult | PendingResult>>;
72
86
  (topic: 'query', query: GroupQuery): Promise<Observation<GroupResult | PendingResult>>;
73
87
  (topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
@@ -76,11 +90,14 @@ export type MdRuntimeClient = {
76
90
  (topic: 'conversation', conversation: string, options: ConversationOptions): Promise<Observation<ConversationView>>;
77
91
  (topic: 'conversations'): Promise<Observation<readonly ConversationEntry[]>>;
78
92
  (topic: 'agents'): Promise<Observation<readonly ConversationAgent[]>>;
93
+ (topic: 'figures'): Promise<Observation<FiguresResult>>;
94
+ (topic: 'holdings'): Promise<Observation<Holdings>>;
95
+ (topic: 'read', name: string, input: unknown): Promise<Observation<ObservedRead>>;
79
96
  };
80
97
  reauthorize(): Promise<void>;
81
98
  settled(): Promise<void>;
82
99
  };
83
- export declare function connectMdRuntime(port: RuntimePort): MdRuntimeClient;
100
+ export declare function connectMdRuntime(port: RuntimePort, buildFile?: BuildFile): MdRuntimeClient;
84
101
  export declare function inTurn(client: MdRuntimeClient, work: () => Promise<void>): Promise<void>;
85
102
  export { chainedWindows, type WindowAnswer, type WindowChain } from './chain.js';
86
103
  export { roomDraftRevision } from './identity.js';