@agentshouse/mdruntime 0.1.0-c14be9ac95f9d → 0.1.0-c15fe07a5ba96

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 (364) hide show
  1. package/README.md +11 -9
  2. package/dist/acceptance.d.ts +6 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +389 -0
  5. package/dist/actions.d.ts +20 -0
  6. package/dist/actions.d.ts.map +1 -0
  7. package/dist/actions.js +251 -0
  8. package/dist/adapter.d.ts +109 -85
  9. package/dist/adapter.d.ts.map +1 -1
  10. package/dist/attached-model.d.ts +5 -11
  11. package/dist/attached-model.d.ts.map +1 -1
  12. package/dist/attached-model.js +36 -47
  13. package/dist/binary.d.ts +0 -5
  14. package/dist/binary.d.ts.map +1 -1
  15. package/dist/binary.js +1 -1
  16. package/dist/bootstrap.d.ts +16 -15
  17. package/dist/bootstrap.d.ts.map +1 -1
  18. package/dist/bootstrap.js +277 -153
  19. package/dist/cell.d.ts +6 -0
  20. package/dist/cell.d.ts.map +1 -0
  21. package/dist/cell.js +9 -0
  22. package/dist/chain.d.ts +2 -1
  23. package/dist/chain.d.ts.map +1 -1
  24. package/dist/change.d.ts +1 -0
  25. package/dist/change.d.ts.map +1 -1
  26. package/dist/chat-types.d.ts +5 -0
  27. package/dist/chat-types.d.ts.map +1 -0
  28. package/dist/chat-types.js +13 -0
  29. package/dist/client.d.ts +27 -13
  30. package/dist/client.d.ts.map +1 -1
  31. package/dist/client.js +57 -8
  32. package/dist/collection.d.ts +7 -4
  33. package/dist/collection.d.ts.map +1 -1
  34. package/dist/collection.js +24 -19
  35. package/dist/compile.d.ts +6 -6
  36. package/dist/compile.d.ts.map +1 -1
  37. package/dist/compile.js +278 -282
  38. package/dist/connection.d.ts +6 -143
  39. package/dist/connection.d.ts.map +1 -1
  40. package/dist/connection.js +103 -5031
  41. package/dist/context.d.ts +2 -0
  42. package/dist/context.d.ts.map +1 -0
  43. package/dist/{chat/context.js → context.js} +1 -4
  44. package/dist/conversation-live.d.ts +136 -0
  45. package/dist/conversation-live.d.ts.map +1 -0
  46. package/dist/conversation-live.js +248 -0
  47. package/dist/conversation-row.d.ts +33 -0
  48. package/dist/conversation-row.d.ts.map +1 -0
  49. package/dist/conversation-row.js +53 -0
  50. package/dist/conversation.d.ts +42 -44
  51. package/dist/conversation.d.ts.map +1 -1
  52. package/dist/conversation.js +886 -772
  53. package/dist/discovery.d.ts +10 -0
  54. package/dist/discovery.d.ts.map +1 -0
  55. package/dist/discovery.js +175 -0
  56. package/dist/durability.d.ts +15 -5
  57. package/dist/durability.d.ts.map +1 -1
  58. package/dist/durability.js +5 -0
  59. package/dist/entry.d.ts +3 -2
  60. package/dist/entry.d.ts.map +1 -1
  61. package/dist/entry.js +18 -8
  62. package/dist/figures.d.ts +49 -0
  63. package/dist/figures.d.ts.map +1 -0
  64. package/dist/figures.js +197 -0
  65. package/dist/file.d.ts +2 -11
  66. package/dist/file.d.ts.map +1 -1
  67. package/dist/file.js +6 -4
  68. package/dist/holdings.d.ts +29 -0
  69. package/dist/holdings.d.ts.map +1 -0
  70. package/dist/holdings.js +95 -0
  71. package/dist/host.d.ts +4 -7
  72. package/dist/host.d.ts.map +1 -1
  73. package/dist/host.js +59 -41
  74. package/dist/identity.d.ts +0 -1
  75. package/dist/identity.d.ts.map +1 -1
  76. package/dist/identity.js +0 -3
  77. package/dist/index.d.ts +30 -13
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +10 -3
  80. package/dist/install.d.ts +56 -0
  81. package/dist/install.d.ts.map +1 -0
  82. package/dist/install.js +556 -0
  83. package/dist/job.d.ts +33 -0
  84. package/dist/job.d.ts.map +1 -0
  85. package/dist/job.js +54 -0
  86. package/dist/lifecycle.d.ts +7 -0
  87. package/dist/lifecycle.d.ts.map +1 -0
  88. package/dist/lifecycle.js +268 -0
  89. package/dist/listing.d.ts +53 -0
  90. package/dist/listing.d.ts.map +1 -0
  91. package/dist/listing.js +176 -0
  92. package/dist/live.d.ts +5 -4
  93. package/dist/live.d.ts.map +1 -1
  94. package/dist/live.js +62 -20
  95. package/dist/locks.d.ts +9 -0
  96. package/dist/locks.d.ts.map +1 -0
  97. package/dist/locks.js +61 -0
  98. package/dist/log.d.ts +1 -0
  99. package/dist/log.d.ts.map +1 -1
  100. package/dist/lost.d.ts +5 -0
  101. package/dist/lost.d.ts.map +1 -0
  102. package/dist/lost.js +61 -0
  103. package/dist/media.d.ts +8 -0
  104. package/dist/media.d.ts.map +1 -0
  105. package/dist/media.js +218 -0
  106. package/dist/memory.d.ts +13 -6
  107. package/dist/memory.d.ts.map +1 -1
  108. package/dist/memory.js +218 -101
  109. package/dist/messages.d.ts +27 -3
  110. package/dist/messages.d.ts.map +1 -1
  111. package/dist/messages.js +97 -19
  112. package/dist/model.d.ts +8 -10
  113. package/dist/model.d.ts.map +1 -1
  114. package/dist/model.js +6 -18
  115. package/dist/models.d.ts +14 -0
  116. package/dist/models.d.ts.map +1 -0
  117. package/dist/models.js +195 -0
  118. package/dist/observation.d.ts +3 -2
  119. package/dist/observation.d.ts.map +1 -1
  120. package/dist/observation.js +8 -3
  121. package/dist/opening.d.ts +4 -0
  122. package/dist/opening.d.ts.map +1 -0
  123. package/dist/opening.js +57 -0
  124. package/dist/outcome.d.ts +17 -7
  125. package/dist/outcome.d.ts.map +1 -1
  126. package/dist/outcome.js +19 -5
  127. package/dist/overlay.d.ts +1 -0
  128. package/dist/overlay.d.ts.map +1 -1
  129. package/dist/overlay.js +12 -1
  130. package/dist/{chat/parts.d.ts → parts.d.ts} +11 -9
  131. package/dist/{chat/parts.d.ts.map → parts.d.ts.map} +1 -1
  132. package/dist/{chat/parts.js → parts.js} +50 -44
  133. package/dist/paths.d.ts +2 -0
  134. package/dist/paths.d.ts.map +1 -1
  135. package/dist/paths.js +26 -0
  136. package/dist/preparation.d.ts +20 -0
  137. package/dist/preparation.d.ts.map +1 -0
  138. package/dist/preparation.js +226 -0
  139. package/dist/queries.d.ts +16 -0
  140. package/dist/queries.d.ts.map +1 -0
  141. package/dist/queries.js +272 -0
  142. package/dist/query.d.ts +18 -207
  143. package/dist/query.d.ts.map +1 -1
  144. package/dist/query.js +3 -505
  145. package/dist/{chat/questions.d.ts → questions.d.ts} +5 -2
  146. package/dist/questions.d.ts.map +1 -0
  147. package/dist/{chat/questions.js → questions.js} +12 -1
  148. package/dist/reach.d.ts +20 -13
  149. package/dist/reach.d.ts.map +1 -1
  150. package/dist/reach.js +203 -134
  151. package/dist/react.d.ts +10 -2
  152. package/dist/react.d.ts.map +1 -1
  153. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  154. package/dist/read.d.ts.map +1 -0
  155. package/dist/{chat/read.js → read.js} +4 -0
  156. package/dist/readiness.d.ts +5 -24
  157. package/dist/readiness.d.ts.map +1 -1
  158. package/dist/readiness.js +2 -8
  159. package/dist/reads.d.ts +36 -10
  160. package/dist/reads.d.ts.map +1 -1
  161. package/dist/reads.js +157 -86
  162. package/dist/recovery.d.ts +1 -0
  163. package/dist/recovery.d.ts.map +1 -1
  164. package/dist/recovery.js +35 -1
  165. package/dist/refresh.d.ts +10 -5
  166. package/dist/refresh.d.ts.map +1 -1
  167. package/dist/refresh.js +89 -31
  168. package/dist/refusal.d.ts +5 -0
  169. package/dist/refusal.d.ts.map +1 -0
  170. package/dist/refusal.js +56 -0
  171. package/dist/replica.d.ts +11 -12
  172. package/dist/replica.d.ts.map +1 -1
  173. package/dist/replica.js +55 -22
  174. package/dist/room-draft.d.ts +22 -5
  175. package/dist/room-draft.d.ts.map +1 -1
  176. package/dist/room-draft.js +131 -51
  177. package/dist/room-drafts.d.ts +24 -0
  178. package/dist/room-drafts.d.ts.map +1 -0
  179. package/dist/room-drafts.js +216 -0
  180. package/dist/rows.d.ts +18 -16
  181. package/dist/rows.d.ts.map +1 -1
  182. package/dist/rows.js +45 -153
  183. package/dist/runtime.d.ts +43 -0
  184. package/dist/runtime.d.ts.map +1 -0
  185. package/dist/runtime.js +1 -0
  186. package/dist/save.d.ts +7 -1
  187. package/dist/save.d.ts.map +1 -1
  188. package/dist/save.js +31 -19
  189. package/dist/saves.d.ts +70 -0
  190. package/dist/saves.d.ts.map +1 -0
  191. package/dist/saves.js +1008 -0
  192. package/dist/search.d.ts +12 -63
  193. package/dist/search.d.ts.map +1 -1
  194. package/dist/search.js +9 -52
  195. package/dist/seed.d.ts +11 -2
  196. package/dist/seed.d.ts.map +1 -1
  197. package/dist/seed.js +71 -0
  198. package/dist/shared.d.ts +1 -2
  199. package/dist/shared.d.ts.map +1 -1
  200. package/dist/shared.js +9 -15
  201. package/dist/shown.d.ts +31 -0
  202. package/dist/shown.d.ts.map +1 -0
  203. package/dist/shown.js +295 -0
  204. package/dist/socket/admission.d.ts +7 -0
  205. package/dist/socket/admission.d.ts.map +1 -0
  206. package/dist/socket/admission.js +39 -0
  207. package/dist/socket/answers.d.ts +6 -0
  208. package/dist/socket/answers.d.ts.map +1 -0
  209. package/dist/socket/answers.js +20 -0
  210. package/dist/socket/lanes.d.ts +20 -0
  211. package/dist/socket/lanes.d.ts.map +1 -0
  212. package/dist/socket/lanes.js +77 -0
  213. package/dist/socket/reads.d.ts +10 -0
  214. package/dist/socket/reads.d.ts.map +1 -0
  215. package/dist/socket/reads.js +31 -0
  216. package/dist/socket/rooms.d.ts +44 -0
  217. package/dist/socket/rooms.d.ts.map +1 -0
  218. package/dist/socket/rooms.js +90 -0
  219. package/dist/socket/session.d.ts +39 -0
  220. package/dist/socket/session.d.ts.map +1 -0
  221. package/dist/socket/session.js +23 -0
  222. package/dist/socket.d.ts +70 -0
  223. package/dist/socket.d.ts.map +1 -0
  224. package/dist/socket.js +175 -0
  225. package/dist/source.d.ts +61 -0
  226. package/dist/source.d.ts.map +1 -0
  227. package/dist/source.js +81 -0
  228. package/dist/status.d.ts +4 -5
  229. package/dist/status.d.ts.map +1 -1
  230. package/dist/status.js +3 -7
  231. package/dist/store/fences.d.ts +16 -0
  232. package/dist/store/fences.d.ts.map +1 -0
  233. package/dist/store/fences.js +26 -0
  234. package/dist/store/installs.d.ts +30 -0
  235. package/dist/store/installs.d.ts.map +1 -0
  236. package/dist/store/installs.js +34 -0
  237. package/dist/store/readiness.d.ts +10 -0
  238. package/dist/store/readiness.d.ts.map +1 -0
  239. package/dist/store/readiness.js +52 -0
  240. package/dist/store/records.d.ts +212 -0
  241. package/dist/store/records.d.ts.map +1 -0
  242. package/dist/store/records.js +431 -0
  243. package/dist/store/room-held.d.ts +8 -0
  244. package/dist/store/room-held.d.ts.map +1 -0
  245. package/dist/store/room-held.js +17 -0
  246. package/dist/store/space.d.ts +11 -0
  247. package/dist/store/space.d.ts.map +1 -0
  248. package/dist/store/space.js +43 -0
  249. package/dist/store/watchers.d.ts +17 -0
  250. package/dist/store/watchers.d.ts.map +1 -0
  251. package/dist/store/watchers.js +57 -0
  252. package/dist/store/writes.d.ts +24 -0
  253. package/dist/store/writes.d.ts.map +1 -0
  254. package/dist/store/writes.js +125 -0
  255. package/dist/store.d.ts +105 -158
  256. package/dist/store.d.ts.map +1 -1
  257. package/dist/store.js +143 -401
  258. package/dist/stored.d.ts +66 -55
  259. package/dist/stored.d.ts.map +1 -1
  260. package/dist/stored.js +355 -273
  261. package/dist/surface.d.ts +88 -0
  262. package/dist/surface.d.ts.map +1 -0
  263. package/dist/surface.js +223 -0
  264. package/dist/sync.d.ts +19 -0
  265. package/dist/sync.d.ts.map +1 -0
  266. package/dist/sync.js +532 -0
  267. package/dist/tables.d.ts +143 -68
  268. package/dist/tables.d.ts.map +1 -1
  269. package/dist/tables.js +267 -103
  270. package/dist/tallies.d.ts +18 -0
  271. package/dist/tallies.d.ts.map +1 -0
  272. package/dist/tallies.js +129 -0
  273. package/dist/transfer.d.ts +0 -5
  274. package/dist/transfer.d.ts.map +1 -1
  275. package/dist/validation.d.ts +3 -4
  276. package/dist/validation.d.ts.map +1 -1
  277. package/dist/validation.js +42 -100
  278. package/dist/windows.d.ts +1 -12
  279. package/dist/windows.d.ts.map +1 -1
  280. package/dist/windows.js +2 -75
  281. package/dist/wire.d.ts +22 -10
  282. package/dist/wire.d.ts.map +1 -1
  283. package/dist/wire.js +9 -3
  284. package/package.json +11 -18
  285. package/AGENTS.md +0 -319
  286. package/dist/chat/acts.d.ts +0 -33
  287. package/dist/chat/acts.d.ts.map +0 -1
  288. package/dist/chat/acts.js +0 -36
  289. package/dist/chat/context.d.ts +0 -3
  290. package/dist/chat/context.d.ts.map +0 -1
  291. package/dist/chat/earlier.d.ts +0 -10
  292. package/dist/chat/earlier.d.ts.map +0 -1
  293. package/dist/chat/earlier.js +0 -54
  294. package/dist/chat/house.d.ts +0 -25
  295. package/dist/chat/house.d.ts.map +0 -1
  296. package/dist/chat/house.js +0 -38
  297. package/dist/chat/input.d.ts +0 -11
  298. package/dist/chat/input.d.ts.map +0 -1
  299. package/dist/chat/input.js +0 -92
  300. package/dist/chat/kit.d.ts +0 -61
  301. package/dist/chat/kit.d.ts.map +0 -1
  302. package/dist/chat/kit.js +0 -123
  303. package/dist/chat/lasting.d.ts +0 -6
  304. package/dist/chat/lasting.d.ts.map +0 -1
  305. package/dist/chat/lasting.js +0 -19
  306. package/dist/chat/list.d.ts +0 -28
  307. package/dist/chat/list.d.ts.map +0 -1
  308. package/dist/chat/list.js +0 -103
  309. package/dist/chat/markdown.d.ts +0 -21
  310. package/dist/chat/markdown.d.ts.map +0 -1
  311. package/dist/chat/markdown.js +0 -246
  312. package/dist/chat/message.d.ts +0 -7
  313. package/dist/chat/message.d.ts.map +0 -1
  314. package/dist/chat/message.js +0 -254
  315. package/dist/chat/messages.d.ts +0 -35
  316. package/dist/chat/messages.d.ts.map +0 -1
  317. package/dist/chat/messages.js +0 -210
  318. package/dist/chat/name.d.ts +0 -7
  319. package/dist/chat/name.d.ts.map +0 -1
  320. package/dist/chat/name.js +0 -37
  321. package/dist/chat/opened.d.ts +0 -12
  322. package/dist/chat/opened.d.ts.map +0 -1
  323. package/dist/chat/opened.js +0 -19
  324. package/dist/chat/overlay.d.ts +0 -32
  325. package/dist/chat/overlay.d.ts.map +0 -1
  326. package/dist/chat/overlay.js +0 -103
  327. package/dist/chat/pieces.d.ts +0 -62
  328. package/dist/chat/pieces.d.ts.map +0 -1
  329. package/dist/chat/pieces.js +0 -1110
  330. package/dist/chat/process.d.ts +0 -20
  331. package/dist/chat/process.d.ts.map +0 -1
  332. package/dist/chat/process.js +0 -32
  333. package/dist/chat/provider.d.ts +0 -70
  334. package/dist/chat/provider.d.ts.map +0 -1
  335. package/dist/chat/provider.js +0 -635
  336. package/dist/chat/question.d.ts +0 -9
  337. package/dist/chat/question.d.ts.map +0 -1
  338. package/dist/chat/question.js +0 -69
  339. package/dist/chat/questions.d.ts.map +0 -1
  340. package/dist/chat/read.d.ts.map +0 -1
  341. package/dist/chat/ready.d.ts +0 -37
  342. package/dist/chat/ready.d.ts.map +0 -1
  343. package/dist/chat/ready.js +0 -93
  344. package/dist/chat/room-file.d.ts +0 -8
  345. package/dist/chat/room-file.d.ts.map +0 -1
  346. package/dist/chat/room-file.js +0 -72
  347. package/dist/chat/steady.d.ts +0 -3
  348. package/dist/chat/steady.d.ts.map +0 -1
  349. package/dist/chat/steady.js +0 -26
  350. package/dist/chat/style.d.ts +0 -4
  351. package/dist/chat/style.d.ts.map +0 -1
  352. package/dist/chat/style.js +0 -307
  353. package/dist/chat.d.ts +0 -15
  354. package/dist/chat.d.ts.map +0 -1
  355. package/dist/chat.js +0 -8
  356. package/dist/fence.d.ts +0 -6
  357. package/dist/fence.d.ts.map +0 -1
  358. package/dist/fence.js +0 -10
  359. package/dist/fulltext.d.ts +0 -27
  360. package/dist/fulltext.d.ts.map +0 -1
  361. package/dist/fulltext.js +0 -368
  362. package/dist/words.d.ts +0 -19
  363. package/dist/words.d.ts.map +0 -1
  364. package/dist/words.js +0 -150
@@ -0,0 +1,251 @@
1
+ import { roomTarget, target } from '@agentshouse/mdmodel';
2
+ import { resendConversations } from './conversation.js';
3
+ import { listingNow } from './listing.js';
4
+ import { locked, lockedRooms } from './locks.js';
5
+ import { scoped } from './models.js';
6
+ import { ABSENT_TARGET, calledResult, failure, historyAnswer, LOCKED_UNREADABLE, lockedRoom, undeclared, UNCERTAIN, UNREADABLE, } from './outcome.js';
7
+ import { refuse } from './refusal.js';
8
+ function operationOf(input) {
9
+ const operation = input?.operation_id;
10
+ return typeof operation === 'string' ? operation : null;
11
+ }
12
+ export async function readHistory(runtime, locator, path, query = {}) {
13
+ const { store, socket, journal } = runtime;
14
+ const { session } = socket;
15
+ if (socket.closed() || session.now().refusal !== null)
16
+ return UNCERTAIN;
17
+ await socket.firstDiscovery;
18
+ if (!session.now().roomsNamed)
19
+ return UNCERTAIN;
20
+ try {
21
+ await socket.authorize();
22
+ }
23
+ catch {
24
+ return UNCERTAIN;
25
+ }
26
+ const { closed, authorization, refusal } = session.now();
27
+ if (closed || authorization === undefined || refusal !== null)
28
+ return UNCERTAIN;
29
+ const since = store.fences.count();
30
+ const transfer = ['transfer', 'history', locator, path];
31
+ if (query.revision !== undefined)
32
+ transfer.push(query.revision);
33
+ if (query.pageToken !== undefined)
34
+ transfer.push(query.pageToken);
35
+ journal.record(transfer.join(' '));
36
+ try {
37
+ const result = await socket.history(authorization, {
38
+ locator,
39
+ path,
40
+ ...(query.revision === undefined ? {} : { revision: query.revision }),
41
+ ...(query.pageToken === undefined ? {} : { pageToken: query.pageToken }),
42
+ });
43
+ journal.record(`outcome history ${result.kind}`);
44
+ if (store.fences.since(locator, since))
45
+ return failure({ kind: 'room-not-readable', locator });
46
+ if (result.kind === 'scoped-refusal') {
47
+ const room = await store.record(result.locator);
48
+ if (room !== undefined)
49
+ await scoped(runtime, result, room, await store.open());
50
+ }
51
+ if (result.kind === 'revoked-authorization')
52
+ await refuse(runtime, 'revoked-authorization');
53
+ return historyAnswer(result);
54
+ }
55
+ catch {
56
+ journal.record('outcome history transport-uncertainty');
57
+ return UNCERTAIN;
58
+ }
59
+ }
60
+ export async function located(runtime, room, path, destination) {
61
+ const crossing = roomTarget(destination);
62
+ const listing = await listingNow(runtime);
63
+ if (crossing === null) {
64
+ const named = target(path, destination);
65
+ return named === null || !listing.has(room) ? null : { room, path: named };
66
+ }
67
+ const held = [...listing.values()].find((listed) => listed.handle === crossing.handle);
68
+ return held === undefined ? null : { room: held.locator, path: crossing.path };
69
+ }
70
+ export async function resolveReference(runtime, room, path, destination) {
71
+ const { store } = runtime;
72
+ if (roomTarget(destination) === null && target(path, destination) === null) {
73
+ return ABSENT_TARGET;
74
+ }
75
+ const at = await located(runtime, room, path, destination);
76
+ if (at === null)
77
+ return UNREADABLE;
78
+ if (await locked(runtime, at.room))
79
+ return LOCKED_UNREADABLE;
80
+ const held = await store.record(at.room);
81
+ if (held !== undefined &&
82
+ (await (await store.open()).entries(held.key, 'visible', [at.path])).length > 0) {
83
+ return { kind: 'document', ...at };
84
+ }
85
+ const history = await readHistory(runtime, at.room, at.path);
86
+ if (history.kind === 'no-history' || history.kind === 'revision')
87
+ return ABSENT_TARGET;
88
+ if (history.kind !== 'history')
89
+ return history;
90
+ const [last] = history.revisions;
91
+ if (last === undefined)
92
+ return ABSENT_TARGET;
93
+ return history.deleted === true
94
+ ? { kind: 'deleted', ...at, revision: last }
95
+ : { kind: 'document', ...at };
96
+ }
97
+ async function declaredAction({ store }, name) {
98
+ for (const capability of (await (await store.open()).facts()).capabilities) {
99
+ for (const action of capability.actions ?? []) {
100
+ if (action.name === name)
101
+ return action;
102
+ }
103
+ }
104
+ return undefined;
105
+ }
106
+ async function calledRooms(runtime, name, input) {
107
+ const member = (await declaredAction(runtime, name))?.room;
108
+ if (member === undefined || input === null || typeof input !== 'object')
109
+ return [];
110
+ const named = input[member];
111
+ return (Array.isArray(named) ? named : [named]).filter((room) => typeof room === 'string');
112
+ }
113
+ export async function invokeAction(runtime, name, input, dispatching) {
114
+ const { store, socket, journal } = runtime;
115
+ const { session } = socket;
116
+ await socket.ready;
117
+ if (socket.closed() || session.now().refusal !== null)
118
+ return UNCERTAIN;
119
+ if ((await declaredAction(runtime, name)) === undefined)
120
+ return undeclared(name);
121
+ try {
122
+ await socket.authorize();
123
+ }
124
+ catch {
125
+ return UNCERTAIN;
126
+ }
127
+ const { closed, authorization, refusal } = session.now();
128
+ if (closed || authorization === undefined || refusal !== null)
129
+ return UNCERTAIN;
130
+ await dispatching?.();
131
+ journal.record(`transfer action ${name}`);
132
+ try {
133
+ const result = await socket.action(authorization, { name, input });
134
+ if (result.kind === 'scoped-refusal') {
135
+ const room = await store.record(result.locator);
136
+ if (room !== undefined)
137
+ await scoped(runtime, result, room, await store.open());
138
+ }
139
+ if (result.kind === 'revoked-authorization')
140
+ await refuse(runtime, 'revoked-authorization');
141
+ journal.record(`outcome action ${result.kind}`);
142
+ if (result.kind === 'rejected')
143
+ journal.record(`refusal rejected ${result.code}`);
144
+ return calledResult(result);
145
+ }
146
+ catch {
147
+ journal.record('outcome action transport-uncertainty');
148
+ return UNCERTAIN;
149
+ }
150
+ }
151
+ export async function readConversationHistory(runtime, request) {
152
+ const { socket, journal } = runtime;
153
+ await socket.ready;
154
+ const stream = socket.conversations();
155
+ if (socket.closed() || socket.session.now().refusal !== null || stream?.history === undefined) {
156
+ return UNCERTAIN;
157
+ }
158
+ journal.record('transfer conversation history');
159
+ try {
160
+ const result = await stream.history(request);
161
+ if (result.kind === 'revoked-authorization')
162
+ await refuse(runtime, 'revoked-authorization');
163
+ journal.record(`outcome conversation history ${result.kind}`);
164
+ return calledResult(result);
165
+ }
166
+ catch {
167
+ journal.record('outcome conversation history transport-uncertainty');
168
+ return UNCERTAIN;
169
+ }
170
+ }
171
+ function unsettled(result) {
172
+ if (result.kind === 'action')
173
+ return false;
174
+ return result.retryable && (result.kind !== 'rejected' || result.reset === undefined);
175
+ }
176
+ async function recoveredAction(runtime, name, input) {
177
+ const { store, socket, recovery } = runtime;
178
+ const { lanes } = socket;
179
+ const operation = operationOf(input);
180
+ if (operation === null)
181
+ return invokeAction(runtime, name, input);
182
+ const kept = async () => (await store.open()).keepCall({ operation, name, input });
183
+ lanes.call(operation);
184
+ try {
185
+ let result = await invokeAction(runtime, name, input, kept);
186
+ if (unsettled(result)) {
187
+ await recovery.attempt(`action ${operation}`, async () => {
188
+ if (socket.closed() || socket.session.now().refusal !== null)
189
+ return 'done';
190
+ if (!socket.isOpen())
191
+ return 'again';
192
+ result = await invokeAction(runtime, name, input, kept);
193
+ return unsettled(result) ? 'again' : 'done';
194
+ }, { again: true });
195
+ }
196
+ if (!unsettled(result))
197
+ await (await store.open()).dropCall(operation);
198
+ return result;
199
+ }
200
+ finally {
201
+ lanes.called(operation);
202
+ }
203
+ }
204
+ export async function called(runtime, name, input) {
205
+ await runtime.socket.ready;
206
+ const lockedNow = await lockedRooms(runtime);
207
+ const room = (await calledRooms(runtime, name, input)).find((one) => lockedNow.includes(one));
208
+ return room === undefined ? recoveredAction(runtime, name, input) : lockedRoom(room);
209
+ }
210
+ export async function resendCalls(runtime, signal) {
211
+ const { store, socket } = runtime;
212
+ const { lanes } = socket;
213
+ if (!socket.isOpen() || socket.closed() || socket.stopping())
214
+ return 'done';
215
+ const local = await store.open();
216
+ for (const held of await local.calls()) {
217
+ if (lanes.calling(held.operation))
218
+ continue;
219
+ if (socket.closed() || signal.aborted)
220
+ return 'done';
221
+ lanes.call(held.operation);
222
+ try {
223
+ if (unsettled(await invokeAction(runtime, held.name, held.input)))
224
+ return 'again';
225
+ await local.dropCall(held.operation);
226
+ }
227
+ finally {
228
+ lanes.called(held.operation);
229
+ }
230
+ }
231
+ return 'done';
232
+ }
233
+ async function resendPass({ socket, conversations }, signal) {
234
+ if (!socket.continuing() || !socket.isOpen() || socket.stopping())
235
+ return 'done';
236
+ const reading = { complete: true, reachable: true };
237
+ try {
238
+ await resendConversations(conversations, reading);
239
+ }
240
+ catch {
241
+ reading.reachable = false;
242
+ }
243
+ if (signal.aborted)
244
+ return 'done';
245
+ return reading.reachable && reading.complete ? 'done' : 'again';
246
+ }
247
+ export function resendLater(runtime) {
248
+ if (!runtime.socket.isOpen())
249
+ return;
250
+ void runtime.recovery.attempt('resend', (signal) => resendPass(runtime, signal), { again: true });
251
+ }
package/dist/adapter.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import type { SavedFacts, TypedPath } from '@agentshouse/mdmodel';
1
2
  import type { ModelResult } from './model.js';
3
+ export type { SavedFacts, TypedPath };
2
4
  import type { Open } from './open.js';
3
5
  import type { ChangeBatch } from './change.js';
4
6
  export type Authorization = object;
@@ -11,7 +13,7 @@ export type TypedSelection = {
11
13
  };
12
14
  export type OperationScopes = {
13
15
  write: readonly string[];
14
- delete: readonly string[];
16
+ erase: readonly string[];
15
17
  };
16
18
  export type ReplicaAdmission = {
17
19
  selection: string;
@@ -27,30 +29,27 @@ export type DiscoveredRoom = {
27
29
  replica: ReplicaAdmission;
28
30
  typedSelection?: TypedSelection;
29
31
  providerOwnedPaths: readonly string[];
32
+ authoredPaths?: readonly string[];
30
33
  };
31
34
  export type Capability = {
32
35
  name: string;
33
36
  limits?: readonly ProviderLimit[];
34
37
  actions?: readonly ActionDeclaration[];
35
- conversationAgents?: ConversationAgents;
36
- };
37
- export type ConversationAgents = {
38
- locator: string;
39
- type: string;
40
- identity: string;
41
- name: string;
42
- retired?: string;
43
38
  };
44
39
  export type ListedConversation = {
45
40
  conversation: string;
46
41
  agent: string;
42
+ agentName: string;
43
+ agentRetired: boolean;
47
44
  name: string;
48
45
  created: string;
49
46
  finished: string | null;
50
47
  outcome: string | null;
51
48
  waiting: boolean;
49
+ newest: string | null;
50
+ processEnded: string | null;
52
51
  };
53
- export type ConversationAction = 'conversation.create' | 'conversation.send' | 'conversation.attach' | 'conversation.answer' | 'conversation.interrupt' | 'conversation.kill' | 'conversation.cancel' | 'conversation.delete' | 'conversation.history';
52
+ export type ConversationAction = 'conversations/create' | 'conversations/send' | 'conversations/interaction/answer' | 'conversations/interrupt' | 'conversations/kill' | 'conversations/delete';
54
53
  export type ConversationMessage = {
55
54
  identity: string;
56
55
  turn: string;
@@ -141,6 +140,10 @@ export type SessionOption = (SessionOptionNaming & {
141
140
  type: 'boolean';
142
141
  currentValue: boolean;
143
142
  });
143
+ export type RunningSubagent = {
144
+ description: string;
145
+ activity: string | null;
146
+ };
144
147
  export type ConversationEvent = {
145
148
  kind: 'turn';
146
149
  conversation: string;
@@ -166,6 +169,10 @@ export type ConversationEvent = {
166
169
  kind: 'starting';
167
170
  conversation: string;
168
171
  step: string | null;
172
+ } | {
173
+ kind: 'subagents';
174
+ conversation: string;
175
+ subagents: readonly RunningSubagent[];
169
176
  } | {
170
177
  kind: 'link';
171
178
  conversation: string;
@@ -184,6 +191,9 @@ export type ConversationEvent = {
184
191
  } | {
185
192
  kind: 'list';
186
193
  entries: readonly ListedConversation[];
194
+ whole: boolean;
195
+ more: boolean;
196
+ cursor: string | null;
187
197
  } | {
188
198
  kind: 'listed';
189
199
  entry: ListedConversation;
@@ -191,9 +201,17 @@ export type ConversationEvent = {
191
201
  kind: 'unlisted';
192
202
  conversation: string;
193
203
  };
204
+ export type ListedAgent = {
205
+ agent: string;
206
+ name: string;
207
+ retired: boolean;
208
+ };
194
209
  export type ConversationStream = {
195
210
  replicate(conversations: readonly string[]): void;
211
+ hold(cursor: string | null): void;
196
212
  observe(notify: (event: ConversationEvent) => void): () => void;
213
+ agents?(): Promise<readonly ListedAgent[] | null>;
214
+ history?(request: ConversationHistoryRequest): Promise<ActionResult>;
197
215
  };
198
216
  export type ActionDeclaration = {
199
217
  name: string;
@@ -213,7 +231,6 @@ export type HistoryRetention = {
213
231
  };
214
232
  export type Retention = {
215
233
  history: HistoryRetention;
216
- outcome: number;
217
234
  refreshHorizon: number;
218
235
  };
219
236
  export type Discovery = {
@@ -223,10 +240,6 @@ export type Discovery = {
223
240
  providerLimits: readonly ProviderLimit[];
224
241
  retention: Retention;
225
242
  member?: Member;
226
- covered?: readonly string[];
227
- };
228
- export type DiscoveryScope = {
229
- readonly authorities: readonly string[];
230
243
  };
231
244
  export type TransportUncertainty = {
232
245
  kind: 'transport-uncertainty';
@@ -255,7 +268,7 @@ export type ContractUnavailable = ProviderRefusal & {
255
268
  export type DiscoverResult = Discovery | TransportUncertainty | RevokedAuthorization | ContractUnavailable;
256
269
  export type PageToken = string;
257
270
  export type ChangeAuthor = {
258
- kind: Open<'user' | 'site' | 'inbox'>;
271
+ kind: Open<'user' | 'site' | 'inbox' | 'app'>;
259
272
  id: string;
260
273
  name: string;
261
274
  };
@@ -269,55 +282,49 @@ export type HeadChange = {
269
282
  time: string;
270
283
  };
271
284
  export type BinaryFile = {
272
- fileRef: string;
273
285
  byteLength: number;
274
286
  mediaType: string;
275
287
  sha256: string;
276
288
  };
277
- export type HeldFile = {
278
- readonly path: string;
279
- readonly revision: string;
280
- };
281
- export type HeldContent = {
282
- files(after: string | null, limit: number): Promise<readonly HeldFile[]>;
283
- contents(paths: readonly string[]): Promise<ReadonlyMap<string, {
284
- readonly content: string;
285
- readonly revision: string;
286
- }>>;
287
- };
288
289
  export type BootstrapRequest = {
289
290
  locator: string;
290
291
  selection: string;
291
292
  pageToken?: PageToken;
292
- held?: HeldContent;
293
- received?: Uint8Array;
294
293
  arriving?: (bytes: number) => void;
294
+ signal?: AbortSignal;
295
+ };
296
+ export type BootstrapPart = {
297
+ readonly id: string;
298
+ readonly bytes: number;
295
299
  };
296
300
  export type BootstrapInventory = {
297
- readonly parts: number;
298
301
  readonly bytes: number;
299
302
  };
300
303
  export type RoomModels = {
301
304
  collection?: ModelResult;
302
- selection?: ModelResult;
303
305
  };
304
306
  export type BootstrapPage = {
305
307
  kind: 'bootstrap';
306
308
  roomVersion: string;
307
309
  models?: RoomModels;
308
310
  documents: Readonly<Record<string, string>>;
311
+ facts: Readonly<Record<string, SavedFacts>>;
309
312
  revisions: Readonly<Record<string, string>>;
310
313
  fileIds?: Readonly<Record<string, string>>;
314
+ created?: Readonly<Record<string, string>>;
311
315
  changes: Readonly<Record<string, HeadChange>>;
312
316
  binaryFiles: Readonly<Record<string, BinaryFile>>;
313
317
  folders?: readonly string[];
314
318
  pageToken?: PageToken;
315
- inventory?: BootstrapInventory;
316
- received?: Uint8Array;
319
+ parts?: readonly BootstrapPart[];
320
+ bytes?: number;
321
+ };
322
+ export type NotReady = {
323
+ kind: 'not-ready';
317
324
  };
318
325
  export type BootstrapResult = BootstrapPage | {
319
326
  kind: 'beyond-horizon';
320
- } | AdapterFailure;
327
+ } | NotReady | AdapterFailure;
321
328
  export type RefreshRequest = {
322
329
  locator: string;
323
330
  selection: string;
@@ -329,8 +336,10 @@ export type RefreshPage = {
329
336
  roomVersion: string;
330
337
  models?: RoomModels;
331
338
  documents: Readonly<Record<string, string>>;
339
+ facts: Readonly<Record<string, SavedFacts>>;
332
340
  revisions: Readonly<Record<string, string>>;
333
341
  fileIds?: Readonly<Record<string, string>>;
342
+ created?: Readonly<Record<string, string>>;
334
343
  changes: Readonly<Record<string, HeadChange>>;
335
344
  binaryFiles: Readonly<Record<string, BinaryFile>>;
336
345
  removals: readonly string[];
@@ -380,15 +389,9 @@ export type MutationResult = (AcceptedRoom & {
380
389
  affected: Readonly<Record<string, string>>;
381
390
  }) | RetryableRefusal | {
382
391
  kind: 'write-halted';
383
- } | {
384
- kind: 'expired';
385
- restored?: true;
386
392
  } | AdapterFailure;
387
393
  export type HistoryAuthor = {
388
- kind: 'user';
389
- id: string;
390
- } | {
391
- kind: 'site' | 'inbox';
394
+ kind: 'user' | 'site' | 'inbox' | 'app';
392
395
  id: string;
393
396
  name: string;
394
397
  };
@@ -420,15 +423,6 @@ export type BinaryRequest = {
420
423
  locator: string;
421
424
  path: string;
422
425
  revision: string;
423
- fileRef?: string;
424
- } | {
425
- kind: 'reference';
426
- fileRef: string;
427
- referrer: unknown;
428
- };
429
- export type ReferrerScope = {
430
- locator: string;
431
- path?: string;
432
426
  };
433
427
  export type BinaryResult = {
434
428
  kind: 'binary';
@@ -442,6 +436,22 @@ export type BinaryLinkResult = {
442
436
  kind: 'link';
443
437
  url: string;
444
438
  name: string;
439
+ mediaType?: string;
440
+ } | (ProviderRefusal & {
441
+ kind: 'rejected';
442
+ }) | AdapterFailure;
443
+ export type AttachRequest = {
444
+ locator: string;
445
+ name: string;
446
+ mediaType: string;
447
+ byteLength: number;
448
+ sha256: string;
449
+ blob: Blob;
450
+ };
451
+ export type AttachResult = {
452
+ kind: 'attached';
453
+ path: string;
454
+ revision: string;
445
455
  } | (ProviderRefusal & {
446
456
  kind: 'rejected';
447
457
  }) | AdapterFailure;
@@ -457,71 +467,85 @@ export type ActionResult = {
457
467
  kind: 'action';
458
468
  result: unknown;
459
469
  at?: RoomVersionAt;
470
+ } | (ProviderRefusal & {
471
+ kind: 'rejected';
472
+ reset?: string;
473
+ }) | AdapterFailure;
474
+ export type SearchHit = {
475
+ room: string;
476
+ path: string;
477
+ line?: number;
478
+ snippet?: string;
479
+ };
480
+ export type SearchAsk = {
481
+ text: string;
482
+ rooms: readonly string[] | null;
483
+ };
484
+ export type SearchAnswer = {
485
+ kind: 'found';
486
+ documents: readonly SearchHit[];
460
487
  } | (ProviderRefusal & {
461
488
  kind: 'rejected';
462
489
  }) | AdapterFailure;
463
490
  export type HeldRoom = {
464
491
  locator: string;
492
+ roomVersion: string | null;
493
+ };
494
+ export type RoomChange = {
495
+ kind: 'room-change';
496
+ locator: string;
497
+ from: string | null;
465
498
  roomVersion: string;
499
+ read(): Promise<RefreshPage>;
500
+ };
501
+ export type AuthorityChange = {
502
+ kind: 'authority-changed';
503
+ rooms: readonly DiscoveredRoom[];
504
+ left: readonly string[];
505
+ member?: Member;
466
506
  };
467
- export type HeldRevisions = (locator: string, paths: readonly string[]) => Promise<ReadonlyMap<string, string>>;
468
507
  export type RoomStreamEvent = {
469
508
  kind: 'opened';
509
+ } | {
510
+ kind: 'discovered';
511
+ discovery: Discovery;
470
512
  } | {
471
513
  kind: 'closed';
472
514
  revoked: boolean;
473
515
  lost: boolean;
516
+ authorityChanged: boolean;
474
517
  } | {
475
- kind: 'opening';
518
+ kind: 'caught-up';
476
519
  expired: readonly string[];
477
- } | {
478
- kind: 'authority-changed';
479
- scope?: DiscoveryScope;
480
- } | {
481
- kind: 'room-version';
482
- locator: string;
483
- roomVersion: string;
484
- };
485
- export type KeptReceipt = {
486
- key: string;
487
- head: unknown;
488
- };
489
- export type StreamReceipts = {
490
- heads(): Promise<readonly KeptReceipt[]>;
491
- parts(key: string, count: number): Promise<readonly unknown[]>;
492
- keep(key: string, head: unknown, part?: {
493
- index: number;
494
- value: unknown;
495
- }): Promise<void>;
496
- drop(keys: readonly string[]): Promise<void>;
497
- };
520
+ } | AuthorityChange | RoomChange;
498
521
  export type RoomStream = {
499
522
  hold(rooms: readonly HeldRoom[]): void;
500
- reopen(): void;
501
- published(locator: string, roomVersion: string): void;
502
- observe(notify: (event: RoomStreamEvent) => void, receipts: StreamReceipts, revisions: HeldRevisions): () => void;
523
+ observe(notify: (event: RoomStreamEvent) => void): () => void;
503
524
  };
525
+ export type PathRule = (path: string) => boolean;
504
526
  export type Adapter = {
505
527
  readonly localSaves?: true;
506
- readonly exhaustiveDiscovery?: true;
507
528
  readonly roomTypes?: string;
529
+ readonly nameableRoomTypes?: readonly string[];
530
+ readonly typedPaths?: readonly TypedPath[];
531
+ readonly pathRule?: PathRule;
532
+ readonly unkeptReads?: readonly string[];
533
+ readonly leadingReads?: readonly string[];
508
534
  authorize(): Promise<Authorization>;
509
- discover(authorization: Authorization, scope?: DiscoveryScope): Promise<DiscoverResult>;
535
+ discover?(authorization: Authorization): Promise<DiscoverResult>;
510
536
  bootstrap(authorization: Authorization, request: BootstrapRequest): Promise<BootstrapResult>;
511
- refresh(authorization: Authorization, request: RefreshRequest): Promise<RefreshResult>;
537
+ refresh?(authorization: Authorization, request: RefreshRequest): Promise<RefreshResult>;
512
538
  mutate(authorization: Authorization, request: MutationRequest, keep: (upload: unknown) => Promise<void>): Promise<MutationResult>;
513
539
  history(authorization: Authorization, request: HistoryRequest): Promise<HistoryResult>;
514
540
  binary(authorization: Authorization, request: BinaryRequest): Promise<BinaryResult>;
515
- link(authorization: Authorization, request: Extract<BinaryRequest, {
516
- kind: 'path';
517
- }>): Promise<BinaryLinkResult>;
518
- referrerScope(referrer: unknown): ReferrerScope | null;
541
+ link(authorization: Authorization, request: BinaryRequest): Promise<BinaryLinkResult>;
542
+ attach(authorization: Authorization, request: AttachRequest): Promise<AttachResult>;
519
543
  action(authorization: Authorization, request: ActionRequest): Promise<ActionResult>;
544
+ search?(authorization: Authorization, request: SearchAsk): Promise<SearchAnswer>;
520
545
  reached(locator: string, roomVersion: string, target: string): boolean;
521
546
  follows(locator: string, roomVersion: string, next: string): boolean;
522
547
  roomStream?: RoomStream;
523
548
  conversations?: ConversationStream;
524
549
  serviceMode?: ServiceModeSignal;
525
550
  };
526
- export {};
527
551
  //# sourceMappingURL=adapter.d.ts.map