@agentshouse/mdruntime 0.1.0-cef5833f6c689 → 0.1.0-cef76ea952695

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 +9 -9
  2. package/dist/acceptance.d.ts +6 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +385 -0
  5. package/dist/actions.d.ts +20 -0
  6. package/dist/actions.d.ts.map +1 -0
  7. package/dist/actions.js +251 -0
  8. package/dist/adapter.d.ts +28 -55
  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 +207 -76
  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/change.d.ts +1 -0
  20. package/dist/change.d.ts.map +1 -1
  21. package/dist/change.js +4 -2
  22. package/dist/chat-types.d.ts +5 -0
  23. package/dist/chat-types.d.ts.map +1 -0
  24. package/dist/chat-types.js +13 -0
  25. package/dist/client.d.ts +18 -2
  26. package/dist/client.d.ts.map +1 -1
  27. package/dist/client.js +7 -2
  28. package/dist/compile.d.ts +5 -0
  29. package/dist/compile.d.ts.map +1 -1
  30. package/dist/compile.js +202 -80
  31. package/dist/connection.d.ts +5 -141
  32. package/dist/connection.d.ts.map +1 -1
  33. package/dist/connection.js +103 -5175
  34. package/dist/conversation-live.d.ts +135 -0
  35. package/dist/conversation-live.d.ts.map +1 -0
  36. package/dist/conversation-live.js +247 -0
  37. package/dist/conversation-row.d.ts +33 -0
  38. package/dist/conversation-row.d.ts.map +1 -0
  39. package/dist/conversation-row.js +53 -0
  40. package/dist/conversation.d.ts +30 -37
  41. package/dist/conversation.d.ts.map +1 -1
  42. package/dist/conversation.js +853 -864
  43. package/dist/discovery.d.ts +10 -0
  44. package/dist/discovery.d.ts.map +1 -0
  45. package/dist/discovery.js +175 -0
  46. package/dist/durability.d.ts +15 -0
  47. package/dist/durability.d.ts.map +1 -1
  48. package/dist/entry.d.ts.map +1 -1
  49. package/dist/entry.js +4 -3
  50. package/dist/expectation.d.ts +4 -2
  51. package/dist/expectation.d.ts.map +1 -1
  52. package/dist/expectation.js +33 -11
  53. package/dist/failure.d.ts +1 -0
  54. package/dist/failure.d.ts.map +1 -1
  55. package/dist/failure.js +3 -0
  56. package/dist/figures.d.ts +49 -0
  57. package/dist/figures.d.ts.map +1 -0
  58. package/dist/figures.js +197 -0
  59. package/dist/holdings.d.ts +29 -0
  60. package/dist/holdings.d.ts.map +1 -0
  61. package/dist/holdings.js +95 -0
  62. package/dist/host.d.ts +1 -0
  63. package/dist/host.d.ts.map +1 -1
  64. package/dist/host.js +11 -4
  65. package/dist/index.d.ts +20 -6
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +5 -1
  68. package/dist/install.d.ts +56 -0
  69. package/dist/install.d.ts.map +1 -0
  70. package/dist/install.js +556 -0
  71. package/dist/job.d.ts +1 -10
  72. package/dist/job.d.ts.map +1 -1
  73. package/dist/job.js +2 -23
  74. package/dist/lifecycle.d.ts +7 -0
  75. package/dist/lifecycle.d.ts.map +1 -0
  76. package/dist/lifecycle.js +270 -0
  77. package/dist/listing.d.ts +53 -0
  78. package/dist/listing.d.ts.map +1 -0
  79. package/dist/listing.js +176 -0
  80. package/dist/live.d.ts +4 -4
  81. package/dist/live.d.ts.map +1 -1
  82. package/dist/live.js +54 -16
  83. package/dist/locks.d.ts +9 -0
  84. package/dist/locks.d.ts.map +1 -0
  85. package/dist/locks.js +62 -0
  86. package/dist/log.d.ts +1 -0
  87. package/dist/log.d.ts.map +1 -1
  88. package/dist/lost.d.ts +5 -0
  89. package/dist/lost.d.ts.map +1 -0
  90. package/dist/lost.js +61 -0
  91. package/dist/media.d.ts +1 -1
  92. package/dist/media.d.ts.map +1 -1
  93. package/dist/media.js +3 -3
  94. package/dist/memory.d.ts +3 -1
  95. package/dist/memory.d.ts.map +1 -1
  96. package/dist/memory.js +45 -5
  97. package/dist/messages.d.ts +22 -1
  98. package/dist/messages.d.ts.map +1 -1
  99. package/dist/messages.js +75 -16
  100. package/dist/model.d.ts +1 -7
  101. package/dist/model.d.ts.map +1 -1
  102. package/dist/model.js +0 -6
  103. package/dist/models.d.ts +14 -0
  104. package/dist/models.d.ts.map +1 -0
  105. package/dist/models.js +197 -0
  106. package/dist/observation.d.ts.map +1 -1
  107. package/dist/observation.js +12 -17
  108. package/dist/opened.js +3 -3
  109. package/dist/opening.d.ts +4 -0
  110. package/dist/opening.d.ts.map +1 -0
  111. package/dist/opening.js +60 -0
  112. package/dist/outcome.d.ts +4 -1
  113. package/dist/outcome.d.ts.map +1 -1
  114. package/dist/outcome.js +3 -0
  115. package/dist/overlay.d.ts +1 -0
  116. package/dist/overlay.d.ts.map +1 -1
  117. package/dist/overlay.js +11 -0
  118. package/dist/parts.d.ts +11 -0
  119. package/dist/parts.d.ts.map +1 -0
  120. package/dist/parts.js +21 -0
  121. package/dist/paths.d.ts +1 -0
  122. package/dist/paths.d.ts.map +1 -1
  123. package/dist/paths.js +22 -0
  124. package/dist/preparation.d.ts +20 -0
  125. package/dist/preparation.d.ts.map +1 -0
  126. package/dist/preparation.js +233 -0
  127. package/dist/queries.d.ts +16 -0
  128. package/dist/queries.d.ts.map +1 -0
  129. package/dist/queries.js +272 -0
  130. package/dist/query.d.ts +10 -2
  131. package/dist/query.d.ts.map +1 -1
  132. package/dist/questions.d.ts +34 -0
  133. package/dist/questions.d.ts.map +1 -0
  134. package/dist/questions.js +122 -0
  135. package/dist/reach.d.ts +8 -6
  136. package/dist/reach.d.ts.map +1 -1
  137. package/dist/reach.js +160 -101
  138. package/dist/react.d.ts +11 -1
  139. package/dist/react.d.ts.map +1 -1
  140. package/dist/react.js +10 -1
  141. package/dist/read.d.ts +7 -0
  142. package/dist/read.d.ts.map +1 -0
  143. package/dist/read.js +17 -0
  144. package/dist/readiness.d.ts +0 -1
  145. package/dist/readiness.d.ts.map +1 -1
  146. package/dist/reads.d.ts +37 -0
  147. package/dist/reads.d.ts.map +1 -0
  148. package/dist/reads.js +174 -0
  149. package/dist/recovery.d.ts.map +1 -1
  150. package/dist/recovery.js +9 -1
  151. package/dist/refresh.d.ts +1 -1
  152. package/dist/refresh.d.ts.map +1 -1
  153. package/dist/refresh.js +8 -20
  154. package/dist/refusal.d.ts +5 -0
  155. package/dist/refusal.d.ts.map +1 -0
  156. package/dist/refusal.js +57 -0
  157. package/dist/replica.d.ts +7 -7
  158. package/dist/replica.d.ts.map +1 -1
  159. package/dist/replica.js +51 -19
  160. package/dist/room-draft.d.ts +1 -3
  161. package/dist/room-draft.d.ts.map +1 -1
  162. package/dist/room-draft.js +3 -3
  163. package/dist/room-drafts.d.ts +24 -0
  164. package/dist/room-drafts.d.ts.map +1 -0
  165. package/dist/room-drafts.js +217 -0
  166. package/dist/rows.d.ts +14 -5
  167. package/dist/rows.d.ts.map +1 -1
  168. package/dist/rows.js +50 -58
  169. package/dist/runtime.d.ts +43 -0
  170. package/dist/runtime.d.ts.map +1 -0
  171. package/dist/runtime.js +1 -0
  172. package/dist/save.d.ts +5 -1
  173. package/dist/save.d.ts.map +1 -1
  174. package/dist/save.js +34 -21
  175. package/dist/saves.d.ts +70 -0
  176. package/dist/saves.d.ts.map +1 -0
  177. package/dist/saves.js +1005 -0
  178. package/dist/seed.d.ts +11 -2
  179. package/dist/seed.d.ts.map +1 -1
  180. package/dist/seed.js +71 -1
  181. package/dist/shared.d.ts +1 -6
  182. package/dist/shared.d.ts.map +1 -1
  183. package/dist/shared.js +13 -95
  184. package/dist/shown.d.ts +31 -0
  185. package/dist/shown.d.ts.map +1 -0
  186. package/dist/shown.js +290 -0
  187. package/dist/socket/admission.d.ts +7 -0
  188. package/dist/socket/admission.d.ts.map +1 -0
  189. package/dist/socket/admission.js +39 -0
  190. package/dist/socket/answers.d.ts +6 -0
  191. package/dist/socket/answers.d.ts.map +1 -0
  192. package/dist/socket/answers.js +20 -0
  193. package/dist/socket/lanes.d.ts +20 -0
  194. package/dist/socket/lanes.d.ts.map +1 -0
  195. package/dist/socket/lanes.js +77 -0
  196. package/dist/socket/reads.d.ts +10 -0
  197. package/dist/socket/reads.d.ts.map +1 -0
  198. package/dist/socket/reads.js +31 -0
  199. package/dist/socket/rooms.d.ts +44 -0
  200. package/dist/socket/rooms.d.ts.map +1 -0
  201. package/dist/socket/rooms.js +90 -0
  202. package/dist/socket/session.d.ts +38 -0
  203. package/dist/socket/session.d.ts.map +1 -0
  204. package/dist/socket/session.js +23 -0
  205. package/dist/socket.d.ts +70 -0
  206. package/dist/socket.d.ts.map +1 -0
  207. package/dist/socket.js +175 -0
  208. package/dist/source.d.ts +61 -0
  209. package/dist/source.d.ts.map +1 -0
  210. package/dist/source.js +82 -0
  211. package/dist/status.d.ts +0 -2
  212. package/dist/status.d.ts.map +1 -1
  213. package/dist/status.js +0 -6
  214. package/dist/store/fences.d.ts +16 -0
  215. package/dist/store/fences.d.ts.map +1 -0
  216. package/dist/store/fences.js +26 -0
  217. package/dist/store/installs.d.ts +30 -0
  218. package/dist/store/installs.d.ts.map +1 -0
  219. package/dist/store/installs.js +34 -0
  220. package/dist/store/readiness.d.ts +10 -0
  221. package/dist/store/readiness.d.ts.map +1 -0
  222. package/dist/store/readiness.js +52 -0
  223. package/dist/store/records.d.ts +210 -0
  224. package/dist/store/records.d.ts.map +1 -0
  225. package/dist/store/records.js +428 -0
  226. package/dist/store/room-held.d.ts +8 -0
  227. package/dist/store/room-held.d.ts.map +1 -0
  228. package/dist/store/room-held.js +17 -0
  229. package/dist/store/space.d.ts +11 -0
  230. package/dist/store/space.d.ts.map +1 -0
  231. package/dist/store/space.js +41 -0
  232. package/dist/store/watchers.d.ts +17 -0
  233. package/dist/store/watchers.d.ts.map +1 -0
  234. package/dist/store/watchers.js +56 -0
  235. package/dist/store/writes.d.ts +24 -0
  236. package/dist/store/writes.d.ts.map +1 -0
  237. package/dist/store/writes.js +125 -0
  238. package/dist/store.d.ts +107 -152
  239. package/dist/store.d.ts.map +1 -1
  240. package/dist/store.js +143 -394
  241. package/dist/stored.d.ts +59 -65
  242. package/dist/stored.d.ts.map +1 -1
  243. package/dist/stored.js +255 -149
  244. package/dist/surface.d.ts +88 -0
  245. package/dist/surface.d.ts.map +1 -0
  246. package/dist/surface.js +224 -0
  247. package/dist/sync.d.ts +19 -0
  248. package/dist/sync.d.ts.map +1 -0
  249. package/dist/sync.js +532 -0
  250. package/dist/tables.d.ts +110 -50
  251. package/dist/tables.d.ts.map +1 -1
  252. package/dist/tables.js +205 -54
  253. package/dist/tallies.d.ts +18 -0
  254. package/dist/tallies.d.ts.map +1 -0
  255. package/dist/tallies.js +129 -0
  256. package/dist/validation.d.ts.map +1 -1
  257. package/dist/validation.js +4 -4
  258. package/dist/wire.d.ts +16 -1
  259. package/dist/wire.d.ts.map +1 -1
  260. package/dist/wire.js +6 -0
  261. package/package.json +3 -2
  262. package/dist/fence.d.ts +0 -6
  263. package/dist/fence.d.ts.map +0 -1
  264. package/dist/fence.js +0 -10
package/dist/locks.js ADDED
@@ -0,0 +1,62 @@
1
+ import { uncaught } from './failure.js';
2
+ import { emitRooms, LOCKS_TOPIC } from './shown.js';
3
+ async function offlineModes({ store, socket }) {
4
+ const modes = new Map();
5
+ for (const [locator, { room }] of socket.rooms.declarations()) {
6
+ const declaration = room ?? socket.rooms.discovered(locator);
7
+ if (declaration !== undefined)
8
+ modes.set(locator, declaration.replica.offline);
9
+ }
10
+ for (const [locator, { offline }] of (await store.covering()).rooms)
11
+ modes.set(locator, offline);
12
+ return modes;
13
+ }
14
+ export async function locked({ store, socket }, locator) {
15
+ if (store.fences.has(locator) || socket.rooms.standing(locator).confirmed)
16
+ return false;
17
+ const held = socket.rooms.declared(locator)?.room ?? socket.rooms.discovered(locator);
18
+ const mode = (await (await store.open()).offline(locator)) ?? held?.replica.offline;
19
+ return mode === 'locked';
20
+ }
21
+ export async function lockedRooms(runtime) {
22
+ const { store, socket } = runtime;
23
+ return [...(await offlineModes(runtime))]
24
+ .filter(([locator, mode]) => mode === 'locked' &&
25
+ !socket.rooms.standing(locator).confirmed &&
26
+ !store.fences.has(locator))
27
+ .map(([locator]) => locator)
28
+ .sort();
29
+ }
30
+ export async function relocked(runtime, before) {
31
+ const after = await lockedRooms(runtime);
32
+ if (JSON.stringify(after) === JSON.stringify(before))
33
+ return;
34
+ runtime.journal.record(`locked ${after.length}`);
35
+ emitRooms(runtime);
36
+ runtime.store.tell(LOCKS_TOPIC, undefined);
37
+ }
38
+ export function confirmLocks({ socket }, listed) {
39
+ if (!socket.isOpen())
40
+ return;
41
+ for (const room of listed) {
42
+ if (room.replica.admission === 'admitted') {
43
+ socket.rooms.stand(room.locator, { confirmed: true });
44
+ }
45
+ }
46
+ }
47
+ export function connectionLost(runtime) {
48
+ const { socket } = runtime;
49
+ if (socket.closed())
50
+ return;
51
+ socket.rooms.connectionLost(() => {
52
+ if (socket.isOpen() || socket.closed())
53
+ return;
54
+ void lockedRooms(runtime).then((before) => {
55
+ socket.rooms.standAll({ confirmed: false });
56
+ return relocked(runtime, before);
57
+ }, uncaught);
58
+ });
59
+ }
60
+ export function watchLocks({ store }, notify) {
61
+ return store.watch(LOCKS_TOPIC, notify).stop;
62
+ }
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/media.d.ts CHANGED
@@ -3,6 +3,6 @@ import { type ShownAnswer } from './outcome.js';
3
3
  export declare const ROOM_MEDIA = "room-media";
4
4
  type Show = (room: string, path: string, revision?: string) => Promise<ShownAnswer>;
5
5
  export declare function shownBy(show: Show, client: MdRuntimeClient): MdRuntimeClient;
6
- export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient, registry?: CustomElementRegistry): void;
6
+ export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient): void;
7
7
  export {};
8
8
  //# sourceMappingURL=media.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,eAAO,MAAM,UAAU,eAAe,CAAC;AAwBvC,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAIpF,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAG5E;AAsBD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,EAClD,QAAQ,GAAE,qBAAsC,GAC/C,IAAI,CA0LN"}
1
+ {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,eAAO,MAAM,UAAU,eAAe,CAAC;AAwBvC,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAIpF,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAG5E;AAsBD,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,IAAI,CA0LxF"}
package/dist/media.js CHANGED
@@ -37,8 +37,8 @@ function drawnFor(mediaType) {
37
37
  return 'audio';
38
38
  return null;
39
39
  }
40
- export function defineRoomMedia(client, registry = customElements) {
41
- if (registry.get(ROOM_MEDIA) !== undefined)
40
+ export function defineRoomMedia(client) {
41
+ if (customElements.get(ROOM_MEDIA) !== undefined)
42
42
  return;
43
43
  const connected = Promise.resolve(client);
44
44
  class RoomMedia extends HTMLElement {
@@ -214,5 +214,5 @@ export function defineRoomMedia(client, registry = customElements) {
214
214
  void this.#load();
215
215
  }
216
216
  }
217
- registry.define(ROOM_MEDIA, RoomMedia);
217
+ customElements.define(ROOM_MEDIA, RoomMedia);
218
218
  }
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, type TypedPath } 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[];
@@ -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,EA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F,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CAipBrF"}
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) {
@@ -101,8 +103,35 @@ export function createMemoryAdapter(options = {}) {
101
103
  return path;
102
104
  }
103
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
+ }
104
131
  function retain(entries) {
105
132
  for (const room of entries) {
133
+ for (const [path, content] of Object.entries(room.documents ?? {}))
134
+ factsAt(room, path, content);
106
135
  note(room.locator, room);
107
136
  const versions = served.get(room.locator) ?? new Map();
108
137
  versions.set(room.roomVersion, room);
@@ -120,6 +149,7 @@ export function createMemoryAdapter(options = {}) {
120
149
  replica: room.replica,
121
150
  ...(room.typedSelection === undefined ? {} : { typedSelection: room.typedSelection }),
122
151
  providerOwnedPaths: room.providerOwnedPaths,
152
+ authoredPaths: room.authoredPaths,
123
153
  };
124
154
  }
125
155
  function page(room, after) {
@@ -135,10 +165,14 @@ export function createMemoryAdapter(options = {}) {
135
165
  roomVersion: room.roomVersion,
136
166
  ...(opening ? { models: modelsOf(room) } : {}),
137
167
  documents: named(room.documents ?? {}, taken),
168
+ facts: factsIn(room, taken),
138
169
  revisions: named(room.revisions ?? {}, [...taken, ...targets]),
139
170
  ...(room.fileIds === undefined
140
171
  ? {}
141
172
  : { fileIds: named(room.fileIds, [...taken, ...targets]) }),
173
+ ...(room.created === undefined
174
+ ? {}
175
+ : { created: named(room.created, [...taken, ...targets]) }),
142
176
  changes: named(room.changes ?? {}, [...taken, ...targets]),
143
177
  binaryFiles: named(room.binaryFiles ?? {}, targets),
144
178
  ...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
@@ -162,6 +196,7 @@ export function createMemoryAdapter(options = {}) {
162
196
  const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
163
197
  const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
164
198
  room.fileIds?.[path] !== from.fileIds?.[path] ||
199
+ room.created?.[path] !== from.created?.[path] ||
165
200
  !sameChange(room.changes?.[path], from.changes?.[path]);
166
201
  const changed = Object.keys(current)
167
202
  .filter((path) => current[path] !== previous[path] || headMoved(path))
@@ -182,10 +217,14 @@ export function createMemoryAdapter(options = {}) {
182
217
  roomVersion: room.roomVersion,
183
218
  ...(models === undefined ? {} : { models }),
184
219
  documents: named(current, taken),
220
+ facts: factsIn(room, taken),
185
221
  revisions: named(room.revisions ?? {}, [...taken, ...targets]),
186
222
  ...(room.fileIds === undefined
187
223
  ? {}
188
224
  : { fileIds: named(room.fileIds, [...taken, ...targets]) }),
225
+ ...(room.created === undefined
226
+ ? {}
227
+ : { created: named(room.created, [...taken, ...targets]) }),
189
228
  changes: named(room.changes ?? {}, [...taken, ...targets]),
190
229
  binaryFiles: named(room.binaryFiles ?? {}, targets),
191
230
  ...(opening ? foldersMoved(room, from) : {}),
@@ -423,9 +462,10 @@ export function createMemoryAdapter(options = {}) {
423
462
  const named = asked.map((room) => room.locator);
424
463
  const unknown = asked.flatMap((room) => {
425
464
  const current = rooms.find((entry) => entry.locator === room.locator);
465
+ const version = room.roomVersion;
426
466
  return current === undefined ||
427
- current.roomVersion === room.roomVersion ||
428
- served.get(room.locator)?.has(room.roomVersion) === true
467
+ (version !== null &&
468
+ (current.roomVersion === version || served.get(room.locator)?.has(version) === true))
429
469
  ? []
430
470
  : [room.locator];
431
471
  });
@@ -435,7 +475,7 @@ export function createMemoryAdapter(options = {}) {
435
475
  expiring = expiring.filter((locator) => !named.includes(locator));
436
476
  queueMicrotask(() => {
437
477
  for (const room of asked) {
438
- if (expired.includes(room.locator))
478
+ if (expired.includes(room.locator) || room.roomVersion === null)
439
479
  carried.delete(room.locator);
440
480
  else {
441
481
  carried.set(room.locator, room.roomVersion);
@@ -559,7 +599,7 @@ export function createMemoryAdapter(options = {}) {
559
599
  return { kind: 'room-not-readable', locator: request.locator };
560
600
  const blob = heldBlob(room, request.path);
561
601
  return blob === undefined
562
- ? { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false }
602
+ ? { kind: 'rejected', code: 'not_found', fields: {}, retryable: false }
563
603
  : { kind: 'binary', body: blob.stream(), mediaType: blob.type };
564
604
  }, request);
565
605
  },
@@ -570,7 +610,7 @@ export function createMemoryAdapter(options = {}) {
570
610
  return { kind: 'room-not-readable', locator: request.locator };
571
611
  const blob = heldBlob(room, request.path);
572
612
  if (blob === undefined) {
573
- return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
613
+ return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
574
614
  }
575
615
  const url = linked.get(blob) ?? URL.createObjectURL(blob);
576
616
  linked.set(blob, url);
@@ -1,6 +1,7 @@
1
1
  import type { AcceptedMessage } from './adapter.js';
2
2
  import type { Connection } from './tables.js';
3
3
  export declare const MESSAGE_TABLES: readonly string[];
4
+ 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";
4
5
  export type HeldConversation = {
5
6
  readonly conversation: string;
6
7
  readonly read: string | null | undefined;
@@ -10,6 +11,25 @@ export type MessageWindow = {
10
11
  readonly messages: AcceptedMessage[];
11
12
  readonly more: boolean;
12
13
  };
14
+ export type HeldSource = {
15
+ readonly source: unknown;
16
+ readonly sender: string | null;
17
+ };
18
+ export type HeldRow = {
19
+ readonly conversation: string;
20
+ readonly said: {
21
+ readonly text: string;
22
+ readonly role: string | null;
23
+ readonly at: string | null;
24
+ } | null;
25
+ readonly failure: string | null;
26
+ readonly opened: HeldSource | null;
27
+ readonly asking: (HeldSource & {
28
+ readonly identity: string;
29
+ readonly text: string;
30
+ readonly at: string | null;
31
+ }) | null;
32
+ };
13
33
  export type ConversationWrite = {
14
34
  readonly conversation: string;
15
35
  readonly messages: readonly AcceptedMessage[];
@@ -18,10 +38,11 @@ export type ConversationWrite = {
18
38
  readonly partial: boolean;
19
39
  };
20
40
  };
21
- export declare function heldConversations(connection: Connection): HeldConversation[];
41
+ export declare function heldConversations(connection: Connection, conversations: readonly string[] | null): HeldConversation[];
22
42
  export declare function keptMessages(connection: Connection, { conversation, messages, read }: ConversationWrite): null;
23
43
  export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
24
44
  export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
45
+ export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
25
46
  export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
26
47
  export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
27
48
  export declare function forgottenMessages(connection: Connection): void;
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAE1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAM3C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,eAAe,EAAE,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7F,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,YAAY,EA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AAI,CAG9D"}
package/dist/messages.js CHANGED
@@ -1,24 +1,58 @@
1
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'`;
2
5
  export const MESSAGE_TABLES = [
3
6
  'CREATE TABLE conversation_reads (conversation TEXT PRIMARY KEY, read TEXT, partial INTEGER NOT NULL) WITHOUT ROWID',
4
7
  '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
8
  'CREATE UNIQUE INDEX conversation_messages_identity ON conversation_messages (conversation, identity)',
6
9
  'CREATE INDEX conversation_messages_position ON conversation_messages (conversation, position, identity)',
7
10
  'CREATE INDEX conversation_messages_turn ON conversation_messages (conversation, turn)',
11
+ `CREATE INDEX conversation_messages_house ON conversation_messages (conversation, position, identity) WHERE ${SAID_BY_HOUSE}`,
8
12
  ];
13
+ const NEWEST_FIRST = 'ORDER BY position DESC, identity DESC LIMIT 1';
14
+ const OLDEST_FIRST = 'ORDER BY position, identity LIMIT 1';
15
+ const OF_THE_ROW = 'SELECT id FROM conversation_messages WHERE conversation = listed.value';
16
+ export const ROWS = `WITH chosen AS (
17
+ SELECT listed.value AS conversation,
18
+ (${OF_THE_ROW} AND ${ANSWERS_THE_TURN} ${NEWEST_FIRST}) AS answer,
19
+ (${OF_THE_ROW} AND text <> '' ${NEWEST_FIRST}) AS said,
20
+ (${OF_THE_ROW} AND ${SAID_BY_HOUSE} ${OLDEST_FIRST}) AS opened,
21
+ (${OF_THE_ROW} AND ${SAID_BY_HOUSE} AND json_extract(message, '$.waiting') = 1 ${OLDEST_FIRST}) AS asking
22
+ FROM json_each(?) AS listed
23
+ )
24
+ SELECT chosen.conversation AS conversation,
25
+ substr(said.text, 1, ${EXCERPT}) AS said_text,
26
+ json_extract(said.message, '$.role') AS said_role,
27
+ json_extract(said.message, '$.accepted_at') AS said_at,
28
+ substr(json_extract(answer.message, '$.failure'), 1, ${EXCERPT}) AS failure,
29
+ json_extract(opened.message, '$.source') AS opened_source,
30
+ json_extract(opened.message, '$.sender') AS opened_sender,
31
+ asking.identity AS asking_identity,
32
+ asking.text AS asking_text,
33
+ json_extract(asking.message, '$.accepted_at') AS asking_at,
34
+ json_extract(asking.message, '$.source') AS asking_source,
35
+ json_extract(asking.message, '$.sender') AS asking_sender
36
+ FROM chosen
37
+ LEFT JOIN conversation_messages said ON said.id = chosen.said
38
+ LEFT JOIN conversation_messages answer ON answer.id = chosen.answer
39
+ LEFT JOIN conversation_messages opened ON opened.id = chosen.opened
40
+ LEFT JOIN conversation_messages asking ON asking.id = chosen.asking`;
9
41
  function text(value) {
10
42
  return typeof value === 'string' ? value : String(value);
11
43
  }
12
- export function heldConversations(connection) {
44
+ export function heldConversations(connection, conversations) {
45
+ const named = conversations === null ? '' : ' AND conversation IN (SELECT value FROM json_each(?))';
46
+ const bound = conversations === null ? [] : [JSON.stringify(conversations)];
13
47
  const held = new Map();
14
- for (const row of connection.rows('SELECT conversation, read, partial FROM conversation_reads')) {
48
+ for (const row of connection.rows(`SELECT conversation, read, partial FROM conversation_reads WHERE 1 = 1${named}`, bound)) {
15
49
  held.set(text(row.conversation), {
16
50
  conversation: text(row.conversation),
17
51
  read: row.read === null ? null : text(row.read),
18
52
  partial: Number(row.partial) === 1,
19
53
  });
20
54
  }
21
- for (const row of connection.rows('SELECT DISTINCT conversation FROM conversation_messages WHERE conversation NOT IN (SELECT conversation FROM conversation_reads)')) {
55
+ for (const row of connection.rows(`SELECT DISTINCT conversation FROM conversation_messages WHERE conversation NOT IN (SELECT conversation FROM conversation_reads)${named}`, bound)) {
22
56
  held.set(text(row.conversation), {
23
57
  conversation: text(row.conversation),
24
58
  read: undefined,
@@ -29,19 +63,14 @@ export function heldConversations(connection) {
29
63
  }
30
64
  export function keptMessages(connection, { conversation, messages, read }) {
31
65
  for (const message of messages) {
32
- const [held] = connection.rows('SELECT id FROM conversation_messages WHERE conversation = ? AND identity = ?', [conversation, message.identity]);
33
- const record = [
66
+ connection.run('INSERT INTO conversation_messages (conversation, identity, turn, position, message, text) VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT (conversation, identity) DO UPDATE SET turn = excluded.turn, position = excluded.position, message = excluded.message, text = excluded.text', [
67
+ conversation,
68
+ message.identity,
34
69
  message.turn,
35
70
  message.position,
36
71
  JSON.stringify(message.message ?? null),
37
72
  message.text,
38
- ];
39
- if (held === undefined) {
40
- connection.run('INSERT INTO conversation_messages (conversation, identity, turn, position, message, text) VALUES (?, ?, ?, ?, ?, ?)', [conversation, message.identity, ...record]);
41
- }
42
- else {
43
- connection.run('UPDATE conversation_messages SET turn = ?, position = ?, message = ?, text = ? WHERE id = ?', [...record, held.id]);
44
- }
73
+ ]);
45
74
  }
46
75
  if (read !== undefined) {
47
76
  connection.run('INSERT OR REPLACE INTO conversation_reads (conversation, read, partial) VALUES (?, ?, ?)', [conversation, read.at, read.partial ? 1 : 0]);
@@ -74,14 +103,44 @@ export function messageCount(connection, conversation, phrase) {
74
103
  const [counted] = connection.rows(`SELECT count(*) AS held FROM conversation_messages WHERE conversation = ?${held.sql}`, [conversation, ...held.bind]);
75
104
  return Number(counted?.held ?? 0);
76
105
  }
106
+ function textOrNull(value) {
107
+ return value === null ? null : text(value);
108
+ }
109
+ function heldSource(source, sender) {
110
+ return {
111
+ source: source === null ? null : JSON.parse(text(source)),
112
+ sender: textOrNull(sender),
113
+ };
114
+ }
115
+ export function conversationRows(connection, conversations) {
116
+ return connection.rows(ROWS, [JSON.stringify(conversations)]).map((row) => ({
117
+ conversation: text(row.conversation),
118
+ said: row.said_text === null
119
+ ? null
120
+ : {
121
+ text: text(row.said_text),
122
+ role: textOrNull(row.said_role),
123
+ at: textOrNull(row.said_at),
124
+ },
125
+ failure: textOrNull(row.failure),
126
+ opened: row.opened_source === null ? null : heldSource(row.opened_source, row.opened_sender),
127
+ asking: row.asking_identity === null
128
+ ? null
129
+ : {
130
+ ...heldSource(row.asking_source, row.asking_sender),
131
+ identity: text(row.asking_identity),
132
+ text: text(row.asking_text),
133
+ at: textOrNull(row.asking_at),
134
+ },
135
+ }));
136
+ }
77
137
  export function turnArrived(connection, conversation, turn) {
78
138
  return (connection.rows('SELECT 1 FROM conversation_messages WHERE conversation = ? AND turn = ? LIMIT 1', [conversation, turn]).length > 0);
79
139
  }
80
140
  export function droppedMessages(connection, conversations) {
81
- for (const conversation of conversations) {
82
- connection.run('DELETE FROM conversation_messages WHERE conversation = ?', [conversation]);
83
- connection.run('DELETE FROM conversation_reads WHERE conversation = ?', [conversation]);
84
- }
141
+ const named = [JSON.stringify(conversations)];
142
+ connection.run('DELETE FROM conversation_messages WHERE conversation IN (SELECT value FROM json_each(?))', named);
143
+ connection.run('DELETE FROM conversation_reads WHERE conversation IN (SELECT value FROM json_each(?))', named);
85
144
  }
86
145
  export function forgottenMessages(connection) {
87
146
  connection.run('DELETE FROM conversation_messages');
package/dist/model.d.ts CHANGED
@@ -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,6 +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
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,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACtE,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;CAAE,CAAC;AAC/F,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,cAAc,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,CAAC,CAAC;AACnG,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC;AAChC,MAAM,MAAM,UAAU,GAClB;IACE,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,GAA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,EAAE,UAAU,GAAG,WAAW,CAI1D"}
package/dist/model.js CHANGED
@@ -23,9 +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
- }
@@ -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;AAMlD,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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