@agentshouse/mdruntime 0.1.0-c7f53cda5b000 → 0.1.0-c806ecaf4afed

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 (309) hide show
  1. package/README.md +10 -10
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +308 -0
  5. package/dist/act-lanes.d.ts +33 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +177 -0
  8. package/dist/actions.d.ts +20 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +251 -0
  11. package/dist/adapter.d.ts +108 -107
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +3 -10
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +29 -47
  16. package/dist/bootstrap.d.ts +15 -18
  17. package/dist/bootstrap.d.ts.map +1 -1
  18. package/dist/bootstrap.js +252 -158
  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-set.d.ts +4 -0
  25. package/dist/change-set.d.ts.map +1 -1
  26. package/dist/change-set.js +6 -0
  27. package/dist/change.d.ts +1 -0
  28. package/dist/change.d.ts.map +1 -1
  29. package/dist/change.js +4 -2
  30. package/dist/chat-types.d.ts +5 -0
  31. package/dist/chat-types.d.ts.map +1 -0
  32. package/dist/chat-types.js +13 -0
  33. package/dist/client.d.ts +25 -15
  34. package/dist/client.d.ts.map +1 -1
  35. package/dist/client.js +32 -15
  36. package/dist/collection.d.ts +23 -7
  37. package/dist/collection.d.ts.map +1 -1
  38. package/dist/collection.js +13 -19
  39. package/dist/compile.d.ts +6 -6
  40. package/dist/compile.d.ts.map +1 -1
  41. package/dist/compile.js +272 -326
  42. package/dist/connection.d.ts +5 -143
  43. package/dist/connection.d.ts.map +1 -1
  44. package/dist/connection.js +105 -5172
  45. package/dist/context.d.ts +2 -0
  46. package/dist/context.d.ts.map +1 -0
  47. package/dist/context.js +7 -0
  48. package/dist/conversation-live.d.ts +136 -0
  49. package/dist/conversation-live.d.ts.map +1 -0
  50. package/dist/conversation-live.js +249 -0
  51. package/dist/conversation-row.d.ts +33 -0
  52. package/dist/conversation-row.d.ts.map +1 -0
  53. package/dist/conversation-row.js +53 -0
  54. package/dist/conversation.d.ts +58 -48
  55. package/dist/conversation.d.ts.map +1 -1
  56. package/dist/conversation.js +942 -824
  57. package/dist/declaration.d.ts +10 -0
  58. package/dist/declaration.d.ts.map +1 -0
  59. package/dist/declaration.js +24 -0
  60. package/dist/discovery.d.ts +10 -0
  61. package/dist/discovery.d.ts.map +1 -0
  62. package/dist/discovery.js +148 -0
  63. package/dist/durability.d.ts +15 -1
  64. package/dist/durability.d.ts.map +1 -1
  65. package/dist/entry.d.ts +3 -2
  66. package/dist/entry.d.ts.map +1 -1
  67. package/dist/entry.js +18 -8
  68. package/dist/expectation.d.ts +4 -2
  69. package/dist/expectation.d.ts.map +1 -1
  70. package/dist/expectation.js +33 -11
  71. package/dist/failure.d.ts +1 -0
  72. package/dist/failure.d.ts.map +1 -1
  73. package/dist/failure.js +3 -0
  74. package/dist/figures.d.ts +49 -0
  75. package/dist/figures.d.ts.map +1 -0
  76. package/dist/figures.js +197 -0
  77. package/dist/holdings.d.ts +29 -0
  78. package/dist/holdings.d.ts.map +1 -0
  79. package/dist/holdings.js +95 -0
  80. package/dist/host.d.ts +20 -8
  81. package/dist/host.d.ts.map +1 -1
  82. package/dist/host.js +66 -38
  83. package/dist/identity.d.ts +0 -1
  84. package/dist/identity.d.ts.map +1 -1
  85. package/dist/identity.js +0 -3
  86. package/dist/index.d.ts +29 -9
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +11 -2
  89. package/dist/install.d.ts +54 -0
  90. package/dist/install.d.ts.map +1 -0
  91. package/dist/install.js +538 -0
  92. package/dist/lifecycle.d.ts +7 -0
  93. package/dist/lifecycle.d.ts.map +1 -0
  94. package/dist/lifecycle.js +272 -0
  95. package/dist/listing.d.ts +48 -0
  96. package/dist/listing.d.ts.map +1 -0
  97. package/dist/listing.js +139 -0
  98. package/dist/live.d.ts +5 -4
  99. package/dist/live.d.ts.map +1 -1
  100. package/dist/live.js +64 -23
  101. package/dist/locks.d.ts +7 -0
  102. package/dist/locks.d.ts.map +1 -0
  103. package/dist/locks.js +33 -0
  104. package/dist/log.d.ts +1 -0
  105. package/dist/log.d.ts.map +1 -1
  106. package/dist/lost.d.ts +5 -0
  107. package/dist/lost.d.ts.map +1 -0
  108. package/dist/lost.js +50 -0
  109. package/dist/media.d.ts +2 -2
  110. package/dist/media.d.ts.map +1 -1
  111. package/dist/media.js +23 -13
  112. package/dist/memory.d.ts +15 -6
  113. package/dist/memory.d.ts.map +1 -1
  114. package/dist/memory.js +206 -97
  115. package/dist/messages.d.ts +24 -3
  116. package/dist/messages.d.ts.map +1 -1
  117. package/dist/messages.js +92 -32
  118. package/dist/model.d.ts +2 -11
  119. package/dist/model.d.ts.map +1 -1
  120. package/dist/model.js +0 -23
  121. package/dist/models.d.ts +10 -0
  122. package/dist/models.d.ts.map +1 -0
  123. package/dist/models.js +156 -0
  124. package/dist/observation.d.ts +2 -2
  125. package/dist/observation.d.ts.map +1 -1
  126. package/dist/observation.js +14 -14
  127. package/dist/opened.d.ts +1 -1
  128. package/dist/opened.d.ts.map +1 -1
  129. package/dist/opened.js +5 -5
  130. package/dist/opening.d.ts +4 -0
  131. package/dist/opening.d.ts.map +1 -0
  132. package/dist/opening.js +59 -0
  133. package/dist/outcome.d.ts +4 -4
  134. package/dist/outcome.d.ts.map +1 -1
  135. package/dist/outcome.js +3 -0
  136. package/dist/overlay.d.ts +3 -1
  137. package/dist/overlay.d.ts.map +1 -1
  138. package/dist/overlay.js +43 -21
  139. package/dist/page-metadata.d.ts +8 -0
  140. package/dist/page-metadata.d.ts.map +1 -0
  141. package/dist/page-metadata.js +19 -0
  142. package/dist/parts.d.ts +11 -0
  143. package/dist/parts.d.ts.map +1 -0
  144. package/dist/parts.js +21 -0
  145. package/dist/paths.d.ts +1 -0
  146. package/dist/paths.d.ts.map +1 -1
  147. package/dist/paths.js +22 -0
  148. package/dist/preparation.d.ts +20 -0
  149. package/dist/preparation.d.ts.map +1 -0
  150. package/dist/preparation.js +233 -0
  151. package/dist/presence.d.ts +52 -0
  152. package/dist/presence.d.ts.map +1 -0
  153. package/dist/presence.js +220 -0
  154. package/dist/queries.d.ts +16 -0
  155. package/dist/queries.d.ts.map +1 -0
  156. package/dist/queries.js +270 -0
  157. package/dist/query.d.ts +14 -210
  158. package/dist/query.d.ts.map +1 -1
  159. package/dist/query.js +3 -505
  160. package/dist/questions.d.ts +34 -0
  161. package/dist/questions.d.ts.map +1 -0
  162. package/dist/questions.js +122 -0
  163. package/dist/queue.d.ts +40 -0
  164. package/dist/queue.d.ts.map +1 -0
  165. package/dist/queue.js +455 -0
  166. package/dist/reach.d.ts +15 -12
  167. package/dist/reach.d.ts.map +1 -1
  168. package/dist/reach.js +210 -146
  169. package/dist/react.d.ts +21 -2
  170. package/dist/react.d.ts.map +1 -1
  171. package/dist/react.js +15 -1
  172. package/dist/read.d.ts +7 -0
  173. package/dist/read.d.ts.map +1 -0
  174. package/dist/read.js +17 -0
  175. package/dist/readiness.d.ts +3 -18
  176. package/dist/readiness.d.ts.map +1 -1
  177. package/dist/readiness.js +4 -10
  178. package/dist/reads.d.ts +36 -10
  179. package/dist/reads.d.ts.map +1 -1
  180. package/dist/reads.js +159 -85
  181. package/dist/recovery.d.ts +1 -0
  182. package/dist/recovery.d.ts.map +1 -1
  183. package/dist/recovery.js +35 -1
  184. package/dist/refresh.d.ts +7 -5
  185. package/dist/refresh.d.ts.map +1 -1
  186. package/dist/refresh.js +35 -7
  187. package/dist/refusal.d.ts +5 -0
  188. package/dist/refusal.d.ts.map +1 -0
  189. package/dist/refusal.js +57 -0
  190. package/dist/replica.d.ts +12 -18
  191. package/dist/replica.d.ts.map +1 -1
  192. package/dist/replica.js +64 -34
  193. package/dist/room-draft.d.ts +24 -10
  194. package/dist/room-draft.d.ts.map +1 -1
  195. package/dist/room-draft.js +133 -102
  196. package/dist/room-drafts.d.ts +24 -0
  197. package/dist/room-drafts.d.ts.map +1 -0
  198. package/dist/room-drafts.js +217 -0
  199. package/dist/rows.d.ts +14 -21
  200. package/dist/rows.d.ts.map +1 -1
  201. package/dist/rows.js +49 -186
  202. package/dist/runtime.d.ts +34 -0
  203. package/dist/runtime.d.ts.map +1 -0
  204. package/dist/runtime.js +1 -0
  205. package/dist/save.d.ts +41 -86
  206. package/dist/save.d.ts.map +1 -1
  207. package/dist/save.js +239 -116
  208. package/dist/saves.d.ts +32 -0
  209. package/dist/saves.d.ts.map +1 -0
  210. package/dist/saves.js +413 -0
  211. package/dist/search.d.ts +12 -63
  212. package/dist/search.d.ts.map +1 -1
  213. package/dist/search.js +9 -52
  214. package/dist/seed.d.ts +11 -2
  215. package/dist/seed.d.ts.map +1 -1
  216. package/dist/seed.js +71 -1
  217. package/dist/shared.d.ts +1 -7
  218. package/dist/shared.d.ts.map +1 -1
  219. package/dist/shared.js +13 -105
  220. package/dist/shown.d.ts +32 -0
  221. package/dist/shown.d.ts.map +1 -0
  222. package/dist/shown.js +290 -0
  223. package/dist/socket/admission.d.ts +7 -0
  224. package/dist/socket/admission.d.ts.map +1 -0
  225. package/dist/socket/admission.js +39 -0
  226. package/dist/socket/answers.d.ts +6 -0
  227. package/dist/socket/answers.d.ts.map +1 -0
  228. package/dist/socket/answers.js +20 -0
  229. package/dist/socket/lanes.d.ts +20 -0
  230. package/dist/socket/lanes.d.ts.map +1 -0
  231. package/dist/socket/lanes.js +77 -0
  232. package/dist/socket/reads.d.ts +10 -0
  233. package/dist/socket/reads.d.ts.map +1 -0
  234. package/dist/socket/reads.js +31 -0
  235. package/dist/socket/session.d.ts +38 -0
  236. package/dist/socket/session.d.ts.map +1 -0
  237. package/dist/socket/session.js +23 -0
  238. package/dist/socket.d.ts +67 -0
  239. package/dist/socket.d.ts.map +1 -0
  240. package/dist/socket.js +170 -0
  241. package/dist/source.d.ts +61 -0
  242. package/dist/source.d.ts.map +1 -0
  243. package/dist/source.js +82 -0
  244. package/dist/status.d.ts +0 -6
  245. package/dist/status.d.ts.map +1 -1
  246. package/dist/status.js +0 -6
  247. package/dist/store/installs.d.ts +30 -0
  248. package/dist/store/installs.d.ts.map +1 -0
  249. package/dist/store/installs.js +34 -0
  250. package/dist/store/readiness.d.ts +10 -0
  251. package/dist/store/readiness.d.ts.map +1 -0
  252. package/dist/store/readiness.js +52 -0
  253. package/dist/store/records.d.ts +212 -0
  254. package/dist/store/records.d.ts.map +1 -0
  255. package/dist/store/records.js +430 -0
  256. package/dist/store/room-held.d.ts +8 -0
  257. package/dist/store/room-held.d.ts.map +1 -0
  258. package/dist/store/room-held.js +17 -0
  259. package/dist/store/space.d.ts +11 -0
  260. package/dist/store/space.d.ts.map +1 -0
  261. package/dist/store/space.js +41 -0
  262. package/dist/store/watchers.d.ts +17 -0
  263. package/dist/store/watchers.d.ts.map +1 -0
  264. package/dist/store/watchers.js +56 -0
  265. package/dist/store/writes.d.ts +24 -0
  266. package/dist/store/writes.d.ts.map +1 -0
  267. package/dist/store/writes.js +125 -0
  268. package/dist/store.d.ts +118 -175
  269. package/dist/store.d.ts.map +1 -1
  270. package/dist/store.js +161 -419
  271. package/dist/stored.d.ts +59 -57
  272. package/dist/stored.d.ts.map +1 -1
  273. package/dist/stored.js +308 -237
  274. package/dist/surface.d.ts +88 -0
  275. package/dist/surface.d.ts.map +1 -0
  276. package/dist/surface.js +223 -0
  277. package/dist/sync.d.ts +19 -0
  278. package/dist/sync.d.ts.map +1 -0
  279. package/dist/sync.js +521 -0
  280. package/dist/tables.d.ts +116 -66
  281. package/dist/tables.d.ts.map +1 -1
  282. package/dist/tables.js +215 -105
  283. package/dist/tallies.d.ts +18 -0
  284. package/dist/tallies.d.ts.map +1 -0
  285. package/dist/tallies.js +129 -0
  286. package/dist/transfer.d.ts +0 -5
  287. package/dist/transfer.d.ts.map +1 -1
  288. package/dist/validation.d.ts +3 -4
  289. package/dist/validation.d.ts.map +1 -1
  290. package/dist/validation.js +42 -100
  291. package/dist/windows.d.ts +1 -12
  292. package/dist/windows.d.ts.map +1 -1
  293. package/dist/windows.js +2 -75
  294. package/dist/wire.d.ts +55 -7
  295. package/dist/wire.d.ts.map +1 -1
  296. package/dist/wire.js +19 -4
  297. package/package.json +3 -2
  298. package/dist/attempt.d.ts +0 -16
  299. package/dist/attempt.d.ts.map +0 -1
  300. package/dist/attempt.js +0 -70
  301. package/dist/fence.d.ts +0 -6
  302. package/dist/fence.d.ts.map +0 -1
  303. package/dist/fence.js +0 -10
  304. package/dist/fulltext.d.ts +0 -27
  305. package/dist/fulltext.d.ts.map +0 -1
  306. package/dist/fulltext.js +0 -368
  307. package/dist/words.d.ts +0 -19
  308. package/dist/words.d.ts.map +0 -1
  309. 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, presence, 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 = presence.losses();
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 (presence.lostSince(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.locator, room.declaration);
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.locator, room.declaration);
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,7 @@
1
+ import type { SavedFacts, TypedPath } from '@agentshouse/mdmodel';
2
+ import type { Operation, SessionState } from '@agentshouse/session-content';
1
3
  import type { ModelResult } from './model.js';
4
+ export type { SavedFacts, TypedPath };
2
5
  import type { Open } from './open.js';
3
6
  import type { ChangeBatch } from './change.js';
4
7
  export type Authorization = object;
@@ -11,46 +14,45 @@ export type TypedSelection = {
11
14
  };
12
15
  export type OperationScopes = {
13
16
  write: readonly string[];
14
- delete: readonly string[];
17
+ erase: readonly string[];
15
18
  };
16
19
  export type ReplicaAdmission = {
17
20
  selection: string;
18
21
  admission: Open<'admitted' | 'unavailable'>;
19
22
  offline: Open<'locked' | 'open'>;
20
23
  };
21
- export type DiscoveredRoom = {
22
- name: string;
23
- locator: string;
24
- handle: string;
25
- roomVersion: string;
26
- operations: OperationScopes;
27
- replica: ReplicaAdmission;
28
- typedSelection?: TypedSelection;
29
- providerOwnedPaths: readonly string[];
24
+ export type RoomDeclaration = {
25
+ readonly name: string;
26
+ readonly handle: string;
27
+ readonly operations: OperationScopes;
28
+ readonly replica: ReplicaAdmission;
29
+ readonly typedSelection: TypedSelection | null;
30
+ readonly providerOwnedPaths: readonly string[];
31
+ readonly authoredPaths: readonly string[];
32
+ };
33
+ export type DiscoveredRoom = RoomDeclaration & {
34
+ readonly locator: string;
35
+ readonly roomVersion: string;
30
36
  };
31
37
  export type Capability = {
32
38
  name: string;
33
39
  limits?: readonly ProviderLimit[];
34
40
  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
41
  };
44
42
  export type ListedConversation = {
45
43
  conversation: string;
46
44
  agent: string;
45
+ agentName: string;
46
+ agentRetired: boolean;
47
47
  name: string;
48
48
  created: string;
49
49
  finished: string | null;
50
50
  outcome: string | null;
51
51
  waiting: boolean;
52
+ newest: string | null;
53
+ processEnded: string | null;
52
54
  };
53
- export type ConversationAction = 'conversation.create' | 'conversation.send' | 'conversation.answer' | 'conversation.interrupt' | 'conversation.kill' | 'conversation.cancel' | 'conversation.delete' | 'conversation.history';
55
+ export type ConversationAction = 'conversations/create' | 'conversations/send' | 'conversations/interaction/answer' | 'conversations/interrupt' | 'conversations/kill' | 'conversations/delete' | 'conversations/take-out' | 'conversations/rename' | 'conversations/option/set' | 'conversations/retry' | 'agent-functions/decide';
54
56
  export type ConversationMessage = {
55
57
  identity: string;
56
58
  turn: string;
@@ -59,6 +61,7 @@ export type ConversationMessage = {
59
61
  };
60
62
  export type AcceptedMessage = ConversationMessage & {
61
63
  position: string;
64
+ change: string;
62
65
  };
63
66
  export type ConversationHistoryRequest = {
64
67
  conversations: readonly {
@@ -74,37 +77,10 @@ export type ConversationHistoryPage = {
74
77
  export type ConversationHistories = {
75
78
  histories: readonly ConversationHistoryPage[];
76
79
  };
77
- export type TurnContext = {
78
- used: number;
79
- window: number;
80
- };
81
80
  export type TurnOperation = {
82
81
  op: 'begin';
83
82
  at: string;
84
- } | {
85
- op: 'start';
86
- index: number;
87
- part: unknown;
88
- } | {
89
- op: 'append';
90
- index: number;
91
- text: string;
92
- } | {
93
- op: 'status';
94
- index: number;
95
- status: string;
96
- result: unknown;
97
- } | {
98
- op: 'count';
99
- index: number;
100
- count: number;
101
- } | {
102
- op: 'plan';
103
- index: number;
104
- entries: readonly unknown[];
105
- } | ({
106
- op: 'context';
107
- } & TurnContext);
83
+ } | Operation;
108
84
  export type ProcessCommand = {
109
85
  [field: string]: unknown;
110
86
  name: string;
@@ -166,6 +142,10 @@ export type ConversationEvent = {
166
142
  kind: 'starting';
167
143
  conversation: string;
168
144
  step: string | null;
145
+ } | {
146
+ kind: 'state';
147
+ conversation: string;
148
+ state: SessionState | null;
169
149
  } | {
170
150
  kind: 'link';
171
151
  conversation: string;
@@ -173,6 +153,7 @@ export type ConversationEvent = {
173
153
  } | {
174
154
  kind: 'deliveries';
175
155
  conversation: string;
156
+ waiting: readonly string[];
176
157
  unknown: readonly string[];
177
158
  } | {
178
159
  kind: 'accepted-message';
@@ -184,6 +165,9 @@ export type ConversationEvent = {
184
165
  } | {
185
166
  kind: 'list';
186
167
  entries: readonly ListedConversation[];
168
+ whole: boolean;
169
+ more: boolean;
170
+ cursor: string | null;
187
171
  } | {
188
172
  kind: 'listed';
189
173
  entry: ListedConversation;
@@ -191,9 +175,24 @@ export type ConversationEvent = {
191
175
  kind: 'unlisted';
192
176
  conversation: string;
193
177
  };
178
+ export type AgentEnvironment = {
179
+ identity: string;
180
+ name: string;
181
+ state: 'online' | 'offline';
182
+ };
183
+ export type ListedAgent = {
184
+ agent: string;
185
+ name: string;
186
+ retired: boolean;
187
+ cli: string;
188
+ environment: AgentEnvironment;
189
+ };
194
190
  export type ConversationStream = {
195
191
  replicate(conversations: readonly string[]): void;
192
+ hold(cursor: string | null): void;
196
193
  observe(notify: (event: ConversationEvent) => void): () => void;
194
+ agents?(): Promise<readonly ListedAgent[] | null>;
195
+ history?(request: ConversationHistoryRequest): Promise<ActionResult>;
197
196
  };
198
197
  export type ActionDeclaration = {
199
198
  name: string;
@@ -213,7 +212,6 @@ export type HistoryRetention = {
213
212
  };
214
213
  export type Retention = {
215
214
  history: HistoryRetention;
216
- outcome: number;
217
215
  refreshHorizon: number;
218
216
  };
219
217
  export type Discovery = {
@@ -223,10 +221,6 @@ export type Discovery = {
223
221
  providerLimits: readonly ProviderLimit[];
224
222
  retention: Retention;
225
223
  member?: Member;
226
- covered?: readonly string[];
227
- };
228
- export type DiscoveryScope = {
229
- readonly authorities: readonly string[];
230
224
  };
231
225
  export type TransportUncertainty = {
232
226
  kind: 'transport-uncertainty';
@@ -255,7 +249,7 @@ export type ContractUnavailable = ProviderRefusal & {
255
249
  export type DiscoverResult = Discovery | TransportUncertainty | RevokedAuthorization | ContractUnavailable;
256
250
  export type PageToken = string;
257
251
  export type ChangeAuthor = {
258
- kind: Open<'user' | 'site' | 'inbox'>;
252
+ kind: Open<'user' | 'site' | 'inbox' | 'app'>;
259
253
  id: string;
260
254
  name: string;
261
255
  };
@@ -273,27 +267,18 @@ export type BinaryFile = {
273
267
  mediaType: string;
274
268
  sha256: string;
275
269
  };
276
- export type HeldFile = {
277
- readonly path: string;
278
- readonly revision: string;
279
- };
280
- export type HeldContent = {
281
- files(after: string | null, limit: number): Promise<readonly HeldFile[]>;
282
- contents(paths: readonly string[]): Promise<ReadonlyMap<string, {
283
- readonly content: string;
284
- readonly revision: string;
285
- }>>;
286
- };
287
270
  export type BootstrapRequest = {
288
271
  locator: string;
289
272
  selection: string;
290
273
  pageToken?: PageToken;
291
- held?: HeldContent;
292
- received?: Uint8Array;
293
274
  arriving?: (bytes: number) => void;
275
+ signal?: AbortSignal;
276
+ };
277
+ export type BootstrapPart = {
278
+ readonly id: string;
279
+ readonly bytes: number;
294
280
  };
295
281
  export type BootstrapInventory = {
296
- readonly parts: number;
297
282
  readonly bytes: number;
298
283
  };
299
284
  export type RoomModels = {
@@ -304,18 +289,23 @@ export type BootstrapPage = {
304
289
  roomVersion: string;
305
290
  models?: RoomModels;
306
291
  documents: Readonly<Record<string, string>>;
292
+ facts: Readonly<Record<string, SavedFacts>>;
307
293
  revisions: Readonly<Record<string, string>>;
308
294
  fileIds?: Readonly<Record<string, string>>;
295
+ created?: Readonly<Record<string, string>>;
309
296
  changes: Readonly<Record<string, HeadChange>>;
310
297
  binaryFiles: Readonly<Record<string, BinaryFile>>;
311
298
  folders?: readonly string[];
312
299
  pageToken?: PageToken;
313
- inventory?: BootstrapInventory;
314
- received?: Uint8Array;
300
+ parts?: readonly BootstrapPart[];
301
+ bytes?: number;
302
+ };
303
+ export type NotReady = {
304
+ kind: 'not-ready';
315
305
  };
316
306
  export type BootstrapResult = BootstrapPage | {
317
307
  kind: 'beyond-horizon';
318
- } | AdapterFailure;
308
+ } | NotReady | AdapterFailure;
319
309
  export type RefreshRequest = {
320
310
  locator: string;
321
311
  selection: string;
@@ -327,8 +317,10 @@ export type RefreshPage = {
327
317
  roomVersion: string;
328
318
  models?: RoomModels;
329
319
  documents: Readonly<Record<string, string>>;
320
+ facts: Readonly<Record<string, SavedFacts>>;
330
321
  revisions: Readonly<Record<string, string>>;
331
322
  fileIds?: Readonly<Record<string, string>>;
323
+ created?: Readonly<Record<string, string>>;
332
324
  changes: Readonly<Record<string, HeadChange>>;
333
325
  binaryFiles: Readonly<Record<string, BinaryFile>>;
334
326
  removals: readonly string[];
@@ -378,15 +370,9 @@ export type MutationResult = (AcceptedRoom & {
378
370
  affected: Readonly<Record<string, string>>;
379
371
  }) | RetryableRefusal | {
380
372
  kind: 'write-halted';
381
- } | {
382
- kind: 'expired';
383
- restored?: true;
384
373
  } | AdapterFailure;
385
374
  export type HistoryAuthor = {
386
- kind: 'user';
387
- id: string;
388
- } | {
389
- kind: 'site' | 'inbox';
375
+ kind: 'user' | 'site' | 'inbox' | 'app';
390
376
  id: string;
391
377
  name: string;
392
378
  };
@@ -462,70 +448,85 @@ export type ActionResult = {
462
448
  kind: 'action';
463
449
  result: unknown;
464
450
  at?: RoomVersionAt;
451
+ } | (ProviderRefusal & {
452
+ kind: 'rejected';
453
+ reset?: string;
454
+ }) | AdapterFailure;
455
+ export type SearchHit = {
456
+ room: string;
457
+ path: string;
458
+ line?: number;
459
+ snippet?: string;
460
+ };
461
+ export type SearchAsk = {
462
+ text: string;
463
+ rooms: readonly string[] | null;
464
+ };
465
+ export type SearchAnswer = {
466
+ kind: 'found';
467
+ documents: readonly SearchHit[];
465
468
  } | (ProviderRefusal & {
466
469
  kind: 'rejected';
467
470
  }) | AdapterFailure;
468
471
  export type HeldRoom = {
469
472
  locator: string;
473
+ roomVersion: string | null;
474
+ };
475
+ export type RoomChange = {
476
+ kind: 'room-change';
477
+ locator: string;
478
+ from: string | null;
470
479
  roomVersion: string;
480
+ read(): Promise<RefreshPage>;
481
+ };
482
+ export type AuthorityChange = {
483
+ kind: 'authority-changed';
484
+ rooms: readonly DiscoveredRoom[];
485
+ left: readonly string[];
486
+ member?: Member;
471
487
  };
472
- export type HeldRevisions = (locator: string, paths: readonly string[]) => Promise<ReadonlyMap<string, string>>;
473
488
  export type RoomStreamEvent = {
474
489
  kind: 'opened';
490
+ } | {
491
+ kind: 'discovered';
492
+ discovery: Discovery;
475
493
  } | {
476
494
  kind: 'closed';
477
495
  revoked: boolean;
478
496
  lost: boolean;
497
+ authorityChanged: boolean;
479
498
  } | {
480
- kind: 'opening';
499
+ kind: 'caught-up';
481
500
  expired: readonly string[];
482
- } | {
483
- kind: 'authority-changed';
484
- scope?: DiscoveryScope;
485
- } | {
486
- kind: 'room-version';
487
- locator: string;
488
- roomVersion: string;
489
- };
490
- export type KeptReceipt = {
491
- key: string;
492
- head: unknown;
493
- };
494
- export type StreamReceipts = {
495
- heads(): Promise<readonly KeptReceipt[]>;
496
- parts(key: string, count: number): Promise<readonly unknown[]>;
497
- keep(key: string, head: unknown, part?: {
498
- index: number;
499
- value: unknown;
500
- }): Promise<void>;
501
- drop(keys: readonly string[]): Promise<void>;
502
- };
501
+ } | AuthorityChange | RoomChange;
503
502
  export type RoomStream = {
504
503
  hold(rooms: readonly HeldRoom[]): void;
505
- reopen(): void;
506
- published(locator: string, roomVersion: string): void;
507
- observe(notify: (event: RoomStreamEvent) => void, receipts: StreamReceipts, revisions: HeldRevisions): () => void;
504
+ observe(notify: (event: RoomStreamEvent) => void): () => void;
508
505
  };
506
+ export type PathRule = (path: string) => boolean;
509
507
  export type Adapter = {
510
508
  readonly localSaves?: true;
511
- readonly exhaustiveDiscovery?: true;
512
509
  readonly roomTypes?: string;
513
510
  readonly nameableRoomTypes?: readonly string[];
511
+ readonly typedPaths?: readonly TypedPath[];
512
+ readonly pathRule?: PathRule;
513
+ readonly unkeptReads?: readonly string[];
514
+ readonly leadingReads?: readonly string[];
514
515
  authorize(): Promise<Authorization>;
515
- discover(authorization: Authorization, scope?: DiscoveryScope): Promise<DiscoverResult>;
516
+ discover?(authorization: Authorization): Promise<DiscoverResult>;
516
517
  bootstrap(authorization: Authorization, request: BootstrapRequest): Promise<BootstrapResult>;
517
- refresh(authorization: Authorization, request: RefreshRequest): Promise<RefreshResult>;
518
+ refresh?(authorization: Authorization, request: RefreshRequest): Promise<RefreshResult>;
518
519
  mutate(authorization: Authorization, request: MutationRequest, keep: (upload: unknown) => Promise<void>): Promise<MutationResult>;
519
520
  history(authorization: Authorization, request: HistoryRequest): Promise<HistoryResult>;
520
521
  binary(authorization: Authorization, request: BinaryRequest): Promise<BinaryResult>;
521
522
  link(authorization: Authorization, request: BinaryRequest): Promise<BinaryLinkResult>;
522
523
  attach(authorization: Authorization, request: AttachRequest): Promise<AttachResult>;
523
524
  action(authorization: Authorization, request: ActionRequest): Promise<ActionResult>;
525
+ search?(authorization: Authorization, request: SearchAsk): Promise<SearchAnswer>;
524
526
  reached(locator: string, roomVersion: string, target: string): boolean;
525
527
  follows(locator: string, roomVersion: string, next: string): boolean;
526
528
  roomStream?: RoomStream;
527
529
  conversations?: ConversationStream;
528
530
  serviceMode?: ServiceModeSignal;
529
531
  };
530
- export {};
531
532
  //# sourceMappingURL=adapter.d.ts.map