@agentshouse/mdruntime 0.1.0-cc2e934017fb1 → 0.1.0-cc4575cb1254b

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 (265) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +15 -24
  4. package/dist/act-lanes.d.ts +30 -0
  5. package/dist/act-lanes.d.ts.map +1 -0
  6. package/dist/act-lanes.js +225 -0
  7. package/dist/actions.d.ts +8 -2
  8. package/dist/actions.d.ts.map +1 -1
  9. package/dist/actions.js +139 -68
  10. package/dist/adapter.d.ts +114 -24
  11. package/dist/adapter.d.ts.map +1 -1
  12. package/dist/attached-model.d.ts +0 -1
  13. package/dist/attached-model.d.ts.map +1 -1
  14. package/dist/attached-model.js +2 -7
  15. package/dist/authored.d.ts +88 -0
  16. package/dist/authored.d.ts.map +1 -0
  17. package/dist/authored.js +347 -0
  18. package/dist/binary.d.ts +6 -2
  19. package/dist/binary.d.ts.map +1 -1
  20. package/dist/binary.js +10 -3
  21. package/dist/change.d.ts +6 -2
  22. package/dist/change.d.ts.map +1 -1
  23. package/dist/change.js +3 -0
  24. package/dist/chat-types.d.ts +0 -2
  25. package/dist/chat-types.d.ts.map +1 -1
  26. package/dist/chat-types.js +2 -4
  27. package/dist/client.d.ts +20 -14
  28. package/dist/client.d.ts.map +1 -1
  29. package/dist/client.js +32 -60
  30. package/dist/collection.d.ts +5 -1
  31. package/dist/collection.d.ts.map +1 -1
  32. package/dist/collection.js +16 -8
  33. package/dist/column.d.ts +5 -0
  34. package/dist/column.d.ts.map +1 -0
  35. package/dist/column.js +9 -0
  36. package/dist/compile.d.ts +2 -0
  37. package/dist/compile.d.ts.map +1 -1
  38. package/dist/compile.js +21 -11
  39. package/dist/connection.d.ts +1 -1
  40. package/dist/connection.d.ts.map +1 -1
  41. package/dist/connection.js +22 -16
  42. package/dist/context.d.ts.map +1 -1
  43. package/dist/context.js +1 -1
  44. package/dist/conversation-live.d.ts +23 -10
  45. package/dist/conversation-live.d.ts.map +1 -1
  46. package/dist/conversation-live.js +18 -8
  47. package/dist/conversation-row.d.ts +8 -1
  48. package/dist/conversation-row.d.ts.map +1 -1
  49. package/dist/conversation-row.js +20 -7
  50. package/dist/conversation.d.ts +26 -15
  51. package/dist/conversation.d.ts.map +1 -1
  52. package/dist/conversation.js +270 -206
  53. package/dist/declaration.js +1 -1
  54. package/dist/discovery.d.ts +3 -1
  55. package/dist/discovery.d.ts.map +1 -1
  56. package/dist/discovery.js +36 -9
  57. package/dist/download.d.ts +6 -0
  58. package/dist/download.d.ts.map +1 -0
  59. package/dist/download.js +42 -0
  60. package/dist/durability.d.ts +5 -0
  61. package/dist/durability.d.ts.map +1 -1
  62. package/dist/durability.js +7 -0
  63. package/dist/entry.d.ts +14 -0
  64. package/dist/entry.d.ts.map +1 -1
  65. package/dist/entry.js +45 -16
  66. package/dist/expectation.d.ts +25 -14
  67. package/dist/expectation.d.ts.map +1 -1
  68. package/dist/expectation.js +51 -20
  69. package/dist/failure.d.ts +2 -0
  70. package/dist/failure.d.ts.map +1 -1
  71. package/dist/failure.js +6 -1
  72. package/dist/figures.d.ts.map +1 -1
  73. package/dist/figures.js +4 -2
  74. package/dist/file.d.ts +1 -1
  75. package/dist/file.d.ts.map +1 -1
  76. package/dist/file.js +3 -2
  77. package/dist/host.d.ts +7 -2
  78. package/dist/host.d.ts.map +1 -1
  79. package/dist/host.js +80 -34
  80. package/dist/house-query.d.ts +24 -0
  81. package/dist/house-query.d.ts.map +1 -0
  82. package/dist/house-query.js +67 -0
  83. package/dist/index.d.ts +18 -11
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +12 -6
  86. package/dist/install.d.ts +10 -4
  87. package/dist/install.d.ts.map +1 -1
  88. package/dist/install.js +45 -46
  89. package/dist/lifecycle.d.ts +1 -1
  90. package/dist/lifecycle.d.ts.map +1 -1
  91. package/dist/lifecycle.js +50 -32
  92. package/dist/listing.d.ts +24 -12
  93. package/dist/listing.d.ts.map +1 -1
  94. package/dist/listing.js +50 -21
  95. package/dist/live.d.ts +5 -3
  96. package/dist/live.d.ts.map +1 -1
  97. package/dist/live.js +71 -30
  98. package/dist/loaded.d.ts +7 -0
  99. package/dist/loaded.d.ts.map +1 -0
  100. package/dist/loaded.js +46 -0
  101. package/dist/locks.d.ts.map +1 -1
  102. package/dist/locks.js +4 -3
  103. package/dist/lost.d.ts.map +1 -1
  104. package/dist/lost.js +2 -3
  105. package/dist/media.d.ts +19 -3
  106. package/dist/media.d.ts.map +1 -1
  107. package/dist/media.js +167 -33
  108. package/dist/memory.d.ts +7 -3
  109. package/dist/memory.d.ts.map +1 -1
  110. package/dist/memory.js +77 -29
  111. package/dist/messages.d.ts +17 -3
  112. package/dist/messages.d.ts.map +1 -1
  113. package/dist/messages.js +29 -10
  114. package/dist/modal.d.ts +2 -0
  115. package/dist/modal.d.ts.map +1 -0
  116. package/dist/modal.js +11 -0
  117. package/dist/model.d.ts +4 -2
  118. package/dist/model.d.ts.map +1 -1
  119. package/dist/model.js +7 -1
  120. package/dist/models.d.ts.map +1 -1
  121. package/dist/models.js +5 -8
  122. package/dist/name.d.ts +0 -1
  123. package/dist/name.d.ts.map +1 -1
  124. package/dist/name.js +3 -7
  125. package/dist/observation.d.ts +29 -12
  126. package/dist/observation.d.ts.map +1 -1
  127. package/dist/observation.js +206 -69
  128. package/dist/online.d.ts +7 -0
  129. package/dist/online.d.ts.map +1 -0
  130. package/dist/online.js +29 -0
  131. package/dist/opening.d.ts.map +1 -1
  132. package/dist/opening.js +20 -10
  133. package/dist/outcome.d.ts +24 -4
  134. package/dist/outcome.d.ts.map +1 -1
  135. package/dist/outcome.js +33 -3
  136. package/dist/overlay.d.ts +7 -4
  137. package/dist/overlay.d.ts.map +1 -1
  138. package/dist/overlay.js +11 -9
  139. package/dist/parts.d.ts +4 -9
  140. package/dist/parts.d.ts.map +1 -1
  141. package/dist/parts.js +30 -15
  142. package/dist/preparation.d.ts +33 -7
  143. package/dist/preparation.d.ts.map +1 -1
  144. package/dist/preparation.js +198 -87
  145. package/dist/presence.d.ts +8 -2
  146. package/dist/presence.d.ts.map +1 -1
  147. package/dist/presence.js +24 -13
  148. package/dist/queries.d.ts +2 -2
  149. package/dist/queries.d.ts.map +1 -1
  150. package/dist/queries.js +81 -64
  151. package/dist/query.d.ts +2 -2
  152. package/dist/questions.d.ts +1 -5
  153. package/dist/questions.d.ts.map +1 -1
  154. package/dist/questions.js +3 -8
  155. package/dist/queue.d.ts +2 -2
  156. package/dist/queue.d.ts.map +1 -1
  157. package/dist/queue.js +73 -48
  158. package/dist/reach.d.ts +15 -6
  159. package/dist/reach.d.ts.map +1 -1
  160. package/dist/reach.js +166 -41
  161. package/dist/react.d.ts +11 -5
  162. package/dist/react.d.ts.map +1 -1
  163. package/dist/react.js +28 -5
  164. package/dist/readiness.d.ts +20 -4
  165. package/dist/readiness.d.ts.map +1 -1
  166. package/dist/readiness.js +17 -10
  167. package/dist/reads.d.ts +4 -2
  168. package/dist/reads.d.ts.map +1 -1
  169. package/dist/reads.js +7 -3
  170. package/dist/recovery.d.ts +4 -1
  171. package/dist/recovery.d.ts.map +1 -1
  172. package/dist/recovery.js +31 -8
  173. package/dist/reference-forms.d.ts +4 -0
  174. package/dist/reference-forms.d.ts.map +1 -0
  175. package/dist/reference-forms.js +74 -0
  176. package/dist/refresh.d.ts +1 -1
  177. package/dist/refresh.js +4 -4
  178. package/dist/refusal.d.ts.map +1 -1
  179. package/dist/refusal.js +1 -3
  180. package/dist/replica.d.ts.map +1 -1
  181. package/dist/replica.js +4 -4
  182. package/dist/retried.d.ts +30 -0
  183. package/dist/retried.d.ts.map +1 -0
  184. package/dist/retried.js +72 -0
  185. package/dist/room-draft.d.ts +30 -5
  186. package/dist/room-draft.d.ts.map +1 -1
  187. package/dist/room-draft.js +258 -32
  188. package/dist/room-drafts.d.ts.map +1 -1
  189. package/dist/room-drafts.js +11 -6
  190. package/dist/room-list.d.ts +10 -0
  191. package/dist/room-list.d.ts.map +1 -0
  192. package/dist/room-list.js +45 -0
  193. package/dist/rows.d.ts +10 -2
  194. package/dist/rows.d.ts.map +1 -1
  195. package/dist/rows.js +23 -10
  196. package/dist/running.d.ts +5 -0
  197. package/dist/running.d.ts.map +1 -0
  198. package/dist/running.js +10 -0
  199. package/dist/runtime.d.ts +6 -4
  200. package/dist/runtime.d.ts.map +1 -1
  201. package/dist/save.d.ts +2 -0
  202. package/dist/save.d.ts.map +1 -1
  203. package/dist/save.js +105 -124
  204. package/dist/saves.d.ts +4 -2
  205. package/dist/saves.d.ts.map +1 -1
  206. package/dist/saves.js +66 -21
  207. package/dist/seed.d.ts.map +1 -1
  208. package/dist/seed.js +2 -2
  209. package/dist/shown.d.ts +5 -2
  210. package/dist/shown.d.ts.map +1 -1
  211. package/dist/shown.js +79 -43
  212. package/dist/socket/lanes.d.ts +12 -4
  213. package/dist/socket/lanes.d.ts.map +1 -1
  214. package/dist/socket/lanes.js +34 -8
  215. package/dist/socket/session.d.ts +4 -1
  216. package/dist/socket/session.d.ts.map +1 -1
  217. package/dist/socket/session.js +3 -0
  218. package/dist/socket.d.ts +4 -3
  219. package/dist/socket.d.ts.map +1 -1
  220. package/dist/socket.js +4 -9
  221. package/dist/source.d.ts +7 -7
  222. package/dist/source.d.ts.map +1 -1
  223. package/dist/source.js +15 -2
  224. package/dist/store/installs.d.ts +2 -2
  225. package/dist/store/installs.d.ts.map +1 -1
  226. package/dist/store/installs.js +10 -4
  227. package/dist/store/readiness.d.ts +5 -4
  228. package/dist/store/readiness.d.ts.map +1 -1
  229. package/dist/store/readiness.js +28 -12
  230. package/dist/store/records.d.ts +21 -5
  231. package/dist/store/records.d.ts.map +1 -1
  232. package/dist/store/records.js +63 -22
  233. package/dist/store/rooms-shown.d.ts +8 -0
  234. package/dist/store/rooms-shown.d.ts.map +1 -0
  235. package/dist/store/rooms-shown.js +13 -0
  236. package/dist/store.d.ts +17 -10
  237. package/dist/store.d.ts.map +1 -1
  238. package/dist/store.js +18 -6
  239. package/dist/stored.d.ts +38 -14
  240. package/dist/stored.d.ts.map +1 -1
  241. package/dist/stored.js +203 -55
  242. package/dist/surface.d.ts +14 -8
  243. package/dist/surface.d.ts.map +1 -1
  244. package/dist/surface.js +59 -27
  245. package/dist/sync.d.ts +4 -2
  246. package/dist/sync.d.ts.map +1 -1
  247. package/dist/sync.js +76 -40
  248. package/dist/tables.d.ts +22 -52
  249. package/dist/tables.d.ts.map +1 -1
  250. package/dist/tables.js +90 -324
  251. package/dist/tallies.d.ts.map +1 -1
  252. package/dist/tallies.js +1 -2
  253. package/dist/validation.d.ts +2 -0
  254. package/dist/validation.d.ts.map +1 -1
  255. package/dist/validation.js +47 -10
  256. package/dist/wire.d.ts +38 -15
  257. package/dist/wire.d.ts.map +1 -1
  258. package/dist/wire.js +20 -13
  259. package/package.json +3 -3
  260. package/dist/attempt.d.ts +0 -16
  261. package/dist/attempt.d.ts.map +0 -1
  262. package/dist/attempt.js +0 -70
  263. package/dist/log.d.ts +0 -6
  264. package/dist/log.d.ts.map +0 -1
  265. package/dist/log.js +0 -14
package/dist/tables.js CHANGED
@@ -1,9 +1,13 @@
1
1
  import { sql } from '@agentshouse/mdmodel';
2
2
  import { answerQuery } from './compile.js';
3
- import { conversationRows, droppedMessages, forgottenMessages, heldConversations, keptMessages, messageCount, messageWindow, MESSAGE_TABLES, turnArrived, } from './messages.js';
3
+ import { amended, authoredLocators, authoredPart, call, callRecords, chatDraft, chatDraftConversations, chatDraftRecord, chatDraftRecords, chatDraftsDropped, claim, fact, fenced, fencedWork, fences, FILE_PART_BYTES, authoredEmptied, heldOrder, kept, moving, pendingBatch, pendingState, queuedLocators, queueOf, queues, remember, roomDraft, roomDraftRecords, spooled, unfenced, unsent, unsentStatus, } from './authored.js';
4
+ import { count, text, texts } from './column.js';
5
+ import { conversationFacts, conversationRows, forgottenConversations, heldConversations, keptFact, keptMessages, messageCount, messageWindow, MESSAGE_TABLES, turnArrived, } from './messages.js';
4
6
  import { keptRead, READ_TABLES, readsOfOtherBuildsForgotten, storedRead, } from './reads.js';
5
7
  import { conversationTallies, roomTallies, } from './tallies.js';
6
- import { abandon, release, commit, covering, demoted, ended, entries, erase, facts, fenceRooms, folders, heldLocators, heldRoom, heldRooms, offlineMode, opened, overlaid, presentation, rederive, referrers, refreshing, REPLICA_TABLES, resume, stage, typed, stagedLocators, typedWithin, unrefresh, } from './stored.js';
8
+ import { abandon, release, commit, covering, demoted, ended, entries, erase, facts, fenceRooms, folders, heldLocators, heldRoom, heldRooms, holders, offlineMode, opened, overlaid, presentation, rederive, referrers, refreshing, REPLICA_TABLES, resume, stage, typed, stagedLocators, tablesOf, typedWithin, unrefresh, } from './stored.js';
9
+ export { kindedRevision } from './reference-forms.js';
10
+ export { authoredEmptied, authoredTable, FILE_PART_BYTES, formatted, heldTables, } from './authored.js';
7
11
  const STATEMENTS_HELD = 256;
8
12
  export function sqliteConnection(engine, database) {
9
13
  const decoder = new TextDecoder();
@@ -71,36 +75,16 @@ export function sqliteConnection(engine, database) {
71
75
  },
72
76
  };
73
77
  }
74
- export const FILE_PART_BYTES = 1_048_576;
75
78
  const PROBE_BYTES = 4 * FILE_PART_BYTES;
76
- const TABLES = [
77
- ['authored_facts', 'name TEXT PRIMARY KEY, value TEXT NOT NULL'],
78
- ['authored_queues', 'locator TEXT PRIMARY KEY, ids TEXT NOT NULL'],
79
- [
80
- 'authored_pending',
81
- 'locator TEXT NOT NULL, id TEXT NOT NULL, batch TEXT NOT NULL, state TEXT NOT NULL, files TEXT NOT NULL, paths TEXT NOT NULL, moving INTEGER NOT NULL, PRIMARY KEY (locator, id)',
82
- ],
83
- [
84
- 'authored_room_drafts',
85
- 'locator TEXT NOT NULL, path TEXT NOT NULL, record TEXT NOT NULL, files TEXT NOT NULL, PRIMARY KEY (locator, path)',
86
- ],
87
- ['authored_chat_drafts', 'conversation TEXT PRIMARY KEY, record TEXT NOT NULL'],
88
- ['authored_calls', 'operation TEXT PRIMARY KEY, record TEXT NOT NULL, files TEXT NOT NULL'],
89
- ['authored_fences', 'locator TEXT PRIMARY KEY'],
90
- ];
91
79
  export const RUNTIME_TABLES = [
92
- ...TABLES.map(([name, columns]) => `CREATE TABLE ${name} (${columns}) WITHOUT ROWID`),
93
- 'CREATE TABLE file_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
94
80
  'CREATE TABLE opened_files (key TEXT PRIMARY KEY, locator TEXT NOT NULL, path TEXT NOT NULL, revision TEXT NOT NULL, media_type TEXT NOT NULL, sha256 TEXT, byte_length INTEGER) WITHOUT ROWID',
95
81
  'CREATE INDEX opened_files_name ON opened_files (locator, path, revision)',
82
+ 'CREATE TABLE opened_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
96
83
  ...REPLICA_TABLES,
97
84
  ...MESSAGE_TABLES,
98
85
  ...READ_TABLES,
99
86
  ];
100
- const OWNERS = ['authored_pending', 'authored_room_drafts', 'authored_calls'];
101
- const AUTHORED_KEYS = OWNERS.map((table) => `SELECT value FROM ${table}, json_each(${table}.files)`).join(' UNION ');
102
- const UNOWNED_PARTS = `DELETE FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS} UNION SELECT key FROM opened_files)`;
103
- const CLEANABLE_BYTES = `SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS})`;
87
+ const UNOPENED_PARTS = 'DELETE FROM opened_parts WHERE key NOT IN (SELECT key FROM opened_files)';
104
88
  const READS = new Set([
105
89
  'authored.status',
106
90
  'authored.moving',
@@ -129,6 +113,7 @@ const READS = new Set([
129
113
  'replica.entries',
130
114
  'replica.typed',
131
115
  'replica.referrers',
116
+ 'replica.holders',
132
117
  'replica.folders',
133
118
  'replica.typedWithin',
134
119
  'opened.find',
@@ -140,6 +125,8 @@ const READS = new Set([
140
125
  'conversation.turn',
141
126
  'conversation.rows',
142
127
  'conversation.tallies',
128
+ 'conversation.facts',
129
+ 'conversation.stored',
143
130
  'read.stored',
144
131
  ]);
145
132
  const KINDS = new Set([
@@ -171,6 +158,7 @@ const KINDS = new Set([
171
158
  'opened.drop',
172
159
  'opened.clean',
173
160
  'conversation.keep',
161
+ 'conversation.fact',
174
162
  'conversation.drop',
175
163
  'space.probe',
176
164
  'read.keep',
@@ -182,290 +170,75 @@ export function isRuntime(request) {
182
170
  export function readsRuntime(request) {
183
171
  return READS.has(request.kind);
184
172
  }
185
- function text(value) {
186
- return typeof value === 'string' ? value : String(value);
187
- }
188
- function texts(rows, column) {
189
- return rows.map((row) => text(row[column]));
190
- }
191
- function owned(files) {
192
- return JSON.stringify([...new Set(files)]);
193
- }
194
- function fact(connection, name) {
195
- const [held] = connection.rows('SELECT value FROM authored_facts WHERE name = ?', [name]);
196
- return held === undefined ? null : text(held.value);
197
- }
198
- function remember(connection, name, value) {
199
- connection.run('INSERT OR REPLACE INTO authored_facts (name, value) VALUES (?, ?)', [
200
- name,
201
- value,
202
- ]);
203
- return null;
204
- }
205
- function fenced(connection, locator) {
206
- return connection.rows('SELECT 1 FROM authored_fences WHERE locator = ?', [locator]).length > 0;
207
- }
208
- function stored(connection, key) {
209
- return connection.rows('SELECT 1 FROM file_parts WHERE key = ? LIMIT 1', [key]).length > 0;
210
- }
211
- function storedPart(connection, key, part, bytes) {
212
- connection.run('INSERT INTO file_parts (key, part, bytes) VALUES (?, ?, ?)', [key, part, bytes]);
213
- }
214
- async function storedFiles(connection, files) {
215
- for (const { key, blob } of files) {
216
- if (stored(connection, key))
217
- continue;
218
- for (let at = 0, part = 0; at < blob.size; at += FILE_PART_BYTES, part += 1) {
219
- const bytes = new Uint8Array(await blob.slice(at, at + FILE_PART_BYTES).arrayBuffer());
220
- storedPart(connection, key, part, bytes);
221
- }
222
- }
223
- }
224
- function filePart(connection, key, part) {
225
- const [held] = connection.rows('SELECT bytes FROM file_parts WHERE key = ? AND part = ?', [
226
- key,
227
- part,
228
- ]);
229
- return held?.bytes instanceof Uint8Array ? held.bytes : null;
230
- }
231
- function* fileParts(connection, key) {
232
- for (let part = 0;; part += 1) {
233
- const bytes = filePart(connection, key, part);
234
- if (bytes === null)
235
- return;
236
- yield bytes;
237
- }
238
- }
239
- async function spooled(connection, spool, { key, type }) {
240
- for (const held of [...spool.held()]) {
241
- if (held !== key && !stored(connection, held))
242
- await spool.drop(held);
243
- }
244
- return spool.spool(key, type, fileParts(connection, key));
245
- }
246
- function unowned(connection) {
247
- connection.run(UNOWNED_PARTS);
248
- }
249
- function queued(connection) {
250
- return connection.rows('SELECT locator, ids FROM authored_queues').map((row) => ({
251
- locator: text(row.locator),
252
- ids: JSON.parse(text(row.ids)),
253
- }));
254
- }
255
173
  function heldWork(connection, locator) {
256
174
  const room = heldRoom(connection, locator);
257
- const pending = new Map(connection
258
- .rows('SELECT id, batch, state FROM authored_pending WHERE locator = ?', [locator])
259
- .map((row) => [
260
- text(row.id),
261
- { id: text(row.id), batch: text(row.batch), state: text(row.state) },
262
- ]));
263
175
  return {
264
176
  room: room === null ? null : { ...room, overlaid: overlaid(connection, room.key) },
265
- queue: heldOrder(connection, locator).map((id) => {
266
- const held = pending.get(id);
267
- if (held === undefined)
268
- throw new Error(`Missing Pending Change ${locator}/${id}`);
269
- return held;
270
- }),
177
+ queue: queueOf(connection, locator),
271
178
  };
272
179
  }
273
180
  function status(connection) {
274
- const [completed] = connection.rows("SELECT value FROM replica_facts WHERE name = 'lastCompleted'");
275
181
  return {
276
- queued: texts(connection.rows('SELECT locator FROM authored_queues'), 'locator'),
277
- lastCompleted: completed === undefined ? null : text(completed.value),
278
- changes: connection
279
- .rows('SELECT p.locator, c.value AS path FROM authored_pending p, json_each(p.paths) c')
280
- .map((row) => ({ locator: text(row.locator), path: text(row.path) })),
281
- resets: connection
282
- .rows(`SELECT locator, json_extract(state, '$.submission.reset') AS reset FROM authored_pending
283
- WHERE json_extract(state, '$.submission.state') = 'reset'`)
284
- .map((row) => ({ locator: text(row.locator), reset: text(row.reset) })),
285
- returned: texts(connection.rows(`SELECT record FROM authored_room_drafts WHERE json_type(record, '$.returned') = 'object'`), 'record'),
182
+ ...unsentStatus(connection),
183
+ lastCompleted: facts(connection, ['lastCompleted']).lastCompleted ?? null,
286
184
  };
287
185
  }
288
186
  function pendingOf(connection, locator, id) {
289
- const [held] = connection.rows('SELECT state FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
290
187
  return {
291
- state: held === undefined ? null : text(held.state),
188
+ state: pendingState(connection, locator, id),
292
189
  room: connection.rows('SELECT 1 FROM replica_rooms WHERE locator = ?', [locator]).length > 0,
293
190
  };
294
191
  }
295
- function roomDraftRecords(connection, locator, paths) {
296
- if (locator === null) {
297
- return texts(connection.rows('SELECT record FROM authored_room_drafts'), 'record');
298
- }
299
- if (paths === null) {
300
- return texts(connection.rows('SELECT record FROM authored_room_drafts WHERE locator = ?', [locator]), 'record');
301
- }
302
- return texts(connection.rows('SELECT record FROM authored_room_drafts WHERE locator = ? AND path IN (SELECT value FROM json_each(?))', [locator, JSON.stringify(paths)]), 'record');
303
- }
304
- function chatDraftRecord(connection, conversation) {
305
- const [held] = connection.rows('SELECT record FROM authored_chat_drafts WHERE conversation = ?', [
306
- conversation,
307
- ]);
308
- return held === undefined ? null : text(held.record);
309
- }
310
- function heldOrder(connection, locator) {
311
- const [held] = connection.rows('SELECT ids FROM authored_queues WHERE locator = ?', [locator]);
312
- return held === undefined ? [] : JSON.parse(text(held.ids));
313
- }
314
- function keptRows(connection, { locator, order, added, founded, roomDrafts, consumedRoomDrafts }) {
315
- for (const path of consumedRoomDrafts ?? []) {
316
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
317
- locator,
318
- path,
319
- ]);
320
- }
321
- for (const { path, record, files } of roomDrafts ?? []) {
322
- connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, record, owned(files)]);
323
- }
324
- if (order === undefined)
325
- return;
326
- const before = new Set(heldOrder(connection, locator));
327
- const after = new Set(order);
328
- if (after.size === 0)
329
- connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
330
- else {
331
- connection.run('INSERT OR REPLACE INTO authored_queues (locator, ids) VALUES (?, ?)', [
332
- locator,
333
- JSON.stringify([...after]),
334
- ]);
335
- }
336
- for (const id of before) {
337
- if (!after.has(id)) {
338
- connection.run('DELETE FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
339
- }
340
- }
341
- for (const { id, batch, state, files, paths, moving } of added ?? []) {
342
- if (before.has(id))
343
- continue;
344
- connection.run('INSERT OR REPLACE INTO authored_pending (locator, id, batch, state, files, paths, moving) VALUES (?, ?, ?, ?, ?, ?, ?)', [locator, id, batch, state, owned(files), JSON.stringify(paths), moving ? 1 : 0]);
345
- }
346
- for (const { id, batch, files, paths, moving } of founded ?? []) {
347
- const [held] = connection.rows('SELECT files FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
348
- if (held === undefined || !before.has(id))
349
- continue;
350
- connection.run('UPDATE authored_pending SET batch = ?, files = ?, paths = ?, moving = ? WHERE locator = ? AND id = ?', [
351
- batch,
352
- owned([...JSON.parse(text(held.files)), ...files]),
353
- JSON.stringify(paths),
354
- moving ? 1 : 0,
355
- locator,
356
- id,
357
- ]);
358
- }
359
- }
360
- async function kept(connection, { writes, files, whole }) {
361
- const refused = writes.find(({ locator }) => fenced(connection, locator));
362
- if (refused !== undefined && whole)
363
- return refused.locator;
364
- await storedFiles(connection, files);
365
- for (const write of writes) {
366
- if (!fenced(connection, write.locator))
367
- keptRows(connection, write);
368
- }
369
- unowned(connection);
370
- return refused?.locator ?? null;
371
- }
372
- function amended(connection, { locator, id, amendment }) {
373
- if (fenced(connection, locator))
374
- return null;
375
- const [held] = connection.rows('SELECT state FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
376
- if (held === undefined)
377
- return null;
378
- connection.run('UPDATE authored_pending SET state = ? WHERE locator = ? AND id = ?', [
379
- JSON.stringify({
380
- ...JSON.parse(text(held.state)),
381
- ...JSON.parse(amendment),
382
- }),
383
- locator,
384
- id,
385
- ]);
386
- return null;
387
- }
388
- async function roomDraft(connection, { locator, path, kept: draft, files }) {
389
- if (fenced(connection, locator))
390
- return locator;
391
- await storedFiles(connection, files);
392
- if (draft === null) {
393
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
394
- locator,
395
- path,
192
+ function storedConversations(connection, conversations) {
193
+ const named = conversations === null ? '' : ' WHERE conversation IN (SELECT value FROM json_each(?))';
194
+ const bound = conversations === null ? [] : [JSON.stringify(conversations)];
195
+ return [
196
+ ...new Set([
197
+ ...tablesOf(MESSAGE_TABLES).flatMap((table) => texts(connection.rows(`SELECT DISTINCT conversation FROM ${table}${named}`, bound), 'conversation')),
198
+ ...chatDraftConversations(connection, conversations),
199
+ ]),
200
+ ];
201
+ }
202
+ function droppedConversations(connection, conversations) {
203
+ const held = storedConversations(connection, conversations);
204
+ for (const table of tablesOf(MESSAGE_TABLES)) {
205
+ connection.run(`DELETE FROM ${table} WHERE conversation IN (SELECT value FROM json_each(?))`, [
206
+ JSON.stringify(conversations),
396
207
  ]);
397
208
  }
398
- else {
399
- connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, draft.record, owned(draft.files)]);
400
- }
401
- unowned(connection);
402
- return null;
403
- }
404
- function chatDraft(connection, { kept: drafts, dropped }) {
405
- for (const conversation of dropped) {
406
- connection.run('DELETE FROM authored_chat_drafts WHERE conversation = ?', [conversation]);
407
- }
408
- for (const { conversation, record } of drafts) {
409
- connection.run('INSERT OR REPLACE INTO authored_chat_drafts (conversation, record) VALUES (?, ?)', [conversation, record]);
410
- }
411
- return null;
209
+ chatDraftsDropped(connection, conversations);
210
+ return held;
412
211
  }
413
- async function call(connection, { operation, kept: held, files }) {
414
- await storedFiles(connection, files);
415
- if (held === null)
416
- connection.run('DELETE FROM authored_calls WHERE operation = ?', [operation]);
417
- else {
418
- connection.run('INSERT OR REPLACE INTO authored_calls (operation, record, files) VALUES (?, ?, ?)', [operation, held.record, owned(held.files)]);
419
- }
420
- unowned(connection);
421
- return null;
422
- }
423
- function roomWork(connection, locator) {
424
- connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
425
- connection.run('DELETE FROM authored_pending WHERE locator = ?', [locator]);
212
+ function unopened(connection) {
213
+ connection.run(UNOPENED_PARTS);
426
214
  }
427
215
  function fence(connection, locators) {
216
+ fencedWork(connection, locators);
428
217
  for (const locator of locators) {
429
- connection.run('INSERT OR REPLACE INTO authored_fences (locator) VALUES (?)', [locator]);
430
- roomWork(connection, locator);
431
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ?', [locator]);
432
218
  connection.run('DELETE FROM opened_files WHERE locator = ?', [locator]);
433
219
  }
434
- unowned(connection);
220
+ unopened(connection);
435
221
  return fenceRooms(connection, locators);
436
222
  }
437
223
  function erased(connection, { locator, limit }) {
438
224
  return erase(connection, locator, limit);
439
225
  }
440
- function unfenced(connection, locators) {
226
+ function unfencedRooms(connection, locators) {
441
227
  const erased = locators.filter((locator) => connection.rows('SELECT 1 FROM replica_erasing WHERE locator = ? LIMIT 1', [locator])
442
228
  .length === 0);
443
- for (const locator of erased) {
444
- connection.run('DELETE FROM authored_fences WHERE locator = ?', [locator]);
445
- }
229
+ unfenced(connection, erased);
446
230
  return erased;
447
231
  }
448
- function claim(connection, holder) {
449
- const held = fact(connection, 'holder');
450
- if (held !== null)
451
- return held === holder;
452
- remember(connection, 'holder', holder);
453
- return true;
454
- }
455
232
  function end(connection, holder) {
456
233
  ended(connection);
457
- forgottenMessages(connection);
234
+ forgottenConversations(connection);
458
235
  if (holder !== null && claim(connection, holder))
459
236
  return true;
460
- for (const [table] of TABLES)
461
- connection.run(`DELETE FROM ${table}`);
237
+ authoredEmptied(connection);
462
238
  connection.run('DELETE FROM opened_files');
463
- connection.run('DELETE FROM file_parts');
239
+ connection.run('DELETE FROM opened_parts');
464
240
  return false;
465
241
  }
466
- function count(value) {
467
- return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
468
- }
469
242
  function openedFile(connection, { locator, path, revision }) {
470
243
  const [held] = connection.rows('SELECT key, media_type, byte_length FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NOT NULL', [locator, path, revision]);
471
244
  return held === undefined
@@ -480,7 +253,7 @@ function opening(connection, { key, locator, path, revision, mediaType }) {
480
253
  if (fenced(connection, locator))
481
254
  return false;
482
255
  connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NULL', [locator, path, revision]);
483
- unowned(connection);
256
+ unopened(connection);
484
257
  connection.run('INSERT INTO opened_files (key, locator, path, revision, media_type) VALUES (?, ?, ?, ?, ?)', [key, locator, path, revision, mediaType]);
485
258
  return true;
486
259
  }
@@ -493,19 +266,23 @@ function fetching(connection, key) {
493
266
  function openedPart(connection, { key, part, bytes }) {
494
267
  if (fetching(connection, key) === null)
495
268
  return false;
496
- storedPart(connection, key, part, bytes);
269
+ connection.run('INSERT INTO opened_parts (key, part, bytes) VALUES (?, ?, ?)', [
270
+ key,
271
+ part,
272
+ bytes,
273
+ ]);
497
274
  return true;
498
275
  }
499
276
  function dropped(connection, key) {
500
277
  connection.run('DELETE FROM opened_files WHERE key = ?', [key]);
501
- connection.run('DELETE FROM file_parts WHERE key = ?', [key]);
278
+ connection.run('DELETE FROM opened_parts WHERE key = ?', [key]);
502
279
  return null;
503
280
  }
504
281
  function keptOpened(connection, { key, sha256, byteLength, parts }) {
505
282
  const fetched = fetching(connection, key);
506
283
  if (fetched === null)
507
284
  return false;
508
- const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM file_parts WHERE key = ?', [key]);
285
+ const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts WHERE key = ?', [key]);
509
286
  const whole = count(held.parts) === parts &&
510
287
  count(held.bytes) === byteLength &&
511
288
  (parts === 0 || (count(held.first) === 0 && count(held.last) === parts - 1));
@@ -519,27 +296,24 @@ function keptOpened(connection, { key, sha256, byteLength, parts }) {
519
296
  key,
520
297
  ]);
521
298
  connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND key <> ?', [fetched.locator, fetched.path, fetched.revision, key]);
522
- unowned(connection);
299
+ unopened(connection);
523
300
  return true;
524
301
  }
525
- const UNSENT = [
526
- ['pending-change', 'authored_pending'],
527
- ['call', 'authored_calls'],
528
- ['room-draft', 'authored_room_drafts'],
529
- ['chat-draft', 'authored_chat_drafts'],
530
- ];
531
- function unsent(connection) {
532
- const [held] = connection.rows(`SELECT ${UNSENT.map(([kind, table]) => `(SELECT count(*) FROM ${table}) AS "${kind}"`).join(', ')}`);
533
- return UNSENT.map(([kind]) => ({ kind, count: count(held[kind]) })).filter((work) => work.count > 0);
302
+ function heldPart(connection, key, part) {
303
+ const [held] = connection.rows('SELECT bytes FROM opened_parts WHERE key = ? AND part = ?', [
304
+ key,
305
+ part,
306
+ ]);
307
+ return held?.bytes instanceof Uint8Array ? held.bytes : authoredPart(connection, key, part);
534
308
  }
535
309
  function cleanable(connection) {
536
- const [held] = connection.rows(CLEANABLE_BYTES);
310
+ const [held] = connection.rows('SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts');
537
311
  return count(held.bytes);
538
312
  }
539
313
  function cleaned(connection) {
540
314
  connection.run('DELETE FROM opened_files');
541
315
  const freed = cleanable(connection);
542
- unowned(connection);
316
+ unopened(connection);
543
317
  return freed;
544
318
  }
545
319
  function openedHeld(connection) {
@@ -565,51 +339,39 @@ export function answerRuntime(connection, request, spool) {
565
339
  case 'authored.status':
566
340
  return status(connection);
567
341
  case 'authored.moving':
568
- return {
569
- queues: queued(connection),
570
- pending: connection
571
- .rows('SELECT locator, id, batch, state FROM authored_pending WHERE moving = 1 ORDER BY locator')
572
- .map((row) => ({
573
- locator: text(row.locator),
574
- id: text(row.id),
575
- batch: text(row.batch),
576
- state: text(row.state),
577
- })),
578
- };
342
+ return moving(connection);
579
343
  case 'authored.pending':
580
344
  return pendingOf(connection, request.locator, request.id);
581
- case 'authored.batch': {
582
- const [held] = connection.rows('SELECT batch FROM authored_pending WHERE locator = ? AND id = ?', [request.locator, request.id]);
583
- return held === undefined ? null : text(held.batch);
584
- }
345
+ case 'authored.batch':
346
+ return pendingBatch(connection, request.locator, request.id);
585
347
  case 'authored.order':
586
348
  return heldOrder(connection, request.locator);
587
349
  case 'authored.queued':
588
- return texts(connection.rows('SELECT locator FROM authored_queues'), 'locator');
350
+ return queuedLocators(connection);
589
351
  case 'authored.roomDrafts':
590
352
  return roomDraftRecords(connection, request.locator, request.paths);
591
353
  case 'authored.chatDraft.read':
592
354
  return chatDraftRecord(connection, request.conversation);
593
355
  case 'authored.chatDrafts':
594
- return texts(connection.rows('SELECT record FROM authored_chat_drafts'), 'record');
356
+ return chatDraftRecords(connection);
595
357
  case 'authored.calls':
596
- return texts(connection.rows('SELECT record FROM authored_calls'), 'record');
358
+ return callRecords(connection);
597
359
  case 'authored.fences':
598
- return texts(connection.rows('SELECT locator FROM authored_fences'), 'locator');
360
+ return fences(connection);
599
361
  case 'authored.unsent':
600
362
  return unsent(connection);
601
363
  case 'authored.fact':
602
364
  return fact(connection, request.name);
603
365
  case 'authored.file':
604
- return spooled(connection, spool, request);
366
+ return spooled(connection, spool, request.key, request.type);
605
367
  case 'authored.amend':
606
- return amended(connection, request);
368
+ return amended(connection, request.locator, request.id, request.amendment);
607
369
  case 'authored.roomDraft':
608
- return roomDraft(connection, request);
370
+ return roomDraft(connection, request.locator, request.path, request.kept, request.files);
609
371
  case 'authored.chatDraft':
610
- return chatDraft(connection, request);
372
+ return chatDraft(connection, request.kept, request.dropped);
611
373
  case 'authored.call':
612
- return call(connection, request);
374
+ return call(connection, request.operation, request.kept, request.files);
613
375
  case 'authored.remember':
614
376
  return remember(connection, request.name, request.value);
615
377
  case 'authored.claim':
@@ -623,18 +385,18 @@ export function answerRuntime(connection, request, spool) {
623
385
  case 'replica.room':
624
386
  return heldWork(connection, request.locator);
625
387
  case 'replica.covering':
626
- return {
627
- rooms: covering(connection),
628
- queues: queued(connection),
629
- };
388
+ return { ...covering(connection, request.since), queues: queues(connection) };
630
389
  case 'replica.offline':
631
390
  return offlineMode(connection, request.locator);
632
391
  case 'replica.held':
633
- return { held: heldLocators(connection), staged: stagedLocators(connection) };
392
+ return {
393
+ held: [...new Set([...heldLocators(connection), ...authoredLocators(connection)])],
394
+ staged: stagedLocators(connection),
395
+ };
634
396
  case 'replica.demote':
635
397
  return demoted(connection);
636
398
  case 'replica.facts':
637
- return facts(connection);
399
+ return facts(connection, request.names);
638
400
  case 'replica.presentation':
639
401
  return presentation(connection, request.app);
640
402
  case 'replica.query':
@@ -647,6 +409,8 @@ export function answerRuntime(connection, request, spool) {
647
409
  return typed(connection, request.key, request.view, request.paths);
648
410
  case 'replica.referrers':
649
411
  return referrers(connection, request.key, request.view, request.targets);
412
+ case 'replica.holders':
413
+ return holders(connection, request.key, request.view, request.sought);
650
414
  case 'replica.folders':
651
415
  return folders(connection, request.key, request.paths);
652
416
  case 'replica.typedWithin':
@@ -668,7 +432,7 @@ export function answerRuntime(connection, request, spool) {
668
432
  case 'replica.abandon':
669
433
  return abandon(connection, request.locator);
670
434
  case 'replica.unfence':
671
- return unfenced(connection, request.locators);
435
+ return unfencedRooms(connection, request.locators);
672
436
  case 'replica.release':
673
437
  return release(connection, request.key);
674
438
  case 'replica.rederive':
@@ -700,7 +464,7 @@ export function answerRuntime(connection, request, spool) {
700
464
  case 'opened.held':
701
465
  return openedHeld(connection);
702
466
  case 'file.part':
703
- return filePart(connection, request.key, request.part);
467
+ return heldPart(connection, request.key, request.part);
704
468
  case 'conversation.held':
705
469
  return heldConversations(connection, request.conversations);
706
470
  case 'conversation.keep': {
@@ -717,14 +481,16 @@ export function answerRuntime(connection, request, spool) {
717
481
  return conversationRows(connection, request.conversations);
718
482
  case 'conversation.tallies':
719
483
  return conversationTallies(connection, request.conversations, request.since);
484
+ case 'conversation.facts':
485
+ return conversationFacts(connection);
486
+ case 'conversation.fact': {
487
+ const { kind: _kind, ...fact } = request;
488
+ return keptFact(connection, fact);
489
+ }
490
+ case 'conversation.stored':
491
+ return storedConversations(connection, null);
720
492
  case 'conversation.drop':
721
- chatDraft(connection, {
722
- kind: 'authored.chatDraft',
723
- kept: [],
724
- dropped: request.conversations,
725
- });
726
- droppedMessages(connection, request.conversations);
727
- return null;
493
+ return droppedConversations(connection, request.conversations);
728
494
  case 'space.probe':
729
495
  return spool.probe(PROBE_BYTES).then(() => null);
730
496
  case 'read.stored':
@@ -1 +1 @@
1
- {"version":3,"file":"tallies.d.ts","sourceRoot":"","sources":["../src/tallies.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAE5E,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAI1D,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC;IAC7E,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC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KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,KAAK,EAAE,MAAM,GACZ,SAAS,EAAE,CAwBb;AA0BD,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,EACvC,KAAK,EAAE,MAAM,GACZ,iBAAiB,EAAE,CAerB"}
package/dist/tallies.js CHANGED
@@ -1,5 +1,4 @@
1
- import { instantKey, sql } from '@agentshouse/mdmodel';
2
- import { CHAT_MESSAGE_TYPE, CHAT_TYPE } from './chat-types.js';
1
+ import { CHAT_MESSAGE_TYPE, CHAT_TYPE, instantKey, sql } from '@agentshouse/mdmodel';
3
2
  import { answerQuery, VISIBLE, within } from './compile.js';
4
3
  import { HOUSE_DIRECTORY } from './figures.js';
5
4
  const NONE = { count: 0, size: 0 };
@@ -1,5 +1,6 @@
1
1
  import { type Validation } from '@agentshouse/mdmodel';
2
2
  import { type Composition } from './collection.js';
3
+ import type { Holder, Sought } from './stored.js';
3
4
  type Examined = {
4
5
  readonly path: string;
5
6
  readonly content: string | null;
@@ -23,6 +24,7 @@ type Neighbourhood = {
23
24
  readonly lookup: Lookup;
24
25
  readonly texts: (paths: readonly string[]) => Promise<ReadonlyMap<string, string | null>>;
25
26
  readonly referrers: (targets: readonly string[]) => Promise<readonly string[]>;
27
+ readonly holders: (sought: readonly Sought[]) => Promise<readonly Holder[]>;
26
28
  };
27
29
  export declare function validatedNeighbourhood(changes: readonly Changed[], composition: Composition, source: Neighbourhood): Promise<Validation>;
28
30
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,UAAU,EAGhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAM5E,KAAK,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IA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