@agentshouse/mdruntime 0.1.0-cec6690d5712e → 0.1.0-cedd665dffa4c

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 (392) hide show
  1. package/README.md +24 -19
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +299 -0
  5. package/dist/act-lanes.d.ts +30 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +225 -0
  8. package/dist/actions.d.ts +26 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +302 -0
  11. package/dist/adapter.d.ts +207 -94
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +6 -10
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +35 -41
  16. package/dist/binary.d.ts +18 -0
  17. package/dist/binary.d.ts.map +1 -0
  18. package/dist/binary.js +8 -0
  19. package/dist/bootstrap.d.ts +31 -11
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +311 -92
  22. package/dist/cell.d.ts +6 -0
  23. package/dist/cell.d.ts.map +1 -0
  24. package/dist/cell.js +9 -0
  25. package/dist/chain.d.ts +12 -0
  26. package/dist/chain.d.ts.map +1 -0
  27. package/dist/chain.js +64 -0
  28. package/dist/change-set.d.ts +13 -14
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +17 -62
  31. package/dist/change.d.ts +46 -0
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +39 -0
  34. package/dist/chat-types.d.ts +3 -0
  35. package/dist/chat-types.d.ts.map +1 -0
  36. package/dist/chat-types.js +11 -0
  37. package/dist/client.d.ts +51 -27
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +133 -26
  40. package/dist/collection.d.ts +34 -9
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +55 -79
  43. package/dist/compile.d.ts +18 -0
  44. package/dist/compile.d.ts.map +1 -0
  45. package/dist/compile.js +723 -0
  46. package/dist/connection.d.ts +8 -111
  47. package/dist/connection.d.ts.map +1 -1
  48. package/dist/connection.js +113 -2221
  49. package/dist/context.d.ts +2 -0
  50. package/dist/context.d.ts.map +1 -0
  51. package/dist/{chat/context.js → context.js} +2 -5
  52. package/dist/conversation-live.d.ts +150 -0
  53. package/dist/conversation-live.d.ts.map +1 -0
  54. package/dist/conversation-live.js +259 -0
  55. package/dist/conversation-row.d.ts +40 -0
  56. package/dist/conversation-row.d.ts.map +1 -0
  57. package/dist/conversation-row.js +66 -0
  58. package/dist/conversation.d.ts +84 -45
  59. package/dist/conversation.d.ts.map +1 -1
  60. package/dist/conversation.js +1118 -584
  61. package/dist/declaration.d.ts +10 -0
  62. package/dist/declaration.d.ts.map +1 -0
  63. package/dist/declaration.js +24 -0
  64. package/dist/digest.d.ts +7 -0
  65. package/dist/digest.d.ts.map +1 -0
  66. package/dist/digest.js +113 -0
  67. package/dist/discovery.d.ts +10 -0
  68. package/dist/discovery.d.ts.map +1 -0
  69. package/dist/discovery.js +150 -0
  70. package/dist/durability.d.ts +23 -1
  71. package/dist/durability.d.ts.map +1 -1
  72. package/dist/durability.js +9 -0
  73. package/dist/entry.d.ts +20 -0
  74. package/dist/entry.d.ts.map +1 -0
  75. package/dist/entry.js +161 -0
  76. package/dist/expectation.d.ts +26 -13
  77. package/dist/expectation.d.ts.map +1 -1
  78. package/dist/expectation.js +72 -19
  79. package/dist/failure.d.ts +3 -0
  80. package/dist/failure.d.ts.map +1 -1
  81. package/dist/failure.js +6 -0
  82. package/dist/figures.d.ts +49 -0
  83. package/dist/figures.d.ts.map +1 -0
  84. package/dist/figures.js +199 -0
  85. package/dist/file.d.ts +2 -19
  86. package/dist/file.d.ts.map +1 -1
  87. package/dist/file.js +8 -122
  88. package/dist/holdings.d.ts +29 -0
  89. package/dist/holdings.d.ts.map +1 -0
  90. package/dist/holdings.js +95 -0
  91. package/dist/host.d.ts +29 -4
  92. package/dist/host.d.ts.map +1 -1
  93. package/dist/host.js +179 -25
  94. package/dist/identity.d.ts +1 -0
  95. package/dist/identity.d.ts.map +1 -1
  96. package/dist/identity.js +3 -0
  97. package/dist/index.d.ts +42 -12
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +20 -2
  100. package/dist/install.d.ts +60 -0
  101. package/dist/install.d.ts.map +1 -0
  102. package/dist/install.js +537 -0
  103. package/dist/lifecycle.d.ts +7 -0
  104. package/dist/lifecycle.d.ts.map +1 -0
  105. package/dist/lifecycle.js +278 -0
  106. package/dist/listing.d.ts +52 -0
  107. package/dist/listing.d.ts.map +1 -0
  108. package/dist/listing.js +152 -0
  109. package/dist/live.d.ts +25 -0
  110. package/dist/live.d.ts.map +1 -0
  111. package/dist/live.js +206 -0
  112. package/dist/loaded.d.ts +5 -0
  113. package/dist/loaded.d.ts.map +1 -0
  114. package/dist/loaded.js +40 -0
  115. package/dist/locks.d.ts +7 -0
  116. package/dist/locks.d.ts.map +1 -0
  117. package/dist/locks.js +32 -0
  118. package/dist/lost.d.ts +5 -0
  119. package/dist/lost.d.ts.map +1 -0
  120. package/dist/lost.js +49 -0
  121. package/dist/media.d.ts +13 -0
  122. package/dist/media.d.ts.map +1 -0
  123. package/dist/media.js +269 -0
  124. package/dist/memory.d.ts +26 -8
  125. package/dist/memory.d.ts.map +1 -1
  126. package/dist/memory.js +307 -97
  127. package/dist/messages.d.ts +58 -0
  128. package/dist/messages.d.ts.map +1 -0
  129. package/dist/messages.js +162 -0
  130. package/dist/model.d.ts +11 -12
  131. package/dist/model.d.ts.map +1 -1
  132. package/dist/model.js +7 -15
  133. package/dist/models.d.ts +10 -0
  134. package/dist/models.d.ts.map +1 -0
  135. package/dist/models.js +153 -0
  136. package/dist/name.d.ts +4 -0
  137. package/dist/name.d.ts.map +1 -0
  138. package/dist/name.js +122 -0
  139. package/dist/observation.d.ts +42 -9
  140. package/dist/observation.d.ts.map +1 -1
  141. package/dist/observation.js +238 -33
  142. package/dist/opened.d.ts +22 -0
  143. package/dist/opened.d.ts.map +1 -0
  144. package/dist/opened.js +107 -0
  145. package/dist/opening.d.ts +4 -0
  146. package/dist/opening.d.ts.map +1 -0
  147. package/dist/opening.js +53 -0
  148. package/dist/outcome.d.ts +63 -5
  149. package/dist/outcome.d.ts.map +1 -1
  150. package/dist/outcome.js +70 -0
  151. package/dist/overlay.d.ts +21 -6
  152. package/dist/overlay.d.ts.map +1 -1
  153. package/dist/overlay.js +163 -187
  154. package/dist/page-metadata.d.ts +8 -0
  155. package/dist/page-metadata.d.ts.map +1 -0
  156. package/dist/page-metadata.js +19 -0
  157. package/dist/parts.d.ts +4 -0
  158. package/dist/parts.d.ts.map +1 -0
  159. package/dist/parts.js +13 -0
  160. package/dist/paths.d.ts +2 -0
  161. package/dist/paths.d.ts.map +1 -1
  162. package/dist/paths.js +26 -0
  163. package/dist/preparation.d.ts +41 -0
  164. package/dist/preparation.d.ts.map +1 -0
  165. package/dist/preparation.js +314 -0
  166. package/dist/presence.d.ts +58 -0
  167. package/dist/presence.d.ts.map +1 -0
  168. package/dist/presence.js +231 -0
  169. package/dist/queries.d.ts +16 -0
  170. package/dist/queries.d.ts.map +1 -0
  171. package/dist/queries.js +308 -0
  172. package/dist/query.d.ts +51 -183
  173. package/dist/query.d.ts.map +1 -1
  174. package/dist/query.js +3 -464
  175. package/dist/{chat/questions.d.ts → questions.d.ts} +5 -7
  176. package/dist/questions.d.ts.map +1 -0
  177. package/dist/{chat/questions.js → questions.js} +11 -7
  178. package/dist/queue.d.ts +40 -0
  179. package/dist/queue.d.ts.map +1 -0
  180. package/dist/queue.js +480 -0
  181. package/dist/reach.d.ts +20 -5
  182. package/dist/reach.d.ts.map +1 -1
  183. package/dist/reach.js +357 -80
  184. package/dist/react.d.ts +23 -7
  185. package/dist/react.d.ts.map +1 -1
  186. package/dist/react.js +40 -18
  187. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  188. package/dist/read.d.ts.map +1 -0
  189. package/dist/{chat/read.js → read.js} +4 -0
  190. package/dist/readiness.d.ts +55 -0
  191. package/dist/readiness.d.ts.map +1 -0
  192. package/dist/readiness.js +25 -0
  193. package/dist/reads.d.ts +39 -0
  194. package/dist/reads.d.ts.map +1 -0
  195. package/dist/reads.js +178 -0
  196. package/dist/recovery.d.ts +28 -0
  197. package/dist/recovery.d.ts.map +1 -0
  198. package/dist/recovery.js +254 -0
  199. package/dist/refresh.d.ts +17 -14
  200. package/dist/refresh.d.ts.map +1 -1
  201. package/dist/refresh.js +145 -58
  202. package/dist/refusal.d.ts +5 -0
  203. package/dist/refusal.d.ts.map +1 -0
  204. package/dist/refusal.js +55 -0
  205. package/dist/replica.d.ts +53 -33
  206. package/dist/replica.d.ts.map +1 -1
  207. package/dist/replica.js +349 -167
  208. package/dist/retried.d.ts +30 -0
  209. package/dist/retried.d.ts.map +1 -0
  210. package/dist/retried.js +72 -0
  211. package/dist/room-draft.d.ts +82 -11
  212. package/dist/room-draft.d.ts.map +1 -1
  213. package/dist/room-draft.js +490 -78
  214. package/dist/room-drafts.d.ts +24 -0
  215. package/dist/room-drafts.d.ts.map +1 -0
  216. package/dist/room-drafts.js +220 -0
  217. package/dist/rows.d.ts +31 -35
  218. package/dist/rows.d.ts.map +1 -1
  219. package/dist/rows.js +60 -126
  220. package/dist/runtime.d.ts +34 -0
  221. package/dist/runtime.d.ts.map +1 -0
  222. package/dist/runtime.js +1 -0
  223. package/dist/save.d.ts +45 -22
  224. package/dist/save.d.ts.map +1 -1
  225. package/dist/save.js +977 -215
  226. package/dist/saves.d.ts +32 -0
  227. package/dist/saves.d.ts.map +1 -0
  228. package/dist/saves.js +426 -0
  229. package/dist/search.d.ts +15 -55
  230. package/dist/search.d.ts.map +1 -1
  231. package/dist/search.js +10 -121
  232. package/dist/seed.d.ts +25 -0
  233. package/dist/seed.d.ts.map +1 -0
  234. package/dist/seed.js +145 -0
  235. package/dist/shared.d.ts +10 -0
  236. package/dist/shared.d.ts.map +1 -0
  237. package/dist/shared.js +339 -0
  238. package/dist/shown.d.ts +33 -0
  239. package/dist/shown.d.ts.map +1 -0
  240. package/dist/shown.js +309 -0
  241. package/dist/socket/admission.d.ts +7 -0
  242. package/dist/socket/admission.d.ts.map +1 -0
  243. package/dist/socket/admission.js +39 -0
  244. package/dist/socket/answers.d.ts +6 -0
  245. package/dist/socket/answers.d.ts.map +1 -0
  246. package/dist/socket/answers.js +20 -0
  247. package/dist/socket/lanes.d.ts +28 -0
  248. package/dist/socket/lanes.d.ts.map +1 -0
  249. package/dist/socket/lanes.js +103 -0
  250. package/dist/socket/reads.d.ts +10 -0
  251. package/dist/socket/reads.d.ts.map +1 -0
  252. package/dist/socket/reads.js +31 -0
  253. package/dist/socket/session.d.ts +38 -0
  254. package/dist/socket/session.d.ts.map +1 -0
  255. package/dist/socket/session.js +23 -0
  256. package/dist/socket.d.ts +67 -0
  257. package/dist/socket.d.ts.map +1 -0
  258. package/dist/socket.js +164 -0
  259. package/dist/source.d.ts +59 -0
  260. package/dist/source.d.ts.map +1 -0
  261. package/dist/source.js +93 -0
  262. package/dist/status.d.ts +5 -2
  263. package/dist/status.d.ts.map +1 -1
  264. package/dist/status.js +3 -7
  265. package/dist/store/installs.d.ts +30 -0
  266. package/dist/store/installs.d.ts.map +1 -0
  267. package/dist/store/installs.js +40 -0
  268. package/dist/store/readiness.d.ts +11 -0
  269. package/dist/store/readiness.d.ts.map +1 -0
  270. package/dist/store/readiness.js +68 -0
  271. package/dist/store/records.d.ts +217 -0
  272. package/dist/store/records.d.ts.map +1 -0
  273. package/dist/store/records.js +464 -0
  274. package/dist/store/room-held.d.ts +8 -0
  275. package/dist/store/room-held.d.ts.map +1 -0
  276. package/dist/store/room-held.js +17 -0
  277. package/dist/store/rooms-shown.d.ts +8 -0
  278. package/dist/store/rooms-shown.d.ts.map +1 -0
  279. package/dist/store/rooms-shown.js +13 -0
  280. package/dist/store/space.d.ts +11 -0
  281. package/dist/store/space.d.ts.map +1 -0
  282. package/dist/store/space.js +41 -0
  283. package/dist/store/watchers.d.ts +17 -0
  284. package/dist/store/watchers.d.ts.map +1 -0
  285. package/dist/store/watchers.js +56 -0
  286. package/dist/store/writes.d.ts +24 -0
  287. package/dist/store/writes.d.ts.map +1 -0
  288. package/dist/store/writes.js +125 -0
  289. package/dist/store.d.ts +114 -116
  290. package/dist/store.d.ts.map +1 -1
  291. package/dist/store.js +164 -494
  292. package/dist/stored.d.ts +167 -0
  293. package/dist/stored.d.ts.map +1 -0
  294. package/dist/stored.js +703 -0
  295. package/dist/surface.d.ts +89 -0
  296. package/dist/surface.d.ts.map +1 -0
  297. package/dist/surface.js +222 -0
  298. package/dist/sync.d.ts +19 -0
  299. package/dist/sync.d.ts.map +1 -0
  300. package/dist/sync.js +535 -0
  301. package/dist/tables.d.ts +419 -0
  302. package/dist/tables.d.ts.map +1 -0
  303. package/dist/tables.js +758 -0
  304. package/dist/tallies.d.ts +18 -0
  305. package/dist/tallies.d.ts.map +1 -0
  306. package/dist/tallies.js +128 -0
  307. package/dist/transfer.d.ts +0 -5
  308. package/dist/transfer.d.ts.map +1 -1
  309. package/dist/turn.d.ts +9 -0
  310. package/dist/turn.d.ts.map +1 -0
  311. package/dist/turn.js +75 -0
  312. package/dist/validation.d.ts +29 -0
  313. package/dist/validation.d.ts.map +1 -0
  314. package/dist/validation.js +98 -0
  315. package/dist/windows.d.ts +11 -0
  316. package/dist/windows.d.ts.map +1 -0
  317. package/dist/windows.js +16 -0
  318. package/dist/wire.d.ts +221 -34
  319. package/dist/wire.d.ts.map +1 -1
  320. package/dist/wire.js +74 -31
  321. package/package.json +28 -24
  322. package/AGENTS.md +0 -299
  323. package/dist/attachment.d.ts +0 -3
  324. package/dist/attachment.d.ts.map +0 -1
  325. package/dist/attachment.js +0 -8
  326. package/dist/attempt.d.ts +0 -16
  327. package/dist/attempt.d.ts.map +0 -1
  328. package/dist/attempt.js +0 -57
  329. package/dist/chat/acts.d.ts +0 -34
  330. package/dist/chat/acts.d.ts.map +0 -1
  331. package/dist/chat/acts.js +0 -36
  332. package/dist/chat/context.d.ts +0 -3
  333. package/dist/chat/context.d.ts.map +0 -1
  334. package/dist/chat/input.d.ts +0 -9
  335. package/dist/chat/input.d.ts.map +0 -1
  336. package/dist/chat/input.js +0 -99
  337. package/dist/chat/kit.d.ts +0 -60
  338. package/dist/chat/kit.d.ts.map +0 -1
  339. package/dist/chat/kit.js +0 -123
  340. package/dist/chat/lasting.d.ts +0 -6
  341. package/dist/chat/lasting.d.ts.map +0 -1
  342. package/dist/chat/lasting.js +0 -19
  343. package/dist/chat/list.d.ts +0 -20
  344. package/dist/chat/list.d.ts.map +0 -1
  345. package/dist/chat/list.js +0 -59
  346. package/dist/chat/markdown.d.ts +0 -19
  347. package/dist/chat/markdown.d.ts.map +0 -1
  348. package/dist/chat/markdown.js +0 -187
  349. package/dist/chat/message.d.ts +0 -6
  350. package/dist/chat/message.d.ts.map +0 -1
  351. package/dist/chat/message.js +0 -192
  352. package/dist/chat/messages.d.ts +0 -21
  353. package/dist/chat/messages.d.ts.map +0 -1
  354. package/dist/chat/messages.js +0 -151
  355. package/dist/chat/name.d.ts +0 -6
  356. package/dist/chat/name.d.ts.map +0 -1
  357. package/dist/chat/name.js +0 -37
  358. package/dist/chat/opened.d.ts +0 -11
  359. package/dist/chat/opened.d.ts.map +0 -1
  360. package/dist/chat/opened.js +0 -17
  361. package/dist/chat/overlay.d.ts +0 -31
  362. package/dist/chat/overlay.d.ts.map +0 -1
  363. package/dist/chat/overlay.js +0 -97
  364. package/dist/chat/parts.d.ts +0 -57
  365. package/dist/chat/parts.d.ts.map +0 -1
  366. package/dist/chat/parts.js +0 -119
  367. package/dist/chat/process.d.ts +0 -20
  368. package/dist/chat/process.d.ts.map +0 -1
  369. package/dist/chat/process.js +0 -32
  370. package/dist/chat/provider.d.ts +0 -63
  371. package/dist/chat/provider.d.ts.map +0 -1
  372. package/dist/chat/provider.js +0 -645
  373. package/dist/chat/question.d.ts +0 -9
  374. package/dist/chat/question.d.ts.map +0 -1
  375. package/dist/chat/question.js +0 -80
  376. package/dist/chat/questions.d.ts.map +0 -1
  377. package/dist/chat/read.d.ts.map +0 -1
  378. package/dist/chat/ready.d.ts +0 -33
  379. package/dist/chat/ready.d.ts.map +0 -1
  380. package/dist/chat/ready.js +0 -91
  381. package/dist/chat/style.d.ts +0 -4
  382. package/dist/chat/style.d.ts.map +0 -1
  383. package/dist/chat/style.js +0 -302
  384. package/dist/chat.d.ts +0 -14
  385. package/dist/chat.d.ts.map +0 -1
  386. package/dist/chat.js +0 -8
  387. package/dist/log.d.ts +0 -5
  388. package/dist/log.d.ts.map +0 -1
  389. package/dist/log.js +0 -14
  390. package/dist/read-side.d.ts +0 -18
  391. package/dist/read-side.d.ts.map +0 -1
  392. package/dist/read-side.js +0 -433
@@ -0,0 +1,24 @@
1
+ import { type ChangeSet } from './change-set.js';
2
+ import { type VisibleLayer } from './replica.js';
3
+ import { type RoomDraft, type RoomDraftWrite } from './room-draft.js';
4
+ import type { Runtime } from './runtime.js';
5
+ import type { Store } from './store.js';
6
+ export type RoomDraftSurface = {
7
+ list(): Promise<readonly RoomDraft[]>;
8
+ read(room: string, path: string): Promise<RoomDraft | null>;
9
+ write(room: string, path: string, revision: string | null, parts: unknown, next?: string): Promise<RoomDraftWrite>;
10
+ discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
11
+ };
12
+ export type PresentationSurface = {
13
+ read(app: string): Promise<unknown>;
14
+ write(app: string, value: unknown): Promise<void>;
15
+ edit(app: string, members: Readonly<Record<string, unknown>>): Promise<void>;
16
+ };
17
+ export declare function visibleOf(store: Store, locator: string, paths: readonly string[]): Promise<VisibleLayer | undefined>;
18
+ export declare function publishRoomDrafts({ store, socket }: Runtime, waitingOnly: boolean, touched?: ChangeSet['documents'] | null): Promise<void>;
19
+ export declare function emitPresentation({ store, socket }: Runtime, app: string): Promise<void>;
20
+ export declare function roomDraftSurface(runtime: Runtime): RoomDraftSurface;
21
+ export declare function presentationSurface(runtime: Runtime): PresentationSurface;
22
+ export declare function watchRoomDrafts({ store, socket }: Runtime, deliver: (value: unknown) => void): () => void;
23
+ export declare function watchPresentation({ store, socket }: Runtime, app: string, deliver: (value: unknown) => void): () => void;
24
+ //# sourceMappingURL=room-drafts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-drafts.d.ts","sourceRoot":"","sources":["../src/room-drafts.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5D,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EASL,KAAK,SAAS,EAEd,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,IAAI,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;IACtC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAC5D,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,KAAK,EAAE,OAAO,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAChF,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,KAAK,CAAC,GAAG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changeSet } from './change-set.js';
3
+ import { collectionOf } from './collection.js';
4
+ import { runtimeError, uncaught } from './failure.js';
5
+ import { roomDraftRevision } from './identity.js';
6
+ import { normalize } from './paths.js';
7
+ import { slicing } from './replica.js';
8
+ import { binaryBase, gatheredParts, held, heldFile, heldMarks, readParts, staleWrite, underneath, } from './room-draft.js';
9
+ import { stepped } from './turn.js';
10
+ const ROOM_DRAFTS = 'room-drafts';
11
+ const presentationTopic = (app) => `presentation\u0000${app}`;
12
+ export async function visibleOf(store, locator, paths) {
13
+ const kept = await store.record(locator);
14
+ if (kept === undefined)
15
+ return undefined;
16
+ const local = await store.open();
17
+ const slice = await stepped(slicing(await local.entries(kept.key, 'visible', paths), paths));
18
+ return { ...slice, collection: collectionOf(slice.documents, store.composed(kept)) };
19
+ }
20
+ function roomDraftOf(record, visible) {
21
+ return structuredClone({
22
+ room: record.locator,
23
+ path: record.path,
24
+ revision: record.revision,
25
+ parts: record.parts,
26
+ changedUnderneath: underneath(record.parts, record.path, visible),
27
+ marks: record.marks,
28
+ returned: record.returned,
29
+ });
30
+ }
31
+ async function roomDraftsOf(store, records) {
32
+ const rooms = new Map();
33
+ for (const record of records) {
34
+ const paths = rooms.get(record.locator) ?? [];
35
+ paths.push(record.path);
36
+ rooms.set(record.locator, paths);
37
+ }
38
+ const layers = new Map();
39
+ for (const [locator, paths] of rooms) {
40
+ layers.set(locator, await visibleOf(store, locator, paths));
41
+ }
42
+ return records.map((record) => roomDraftOf(record, layers.get(record.locator)));
43
+ }
44
+ function inOrder(records) {
45
+ return [...records].sort((left, right) => {
46
+ if (left.locator !== right.locator)
47
+ return left.locator < right.locator ? -1 : 1;
48
+ if (left.path !== right.path)
49
+ return left.path < right.path ? -1 : 1;
50
+ return 0;
51
+ });
52
+ }
53
+ async function snapshotRoomDrafts(store) {
54
+ return roomDraftsOf(store, inOrder(await store.drafts()));
55
+ }
56
+ export function publishRoomDrafts({ store, socket }, waitingOnly, touched = null) {
57
+ const unwatched = () => socket.closed() || store.watching(ROOM_DRAFTS).length === 0;
58
+ if (unwatched())
59
+ return Promise.resolve();
60
+ return store.publication(async () => {
61
+ if (unwatched())
62
+ return;
63
+ const records = await store.drafts();
64
+ if (socket.closed())
65
+ return;
66
+ if (touched !== null &&
67
+ !records.some((record) => touched.some(({ locator, path }) => locator === record.locator && (path === null || path === record.path)))) {
68
+ return;
69
+ }
70
+ const value = await roomDraftsOf(store, inOrder(records));
71
+ if (socket.closed())
72
+ return;
73
+ const answered = store.watching(ROOM_DRAFTS, waitingOnly ? 'waiting' : 'all');
74
+ for (const watcher of answered)
75
+ watcher.answer(value);
76
+ });
77
+ }
78
+ async function presentationOf(store, app) {
79
+ const value = await (await store.open()).presentation(app);
80
+ return value === undefined ? null : structuredClone(value);
81
+ }
82
+ export function emitPresentation({ store, socket }, app) {
83
+ const topic = presentationTopic(app);
84
+ const listening = () => store.watching(topic, 'ready');
85
+ if (socket.closed() || listening().length === 0)
86
+ return Promise.resolve();
87
+ return store.publication(async () => {
88
+ if (socket.closed() || listening().length === 0)
89
+ return;
90
+ const value = await presentationOf(store, app);
91
+ if (socket.closed())
92
+ return;
93
+ for (const watcher of listening())
94
+ watcher.answer(value);
95
+ });
96
+ }
97
+ async function writtenRoomDraft({ store }, room, path, revision, input, next) {
98
+ const parts = readParts(input, path);
99
+ if (path === '' || normalize(path) !== path)
100
+ throw runtimeError('room-draft-malformed', `room-draft-malformed at ${path}: a path inside the Room, such as notes/a.md`);
101
+ const local = await store.open();
102
+ const current = await store.draft(room, path);
103
+ if ((current?.revision ?? null) !== revision) {
104
+ return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
105
+ }
106
+ const file = parts.file === undefined
107
+ ? undefined
108
+ : await heldFile(parts.file.blob, parts.file.base === undefined
109
+ ? binaryBase(await visibleOf(store, room, [path]), path)
110
+ : parts.file.base);
111
+ const kept = held(current?.parts, parts, file);
112
+ const record = {
113
+ locator: room,
114
+ path,
115
+ revision: next,
116
+ parts: kept,
117
+ marks: heldMarks(current?.marks ?? {}, kept),
118
+ returned: current?.returned ?? null,
119
+ };
120
+ await local.keepRoomDraft(record, parts.file === undefined || file === undefined
121
+ ? []
122
+ : [{ key: file.localId, blob: parts.file.blob }]);
123
+ await store.changed(changeSet(room, { drafts: [path] }));
124
+ return { outcome: 'written', roomDraft: (await roomDraftsOf(store, [record]))[0] };
125
+ }
126
+ async function keptPresentation({ store }, app, value) {
127
+ await (await store.open()).present({ app, value });
128
+ await store.changed(changeSet('', { presentation: app }));
129
+ }
130
+ export function roomDraftSurface(runtime) {
131
+ const { store } = runtime;
132
+ return {
133
+ list() {
134
+ return store
135
+ .exclusive(async () => {
136
+ await store.open();
137
+ return snapshotRoomDrafts(store);
138
+ })
139
+ .then((listed) => {
140
+ publishRoomDrafts(runtime, true);
141
+ return listed;
142
+ });
143
+ },
144
+ async read(room, path) {
145
+ const record = await store.draft(room, path);
146
+ return record === undefined ? null : (await roomDraftsOf(store, [record]))[0];
147
+ },
148
+ write(room, path, revision, input, next = roomDraftRevision()) {
149
+ if (typeof next !== 'string' || next === '')
150
+ return Promise.reject(runtimeError('room-draft-malformed'));
151
+ return store.gathered(`room-draft\u0000${room}\u0000${path}`, { revision, input, next }, (earlier, later) => {
152
+ if (later.revision !== earlier.next)
153
+ return null;
154
+ const parts = gatheredParts(earlier.input, later.input);
155
+ return parts === null
156
+ ? null
157
+ : { revision: earlier.revision, input: parts, next: later.next };
158
+ }, (written) => writtenRoomDraft(runtime, room, path, written.revision, written.input, written.next));
159
+ },
160
+ discard(room, path, revision) {
161
+ return store.exclusive(async () => {
162
+ const local = await store.open();
163
+ const current = await store.draft(room, path);
164
+ if (current === undefined || current.revision !== revision) {
165
+ return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
166
+ }
167
+ await local.discardRoomDraft(room, path);
168
+ await store.changed(changeSet(room, { drafts: [path] }));
169
+ return { outcome: 'written', roomDraft: null };
170
+ });
171
+ },
172
+ };
173
+ }
174
+ export function presentationSurface(runtime) {
175
+ const { store } = runtime;
176
+ return {
177
+ read(app) {
178
+ return store.exclusive(() => presentationOf(store, app));
179
+ },
180
+ write(app, value) {
181
+ return store.exclusive(() => keptPresentation(runtime, app, structuredClone(value)));
182
+ },
183
+ edit(app, members) {
184
+ return store.gathered(`presentation\u0000${app}`, structuredClone(members), (earlier, later) => ({ ...earlier, ...later }), async (edited) => {
185
+ const kept = await (await store.open()).presentation(app);
186
+ await keptPresentation(runtime, app, Object.fromEntries([
187
+ ...Object.entries(plain(kept) ? kept : {}).filter(([member]) => !Object.hasOwn(edited, member)),
188
+ ...Object.entries(edited).filter(([, value]) => value !== null),
189
+ ]));
190
+ });
191
+ },
192
+ };
193
+ }
194
+ export function watchRoomDrafts({ store, socket }, deliver) {
195
+ const watcher = store.watch(ROOM_DRAFTS, deliver);
196
+ const unwatched = () => socket.closed() || !watcher.held();
197
+ void store
198
+ .exclusive(async () => {
199
+ await store.open();
200
+ })
201
+ .then(() => store.publication(async () => {
202
+ if (unwatched())
203
+ return;
204
+ const value = await snapshotRoomDrafts(store);
205
+ if (!unwatched())
206
+ watcher.answer(value);
207
+ }), uncaught);
208
+ return watcher.stop;
209
+ }
210
+ export function watchPresentation({ store, socket }, app, deliver) {
211
+ const watcher = store.watch(presentationTopic(app), deliver);
212
+ void store
213
+ .exclusive(async () => {
214
+ const value = await presentationOf(store, app);
215
+ if (!socket.closed() && watcher.held())
216
+ watcher.answer(value);
217
+ })
218
+ .catch(uncaught);
219
+ return watcher.stop;
220
+ }
package/dist/rows.d.ts CHANGED
@@ -1,44 +1,40 @@
1
- import { type Document } from '@agentshouse/mdmodel';
2
- import type { HeadChange } from './adapter.js';
1
+ import { type HeldValue } from '@agentshouse/mdmodel';
2
+ import type { SavedFacts } from './adapter.js';
3
3
  import { type Composition } from './collection.js';
4
- type Fields = Readonly<Record<string, unknown>>;
5
- export type DocumentRow = {
6
- key: string;
7
- kind: 'document';
8
- room: string;
9
- path: string;
10
- type: string | null;
11
- fields: Fields;
12
- values: Fields;
13
- reached: Readonly<Record<string, readonly unknown[]>>;
14
- directories: readonly string[];
15
- body: string;
16
- change: HeadChange | null;
4
+ import type { PlanReach } from './query.js';
5
+ type LinkKind = 'field' | 'link';
6
+ type HeldLink = {
7
+ readonly kind: LinkKind;
8
+ readonly keys: string;
9
+ readonly places: string;
10
+ readonly target: string;
11
+ readonly field: string;
17
12
  };
18
- export type BodyRow = {
19
- key: string;
20
- kind: 'body';
21
- room: string;
22
- path: string;
23
- preamble: string;
24
- sections: Readonly<Record<string, string>>;
25
- markdown: string;
13
+ export type Described = {
14
+ readonly type: string | null;
15
+ readonly declared: string | null;
16
+ readonly folder: string;
17
+ readonly fields: string | null;
18
+ readonly links: string | null;
26
19
  };
27
- export type ReferenceRow = {
28
- key: string;
29
- kind: 'reference';
30
- room: string;
31
- source: string;
32
- target: string;
33
- field: string;
34
- forms: readonly string[];
35
- path: string;
36
- type: string;
20
+ export type Held = {
21
+ readonly type: string | null;
22
+ readonly fields: Readonly<Record<string, unknown>> | null;
23
+ readonly links: readonly string[];
24
+ };
25
+ export type Derived = {
26
+ readonly values: readonly HeldValue[];
27
+ readonly links: readonly HeldLink[];
37
28
  };
38
- export type Row = DocumentRow | BodyRow | ReferenceRow;
39
29
  export declare function documentKey(room: string, path: string): string;
40
30
  export declare function roomOfKey(key: string): string;
31
+ export declare function roomsOfReach(reach: PlanReach): ReadonlySet<string>;
32
+ export declare function pathOfKey(key: string): string;
41
33
  export declare function markdownPath(path: string): boolean;
42
- export declare function rowsOf(room: string, path: string, document: Document | null, composition: Composition, change: HeadChange | null): readonly Row[];
34
+ export declare function folderOf(path: string): string;
35
+ export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
36
+ export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
37
+ export declare function heldOf(path: string, content: string | null, facts: SavedFacts | null): Held;
38
+ export declare function derived(path: string, held: Held, composition: Composition): Derived;
43
39
  export {};
44
40
  //# sourceMappingURL=rows.d.ts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AM,EACZ,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,GACvB,UAAU,GAAG,IAAI,CAQnB;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,KAAK,EAAE,UAAU,GAAG,IAAI,GACvB,SAAS,CAaX;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,IAAI,CAK3F;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAYnF"}
package/dist/rows.js CHANGED
@@ -1,6 +1,5 @@
1
- import { ARRAY_INDEX, escapePointer, references, target, } from '@agentshouse/mdmodel';
2
- import { governing } from './collection.js';
3
- import { definitionOf } from './model.js';
1
+ import { byCodePoint, documentFacts, indexed, parse } from '@agentshouse/mdmodel';
2
+ import { definitionsAt, governing } from './collection.js';
4
3
  function keyOf(...parts) {
5
4
  return `${parts.join('\u0000')}\u0000`;
6
5
  }
@@ -10,134 +9,69 @@ export function documentKey(room, path) {
10
9
  export function roomOfKey(key) {
11
10
  return key.split('\u0000')[1];
12
11
  }
13
- function plainObject(value) {
14
- return typeof value === 'object' && value !== null && !Array.isArray(value);
12
+ export function roomsOfReach(reach) {
13
+ return new Set([...reach.rooms, ...reach.documents.map(roomOfKey)]);
15
14
  }
16
- function compared(reading, exact, value) {
17
- if (!reading.references.has(exact))
18
- return value;
19
- return (typeof value === 'string' ? target(reading.path, value) : null) ?? undefined;
15
+ export function pathOfKey(key) {
16
+ return key.split('\u0000')[2];
20
17
  }
21
- function record(reading, node, forms, exact) {
22
- const value = Array.isArray(node)
23
- ? node.map((item, index) => compared(reading, `${exact}/${index}`, item))
24
- : compared(reading, exact, node);
25
- for (const form of forms) {
26
- if (form.pending)
27
- continue;
28
- (reading.reached[form.text] ??= []).push(value);
29
- if (!form.through && value !== undefined && !plainObject(value)) {
30
- reading.values[form.text] = value;
31
- }
32
- }
33
- if (Array.isArray(node) || plainObject(node) || !reading.references.has(exact))
34
- return;
35
- const found = compared(reading, exact, node);
36
- if (typeof found !== 'string')
37
- return;
38
- const field = forms
39
- .map((form) => form.text)
40
- .reduce((left, right) => (right.length < left.length ? right : left));
41
- const known = reading.targets.get(`${field}\u0000${found}`);
42
- const kept = known ?? { field, target: found, forms: new Set() };
43
- for (const form of forms)
44
- kept.forms.add(form.text);
45
- reading.targets.set(`${field}\u0000${found}`, kept);
18
+ export function markdownPath(path) {
19
+ return path.endsWith('.md');
46
20
  }
47
- function walk(reading, node, forms, exact) {
48
- record(reading, node, forms, exact);
49
- if (Array.isArray(node)) {
50
- node.forEach((item, index) => walk(reading, item, forms.flatMap((form) => [
51
- ...(form.pending
52
- ? []
53
- : [{ text: `${form.text}/${index}`, through: form.through, pending: false }]),
54
- { text: form.text, through: true, pending: true },
55
- ]), `${exact}/${index}`));
56
- return;
57
- }
58
- if (!plainObject(node))
59
- return;
60
- for (const [key, value] of Object.entries(node)) {
61
- const segment = escapePointer(key);
62
- walk(reading, value, forms.flatMap((form) => form.pending && ARRAY_INDEX.test(key)
63
- ? []
64
- : [{ text: `${form.text}/${segment}`, through: form.through, pending: false }]), `${exact}/${segment}`);
65
- }
21
+ export function folderOf(path) {
22
+ return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
66
23
  }
67
- function directoriesOf(path) {
68
- const parts = path.split('/').slice(0, -1);
69
- return ['', ...parts.map((_, index) => parts.slice(0, index + 1).join('/'))];
24
+ function byKey(_key, value) {
25
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
26
+ return value;
27
+ return Object.fromEntries(Object.entries(value).sort(([one], [other]) => byCodePoint(one, other)));
70
28
  }
71
- export function markdownPath(path) {
72
- return path.endsWith('.md');
29
+ function fieldsText(fields) {
30
+ return JSON.stringify(fields, byKey);
31
+ }
32
+ export function writtenFacts(path, content, composition) {
33
+ const model = governing(composition, path);
34
+ const facts = documentFacts(path, parse(content, path, definitionsAt(composition, path)), {
35
+ types: model.status === 'unavailable' ? {} : model.types,
36
+ });
37
+ return facts === null
38
+ ? null
39
+ : { ...facts, fields: JSON.parse(fieldsText(facts.fields)) };
73
40
  }
74
- export function rowsOf(room, path, document, composition, change) {
75
- const key = documentKey(room, path);
76
- const body = keyOf('b', room, path);
77
- if (document === null || !markdownPath(path)) {
78
- return [
79
- {
80
- key,
81
- kind: 'document',
82
- room,
83
- path,
84
- type: null,
85
- fields: {},
86
- values: {},
87
- reached: {},
88
- directories: directoriesOf(path),
89
- body,
90
- change,
91
- },
92
- ];
93
- }
94
- const type = document.type ?? 'any';
95
- const definition = definitionOf(governing(composition, path), document.type);
96
- const reading = {
97
- path,
98
- references: new Set(definition === undefined ? [] : references(document, definition).map((one) => one.pointer)),
99
- values: {},
100
- reached: {},
101
- targets: new Map(),
41
+ export function described(path, content, facts) {
42
+ const folder = folderOf(path);
43
+ const unread = { type: null, fields: null, links: null, folder };
44
+ if (content === null || facts === null)
45
+ return { ...unread, declared: null };
46
+ const links = JSON.stringify(facts.links);
47
+ if (!markdownPath(path))
48
+ return { ...unread, declared: facts.type, links };
49
+ return {
50
+ type: facts.type,
51
+ declared: facts.type,
52
+ folder,
53
+ fields: fieldsText(facts.fields),
54
+ links,
102
55
  };
103
- for (const [name, value] of Object.entries(document.fields)) {
104
- const segment = escapePointer(name);
105
- walk(reading, value, [{ text: `/${segment}`, through: false, pending: false }], `/${segment}`);
106
- }
107
- const { values, reached } = reading;
108
- return [
109
- {
110
- key,
111
- kind: 'document',
112
- room,
113
- path,
114
- type,
115
- fields: document.fields,
116
- values,
117
- reached,
118
- directories: directoriesOf(path),
119
- body,
120
- change,
121
- },
122
- {
123
- key: body,
124
- kind: 'body',
125
- room,
126
- path,
127
- preamble: document.preamble,
128
- sections: document.sections,
129
- markdown: document.content,
130
- },
131
- ...[...reading.targets.values()].map(({ field, target: found, forms }) => ({
132
- key: keyOf('r', room, path, field, found),
133
- kind: 'reference',
134
- room,
135
- source: key,
136
- target: documentKey(room, found),
137
- field,
138
- forms: [...forms].sort(),
139
- path,
140
- type,
141
- })),
142
- ];
56
+ }
57
+ export function heldOf(path, content, facts) {
58
+ if (content === null || facts === null)
59
+ return { type: null, fields: null, links: [] };
60
+ return markdownPath(path)
61
+ ? { type: facts.type, fields: facts.fields, links: facts.links }
62
+ : { type: null, fields: null, links: facts.links };
63
+ }
64
+ export function derived(path, held, composition) {
65
+ const stored = held.links.map((target) => ({
66
+ kind: 'link',
67
+ keys: '',
68
+ places: '',
69
+ target,
70
+ field: '',
71
+ }));
72
+ if (held.type === null || held.fields === null)
73
+ return { values: [], links: stored };
74
+ const definition = definitionsAt(composition, path)(held.type);
75
+ const { values, links: fields } = indexed(path, held.fields, definition);
76
+ return { values, links: [...fields, ...stored] };
143
77
  }
@@ -0,0 +1,34 @@
1
+ import type { RoomDeclaration, TypedPath } from './adapter.js';
2
+ import type { RuntimeShell } from './durability.js';
3
+ import type { LiveConversations } from './conversation-live.js';
4
+ import type { WriteRule } from './declaration.js';
5
+ import type { FiguresRead } from './figures.js';
6
+ import type { LiveQueries } from './live.js';
7
+ import type { ModelState } from './model.js';
8
+ import type { Presence } from './presence.js';
9
+ import type { ReadAnswers } from './reads.js';
10
+ import type { Recovery } from './recovery.js';
11
+ import type { Retries } from './retried.js';
12
+ import type { RuntimeSocket } from './socket.js';
13
+ import type { HeldCover, Store } from './store.js';
14
+ import type { schemaTypes } from './attached-model.js';
15
+ export type Runtime = {
16
+ readonly store: Store;
17
+ readonly socket: RuntimeSocket;
18
+ readonly presence: Presence;
19
+ readonly recovery: Recovery;
20
+ readonly retries: Retries;
21
+ readonly shell: RuntimeShell;
22
+ readonly localSaves: boolean;
23
+ readonly roomTypes: Parameters<typeof schemaTypes>[1];
24
+ readonly builtIn: ModelState;
25
+ readonly typedPaths: readonly TypedPath[];
26
+ readonly writeRule: (declaration: RoomDeclaration) => WriteRule;
27
+ readonly usableWhenHeld: readonly string[];
28
+ readonly build: string;
29
+ readonly conversations: LiveConversations;
30
+ readonly liveQueries: LiveQueries<HeldCover>;
31
+ readonly figures: FiguresRead;
32
+ readonly lastAnswers: ReadAnswers;
33
+ };
34
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ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