@agentshouse/mdruntime 0.1.0-c01d4615bfe46 → 0.1.0-c024a9c474f5e

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 (264) hide show
  1. package/README.md +14 -13
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +32 -3
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +58 -19
  6. package/dist/adapter.d.ts +183 -21
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/attached-model.d.ts.map +1 -1
  9. package/dist/attached-model.js +2 -2
  10. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  11. package/dist/attachment.d.ts.map +1 -0
  12. package/dist/attachment.js +15 -0
  13. package/dist/authored.d.ts +88 -0
  14. package/dist/authored.d.ts.map +1 -0
  15. package/dist/authored.js +345 -0
  16. package/dist/chain.d.ts +1 -1
  17. package/dist/chain.d.ts.map +1 -1
  18. package/dist/chain.js +5 -2
  19. package/dist/change.d.ts +6 -2
  20. package/dist/change.d.ts.map +1 -1
  21. package/dist/change.js +3 -0
  22. package/dist/chat-types.js +2 -2
  23. package/dist/client.d.ts +23 -8
  24. package/dist/client.d.ts.map +1 -1
  25. package/dist/client.js +25 -54
  26. package/dist/collection.d.ts +6 -1
  27. package/dist/collection.d.ts.map +1 -1
  28. package/dist/collection.js +23 -9
  29. package/dist/column.d.ts +5 -0
  30. package/dist/column.d.ts.map +1 -0
  31. package/dist/column.js +9 -0
  32. package/dist/compile.d.ts +2 -1
  33. package/dist/compile.d.ts.map +1 -1
  34. package/dist/compile.js +73 -42
  35. package/dist/connection.d.ts +1 -1
  36. package/dist/connection.d.ts.map +1 -1
  37. package/dist/connection.js +16 -6
  38. package/dist/context.d.ts.map +1 -1
  39. package/dist/context.js +1 -1
  40. package/dist/conversation-live.d.ts +8 -5
  41. package/dist/conversation-live.d.ts.map +1 -1
  42. package/dist/conversation-live.js +5 -3
  43. package/dist/conversation-row.d.ts +23 -1
  44. package/dist/conversation-row.d.ts.map +1 -1
  45. package/dist/conversation-row.js +37 -8
  46. package/dist/conversation.d.ts +20 -9
  47. package/dist/conversation.d.ts.map +1 -1
  48. package/dist/conversation.js +102 -68
  49. package/dist/declaration.js +3 -3
  50. package/dist/discovery.d.ts +3 -1
  51. package/dist/discovery.d.ts.map +1 -1
  52. package/dist/discovery.js +30 -5
  53. package/dist/download.d.ts +6 -0
  54. package/dist/download.d.ts.map +1 -0
  55. package/dist/download.js +42 -0
  56. package/dist/durability.d.ts +2 -1
  57. package/dist/durability.d.ts.map +1 -1
  58. package/dist/durability.js +3 -0
  59. package/dist/entry.d.ts +26 -1
  60. package/dist/entry.d.ts.map +1 -1
  61. package/dist/entry.js +126 -36
  62. package/dist/failure.d.ts.map +1 -1
  63. package/dist/failure.js +3 -1
  64. package/dist/figures.d.ts +1 -1
  65. package/dist/figures.d.ts.map +1 -1
  66. package/dist/figures.js +6 -4
  67. package/dist/file.d.ts +1 -1
  68. package/dist/file.d.ts.map +1 -1
  69. package/dist/file.js +1 -1
  70. package/dist/holdings.d.ts.map +1 -1
  71. package/dist/holdings.js +5 -3
  72. package/dist/host.d.ts +6 -2
  73. package/dist/host.d.ts.map +1 -1
  74. package/dist/host.js +70 -29
  75. package/dist/house-query.d.ts +24 -0
  76. package/dist/house-query.d.ts.map +1 -0
  77. package/dist/house-query.js +102 -0
  78. package/dist/identity.d.ts +1 -1
  79. package/dist/identity.d.ts.map +1 -1
  80. package/dist/identity.js +1 -1
  81. package/dist/index.d.ts +20 -12
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +10 -5
  84. package/dist/install.d.ts +8 -2
  85. package/dist/install.d.ts.map +1 -1
  86. package/dist/install.js +40 -33
  87. package/dist/lifecycle.d.ts +1 -1
  88. package/dist/lifecycle.d.ts.map +1 -1
  89. package/dist/lifecycle.js +42 -25
  90. package/dist/linked-file.d.ts +7 -0
  91. package/dist/linked-file.d.ts.map +1 -0
  92. package/dist/linked-file.js +13 -0
  93. package/dist/listing.d.ts +24 -12
  94. package/dist/listing.d.ts.map +1 -1
  95. package/dist/listing.js +50 -21
  96. package/dist/live.d.ts +19 -3
  97. package/dist/live.d.ts.map +1 -1
  98. package/dist/live.js +94 -36
  99. package/dist/loaded.d.ts +7 -0
  100. package/dist/loaded.d.ts.map +1 -0
  101. package/dist/loaded.js +46 -0
  102. package/dist/locks.d.ts.map +1 -1
  103. package/dist/locks.js +4 -2
  104. package/dist/lost.js +1 -1
  105. package/dist/media.d.ts +19 -3
  106. package/dist/media.d.ts.map +1 -1
  107. package/dist/media.js +177 -27
  108. package/dist/memory.d.ts +4 -2
  109. package/dist/memory.d.ts.map +1 -1
  110. package/dist/memory.js +50 -16
  111. package/dist/messages.d.ts +12 -1
  112. package/dist/messages.d.ts.map +1 -1
  113. package/dist/messages.js +28 -6
  114. package/dist/modal.d.ts +2 -0
  115. package/dist/modal.d.ts.map +1 -0
  116. package/dist/modal.js +11 -0
  117. package/dist/model.d.ts +10 -7
  118. package/dist/model.d.ts.map +1 -1
  119. package/dist/model.js +7 -1
  120. package/dist/models.d.ts.map +1 -1
  121. package/dist/models.js +3 -3
  122. package/dist/name.d.ts +0 -1
  123. package/dist/name.d.ts.map +1 -1
  124. package/dist/name.js +3 -7
  125. package/dist/observation.d.ts +26 -10
  126. package/dist/observation.d.ts.map +1 -1
  127. package/dist/observation.js +200 -69
  128. package/dist/online.d.ts +7 -0
  129. package/dist/online.d.ts.map +1 -0
  130. package/dist/online.js +29 -0
  131. package/dist/opened.d.ts +5 -5
  132. package/dist/opened.d.ts.map +1 -1
  133. package/dist/opened.js +2 -2
  134. package/dist/opening.d.ts.map +1 -1
  135. package/dist/opening.js +20 -2
  136. package/dist/outcome.d.ts +27 -14
  137. package/dist/outcome.d.ts.map +1 -1
  138. package/dist/outcome.js +14 -5
  139. package/dist/overlay.d.ts +20 -9
  140. package/dist/overlay.d.ts.map +1 -1
  141. package/dist/overlay.js +110 -41
  142. package/dist/parts.d.ts +4 -1
  143. package/dist/parts.d.ts.map +1 -1
  144. package/dist/parts.js +30 -7
  145. package/dist/paths.d.ts +1 -1
  146. package/dist/paths.js +1 -1
  147. package/dist/preparation.d.ts +33 -7
  148. package/dist/preparation.d.ts.map +1 -1
  149. package/dist/preparation.js +195 -78
  150. package/dist/presence.d.ts +8 -2
  151. package/dist/presence.d.ts.map +1 -1
  152. package/dist/presence.js +24 -13
  153. package/dist/queries.d.ts +1 -1
  154. package/dist/queries.d.ts.map +1 -1
  155. package/dist/queries.js +115 -67
  156. package/dist/query.d.ts +2 -2
  157. package/dist/query.d.ts.map +1 -1
  158. package/dist/questions.d.ts +1 -0
  159. package/dist/questions.d.ts.map +1 -1
  160. package/dist/questions.js +3 -1
  161. package/dist/queue.d.ts +1 -1
  162. package/dist/queue.d.ts.map +1 -1
  163. package/dist/queue.js +55 -23
  164. package/dist/reach.d.ts +15 -6
  165. package/dist/reach.d.ts.map +1 -1
  166. package/dist/reach.js +140 -25
  167. package/dist/react.d.ts +11 -1
  168. package/dist/react.d.ts.map +1 -1
  169. package/dist/readiness.d.ts +22 -3
  170. package/dist/readiness.d.ts.map +1 -1
  171. package/dist/readiness.js +18 -10
  172. package/dist/reads.d.ts +2 -2
  173. package/dist/reads.d.ts.map +1 -1
  174. package/dist/reads.js +21 -13
  175. package/dist/recovery.d.ts +1 -0
  176. package/dist/recovery.d.ts.map +1 -1
  177. package/dist/recovery.js +2 -1
  178. package/dist/refresh.d.ts +1 -1
  179. package/dist/refresh.js +4 -4
  180. package/dist/replica.d.ts +3 -8
  181. package/dist/replica.d.ts.map +1 -1
  182. package/dist/replica.js +5 -5
  183. package/dist/room-draft.d.ts +29 -4
  184. package/dist/room-draft.d.ts.map +1 -1
  185. package/dist/room-draft.js +237 -16
  186. package/dist/room-drafts.d.ts.map +1 -1
  187. package/dist/room-drafts.js +12 -7
  188. package/dist/room-list.d.ts +10 -0
  189. package/dist/room-list.d.ts.map +1 -0
  190. package/dist/room-list.js +47 -0
  191. package/dist/rows.d.ts +11 -3
  192. package/dist/rows.d.ts.map +1 -1
  193. package/dist/rows.js +25 -11
  194. package/dist/run-tables.d.ts +25 -0
  195. package/dist/run-tables.d.ts.map +1 -0
  196. package/dist/run-tables.js +98 -0
  197. package/dist/running.d.ts +5 -0
  198. package/dist/running.d.ts.map +1 -0
  199. package/dist/running.js +10 -0
  200. package/dist/runs.d.ts +27 -0
  201. package/dist/runs.d.ts.map +1 -0
  202. package/dist/runs.js +92 -0
  203. package/dist/runtime.d.ts +7 -3
  204. package/dist/runtime.d.ts.map +1 -1
  205. package/dist/save.d.ts +1 -0
  206. package/dist/save.d.ts.map +1 -1
  207. package/dist/save.js +31 -96
  208. package/dist/saves.d.ts +7 -5
  209. package/dist/saves.d.ts.map +1 -1
  210. package/dist/saves.js +108 -54
  211. package/dist/seed.d.ts.map +1 -1
  212. package/dist/seed.js +2 -2
  213. package/dist/selector.d.ts +3 -0
  214. package/dist/selector.d.ts.map +1 -0
  215. package/dist/selector.js +22 -0
  216. package/dist/shown.d.ts +4 -2
  217. package/dist/shown.d.ts.map +1 -1
  218. package/dist/shown.js +73 -48
  219. package/dist/socket/session.d.ts +4 -1
  220. package/dist/socket/session.d.ts.map +1 -1
  221. package/dist/socket/session.js +3 -0
  222. package/dist/socket.d.ts +6 -1
  223. package/dist/socket.d.ts.map +1 -1
  224. package/dist/socket.js +14 -2
  225. package/dist/source.d.ts +42 -0
  226. package/dist/source.d.ts.map +1 -1
  227. package/dist/source.js +76 -9
  228. package/dist/store/installs.d.ts +2 -2
  229. package/dist/store/installs.d.ts.map +1 -1
  230. package/dist/store/installs.js +10 -4
  231. package/dist/store/readiness.d.ts +5 -4
  232. package/dist/store/readiness.d.ts.map +1 -1
  233. package/dist/store/readiness.js +28 -12
  234. package/dist/store/records.d.ts +24 -5
  235. package/dist/store/records.d.ts.map +1 -1
  236. package/dist/store/records.js +59 -24
  237. package/dist/store/rooms-shown.d.ts +8 -0
  238. package/dist/store/rooms-shown.d.ts.map +1 -0
  239. package/dist/store/rooms-shown.js +13 -0
  240. package/dist/store.d.ts +15 -10
  241. package/dist/store.d.ts.map +1 -1
  242. package/dist/store.js +12 -5
  243. package/dist/stored.d.ts +40 -16
  244. package/dist/stored.d.ts.map +1 -1
  245. package/dist/stored.js +210 -52
  246. package/dist/surface.d.ts +18 -7
  247. package/dist/surface.d.ts.map +1 -1
  248. package/dist/surface.js +52 -16
  249. package/dist/sync.d.ts +4 -2
  250. package/dist/sync.d.ts.map +1 -1
  251. package/dist/sync.js +47 -25
  252. package/dist/tables.d.ts +34 -49
  253. package/dist/tables.d.ts.map +1 -1
  254. package/dist/tables.js +84 -325
  255. package/dist/tallies.js +2 -2
  256. package/dist/validation.d.ts +2 -0
  257. package/dist/validation.d.ts.map +1 -1
  258. package/dist/validation.js +50 -10
  259. package/dist/wire.d.ts +29 -14
  260. package/dist/wire.d.ts.map +1 -1
  261. package/dist/wire.js +18 -13
  262. package/package.json +4 -4
  263. package/dist/binary.d.ts.map +0 -1
  264. package/dist/binary.js +0 -8
package/dist/client.js CHANGED
@@ -1,27 +1,11 @@
1
- import { shownBy } from './media.js';
1
+ import { handedCopy, handedLink } from './download.js';
2
2
  import { pageMetadataBlock } from './page-metadata.js';
3
- import { observed } from './observation.js';
3
+ import { appRooms, observed } from './observation.js';
4
4
  import { runtimeError } from './failure.js';
5
- import { blobOf, } from './outcome.js';
5
+ import { attachmentBlob, } from './outcome.js';
6
6
  import { AUTHORIZATION_ENDED, PORT_CLOSED, wireAnswer, } from './wire.js';
7
7
  // 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.
8
8
  const SETTLED_FRAMES = 2;
9
- // 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.
10
- const HANDED_COPY_MS = 60_000;
11
- const PAGE = /\.html?$/iu;
12
- const STARTED = { kind: 'started' };
13
- const BLOCKED = {
14
- kind: 'blocked',
15
- code: 'popup-blocked',
16
- fields: {},
17
- retryable: true,
18
- };
19
- function handed(url, name) {
20
- const anchor = document.createElement('a');
21
- anchor.href = url;
22
- anchor.download = name;
23
- anchor.click();
24
- }
25
9
  function refused(refusal) {
26
10
  return runtimeError(refusal.code);
27
11
  }
@@ -91,7 +75,7 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
91
75
  }
92
76
  if (message.kind === 'ended') {
93
77
  for (const { topic, handle } of observations.values()) {
94
- if (topic === 'member')
78
+ if (topic === 'member' || topic === 'time-zone')
95
79
  handle.receive(null);
96
80
  }
97
81
  end(runtimeError('authorization-ended', AUTHORIZATION_ENDED));
@@ -161,12 +145,12 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
161
145
  let received = 0;
162
146
  const stream = new ReadableStream({
163
147
  async pull(controller) {
164
- const bytes = await ask('binaryFile.part', [file, part]);
148
+ const bytes = await ask('attachment.part', [file, part]);
165
149
  if (bytes === null) {
166
150
  if (received === byteLength)
167
151
  controller.close();
168
152
  else
169
- controller.error(runtimeError('binary-file-absent', 'The file ended early'));
153
+ controller.error(runtimeError('attachment-absent', 'The file ended early'));
170
154
  return;
171
155
  }
172
156
  part += 1;
@@ -177,30 +161,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
177
161
  return { kind: 'binary', stream, byteLength, mediaType };
178
162
  }
179
163
  async function download(room, path, revision) {
180
- const tab = PAGE.test(path) ? globalThis.open('', '_blank') : null;
181
- const linked = await ask('binaryFile.link', [room, path, revision]);
182
- if (linked.kind === 'link' && PAGE.test(linked.name)) {
183
- const away = tab ?? globalThis.open('', '_blank');
184
- if (away === null)
185
- return BLOCKED;
186
- away.location.replace(linked.url);
187
- return STARTED;
188
- }
189
- tab?.close();
190
- if (linked.kind === 'link') {
191
- handed(linked.url, linked.name);
192
- return STARTED;
193
- }
164
+ const linked = await handedLink(path, () => ask('attachment.link', [room, path, revision]));
194
165
  if (linked.kind !== 'absent')
195
166
  return linked;
196
- const read = streamed(await ask('binaryFile.read', [room, path, revision]));
167
+ const read = streamed(await ask('attachment.read', [room, path, revision]));
197
168
  if (read.kind !== 'binary')
198
169
  return read;
199
- const copy = await blobOf(read);
200
- const url = URL.createObjectURL(copy);
201
- handed(url, path.slice(path.lastIndexOf('/') + 1));
202
- setTimeout(() => URL.revokeObjectURL(url), HANDED_COPY_MS);
203
- return STARTED;
170
+ return handedCopy(await attachmentBlob(read), path.slice(path.lastIndexOf('/') + 1));
204
171
  }
205
172
  function settled() {
206
173
  if (settling !== null)
@@ -231,12 +198,12 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
231
198
  });
232
199
  return settling;
233
200
  }
234
- const show = (room, path, revision) => ask('binaryFile.show', [room, path, revision]).then((shown) => streamed(shown));
235
- return shownBy(show, {
201
+ return {
236
202
  buildFile,
237
- rooms: () => ask('rooms', []),
203
+ rooms: () => ask('rooms', []).then(appRooms),
238
204
  query: ((query) => ask('query', [query])),
239
205
  search: (request) => ask('search', [request]),
206
+ queryHouse: (query, options) => ask('queryHouse', options === undefined ? [query] : [query, options]),
240
207
  types: (locator) => ask('types', [locator]),
241
208
  roomDraft: {
242
209
  list: () => ask('roomDraft.list', []),
@@ -263,13 +230,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
263
230
  takeOut: (conversation, message, operation) => ask('conversation.takeOut', [conversation, message, operation]),
264
231
  decide: (request, decision, operation) => ask('conversation.decide', [request, decision, operation]),
265
232
  rename: (conversation, name, operation) => ask('conversation.rename', [conversation, name, operation]),
266
- option: (conversation, option, value, operation) => ask('conversation.option', [conversation, option, value, operation]),
233
+ set: (conversation, settings, operation) => ask('conversation.set', [conversation, settings, operation]),
267
234
  retry: (conversation, message, operation) => ask('conversation.retry', [conversation, message, operation]),
268
- pins: () => ask('conversation.pins', []),
269
235
  pin: (figures) => ask('conversation.pin', [figures]),
270
- openedTurns: () => ask('conversation.openedTurns', []),
271
236
  openTurn: (conversation, turn) => ask('conversation.openTurn', [conversation, turn]),
272
237
  dismissSuggestion: (conversation, suggestion) => ask('conversation.dismissSuggestion', [conversation, suggestion]),
238
+ attach: (file) => ask('conversation.attach', [file]),
239
+ attachment: (link) => ask('conversation.attachment', [link]),
273
240
  pageMetadata: async (app, address) => pageMetadataBlock(app, address, [...observations]
274
241
  .sort(([left], [right]) => left - right)
275
242
  .flatMap(([, { topic, input }]) => (topic === 'query' ? [input[0]] : []))),
@@ -282,9 +249,10 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
282
249
  },
283
250
  history: (locator, path, query) => ask('history', [locator, path, query]),
284
251
  resolve: (room, path, destination) => ask('resolve', [room, path, destination]),
285
- binaryFile: {
286
- read: (room, path, revision) => ask('binaryFile.read', [room, path, revision]).then((read) => streamed(read)),
287
- attach: (room, file) => ask('binaryFile.attach', [room, file]),
252
+ attachment: {
253
+ read: (room, path, revision) => ask('attachment.read', [room, path, revision]).then((read) => streamed(read)),
254
+ show: (room, path, revision) => ask('attachment.show', [room, path, revision]).then((shown) => streamed(shown)),
255
+ attach: (room, file) => ask('attachment.attach', [room, file]),
288
256
  download,
289
257
  },
290
258
  call: (name, input) => ask('call', [name, input]),
@@ -294,12 +262,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
294
262
  retry: () => ask('retry', []),
295
263
  cleanUp: () => ask('cleanUp', []),
296
264
  unsent: () => ask('unsent', []),
265
+ sent: () => ask('sent', []),
297
266
  reset: () => ask('reset', []),
298
267
  readAgain: () => ask('readAgain', []),
299
268
  observe: ((topic, ...input) => watch(topic, input)),
300
269
  reauthorize: () => ask('reauthorize', []),
301
270
  settled,
302
- });
271
+ };
303
272
  }
304
273
  const turns = new WeakMap();
305
274
  export function inTurn(client, work) {
@@ -309,5 +278,7 @@ export function inTurn(client, work) {
309
278
  }
310
279
  export { chainedWindows } from './chain.js';
311
280
  export { roomDraftRevision } from './identity.js';
312
- export { defineRoomMedia, ROOM_MEDIA } from './media.js';
313
- export { unanswered } from './wire.js';
281
+ export { atAddress, importedFile } from './loaded.js';
282
+ export { defineRoomMedia, ROOM_MEDIA, viewFile } from './media.js';
283
+ export { shownModal } from './modal.js';
284
+ export { unanswered, undelivered } from './wire.js';
@@ -1,4 +1,4 @@
1
- import { type DefinitionOf, type Document, type TypedPath } from '@agentshouse/mdmodel';
1
+ import { type DefinitionOf, type Document, type ParseResult, type TypedPath, type VerifiedModel } from '@agentshouse/mdmodel';
2
2
  import type { ModelState, TypesResult } from './model.js';
3
3
  import type { AppTypedSelection } from './listing.js';
4
4
  import type { MdModelIdentity } from './adapter.js';
@@ -20,6 +20,7 @@ export type Composed = {
20
20
  readonly composition: Composition;
21
21
  readonly fingerprint: string;
22
22
  };
23
+ export declare function typesPrint(types: VerifiedModel['types']): string;
23
24
  export declare function composedOf(composition: Composition): Composed;
24
25
  type Selecting<M> = {
25
26
  readonly model: M;
@@ -42,6 +43,10 @@ export declare function definitionsIn(room: {
42
43
  export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition): Collection;
43
44
  export declare function documentsOf(collection: Collection): Generator<number, Iterable<readonly [string, Document]>, void>;
44
45
  export declare function validRoot(root: unknown): root is string;
46
+ export declare const UNTYPED = "any";
47
+ export declare function textType(read: ParseResult): string | undefined;
48
+ export declare function typeAt(composition: Composition, path: string, read: ParseResult): string | undefined;
49
+ export declare function typedText(read: ParseResult): boolean;
45
50
  export declare function available(composition: Composition): boolean;
46
51
  export {};
47
52
  //# 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,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,SAAS,EAEf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,eAAO,MAAM,QAAQ,EAAE,eAAwE,CA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AAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAIlF;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,cAAc,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAAE,EACxF,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,YAAY,CAQd;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,eAAO,MAAM,OAAO,QAAQ,CAAC;AAE7B,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAE9D;AAED,wBAAgB,MAAM,CACpB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,WAAW,GAChB,MAAM,GAAG,SAAS,CAIpB;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAEpD;AAED,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAE3D"}
@@ -1,26 +1,27 @@
1
- import { definitionAt, parse, VERSION, } from '@agentshouse/mdmodel';
1
+ import { definitionAt, folderType, parse, VERSION, } from '@agentshouse/mdmodel';
2
2
  import { beneath, normalize } from './paths.js';
3
3
  import { hashed } from './observation.js';
4
4
  import { sortedKeys } from './shared.js';
5
5
  export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
6
6
  const typesPrinted = new WeakMap();
7
- function typesPrint(model) {
8
- if (model.status === 'unavailable')
9
- return '';
10
- let print = typesPrinted.get(model.types);
7
+ export function typesPrint(types) {
8
+ let print = typesPrinted.get(types);
11
9
  if (print === undefined) {
12
- print = hashed(JSON.stringify(model.types)).toString(36);
13
- typesPrinted.set(model.types, print);
10
+ print = hashed(JSON.stringify(types)).toString(36);
11
+ typesPrinted.set(types, print);
14
12
  }
15
13
  return print;
16
14
  }
15
+ function modelPrint(model) {
16
+ return model.status === 'unavailable' ? '' : typesPrint(model.types);
17
+ }
17
18
  export function composedOf(composition) {
18
19
  const { model, selection } = composition;
19
20
  return {
20
21
  composition,
21
22
  fingerprint: JSON.stringify([
22
- typesPrint(model),
23
- selection === null ? null : [selection.roots, typesPrint(selection.model)],
23
+ modelPrint(model),
24
+ selection === null ? null : [selection.roots, modelPrint(selection.model)],
24
25
  ]),
25
26
  };
26
27
  }
@@ -73,6 +74,19 @@ export function* documentsOf(collection) {
73
74
  export function validRoot(root) {
74
75
  return typeof root === 'string' && normalize(root) === root;
75
76
  }
77
+ export const UNTYPED = 'any';
78
+ export function textType(read) {
79
+ return read.ok ? (read.document.type ?? UNTYPED) : undefined;
80
+ }
81
+ export function typeAt(composition, path, read) {
82
+ if (!read.ok || read.document.type !== undefined)
83
+ return textType(read);
84
+ const model = governing(composition, path);
85
+ return (model.status === 'unavailable' ? undefined : folderType(model, path)) ?? UNTYPED;
86
+ }
87
+ export function typedText(read) {
88
+ return (textType(read) ?? UNTYPED) !== UNTYPED;
89
+ }
76
90
  export function available(composition) {
77
91
  return composition.model.status !== 'unavailable';
78
92
  }
@@ -0,0 +1,5 @@
1
+ import type { Row, Value } from './tables.js';
2
+ export declare function text(value: Value | undefined): string;
3
+ export declare function texts(rows: readonly Row[], column: string): string[];
4
+ export declare function count(value: Value | undefined): number;
5
+ //# sourceMappingURL=column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../src/column.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE9C,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAErD;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAEpE;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAEtD"}
package/dist/column.js ADDED
@@ -0,0 +1,9 @@
1
+ export function text(value) {
2
+ return typeof value === 'string' ? value : String(value);
3
+ }
4
+ export function texts(rows, column) {
5
+ return rows.map((row) => text(row[column]));
6
+ }
7
+ export function count(value) {
8
+ return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
9
+ }
package/dist/compile.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare function within(alias: string, path: string): Fragment;
13
13
  export type QueryAnswer = QueryRows & {
14
14
  readonly more?: string;
15
15
  };
16
- export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
16
+ export declare function namedHandles(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], handles: readonly string[]): readonly string[];
17
+ export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null, follows?: readonly QueryRoom[]): QueryAnswer;
17
18
  export {};
18
19
  //# sourceMappingURL=compile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,GAAG,EAQJ,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,KAAK,EAAE,IAAI,EAAuC,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvF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,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MAAyD,CAAC;AAsBlG,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAE5D;AAufD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAkajE,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,MAAM,EAAE,CAenB;AAED,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,OAAO,GAAE,SAAS,SAAS,EAAO,GACjC,WAAW,CAUb"}
package/dist/compile.js CHANGED
@@ -1,21 +1,24 @@
1
1
  import { ARRAY_INDEX, bodied, byCodePoint, compared, cursorOf, heldKind, parse, pointerSegments, sql, } from '@agentshouse/mdmodel';
2
- import { binaryRecord } from './binary.js';
3
- import { definitionsAt } from './collection.js';
2
+ import { attachmentRecord } from './attachment.js';
3
+ import { definitionsAt, UNTYPED } from './collection.js';
4
4
  import { documentKey, pathOfKey, roomOfKey } from './rows.js';
5
+ import { ROOM_HANDLE } from './stored.js';
5
6
  import { FROM_START, MAXIMUM_WINDOW } from './windows.js';
6
- const UNTYPED = 'any';
7
7
  const { all, any, exists, fragment, grouped, joined, listed } = sql;
8
- export const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1 AND ${alias}.queried = 1`;
8
+ export const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1`;
9
9
  function located(alias) {
10
10
  return fragment(`(SELECT k.locator FROM replica_keys k WHERE k.key = ${alias}.key)`);
11
11
  }
12
- export function within(alias, path) {
13
- return fragment(`(${alias}.path = ? OR (${alias}.path >= ? AND ${alias}.path < ?))`, [
14
- path,
15
- `${path}/`,
16
- `${path}0`,
12
+ function inside(path, folder) {
13
+ return fragment(`(${path} = ? OR (${path} >= ? AND ${path} < ?))`, [
14
+ folder,
15
+ `${folder}/`,
16
+ `${folder}0`,
17
17
  ]);
18
18
  }
19
+ export function within(alias, path) {
20
+ return inside(`${alias}.path`, path);
21
+ }
19
22
  function ancestors(area) {
20
23
  const depth = area.path.split('/').length;
21
24
  return area.open.flatMap((open) => {
@@ -23,18 +26,18 @@ function ancestors(area) {
23
26
  return segments.slice(depth - 1, -1).map((_, at) => segments.slice(0, depth + at).join('/'));
24
27
  });
25
28
  }
26
- function fenced(alias, key, area, folders) {
29
+ function fenced(key, path, held, area, folders) {
27
30
  const opened = any([
28
- ...area.open.map((open) => within(alias, open)),
29
- ...(folders ? ancestors(area).map((path) => fragment(`${alias}.path = ?`, [path])) : []),
31
+ ...area.open.map((open) => inside(path, open)),
32
+ ...(folders ? ancestors(area).map((ancestor) => fragment(`${path} = ?`, [ancestor])) : []),
30
33
  ]);
31
34
  return all([
32
- fragment(`${alias}.key = ?`, [key]),
33
- within(alias, area.path),
35
+ fragment(`${key} = ?`, [held]),
36
+ inside(path, area.path),
34
37
  fragment(`NOT ${grouped(opened).sql}`, opened.bind),
35
38
  ]);
36
39
  }
37
- function reached(bound, alias) {
40
+ function reached(bound, key, path) {
38
41
  const reach = bound.reach;
39
42
  if (reach === null)
40
43
  return fragment('1');
@@ -47,49 +50,65 @@ function reached(bound, alias) {
47
50
  return key === undefined ? [] : [[key, pathOfKey(held)]];
48
51
  });
49
52
  const outside = any(reach.areas.flatMap((area) => {
50
- const key = bound.keys.get(area.room);
51
- return key === undefined ? [] : [fenced(alias, key, area, false)];
53
+ const held = bound.keys.get(area.room);
54
+ return held === undefined ? [] : [fenced(key, path, held, area, false)];
52
55
  }));
53
56
  return all([
54
57
  any([
55
- ...(rooms.length === 0 ? [] : [fragment(`${alias}.key IN ${listed(rooms).sql}`, rooms)]),
58
+ ...(rooms.length === 0 ? [] : [fragment(`${key} IN ${listed(rooms).sql}`, rooms)]),
56
59
  ...(documents.length === 0
57
60
  ? []
58
61
  : [
59
- fragment(`EXISTS (SELECT 1 FROM json_each(?) j WHERE j.value ->> 0 = ${alias}.key AND j.value ->> 1 = ${alias}.path)`, [JSON.stringify(documents)]),
62
+ fragment(`EXISTS (SELECT 1 FROM json_each(?) j WHERE j.value ->> 0 = ${key} AND j.value ->> 1 = ${path})`, [JSON.stringify(documents)]),
60
63
  ]),
61
64
  ]),
62
65
  ...(reach.areas.length === 0 ? [] : [fragment(`NOT ${grouped(outside).sql}`, outside.bind)]),
63
66
  ]);
64
67
  }
68
+ function handled(bound, link) {
69
+ return fragment(`FROM replica_rooms h WHERE ${ROOM_HANDLE('h')} = ${link}.handle AND h.key IN (SELECT value FROM json_each(?))`, [bound.follows]);
70
+ }
71
+ function followed(bound) {
72
+ return {
73
+ targets: (link, document) => {
74
+ const room = handled(bound, link);
75
+ return joined([
76
+ fragment(`replica_entries ${document} ON ${document}.key = CASE WHEN ${link}.handle IS NULL THEN d.key ELSE (SELECT h.key ${room.sql}) END AND ${document}.path = ${link}.target AND ${VISIBLE(document)} AND`, room.bind),
77
+ grouped(reached(bound, `${document}.key`, `${document}.path`)),
78
+ ], ' ');
79
+ },
80
+ unfollowed: (link) => {
81
+ const own = reached(bound, 'd.key', `${link}.target`);
82
+ const room = handled(bound, link);
83
+ const other = reached(bound, 'h.key', `${link}.target`);
84
+ return fragment(`NOT ((${link}.handle IS NULL AND ${own.sql}) OR EXISTS (SELECT 1 ${room.sql} AND ${other.sql}))`, [...own.bind, ...room.bind, ...other.bind]);
85
+ },
86
+ };
87
+ }
65
88
  function related(bound, plan) {
66
89
  const parts = [];
67
- if (plan.hop !== null) {
68
- parts.push(exists(joined([
69
- fragment(`SELECT 1 FROM replica_links l JOIN replica_entries m ON m.key = d.key AND m.path = l.target AND ${VISIBLE('m')} WHERE l.doc = d.id AND l.kind = 'field' AND`),
70
- grouped(sql.placed('l', plan.hop.field, 'link')),
71
- fragment('AND'),
72
- grouped(all([sql.scoped('m', plan.hop), reached(bound, 'm')])),
73
- ], ' ')));
74
- }
90
+ if (plan.hop !== null)
91
+ parts.push(sql.hopped('d', plan.hop, followed(bound)));
75
92
  if (plan.backlinks !== null) {
76
93
  const field = plan.backlinks.field;
77
94
  parts.push(exists(joined([
78
- fragment(`SELECT 1 FROM replica_links l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE l.key = d.key AND l.target = d.path AND l.kind = 'field' AND`),
95
+ fragment(`SELECT 1 FROM replica_links l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE l.key = d.key AND l.handle IS NULL AND l.target = d.path AND l.kind = 'field' AND`),
79
96
  ...(field === null ? [] : [grouped(sql.placed('l', field, 'link')), fragment('AND')]),
80
- grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's')])),
97
+ grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's.key', 's.path')])),
81
98
  ], ' ')));
82
99
  }
83
100
  return parts;
84
101
  }
85
- function filtered(bound, plan) {
102
+ function tested(bound, plan) {
86
103
  const keys = bound.rooms.map(({ key }) => key);
87
- return all([
104
+ return [
88
105
  fragment(`d.key IN ${listed(keys).sql} AND ${VISIBLE('d')}`, keys),
89
- reached(bound, 'd'),
106
+ reached(bound, 'd.key', 'd.path'),
90
107
  sql.tests('d', plan),
91
- ...related(bound, plan),
92
- ]);
108
+ ];
109
+ }
110
+ function filtered(bound, plan) {
111
+ return all([...tested(bound, plan), ...related(bound, plan)]);
93
112
  }
94
113
  function orderingOf(options) {
95
114
  const stringSort = options.stringSort ?? 'locale';
@@ -335,7 +354,7 @@ function documentOf(shape, queried, row, linked) {
335
354
  ...(binary === null
336
355
  ? {}
337
356
  : {
338
- binaryFile: binaryRecord(path, binary, revision ?? undefined),
357
+ attachment: attachmentRecord(path, binary, revision ?? undefined),
339
358
  }),
340
359
  ...(shape.markdown && content !== null ? { markdown: content } : {}),
341
360
  ...(shape.change ? { change: changeOf(row) } : {}),
@@ -389,10 +408,10 @@ function backlinksOf(connection, bound, rows) {
389
408
  held.push(row.path);
390
409
  byKey.set(key, held);
391
410
  }
392
- const reach = reached(bound, 's');
411
+ const reach = reached(bound, 's.key', 's.path');
393
412
  for (const [key, targets] of byKey) {
394
413
  const room = bound.rooms.find((one) => one.key === key).locator;
395
- const found = connection.rows(`SELECT target, path, type, field FROM (SELECT l.target, s.path, s.type, l.field, ROW_NUMBER() OVER (PARTITION BY l.target ORDER BY s.path, l.field) AS rank FROM (SELECT DISTINCT doc, target, field FROM replica_links WHERE key = ? AND kind = 'field' AND target IN (SELECT value FROM json_each(?))) l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE ${reach.sql}) WHERE rank <= ? ORDER BY target, path, field`, [key, JSON.stringify(targets), ...reach.bind, MAXIMUM_WINDOW]);
414
+ const found = connection.rows(`SELECT target, path, type, field FROM (SELECT l.target, s.path, s.type, l.field, ROW_NUMBER() OVER (PARTITION BY l.target ORDER BY s.path, l.field) AS rank FROM (SELECT DISTINCT doc, target, field FROM replica_links WHERE key = ? AND kind = 'field' AND handle IS NULL AND target IN (SELECT value FROM json_each(?))) l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE ${reach.sql}) WHERE rank <= ? ORDER BY target, path, field`, [key, JSON.stringify(targets), ...reach.bind, MAXIMUM_WINDOW]);
396
415
  for (const row of found) {
397
416
  const at = documentKey(room, row.target);
398
417
  const held = linked.get(at) ?? [];
@@ -507,7 +526,7 @@ function storedFolders(bound, plan, subfolder) {
507
526
  const key = bound.keys.get(area.room);
508
527
  if (key === undefined)
509
528
  return [];
510
- const fence = fenced('f', key, area, true);
529
+ const fence = fenced('f.key', 'f.path', key, area, true);
511
530
  return [fragment(`NOT ${grouped(fence).sql}`, fence.bind)];
512
531
  });
513
532
  const under = prefix === ''
@@ -703,16 +722,28 @@ function groups(connection, bound, plan, shape) {
703
722
  ...(total === undefined ? {} : { total }),
704
723
  };
705
724
  }
706
- function boundOf(connection, plan, rooms) {
725
+ function boundOf(connection, plan, rooms, follows) {
707
726
  return {
708
727
  rooms: [...rooms].sort((left, right) => left.locator < right.locator ? -1 : left.locator > right.locator ? 1 : 0),
709
- keys: new Map(rooms.map(({ locator, key }) => [locator, key])),
728
+ keys: new Map([...rooms, ...follows].map(({ locator, key }) => [locator, key])),
729
+ follows: JSON.stringify(follows.map(({ key }) => key)),
710
730
  reach: plan.reach,
711
731
  collate: collating(connection),
712
732
  };
713
733
  }
714
- export function answerQuery(connection, plan, rooms, budget = null) {
715
- const bound = boundOf(connection, plan, rooms);
734
+ export function namedHandles(connection, plan, rooms, handles) {
735
+ if (plan.hop === null)
736
+ return [];
737
+ const statement = joined([
738
+ fragment("SELECT DISTINCT l.handle FROM replica_entries d JOIN replica_links l ON l.doc = d.id AND l.kind = 'field' AND l.handle IN (SELECT value FROM json_each(?)) AND ", [JSON.stringify(handles)]),
739
+ grouped(sql.placed('l', plan.hop.field, 'link')),
740
+ fragment(' WHERE '),
741
+ all(tested(boundOf(connection, plan, rooms, []), plan)),
742
+ ], '');
743
+ return connection.rows(statement.sql, statement.bind).map((row) => row.handle);
744
+ }
745
+ export function answerQuery(connection, plan, rooms, budget = null, follows = []) {
746
+ const bound = boundOf(connection, plan, rooms, follows);
716
747
  if (rooms.length === 0) {
717
748
  return plan.shape.kind === 'groups'
718
749
  ? { groups: [], ...(plan.total ? { total: 0 } : {}) }
@@ -10,8 +10,8 @@ export type MdRuntimeOptions = {
10
10
  authorization?: Authorization;
11
11
  signal?: AbortSignal;
12
12
  recovery?: Recovery;
13
- usableWhenHeld?: readonly string[];
14
13
  build?: string;
14
+ storeOnNeed?: boolean;
15
15
  };
16
16
  export declare function composeRuntime(options: MdRuntimeOptions): ComposedRuntime;
17
17
  //# sourceMappingURL=connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAI/E,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAUrE,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAK9D,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,eAAe,CAAC;IAC1B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAIF,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAoGzE"}
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAsC,MAAM,cAAc,CAAC;AAI/F,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAUrE,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAK9D,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAOrE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,eAAe,CAAC;IAC1B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAIF,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CA6GzE"}
@@ -1,3 +1,4 @@
1
+ import { notReadyWaitMs } from '@agentshouse/mdmodel';
1
2
  import { submitLater } from './acceptance.js';
2
3
  import { invokeAction, called, readConversationHistory, resendLater } from './actions.js';
3
4
  import { builtInModel, NO_ROOM_TYPES } from './attached-model.js';
@@ -19,6 +20,10 @@ import { publishChangeSet, show } from './shown.js';
19
20
  import { createSocket } from './socket.js';
20
21
  import { createStore } from './store.js';
21
22
  import { composedRuntime } from './surface.js';
23
+ import { adopt, discover } from './sync.js';
24
+ function writable(room) {
25
+ return room !== undefined && room.operations.write.length > 0;
26
+ }
22
27
  const ROOM_ATTEMPTS = 16;
23
28
  export function composeRuntime(options) {
24
29
  const { adapter, shell } = options;
@@ -27,7 +32,7 @@ export function composeRuntime(options) {
27
32
  const typedPaths = adapter.typedPaths ?? [];
28
33
  const retries = createRetries(shell);
29
34
  const socket = createSocket(adapter, retries, options.authorization);
30
- const presence = createPresence();
35
+ const presence = createPresence(notReadyWaitMs);
31
36
  const store = createStore({
32
37
  retries,
33
38
  database: {
@@ -47,6 +52,7 @@ export function composeRuntime(options) {
47
52
  typedPaths,
48
53
  persistence: shell.persistence,
49
54
  lost: presence.lost,
55
+ losing: presence.losing,
50
56
  opening: (local) => open(runtime, local),
51
57
  unpublished: uncaught,
52
58
  changed(set) {
@@ -56,7 +62,7 @@ export function composeRuntime(options) {
56
62
  submitLater(runtime, locator);
57
63
  return publishChangeSet(runtime, set);
58
64
  },
59
- deliverReadiness: (owed) => deliverOwedReadiness(runtime, owed),
65
+ deliverReadiness: (owed, rooms) => deliverOwedReadiness(runtime, owed, rooms),
60
66
  spaceFreed: () => spaceFreed(runtime),
61
67
  });
62
68
  const recovery = (options.recovery ?? createRecovery()).scope(ROOM_ATTEMPTS);
@@ -67,12 +73,14 @@ export function composeRuntime(options) {
67
73
  recovery,
68
74
  retries,
69
75
  shell,
70
- localSaves: adapter.localSaves === true,
76
+ savesLocally: (locator) => adapter.localSaves === true && !writable(presence.room(locator)),
71
77
  roomTypes,
72
78
  builtIn,
73
79
  typedPaths,
74
- writeRule: (declaration) => writeRule(declaration, adapter.pathRule ?? (() => true), adapter.localSaves === true),
75
- usableWhenHeld: options.usableWhenHeld ?? [],
80
+ renamedActions: adapter.renamedActions ?? new Map(),
81
+ rewrittenInputs: adapter.rewrittenInputs ?? new Map(),
82
+ keptInput: adapter.keptInput ?? ((input) => input),
83
+ writeRule: (declaration) => writeRule(declaration, adapter.pathRule ?? (() => true), adapter.localSaves === true && !writable(declaration)),
76
84
  build: options.build ?? '',
77
85
  conversations: createLiveConversations({
78
86
  call: (name, input, attempt) => invokeAction(runtime, name, input, { attempt }),
@@ -115,7 +123,9 @@ export function composeRuntime(options) {
115
123
  full: store.space.full,
116
124
  filled: () => filled(runtime),
117
125
  }),
126
+ discover: () => discover(runtime),
127
+ adopt: (unstored) => adopt(runtime, unstored),
118
128
  };
119
- start(runtime, options.signal);
129
+ start(runtime, options.signal, options.storeOnNeed === true);
120
130
  return composedRuntime(runtime);
121
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIpD"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKpD"}
package/dist/context.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function contextFigure(tokens) {
2
- if (tokens >= 1_000_000)
2
+ if (Math.round(tokens / 1_000) >= 1_000)
3
3
  return `${(tokens / 1_000_000).toFixed(1).replace(/\.0$/, '')}M`;
4
4
  if (tokens >= 1_000)
5
5
  return `${Math.round(tokens / 1_000)}k`;