@agentshouse/mdruntime 0.1.0-c1db74d14e5fa → 0.1.0-c1e540acf5f9d

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 (389) hide show
  1. package/README.md +23 -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 +187 -124
  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 +0 -5
  17. package/dist/binary.d.ts.map +1 -1
  18. package/dist/binary.js +1 -1
  19. package/dist/bootstrap.d.ts +31 -11
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +309 -109
  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 -16
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +17 -88
  31. package/dist/change.d.ts +32 -1
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +14 -3
  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 +41 -25
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +132 -27
  40. package/dist/collection.d.ts +29 -21
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +48 -290
  43. package/dist/compile.d.ts +18 -0
  44. package/dist/compile.d.ts.map +1 -0
  45. package/dist/compile.js +724 -0
  46. package/dist/connection.d.ts +7 -129
  47. package/dist/connection.d.ts.map +1 -1
  48. package/dist/connection.js +107 -3346
  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} +1 -4
  52. package/dist/conversation-live.d.ts +147 -0
  53. package/dist/conversation-live.d.ts.map +1 -0
  54. package/dist/conversation-live.js +258 -0
  55. package/dist/conversation-row.d.ts +33 -0
  56. package/dist/conversation-row.d.ts.map +1 -0
  57. package/dist/conversation-row.js +53 -0
  58. package/dist/conversation.d.ts +80 -48
  59. package/dist/conversation.d.ts.map +1 -1
  60. package/dist/conversation.js +1079 -689
  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 +20 -4
  71. package/dist/durability.d.ts.map +1 -1
  72. package/dist/durability.js +9 -0
  73. package/dist/entry.d.ts +5 -2
  74. package/dist/entry.d.ts.map +1 -1
  75. package/dist/entry.js +33 -28
  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 +197 -0
  85. package/dist/file.d.ts +2 -19
  86. package/dist/file.d.ts.map +1 -1
  87. package/dist/file.js +7 -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 +25 -10
  92. package/dist/host.d.ts.map +1 -1
  93. package/dist/host.js +145 -33
  94. package/dist/identity.d.ts +0 -2
  95. package/dist/identity.d.ts.map +1 -1
  96. package/dist/identity.js +0 -6
  97. package/dist/index.d.ts +40 -15
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +18 -3
  100. package/dist/install.d.ts +54 -0
  101. package/dist/install.d.ts.map +1 -0
  102. package/dist/install.js +530 -0
  103. package/dist/lifecycle.d.ts +7 -0
  104. package/dist/lifecycle.d.ts.map +1 -0
  105. package/dist/lifecycle.js +277 -0
  106. package/dist/listing.d.ts +48 -0
  107. package/dist/listing.d.ts.map +1 -0
  108. package/dist/listing.js +139 -0
  109. package/dist/live.d.ts +23 -0
  110. package/dist/live.d.ts.map +1 -0
  111. package/dist/live.js +165 -0
  112. package/dist/locks.d.ts +7 -0
  113. package/dist/locks.d.ts.map +1 -0
  114. package/dist/locks.js +32 -0
  115. package/dist/lost.d.ts +5 -0
  116. package/dist/lost.d.ts.map +1 -0
  117. package/dist/lost.js +49 -0
  118. package/dist/media.d.ts +8 -0
  119. package/dist/media.d.ts.map +1 -0
  120. package/dist/media.js +218 -0
  121. package/dist/memory.d.ts +24 -8
  122. package/dist/memory.d.ts.map +1 -1
  123. package/dist/memory.js +291 -116
  124. package/dist/messages.d.ts +56 -0
  125. package/dist/messages.d.ts.map +1 -0
  126. package/dist/messages.js +158 -0
  127. package/dist/model.d.ts +11 -13
  128. package/dist/model.d.ts.map +1 -1
  129. package/dist/model.js +7 -24
  130. package/dist/models.d.ts +10 -0
  131. package/dist/models.d.ts.map +1 -0
  132. package/dist/models.js +153 -0
  133. package/dist/name.d.ts +4 -0
  134. package/dist/name.d.ts.map +1 -0
  135. package/dist/name.js +122 -0
  136. package/dist/observation.d.ts +19 -3
  137. package/dist/observation.d.ts.map +1 -1
  138. package/dist/observation.js +116 -20
  139. package/dist/opened.d.ts +22 -0
  140. package/dist/opened.d.ts.map +1 -0
  141. package/dist/opened.js +107 -0
  142. package/dist/opening.d.ts +4 -0
  143. package/dist/opening.d.ts.map +1 -0
  144. package/dist/opening.js +53 -0
  145. package/dist/outcome.d.ts +52 -8
  146. package/dist/outcome.d.ts.map +1 -1
  147. package/dist/outcome.js +57 -0
  148. package/dist/overlay.d.ts +8 -5
  149. package/dist/overlay.d.ts.map +1 -1
  150. package/dist/overlay.js +131 -166
  151. package/dist/page-metadata.d.ts +8 -0
  152. package/dist/page-metadata.d.ts.map +1 -0
  153. package/dist/page-metadata.js +19 -0
  154. package/dist/parts.d.ts +4 -0
  155. package/dist/parts.d.ts.map +1 -0
  156. package/dist/parts.js +13 -0
  157. package/dist/paths.d.ts +2 -0
  158. package/dist/paths.d.ts.map +1 -1
  159. package/dist/paths.js +26 -0
  160. package/dist/preparation.d.ts +20 -0
  161. package/dist/preparation.d.ts.map +1 -0
  162. package/dist/preparation.js +227 -0
  163. package/dist/presence.d.ts +52 -0
  164. package/dist/presence.d.ts.map +1 -0
  165. package/dist/presence.js +220 -0
  166. package/dist/queries.d.ts +16 -0
  167. package/dist/queries.d.ts.map +1 -0
  168. package/dist/queries.js +282 -0
  169. package/dist/query.d.ts +27 -186
  170. package/dist/query.d.ts.map +1 -1
  171. package/dist/query.js +3 -464
  172. package/dist/{chat/questions.d.ts → questions.d.ts} +5 -7
  173. package/dist/questions.d.ts.map +1 -0
  174. package/dist/{chat/questions.js → questions.js} +11 -7
  175. package/dist/queue.d.ts +40 -0
  176. package/dist/queue.d.ts.map +1 -0
  177. package/dist/queue.js +450 -0
  178. package/dist/reach.d.ts +19 -9
  179. package/dist/reach.d.ts.map +1 -1
  180. package/dist/reach.js +341 -108
  181. package/dist/react.d.ts +19 -5
  182. package/dist/react.d.ts.map +1 -1
  183. package/dist/react.js +40 -18
  184. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  185. package/dist/read.d.ts.map +1 -0
  186. package/dist/{chat/read.js → read.js} +4 -0
  187. package/dist/readiness.d.ts +14 -18
  188. package/dist/readiness.d.ts.map +1 -1
  189. package/dist/readiness.js +2 -8
  190. package/dist/reads.d.ts +39 -0
  191. package/dist/reads.d.ts.map +1 -0
  192. package/dist/reads.js +178 -0
  193. package/dist/recovery.d.ts +5 -2
  194. package/dist/recovery.d.ts.map +1 -1
  195. package/dist/recovery.js +65 -8
  196. package/dist/refresh.d.ts +17 -14
  197. package/dist/refresh.d.ts.map +1 -1
  198. package/dist/refresh.js +145 -54
  199. package/dist/refusal.d.ts +5 -0
  200. package/dist/refusal.d.ts.map +1 -0
  201. package/dist/refusal.js +55 -0
  202. package/dist/replica.d.ts +50 -33
  203. package/dist/replica.d.ts.map +1 -1
  204. package/dist/replica.js +338 -189
  205. package/dist/retried.d.ts +30 -0
  206. package/dist/retried.d.ts.map +1 -0
  207. package/dist/retried.js +72 -0
  208. package/dist/room-draft.d.ts +39 -10
  209. package/dist/room-draft.d.ts.map +1 -1
  210. package/dist/room-draft.js +194 -118
  211. package/dist/room-drafts.d.ts +24 -0
  212. package/dist/room-drafts.d.ts.map +1 -0
  213. package/dist/room-drafts.js +217 -0
  214. package/dist/rows.d.ts +31 -29
  215. package/dist/rows.d.ts.map +1 -1
  216. package/dist/rows.js +60 -118
  217. package/dist/runtime.d.ts +34 -0
  218. package/dist/runtime.d.ts.map +1 -0
  219. package/dist/runtime.js +1 -0
  220. package/dist/save.d.ts +43 -48
  221. package/dist/save.d.ts.map +1 -1
  222. package/dist/save.js +791 -274
  223. package/dist/saves.d.ts +32 -0
  224. package/dist/saves.d.ts.map +1 -0
  225. package/dist/saves.js +410 -0
  226. package/dist/search.d.ts +15 -77
  227. package/dist/search.d.ts.map +1 -1
  228. package/dist/search.js +10 -184
  229. package/dist/seed.d.ts +25 -0
  230. package/dist/seed.d.ts.map +1 -0
  231. package/dist/seed.js +145 -0
  232. package/dist/shared.d.ts +6 -7
  233. package/dist/shared.d.ts.map +1 -1
  234. package/dist/shared.js +75 -104
  235. package/dist/shown.d.ts +33 -0
  236. package/dist/shown.d.ts.map +1 -0
  237. package/dist/shown.js +302 -0
  238. package/dist/socket/admission.d.ts +7 -0
  239. package/dist/socket/admission.d.ts.map +1 -0
  240. package/dist/socket/admission.js +39 -0
  241. package/dist/socket/answers.d.ts +6 -0
  242. package/dist/socket/answers.d.ts.map +1 -0
  243. package/dist/socket/answers.js +20 -0
  244. package/dist/socket/lanes.d.ts +28 -0
  245. package/dist/socket/lanes.d.ts.map +1 -0
  246. package/dist/socket/lanes.js +103 -0
  247. package/dist/socket/reads.d.ts +10 -0
  248. package/dist/socket/reads.d.ts.map +1 -0
  249. package/dist/socket/reads.js +31 -0
  250. package/dist/socket/session.d.ts +38 -0
  251. package/dist/socket/session.d.ts.map +1 -0
  252. package/dist/socket/session.js +23 -0
  253. package/dist/socket.d.ts +67 -0
  254. package/dist/socket.d.ts.map +1 -0
  255. package/dist/socket.js +164 -0
  256. package/dist/source.d.ts +54 -0
  257. package/dist/source.d.ts.map +1 -0
  258. package/dist/source.js +82 -0
  259. package/dist/status.d.ts +4 -5
  260. package/dist/status.d.ts.map +1 -1
  261. package/dist/status.js +3 -7
  262. package/dist/store/installs.d.ts +30 -0
  263. package/dist/store/installs.d.ts.map +1 -0
  264. package/dist/store/installs.js +34 -0
  265. package/dist/store/readiness.d.ts +10 -0
  266. package/dist/store/readiness.d.ts.map +1 -0
  267. package/dist/store/readiness.js +52 -0
  268. package/dist/store/records.d.ts +215 -0
  269. package/dist/store/records.d.ts.map +1 -0
  270. package/dist/store/records.js +439 -0
  271. package/dist/store/room-held.d.ts +8 -0
  272. package/dist/store/room-held.d.ts.map +1 -0
  273. package/dist/store/room-held.js +17 -0
  274. package/dist/store/space.d.ts +11 -0
  275. package/dist/store/space.d.ts.map +1 -0
  276. package/dist/store/space.js +41 -0
  277. package/dist/store/watchers.d.ts +17 -0
  278. package/dist/store/watchers.d.ts.map +1 -0
  279. package/dist/store/watchers.js +56 -0
  280. package/dist/store/writes.d.ts +24 -0
  281. package/dist/store/writes.d.ts.map +1 -0
  282. package/dist/store/writes.js +125 -0
  283. package/dist/store.d.ts +111 -148
  284. package/dist/store.d.ts.map +1 -1
  285. package/dist/store.js +159 -698
  286. package/dist/stored.d.ts +157 -0
  287. package/dist/stored.d.ts.map +1 -0
  288. package/dist/stored.js +649 -0
  289. package/dist/surface.d.ts +89 -0
  290. package/dist/surface.d.ts.map +1 -0
  291. package/dist/surface.js +222 -0
  292. package/dist/sync.d.ts +19 -0
  293. package/dist/sync.d.ts.map +1 -0
  294. package/dist/sync.js +535 -0
  295. package/dist/tables.d.ts +415 -0
  296. package/dist/tables.d.ts.map +1 -0
  297. package/dist/tables.js +761 -0
  298. package/dist/tallies.d.ts +18 -0
  299. package/dist/tallies.d.ts.map +1 -0
  300. package/dist/tallies.js +128 -0
  301. package/dist/transfer.d.ts +0 -5
  302. package/dist/transfer.d.ts.map +1 -1
  303. package/dist/turn.d.ts +5 -3
  304. package/dist/turn.d.ts.map +1 -1
  305. package/dist/turn.js +51 -21
  306. package/dist/validation.d.ts +29 -0
  307. package/dist/validation.d.ts.map +1 -0
  308. package/dist/validation.js +104 -0
  309. package/dist/windows.d.ts +11 -0
  310. package/dist/windows.d.ts.map +1 -0
  311. package/dist/windows.js +16 -0
  312. package/dist/wire.d.ts +228 -37
  313. package/dist/wire.d.ts.map +1 -1
  314. package/dist/wire.js +75 -34
  315. package/package.json +19 -19
  316. package/AGENTS.md +0 -300
  317. package/dist/acquisition.d.ts +0 -14
  318. package/dist/acquisition.d.ts.map +0 -1
  319. package/dist/acquisition.js +0 -24
  320. package/dist/attempt.d.ts +0 -16
  321. package/dist/attempt.d.ts.map +0 -1
  322. package/dist/attempt.js +0 -70
  323. package/dist/chat/acts.d.ts +0 -33
  324. package/dist/chat/acts.d.ts.map +0 -1
  325. package/dist/chat/acts.js +0 -36
  326. package/dist/chat/context.d.ts +0 -3
  327. package/dist/chat/context.d.ts.map +0 -1
  328. package/dist/chat/input.d.ts +0 -9
  329. package/dist/chat/input.d.ts.map +0 -1
  330. package/dist/chat/input.js +0 -99
  331. package/dist/chat/kit.d.ts +0 -60
  332. package/dist/chat/kit.d.ts.map +0 -1
  333. package/dist/chat/kit.js +0 -123
  334. package/dist/chat/lasting.d.ts +0 -6
  335. package/dist/chat/lasting.d.ts.map +0 -1
  336. package/dist/chat/lasting.js +0 -19
  337. package/dist/chat/list.d.ts +0 -26
  338. package/dist/chat/list.d.ts.map +0 -1
  339. package/dist/chat/list.js +0 -62
  340. package/dist/chat/markdown.d.ts +0 -20
  341. package/dist/chat/markdown.d.ts.map +0 -1
  342. package/dist/chat/markdown.js +0 -188
  343. package/dist/chat/message.d.ts +0 -6
  344. package/dist/chat/message.d.ts.map +0 -1
  345. package/dist/chat/message.js +0 -192
  346. package/dist/chat/messages.d.ts +0 -21
  347. package/dist/chat/messages.d.ts.map +0 -1
  348. package/dist/chat/messages.js +0 -151
  349. package/dist/chat/name.d.ts +0 -6
  350. package/dist/chat/name.d.ts.map +0 -1
  351. package/dist/chat/name.js +0 -37
  352. package/dist/chat/opened.d.ts +0 -11
  353. package/dist/chat/opened.d.ts.map +0 -1
  354. package/dist/chat/opened.js +0 -17
  355. package/dist/chat/overlay.d.ts +0 -31
  356. package/dist/chat/overlay.d.ts.map +0 -1
  357. package/dist/chat/overlay.js +0 -97
  358. package/dist/chat/parts.d.ts +0 -57
  359. package/dist/chat/parts.d.ts.map +0 -1
  360. package/dist/chat/parts.js +0 -119
  361. package/dist/chat/process.d.ts +0 -20
  362. package/dist/chat/process.d.ts.map +0 -1
  363. package/dist/chat/process.js +0 -32
  364. package/dist/chat/provider.d.ts +0 -63
  365. package/dist/chat/provider.d.ts.map +0 -1
  366. package/dist/chat/provider.js +0 -620
  367. package/dist/chat/question.d.ts +0 -9
  368. package/dist/chat/question.d.ts.map +0 -1
  369. package/dist/chat/question.js +0 -80
  370. package/dist/chat/questions.d.ts.map +0 -1
  371. package/dist/chat/read.d.ts.map +0 -1
  372. package/dist/chat/ready.d.ts +0 -33
  373. package/dist/chat/ready.d.ts.map +0 -1
  374. package/dist/chat/ready.js +0 -91
  375. package/dist/chat/style.d.ts +0 -4
  376. package/dist/chat/style.d.ts.map +0 -1
  377. package/dist/chat/style.js +0 -302
  378. package/dist/chat.d.ts +0 -14
  379. package/dist/chat.d.ts.map +0 -1
  380. package/dist/chat.js +0 -8
  381. package/dist/fence.d.ts +0 -6
  382. package/dist/fence.d.ts.map +0 -1
  383. package/dist/fence.js +0 -10
  384. package/dist/log.d.ts +0 -5
  385. package/dist/log.d.ts.map +0 -1
  386. package/dist/log.js +0 -14
  387. package/dist/read-side.d.ts +0 -25
  388. package/dist/read-side.d.ts.map +0 -1
  389. package/dist/read-side.js +0 -639
package/dist/memory.js CHANGED
@@ -1,7 +1,13 @@
1
+ import { definitionAt, documentFacts, parse } from '@agentshouse/mdmodel';
2
+ import { NO_ROOM_TYPES, schemaTypes } from './attached-model.js';
3
+ import { selected } from './collection.js';
1
4
  import { sameChange } from './overlay.js';
5
+ const ATTACHMENTS = 'attachments';
6
+ function lastName(path) {
7
+ return path.slice(path.lastIndexOf('/') + 1);
8
+ }
2
9
  const FIXTURE_RETENTION = {
3
10
  history: { kind: 'duration', seconds: 1 },
4
- outcome: 604_800,
5
11
  refreshHorizon: 1,
6
12
  };
7
13
  function declaredRetention(value) {
@@ -15,12 +21,7 @@ function declaredRetention(value) {
15
21
  }
16
22
  const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
17
23
  function modelsOf(room) {
18
- return {
19
- collection: room.model ?? MODEL_ABSENT,
20
- ...(room.typedSelection === undefined
21
- ? {}
22
- : { selection: room.selectionModel ?? MODEL_ABSENT }),
23
- };
24
+ return { collection: room.model ?? MODEL_ABSENT };
24
25
  }
25
26
  function changedModels(room, from) {
26
27
  const now = modelsOf(room);
@@ -53,14 +54,17 @@ export function createMemoryAdapter(options = {}) {
53
54
  const listeners = new Set();
54
55
  const modeObservers = new Set();
55
56
  const scripted = new Map();
56
- const unsealed = new Map();
57
- const sealed = new Set();
58
- const sentTurns = new Map();
57
+ const repeats = new Map();
59
58
  const historyPageSize = options.historyPageSize;
60
- let held = [];
61
- let heldDemand = null;
59
+ const attached = new Map();
60
+ const linked = new WeakMap();
61
+ const carried = new Map();
62
62
  let expiring = [];
63
+ let openings = 0;
64
+ const declaredRooms = new Set();
63
65
  let replicated = [];
66
+ let heldCursor = null;
67
+ let agents = structuredClone(options.agents ?? []);
64
68
  let issued = 0;
65
69
  function scriptConversations(entries) {
66
70
  scripted.clear();
@@ -88,8 +92,53 @@ export function createMemoryAdapter(options = {}) {
88
92
  const wanted = ordinals.get(`${locator}\u0000${target}`);
89
93
  return held !== undefined && wanted !== undefined && held >= wanted;
90
94
  }
95
+ function heldBlob(room, path) {
96
+ return attached.get(`${room.locator}\u0000${path}`) ?? room.blobs?.[path];
97
+ }
98
+ function freePath(room, name) {
99
+ const dot = name.lastIndexOf('.');
100
+ const stem = dot > 0 ? name.slice(0, dot) : name;
101
+ const extension = dot > 0 ? name.slice(dot) : '';
102
+ for (let count = 1;; count += 1) {
103
+ const path = `${ATTACHMENTS}/${count === 1 ? stem : `${stem}-${count}`}${extension}`;
104
+ if (heldBlob(room, path) === undefined && room.documents?.[path] === undefined)
105
+ return path;
106
+ }
107
+ }
108
+ const saved = new WeakMap();
109
+ const roomTypes = options.roomTypes ?? NO_ROOM_TYPES;
110
+ function factsAt(room, path, content) {
111
+ const types = selected({ selection: room.typedSelection ?? null }, path)
112
+ ? roomTypes.types
113
+ : schemaTypes(room.model?.kind === 'model' ? room.model.snapshot.schema : null, roomTypes);
114
+ let held = saved.get(types);
115
+ if (held === undefined) {
116
+ held = new Map();
117
+ saved.set(types, held);
118
+ }
119
+ const key = `${path}\u0000${content}`;
120
+ if (!held.has(key)) {
121
+ const facts = documentFacts(path, parse(content, path, definitionAt({ types }, path, options.typedPaths)), {
122
+ types,
123
+ });
124
+ held.set(key, facts === null ? null : JSON.parse(JSON.stringify(facts)));
125
+ }
126
+ return held.get(key);
127
+ }
128
+ function factsIn(room, paths) {
129
+ const facts = {};
130
+ for (const path of paths) {
131
+ const content = room.documents?.[path];
132
+ const held = room.facts?.[path] ?? (content === undefined ? null : factsAt(room, path, content));
133
+ if (held !== null)
134
+ facts[path] = held;
135
+ }
136
+ return facts;
137
+ }
91
138
  function retain(entries) {
92
139
  for (const room of entries) {
140
+ for (const [path, content] of Object.entries(room.documents ?? {}))
141
+ factsAt(room, path, content);
93
142
  note(room.locator, room);
94
143
  const versions = served.get(room.locator) ?? new Map();
95
144
  versions.set(room.roomVersion, room);
@@ -105,8 +154,9 @@ export function createMemoryAdapter(options = {}) {
105
154
  roomVersion: room.roomVersion,
106
155
  operations: room.operations,
107
156
  replica: room.replica,
108
- ...(room.typedSelection === undefined ? {} : { typedSelection: room.typedSelection }),
157
+ typedSelection: room.typedSelection ?? null,
109
158
  providerOwnedPaths: room.providerOwnedPaths,
159
+ authoredPaths: room.authoredPaths ?? ['**'],
110
160
  };
111
161
  }
112
162
  function page(room, after) {
@@ -122,23 +172,43 @@ export function createMemoryAdapter(options = {}) {
122
172
  roomVersion: room.roomVersion,
123
173
  ...(opening ? { models: modelsOf(room) } : {}),
124
174
  documents: named(room.documents ?? {}, taken),
175
+ facts: factsIn(room, taken),
125
176
  revisions: named(room.revisions ?? {}, [...taken, ...targets]),
177
+ ...(room.fileIds === undefined
178
+ ? {}
179
+ : { fileIds: named(room.fileIds, [...taken, ...targets]) }),
180
+ ...(room.created === undefined
181
+ ? {}
182
+ : { created: named(room.created, [...taken, ...targets]) }),
126
183
  changes: named(room.changes ?? {}, [...taken, ...targets]),
127
184
  binaryFiles: named(room.binaryFiles ?? {}, targets),
185
+ ...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
128
186
  ...(next < paths.length ? { pageToken: taken.at(-1) } : {}),
129
187
  };
130
188
  }
131
- function advancement(room, from, at) {
189
+ function foldersMoved(room, from) {
190
+ const now = new Set(room.folders ?? []);
191
+ const before = new Set(from.folders ?? []);
192
+ const folders = [...now].filter((folder) => !before.has(folder)).sort();
193
+ const folderRemovals = [...before].filter((folder) => !now.has(folder)).sort();
194
+ return {
195
+ ...(folders.length === 0 ? {} : { folders }),
196
+ ...(folderRemovals.length === 0 ? {} : { folderRemovals }),
197
+ };
198
+ }
199
+ function advancement(room, from, at, whole = false) {
132
200
  const current = room.documents ?? {};
133
201
  const previous = from.documents ?? {};
134
202
  const currentTargets = new Set(Object.keys(room.binaryFiles ?? {}));
135
203
  const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
136
204
  const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
205
+ room.fileIds?.[path] !== from.fileIds?.[path] ||
206
+ room.created?.[path] !== from.created?.[path] ||
137
207
  !sameChange(room.changes?.[path], from.changes?.[path]);
138
208
  const changed = Object.keys(current)
139
209
  .filter((path) => current[path] !== previous[path] || headMoved(path))
140
210
  .sort();
141
- const size = pageSize ?? changed.length;
211
+ const size = whole ? changed.length : (pageSize ?? changed.length);
142
212
  const taken = changed.slice(at, at + size);
143
213
  const next = at + taken.length;
144
214
  const opening = at === 0;
@@ -154,9 +224,17 @@ export function createMemoryAdapter(options = {}) {
154
224
  roomVersion: room.roomVersion,
155
225
  ...(models === undefined ? {} : { models }),
156
226
  documents: named(current, taken),
227
+ facts: factsIn(room, taken),
157
228
  revisions: named(room.revisions ?? {}, [...taken, ...targets]),
229
+ ...(room.fileIds === undefined
230
+ ? {}
231
+ : { fileIds: named(room.fileIds, [...taken, ...targets]) }),
232
+ ...(room.created === undefined
233
+ ? {}
234
+ : { created: named(room.created, [...taken, ...targets]) }),
158
235
  changes: named(room.changes ?? {}, [...taken, ...targets]),
159
236
  binaryFiles: named(room.binaryFiles ?? {}, targets),
237
+ ...(opening ? foldersMoved(room, from) : {}),
160
238
  removals: opening
161
239
  ? [
162
240
  ...Object.keys(previous).filter((path) => !(path in current) && !currentTargets.has(path)),
@@ -166,30 +244,45 @@ export function createMemoryAdapter(options = {}) {
166
244
  ...(pageToken === undefined ? {} : { pageToken }),
167
245
  };
168
246
  }
247
+ function carry(locator) {
248
+ const at = carried.get(locator);
249
+ const current = rooms.find((entry) => entry.locator === locator);
250
+ if (at === undefined || current === undefined || current.roomVersion === at)
251
+ return;
252
+ const from = served.get(locator)?.get(at);
253
+ carried.set(locator, current.roomVersion);
254
+ if (from === undefined)
255
+ return;
256
+ const page = advancement(current, from, 0, true);
257
+ for (const observer of observers) {
258
+ observer({
259
+ kind: 'room-change',
260
+ locator,
261
+ from: at,
262
+ roomVersion: current.roomVersion,
263
+ read: async () => page,
264
+ });
265
+ }
266
+ }
169
267
  function pageOf(conversation, after) {
170
268
  const messages = conversation.messages ?? [];
171
- const first = typeof after === 'string' ? messages.findIndex((message) => message.position > after) : 0;
269
+ const first = typeof after === 'string' ? messages.findIndex((message) => message.change > after) : 0;
172
270
  const from = first === -1 ? messages.length : first;
173
271
  const page = messages.slice(from, from + (historyPageSize ?? messages.length));
174
272
  const last = page.at(-1);
175
273
  return {
176
274
  conversation: conversation.conversation,
177
275
  messages: page,
178
- ...(last !== undefined && from + page.length < messages.length
179
- ? { next: last.position }
180
- : {}),
276
+ ...(last !== undefined && from + page.length < messages.length ? { next: last.change } : {}),
181
277
  };
182
278
  }
183
- function historiesOf(input) {
184
- const asked = input?.conversations;
185
- if (!Array.isArray(asked))
186
- return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
279
+ function historiesOf(request) {
187
280
  const histories = [];
188
- for (const entry of asked) {
189
- const conversation = typeof entry.conversation === 'string' ? scripted.get(entry.conversation) : undefined;
281
+ for (const entry of request.conversations) {
282
+ const conversation = scripted.get(entry.conversation);
190
283
  if (conversation === undefined)
191
284
  continue;
192
- const outcome = conversation.outcomes?.['conversation.history'];
285
+ const outcome = conversation.outcomes?.history;
193
286
  if (outcome !== undefined)
194
287
  return outcome;
195
288
  histories.push(pageOf(conversation, entry.after));
@@ -200,15 +293,22 @@ export function createMemoryAdapter(options = {}) {
200
293
  function conversationAction(request) {
201
294
  const name = request.name;
202
295
  const input = (request.input ?? {});
203
- if (name === 'conversation.history')
204
- return historiesOf(request.input);
205
- if (name === 'conversation.create') {
296
+ const operation = typeof input.operation_id === 'string' ? `${name}\u0000${input.operation_id}` : null;
297
+ const first = (answer) => {
298
+ if (operation !== null)
299
+ repeats.set(operation, answer);
300
+ return answer;
301
+ };
302
+ const repeated = operation === null ? undefined : repeats.get(operation);
303
+ if (name === 'conversations/create') {
304
+ if (repeated !== undefined)
305
+ return repeated;
206
306
  issued += 1;
207
307
  const conversation = `conversation-${issued}`;
208
308
  scripted.set(conversation, { conversation });
209
- return { kind: 'action', result: { conversation } };
309
+ return first({ kind: 'action', result: { conversation_id: conversation } });
210
310
  }
211
- const named = typeof input.conversation === 'string' ? input.conversation : '';
311
+ const named = typeof input.conversation_id === 'string' ? input.conversation_id : '';
212
312
  const conversation = scripted.get(named);
213
313
  if (conversation === undefined) {
214
314
  return {
@@ -221,34 +321,41 @@ export function createMemoryAdapter(options = {}) {
221
321
  const outcome = conversation.outcomes?.[name];
222
322
  if (outcome !== undefined)
223
323
  return outcome;
224
- if (name === 'conversation.send') {
225
- const operation = typeof input.operation_id === 'string' ? input.operation_id : null;
226
- const answered = operation === null ? undefined : sentTurns.get(operation);
227
- if (answered !== undefined)
228
- return { kind: 'action', result: { turn: answered } };
324
+ if (name === 'conversations/send') {
325
+ if (repeated !== undefined)
326
+ return repeated;
229
327
  issued += 1;
230
- const turn = `turn-${issued}`;
231
- unsealed.set(turn, named);
232
- if (operation !== null)
233
- sentTurns.set(operation, turn);
234
- return { kind: 'action', result: { turn } };
235
- }
236
- if (name === 'conversation.cancel') {
237
- const turn = typeof input.turn === 'string' ? input.turn : '';
238
- if (sealed.has(turn) || !unsealed.has(turn)) {
239
- return { kind: 'rejected', code: 'turn-sealed', fields: { turn }, retryable: false };
240
- }
241
- unsealed.delete(turn);
242
- return { kind: 'action', result: { turn, cancelled: true } };
328
+ return first({ kind: 'action', result: { message_id: `turn-${issued}` } });
243
329
  }
244
- if (name === 'conversation.delete')
330
+ if (name === 'conversations/delete')
245
331
  scripted.delete(named);
246
- return { kind: 'action', result: { conversation: named } };
332
+ return { kind: 'action', result: { conversation_id: named } };
333
+ }
334
+ function decided(request) {
335
+ const { request: asked, message, decision, } = (request.input ?? {});
336
+ return {
337
+ kind: 'action',
338
+ result: {
339
+ request: asked,
340
+ ...(message === undefined ? {} : { message }),
341
+ state: decision === 'approve' ? 'started' : 'declined',
342
+ },
343
+ };
247
344
  }
248
345
  function announceList() {
249
- const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined ? [] : [{ conversation, ...listed }]);
250
- for (const listener of listeners)
251
- listener({ kind: 'list', entries });
346
+ const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
347
+ ? []
348
+ : [{ conversation, ...listed, newest: messages.at(-1)?.change ?? null }]);
349
+ for (const listener of listeners) {
350
+ listener({
351
+ kind: 'list',
352
+ agents: structuredClone(agents),
353
+ entries,
354
+ whole: true,
355
+ more: false,
356
+ cursor: null,
357
+ });
358
+ }
252
359
  }
253
360
  function discovery() {
254
361
  return {
@@ -260,8 +367,42 @@ export function createMemoryAdapter(options = {}) {
260
367
  ...(options.member === undefined ? {} : { member: options.member }),
261
368
  };
262
369
  }
370
+ function discovered() {
371
+ return resolveScript(scripts.discover, discovery, undefined).then((answer) => {
372
+ if (answer.kind === 'discovery')
373
+ for (const room of answer.rooms)
374
+ note(room.locator, room);
375
+ return answer;
376
+ });
377
+ }
378
+ function opened(notify) {
379
+ const opening = ++openings;
380
+ notify({ kind: 'opened' });
381
+ void discovered()
382
+ .catch(() => ({ kind: 'transport-uncertainty' }))
383
+ .then((answer) => {
384
+ if (opening !== openings)
385
+ return;
386
+ if (answer.kind !== 'discovery') {
387
+ openings += 1;
388
+ carried.clear();
389
+ const revoked = answer.kind === 'revoked-authorization';
390
+ notify({ kind: 'closed', revoked, lost: !revoked, authorityChanged: false });
391
+ return;
392
+ }
393
+ declaredRooms.clear();
394
+ for (const room of answer.rooms)
395
+ declaredRooms.add(room.locator);
396
+ notify({ kind: 'discovered', discovery: answer });
397
+ });
398
+ }
399
+ function emitAll(event) {
400
+ for (const observer of observers)
401
+ observer(event);
402
+ }
263
403
  return {
264
- ...(options.exhaustiveDiscovery === undefined ? {} : { exhaustiveDiscovery: true }),
404
+ ...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
405
+ ...(options.typedPaths === undefined ? {} : { typedPaths: options.typedPaths }),
265
406
  setRooms(next) {
266
407
  rooms = [...next];
267
408
  retain(rooms);
@@ -269,27 +410,41 @@ export function createMemoryAdapter(options = {}) {
269
410
  setConversations(next) {
270
411
  scriptConversations(next);
271
412
  },
413
+ setAgents(next) {
414
+ agents = structuredClone(next);
415
+ },
272
416
  open() {
417
+ carried.clear();
273
418
  announceList();
274
- for (const observer of observers)
275
- observer({ kind: 'opened' });
419
+ opened(emitAll);
276
420
  },
277
- close(revoked = false) {
278
- for (const observer of observers)
279
- observer({ kind: 'closed', revoked });
421
+ close({ revoked = false, lost = !revoked, authorityChanged = false } = {}) {
422
+ openings += 1;
423
+ carried.clear();
424
+ emitAll({ kind: 'closed', revoked, lost, authorityChanged });
280
425
  },
281
426
  expire(locators) {
282
427
  expiring = [...locators];
283
428
  },
284
- notifyRoomVersion({ locator, roomVersion }) {
285
- for (const observer of observers)
286
- observer({ kind: 'room-version', locator, roomVersion });
429
+ notifyRoomVersion({ locator }) {
430
+ carry(locator);
431
+ },
432
+ notifyAuthorityChanged(locators) {
433
+ const named = new Set(locators ?? [...declaredRooms, ...rooms.map((room) => room.locator)]);
434
+ const listed = rooms.filter((room) => named.has(room.locator));
435
+ const left = [...named].filter((locator) => !listed.some((room) => room.locator === locator));
436
+ for (const room of listed)
437
+ declaredRooms.add(room.locator);
438
+ for (const locator of left)
439
+ declaredRooms.delete(locator);
440
+ emitAll({
441
+ kind: 'authority-changed',
442
+ rooms: listed.map(declared),
443
+ left,
444
+ ...(options.member === undefined ? {} : { member: options.member }),
445
+ });
287
446
  },
288
447
  notifyConversation(event) {
289
- if (event.kind === 'accepted-message') {
290
- sealed.add(event.message.turn);
291
- unsealed.delete(event.message.turn);
292
- }
293
448
  for (const listener of listeners)
294
449
  listener(event);
295
450
  },
@@ -298,24 +453,28 @@ export function createMemoryAdapter(options = {}) {
298
453
  observer(mode);
299
454
  },
300
455
  heldRooms() {
301
- return held;
302
- },
303
- heldDemand() {
304
- return heldDemand;
456
+ return [...carried.keys()].sort();
305
457
  },
306
458
  replicatedConversations() {
307
459
  return replicated;
308
460
  },
461
+ heldConversationCursor() {
462
+ return heldCursor;
463
+ },
309
464
  conversations: {
310
465
  replicate(next) {
311
466
  replicated = [...next];
312
467
  },
468
+ hold(cursor) {
469
+ heldCursor = cursor;
470
+ },
313
471
  observe(notify) {
314
472
  listeners.add(notify);
315
473
  return () => {
316
474
  listeners.delete(notify);
317
475
  };
318
476
  },
477
+ history: (request) => Promise.resolve(historiesOf(request)),
319
478
  },
320
479
  serviceMode: {
321
480
  observe(notify) {
@@ -326,45 +485,47 @@ export function createMemoryAdapter(options = {}) {
326
485
  },
327
486
  },
328
487
  roomStream: {
329
- hold(asked, demand) {
330
- held = asked.map((room) => room.locator);
331
- heldDemand = demand;
332
- const expired = expiring.filter((locator) => held.includes(locator));
333
- expiring = [];
334
- const moved = asked.flatMap((room) => {
488
+ hold(asked) {
489
+ const named = asked.map((room) => room.locator);
490
+ const unknown = asked.flatMap((room) => {
335
491
  const current = rooms.find((entry) => entry.locator === room.locator);
492
+ const version = room.roomVersion;
336
493
  return current === undefined ||
337
- expired.includes(room.locator) ||
338
- current.roomVersion === room.roomVersion
494
+ (version !== null &&
495
+ (current.roomVersion === version || served.get(room.locator)?.has(version) === true))
339
496
  ? []
340
- : [{ locator: room.locator, roomVersion: current.roomVersion }];
497
+ : [room.locator];
341
498
  });
499
+ const expired = [
500
+ ...new Set([...expiring.filter((locator) => named.includes(locator)), ...unknown]),
501
+ ];
502
+ expiring = expiring.filter((locator) => !named.includes(locator));
342
503
  queueMicrotask(() => {
343
- for (const observer of observers) {
344
- for (const room of moved)
345
- observer({ kind: 'room-version', ...room });
346
- observer({ kind: 'opening', expired });
504
+ for (const room of asked) {
505
+ if (expired.includes(room.locator) || room.roomVersion === null)
506
+ carried.delete(room.locator);
507
+ else {
508
+ carried.set(room.locator, room.roomVersion);
509
+ carry(room.locator);
510
+ }
347
511
  }
512
+ emitAll({ kind: 'caught-up', expired });
348
513
  });
349
514
  },
350
- reopen() {
351
- queueMicrotask(() => {
352
- for (const observer of observers)
353
- observer({ kind: 'closed', revoked: false });
354
- });
355
- },
356
- published() { },
357
515
  observe(notify) {
358
516
  observers.add(notify);
359
517
  queueMicrotask(() => {
360
518
  if (!observers.has(notify))
361
519
  return;
362
520
  if (options.unopened === true) {
363
- notify({ kind: 'closed', revoked: false });
521
+ notify({ kind: 'closed', revoked: false, lost: true, authorityChanged: false });
364
522
  return;
365
523
  }
366
524
  announceList();
367
- notify({ kind: 'opened' });
525
+ opened((event) => {
526
+ if (observers.has(notify))
527
+ notify(event);
528
+ });
368
529
  });
369
530
  return () => {
370
531
  observers.delete(notify);
@@ -381,12 +542,7 @@ export function createMemoryAdapter(options = {}) {
381
542
  return resolveScript(scripts.authorize, () => ({}), undefined);
382
543
  },
383
544
  async discover(_authorization) {
384
- return resolveScript(scripts.discover, discovery, undefined).then((answer) => {
385
- if (answer.kind === 'discovery')
386
- for (const room of answer.rooms)
387
- note(room.locator, room);
388
- return answer;
389
- });
545
+ return discovered();
390
546
  },
391
547
  reached,
392
548
  follows(locator, roomVersion, next) {
@@ -443,7 +599,13 @@ export function createMemoryAdapter(options = {}) {
443
599
  retryable: false,
444
600
  affected: {},
445
601
  };
446
- }, request).then((answer) => note(request.locator, answer));
602
+ }, request).then((answer) => {
603
+ const destination = request.changeBatch.between?.destination.room;
604
+ if (answer.kind === 'accepted' && answer.destination !== undefined && destination) {
605
+ note(destination, answer.destination);
606
+ }
607
+ return note(request.locator, answer);
608
+ });
447
609
  },
448
610
  async history(_authorization, request) {
449
611
  return resolveScript(scripts.history, () => {
@@ -459,32 +621,45 @@ export function createMemoryAdapter(options = {}) {
459
621
  },
460
622
  async binary(_authorization, request) {
461
623
  return resolveScript(scripts.binary, () => {
462
- if (request.kind === 'reference') {
463
- return { kind: 'rejected', code: 'unscripted-binary', fields: {}, retryable: false };
464
- }
465
624
  const room = rooms.find((entry) => entry.locator === request.locator);
466
625
  if (room === undefined)
467
626
  return { kind: 'room-not-readable', locator: request.locator };
468
- const blob = room.blobs?.[request.path];
627
+ const blob = heldBlob(room, request.path);
469
628
  return blob === undefined
470
- ? { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false }
471
- : { kind: 'binary', blob };
629
+ ? { kind: 'rejected', code: 'not_found', fields: {}, retryable: false }
630
+ : { kind: 'binary', body: blob.stream(), mediaType: blob.type };
472
631
  }, request);
473
632
  },
474
- referrerScope(referrer) {
475
- if (typeof referrer !== 'object' || referrer === null)
476
- return null;
477
- const { room, path, message } = referrer;
478
- if (typeof message === 'string')
479
- return { kind: 'conversations' };
480
- if (typeof room !== 'string')
481
- return null;
482
- return { kind: 'room', locator: room, ...(typeof path === 'string' ? { path } : {}) };
633
+ async link(_authorization, request) {
634
+ return resolveScript(scripts.link, () => {
635
+ const room = rooms.find((entry) => entry.locator === request.locator);
636
+ if (room === undefined)
637
+ return { kind: 'room-not-readable', locator: request.locator };
638
+ const blob = heldBlob(room, request.path);
639
+ if (blob === undefined) {
640
+ return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
641
+ }
642
+ const url = linked.get(blob) ?? URL.createObjectURL(blob);
643
+ linked.set(blob, url);
644
+ return { kind: 'link', url, name: lastName(request.path), mediaType: blob.type };
645
+ }, request);
646
+ },
647
+ async attach(_authorization, request) {
648
+ return resolveScript(scripts.attach, () => {
649
+ const room = rooms.find((entry) => entry.locator === request.locator);
650
+ if (room === undefined)
651
+ return { kind: 'room-not-readable', locator: request.locator };
652
+ const path = freePath(room, request.name);
653
+ attached.set(`${room.locator}\u0000${path}`, request.blob);
654
+ return { kind: 'attached', path, revision: `attached-${attached.size}` };
655
+ }, request);
483
656
  },
484
657
  async action(_authorization, request) {
485
658
  return resolveScript(scripts.action, () => {
486
- if (request.name.startsWith('conversation.'))
659
+ if (request.name.startsWith('conversations/'))
487
660
  return conversationAction(request);
661
+ if (request.name === 'agent-functions/decide')
662
+ return decided(request);
488
663
  return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
489
664
  }, request).then((answer) => {
490
665
  if (answer.kind === 'action' && answer.at !== undefined)