@agentshouse/mdruntime 0.1.0-ca7c26c6bc27e → 0.1.0-ca92b54804c33

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 (182) hide show
  1. package/README.md +25 -12
  2. package/dist/adapter.d.ts +199 -54
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/adapter.js +1 -9
  5. package/dist/attached-model.d.ts +7 -10
  6. package/dist/attached-model.d.ts.map +1 -1
  7. package/dist/attached-model.js +40 -28
  8. package/dist/attempt.d.ts +16 -0
  9. package/dist/attempt.d.ts.map +1 -0
  10. package/dist/attempt.js +70 -0
  11. package/dist/binary.d.ts +18 -0
  12. package/dist/binary.d.ts.map +1 -0
  13. package/dist/binary.js +8 -0
  14. package/dist/bootstrap.d.ts +37 -5
  15. package/dist/bootstrap.d.ts.map +1 -1
  16. package/dist/bootstrap.js +336 -51
  17. package/dist/chain.d.ts +12 -0
  18. package/dist/chain.d.ts.map +1 -0
  19. package/dist/chain.js +64 -0
  20. package/dist/change-set.d.ts +9 -14
  21. package/dist/change-set.d.ts.map +1 -1
  22. package/dist/change-set.js +11 -56
  23. package/dist/change.d.ts +46 -0
  24. package/dist/change.d.ts.map +1 -1
  25. package/dist/change.js +34 -0
  26. package/dist/client.d.ts +44 -18
  27. package/dist/client.d.ts.map +1 -1
  28. package/dist/client.js +161 -30
  29. package/dist/collection.d.ts +13 -14
  30. package/dist/collection.d.ts.map +1 -1
  31. package/dist/collection.js +52 -56
  32. package/dist/compile.d.ts +11 -0
  33. package/dist/compile.d.ts.map +1 -0
  34. package/dist/compile.js +586 -0
  35. package/dist/connection.d.ts +67 -24
  36. package/dist/connection.d.ts.map +1 -1
  37. package/dist/connection.js +4414 -1205
  38. package/dist/context.d.ts +2 -0
  39. package/dist/context.d.ts.map +1 -0
  40. package/dist/context.js +7 -0
  41. package/dist/conversation.d.ts +65 -21
  42. package/dist/conversation.d.ts.map +1 -1
  43. package/dist/conversation.js +922 -273
  44. package/dist/digest.d.ts +7 -0
  45. package/dist/digest.d.ts.map +1 -0
  46. package/dist/digest.js +113 -0
  47. package/dist/durability.d.ts +10 -1
  48. package/dist/durability.d.ts.map +1 -1
  49. package/dist/durability.js +5 -0
  50. package/dist/entry.d.ts +20 -0
  51. package/dist/entry.d.ts.map +1 -0
  52. package/dist/entry.js +161 -0
  53. package/dist/expectation.d.ts +21 -0
  54. package/dist/expectation.d.ts.map +1 -0
  55. package/dist/expectation.js +70 -0
  56. package/dist/failure.d.ts +13 -0
  57. package/dist/failure.d.ts.map +1 -0
  58. package/dist/failure.js +19 -0
  59. package/dist/file.d.ts +2 -19
  60. package/dist/file.d.ts.map +1 -1
  61. package/dist/file.js +7 -122
  62. package/dist/host.d.ts +11 -2
  63. package/dist/host.d.ts.map +1 -1
  64. package/dist/host.js +134 -34
  65. package/dist/identity.d.ts +3 -0
  66. package/dist/identity.d.ts.map +1 -1
  67. package/dist/identity.js +13 -1
  68. package/dist/index.d.ts +24 -10
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +11 -0
  71. package/dist/job.d.ts +14 -0
  72. package/dist/job.d.ts.map +1 -0
  73. package/dist/job.js +28 -0
  74. package/dist/live.d.ts +23 -0
  75. package/dist/live.d.ts.map +1 -0
  76. package/dist/live.js +165 -0
  77. package/dist/media.d.ts +8 -0
  78. package/dist/media.d.ts.map +1 -0
  79. package/dist/media.js +218 -0
  80. package/dist/memory.d.ts +22 -8
  81. package/dist/memory.d.ts.map +1 -1
  82. package/dist/memory.js +299 -94
  83. package/dist/messages.d.ts +28 -0
  84. package/dist/messages.d.ts.map +1 -0
  85. package/dist/messages.js +91 -0
  86. package/dist/model.d.ts +17 -12
  87. package/dist/model.d.ts.map +1 -1
  88. package/dist/model.js +9 -9
  89. package/dist/name.d.ts +4 -0
  90. package/dist/name.d.ts.map +1 -0
  91. package/dist/name.js +122 -0
  92. package/dist/observation.d.ts +22 -4
  93. package/dist/observation.d.ts.map +1 -1
  94. package/dist/observation.js +120 -14
  95. package/dist/open.d.ts +2 -0
  96. package/dist/open.d.ts.map +1 -0
  97. package/dist/open.js +1 -0
  98. package/dist/opened.d.ts +22 -0
  99. package/dist/opened.d.ts.map +1 -0
  100. package/dist/opened.js +107 -0
  101. package/dist/outcome.d.ts +72 -5
  102. package/dist/outcome.d.ts.map +1 -1
  103. package/dist/outcome.js +81 -1
  104. package/dist/overlay.d.ts +16 -5
  105. package/dist/overlay.d.ts.map +1 -1
  106. package/dist/overlay.js +147 -180
  107. package/dist/paths.d.ts +1 -1
  108. package/dist/paths.d.ts.map +1 -1
  109. package/dist/paths.js +4 -16
  110. package/dist/query.d.ts +42 -181
  111. package/dist/query.d.ts.map +1 -1
  112. package/dist/query.js +3 -423
  113. package/dist/reach.d.ts +19 -5
  114. package/dist/reach.d.ts.map +1 -1
  115. package/dist/reach.js +298 -92
  116. package/dist/react.d.ts +45 -0
  117. package/dist/react.d.ts.map +1 -0
  118. package/dist/react.js +54 -0
  119. package/dist/readiness.d.ts +50 -0
  120. package/dist/readiness.d.ts.map +1 -0
  121. package/dist/readiness.js +27 -0
  122. package/dist/recovery.d.ts +26 -0
  123. package/dist/recovery.d.ts.map +1 -0
  124. package/dist/recovery.js +232 -0
  125. package/dist/refresh.d.ts +20 -7
  126. package/dist/refresh.d.ts.map +1 -1
  127. package/dist/refresh.js +155 -59
  128. package/dist/replica.d.ts +61 -34
  129. package/dist/replica.d.ts.map +1 -1
  130. package/dist/replica.js +355 -162
  131. package/dist/room-draft.d.ts +59 -11
  132. package/dist/room-draft.d.ts.map +1 -1
  133. package/dist/room-draft.js +276 -80
  134. package/dist/rows.d.ts +32 -34
  135. package/dist/rows.d.ts.map +1 -1
  136. package/dist/rows.js +65 -87
  137. package/dist/save.d.ts +74 -6
  138. package/dist/save.d.ts.map +1 -1
  139. package/dist/save.js +902 -182
  140. package/dist/search.d.ts +15 -54
  141. package/dist/search.d.ts.map +1 -1
  142. package/dist/search.js +10 -121
  143. package/dist/seed.d.ts +16 -0
  144. package/dist/seed.d.ts.map +1 -0
  145. package/dist/seed.js +75 -0
  146. package/dist/shared.d.ts +15 -0
  147. package/dist/shared.d.ts.map +1 -0
  148. package/dist/shared.js +421 -0
  149. package/dist/status.d.ts +7 -4
  150. package/dist/status.d.ts.map +1 -1
  151. package/dist/status.js +3 -15
  152. package/dist/store.d.ts +174 -68
  153. package/dist/store.d.ts.map +1 -1
  154. package/dist/store.js +367 -360
  155. package/dist/stored.d.ts +156 -0
  156. package/dist/stored.d.ts.map +1 -0
  157. package/dist/stored.js +635 -0
  158. package/dist/tables.d.ts +381 -0
  159. package/dist/tables.d.ts.map +1 -0
  160. package/dist/tables.js +700 -0
  161. package/dist/transfer.d.ts +0 -5
  162. package/dist/transfer.d.ts.map +1 -1
  163. package/dist/turn.d.ts +9 -0
  164. package/dist/turn.d.ts.map +1 -0
  165. package/dist/turn.js +75 -0
  166. package/dist/validation.d.ts +29 -0
  167. package/dist/validation.d.ts.map +1 -0
  168. package/dist/validation.js +104 -0
  169. package/dist/windows.d.ts +11 -0
  170. package/dist/windows.d.ts.map +1 -0
  171. package/dist/windows.js +16 -0
  172. package/dist/wire.d.ts +179 -45
  173. package/dist/wire.d.ts.map +1 -1
  174. package/dist/wire.js +72 -46
  175. package/package.json +33 -10
  176. package/AGENTS.md +0 -215
  177. package/dist/attachment.d.ts +0 -3
  178. package/dist/attachment.d.ts.map +0 -1
  179. package/dist/attachment.js +0 -8
  180. package/dist/read-side.d.ts +0 -18
  181. package/dist/read-side.d.ts.map +0 -1
  182. package/dist/read-side.js +0 -377
package/dist/client.js CHANGED
@@ -1,5 +1,28 @@
1
+ import { shownBy } from './media.js';
1
2
  import { observed } from './observation.js';
2
- import { answer, AUTHORIZATION_ENDED, carried, envelope, PORT_CLOSED, PROTOCOL_MISMATCH, } from './wire.js';
3
+ import { runtimeError } from './failure.js';
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
+ }
23
+ function refused(refusal) {
24
+ return runtimeError(refusal.code, refusal.code, refusal.retryable);
25
+ }
3
26
  export function connectMdRuntime(port) {
4
27
  let sequence = 0;
5
28
  let refusal = null;
@@ -7,8 +30,10 @@ export function connectMdRuntime(port) {
7
30
  const calls = new Map();
8
31
  const opening = new Map();
9
32
  const observations = new Map();
33
+ let drawing = null;
34
+ let settling = null;
10
35
  const send = (message) => {
11
- port.postMessage(envelope(message));
36
+ port.postMessage(message);
12
37
  };
13
38
  function begin(id, topic, first) {
14
39
  const handle = observed(first, () => {
@@ -25,7 +50,7 @@ export function connectMdRuntime(port) {
25
50
  if (topic === 'connection-refusal')
26
51
  handle.receive(reported);
27
52
  }
28
- const failure = new Error(reported.reason);
53
+ const failure = refused(reported);
29
54
  for (const [id, waiting] of opening) {
30
55
  if (waiting.topic === 'connection-refusal')
31
56
  waiting.settle(begin(id, waiting.topic, reported));
@@ -36,12 +61,12 @@ export function connectMdRuntime(port) {
36
61
  for (const waiting of calls.values())
37
62
  waiting.fail(failure);
38
63
  calls.clear();
64
+ drawing?.();
39
65
  }
40
- function end(reason) {
66
+ function end(failure) {
41
67
  if (ended !== null)
42
68
  return;
43
- ended = reason;
44
- const failure = new Error(reason);
69
+ ended = failure;
45
70
  for (const waiting of opening.values())
46
71
  waiting.fail(failure);
47
72
  opening.clear();
@@ -51,16 +76,10 @@ export function connectMdRuntime(port) {
51
76
  for (const { handle } of observations.values())
52
77
  handle.end();
53
78
  observations.clear();
79
+ drawing?.();
54
80
  }
55
81
  port.addEventListener('message', (event) => {
56
- const wire = carried(event.data);
57
- if (wire === null)
58
- return;
59
- if (!wire.matching) {
60
- refuse(PROTOCOL_MISMATCH);
61
- return;
62
- }
63
- const message = answer(wire.message);
82
+ const message = answer(event.data);
64
83
  if (message === null)
65
84
  return;
66
85
  if (message.kind === 'refusal') {
@@ -68,7 +87,11 @@ export function connectMdRuntime(port) {
68
87
  return;
69
88
  }
70
89
  if (message.kind === 'ended') {
71
- end(AUTHORIZATION_ENDED);
90
+ for (const { topic, handle } of observations.values()) {
91
+ if (topic === 'member')
92
+ handle.receive(null);
93
+ }
94
+ end(runtimeError('authorization-ended', AUTHORIZATION_ENDED));
72
95
  return;
73
96
  }
74
97
  if (message.kind === 'event') {
@@ -78,31 +101,34 @@ export function connectMdRuntime(port) {
78
101
  const waiting = opening.get(message.id);
79
102
  if (waiting !== undefined) {
80
103
  opening.delete(message.id);
81
- if (message.kind === 'failure')
82
- waiting.fail(new Error(message.message));
104
+ if (message.kind === 'failure') {
105
+ waiting.fail(runtimeError(message.code, message.message, message.retryable));
106
+ }
83
107
  else
84
108
  waiting.settle(begin(message.id, waiting.topic, message.value));
109
+ drawing?.();
85
110
  return;
86
111
  }
87
112
  const called = calls.get(message.id);
88
113
  if (called === undefined)
89
114
  return;
90
115
  calls.delete(message.id);
91
- if (message.kind === 'failure')
92
- called.fail(new Error(message.message));
116
+ if (message.kind === 'failure') {
117
+ called.fail(runtimeError(message.code, message.message, message.retryable));
118
+ }
93
119
  else
94
120
  called.settle(message.value);
95
121
  });
96
122
  port.addEventListener('close', () => {
97
- end(PORT_CLOSED);
123
+ end(runtimeError('port-closed', PORT_CLOSED));
98
124
  });
99
125
  port.start();
100
126
  send({ kind: 'hello' });
101
127
  function ask(member, input) {
102
128
  if (ended !== null)
103
- return Promise.reject(new Error(ended));
129
+ return Promise.reject(ended);
104
130
  if (refusal !== null)
105
- return Promise.reject(new Error(refusal.reason));
131
+ return Promise.reject(refused(refusal));
106
132
  const id = (sequence += 1);
107
133
  return new Promise((settle, fail) => {
108
134
  calls.set(id, { settle: settle, fail });
@@ -111,19 +137,101 @@ export function connectMdRuntime(port) {
111
137
  }
112
138
  function watch(topic, input) {
113
139
  if (ended !== null)
114
- return Promise.reject(new Error(ended));
140
+ return Promise.reject(ended);
115
141
  const id = (sequence += 1);
116
142
  if (refusal !== null) {
117
143
  return topic === 'connection-refusal'
118
144
  ? Promise.resolve(begin(id, topic, refusal))
119
- : Promise.reject(new Error(refusal.reason));
145
+ : Promise.reject(refused(refusal));
120
146
  }
121
147
  return new Promise((settle, fail) => {
122
148
  opening.set(id, { topic, settle, fail });
123
149
  send({ kind: 'observe', id, topic, input });
150
+ drawing?.();
151
+ });
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
+ }
204
+ function settled() {
205
+ if (settling !== null)
206
+ return settling;
207
+ settling = new Promise((resolve) => {
208
+ let moved = 0;
209
+ const check = () => {
210
+ moved += 1;
211
+ if (opening.size > 0)
212
+ return;
213
+ const at = moved;
214
+ const waited = (frames) => {
215
+ requestAnimationFrame(() => {
216
+ if (frames < SETTLED_FRAMES) {
217
+ waited(frames + 1);
218
+ return;
219
+ }
220
+ if (moved !== at || opening.size > 0)
221
+ return;
222
+ drawing = null;
223
+ resolve();
224
+ });
225
+ };
226
+ waited(1);
227
+ };
228
+ drawing = check;
229
+ check();
124
230
  });
231
+ return settling;
125
232
  }
126
- return {
233
+ const show = (room, path, revision) => ask('binaryFile.show', [room, path, revision]).then((shown) => streamed(shown));
234
+ return shownBy(show, {
127
235
  rooms: () => ask('rooms', []),
128
236
  query: ((query) => ask('query', [query])),
129
237
  search: (request) => ask('search', [request]),
@@ -131,35 +239,58 @@ export function connectMdRuntime(port) {
131
239
  roomDraft: {
132
240
  list: () => ask('roomDraft.list', []),
133
241
  read: (room, path) => ask('roomDraft.read', [room, path]),
134
- 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]),
135
243
  discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
136
244
  },
137
245
  save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
246
+ saveParts: (room, parts) => ask('saveParts', [room, parts]),
138
247
  presentation: {
139
248
  read: () => ask('presentation.read', []),
140
249
  write: (value) => ask('presentation.write', [value]),
250
+ edit: (members) => ask('presentation.edit', [members]),
141
251
  },
142
252
  conversation: {
143
253
  list: () => ask('conversation.list', []),
144
254
  read: (conversation, options) => ask('conversation.read', [conversation, options]),
145
255
  create: (input) => ask('conversation.create', [input]),
146
- send: (conversation) => ask('conversation.send', [conversation]),
256
+ send: (conversation, operation, draft) => ask('conversation.send', [conversation, operation, draft]),
147
257
  answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
148
258
  interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
149
259
  kill: (conversation) => ask('conversation.kill', [conversation]),
150
- cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
151
260
  delete: (conversation) => ask('conversation.delete', [conversation]),
152
261
  },
153
262
  chatDraft: {
154
- write: (conversation, draft) => ask('chatDraft.write', [conversation, draft]),
263
+ write: (conversation, draft, revision) => ask('chatDraft.write', [conversation, draft, revision]),
264
+ prepend: (conversation, draft) => ask('chatDraft.prepend', [conversation, draft]),
155
265
  discard: (conversation) => ask('chatDraft.discard', [conversation]),
156
266
  },
157
267
  history: (locator, path, query) => ask('history', [locator, path, query]),
268
+ resolve: (room, path, destination) => ask('resolve', [room, path, destination]),
269
+ binaryFile: {
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,
273
+ },
158
274
  call: (name, input) => ask('call', [name, input]),
159
275
  reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
160
276
  log: () => ask('log', []),
161
277
  persistence: () => ask('persistence', []),
278
+ retry: () => ask('retry', []),
279
+ cleanUp: () => ask('cleanUp', []),
280
+ unsent: () => ask('unsent', []),
281
+ reset: () => ask('reset', []),
162
282
  observe: ((topic, ...input) => watch(topic, input)),
163
283
  reauthorize: () => ask('reauthorize', []),
164
- };
284
+ settled,
285
+ });
286
+ }
287
+ const turns = new WeakMap();
288
+ export function inTurn(client, work) {
289
+ const turn = (turns.get(client) ?? Promise.resolve()).then(work);
290
+ turns.set(client, turn.then(() => undefined, () => undefined));
291
+ return turn;
165
292
  }
293
+ export { chainedWindows } from './chain.js';
294
+ export { roomDraftRevision } from './identity.js';
295
+ export { defineRoomMedia, ROOM_MEDIA } from './media.js';
296
+ export { unanswered } from './wire.js';
@@ -1,11 +1,11 @@
1
- import { type Document, type Validation } from '@agentshouse/mdmodel';
1
+ import { type Document, type TypedPath } from '@agentshouse/mdmodel';
2
2
  import type { ModelState } from './model.js';
3
3
  import type { MdModelIdentity } from './adapter.js';
4
- import type { Refused } from './transfer.js';
5
4
  export declare const MD_MODEL: MdModelIdentity;
6
5
  export type Collection = {
7
- documents: Readonly<Record<string, Document>>;
6
+ text: Readonly<Record<string, string>>;
8
7
  composition: Composition;
8
+ document(path: string): Document | undefined;
9
9
  };
10
10
  export type Composition = {
11
11
  model: ModelState;
@@ -13,18 +13,17 @@ export type Composition = {
13
13
  roots: readonly string[];
14
14
  model: ModelState;
15
15
  } | null;
16
+ typedPaths: readonly TypedPath[];
16
17
  };
17
- export declare function governing(composition: Composition, path: string): ModelState;
18
- type Previous = {
19
- text: Readonly<Record<string, string>>;
20
- collection: Collection;
18
+ export type Composed = {
19
+ readonly composition: Composition;
20
+ readonly fingerprint: string;
21
21
  };
22
- export declare function parseCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): Collection;
23
- export declare function readCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): {
24
- kind: 'read';
25
- collection: Collection;
26
- } | Refused;
22
+ export declare function composedOf(composition: Composition): Composed;
23
+ export declare function selected(composition: Composition, path: string): boolean;
24
+ export declare function governing(composition: Composition, path: string): ModelState;
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>;
27
27
  export declare function validRoot(root: unknown): root is string;
28
- export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition): Validation;
29
- export {};
28
+ export declare function available(composition: Composition): boolean;
30
29
  //# sourceMappingURL=collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,EAEb,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAIhG,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9C,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE;QAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI,CAAC;CACnE,CAAC;AASF,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAI5E;AAED,KAAK,QAAQ,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC;AAanF,wBAAgB,eAAe,CAC7B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,QAAQ,GAClB,UAAU,CAOZ;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,QAAQ,GAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GAAG,OAAO,CAQpD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEvD;AAwBD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,WAAW,EAAE,WAAW,GACvB,UAAU,CA0BZ"}
1
+ {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAErF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAEhG,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvC,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE;QAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI,CAAC;IAClE,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAc3F,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,GAAG,QAAQ,CAS7D;AAED,wBAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAKxE;AAED,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAI5E;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,GACvB,UAAU,CAcZ;AAED,wBAAiB,WAAW,CAC1B,UAAU,EAAE,UAAU,GACrB,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAQhE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEvD;AAED,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAE3D"}
@@ -1,8 +1,30 @@
1
- import { parse, validate, VERSION, } from '@agentshouse/mdmodel';
1
+ import { parse, VERSION } from '@agentshouse/mdmodel';
2
2
  import { beneath, normalize } from './paths.js';
3
+ import { hashed } from './observation.js';
4
+ import { sortedKeys } from './shared.js';
3
5
  export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
4
- const NO_TYPES = { types: {} };
5
- 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) {
6
28
  return (composition.selection !== null &&
7
29
  composition.selection.roots.some((root) => beneath(root, path)));
8
30
  }
@@ -11,62 +33,36 @@ export function governing(composition, path) {
11
33
  ? composition.selection.model
12
34
  : composition.model;
13
35
  }
14
- function parsedAt(text, path, previous) {
15
- const retained = previous?.collection.documents[path];
16
- return retained !== undefined && previous?.text[path] === text[path]
17
- ? { ok: true, document: retained }
18
- : parse(text[path], path);
19
- }
20
- export function parseCollection(text, composition, previous) {
21
- const documents = {};
22
- for (const path of Object.keys(text).sort()) {
23
- const parsed = parsedAt(text, path, previous);
24
- if (parsed.ok)
25
- documents[path] = parsed.document;
26
- }
27
- return { documents, composition };
36
+ export function collectionOf(text, composition) {
37
+ const parsed = new Map();
38
+ return {
39
+ text,
40
+ composition,
41
+ document(path) {
42
+ if (parsed.has(path))
43
+ return parsed.get(path) ?? undefined;
44
+ const content = text[path];
45
+ if (content === undefined)
46
+ return undefined;
47
+ const read = parse(content, path);
48
+ parsed.set(path, read.ok ? read.document : null);
49
+ return read.ok ? read.document : undefined;
50
+ },
51
+ };
28
52
  }
29
- export function readCollection(text, composition, previous) {
30
- const documents = {};
31
- for (const path of Object.keys(text).sort()) {
32
- const parsed = parsedAt(text, path, previous);
33
- if (!parsed.ok)
34
- return { kind: 'refused', refusal: parsed.refusal };
35
- documents[path] = parsed.document;
36
- }
37
- return { kind: 'read', collection: { documents, composition } };
53
+ export function* documentsOf(collection) {
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];
60
+ }
61
+ })();
38
62
  }
39
63
  export function validRoot(root) {
40
64
  return typeof root === 'string' && normalize(root) === root;
41
65
  }
42
- function validateAgainst(documents, binaryTargets, model) {
43
- if (model.status === 'unavailable') {
44
- const typed = Object.entries(documents).find(([, content]) => {
45
- const parsed = parse(content);
46
- return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
47
- });
48
- if (typed !== undefined)
49
- return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
50
- }
51
- return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
52
- }
53
- export function validateCollection(text, binaryTargets, composition) {
54
- const collection = {};
55
- const selection = {};
56
- for (const [path, content] of Object.entries(text)) {
57
- if (selected(composition, path))
58
- selection[path] = content;
59
- else
60
- collection[path] = content;
61
- }
62
- const verdicts = [
63
- validateAgainst(collection, binaryTargets.filter((path) => !selected(composition, path)), composition.model),
64
- ];
65
- if (composition.selection !== null) {
66
- verdicts.push(validateAgainst(selection, binaryTargets.filter((path) => selected(composition, path)), composition.selection.model));
67
- }
68
- const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
69
- if (refusals.length === 0)
70
- return verdicts[0];
71
- return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
66
+ export function available(composition) {
67
+ return composition.model.status !== 'unavailable';
72
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"}