@agentshouse/mdruntime 0.1.0-c0bed82db8d73 → 0.1.0-c0c1e81da9166

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 (174) hide show
  1. package/README.md +3 -2
  2. package/dist/adapter.d.ts +101 -71
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/attached-model.d.ts +4 -10
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +35 -46
  7. package/dist/bootstrap.d.ts +16 -15
  8. package/dist/bootstrap.d.ts.map +1 -1
  9. package/dist/bootstrap.js +273 -131
  10. package/dist/chain.d.ts +2 -1
  11. package/dist/chain.d.ts.map +1 -1
  12. package/dist/change.d.ts +1 -0
  13. package/dist/change.d.ts.map +1 -1
  14. package/dist/chat-types.d.ts +3 -0
  15. package/dist/chat-types.d.ts.map +1 -0
  16. package/dist/chat-types.js +2 -0
  17. package/dist/client.d.ts +15 -9
  18. package/dist/client.d.ts.map +1 -1
  19. package/dist/client.js +54 -6
  20. package/dist/collection.d.ts +7 -4
  21. package/dist/collection.d.ts.map +1 -1
  22. package/dist/collection.js +24 -19
  23. package/dist/compile.d.ts +6 -6
  24. package/dist/compile.d.ts.map +1 -1
  25. package/dist/compile.js +278 -282
  26. package/dist/connection.d.ts +16 -11
  27. package/dist/connection.d.ts.map +1 -1
  28. package/dist/connection.js +2312 -1988
  29. package/dist/context.d.ts +2 -0
  30. package/dist/context.d.ts.map +1 -0
  31. package/dist/context.js +7 -0
  32. package/dist/conversation-row.d.ts +33 -0
  33. package/dist/conversation-row.d.ts.map +1 -0
  34. package/dist/conversation-row.js +47 -0
  35. package/dist/conversation.d.ts +27 -18
  36. package/dist/conversation.d.ts.map +1 -1
  37. package/dist/conversation.js +489 -260
  38. package/dist/durability.d.ts +6 -1
  39. package/dist/durability.d.ts.map +1 -1
  40. package/dist/entry.d.ts +3 -2
  41. package/dist/entry.d.ts.map +1 -1
  42. package/dist/entry.js +18 -8
  43. package/dist/figures.d.ts +48 -0
  44. package/dist/figures.d.ts.map +1 -0
  45. package/dist/figures.js +197 -0
  46. package/dist/file.d.ts +2 -11
  47. package/dist/file.d.ts.map +1 -1
  48. package/dist/file.js +6 -4
  49. package/dist/host.d.ts +3 -7
  50. package/dist/host.d.ts.map +1 -1
  51. package/dist/host.js +26 -29
  52. package/dist/identity.d.ts +0 -1
  53. package/dist/identity.d.ts.map +1 -1
  54. package/dist/identity.js +0 -3
  55. package/dist/index.d.ts +16 -9
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +6 -1
  58. package/dist/job.d.ts +33 -0
  59. package/dist/job.d.ts.map +1 -0
  60. package/dist/job.js +54 -0
  61. package/dist/live.d.ts +5 -4
  62. package/dist/live.d.ts.map +1 -1
  63. package/dist/live.js +62 -20
  64. package/dist/media.d.ts +8 -0
  65. package/dist/media.d.ts.map +1 -0
  66. package/dist/media.js +218 -0
  67. package/dist/memory.d.ts +13 -6
  68. package/dist/memory.d.ts.map +1 -1
  69. package/dist/memory.js +218 -91
  70. package/dist/messages.d.ts +27 -3
  71. package/dist/messages.d.ts.map +1 -1
  72. package/dist/messages.js +97 -19
  73. package/dist/model.d.ts +8 -10
  74. package/dist/model.d.ts.map +1 -1
  75. package/dist/model.js +6 -18
  76. package/dist/observation.d.ts +3 -2
  77. package/dist/observation.d.ts.map +1 -1
  78. package/dist/observation.js +8 -3
  79. package/dist/outcome.d.ts +13 -5
  80. package/dist/outcome.d.ts.map +1 -1
  81. package/dist/outcome.js +16 -2
  82. package/dist/overlay.d.ts +1 -0
  83. package/dist/overlay.d.ts.map +1 -1
  84. package/dist/overlay.js +11 -0
  85. package/dist/parts.d.ts +59 -0
  86. package/dist/parts.d.ts.map +1 -0
  87. package/dist/parts.js +118 -0
  88. package/dist/paths.d.ts +1 -0
  89. package/dist/paths.d.ts.map +1 -1
  90. package/dist/paths.js +4 -0
  91. package/dist/query.d.ts +18 -207
  92. package/dist/query.d.ts.map +1 -1
  93. package/dist/query.js +3 -505
  94. package/dist/questions.d.ts +32 -0
  95. package/dist/questions.d.ts.map +1 -0
  96. package/dist/questions.js +118 -0
  97. package/dist/reach.d.ts +18 -11
  98. package/dist/reach.d.ts.map +1 -1
  99. package/dist/reach.js +201 -126
  100. package/dist/react.d.ts +3 -1
  101. package/dist/react.d.ts.map +1 -1
  102. package/dist/read.d.ts +7 -0
  103. package/dist/read.d.ts.map +1 -0
  104. package/dist/read.js +17 -0
  105. package/dist/readiness.d.ts +3 -17
  106. package/dist/readiness.d.ts.map +1 -1
  107. package/dist/readiness.js +4 -10
  108. package/dist/recovery.d.ts +1 -0
  109. package/dist/recovery.d.ts.map +1 -1
  110. package/dist/recovery.js +35 -1
  111. package/dist/refresh.d.ts +7 -5
  112. package/dist/refresh.d.ts.map +1 -1
  113. package/dist/refresh.js +34 -10
  114. package/dist/replica.d.ts +10 -9
  115. package/dist/replica.d.ts.map +1 -1
  116. package/dist/replica.js +53 -21
  117. package/dist/room-draft.d.ts +21 -5
  118. package/dist/room-draft.d.ts.map +1 -1
  119. package/dist/room-draft.js +98 -51
  120. package/dist/rows.d.ts +18 -16
  121. package/dist/rows.d.ts.map +1 -1
  122. package/dist/rows.js +45 -153
  123. package/dist/save.d.ts +2 -0
  124. package/dist/save.d.ts.map +1 -1
  125. package/dist/save.js +22 -13
  126. package/dist/search.d.ts +12 -63
  127. package/dist/search.d.ts.map +1 -1
  128. package/dist/search.js +9 -52
  129. package/dist/shared.d.ts +0 -1
  130. package/dist/shared.d.ts.map +1 -1
  131. package/dist/shared.js +0 -10
  132. package/dist/source.d.ts +61 -0
  133. package/dist/source.d.ts.map +1 -0
  134. package/dist/source.js +81 -0
  135. package/dist/status.d.ts +4 -5
  136. package/dist/status.d.ts.map +1 -1
  137. package/dist/status.js +3 -7
  138. package/dist/store.d.ts +104 -62
  139. package/dist/store.d.ts.map +1 -1
  140. package/dist/store.js +159 -161
  141. package/dist/stored.d.ts +66 -55
  142. package/dist/stored.d.ts.map +1 -1
  143. package/dist/stored.js +343 -273
  144. package/dist/tables.d.ts +110 -65
  145. package/dist/tables.d.ts.map +1 -1
  146. package/dist/tables.js +188 -99
  147. package/dist/tallies.d.ts +18 -0
  148. package/dist/tallies.d.ts.map +1 -0
  149. package/dist/tallies.js +129 -0
  150. package/dist/transfer.d.ts +0 -5
  151. package/dist/transfer.d.ts.map +1 -1
  152. package/dist/validation.d.ts +3 -4
  153. package/dist/validation.d.ts.map +1 -1
  154. package/dist/validation.js +42 -100
  155. package/dist/windows.d.ts +1 -12
  156. package/dist/windows.d.ts.map +1 -1
  157. package/dist/windows.js +2 -75
  158. package/dist/wire.d.ts +18 -8
  159. package/dist/wire.d.ts.map +1 -1
  160. package/dist/wire.js +6 -2
  161. package/package.json +2 -3
  162. package/AGENTS.md +0 -312
  163. package/dist/fence.d.ts +0 -6
  164. package/dist/fence.d.ts.map +0 -1
  165. package/dist/fence.js +0 -10
  166. package/dist/fulltext.d.ts +0 -27
  167. package/dist/fulltext.d.ts.map +0 -1
  168. package/dist/fulltext.js +0 -368
  169. package/dist/reads.d.ts +0 -11
  170. package/dist/reads.d.ts.map +0 -1
  171. package/dist/reads.js +0 -100
  172. package/dist/words.d.ts +0 -19
  173. package/dist/words.d.ts.map +0 -1
  174. package/dist/words.js +0 -150
package/dist/store.js CHANGED
@@ -1,5 +1,9 @@
1
+ import { composedOf } from './collection.js';
1
2
  import { binaryLocalId } from './identity.js';
2
3
  const FILE = '\u0000file';
4
+ function batchFacts(batch) {
5
+ return { paths: batch.changes.map(({ path }) => path), moving: batch.between !== undefined };
6
+ }
3
7
  function batchFiles(batch) {
4
8
  return batch.changes.flatMap((change) => (change.kind === 'binary' ? [change.localId] : []));
5
9
  }
@@ -9,7 +13,8 @@ function draftFiles(drafts) {
9
13
  function roomDraftRow(record) {
10
14
  return { path: record.path, record: JSON.stringify(record), files: draftFiles([record]) };
11
15
  }
12
- function authoredRows({ locator, queue, founded, saved, roomDrafts, consumedRoomDrafts, accepted }, held) {
16
+ function authoredRows({ locator, queue, stored, founded, saved, roomDrafts, consumedRoomDrafts, }) {
17
+ const held = new Set((stored ?? []).map(({ id }) => id));
13
18
  return {
14
19
  locator,
15
20
  ...(queue === undefined
@@ -17,7 +22,7 @@ function authoredRows({ locator, queue, founded, saved, roomDrafts, consumedRoom
17
22
  : {
18
23
  order: queue.map(({ id }) => id),
19
24
  added: queue
20
- .filter(({ id }) => held?.has(id) !== true)
25
+ .filter(({ id }) => !held.has(id))
21
26
  .map((batch) => {
22
27
  const drafts = saved?.get(batch.id) ?? [];
23
28
  return {
@@ -29,6 +34,7 @@ function authoredRows({ locator, queue, founded, saved, roomDrafts, consumedRoom
29
34
  lost: false,
30
35
  }),
31
36
  files: [...batchFiles(batch), ...draftFiles(drafts)],
37
+ ...batchFacts(batch),
32
38
  };
33
39
  }),
34
40
  }),
@@ -39,18 +45,11 @@ function authoredRows({ locator, queue, founded, saved, roomDrafts, consumedRoom
39
45
  id: batch.id,
40
46
  batch: JSON.stringify(batch),
41
47
  files: batchFiles(batch),
48
+ ...batchFacts(batch),
42
49
  })),
43
50
  }),
44
51
  ...(roomDrafts === undefined ? {} : { roomDrafts: roomDrafts.map(roomDraftRow) }),
45
52
  ...(consumedRoomDrafts === undefined ? {} : { consumedRoomDrafts }),
46
- ...(accepted === undefined
47
- ? {}
48
- : {
49
- amendments: accepted.map(({ id, roomVersion }) => ({
50
- id,
51
- amendment: JSON.stringify({ accepted: roomVersion }),
52
- })),
53
- }),
54
53
  };
55
54
  }
56
55
  function marked(value) {
@@ -85,10 +84,17 @@ async function filed(value, read) {
85
84
  restored[name] = await filed(item, read);
86
85
  return restored;
87
86
  }
87
+ function roomOf(row) {
88
+ return {
89
+ record: { ...JSON.parse(row.record), key: row.key },
90
+ indexed: row.indexed,
91
+ documents: row.documents,
92
+ };
93
+ }
88
94
  function json(value, fallback) {
89
95
  return value === undefined ? fallback : JSON.parse(value);
90
96
  }
91
- export function openRuntimeStore(fenced, authored) {
97
+ export function openRuntimeStore(authored) {
92
98
  const keys = new WeakMap();
93
99
  const read = async (key, type) => {
94
100
  const blob = await authored.ask({ kind: 'authored.file', key, type });
@@ -97,8 +103,6 @@ export function openRuntimeStore(fenced, authored) {
97
103
  };
98
104
  const restored = async (records) => Promise.all(records.map(async (record) => (await filed(JSON.parse(record), read))));
99
105
  const amend = async (locator, id, amendment) => {
100
- if (fenced(locator))
101
- return;
102
106
  await authored.ask({
103
107
  kind: 'authored.amend',
104
108
  locator,
@@ -107,56 +111,95 @@ export function openRuntimeStore(fenced, authored) {
107
111
  });
108
112
  };
109
113
  const fact = (name) => authored.ask({ kind: 'authored.fact', name });
110
- const queued = new Map();
111
114
  const changed = new Map();
112
115
  const change = (key) => changed.set(key, (changed.get(key) ?? 0) + 1);
113
- const rows = (writes) => writes.map((write) => authoredRows(write, queued.get(write.locator)));
114
- const noted = (writes) => {
115
- for (const { locator, queue } of writes) {
116
- if (queue !== undefined)
117
- queued.set(locator, new Set(queue.map(({ id }) => id)));
118
- }
119
- };
120
116
  return {
121
- async opened() {
122
- const held = await authored.ask({ kind: 'replica.open' });
123
- const unindexed = new Set(held.keys.flatMap(({ key, rederiving }) => (rederiving === null ? [] : [key])));
124
- const overlaid = new Map();
125
- for (const { key, path } of held.overlaid) {
126
- const paths = overlaid.get(key) ?? new Set();
127
- paths.add(path);
128
- overlaid.set(key, paths);
129
- }
117
+ opened() {
118
+ return authored.ask({ kind: 'replica.open' });
119
+ },
120
+ async rooms(locators) {
121
+ const held = await authored.ask({ kind: 'replica.rooms', locators: locators ?? null });
122
+ return held.map(roomOf);
123
+ },
124
+ async room(locator) {
125
+ const { room, queue } = await authored.ask({ kind: 'replica.room', locator });
130
126
  return {
131
- rooms: new Map(held.rooms
132
- .filter(({ locator }) => !fenced(locator))
133
- .map(({ locator, key, record }) => [
134
- locator,
135
- { ...JSON.parse(record), key },
136
- ])),
137
- transfers: new Map(held.transfers
138
- .filter(({ locator }) => !fenced(locator))
139
- .map(({ locator, key, record }) => [
127
+ room: room === null ? null : { ...roomOf(room), overlaid: new Set(room.overlaid) },
128
+ queue: queue.map(({ batch, state }) => ({
129
+ batch: JSON.parse(batch),
130
+ state: JSON.parse(state),
131
+ })),
132
+ };
133
+ },
134
+ async covering() {
135
+ const { rooms, queues } = await authored.ask({ kind: 'replica.covering' });
136
+ return {
137
+ rooms: new Map(rooms.map(({ locator, ...room }) => [locator, room])),
138
+ queues: new Map(queues.map(({ locator, ids }) => [locator, ids])),
139
+ };
140
+ },
141
+ offline(locator) {
142
+ return authored.ask({ kind: 'replica.offline', locator });
143
+ },
144
+ async held() {
145
+ const { held, staged } = await authored.ask({ kind: 'replica.held' });
146
+ return { held: new Set(held), staged: new Set(staged) };
147
+ },
148
+ async status() {
149
+ const { queued, lastCompleted, changes, resets, returned } = await authored.ask({
150
+ kind: 'authored.status',
151
+ });
152
+ return {
153
+ queued,
154
+ lastCompleted: json(lastCompleted ?? undefined, null),
155
+ unsent: changes.map(({ locator, path }) => ({ room: locator, path })),
156
+ resets,
157
+ returned: returned.map((record) => JSON.parse(record)),
158
+ };
159
+ },
160
+ async batch(locator, id) {
161
+ const held = await authored.ask({ kind: 'authored.batch', locator, id });
162
+ return held === null ? null : JSON.parse(held);
163
+ },
164
+ order(locator) {
165
+ return authored.ask({ kind: 'authored.order', locator });
166
+ },
167
+ queued() {
168
+ return authored.ask({ kind: 'authored.queued' });
169
+ },
170
+ async moving() {
171
+ const { queues, pending } = await authored.ask({ kind: 'authored.moving' });
172
+ return {
173
+ queued: new Map(queues.map(({ locator, ids }) => [locator, ids])),
174
+ moving: pending.map(({ locator, batch, state }) => ({
140
175
  locator,
141
- { ...JSON.parse(record), key },
142
- ])),
143
- unindexed,
144
- overlaid,
145
- erasing: held.erasing.length > 0,
146
- orphans: held.orphans,
147
- lastCompleted: json(held.facts.lastCompleted, null),
148
- providerLimits: json(held.facts.providerLimits, []),
149
- capabilities: json(held.facts.capabilities, []),
150
- member: json(held.facts.member, null),
151
- targets: json(held.facts.targets, {}),
152
- presentation: held.presentation.map(({ app, value }) => ({
153
- app,
154
- value: JSON.parse(value),
176
+ batch: JSON.parse(batch),
177
+ state: JSON.parse(state),
155
178
  })),
156
179
  };
157
180
  },
158
- counts(rooms) {
159
- return authored.ask({ kind: 'replica.counts', rooms });
181
+ async pending(locator, id) {
182
+ const { state, room } = await authored.ask({ kind: 'authored.pending', locator, id });
183
+ return { state: state === null ? undefined : JSON.parse(state), room };
184
+ },
185
+ async facts() {
186
+ const held = await authored.ask({ kind: 'replica.facts' });
187
+ return {
188
+ lastCompleted: json(held.lastCompleted, null),
189
+ providerLimits: json(held.providerLimits, []),
190
+ capabilities: json(held.capabilities, []),
191
+ member: json(held.member, null),
192
+ targets: json(held.targets, {}),
193
+ conversationList: json(held.conversationList, null),
194
+ conversationCursor: json(held.conversationCursor, null),
195
+ };
196
+ },
197
+ async presentation(app) {
198
+ const held = await authored.ask({ kind: 'replica.presentation', app });
199
+ return held === null ? undefined : JSON.parse(held);
200
+ },
201
+ async demote() {
202
+ await authored.ask({ kind: 'replica.demote' });
160
203
  },
161
204
  query(plan, rooms, budget) {
162
205
  return authored.ask({ kind: 'replica.query', plan, rooms, budget });
@@ -170,51 +213,42 @@ export function openRuntimeStore(fenced, authored) {
170
213
  typed(key, view, paths) {
171
214
  return authored.ask({ kind: 'replica.typed', key, view, paths });
172
215
  },
173
- referrers(key, view, targets, kinds) {
174
- return authored.ask({ kind: 'replica.referrers', key, view, targets, kinds });
216
+ referrers(key, view, targets) {
217
+ return authored.ask({ kind: 'replica.referrers', key, view, targets });
175
218
  },
176
- walk(key, view, after, bytes) {
177
- return authored.ask({ kind: 'replica.walk', key, view, after, bytes });
178
- },
179
- files(key, view, after, limit) {
180
- return authored.ask({ kind: 'replica.files', key, view, after, limit });
219
+ folders(key, view, paths) {
220
+ return authored.ask({ kind: 'replica.folders', key, view, paths });
181
221
  },
182
222
  typedWithin(key, view, roots, within) {
183
223
  return authored.ask({ kind: 'replica.typedWithin', key, view, roots, within });
184
224
  },
185
- search(ask) {
186
- return authored.ask({ kind: 'replica.search', ...ask });
187
- },
188
- async stage(record, composition, page, written) {
189
- if (fenced(record.locator))
190
- return null;
191
- const { key, ...kept } = record;
225
+ stage(record, composition, page) {
192
226
  return authored.ask({
193
227
  kind: 'replica.stage',
194
228
  locator: record.locator,
195
229
  transfer: record.transfer,
196
- record: JSON.stringify(kept),
197
- key,
198
- composition,
230
+ key: record.key,
231
+ fingerprint: composedOf(composition).fingerprint,
199
232
  entries: page.entries,
200
233
  folders: page.folders,
201
- ...(written === undefined ? {} : { written }),
234
+ part: page.part ?? null,
202
235
  });
203
236
  },
204
- async transferPart(locator, token) {
205
- if (fenced(locator))
206
- return null;
207
- return authored.ask({ kind: 'replica.transferPart', locator, token });
208
- },
209
- async keepPart(locator, token, part) {
210
- if (fenced(locator))
211
- return;
212
- await authored.ask({ kind: 'replica.keepPart', locator, token, part });
237
+ resume(record, composition, parts, published) {
238
+ return authored.ask({
239
+ kind: 'replica.resume',
240
+ locator: record.locator,
241
+ transfer: record.transfer,
242
+ fingerprint: composedOf(composition).fingerprint,
243
+ parts,
244
+ published,
245
+ });
213
246
  },
214
- async refresh(key, page) {
247
+ async refresh(key, composition, page) {
215
248
  await authored.ask({
216
249
  kind: 'replica.refresh',
217
250
  key,
251
+ composed: composedOf(composition),
218
252
  entries: page.entries,
219
253
  removals: page.removals,
220
254
  folders: page.folders,
@@ -224,82 +258,59 @@ export function openRuntimeStore(fenced, authored) {
224
258
  async unrefresh(key) {
225
259
  await authored.ask({ kind: 'replica.unrefresh', key });
226
260
  },
227
- async commit({ rooms, writes = [], files = [], whole = false, discards = [] }) {
228
- const kept = whole ? writes : writes.filter(({ locator }) => !fenced(locator));
229
- const refused = whole ? kept.find(({ locator }) => fenced(locator)) : undefined;
230
- if (refused !== undefined) {
231
- return { fenced: refused.locator, counts: {}, changed: {}, indexed: {} };
232
- }
261
+ commit({ rooms, writes = [], files = [], whole = false }) {
233
262
  for (const room of rooms)
234
263
  change(room.key);
235
- const committed = await authored.ask({
264
+ return authored.ask({
236
265
  kind: 'replica.commit',
237
- ...(kept.length === 0 && files.length === 0 && discards.length === 0
266
+ ...(writes.length === 0 && files.length === 0
238
267
  ? {}
239
- : { authored: { writes: rows(kept), files, whole, discards } }),
240
- rooms: rooms.filter(({ locator }) => !fenced(locator)),
268
+ : { authored: { writes: writes.map(authoredRows), files, whole } }),
269
+ rooms,
241
270
  });
242
- if (committed.fenced === null || !whole)
243
- noted(kept);
244
- for (const locator of discards)
245
- queued.delete(locator);
246
- return committed;
247
271
  },
248
272
  async fence(locators) {
249
273
  await authored.ask({ kind: 'replica.fence', locators });
250
- for (const locator of locators)
251
- queued.delete(locator);
252
274
  },
253
275
  async erase(locator, limit) {
254
276
  return (await authored.ask({ kind: 'replica.erase', locator, limit })).remaining;
255
277
  },
256
- async abandon(locator, kept = false) {
257
- if (fenced(locator))
258
- return null;
259
- return authored.ask({ kind: 'replica.abandon', locator, kept });
278
+ async abandon(locator) {
279
+ await authored.ask({ kind: 'replica.abandon', locator });
280
+ },
281
+ async unfence(locators) {
282
+ return new Set(await authored.ask({ kind: 'replica.unfence', locators }));
260
283
  },
261
284
  async release(key) {
262
285
  await authored.ask({ kind: 'replica.release', key });
263
286
  },
264
- async rederive(key, limit) {
287
+ async rederive(key, composition, bytes, ms, floor) {
265
288
  change(key);
266
- return (await authored.ask({ kind: 'replica.rederive', key, limit })).done;
289
+ return authored.ask({
290
+ kind: 'replica.rederive',
291
+ key,
292
+ composed: composedOf(composition),
293
+ bytes,
294
+ ms,
295
+ floor,
296
+ });
267
297
  },
268
298
  async fact(name, value) {
269
299
  await authored.ask({ kind: 'replica.fact', name, value: JSON.stringify(value) });
270
300
  },
271
- async queues() {
272
- const { queues, pending } = await authored.ask({ kind: 'authored.queues' });
273
- queued.clear();
274
- for (const queue of queues)
275
- queued.set(queue.locator, new Set(queue.ids));
276
- const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
277
- return queues
278
- .filter((queue) => !fenced(queue.locator))
279
- .map((queue) => ({
280
- locator: queue.locator,
281
- pending: queue.ids.map((id) => {
282
- const record = byId.get(`${queue.locator}\0${id}`);
283
- if (record === undefined)
284
- throw new Error(`Missing Pending Change ${queue.locator}/${id}`);
285
- return {
286
- batch: JSON.parse(record.batch),
287
- state: JSON.parse(record.state),
288
- };
289
- }),
290
- }));
291
- },
292
301
  submit(locator, id, submission, lost) {
293
302
  return amend(locator, id, { submission, lost });
294
303
  },
295
304
  keepUpload(locator, id, upload) {
296
305
  return amend(locator, id, { upload });
297
306
  },
298
- async roomDrafts() {
299
- const held = await authored.ask({ kind: 'authored.roomDrafts' });
300
- return held
301
- .map((record) => JSON.parse(record))
302
- .filter((record) => !fenced(record.locator));
307
+ async roomDrafts(locator, paths) {
308
+ const held = await authored.ask({
309
+ kind: 'authored.roomDrafts',
310
+ locator: locator ?? null,
311
+ paths: paths ?? null,
312
+ });
313
+ return held.map((record) => JSON.parse(record));
303
314
  },
304
315
  async present(record) {
305
316
  await authored.ask({
@@ -308,21 +319,27 @@ export function openRuntimeStore(fenced, authored) {
308
319
  value: JSON.stringify(record.value ?? null),
309
320
  });
310
321
  },
311
- conversations() {
312
- return authored.ask({ kind: 'conversation.held' });
322
+ conversations(conversations) {
323
+ return authored.ask({ kind: 'conversation.held', conversations: conversations ?? null });
313
324
  },
314
325
  async keepMessages(write) {
315
326
  await authored.ask({ kind: 'conversation.keep', ...write });
316
327
  },
317
- messageWindow(conversation, limit, before) {
318
- return authored.ask({ kind: 'conversation.window', conversation, limit, before });
328
+ messageWindow(conversation, limit, before, phrase = null) {
329
+ return authored.ask({ kind: 'conversation.window', conversation, limit, before, phrase });
319
330
  },
320
- messageCount(conversation) {
321
- return authored.ask({ kind: 'conversation.count', conversation });
331
+ messageCount(conversation, phrase = null) {
332
+ return authored.ask({ kind: 'conversation.count', conversation, phrase });
322
333
  },
323
334
  turnArrived(conversation, turn) {
324
335
  return authored.ask({ kind: 'conversation.turn', conversation, turn });
325
336
  },
337
+ conversationRows(conversations) {
338
+ return authored.ask({ kind: 'conversation.rows', conversations });
339
+ },
340
+ jobMarkers(conversation) {
341
+ return authored.ask({ kind: 'conversation.jobs', conversation });
342
+ },
326
343
  async dropConversations(conversations) {
327
344
  await authored.ask({ kind: 'conversation.drop', conversations });
328
345
  },
@@ -330,6 +347,10 @@ export function openRuntimeStore(fenced, authored) {
330
347
  const records = await authored.ask({ kind: 'authored.chatDrafts' });
331
348
  return records.map((record) => JSON.parse(record));
332
349
  },
350
+ async chatDraft(conversation) {
351
+ const record = await authored.ask({ kind: 'authored.chatDraft.read', conversation });
352
+ return record === null ? null : JSON.parse(record);
353
+ },
333
354
  async keepChatDrafts(records) {
334
355
  await authored.ask({
335
356
  kind: 'authored.chatDraft',
@@ -359,8 +380,6 @@ export function openRuntimeStore(fenced, authored) {
359
380
  await authored.ask({ kind: 'authored.call', operation, kept: null, files: [] });
360
381
  },
361
382
  async keepRoomDraft(record, files) {
362
- if (fenced(record.locator))
363
- return;
364
383
  const { path, ...kept } = roomDraftRow(record);
365
384
  await authored.ask({
366
385
  kind: 'authored.roomDraft',
@@ -371,32 +390,11 @@ export function openRuntimeStore(fenced, authored) {
371
390
  });
372
391
  },
373
392
  async discardRoomDraft(locator, path) {
374
- if (fenced(locator))
375
- return;
376
393
  await authored.ask({ kind: 'authored.roomDraft', locator, path, kept: null, files: [] });
377
394
  },
378
395
  fences() {
379
396
  return authored.ask({ kind: 'authored.fences' });
380
397
  },
381
- receivedHeads() {
382
- return authored.ask({ kind: 'replica.received' });
383
- },
384
- receivedParts(key, count) {
385
- return authored.ask({ kind: 'replica.receivedParts', key, count });
386
- },
387
- async keepReceived(key, head, part) {
388
- await authored.ask({
389
- kind: 'replica.receive',
390
- key,
391
- head: JSON.stringify(head),
392
- ...(part === undefined
393
- ? {}
394
- : { part: { index: part.index, value: JSON.stringify(part.value) } }),
395
- });
396
- },
397
- async dropReceived(keys) {
398
- await authored.ask({ kind: 'replica.unreceive', keys });
399
- },
400
398
  generation() {
401
399
  return fact('generation');
402
400
  },