@agentshouse/mdruntime 0.1.0-ca9afacd5aebd → 0.1.0-cae97ad2e9142

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 (228) hide show
  1. package/README.md +18 -15
  2. package/dist/adapter.d.ts +99 -36
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/attached-model.d.ts +5 -1
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +21 -4
  7. package/dist/attempt.d.ts.map +1 -1
  8. package/dist/attempt.js +14 -1
  9. package/dist/binary.d.ts +0 -5
  10. package/dist/binary.d.ts.map +1 -1
  11. package/dist/binary.js +1 -1
  12. package/dist/bootstrap.d.ts +31 -9
  13. package/dist/bootstrap.d.ts.map +1 -1
  14. package/dist/bootstrap.js +155 -64
  15. package/dist/chain.d.ts +11 -0
  16. package/dist/chain.d.ts.map +1 -0
  17. package/dist/chain.js +64 -0
  18. package/dist/change-set.d.ts +9 -14
  19. package/dist/change-set.d.ts.map +1 -1
  20. package/dist/change-set.js +11 -63
  21. package/dist/change.d.ts +31 -1
  22. package/dist/change.d.ts.map +1 -1
  23. package/dist/change.js +10 -1
  24. package/dist/client.d.ts +24 -12
  25. package/dist/client.d.ts.map +1 -1
  26. package/dist/client.js +49 -9
  27. package/dist/collection.d.ts +7 -6
  28. package/dist/collection.d.ts.map +1 -1
  29. package/dist/collection.js +30 -77
  30. package/dist/compile.d.ts +16 -0
  31. package/dist/compile.d.ts.map +1 -0
  32. package/dist/compile.js +767 -0
  33. package/dist/connection.d.ts +42 -15
  34. package/dist/connection.d.ts.map +1 -1
  35. package/dist/connection.js +3415 -810
  36. package/dist/conversation.d.ts +30 -9
  37. package/dist/conversation.d.ts.map +1 -1
  38. package/dist/conversation.js +549 -181
  39. package/dist/digest.d.ts +7 -0
  40. package/dist/digest.d.ts.map +1 -0
  41. package/dist/digest.js +113 -0
  42. package/dist/durability.d.ts +5 -1
  43. package/dist/durability.d.ts.map +1 -1
  44. package/dist/durability.js +5 -0
  45. package/dist/entry.d.ts +19 -0
  46. package/dist/entry.d.ts.map +1 -0
  47. package/dist/entry.js +151 -0
  48. package/dist/fence.d.ts +6 -0
  49. package/dist/fence.d.ts.map +1 -0
  50. package/dist/fence.js +10 -0
  51. package/dist/file.d.ts +2 -10
  52. package/dist/file.d.ts.map +1 -1
  53. package/dist/file.js +3 -120
  54. package/dist/fulltext.d.ts +27 -0
  55. package/dist/fulltext.d.ts.map +1 -0
  56. package/dist/fulltext.js +368 -0
  57. package/dist/host.d.ts +15 -3
  58. package/dist/host.d.ts.map +1 -1
  59. package/dist/host.js +126 -16
  60. package/dist/identity.d.ts +1 -0
  61. package/dist/identity.d.ts.map +1 -1
  62. package/dist/identity.js +3 -0
  63. package/dist/index.d.ts +15 -9
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +5 -0
  66. package/dist/live.d.ts +22 -0
  67. package/dist/live.d.ts.map +1 -0
  68. package/dist/live.js +124 -0
  69. package/dist/memory.d.ts +10 -3
  70. package/dist/memory.d.ts.map +1 -1
  71. package/dist/memory.js +54 -26
  72. package/dist/messages.d.ts +28 -0
  73. package/dist/messages.d.ts.map +1 -0
  74. package/dist/messages.js +90 -0
  75. package/dist/model.d.ts +4 -2
  76. package/dist/model.d.ts.map +1 -1
  77. package/dist/model.js +11 -2
  78. package/dist/name.d.ts +4 -0
  79. package/dist/name.d.ts.map +1 -0
  80. package/dist/name.js +122 -0
  81. package/dist/observation.d.ts +19 -2
  82. package/dist/observation.d.ts.map +1 -1
  83. package/dist/observation.js +113 -12
  84. package/dist/opened.d.ts +22 -0
  85. package/dist/opened.d.ts.map +1 -0
  86. package/dist/opened.js +107 -0
  87. package/dist/outcome.d.ts +38 -4
  88. package/dist/outcome.d.ts.map +1 -1
  89. package/dist/outcome.js +26 -0
  90. package/dist/overlay.d.ts +3 -4
  91. package/dist/overlay.d.ts.map +1 -1
  92. package/dist/overlay.js +100 -182
  93. package/dist/query.d.ts +66 -4
  94. package/dist/query.d.ts.map +1 -1
  95. package/dist/query.js +48 -7
  96. package/dist/reach.d.ts +17 -6
  97. package/dist/reach.d.ts.map +1 -1
  98. package/dist/reach.js +205 -68
  99. package/dist/react.d.ts +8 -6
  100. package/dist/react.d.ts.map +1 -1
  101. package/dist/react.js +7 -17
  102. package/dist/readiness.d.ts +64 -0
  103. package/dist/readiness.d.ts.map +1 -0
  104. package/dist/readiness.js +33 -0
  105. package/dist/reads.d.ts +11 -0
  106. package/dist/reads.d.ts.map +1 -0
  107. package/dist/reads.js +100 -0
  108. package/dist/recovery.d.ts +25 -0
  109. package/dist/recovery.d.ts.map +1 -0
  110. package/dist/recovery.js +198 -0
  111. package/dist/refresh.d.ts +16 -15
  112. package/dist/refresh.d.ts.map +1 -1
  113. package/dist/refresh.js +113 -49
  114. package/dist/replica.d.ts +56 -33
  115. package/dist/replica.d.ts.map +1 -1
  116. package/dist/replica.js +297 -162
  117. package/dist/room-draft.d.ts +17 -2
  118. package/dist/room-draft.d.ts.map +1 -1
  119. package/dist/room-draft.js +65 -25
  120. package/dist/rows.d.ts +35 -37
  121. package/dist/rows.d.ts.map +1 -1
  122. package/dist/rows.js +165 -105
  123. package/dist/save.d.ts +50 -9
  124. package/dist/save.d.ts.map +1 -1
  125. package/dist/save.js +528 -166
  126. package/dist/search.d.ts +39 -28
  127. package/dist/search.d.ts.map +1 -1
  128. package/dist/search.js +37 -105
  129. package/dist/seed.d.ts +16 -0
  130. package/dist/seed.d.ts.map +1 -0
  131. package/dist/seed.js +75 -0
  132. package/dist/shared.d.ts +16 -0
  133. package/dist/shared.d.ts.map +1 -0
  134. package/dist/shared.js +431 -0
  135. package/dist/status.d.ts +4 -0
  136. package/dist/status.d.ts.map +1 -1
  137. package/dist/store.d.ts +116 -74
  138. package/dist/store.d.ts.map +1 -1
  139. package/dist/store.js +353 -444
  140. package/dist/stored.d.ts +150 -0
  141. package/dist/stored.d.ts.map +1 -0
  142. package/dist/stored.js +564 -0
  143. package/dist/tables.d.ts +354 -0
  144. package/dist/tables.d.ts.map +1 -0
  145. package/dist/tables.js +624 -0
  146. package/dist/turn.d.ts +9 -0
  147. package/dist/turn.d.ts.map +1 -0
  148. package/dist/turn.js +75 -0
  149. package/dist/validation.d.ts +30 -0
  150. package/dist/validation.d.ts.map +1 -0
  151. package/dist/validation.js +162 -0
  152. package/dist/windows.d.ts +22 -0
  153. package/dist/windows.d.ts.map +1 -0
  154. package/dist/windows.js +89 -0
  155. package/dist/wire.d.ts +164 -32
  156. package/dist/wire.d.ts.map +1 -1
  157. package/dist/wire.js +55 -31
  158. package/dist/words.d.ts +19 -0
  159. package/dist/words.d.ts.map +1 -0
  160. package/dist/words.js +150 -0
  161. package/package.json +27 -24
  162. package/AGENTS.md +0 -318
  163. package/dist/chat/acts.d.ts +0 -34
  164. package/dist/chat/acts.d.ts.map +0 -1
  165. package/dist/chat/acts.js +0 -36
  166. package/dist/chat/context.d.ts +0 -3
  167. package/dist/chat/context.d.ts.map +0 -1
  168. package/dist/chat/context.js +0 -10
  169. package/dist/chat/input.d.ts +0 -9
  170. package/dist/chat/input.d.ts.map +0 -1
  171. package/dist/chat/input.js +0 -99
  172. package/dist/chat/kit.d.ts +0 -60
  173. package/dist/chat/kit.d.ts.map +0 -1
  174. package/dist/chat/kit.js +0 -123
  175. package/dist/chat/lasting.d.ts +0 -6
  176. package/dist/chat/lasting.d.ts.map +0 -1
  177. package/dist/chat/lasting.js +0 -19
  178. package/dist/chat/list.d.ts +0 -20
  179. package/dist/chat/list.d.ts.map +0 -1
  180. package/dist/chat/list.js +0 -59
  181. package/dist/chat/markdown.d.ts +0 -19
  182. package/dist/chat/markdown.d.ts.map +0 -1
  183. package/dist/chat/markdown.js +0 -187
  184. package/dist/chat/message.d.ts +0 -6
  185. package/dist/chat/message.d.ts.map +0 -1
  186. package/dist/chat/message.js +0 -192
  187. package/dist/chat/messages.d.ts +0 -21
  188. package/dist/chat/messages.d.ts.map +0 -1
  189. package/dist/chat/messages.js +0 -151
  190. package/dist/chat/name.d.ts +0 -6
  191. package/dist/chat/name.d.ts.map +0 -1
  192. package/dist/chat/name.js +0 -37
  193. package/dist/chat/opened.d.ts +0 -11
  194. package/dist/chat/opened.d.ts.map +0 -1
  195. package/dist/chat/opened.js +0 -17
  196. package/dist/chat/overlay.d.ts +0 -31
  197. package/dist/chat/overlay.d.ts.map +0 -1
  198. package/dist/chat/overlay.js +0 -97
  199. package/dist/chat/parts.d.ts +0 -57
  200. package/dist/chat/parts.d.ts.map +0 -1
  201. package/dist/chat/parts.js +0 -119
  202. package/dist/chat/process.d.ts +0 -20
  203. package/dist/chat/process.d.ts.map +0 -1
  204. package/dist/chat/process.js +0 -32
  205. package/dist/chat/provider.d.ts +0 -63
  206. package/dist/chat/provider.d.ts.map +0 -1
  207. package/dist/chat/provider.js +0 -645
  208. package/dist/chat/question.d.ts +0 -9
  209. package/dist/chat/question.d.ts.map +0 -1
  210. package/dist/chat/question.js +0 -80
  211. package/dist/chat/questions.d.ts +0 -31
  212. package/dist/chat/questions.d.ts.map +0 -1
  213. package/dist/chat/questions.js +0 -111
  214. package/dist/chat/read.d.ts +0 -5
  215. package/dist/chat/read.d.ts.map +0 -1
  216. package/dist/chat/read.js +0 -13
  217. package/dist/chat/ready.d.ts +0 -33
  218. package/dist/chat/ready.d.ts.map +0 -1
  219. package/dist/chat/ready.js +0 -91
  220. package/dist/chat/style.d.ts +0 -4
  221. package/dist/chat/style.d.ts.map +0 -1
  222. package/dist/chat/style.js +0 -302
  223. package/dist/chat.d.ts +0 -14
  224. package/dist/chat.d.ts.map +0 -1
  225. package/dist/chat.js +0 -8
  226. package/dist/read-side.d.ts +0 -18
  227. package/dist/read-side.d.ts.map +0 -1
  228. package/dist/read-side.js +0 -440
package/dist/shared.js ADDED
@@ -0,0 +1,431 @@
1
+ import { finished, ROW_WEIGHT } from './turn.js';
2
+ const BITS = 5;
3
+ const MASK = (1 << BITS) - 1;
4
+ const roots = new WeakMap();
5
+ function hashOf(key) {
6
+ let hash = 0x811c9dc5;
7
+ for (let index = 0; index < key.length; index += 1) {
8
+ hash ^= key.charCodeAt(index);
9
+ hash = Math.imul(hash, 0x01000193);
10
+ }
11
+ return hash >>> 0;
12
+ }
13
+ function isLeaf(node) {
14
+ return 'key' in node;
15
+ }
16
+ function isCollision(node) {
17
+ return 'leaves' in node;
18
+ }
19
+ function fragment(hash, shift) {
20
+ return (hash >>> shift) & MASK;
21
+ }
22
+ function count(bits) {
23
+ let left = bits - ((bits >>> 1) & 0x55555555);
24
+ left = (left & 0x33333333) + ((left >>> 2) & 0x33333333);
25
+ return (((left + (left >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
26
+ }
27
+ function slot(bitmap, bit) {
28
+ return count(bitmap & (bit - 1));
29
+ }
30
+ function lookup(root, key) {
31
+ const hash = hashOf(key);
32
+ let node = root.node;
33
+ let shift = 0;
34
+ while (node !== undefined) {
35
+ if (isLeaf(node))
36
+ return node.key === key ? node : undefined;
37
+ if (isCollision(node))
38
+ return node.leaves.find((leaf) => leaf.key === key);
39
+ const bit = 1 << fragment(hash, shift);
40
+ if ((node.bitmap & bit) === 0)
41
+ return undefined;
42
+ node = node.children[slot(node.bitmap, bit)];
43
+ shift += BITS;
44
+ }
45
+ return undefined;
46
+ }
47
+ function branchOf(node, shift) {
48
+ return { bitmap: 1 << fragment(node.hash, shift), children: [node] };
49
+ }
50
+ function joined(left, right, shift) {
51
+ if (left.hash === right.hash) {
52
+ const leaves = isCollision(left) ? left.leaves : [left];
53
+ return { hash: right.hash, leaves: [...leaves, right] };
54
+ }
55
+ return put(branchOf(left, shift), right, shift);
56
+ }
57
+ function put(node, leaf, shift) {
58
+ if (node === undefined)
59
+ return leaf;
60
+ if (isLeaf(node)) {
61
+ if (node.key !== leaf.key)
62
+ return joined(node, leaf, shift);
63
+ return node.value === leaf.value ? node : leaf;
64
+ }
65
+ if (isCollision(node)) {
66
+ if (node.hash !== leaf.hash)
67
+ return joined(node, leaf, shift);
68
+ const at = node.leaves.findIndex((held) => held.key === leaf.key);
69
+ if (at === -1)
70
+ return { hash: node.hash, leaves: [...node.leaves, leaf] };
71
+ if (node.leaves[at].value === leaf.value)
72
+ return node;
73
+ return {
74
+ hash: node.hash,
75
+ leaves: node.leaves.map((held, index) => (index === at ? leaf : held)),
76
+ };
77
+ }
78
+ const bit = 1 << fragment(leaf.hash, shift);
79
+ const at = slot(node.bitmap, bit);
80
+ if ((node.bitmap & bit) === 0) {
81
+ return {
82
+ bitmap: node.bitmap | bit,
83
+ children: [...node.children.slice(0, at), leaf, ...node.children.slice(at)],
84
+ };
85
+ }
86
+ const child = node.children[at];
87
+ const next = put(child, leaf, shift + BITS);
88
+ if (next === child)
89
+ return node;
90
+ return {
91
+ bitmap: node.bitmap,
92
+ children: node.children.map((held, index) => (index === at ? next : held)),
93
+ };
94
+ }
95
+ function lone(node) {
96
+ if (node.children.length !== 1)
97
+ return null;
98
+ const [only] = node.children;
99
+ return isLeaf(only) || isCollision(only) ? only : null;
100
+ }
101
+ function taken(node, hash, key, shift) {
102
+ if (isLeaf(node))
103
+ return node.key === key ? undefined : node;
104
+ if (isCollision(node)) {
105
+ const leaves = node.leaves.filter((leaf) => leaf.key !== key);
106
+ if (leaves.length === node.leaves.length)
107
+ return node;
108
+ return leaves.length === 1 ? leaves[0] : { hash: node.hash, leaves };
109
+ }
110
+ const bit = 1 << fragment(hash, shift);
111
+ if ((node.bitmap & bit) === 0)
112
+ return node;
113
+ const at = slot(node.bitmap, bit);
114
+ const child = node.children[at];
115
+ const next = taken(child, hash, key, shift + BITS);
116
+ if (next === child)
117
+ return node;
118
+ if (next === undefined) {
119
+ if (node.children.length === 1)
120
+ return undefined;
121
+ const rest = {
122
+ bitmap: node.bitmap & ~bit,
123
+ children: node.children.filter((_, index) => index !== at),
124
+ };
125
+ return lone(rest) ?? rest;
126
+ }
127
+ const replaced = {
128
+ bitmap: node.bitmap,
129
+ children: node.children.map((held, index) => (index === at ? next : held)),
130
+ };
131
+ return lone(replaced) ?? replaced;
132
+ }
133
+ function* leavesOf(node) {
134
+ if (node === undefined)
135
+ return;
136
+ if (isLeaf(node)) {
137
+ yield node;
138
+ return;
139
+ }
140
+ if (isCollision(node)) {
141
+ yield* node.leaves;
142
+ return;
143
+ }
144
+ for (const child of node.children)
145
+ yield* leavesOf(child);
146
+ }
147
+ function facade(root) {
148
+ let keys;
149
+ const target = {};
150
+ const map = new Proxy(target, {
151
+ get(held, property, receiver) {
152
+ if (typeof property === 'string') {
153
+ const leaf = lookup(root, property);
154
+ if (leaf !== undefined)
155
+ return leaf.value;
156
+ }
157
+ return Reflect.get(held, property, receiver);
158
+ },
159
+ has(held, property) {
160
+ return ((typeof property === 'string' && lookup(root, property) !== undefined) ||
161
+ Reflect.has(held, property));
162
+ },
163
+ ownKeys() {
164
+ keys ??= [...leavesOf(root.node)].map((leaf) => leaf.key);
165
+ return keys;
166
+ },
167
+ getOwnPropertyDescriptor(_held, property) {
168
+ if (typeof property !== 'string')
169
+ return undefined;
170
+ const leaf = lookup(root, property);
171
+ if (leaf === undefined)
172
+ return undefined;
173
+ return { value: leaf.value, writable: false, enumerable: true, configurable: true };
174
+ },
175
+ set: () => false,
176
+ defineProperty: () => false,
177
+ deleteProperty: () => false,
178
+ });
179
+ roots.set(map, root);
180
+ return map;
181
+ }
182
+ export function* entriesIn(map) {
183
+ const root = roots.get(map);
184
+ if (root === undefined) {
185
+ for (const key of Object.keys(map))
186
+ yield [key, map[key]];
187
+ return;
188
+ }
189
+ for (const leaf of leavesOf(root.node))
190
+ yield [leaf.key, leaf.value];
191
+ }
192
+ function* rooted(map) {
193
+ const held = roots.get(map);
194
+ if (held !== undefined)
195
+ return held;
196
+ let node;
197
+ let size = 0;
198
+ for (const [key, value] of entriesIn(map)) {
199
+ node = put(node, { key, hash: hashOf(key), value }, 0);
200
+ size += 1;
201
+ yield ROW_WEIGHT;
202
+ }
203
+ return { node, size };
204
+ }
205
+ export function* keysIn(...maps) {
206
+ const keys = new Set();
207
+ for (const map of maps) {
208
+ for (const [key] of entriesIn(map)) {
209
+ keys.add(key);
210
+ yield ROW_WEIGHT;
211
+ }
212
+ }
213
+ return keys;
214
+ }
215
+ const RUN = 1 << 10;
216
+ function* merged(left, right) {
217
+ const into = [];
218
+ let at = 0;
219
+ let from = 0;
220
+ while (at < left.length || from < right.length) {
221
+ into.push(from === right.length || (at < left.length && left[at] < right[from])
222
+ ? left[at++]
223
+ : right[from++]);
224
+ yield ROW_WEIGHT;
225
+ }
226
+ return into;
227
+ }
228
+ function* pathsOf(map) {
229
+ for (const [key] of entriesIn(map))
230
+ yield key;
231
+ }
232
+ export function* sortedKeys(map) {
233
+ return yield* sorting(pathsOf(map));
234
+ }
235
+ export function* sorting(keys) {
236
+ let runs = [];
237
+ let run = [];
238
+ for (const key of keys) {
239
+ run.push(key);
240
+ yield ROW_WEIGHT;
241
+ if (run.length === RUN) {
242
+ runs.push(run.sort());
243
+ run = [];
244
+ }
245
+ }
246
+ if (run.length > 0)
247
+ runs.push(run.sort());
248
+ while (runs.length > 1) {
249
+ const next = [];
250
+ for (let at = 0; at < runs.length; at += 2) {
251
+ next.push(at + 1 === runs.length ? runs[at] : yield* merged(runs[at], runs[at + 1]));
252
+ }
253
+ runs = next;
254
+ }
255
+ return runs[0] ?? [];
256
+ }
257
+ export function* sharing(map) {
258
+ return roots.has(map) ? map : facade(yield* rooted(map));
259
+ }
260
+ export function shared(map) {
261
+ return finished(sharing(map));
262
+ }
263
+ export function patched(base, set, removed = []) {
264
+ return finished(patching(base, set, removed));
265
+ }
266
+ export function* patching(base, set, removed = []) {
267
+ const root = yield* rooted(base);
268
+ let node = root.node;
269
+ let size = root.size;
270
+ for (const key of removed) {
271
+ if (node === undefined)
272
+ break;
273
+ const before = lookup({ node, size }, key);
274
+ if (before === undefined)
275
+ continue;
276
+ node = taken(node, before.hash, key, 0);
277
+ size -= 1;
278
+ yield ROW_WEIGHT;
279
+ }
280
+ for (const [key, value] of set) {
281
+ const before = lookup({ node, size }, key);
282
+ node = put(node, { key, hash: hashOf(key), value }, 0);
283
+ if (before === undefined)
284
+ size += 1;
285
+ yield ROW_WEIGHT;
286
+ }
287
+ if (node === root.node && roots.has(base))
288
+ return base;
289
+ return facade({ node, size });
290
+ }
291
+ export function sizeOf(map) {
292
+ return roots.get(map)?.size ?? Object.keys(map).length;
293
+ }
294
+ function* compared(left, right, same, into) {
295
+ const pending = [[left, right]];
296
+ for (let pair = pending.pop(); pair !== undefined; pair = pending.pop()) {
297
+ const [one, other] = pair;
298
+ if (one === other)
299
+ continue;
300
+ if (one !== undefined &&
301
+ other !== undefined &&
302
+ !isLeaf(one) &&
303
+ !isCollision(one) &&
304
+ !isLeaf(other) &&
305
+ !isCollision(other)) {
306
+ const children = [];
307
+ for (let remaining = one.bitmap | other.bitmap; remaining !== 0; remaining &= remaining - 1) {
308
+ const bit = remaining & -remaining;
309
+ children.push([
310
+ (one.bitmap & bit) === 0 ? undefined : one.children[slot(one.bitmap, bit)],
311
+ (other.bitmap & bit) === 0 ? undefined : other.children[slot(other.bitmap, bit)],
312
+ ]);
313
+ }
314
+ pending.push(...children.reverse());
315
+ continue;
316
+ }
317
+ const before = new Map();
318
+ for (const leaf of leavesOf(one)) {
319
+ before.set(leaf.key, leaf.value);
320
+ yield ROW_WEIGHT;
321
+ }
322
+ for (const leaf of leavesOf(other)) {
323
+ const held = before.get(leaf.key);
324
+ before.delete(leaf.key);
325
+ if (held === undefined || !same(held, leaf.value))
326
+ into.add(leaf.key);
327
+ yield ROW_WEIGHT;
328
+ }
329
+ for (const key of before.keys())
330
+ into.add(key);
331
+ }
332
+ }
333
+ export function* differences(left, right, same = Object.is) {
334
+ const into = new Set();
335
+ if (left === right)
336
+ return into;
337
+ const leftRoot = roots.get(left);
338
+ const rightRoot = roots.get(right);
339
+ if (leftRoot !== undefined && rightRoot !== undefined) {
340
+ yield* compared(leftRoot.node, rightRoot.node, same, into);
341
+ return into;
342
+ }
343
+ for (const [key, value] of entriesIn(left)) {
344
+ if (!Object.hasOwn(right, key) || !same(value, right[key]))
345
+ into.add(key);
346
+ yield ROW_WEIGHT;
347
+ }
348
+ for (const [key] of entriesIn(right)) {
349
+ if (!Object.hasOwn(left, key))
350
+ into.add(key);
351
+ yield ROW_WEIGHT;
352
+ }
353
+ return into;
354
+ }
355
+ export function differing(left, right, same = Object.is) {
356
+ return finished(differences(left, right, same));
357
+ }
358
+ const drafts = new WeakMap();
359
+ const GONE = Symbol('gone');
360
+ export function drafted(base) {
361
+ const written = new Map();
362
+ const read = (key) => {
363
+ const held = written.get(key);
364
+ if (held === GONE)
365
+ return undefined;
366
+ return held ?? (Object.hasOwn(base, key) ? base[key] : undefined);
367
+ };
368
+ const draft = new Proxy({}, {
369
+ get(held, property, receiver) {
370
+ if (typeof property === 'string') {
371
+ const value = read(property);
372
+ if (value !== undefined)
373
+ return value;
374
+ }
375
+ return Reflect.get(held, property, receiver);
376
+ },
377
+ has(held, property) {
378
+ return ((typeof property === 'string' && read(property) !== undefined) ||
379
+ Reflect.has(held, property));
380
+ },
381
+ ownKeys() {
382
+ const keys = new Set(Object.keys(base));
383
+ for (const [key, value] of written) {
384
+ if (value === GONE)
385
+ keys.delete(key);
386
+ else
387
+ keys.add(key);
388
+ }
389
+ return [...keys];
390
+ },
391
+ getOwnPropertyDescriptor(_held, property) {
392
+ if (typeof property !== 'string')
393
+ return undefined;
394
+ const value = read(property);
395
+ if (value === undefined)
396
+ return undefined;
397
+ return { value, writable: true, enumerable: true, configurable: true };
398
+ },
399
+ set(_held, property, value) {
400
+ if (typeof property !== 'string')
401
+ return false;
402
+ written.set(property, value);
403
+ return true;
404
+ },
405
+ deleteProperty(_held, property) {
406
+ if (typeof property !== 'string')
407
+ return false;
408
+ written.set(property, GONE);
409
+ return true;
410
+ },
411
+ defineProperty: () => false,
412
+ });
413
+ drafts.set(draft, { base, written });
414
+ return draft;
415
+ }
416
+ export function settled(draft) {
417
+ return finished(settling(draft));
418
+ }
419
+ export function* settling(draft) {
420
+ const held = drafts.get(draft);
421
+ const set = [];
422
+ const removed = [];
423
+ for (const [key, value] of held.written) {
424
+ if (value === GONE)
425
+ removed.push(key);
426
+ else
427
+ set.push([key, value]);
428
+ yield ROW_WEIGHT;
429
+ }
430
+ return yield* patching(held.base, set, removed);
431
+ }
package/dist/status.d.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  import type { Open } from './open.js';
2
+ import type { ProviderRefusal } from './adapter.js';
2
3
  import type { ReturnReason } from './room-draft.js';
3
4
  export type AttentionEntry = {
4
5
  room: string;
5
6
  path: string;
6
7
  returned: ReturnReason;
8
+ } | {
9
+ room: string;
10
+ refusal: ProviderRefusal;
7
11
  };
8
12
  export type SyncStatus = {
9
13
  state: Open<'pending' | 'syncing' | 'synced'>;
@@ -1 +1 @@
1
- {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,IAAI,CAAC,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC;IAC9C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,iBAAiB,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,UAMtB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAE3D;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAErD;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAQhE"}
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,GACtD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,IAAI,CAAC,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC;IAC9C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,iBAAiB,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,UAMtB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAE3D;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAErD;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAQhE"}
package/dist/store.d.ts CHANGED
@@ -1,43 +1,32 @@
1
- import type { ModelState } from './model.js';
2
- import type { Capability, HeadChange, Member, OperationScopes, ProviderLimit, ReplicaAdmission, TypedSelection } from './adapter.js';
3
- import type { AcceptedMessage } from './adapter.js';
1
+ import type { BootstrapInventory, Capability, KeptReceipt, Member, ProviderLimit } from './adapter.js';
4
2
  import type { ChangeBatch } from './change.js';
5
- import { type HeldBinary } from './overlay.js';
6
- import type { ChatDraftFile } from './file.js';
3
+ import type { Composition } from './collection.js';
4
+ import type { Plan } from './query.js';
5
+ import type { ReplicaRecord } from './replica.js';
7
6
  import type { Submission } from './outcome.js';
8
7
  import type { RoomDraftRecord, SavedDraft } from './room-draft.js';
9
- export declare const STORE_SCHEMA = 23;
10
- export declare const AUTHORED_SCHEMA = 1;
11
- export type ReplicaRecord = {
12
- locator: string;
13
- name: string;
14
- handle: string;
15
- operations: OperationScopes;
16
- replica: ReplicaAdmission;
17
- model: ModelState;
18
- typedSelection: TypedSelection | null;
19
- selectionModel: ModelState;
20
- providerOwnedPaths: readonly string[];
21
- roomVersion: string;
22
- transfer: string;
23
- documents: Readonly<Record<string, string>>;
24
- binaries: Readonly<Record<string, HeldBinary>>;
25
- revisions: Readonly<Record<string, string>>;
26
- changes: Readonly<Record<string, HeadChange>>;
27
- written: Readonly<Record<string, string>>;
8
+ import type { ModelState } from './model.js';
9
+ import type { SearchWindow } from './search.js';
10
+ import type { CommittedWrite, ConversationWrite, CountedRoom, HeldConversation, HeldEntry, MessageWindow, QueryAnswer, QueryRoom, Referrer, RoomCommit, RuntimeDatabase, SearchAsk, StoredEntry, StoredFile, TypedEntry, View, Walked } from './tables.js';
11
+ export type { ConversationWrite, HeldConversation, MessageWindow } from './tables.js';
12
+ export type TransferWriting = {
13
+ readonly token: string | null;
14
+ readonly written: number;
28
15
  };
29
- export type StagedLayer = Pick<ReplicaRecord, 'documents' | 'binaries' | 'revisions' | 'changes' | 'written'>;
30
16
  export type TransferRecord = {
31
- locator: string;
32
- transfer: string;
33
- selection: string;
34
- from: string;
35
- last: string;
36
- pageToken: string | null;
37
- models: {
38
- collection: ModelState;
39
- selection: ModelState;
17
+ readonly locator: string;
18
+ readonly transfer: string;
19
+ readonly selection: string;
20
+ readonly from: string;
21
+ readonly last: string;
22
+ readonly pageToken: string | null;
23
+ readonly writing: TransferWriting | null;
24
+ readonly inventory: BootstrapInventory | null;
25
+ readonly done: BootstrapInventory;
26
+ readonly models: {
27
+ readonly collection: ModelState;
40
28
  };
29
+ readonly key: number | null;
41
30
  };
42
31
  export type PendingState = {
43
32
  readonly drafts: readonly SavedDraft[];
@@ -46,6 +35,9 @@ export type PendingState = {
46
35
  readonly upload?: unknown;
47
36
  readonly accepted?: string;
48
37
  };
38
+ export type TargetRecord = {
39
+ established: boolean;
40
+ };
49
41
  export type QueueRecord = {
50
42
  locator: string;
51
43
  pending: readonly {
@@ -57,72 +49,122 @@ export type PresentationRecord = {
57
49
  app: string;
58
50
  value: unknown;
59
51
  };
60
- export type HeldConversation = {
61
- conversation: string;
62
- read: string | null | undefined;
63
- messages: readonly AcceptedMessage[];
64
- };
65
- export type ConversationWrite = {
66
- conversation: string;
67
- messages: readonly AcceptedMessage[];
68
- read?: string | null;
69
- sealed?: boolean;
52
+ export type ChatSubmission = {
53
+ readonly operation: string;
54
+ readonly text: string;
55
+ readonly turn: string | null;
70
56
  };
71
57
  export type ChatDraftRecord = {
72
58
  conversation: string;
73
59
  text: string;
74
- files: readonly ChatDraftFile[];
75
- turn: string | null;
76
60
  revision: string;
61
+ submitted?: readonly ChatSubmission[];
62
+ moves?: readonly string[];
77
63
  };
78
- export type RecordWrite = {
79
- next: ReplicaRecord;
80
- previous: ReplicaRecord | null;
81
- stored?: StagedLayer;
64
+ export type CallRecord = {
65
+ readonly operation: string;
66
+ readonly name: string;
67
+ readonly input: unknown;
82
68
  };
83
69
  export type AuthoredWrite = {
84
70
  locator: string;
85
- queue: readonly ChangeBatch[];
71
+ queue?: readonly ChangeBatch[];
72
+ founded?: readonly ChangeBatch[];
86
73
  saved?: ReadonlyMap<string, readonly SavedDraft[]>;
87
74
  roomDrafts?: readonly RoomDraftRecord[];
88
75
  consumedRoomDrafts?: readonly string[];
76
+ accepted?: readonly {
77
+ readonly id: string;
78
+ readonly roomVersion: string;
79
+ }[];
80
+ };
81
+ export type StagedPage = {
82
+ readonly entries: readonly StoredEntry[];
83
+ readonly folders: readonly string[];
84
+ };
85
+ export type RefreshedPage = StagedPage & {
86
+ readonly removals: readonly string[];
87
+ readonly folderRemovals: readonly string[];
88
+ };
89
+ export type Opened = {
90
+ readonly rooms: ReadonlyMap<string, ReplicaRecord>;
91
+ readonly transfers: ReadonlyMap<string, TransferRecord>;
92
+ readonly kept: ReadonlyMap<string, ReadonlyMap<string, number>>;
93
+ readonly unindexed: ReadonlySet<number>;
94
+ readonly overlaid: ReadonlyMap<number, ReadonlySet<string>>;
95
+ readonly erasing: boolean;
96
+ readonly orphans: readonly number[];
97
+ readonly lastCompleted: string | null;
98
+ readonly providerLimits: readonly ProviderLimit[];
99
+ readonly capabilities: readonly Capability[];
100
+ readonly member: Member | null;
101
+ readonly targets: Readonly<Record<string, TargetRecord>>;
102
+ readonly presentation: readonly PresentationRecord[];
103
+ };
104
+ export type Commit = {
105
+ readonly rooms: readonly RoomCommit[];
106
+ readonly writes?: readonly AuthoredWrite[];
107
+ readonly files?: readonly StoredFile[];
108
+ readonly whole?: boolean;
109
+ readonly discards?: readonly string[];
89
110
  };
90
111
  export type RuntimeStore = {
91
- all(): Promise<readonly ReplicaRecord[]>;
92
- keepAuthored(input: AuthoredWrite): Promise<void>;
93
- write(input: RecordWrite): Promise<void>;
94
- revokeModels(records: readonly ReplicaRecord[]): Promise<void>;
95
- lastCompleted(): Promise<string | null>;
96
- complete(at: string): Promise<void>;
97
- providerLimits(): Promise<readonly ProviderLimit[]>;
98
- capabilities(): Promise<readonly Capability[]>;
99
- declare(limits: readonly ProviderLimit[], capabilities: readonly Capability[]): Promise<void>;
100
- member(): Promise<Member | null>;
101
- keepMember(member: Member | null): Promise<void>;
112
+ opened(): Promise<Opened>;
113
+ counts(rooms: readonly CountedRoom[]): Promise<readonly number[]>;
114
+ query(plan: Plan, rooms: readonly QueryRoom[], budget: number | null): Promise<QueryAnswer>;
115
+ changes(keys: readonly number[]): number;
116
+ entries(key: number, view: View, paths: readonly string[]): Promise<readonly HeldEntry[]>;
117
+ typed(key: number, view: View, paths: readonly string[]): Promise<readonly TypedEntry[]>;
118
+ referrers(key: number, view: View, targets: readonly string[], kinds: readonly string[]): Promise<readonly Referrer[]>;
119
+ walk(key: number, view: View, after: string | null, bytes: number): Promise<Walked>;
120
+ files(key: number, view: View, after: string | null, limit: number): Promise<readonly {
121
+ readonly path: string;
122
+ readonly revision: string;
123
+ }[]>;
124
+ typedWithin(key: number, view: View, roots: readonly string[], within: boolean): Promise<boolean>;
125
+ search(ask: SearchAsk): Promise<SearchWindow>;
126
+ stage(record: TransferRecord, composition: Composition, page: StagedPage, written?: string): Promise<number | null>;
127
+ transferPart(locator: string, token: string): Promise<Uint8Array | null>;
128
+ keepPart(locator: string, token: string, part: Uint8Array): Promise<void>;
129
+ refresh(key: number, page: RefreshedPage): Promise<void>;
130
+ unrefresh(key: number): Promise<void>;
131
+ commit(commit: Commit): Promise<CommittedWrite>;
132
+ fence(locators: readonly string[]): Promise<void>;
133
+ erase(locator: string | null, limit: number): Promise<boolean>;
134
+ abandon(locator: string, kept?: boolean): Promise<number | null>;
135
+ release(key: number): Promise<void>;
136
+ rederive(key: number, limit: number): Promise<boolean>;
137
+ fact(name: string, value: unknown): Promise<void>;
102
138
  queues(): Promise<readonly QueueRecord[]>;
103
139
  submit(locator: string, id: string, submission: Submission, lost: boolean): Promise<void>;
104
- accept(locator: string, id: string, roomVersion: string): Promise<void>;
105
140
  keepUpload(locator: string, id: string, upload: unknown): Promise<void>;
106
141
  roomDrafts(): Promise<readonly RoomDraftRecord[]>;
107
- presentation(): Promise<readonly PresentationRecord[]>;
108
142
  present(record: PresentationRecord): Promise<void>;
109
143
  conversations(): Promise<readonly HeldConversation[]>;
110
144
  keepMessages(write: ConversationWrite): Promise<void>;
145
+ messageWindow(conversation: string, limit: number, before: readonly [string, string] | null): Promise<MessageWindow>;
146
+ messageCount(conversation: string): Promise<number>;
147
+ turnArrived(conversation: string, turn: string): Promise<boolean>;
111
148
  dropConversations(conversations: readonly string[]): Promise<void>;
112
149
  chatDrafts(): Promise<readonly ChatDraftRecord[]>;
113
- keepChatDraft(record: ChatDraftRecord): Promise<void>;
150
+ keepChatDrafts(records: readonly ChatDraftRecord[]): Promise<void>;
114
151
  dropChatDraft(conversation: string): Promise<void>;
115
- keepRoomDraft(record: RoomDraftRecord): Promise<void>;
152
+ calls(): Promise<readonly CallRecord[]>;
153
+ keepCall(record: CallRecord): Promise<void>;
154
+ dropCall(operation: string): Promise<void>;
155
+ keepRoomDraft(record: RoomDraftRecord, files: readonly StoredFile[]): Promise<void>;
116
156
  discardRoomDraft(locator: string, path: string): Promise<void>;
117
- dropRooms(locators: readonly string[]): Promise<void>;
118
- transfers(): Promise<readonly TransferRecord[]>;
119
- staged(record: TransferRecord): Promise<StagedLayer>;
120
- stage(record: TransferRecord, page: StagedLayer): Promise<void>;
121
- abandon(locator: string): Promise<void>;
157
+ fences(): Promise<readonly string[]>;
158
+ receivedHeads(): Promise<readonly KeptReceipt[]>;
159
+ receivedParts(key: string, count: number): Promise<readonly unknown[]>;
160
+ keepReceived(key: string, head: unknown, part?: {
161
+ index: number;
162
+ value: unknown;
163
+ }): Promise<void>;
164
+ dropReceived(keys: readonly string[]): Promise<void>;
122
165
  generation(): Promise<string | null>;
123
166
  rememberGeneration(value: string): Promise<void>;
124
- close(): void;
167
+ file(key: string, type: string): Promise<Blob>;
125
168
  };
126
- export declare function removeRuntimeStore(): Promise<void>;
127
- export declare function openRuntimeStore(): Promise<RuntimeStore>;
169
+ export declare function openRuntimeStore(fenced: (locator: string) => boolean, authored: RuntimeDatabase): RuntimeStore;
128
170
  //# sourceMappingURL=store.d.ts.map