@agentshouse/mdruntime 0.1.0-cd26b960b7262 → 0.1.0-cd30853a1b15e

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