@agentshouse/mdruntime 0.1.0-c454894e67f74 → 0.1.0-c49444f2a8fc6

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 (243) hide show
  1. package/README.md +19 -16
  2. package/dist/adapter.d.ts +148 -79
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/attached-model.d.ts +7 -10
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +40 -41
  7. package/dist/binary.d.ts +0 -5
  8. package/dist/binary.d.ts.map +1 -1
  9. package/dist/binary.js +1 -1
  10. package/dist/bootstrap.d.ts +31 -11
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +319 -107
  13. package/dist/chain.d.ts +12 -0
  14. package/dist/chain.d.ts.map +1 -0
  15. package/dist/chain.js +64 -0
  16. package/dist/change-set.d.ts +9 -16
  17. package/dist/change-set.d.ts.map +1 -1
  18. package/dist/change-set.js +11 -88
  19. package/dist/change.d.ts +32 -1
  20. package/dist/change.d.ts.map +1 -1
  21. package/dist/change.js +10 -1
  22. package/dist/client.d.ts +22 -10
  23. package/dist/client.d.ts.map +1 -1
  24. package/dist/client.js +97 -11
  25. package/dist/collection.d.ts +11 -21
  26. package/dist/collection.d.ts.map +1 -1
  27. package/dist/collection.js +39 -291
  28. package/dist/compile.d.ts +11 -0
  29. package/dist/compile.d.ts.map +1 -0
  30. package/dist/compile.js +586 -0
  31. package/dist/connection.d.ts +34 -18
  32. package/dist/connection.d.ts.map +1 -1
  33. package/dist/connection.js +3742 -1778
  34. package/dist/context.d.ts +2 -0
  35. package/dist/context.d.ts.map +1 -0
  36. package/dist/{chat/context.js → context.js} +1 -4
  37. package/dist/conversation-row.d.ts +33 -0
  38. package/dist/conversation-row.d.ts.map +1 -0
  39. package/dist/conversation-row.js +47 -0
  40. package/dist/conversation.d.ts +41 -18
  41. package/dist/conversation.d.ts.map +1 -1
  42. package/dist/conversation.js +715 -312
  43. package/dist/digest.d.ts +7 -0
  44. package/dist/digest.d.ts.map +1 -0
  45. package/dist/digest.js +113 -0
  46. package/dist/durability.d.ts +7 -4
  47. package/dist/durability.d.ts.map +1 -1
  48. package/dist/durability.js +5 -0
  49. package/dist/entry.d.ts +5 -2
  50. package/dist/entry.d.ts.map +1 -1
  51. package/dist/entry.js +33 -28
  52. package/dist/file.d.ts +2 -19
  53. package/dist/file.d.ts.map +1 -1
  54. package/dist/file.js +7 -122
  55. package/dist/host.d.ts +6 -8
  56. package/dist/host.d.ts.map +1 -1
  57. package/dist/host.js +97 -23
  58. package/dist/identity.d.ts +0 -2
  59. package/dist/identity.d.ts.map +1 -1
  60. package/dist/identity.js +0 -6
  61. package/dist/index.d.ts +22 -13
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +9 -1
  64. package/dist/job.d.ts +33 -0
  65. package/dist/job.d.ts.map +1 -0
  66. package/dist/job.js +54 -0
  67. package/dist/live.d.ts +23 -0
  68. package/dist/live.d.ts.map +1 -0
  69. package/dist/live.js +165 -0
  70. package/dist/media.d.ts +8 -0
  71. package/dist/media.d.ts.map +1 -0
  72. package/dist/media.js +218 -0
  73. package/dist/memory.d.ts +19 -7
  74. package/dist/memory.d.ts.map +1 -1
  75. package/dist/memory.js +248 -103
  76. package/dist/messages.d.ts +52 -0
  77. package/dist/messages.d.ts.map +1 -0
  78. package/dist/messages.js +168 -0
  79. package/dist/model.d.ts +8 -10
  80. package/dist/model.d.ts.map +1 -1
  81. package/dist/model.js +6 -18
  82. package/dist/name.d.ts +4 -0
  83. package/dist/name.d.ts.map +1 -0
  84. package/dist/name.js +122 -0
  85. package/dist/observation.d.ts +17 -2
  86. package/dist/observation.d.ts.map +1 -1
  87. package/dist/observation.js +100 -5
  88. package/dist/opened.d.ts +22 -0
  89. package/dist/opened.d.ts.map +1 -0
  90. package/dist/opened.js +107 -0
  91. package/dist/outcome.d.ts +45 -7
  92. package/dist/outcome.d.ts.map +1 -1
  93. package/dist/outcome.js +39 -0
  94. package/dist/overlay.d.ts +4 -5
  95. package/dist/overlay.d.ts.map +1 -1
  96. package/dist/overlay.js +106 -156
  97. package/dist/{chat/parts.d.ts → parts.d.ts} +11 -9
  98. package/dist/parts.d.ts.map +1 -0
  99. package/dist/{chat/parts.js → parts.js} +45 -46
  100. package/dist/paths.d.ts +1 -0
  101. package/dist/paths.d.ts.map +1 -1
  102. package/dist/paths.js +4 -0
  103. package/dist/query.d.ts +16 -185
  104. package/dist/query.d.ts.map +1 -1
  105. package/dist/query.js +3 -464
  106. package/dist/{chat/questions.d.ts → questions.d.ts} +3 -2
  107. package/dist/questions.d.ts.map +1 -0
  108. package/dist/{chat/questions.js → questions.js} +8 -1
  109. package/dist/reach.d.ts +17 -9
  110. package/dist/reach.d.ts.map +1 -1
  111. package/dist/reach.js +276 -99
  112. package/dist/react.d.ts +6 -4
  113. package/dist/react.d.ts.map +1 -1
  114. package/dist/react.js +7 -17
  115. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  116. package/dist/read.d.ts.map +1 -0
  117. package/dist/{chat/read.js → read.js} +4 -0
  118. package/dist/readiness.d.ts +14 -17
  119. package/dist/readiness.d.ts.map +1 -1
  120. package/dist/readiness.js +2 -8
  121. package/dist/recovery.d.ts +3 -2
  122. package/dist/recovery.d.ts.map +1 -1
  123. package/dist/recovery.js +43 -8
  124. package/dist/refresh.d.ts +17 -14
  125. package/dist/refresh.d.ts.map +1 -1
  126. package/dist/refresh.js +143 -52
  127. package/dist/replica.d.ts +58 -33
  128. package/dist/replica.d.ts.map +1 -1
  129. package/dist/replica.js +331 -181
  130. package/dist/room-draft.d.ts +37 -6
  131. package/dist/room-draft.d.ts.map +1 -1
  132. package/dist/room-draft.js +161 -74
  133. package/dist/rows.d.ts +31 -29
  134. package/dist/rows.d.ts.map +1 -1
  135. package/dist/rows.js +59 -116
  136. package/dist/save.d.ts +53 -14
  137. package/dist/save.d.ts.map +1 -1
  138. package/dist/save.js +534 -187
  139. package/dist/search.d.ts +15 -77
  140. package/dist/search.d.ts.map +1 -1
  141. package/dist/search.js +10 -184
  142. package/dist/seed.d.ts +16 -0
  143. package/dist/seed.d.ts.map +1 -0
  144. package/dist/seed.js +75 -0
  145. package/dist/shared.d.ts +7 -3
  146. package/dist/shared.d.ts.map +1 -1
  147. package/dist/shared.js +119 -66
  148. package/dist/source.d.ts +61 -0
  149. package/dist/source.d.ts.map +1 -0
  150. package/dist/source.js +81 -0
  151. package/dist/status.d.ts +4 -5
  152. package/dist/status.d.ts.map +1 -1
  153. package/dist/status.js +3 -7
  154. package/dist/store.d.ts +159 -108
  155. package/dist/store.d.ts.map +1 -1
  156. package/dist/store.js +365 -686
  157. package/dist/stored.d.ts +156 -0
  158. package/dist/stored.d.ts.map +1 -0
  159. package/dist/stored.js +635 -0
  160. package/dist/tables.d.ts +388 -0
  161. package/dist/tables.d.ts.map +1 -0
  162. package/dist/tables.js +706 -0
  163. package/dist/transfer.d.ts +0 -5
  164. package/dist/transfer.d.ts.map +1 -1
  165. package/dist/turn.d.ts +5 -3
  166. package/dist/turn.d.ts.map +1 -1
  167. package/dist/turn.js +51 -21
  168. package/dist/validation.d.ts +29 -0
  169. package/dist/validation.d.ts.map +1 -0
  170. package/dist/validation.js +104 -0
  171. package/dist/windows.d.ts +11 -0
  172. package/dist/windows.d.ts.map +1 -0
  173. package/dist/windows.js +16 -0
  174. package/dist/wire.d.ts +42 -5
  175. package/dist/wire.d.ts.map +1 -1
  176. package/dist/wire.js +12 -2
  177. package/package.json +18 -19
  178. package/AGENTS.md +0 -302
  179. package/dist/acquisition.d.ts +0 -14
  180. package/dist/acquisition.d.ts.map +0 -1
  181. package/dist/acquisition.js +0 -24
  182. package/dist/chat/acts.d.ts +0 -33
  183. package/dist/chat/acts.d.ts.map +0 -1
  184. package/dist/chat/acts.js +0 -36
  185. package/dist/chat/context.d.ts +0 -3
  186. package/dist/chat/context.d.ts.map +0 -1
  187. package/dist/chat/input.d.ts +0 -9
  188. package/dist/chat/input.d.ts.map +0 -1
  189. package/dist/chat/input.js +0 -99
  190. package/dist/chat/kit.d.ts +0 -61
  191. package/dist/chat/kit.d.ts.map +0 -1
  192. package/dist/chat/kit.js +0 -123
  193. package/dist/chat/lasting.d.ts +0 -6
  194. package/dist/chat/lasting.d.ts.map +0 -1
  195. package/dist/chat/lasting.js +0 -19
  196. package/dist/chat/list.d.ts +0 -27
  197. package/dist/chat/list.d.ts.map +0 -1
  198. package/dist/chat/list.js +0 -63
  199. package/dist/chat/markdown.d.ts +0 -20
  200. package/dist/chat/markdown.d.ts.map +0 -1
  201. package/dist/chat/markdown.js +0 -188
  202. package/dist/chat/message.d.ts +0 -6
  203. package/dist/chat/message.d.ts.map +0 -1
  204. package/dist/chat/message.js +0 -192
  205. package/dist/chat/messages.d.ts +0 -22
  206. package/dist/chat/messages.d.ts.map +0 -1
  207. package/dist/chat/messages.js +0 -155
  208. package/dist/chat/name.d.ts +0 -6
  209. package/dist/chat/name.d.ts.map +0 -1
  210. package/dist/chat/name.js +0 -37
  211. package/dist/chat/opened.d.ts +0 -11
  212. package/dist/chat/opened.d.ts.map +0 -1
  213. package/dist/chat/opened.js +0 -17
  214. package/dist/chat/overlay.d.ts +0 -31
  215. package/dist/chat/overlay.d.ts.map +0 -1
  216. package/dist/chat/overlay.js +0 -97
  217. package/dist/chat/parts.d.ts.map +0 -1
  218. package/dist/chat/process.d.ts +0 -20
  219. package/dist/chat/process.d.ts.map +0 -1
  220. package/dist/chat/process.js +0 -32
  221. package/dist/chat/provider.d.ts +0 -63
  222. package/dist/chat/provider.d.ts.map +0 -1
  223. package/dist/chat/provider.js +0 -629
  224. package/dist/chat/question.d.ts +0 -9
  225. package/dist/chat/question.d.ts.map +0 -1
  226. package/dist/chat/question.js +0 -80
  227. package/dist/chat/questions.d.ts.map +0 -1
  228. package/dist/chat/read.d.ts.map +0 -1
  229. package/dist/chat/ready.d.ts +0 -34
  230. package/dist/chat/ready.d.ts.map +0 -1
  231. package/dist/chat/ready.js +0 -91
  232. package/dist/chat/style.d.ts +0 -4
  233. package/dist/chat/style.d.ts.map +0 -1
  234. package/dist/chat/style.js +0 -302
  235. package/dist/chat.d.ts +0 -14
  236. package/dist/chat.d.ts.map +0 -1
  237. package/dist/chat.js +0 -8
  238. package/dist/fence.d.ts +0 -6
  239. package/dist/fence.d.ts.map +0 -1
  240. package/dist/fence.js +0 -10
  241. package/dist/read-side.d.ts +0 -25
  242. package/dist/read-side.d.ts.map +0 -1
  243. package/dist/read-side.js +0 -639
package/dist/client.js CHANGED
@@ -1,6 +1,25 @@
1
+ import { shownBy } from './media.js';
1
2
  import { observed } from './observation.js';
2
3
  import { runtimeError } from './failure.js';
3
4
  import { answer, AUTHORIZATION_ENDED, PORT_CLOSED, } from './wire.js';
5
+ // React renders an arrived value in a later task and opens what that render observes as it commits, so this many frames opening nothing mean the page drew what it observes.
6
+ const SETTLED_FRAMES = 2;
7
+ // A browser reads a download's address only after the click that hands it returns, so a copy's address is released a minute later.
8
+ const HANDED_COPY_MS = 60_000;
9
+ const PAGE = /\.html?$/iu;
10
+ const STARTED = { kind: 'started' };
11
+ const BLOCKED = {
12
+ kind: 'blocked',
13
+ code: 'popup-blocked',
14
+ fields: {},
15
+ retryable: true,
16
+ };
17
+ function handed(url, name) {
18
+ const anchor = document.createElement('a');
19
+ anchor.href = url;
20
+ anchor.download = name;
21
+ anchor.click();
22
+ }
4
23
  function refused(refusal) {
5
24
  return runtimeError(refusal.code, refusal.code, refusal.retryable);
6
25
  }
@@ -131,6 +150,57 @@ export function connectMdRuntime(port) {
131
150
  drawing?.();
132
151
  });
133
152
  }
153
+ function streamed(answer) {
154
+ if (answer.kind !== 'binary')
155
+ return answer;
156
+ const { file, byteLength, mediaType } = answer;
157
+ let part = 0;
158
+ let received = 0;
159
+ const stream = new ReadableStream({
160
+ async pull(controller) {
161
+ const bytes = await ask('binaryFile.part', [file, part]);
162
+ if (bytes === null) {
163
+ if (received === byteLength)
164
+ controller.close();
165
+ else
166
+ controller.error(runtimeError('binary-file-absent', 'The file ended early'));
167
+ return;
168
+ }
169
+ part += 1;
170
+ received += bytes.byteLength;
171
+ controller.enqueue(bytes);
172
+ },
173
+ }, { highWaterMark: 0 });
174
+ return { kind: 'binary', stream, byteLength, mediaType };
175
+ }
176
+ async function download(room, path, revision) {
177
+ const tab = PAGE.test(path) ? globalThis.open('', '_blank') : null;
178
+ const linked = await ask('binaryFile.link', [room, path, revision]);
179
+ if (linked.kind === 'link' && PAGE.test(linked.name)) {
180
+ const away = tab ?? globalThis.open('', '_blank');
181
+ if (away === null)
182
+ return BLOCKED;
183
+ away.location.replace(linked.url);
184
+ return STARTED;
185
+ }
186
+ tab?.close();
187
+ if (linked.kind === 'link') {
188
+ handed(linked.url, linked.name);
189
+ return STARTED;
190
+ }
191
+ if (linked.kind !== 'absent')
192
+ return linked;
193
+ const read = streamed(await ask('binaryFile.read', [room, path, revision]));
194
+ if (read.kind !== 'binary')
195
+ return read;
196
+ const copy = await new Response(read.stream, {
197
+ headers: { 'content-type': read.mediaType },
198
+ }).blob();
199
+ const url = URL.createObjectURL(copy);
200
+ handed(url, path.slice(path.lastIndexOf('/') + 1));
201
+ setTimeout(() => URL.revokeObjectURL(url), HANDED_COPY_MS);
202
+ return STARTED;
203
+ }
134
204
  function settled() {
135
205
  if (settling !== null)
136
206
  return settling;
@@ -141,21 +211,27 @@ export function connectMdRuntime(port) {
141
211
  if (opening.size > 0)
142
212
  return;
143
213
  const at = moved;
144
- requestAnimationFrame(() => {
214
+ const waited = (frames) => {
145
215
  requestAnimationFrame(() => {
216
+ if (frames < SETTLED_FRAMES) {
217
+ waited(frames + 1);
218
+ return;
219
+ }
146
220
  if (moved !== at || opening.size > 0)
147
221
  return;
148
222
  drawing = null;
149
223
  resolve();
150
224
  });
151
- });
225
+ };
226
+ waited(1);
152
227
  };
153
228
  drawing = check;
154
229
  check();
155
230
  });
156
231
  return settling;
157
232
  }
158
- return {
233
+ const show = (room, path, revision) => ask('binaryFile.show', [room, path, revision]).then((shown) => streamed(shown));
234
+ return shownBy(show, {
159
235
  rooms: () => ask('rooms', []),
160
236
  query: ((query) => ask('query', [query])),
161
237
  search: (request) => ask('search', [request]),
@@ -163,13 +239,15 @@ export function connectMdRuntime(port) {
163
239
  roomDraft: {
164
240
  list: () => ask('roomDraft.list', []),
165
241
  read: (room, path) => ask('roomDraft.read', [room, path]),
166
- write: (room, path, revision, parts) => ask('roomDraft.write', [room, path, revision, parts]),
242
+ write: (room, path, revision, parts, next) => ask('roomDraft.write', next === undefined ? [room, path, revision, parts] : [room, path, revision, parts, next]),
167
243
  discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
168
244
  },
169
245
  save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
246
+ saveParts: (room, parts) => ask('saveParts', [room, parts]),
170
247
  presentation: {
171
248
  read: () => ask('presentation.read', []),
172
249
  write: (value) => ask('presentation.write', [value]),
250
+ edit: (members) => ask('presentation.edit', [members]),
173
251
  },
174
252
  conversation: {
175
253
  list: () => ask('conversation.list', []),
@@ -179,32 +257,40 @@ export function connectMdRuntime(port) {
179
257
  answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
180
258
  interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
181
259
  kill: (conversation) => ask('conversation.kill', [conversation]),
182
- cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
183
260
  delete: (conversation) => ask('conversation.delete', [conversation]),
184
261
  },
185
262
  chatDraft: {
186
263
  write: (conversation, draft, revision) => ask('chatDraft.write', [conversation, draft, revision]),
264
+ prepend: (conversation, draft) => ask('chatDraft.prepend', [conversation, draft]),
187
265
  discard: (conversation) => ask('chatDraft.discard', [conversation]),
188
266
  },
189
267
  history: (locator, path, query) => ask('history', [locator, path, query]),
268
+ resolve: (room, path, destination) => ask('resolve', [room, path, destination]),
190
269
  binaryFile: {
191
- read: (room, path, revision) => ask('binaryFile.read', [room, path, revision]),
192
- readReference: (reference) => ask('binaryFile.readReference', [reference]),
270
+ read: (room, path, revision) => ask('binaryFile.read', [room, path, revision]).then((read) => streamed(read)),
271
+ attach: (room, file) => ask('binaryFile.attach', [room, file]),
272
+ download,
193
273
  },
194
274
  call: (name, input) => ask('call', [name, input]),
195
275
  reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
196
276
  log: () => ask('log', []),
197
277
  persistence: () => ask('persistence', []),
198
278
  retry: () => ask('retry', []),
279
+ cleanUp: () => ask('cleanUp', []),
280
+ unsent: () => ask('unsent', []),
281
+ reset: () => ask('reset', []),
199
282
  observe: ((topic, ...input) => watch(topic, input)),
200
283
  reauthorize: () => ask('reauthorize', []),
201
284
  settled,
202
- };
285
+ });
203
286
  }
204
287
  const turns = new WeakMap();
205
288
  export function inTurn(client, work) {
206
- const next = (turns.get(client) ?? Promise.resolve()).then(work).catch(() => undefined);
207
- turns.set(client, next);
208
- return next;
289
+ const turn = (turns.get(client) ?? Promise.resolve()).then(work);
290
+ turns.set(client, turn.then(() => undefined, () => undefined));
291
+ return turn;
209
292
  }
293
+ export { chainedWindows } from './chain.js';
294
+ export { roomDraftRevision } from './identity.js';
295
+ export { defineRoomMedia, ROOM_MEDIA } from './media.js';
210
296
  export { unanswered } from './wire.js';
@@ -1,9 +1,6 @@
1
- import { type Document, type Frontmatter, type Validation } from '@agentshouse/mdmodel';
2
- import { type ModelState } from './model.js';
1
+ import { type Document, type TypedPath } from '@agentshouse/mdmodel';
2
+ import type { ModelState } from './model.js';
3
3
  import type { MdModelIdentity } from './adapter.js';
4
- import { type Paths } from './shared.js';
5
- import type { Refused } from './transfer.js';
6
- import { type Later } from './turn.js';
7
4
  export declare const MD_MODEL: MdModelIdentity;
8
5
  export type Collection = {
9
6
  text: Readonly<Record<string, string>>;
@@ -16,24 +13,17 @@ export type Composition = {
16
13
  roots: readonly string[];
17
14
  model: ModelState;
18
15
  } | null;
16
+ typedPaths: readonly TypedPath[];
19
17
  };
18
+ export type Composed = {
19
+ readonly composition: Composition;
20
+ readonly fingerprint: string;
21
+ };
22
+ export declare function composedOf(composition: Composition): Composed;
23
+ export declare function selected(composition: Composition, path: string): boolean;
20
24
  export declare function governing(composition: Composition, path: string): ModelState;
21
- export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition, previous?: Collection): Collection;
22
- export declare function passingFrontmatter(collection: Collection, path: string): Frontmatter | undefined;
23
- export declare function documentsOf(collection: Collection): Generator<readonly [string, Document]>;
24
- export declare function unreadable(text: Readonly<Record<string, string>>, previous?: Readonly<Record<string, string>>): Refused | null;
25
+ export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition): Collection;
26
+ export declare function documentsOf(collection: Collection): Generator<number, Iterable<readonly [string, Document]>, void>;
25
27
  export declare function validRoot(root: unknown): root is string;
26
- export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition): Validation;
27
- type Held = {
28
- text: Paths<string>;
29
- binaries: Paths<unknown>;
30
- };
31
- export declare function indexReferrers(held: Held, composition: Composition): Later<void>;
32
- export declare function referencesIndexed(held: Held, composition: Composition): boolean;
33
- export declare function referring(held: Held, composition: Composition, targets: Iterable<string>): ReadonlySet<string> | null;
34
28
  export declare function available(composition: Composition): boolean;
35
- export declare function changedCleanly(next: Held, previous: Held & {
36
- composition: Composition;
37
- }, composition: Composition): boolean;
38
- export {};
39
29
  //# sourceMappingURL=collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,QAAQ,EAEb,KAAK,WAAW,EAChB,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAA8B,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;A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3D"}
@@ -1,11 +1,30 @@
1
- import { checkDocument, parseFrontmatter, references, sectionReferences, target, parse, resolves, validate, VERSION, } from '@agentshouse/mdmodel';
1
+ import { parse, VERSION } from '@agentshouse/mdmodel';
2
2
  import { beneath, normalize } from './paths.js';
3
- import { sameTyping } from './model.js';
4
- import { differing, patched, shared } from './shared.js';
5
- import { inUnits, ROW_WEIGHT } from './turn.js';
3
+ import { hashed } from './observation.js';
4
+ import { sortedKeys } from './shared.js';
6
5
  export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
7
- const NO_TYPES = { types: {} };
8
- function selected(composition, path) {
6
+ const typesPrinted = new WeakMap();
7
+ function typesPrint(model) {
8
+ if (model.status === 'unavailable')
9
+ return '';
10
+ let print = typesPrinted.get(model.types);
11
+ if (print === undefined) {
12
+ print = hashed(JSON.stringify(model.types)).toString(36);
13
+ typesPrinted.set(model.types, print);
14
+ }
15
+ return print;
16
+ }
17
+ export function composedOf(composition) {
18
+ const { model, selection } = composition;
19
+ return {
20
+ composition,
21
+ fingerprint: JSON.stringify([
22
+ typesPrint(model),
23
+ selection === null ? null : [selection.roots, typesPrint(selection.model)],
24
+ ]),
25
+ };
26
+ }
27
+ export function selected(composition, path) {
9
28
  return (composition.selection !== null &&
10
29
  composition.selection.roots.some((root) => beneath(root, path)));
11
30
  }
@@ -14,307 +33,36 @@ export function governing(composition, path) {
14
33
  ? composition.selection.model
15
34
  : composition.model;
16
35
  }
17
- const parsedIn = new WeakMap();
18
- function carried(previous, text) {
19
- const held = parsedIn.get(previous);
20
- if (held === undefined)
21
- return shared({});
22
- const kept = patched(held.base, held.added);
23
- held.base = kept;
24
- held.added = new Map();
25
- return patched(kept, [], differing(previous.text, text));
26
- }
27
- function cachedIn(collection, path) {
28
- const held = parsedIn.get(collection);
29
- if (held === undefined)
30
- return undefined;
31
- if (held.added.has(path))
32
- return held.added.get(path);
33
- return Object.hasOwn(held.base, path) ? held.base[path] : undefined;
34
- }
35
- export function collectionOf(text, composition, previous) {
36
- const parsed = {
37
- base: previous === undefined ? shared({}) : carried(previous, text),
38
- added: new Map(),
39
- };
40
- const collection = {
36
+ export function collectionOf(text, composition) {
37
+ const parsed = new Map();
38
+ return {
41
39
  text,
42
40
  composition,
43
41
  document(path) {
44
- const held = cachedIn(collection, path);
45
- if (held !== undefined)
46
- return held ?? undefined;
42
+ if (parsed.has(path))
43
+ return parsed.get(path) ?? undefined;
47
44
  const content = text[path];
48
45
  if (content === undefined)
49
46
  return undefined;
50
47
  const read = parse(content, path);
51
- parsed.added.set(path, read.ok ? read.document : null);
48
+ parsed.set(path, read.ok ? read.document : null);
52
49
  return read.ok ? read.document : undefined;
53
50
  },
54
51
  };
55
- parsedIn.set(collection, parsed);
56
- return collection;
57
- }
58
- export function passingFrontmatter(collection, path) {
59
- const held = cachedIn(collection, path);
60
- if (held !== undefined)
61
- return held ?? undefined;
62
- const content = collection.text[path];
63
- if (content === undefined)
64
- return undefined;
65
- const read = parseFrontmatter(content, path);
66
- return read.ok ? read.frontmatter : undefined;
67
52
  }
68
53
  export function* documentsOf(collection) {
69
- for (const path of Object.keys(collection.text).sort()) {
70
- const held = cachedIn(collection, path);
71
- if (held === null)
72
- continue;
73
- if (held !== undefined) {
74
- yield [path, held];
75
- continue;
54
+ const paths = yield* sortedKeys(collection.text);
55
+ return (function* () {
56
+ for (const path of paths) {
57
+ const document = collection.document(path);
58
+ if (document !== undefined)
59
+ yield [path, document];
76
60
  }
77
- const read = parse(collection.text[path], path);
78
- if (read.ok)
79
- yield [path, read.document];
80
- }
81
- }
82
- export function unreadable(text, previous) {
83
- const paths = previous === undefined
84
- ? Object.keys(text)
85
- : [...differing(previous, text)].filter((path) => text[path] !== undefined);
86
- for (const path of paths.sort()) {
87
- const read = parse(text[path], path);
88
- if (!read.ok)
89
- return { kind: 'refused', refusal: read.refusal };
90
- }
91
- return null;
61
+ })();
92
62
  }
93
63
  export function validRoot(root) {
94
64
  return typeof root === 'string' && normalize(root) === root;
95
65
  }
96
- function validateAgainst(documents, binaryTargets, model) {
97
- if (model.status === 'unavailable') {
98
- const typed = Object.entries(documents).find(([, content]) => {
99
- const parsed = parse(content);
100
- return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
101
- });
102
- if (typed !== undefined)
103
- return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
104
- }
105
- return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
106
- }
107
- export function validateCollection(text, binaryTargets, composition) {
108
- const collection = {};
109
- const selection = {};
110
- for (const [path, content] of Object.entries(text)) {
111
- if (selected(composition, path))
112
- selection[path] = content;
113
- else
114
- collection[path] = content;
115
- }
116
- const verdicts = [
117
- validateAgainst(collection, binaryTargets.filter((path) => !selected(composition, path)), composition.model),
118
- ];
119
- if (composition.selection !== null) {
120
- verdicts.push(validateAgainst(selection, binaryTargets.filter((path) => selected(composition, path)), composition.selection.model));
121
- }
122
- const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
123
- if (refusals.length === 0)
124
- return verdicts[0];
125
- return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
126
- }
127
- const referrersOf = new WeakMap();
128
- function typing(left, right) {
129
- return (sameTyping(left.model, right.model) &&
130
- (left.selection === null || right.selection === null
131
- ? left.selection === right.selection
132
- : sameTyping(left.selection.model, right.selection.model)) &&
133
- JSON.stringify(left.selection?.roots ?? null) === JSON.stringify(right.selection?.roots ?? null));
134
- }
135
- function declared(content) {
136
- if (content === undefined)
137
- return undefined;
138
- const read = parseFrontmatter(content);
139
- return read.ok ? (read.frontmatter.type ?? 'any') : undefined;
140
- }
141
- function typedIn(content) {
142
- const type = declared(content);
143
- return type !== undefined && type !== 'any';
144
- }
145
- function modelOf(composition, path) {
146
- const model = governing(composition, path);
147
- return model.status === 'unavailable' ? null : { types: model.types };
148
- }
149
- function checked(path, content, composition) {
150
- return checkDocument(path, content, modelOf(composition, path) ?? NO_TYPES);
151
- }
152
- function targetsOf(check) {
153
- if (!check.ok)
154
- return [];
155
- return [...new Set(check.references.flatMap(({ target }) => (target === null ? [] : [target])))];
156
- }
157
- function referencedBy(path, content, composition) {
158
- const model = modelOf(composition, path);
159
- if (model === null)
160
- return [];
161
- const read = parseFrontmatter(content, path);
162
- const type = read.ok ? read.frontmatter.type : undefined;
163
- if (!read.ok || type === undefined || !Object.hasOwn(model.types, type))
164
- return [];
165
- const definition = model.types[type];
166
- return [
167
- ...new Set([
168
- ...references(read.frontmatter, definition).flatMap(({ value }) => {
169
- const found = target(path, value);
170
- return found === null ? [] : [found];
171
- }),
172
- ...sectionReferences(path, content, definition).flatMap(({ target }) => target === null ? [] : [target]),
173
- ]),
174
- ];
175
- }
176
- function reindexed(index, changed) {
177
- const referrers = new Map();
178
- const touch = (target) => {
179
- let held = referrers.get(target);
180
- if (held === undefined) {
181
- held = new Set(Object.hasOwn(index.referrers, target) ? index.referrers[target] : []);
182
- referrers.set(target, held);
183
- }
184
- return held;
185
- };
186
- for (const [path, found] of changed) {
187
- const before = Object.hasOwn(index.targets, path) ? index.targets[path] : [];
188
- for (const target of before)
189
- touch(target).delete(path);
190
- for (const target of found)
191
- touch(target).add(path);
192
- }
193
- const emptied = [...referrers].filter(([, held]) => held.size === 0).map(([target]) => target);
194
- return {
195
- composition: index.composition,
196
- targets: patched(index.targets, [...changed].filter(([, found]) => found.length > 0), [...changed].filter(([, found]) => found.length === 0).map(([path]) => path)),
197
- referrers: patched(index.referrers, [...referrers]
198
- .filter(([, held]) => held.size > 0)
199
- .map(([target, held]) => [target, [...held]]), emptied),
200
- };
201
- }
202
- function heldIndex(held, composition) {
203
- const index = referrersOf.get(held.text);
204
- return index !== undefined && typing(index.composition, composition) ? index : null;
205
- }
206
- const indexing = new WeakMap();
207
- export function indexReferrers(held, composition) {
208
- if (heldIndex(held, composition) !== null)
209
- return;
210
- const running = indexing.get(held.text);
211
- if (running !== undefined)
212
- return running;
213
- const targets = new Map();
214
- const referrers = new Map();
215
- const filled = inUnits(Object.keys(held.text), (path) => {
216
- const content = held.text[path];
217
- const found = referencedBy(path, content, composition);
218
- if (found.length > 0)
219
- targets.set(path, found);
220
- for (const target of found)
221
- referrers.set(target, [...(referrers.get(target) ?? []), path]);
222
- return ROW_WEIGHT + content.length;
223
- });
224
- const indexed = () => {
225
- referrersOf.set(held.text, {
226
- composition,
227
- targets: patched(shared({}), targets),
228
- referrers: patched(shared({}), referrers),
229
- });
230
- };
231
- if (!(filled instanceof Promise))
232
- return indexed();
233
- const building = filled.then(indexed).finally(() => indexing.delete(held.text));
234
- indexing.set(held.text, building);
235
- return building;
236
- }
237
- export function referencesIndexed(held, composition) {
238
- return heldIndex(held, composition) !== null;
239
- }
240
- export function referring(held, composition, targets) {
241
- const index = heldIndex(held, composition);
242
- if (index === null)
243
- return null;
244
- const found = new Set();
245
- for (const target of targets) {
246
- if (!Object.hasOwn(index.referrers, target))
247
- continue;
248
- for (const file of index.referrers[target])
249
- found.add(file);
250
- }
251
- return found;
252
- }
253
66
  export function available(composition) {
254
- return (composition.model.status !== 'unavailable' &&
255
- (composition.selection === null || composition.selection.model.status !== 'unavailable'));
256
- }
257
- export function changedCleanly(next, previous, composition) {
258
- if (!typing(previous.composition, composition))
259
- return false;
260
- const paths = new Set([
261
- ...differing(previous.text, next.text),
262
- ...differing(previous.binaries, next.binaries, () => true),
263
- ]);
264
- const binary = (path) => Object.hasOwn(next.binaries, path);
265
- const within = (file) => (path) => selected(composition, path) === selected(composition, file);
266
- const reaching = (file, check) => {
267
- if (!check.ok)
268
- return false;
269
- const part = within(file);
270
- return check.references.every((reference) => resolves(reference, (path) => (part(path) ? declared(next.text[path]) : undefined), (path) => part(path) && binary(path)));
271
- };
272
- const changedTargets = new Map();
273
- const shifted = [];
274
- for (const path of paths) {
275
- const now = next.text[path];
276
- const was = previous.text[path];
277
- const modeled = modelOf(composition, path) !== null;
278
- if ((now === undefined) !== (was === undefined) ||
279
- declared(now) !== declared(was) ||
280
- binary(path) !== Object.hasOwn(previous.binaries, path)) {
281
- shifted.push(path);
282
- }
283
- if (!modeled && typedIn(was) && !typedIn(now))
284
- return false;
285
- if (now === undefined) {
286
- if (modeled)
287
- changedTargets.set(path, []);
288
- continue;
289
- }
290
- if (binary(path))
291
- return false;
292
- if (!modeled) {
293
- if (declared(now) === undefined)
294
- return false;
295
- if (!typedIn(now) && !checked(path, now, composition).ok)
296
- return false;
297
- continue;
298
- }
299
- const check = checked(path, now, composition);
300
- if (!reaching(path, check))
301
- return false;
302
- changedTargets.set(path, targetsOf(check));
303
- }
304
- const index = heldIndex(previous, composition);
305
- if (index === null && shifted.length > 0)
306
- return false;
307
- for (const target of shifted) {
308
- const files = index !== null && Object.hasOwn(index.referrers, target) ? index.referrers[target] : [];
309
- for (const file of files) {
310
- if (paths.has(file))
311
- continue;
312
- if (!reaching(file, checked(file, next.text[file], composition)))
313
- return false;
314
- }
315
- }
316
- if (index !== null) {
317
- referrersOf.set(next.text, changedTargets.size === 0 ? index : reindexed(index, changedTargets));
318
- }
319
- return true;
67
+ return composition.model.status !== 'unavailable';
320
68
  }
@@ -0,0 +1,11 @@
1
+ import type { Plan, QueryRows } from './query.js';
2
+ import type { Connection } from './tables.js';
3
+ export type QueryRoom = {
4
+ readonly locator: string;
5
+ readonly key: number;
6
+ };
7
+ export type QueryAnswer = QueryRows & {
8
+ readonly more?: string;
9
+ };
10
+ export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
11
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,IAAI,EAAuC,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvF,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AA+a3E,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAkUjE,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,GAAE,MAAM,GAAG,IAAW,GAC3B,WAAW,CAUb"}