@agentshouse/mdruntime 0.1.0-cd9e28a590f84 → 0.1.0-cdded6c080913

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 (260) hide show
  1. package/README.md +1 -1
  2. package/dist/acceptance.d.ts +6 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +389 -0
  5. package/dist/actions.d.ts +20 -0
  6. package/dist/actions.d.ts.map +1 -0
  7. package/dist/actions.js +250 -0
  8. package/dist/adapter.d.ts +23 -25
  9. package/dist/adapter.d.ts.map +1 -1
  10. package/dist/attached-model.d.ts +3 -10
  11. package/dist/attached-model.d.ts.map +1 -1
  12. package/dist/attached-model.js +21 -56
  13. package/dist/bootstrap.d.ts +8 -4
  14. package/dist/bootstrap.d.ts.map +1 -1
  15. package/dist/bootstrap.js +209 -78
  16. package/dist/cell.d.ts +6 -0
  17. package/dist/cell.d.ts.map +1 -0
  18. package/dist/cell.js +9 -0
  19. package/dist/chain.d.ts +2 -1
  20. package/dist/chain.d.ts.map +1 -1
  21. package/dist/change.d.ts +1 -0
  22. package/dist/change.d.ts.map +1 -1
  23. package/dist/chat-types.d.ts +5 -0
  24. package/dist/chat-types.d.ts.map +1 -0
  25. package/dist/chat-types.js +13 -0
  26. package/dist/client.d.ts +17 -2
  27. package/dist/client.d.ts.map +1 -1
  28. package/dist/client.js +3 -0
  29. package/dist/collection.d.ts +2 -1
  30. package/dist/collection.d.ts.map +1 -1
  31. package/dist/compile.d.ts +7 -7
  32. package/dist/compile.d.ts.map +1 -1
  33. package/dist/compile.js +229 -301
  34. package/dist/connection.d.ts +5 -141
  35. package/dist/connection.d.ts.map +1 -1
  36. package/dist/connection.js +98 -5279
  37. package/dist/context.d.ts +2 -0
  38. package/dist/context.d.ts.map +1 -0
  39. package/dist/context.js +7 -0
  40. package/dist/conversation-row.d.ts +33 -0
  41. package/dist/conversation-row.d.ts.map +1 -0
  42. package/dist/conversation-row.js +53 -0
  43. package/dist/conversation.d.ts +16 -6
  44. package/dist/conversation.d.ts.map +1 -1
  45. package/dist/conversation.js +366 -216
  46. package/dist/discovery.d.ts +10 -0
  47. package/dist/discovery.d.ts.map +1 -0
  48. package/dist/discovery.js +175 -0
  49. package/dist/durability.d.ts +15 -0
  50. package/dist/durability.d.ts.map +1 -1
  51. package/dist/entry.d.ts +2 -2
  52. package/dist/entry.d.ts.map +1 -1
  53. package/dist/entry.js +17 -8
  54. package/dist/figures.d.ts +48 -0
  55. package/dist/figures.d.ts.map +1 -0
  56. package/dist/figures.js +197 -0
  57. package/dist/holdings.d.ts +29 -0
  58. package/dist/holdings.d.ts.map +1 -0
  59. package/dist/holdings.js +95 -0
  60. package/dist/host.d.ts +2 -2
  61. package/dist/host.d.ts.map +1 -1
  62. package/dist/host.js +22 -15
  63. package/dist/identity.d.ts +0 -1
  64. package/dist/identity.d.ts.map +1 -1
  65. package/dist/identity.js +0 -3
  66. package/dist/index.d.ts +19 -4
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +4 -0
  69. package/dist/install.d.ts +56 -0
  70. package/dist/install.d.ts.map +1 -0
  71. package/dist/install.js +560 -0
  72. package/dist/job.d.ts +33 -0
  73. package/dist/job.d.ts.map +1 -0
  74. package/dist/job.js +54 -0
  75. package/dist/lifecycle.d.ts +7 -0
  76. package/dist/lifecycle.d.ts.map +1 -0
  77. package/dist/lifecycle.js +267 -0
  78. package/dist/listing.d.ts +53 -0
  79. package/dist/listing.d.ts.map +1 -0
  80. package/dist/listing.js +175 -0
  81. package/dist/live.d.ts +5 -4
  82. package/dist/live.d.ts.map +1 -1
  83. package/dist/live.js +62 -20
  84. package/dist/locks.d.ts +9 -0
  85. package/dist/locks.d.ts.map +1 -0
  86. package/dist/locks.js +61 -0
  87. package/dist/log.d.ts +1 -0
  88. package/dist/log.d.ts.map +1 -1
  89. package/dist/lost.d.ts +5 -0
  90. package/dist/lost.d.ts.map +1 -0
  91. package/dist/lost.js +61 -0
  92. package/dist/memory.d.ts +4 -1
  93. package/dist/memory.d.ts.map +1 -1
  94. package/dist/memory.js +43 -4
  95. package/dist/messages.d.ts +25 -1
  96. package/dist/messages.d.ts.map +1 -1
  97. package/dist/messages.js +84 -5
  98. package/dist/model.d.ts +2 -9
  99. package/dist/model.d.ts.map +1 -1
  100. package/dist/model.js +0 -9
  101. package/dist/models.d.ts +14 -0
  102. package/dist/models.d.ts.map +1 -0
  103. package/dist/models.js +193 -0
  104. package/dist/observation.d.ts +2 -2
  105. package/dist/observation.d.ts.map +1 -1
  106. package/dist/observation.js +7 -2
  107. package/dist/opening.d.ts +4 -0
  108. package/dist/opening.d.ts.map +1 -0
  109. package/dist/opening.js +56 -0
  110. package/dist/outcome.d.ts +4 -1
  111. package/dist/outcome.d.ts.map +1 -1
  112. package/dist/outcome.js +3 -0
  113. package/dist/overlay.d.ts +1 -0
  114. package/dist/overlay.d.ts.map +1 -1
  115. package/dist/overlay.js +11 -0
  116. package/dist/parts.d.ts +59 -0
  117. package/dist/parts.d.ts.map +1 -0
  118. package/dist/parts.js +118 -0
  119. package/dist/preparation.d.ts +20 -0
  120. package/dist/preparation.d.ts.map +1 -0
  121. package/dist/preparation.js +226 -0
  122. package/dist/queries.d.ts +16 -0
  123. package/dist/queries.d.ts.map +1 -0
  124. package/dist/queries.js +272 -0
  125. package/dist/query.d.ts +13 -212
  126. package/dist/query.d.ts.map +1 -1
  127. package/dist/query.js +3 -524
  128. package/dist/questions.d.ts +34 -0
  129. package/dist/questions.d.ts.map +1 -0
  130. package/dist/questions.js +122 -0
  131. package/dist/reach.d.ts +12 -10
  132. package/dist/reach.d.ts.map +1 -1
  133. package/dist/reach.js +165 -109
  134. package/dist/react.d.ts +9 -2
  135. package/dist/react.d.ts.map +1 -1
  136. package/dist/read.d.ts +7 -0
  137. package/dist/read.d.ts.map +1 -0
  138. package/dist/read.js +17 -0
  139. package/dist/reads.d.ts +36 -0
  140. package/dist/reads.d.ts.map +1 -0
  141. package/dist/reads.js +150 -0
  142. package/dist/recovery.d.ts.map +1 -1
  143. package/dist/recovery.js +9 -1
  144. package/dist/refresh.d.ts +1 -1
  145. package/dist/refresh.d.ts.map +1 -1
  146. package/dist/refresh.js +8 -20
  147. package/dist/refusal.d.ts +5 -0
  148. package/dist/refusal.d.ts.map +1 -0
  149. package/dist/refusal.js +56 -0
  150. package/dist/replica.d.ts +8 -8
  151. package/dist/replica.d.ts.map +1 -1
  152. package/dist/replica.js +50 -18
  153. package/dist/room-draft.d.ts +2 -2
  154. package/dist/room-draft.d.ts.map +1 -1
  155. package/dist/room-drafts.d.ts +24 -0
  156. package/dist/room-drafts.d.ts.map +1 -0
  157. package/dist/room-drafts.js +216 -0
  158. package/dist/rows.d.ts +14 -22
  159. package/dist/rows.d.ts.map +1 -1
  160. package/dist/rows.js +48 -189
  161. package/dist/runtime.d.ts +42 -0
  162. package/dist/runtime.d.ts.map +1 -0
  163. package/dist/runtime.js +1 -0
  164. package/dist/save.d.ts.map +1 -1
  165. package/dist/save.js +11 -8
  166. package/dist/saves.d.ts +70 -0
  167. package/dist/saves.d.ts.map +1 -0
  168. package/dist/saves.js +1004 -0
  169. package/dist/search.d.ts.map +1 -1
  170. package/dist/search.js +1 -1
  171. package/dist/seed.d.ts +11 -2
  172. package/dist/seed.d.ts.map +1 -1
  173. package/dist/seed.js +71 -0
  174. package/dist/shown.d.ts +31 -0
  175. package/dist/shown.d.ts.map +1 -0
  176. package/dist/shown.js +294 -0
  177. package/dist/socket/admission.d.ts +7 -0
  178. package/dist/socket/admission.d.ts.map +1 -0
  179. package/dist/socket/admission.js +39 -0
  180. package/dist/socket/answers.d.ts +6 -0
  181. package/dist/socket/answers.d.ts.map +1 -0
  182. package/dist/socket/answers.js +20 -0
  183. package/dist/socket/lanes.d.ts +20 -0
  184. package/dist/socket/lanes.d.ts.map +1 -0
  185. package/dist/socket/lanes.js +77 -0
  186. package/dist/socket/reads.d.ts +10 -0
  187. package/dist/socket/reads.d.ts.map +1 -0
  188. package/dist/socket/reads.js +31 -0
  189. package/dist/socket/rooms.d.ts +43 -0
  190. package/dist/socket/rooms.d.ts.map +1 -0
  191. package/dist/socket/rooms.js +90 -0
  192. package/dist/socket/session.d.ts +39 -0
  193. package/dist/socket/session.d.ts.map +1 -0
  194. package/dist/socket/session.js +23 -0
  195. package/dist/socket.d.ts +70 -0
  196. package/dist/socket.d.ts.map +1 -0
  197. package/dist/socket.js +175 -0
  198. package/dist/source.d.ts +61 -0
  199. package/dist/source.d.ts.map +1 -0
  200. package/dist/source.js +81 -0
  201. package/dist/status.d.ts +0 -2
  202. package/dist/status.d.ts.map +1 -1
  203. package/dist/status.js +0 -6
  204. package/dist/store/fences.d.ts +16 -0
  205. package/dist/store/fences.d.ts.map +1 -0
  206. package/dist/store/fences.js +26 -0
  207. package/dist/store/installs.d.ts +30 -0
  208. package/dist/store/installs.d.ts.map +1 -0
  209. package/dist/store/installs.js +34 -0
  210. package/dist/store/readiness.d.ts +10 -0
  211. package/dist/store/readiness.d.ts.map +1 -0
  212. package/dist/store/readiness.js +52 -0
  213. package/dist/store/records.d.ts +212 -0
  214. package/dist/store/records.d.ts.map +1 -0
  215. package/dist/store/records.js +408 -0
  216. package/dist/store/room-held.d.ts +8 -0
  217. package/dist/store/room-held.d.ts.map +1 -0
  218. package/dist/store/room-held.js +17 -0
  219. package/dist/store/space.d.ts +11 -0
  220. package/dist/store/space.d.ts.map +1 -0
  221. package/dist/store/space.js +43 -0
  222. package/dist/store/watchers.d.ts +17 -0
  223. package/dist/store/watchers.d.ts.map +1 -0
  224. package/dist/store/watchers.js +57 -0
  225. package/dist/store/writes.d.ts +24 -0
  226. package/dist/store/writes.d.ts.map +1 -0
  227. package/dist/store/writes.js +125 -0
  228. package/dist/store.d.ts +107 -153
  229. package/dist/store.d.ts.map +1 -1
  230. package/dist/store.js +143 -396
  231. package/dist/stored.d.ts +58 -64
  232. package/dist/stored.d.ts.map +1 -1
  233. package/dist/stored.js +244 -156
  234. package/dist/surface.d.ts +88 -0
  235. package/dist/surface.d.ts.map +1 -0
  236. package/dist/surface.js +222 -0
  237. package/dist/sync.d.ts +20 -0
  238. package/dist/sync.d.ts.map +1 -0
  239. package/dist/sync.js +531 -0
  240. package/dist/tables.d.ts +110 -48
  241. package/dist/tables.d.ts.map +1 -1
  242. package/dist/tables.js +209 -54
  243. package/dist/tallies.d.ts +18 -0
  244. package/dist/tallies.d.ts.map +1 -0
  245. package/dist/tallies.js +129 -0
  246. package/dist/validation.d.ts.map +1 -1
  247. package/dist/validation.js +7 -4
  248. package/dist/windows.d.ts +1 -12
  249. package/dist/windows.d.ts.map +1 -1
  250. package/dist/windows.js +2 -75
  251. package/dist/wire.d.ts +16 -1
  252. package/dist/wire.d.ts.map +1 -1
  253. package/dist/wire.js +6 -0
  254. package/package.json +2 -2
  255. package/dist/fence.d.ts +0 -6
  256. package/dist/fence.d.ts.map +0 -1
  257. package/dist/fence.js +0 -10
  258. package/dist/phrase.d.ts +0 -3
  259. package/dist/phrase.d.ts.map +0 -1
  260. package/dist/phrase.js +0 -8
@@ -0,0 +1,9 @@
1
+ import type { DiscoveredRoom } from './adapter.js';
2
+ import type { Runtime } from './runtime.js';
3
+ export declare function locked({ store, socket }: Runtime, locator: string): Promise<boolean>;
4
+ export declare function lockedRooms(runtime: Runtime): Promise<readonly string[]>;
5
+ export declare function relocked(runtime: Runtime, before: readonly string[]): Promise<void>;
6
+ export declare function confirmLocks({ socket }: Runtime, listed: readonly DiscoveredRoom[]): void;
7
+ export declare function connectionLost(runtime: Runtime): void;
8
+ export declare function watchLocks({ store }: Runtime, notify: () => void): () => void;
9
+ //# sourceMappingURL=locks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../src/locks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAa5C,wBAAsB,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAK1F;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAW9E;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,iBAMzE;AAED,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,cAAc,EAAE,QAOlF;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAa9C;AAED,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAE7E"}
package/dist/locks.js ADDED
@@ -0,0 +1,61 @@
1
+ import { emitRooms, LOCKS_TOPIC } from './shown.js';
2
+ async function offlineModes({ store, socket }) {
3
+ const modes = new Map();
4
+ for (const [locator, { room }] of socket.rooms.declarations()) {
5
+ const declaration = room ?? socket.rooms.discovered(locator);
6
+ if (declaration !== undefined)
7
+ modes.set(locator, declaration.replica.offline);
8
+ }
9
+ for (const [locator, { offline }] of (await store.covering()).rooms)
10
+ modes.set(locator, offline);
11
+ return modes;
12
+ }
13
+ export async function locked({ store, socket }, locator) {
14
+ if (store.fences.has(locator) || socket.rooms.standing(locator).confirmed)
15
+ return false;
16
+ const held = socket.rooms.declared(locator)?.room ?? socket.rooms.discovered(locator);
17
+ const mode = (await (await store.open()).offline(locator)) ?? held?.replica.offline;
18
+ return mode === 'locked';
19
+ }
20
+ export async function lockedRooms(runtime) {
21
+ const { store, socket } = runtime;
22
+ return [...(await offlineModes(runtime))]
23
+ .filter(([locator, mode]) => mode === 'locked' &&
24
+ !socket.rooms.standing(locator).confirmed &&
25
+ !store.fences.has(locator))
26
+ .map(([locator]) => locator)
27
+ .sort();
28
+ }
29
+ export async function relocked(runtime, before) {
30
+ const after = await lockedRooms(runtime);
31
+ if (JSON.stringify(after) === JSON.stringify(before))
32
+ return;
33
+ runtime.journal.record(`locked ${after.length}`);
34
+ emitRooms(runtime);
35
+ runtime.store.tell(LOCKS_TOPIC, undefined);
36
+ }
37
+ export function confirmLocks({ socket }, listed) {
38
+ if (!socket.isOpen())
39
+ return;
40
+ for (const room of listed) {
41
+ if (room.replica.admission === 'admitted') {
42
+ socket.rooms.stand(room.locator, { confirmed: true });
43
+ }
44
+ }
45
+ }
46
+ export function connectionLost(runtime) {
47
+ const { socket } = runtime;
48
+ if (socket.closed())
49
+ return;
50
+ socket.rooms.connectionLost(() => {
51
+ if (socket.isOpen() || socket.closed())
52
+ return;
53
+ void lockedRooms(runtime).then((before) => {
54
+ socket.rooms.standAll({ confirmed: false });
55
+ return relocked(runtime, before);
56
+ }, () => { });
57
+ });
58
+ }
59
+ export function watchLocks({ store }, notify) {
60
+ return store.watch(LOCKS_TOPIC, notify).stop;
61
+ }
package/dist/log.d.ts CHANGED
@@ -2,4 +2,5 @@ export declare function createLog(): {
2
2
  record(event: string): void;
3
3
  export(): string;
4
4
  };
5
+ export type Log = ReturnType<typeof createLog>;
5
6
  //# sourceMappingURL=log.d.ts.map
package/dist/log.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS;IAGrB,MAAM,QAAQ,MAAM;IAIpB,MAAM;EAIT"}
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS;IAGrB,MAAM,QAAQ,MAAM;IAIpB,MAAM;EAIT;AAED,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}
package/dist/lost.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { Runtime } from './runtime.js';
2
+ export declare function eraseFenced({ store }: Runtime, locators: readonly string[]): Promise<void>;
3
+ export declare function fenceLive(runtime: Runtime, locators: readonly string[]): void;
4
+ export declare function loseRooms(runtime: Runtime, locators: readonly string[]): Promise<void>;
5
+ //# sourceMappingURL=lost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lost.d.ts","sourceRoot":"","sources":["../src/lost.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAU5C,wBAAsB,WAAW,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,iBAIhF;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,QAOtE;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,iBAqC5E"}
package/dist/lost.js ADDED
@@ -0,0 +1,61 @@
1
+ import { changeSet, mergeChangeSets } from './change-set.js';
2
+ import { ERASE_BATCH, forgetInstall } from './install.js';
3
+ import { recoverReads, statusShown } from './shown.js';
4
+ import { yielded } from './turn.js';
5
+ function forget({ store, socket }, locator) {
6
+ forgetInstall(store, locator);
7
+ socket.rooms.forget(locator);
8
+ store.forget(locator);
9
+ }
10
+ export async function eraseFenced({ store }, locators) {
11
+ for (const locator of locators) {
12
+ while (await store.durably((local) => local.erase(locator, ERASE_BATCH)))
13
+ await yielded();
14
+ }
15
+ }
16
+ export function fenceLive(runtime, locators) {
17
+ const { store, socket, journal } = runtime;
18
+ for (const locator of new Set(locators)) {
19
+ if (!store.fences.raise(locator, socket.session.now().discoveries))
20
+ continue;
21
+ forget(runtime, locator);
22
+ journal.record(`room lost ${locator}`);
23
+ }
24
+ }
25
+ export async function loseRooms(runtime, locators) {
26
+ const { store } = runtime;
27
+ fenceLive(runtime, locators);
28
+ const fresh = [...new Set(locators)].filter((locator) => {
29
+ const fence = store.fences.of(locator);
30
+ if (fence === undefined || fence.written)
31
+ return false;
32
+ store.fences.mark(locator, true);
33
+ return true;
34
+ });
35
+ if (fresh.length === 0)
36
+ return;
37
+ let held = [];
38
+ try {
39
+ await store.durably(async (local) => {
40
+ held = await local.roomDrafts();
41
+ await local.fence(fresh);
42
+ });
43
+ }
44
+ catch (error) {
45
+ for (const locator of fresh)
46
+ store.fences.mark(locator, false);
47
+ throw error;
48
+ }
49
+ finally {
50
+ store.changed(mergeChangeSets(fresh.map((locator) => changeSet(locator, {
51
+ documents: null,
52
+ room: true,
53
+ queue: true,
54
+ drafts: held.filter((draft) => draft.locator === locator).map(({ path }) => path),
55
+ }))));
56
+ recoverReads(runtime);
57
+ statusShown(runtime);
58
+ }
59
+ await store.durably((local) => runtime.unpair(local));
60
+ await eraseFenced(runtime, fresh);
61
+ }
package/dist/memory.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import type { ModelResult } from './model.js';
2
- import { type AcceptedMessage, type ActionResult, type Adapter, type BinaryFile, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type HeadChange, type ListedAgent, type ListedConversation, type Member, type ProviderLimit, type Retention, type ServiceMode } from './adapter.js';
2
+ import { type AcceptedMessage, type ActionResult, type Adapter, type BinaryFile, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type SavedFacts, type HeadChange, type ListedAgent, type ListedConversation, type Member, type ProviderLimit, type Retention, type ServiceMode, type TypedPath } from './adapter.js';
3
3
  export type MemoryRoom = DiscoveredRoom & {
4
4
  model?: ModelResult;
5
5
  documents?: Readonly<Record<string, string>>;
6
+ facts?: Readonly<Record<string, SavedFacts>>;
6
7
  revisions?: Readonly<Record<string, string>>;
7
8
  fileIds?: Readonly<Record<string, string>>;
9
+ created?: Readonly<Record<string, string>>;
8
10
  changes?: Readonly<Record<string, HeadChange>>;
9
11
  binaryFiles?: Readonly<Record<string, BinaryFile>>;
10
12
  folders?: readonly string[];
@@ -28,6 +30,7 @@ export type MemoryAdapterOptions = {
28
30
  member?: Member;
29
31
  unopened?: boolean;
30
32
  roomTypes?: string;
33
+ typedPaths?: readonly TypedPath[];
31
34
  };
32
35
  export type MemoryAdapter = Adapter & {
33
36
  discover: NonNullable<Adapter['discover']>;
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,YAAY,EACjB,KAAK,OAAO,EAIZ,KAAK,UAAU,EAMf,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAKtB,KAAK,cAAc,EACnB,KAAK,UAAU,EAGf,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,MAAM,EAGX,KAAK,aAAa,EAIlB,KAAK,SAAS,EAGd,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAwBtB,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG;IACxC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7C,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAC/C,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,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,CAAC,YAAY,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAChF,sBAAsB,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3D,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnD,iBAAiB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C,SAAS,IAAI,SAAS,MAAM,EAAE,CAAC;IAC/B,uBAAuB,IAAI,SAAS,MAAM,EAAE,CAAC;IAC7C,sBAAsB,IAAI,MAAM,GAAG,IAAI,CAAC;CACzC,CAAC;AA0CF,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CAgpBrF"}
package/dist/memory.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { documentFacts, parse } from '@agentshouse/mdmodel';
2
+ import { NO_ROOM_TYPES, schemaTypes } from './attached-model.js';
1
3
  import { sameChange } from './overlay.js';
2
4
  const ATTACHMENTS = 'attachments';
3
5
  function lastName(path) {
@@ -5,7 +7,6 @@ function lastName(path) {
5
7
  }
6
8
  const FIXTURE_RETENTION = {
7
9
  history: { kind: 'duration', seconds: 1 },
8
- outcome: 604_800,
9
10
  refreshHorizon: 1,
10
11
  };
11
12
  function declaredRetention(value) {
@@ -102,8 +103,35 @@ export function createMemoryAdapter(options = {}) {
102
103
  return path;
103
104
  }
104
105
  }
106
+ const saved = new WeakMap();
107
+ function factsAt(room, path, content) {
108
+ const types = schemaTypes(room.model?.kind === 'model' ? room.model.snapshot.schema : null, NO_ROOM_TYPES);
109
+ let held = saved.get(types);
110
+ if (held === undefined) {
111
+ held = new Map();
112
+ saved.set(types, held);
113
+ }
114
+ const key = `${path}\u0000${content}`;
115
+ if (!held.has(key)) {
116
+ const facts = documentFacts(path, parse(content, path), { types });
117
+ held.set(key, facts === null ? null : JSON.parse(JSON.stringify(facts)));
118
+ }
119
+ return held.get(key);
120
+ }
121
+ function factsIn(room, paths) {
122
+ const facts = {};
123
+ for (const path of paths) {
124
+ const content = room.documents?.[path];
125
+ const held = room.facts?.[path] ?? (content === undefined ? null : factsAt(room, path, content));
126
+ if (held !== null)
127
+ facts[path] = held;
128
+ }
129
+ return facts;
130
+ }
105
131
  function retain(entries) {
106
132
  for (const room of entries) {
133
+ for (const [path, content] of Object.entries(room.documents ?? {}))
134
+ factsAt(room, path, content);
107
135
  note(room.locator, room);
108
136
  const versions = served.get(room.locator) ?? new Map();
109
137
  versions.set(room.roomVersion, room);
@@ -136,10 +164,14 @@ export function createMemoryAdapter(options = {}) {
136
164
  roomVersion: room.roomVersion,
137
165
  ...(opening ? { models: modelsOf(room) } : {}),
138
166
  documents: named(room.documents ?? {}, taken),
167
+ facts: factsIn(room, taken),
139
168
  revisions: named(room.revisions ?? {}, [...taken, ...targets]),
140
169
  ...(room.fileIds === undefined
141
170
  ? {}
142
171
  : { fileIds: named(room.fileIds, [...taken, ...targets]) }),
172
+ ...(room.created === undefined
173
+ ? {}
174
+ : { created: named(room.created, [...taken, ...targets]) }),
143
175
  changes: named(room.changes ?? {}, [...taken, ...targets]),
144
176
  binaryFiles: named(room.binaryFiles ?? {}, targets),
145
177
  ...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
@@ -163,6 +195,7 @@ export function createMemoryAdapter(options = {}) {
163
195
  const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
164
196
  const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
165
197
  room.fileIds?.[path] !== from.fileIds?.[path] ||
198
+ room.created?.[path] !== from.created?.[path] ||
166
199
  !sameChange(room.changes?.[path], from.changes?.[path]);
167
200
  const changed = Object.keys(current)
168
201
  .filter((path) => current[path] !== previous[path] || headMoved(path))
@@ -183,10 +216,14 @@ export function createMemoryAdapter(options = {}) {
183
216
  roomVersion: room.roomVersion,
184
217
  ...(models === undefined ? {} : { models }),
185
218
  documents: named(current, taken),
219
+ facts: factsIn(room, taken),
186
220
  revisions: named(room.revisions ?? {}, [...taken, ...targets]),
187
221
  ...(room.fileIds === undefined
188
222
  ? {}
189
223
  : { fileIds: named(room.fileIds, [...taken, ...targets]) }),
224
+ ...(room.created === undefined
225
+ ? {}
226
+ : { created: named(room.created, [...taken, ...targets]) }),
190
227
  changes: named(room.changes ?? {}, [...taken, ...targets]),
191
228
  binaryFiles: named(room.binaryFiles ?? {}, targets),
192
229
  ...(opening ? foldersMoved(room, from) : {}),
@@ -337,6 +374,7 @@ export function createMemoryAdapter(options = {}) {
337
374
  }
338
375
  return {
339
376
  ...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
377
+ ...(options.typedPaths === undefined ? {} : { typedPaths: options.typedPaths }),
340
378
  setRooms(next) {
341
379
  rooms = [...next];
342
380
  retain(rooms);
@@ -423,9 +461,10 @@ export function createMemoryAdapter(options = {}) {
423
461
  const named = asked.map((room) => room.locator);
424
462
  const unknown = asked.flatMap((room) => {
425
463
  const current = rooms.find((entry) => entry.locator === room.locator);
464
+ const version = room.roomVersion;
426
465
  return current === undefined ||
427
- current.roomVersion === room.roomVersion ||
428
- served.get(room.locator)?.has(room.roomVersion) === true
466
+ (version !== null &&
467
+ (current.roomVersion === version || served.get(room.locator)?.has(version) === true))
429
468
  ? []
430
469
  : [room.locator];
431
470
  });
@@ -435,7 +474,7 @@ export function createMemoryAdapter(options = {}) {
435
474
  expiring = expiring.filter((locator) => !named.includes(locator));
436
475
  queueMicrotask(() => {
437
476
  for (const room of asked) {
438
- if (expired.includes(room.locator))
477
+ if (expired.includes(room.locator) || room.roomVersion === null)
439
478
  carried.delete(room.locator);
440
479
  else {
441
480
  carried.set(room.locator, room.roomVersion);
@@ -1,6 +1,9 @@
1
1
  import type { AcceptedMessage } from './adapter.js';
2
+ import type { JobMarker } from './job.js';
2
3
  import type { Connection } from './tables.js';
3
4
  export declare const MESSAGE_TABLES: readonly string[];
5
+ export declare const ROWS = "WITH chosen AS (\n SELECT listed.value AS conversation,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'assistant' ORDER BY position DESC, identity DESC LIMIT 1) AS answer,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND text <> '' ORDER BY position DESC, identity DESC LIMIT 1) AS said,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' ORDER BY position, identity LIMIT 1) AS opened,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' AND json_extract(message, '$.waiting') = 1 ORDER BY position, identity LIMIT 1) AS asking\n FROM json_each(?) AS listed\n )\n SELECT chosen.conversation AS conversation,\n substr(said.text, 1, 512) AS said_text,\n json_extract(said.message, '$.role') AS said_role,\n json_extract(said.message, '$.accepted_at') AS said_at,\n substr(json_extract(answer.message, '$.failure'), 1, 512) AS failure,\n json_extract(opened.message, '$.source') AS opened_source,\n json_extract(opened.message, '$.sender') AS opened_sender,\n asking.identity AS asking_identity,\n asking.text AS asking_text,\n json_extract(asking.message, '$.accepted_at') AS asking_at,\n json_extract(asking.message, '$.source') AS asking_source,\n json_extract(asking.message, '$.sender') AS asking_sender\n FROM chosen\n LEFT JOIN conversation_messages said ON said.id = chosen.said\n LEFT JOIN conversation_messages answer ON answer.id = chosen.answer\n LEFT JOIN conversation_messages opened ON opened.id = chosen.opened\n LEFT JOIN conversation_messages asking ON asking.id = chosen.asking";
6
+ export declare const JOB_MARKERS = "SELECT json_extract(part.value, '$.text') AS said,\n json_extract(message, '$.accepted_at') AS at\n FROM conversation_messages, json_each(message, '$.parts') AS part\n WHERE conversation = ? AND instr(message, '\"marker\":\"job\"') > 0\n AND json_extract(part.value, '$.type') = 'marker'\n AND json_extract(part.value, '$.marker') = 'job'\n ORDER BY position, identity, part.key";
4
7
  export type HeldConversation = {
5
8
  readonly conversation: string;
6
9
  readonly read: string | null | undefined;
@@ -10,6 +13,25 @@ export type MessageWindow = {
10
13
  readonly messages: AcceptedMessage[];
11
14
  readonly more: boolean;
12
15
  };
16
+ export type HeldSource = {
17
+ readonly source: unknown;
18
+ readonly sender: string | null;
19
+ };
20
+ export type HeldRow = {
21
+ readonly conversation: string;
22
+ readonly said: {
23
+ readonly text: string;
24
+ readonly role: string | null;
25
+ readonly at: string | null;
26
+ } | null;
27
+ readonly failure: string | null;
28
+ readonly opened: HeldSource | null;
29
+ readonly asking: (HeldSource & {
30
+ readonly identity: string;
31
+ readonly text: string;
32
+ readonly at: string | null;
33
+ }) | null;
34
+ };
13
35
  export type ConversationWrite = {
14
36
  readonly conversation: string;
15
37
  readonly messages: readonly AcceptedMessage[];
@@ -18,10 +40,12 @@ export type ConversationWrite = {
18
40
  readonly partial: boolean;
19
41
  };
20
42
  };
21
- export declare function heldConversations(connection: Connection): HeldConversation[];
43
+ export declare function heldConversations(connection: Connection, conversations: readonly string[] | null): HeldConversation[];
22
44
  export declare function keptMessages(connection: Connection, { conversation, messages, read }: ConversationWrite): null;
23
45
  export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
24
46
  export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
47
+ export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
48
+ export declare function jobMarkers(connection: Connection, conversation: string): JobMarker[];
25
49
  export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
26
50
  export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
27
51
  export declare function forgottenMessages(connection: Connection): void;
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAE1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAM3C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC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AE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,MAAM,CAOR;AAaD,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,SAAS,MAAM,EAAE,GAC/B,OAAO,EAAE,CAuBX;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,CAIpF;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAO/F;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAK9F;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAG9D"}
package/dist/messages.js CHANGED
@@ -1,24 +1,67 @@
1
- import { HOLDS_PHRASE } from './phrase.js';
1
+ import { sql } from '@agentshouse/mdmodel';
2
+ import { EXCERPT } from './read.js';
3
+ const SAID_BY_HOUSE = `json_extract(message, '$.role') = 'house'`;
4
+ const ANSWERS_THE_TURN = `json_extract(message, '$.role') = 'assistant'`;
5
+ const MARKS_A_JOB = `instr(message, '"marker":"job"') > 0`;
2
6
  export const MESSAGE_TABLES = [
3
7
  'CREATE TABLE conversation_reads (conversation TEXT PRIMARY KEY, read TEXT, partial INTEGER NOT NULL) WITHOUT ROWID',
4
8
  'CREATE TABLE conversation_messages (id INTEGER PRIMARY KEY, conversation TEXT NOT NULL, identity TEXT NOT NULL, turn TEXT NOT NULL, position TEXT NOT NULL, message TEXT NOT NULL, text TEXT NOT NULL)',
5
9
  'CREATE UNIQUE INDEX conversation_messages_identity ON conversation_messages (conversation, identity)',
6
10
  'CREATE INDEX conversation_messages_position ON conversation_messages (conversation, position, identity)',
7
11
  'CREATE INDEX conversation_messages_turn ON conversation_messages (conversation, turn)',
12
+ `CREATE INDEX conversation_messages_house ON conversation_messages (conversation, position, identity) WHERE ${SAID_BY_HOUSE}`,
13
+ `CREATE INDEX conversation_messages_jobs ON conversation_messages (conversation, position, identity) WHERE ${MARKS_A_JOB}`,
8
14
  ];
15
+ const NEWEST_FIRST = 'ORDER BY position DESC, identity DESC LIMIT 1';
16
+ const OLDEST_FIRST = 'ORDER BY position, identity LIMIT 1';
17
+ const OF_THE_ROW = 'SELECT id FROM conversation_messages WHERE conversation = listed.value';
18
+ export const ROWS = `WITH chosen AS (
19
+ SELECT listed.value AS conversation,
20
+ (${OF_THE_ROW} AND ${ANSWERS_THE_TURN} ${NEWEST_FIRST}) AS answer,
21
+ (${OF_THE_ROW} AND text <> '' ${NEWEST_FIRST}) AS said,
22
+ (${OF_THE_ROW} AND ${SAID_BY_HOUSE} ${OLDEST_FIRST}) AS opened,
23
+ (${OF_THE_ROW} AND ${SAID_BY_HOUSE} AND json_extract(message, '$.waiting') = 1 ${OLDEST_FIRST}) AS asking
24
+ FROM json_each(?) AS listed
25
+ )
26
+ SELECT chosen.conversation AS conversation,
27
+ substr(said.text, 1, ${EXCERPT}) AS said_text,
28
+ json_extract(said.message, '$.role') AS said_role,
29
+ json_extract(said.message, '$.accepted_at') AS said_at,
30
+ substr(json_extract(answer.message, '$.failure'), 1, ${EXCERPT}) AS failure,
31
+ json_extract(opened.message, '$.source') AS opened_source,
32
+ json_extract(opened.message, '$.sender') AS opened_sender,
33
+ asking.identity AS asking_identity,
34
+ asking.text AS asking_text,
35
+ json_extract(asking.message, '$.accepted_at') AS asking_at,
36
+ json_extract(asking.message, '$.source') AS asking_source,
37
+ json_extract(asking.message, '$.sender') AS asking_sender
38
+ FROM chosen
39
+ LEFT JOIN conversation_messages said ON said.id = chosen.said
40
+ LEFT JOIN conversation_messages answer ON answer.id = chosen.answer
41
+ LEFT JOIN conversation_messages opened ON opened.id = chosen.opened
42
+ LEFT JOIN conversation_messages asking ON asking.id = chosen.asking`;
43
+ export const JOB_MARKERS = `SELECT json_extract(part.value, '$.text') AS said,
44
+ json_extract(message, '$.accepted_at') AS at
45
+ FROM conversation_messages, json_each(message, '$.parts') AS part
46
+ WHERE conversation = ? AND ${MARKS_A_JOB}
47
+ AND json_extract(part.value, '$.type') = 'marker'
48
+ AND json_extract(part.value, '$.marker') = 'job'
49
+ ORDER BY position, identity, part.key`;
9
50
  function text(value) {
10
51
  return typeof value === 'string' ? value : String(value);
11
52
  }
12
- export function heldConversations(connection) {
53
+ export function heldConversations(connection, conversations) {
54
+ const named = conversations === null ? '' : ' AND conversation IN (SELECT value FROM json_each(?))';
55
+ const bound = conversations === null ? [] : [JSON.stringify(conversations)];
13
56
  const held = new Map();
14
- for (const row of connection.rows('SELECT conversation, read, partial FROM conversation_reads')) {
57
+ for (const row of connection.rows(`SELECT conversation, read, partial FROM conversation_reads WHERE 1 = 1${named}`, bound)) {
15
58
  held.set(text(row.conversation), {
16
59
  conversation: text(row.conversation),
17
60
  read: row.read === null ? null : text(row.read),
18
61
  partial: Number(row.partial) === 1,
19
62
  });
20
63
  }
21
- for (const row of connection.rows('SELECT DISTINCT conversation FROM conversation_messages WHERE conversation NOT IN (SELECT conversation FROM conversation_reads)')) {
64
+ for (const row of connection.rows(`SELECT DISTINCT conversation FROM conversation_messages WHERE conversation NOT IN (SELECT conversation FROM conversation_reads)${named}`, bound)) {
22
65
  held.set(text(row.conversation), {
23
66
  conversation: text(row.conversation),
24
67
  read: undefined,
@@ -60,7 +103,7 @@ function accepted(row) {
60
103
  function holding(phrase) {
61
104
  return phrase === null
62
105
  ? { sql: '', bind: [] }
63
- : { sql: ` AND ${HOLDS_PHRASE}(text, ?)`, bind: [phrase.toLowerCase()] };
106
+ : { sql: ` AND ${sql.HOLDS_PHRASE}(text, ?)`, bind: [phrase.toLowerCase()] };
64
107
  }
65
108
  export function messageWindow(connection, conversation, limit, before, phrase) {
66
109
  const held = holding(phrase);
@@ -74,6 +117,42 @@ export function messageCount(connection, conversation, phrase) {
74
117
  const [counted] = connection.rows(`SELECT count(*) AS held FROM conversation_messages WHERE conversation = ?${held.sql}`, [conversation, ...held.bind]);
75
118
  return Number(counted?.held ?? 0);
76
119
  }
120
+ function textOrNull(value) {
121
+ return value === null || value === undefined ? null : text(value);
122
+ }
123
+ function heldSource(source, sender) {
124
+ return {
125
+ source: source === null || source === undefined ? null : JSON.parse(text(source)),
126
+ sender: textOrNull(sender),
127
+ };
128
+ }
129
+ export function conversationRows(connection, conversations) {
130
+ return connection.rows(ROWS, [JSON.stringify(conversations)]).map((row) => ({
131
+ conversation: text(row.conversation),
132
+ said: row.said_text === null
133
+ ? null
134
+ : {
135
+ text: text(row.said_text),
136
+ role: textOrNull(row.said_role),
137
+ at: textOrNull(row.said_at),
138
+ },
139
+ failure: textOrNull(row.failure),
140
+ opened: row.opened_source === null ? null : heldSource(row.opened_source, row.opened_sender),
141
+ asking: row.asking_identity === null
142
+ ? null
143
+ : {
144
+ ...heldSource(row.asking_source, row.asking_sender),
145
+ identity: text(row.asking_identity),
146
+ text: text(row.asking_text),
147
+ at: textOrNull(row.asking_at),
148
+ },
149
+ }));
150
+ }
151
+ export function jobMarkers(connection, conversation) {
152
+ return connection
153
+ .rows(JOB_MARKERS, [conversation])
154
+ .map((row) => ({ said: text(row.said), at: text(row.at) }));
155
+ }
77
156
  export function turnArrived(connection, conversation, turn) {
78
157
  return (connection.rows('SELECT 1 FROM conversation_messages WHERE conversation = ? AND turn = ? LIMIT 1', [conversation, turn]).length > 0);
79
158
  }
package/dist/model.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Definition, ValueFacts, VerifiedModel } from '@agentshouse/mdmodel';
1
+ import type { Definition, VerifiedModel } from '@agentshouse/mdmodel';
2
2
  import type { Open } from './open.js';
3
3
  export type ModelIdentity = {
4
4
  identity: string;
@@ -8,7 +8,7 @@ export type ModelSnapshot = ModelIdentity & {
8
8
  schema: string | null;
9
9
  revision: string | null;
10
10
  };
11
- export type ModelUnavailableReason = Open<'not-readable' | 'revoked' | 'not-acquired' | 'invalid'>;
11
+ export type ModelUnavailableReason = Open<'not-readable' | 'revoked' | 'not-acquired'>;
12
12
  export type ModelResult = {
13
13
  kind: 'model';
14
14
  snapshot: ModelSnapshot;
@@ -20,8 +20,6 @@ export type MdType = Definition;
20
20
  export type ModelState = {
21
21
  status: 'unavailable';
22
22
  reason: ModelUnavailableReason;
23
- schema?: string | null;
24
- revision?: string | null;
25
23
  } | {
26
24
  status: 'current' | 'cached';
27
25
  snapshot: ModelSnapshot;
@@ -37,8 +35,6 @@ export type TypesResult = {
37
35
  status: Open<'unavailable'>;
38
36
  reason: ModelUnavailableReason;
39
37
  types: null;
40
- schema?: string | null;
41
- revision?: string | null;
42
38
  } | {
43
39
  status: Open<'current' | 'cached'>;
44
40
  identity: string;
@@ -57,7 +53,4 @@ export declare const NO_MODEL: ModelState;
57
53
  export declare function definitionOf(state: ModelState, type: string | undefined): Definition | undefined;
58
54
  export declare function modelTypes(state: ModelState): TypesResult;
59
55
  export declare function storedModel(state: ModelState): StoredModel;
60
- export declare function cached(state: ModelState): ModelState;
61
- export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
62
- export declare function referenceField(facts: ValueFacts | undefined): boolean;
63
56
  //# sourceMappingURL=model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CA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AS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AACN,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC;CACpC,CAAC;AACF,eAAO,MAAM,QAAQ,EAAE,UAA8D,CAAC;AACtF,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAGhG;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAczD;AACD,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAI1D"}
package/dist/model.js CHANGED
@@ -23,12 +23,3 @@ export function storedModel(state) {
23
23
  const { types: _types, ...stored } = state;
24
24
  return stored;
25
25
  }
26
- export function cached(state) {
27
- return state.status === 'unavailable' ? state : { ...state, status: 'cached' };
28
- }
29
- export function sameModel(left, right) {
30
- return left.identity === right.identity && left.version === right.version;
31
- }
32
- export function referenceField(facts) {
33
- return facts?.reference !== undefined || facts?.items?.reference !== undefined;
34
- }
@@ -0,0 +1,14 @@
1
+ import type { ScopedRefusal } from './adapter.js';
2
+ import { type ModelState } from './model.js';
3
+ import { type ReplicaRecord } from './replica.js';
4
+ import type { Runtime } from './runtime.js';
5
+ import type { RoomDeclaration } from './socket.js';
6
+ import type { RuntimeStore } from './store.js';
7
+ export declare function declaredAsHeld(held: ReplicaRecord | undefined, room: RoomDeclaration): boolean;
8
+ export declare function revoked(model: ModelState | undefined): boolean;
9
+ export declare function keepNaming(runtime: Runtime, local: RuntimeStore, room: RoomDeclaration): Promise<void>;
10
+ export declare function retainModel(runtime: Runtime, local: RuntimeStore, room: RoomDeclaration, given: ModelState | null): Promise<void>;
11
+ export declare function scoped(runtime: Runtime, result: ScopedRefusal, room: RoomDeclaration, local: RuntimeStore): Promise<void>;
12
+ export declare function settleModels(runtime: Runtime, held: readonly RoomDeclaration[], status: 'current' | 'cached', local: RuntimeStore): Promise<void>;
13
+ export declare function cachedModels(runtime: Runtime, local: RuntimeStore): Promise<void>;
14
+ //# sourceMappingURL=models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAKlD,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAQ9F;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAE9D;AAMD,wBAAsB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,iBAqB5F;AAMD,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,UAAU,GAAG,IAAI,iBAsDzB;AAED,wBAAsB,MAAM,CAC1B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,YAAY,iBA0BpB;AAED,wBAAsB,YAAY,CAChC,OAAO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