@agentshouse/mdruntime 0.1.0-c806ecaf4afed → 0.1.0-c80bb5b77602a

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 (261) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +15 -24
  4. package/dist/act-lanes.d.ts +11 -14
  5. package/dist/act-lanes.d.ts.map +1 -1
  6. package/dist/act-lanes.js +53 -5
  7. package/dist/actions.d.ts +8 -2
  8. package/dist/actions.d.ts.map +1 -1
  9. package/dist/actions.js +138 -68
  10. package/dist/adapter.d.ts +109 -24
  11. package/dist/adapter.d.ts.map +1 -1
  12. package/dist/attached-model.d.ts +0 -1
  13. package/dist/attached-model.d.ts.map +1 -1
  14. package/dist/attached-model.js +2 -7
  15. package/dist/authored.d.ts +88 -0
  16. package/dist/authored.d.ts.map +1 -0
  17. package/dist/authored.js +347 -0
  18. package/dist/binary.d.ts +6 -2
  19. package/dist/binary.d.ts.map +1 -1
  20. package/dist/binary.js +10 -3
  21. package/dist/change.d.ts +6 -2
  22. package/dist/change.d.ts.map +1 -1
  23. package/dist/change.js +3 -0
  24. package/dist/chat-types.d.ts +0 -2
  25. package/dist/chat-types.d.ts.map +1 -1
  26. package/dist/chat-types.js +2 -4
  27. package/dist/client.d.ts +20 -14
  28. package/dist/client.d.ts.map +1 -1
  29. package/dist/client.js +28 -56
  30. package/dist/collection.d.ts +5 -1
  31. package/dist/collection.d.ts.map +1 -1
  32. package/dist/collection.js +16 -8
  33. package/dist/column.d.ts +5 -0
  34. package/dist/column.d.ts.map +1 -0
  35. package/dist/column.js +9 -0
  36. package/dist/compile.d.ts +2 -0
  37. package/dist/compile.d.ts.map +1 -1
  38. package/dist/compile.js +21 -11
  39. package/dist/connection.d.ts +1 -1
  40. package/dist/connection.d.ts.map +1 -1
  41. package/dist/connection.js +21 -16
  42. package/dist/context.d.ts.map +1 -1
  43. package/dist/context.js +1 -1
  44. package/dist/conversation-live.d.ts +23 -10
  45. package/dist/conversation-live.d.ts.map +1 -1
  46. package/dist/conversation-live.js +18 -8
  47. package/dist/conversation-row.d.ts +8 -1
  48. package/dist/conversation-row.d.ts.map +1 -1
  49. package/dist/conversation-row.js +20 -7
  50. package/dist/conversation.d.ts +22 -11
  51. package/dist/conversation.d.ts.map +1 -1
  52. package/dist/conversation.js +258 -188
  53. package/dist/declaration.js +1 -1
  54. package/dist/discovery.d.ts +3 -1
  55. package/dist/discovery.d.ts.map +1 -1
  56. package/dist/discovery.js +36 -9
  57. package/dist/download.d.ts +6 -0
  58. package/dist/download.d.ts.map +1 -0
  59. package/dist/download.js +42 -0
  60. package/dist/durability.d.ts +5 -0
  61. package/dist/durability.d.ts.map +1 -1
  62. package/dist/durability.js +7 -0
  63. package/dist/entry.d.ts +14 -0
  64. package/dist/entry.d.ts.map +1 -1
  65. package/dist/entry.js +45 -16
  66. package/dist/expectation.d.ts +25 -14
  67. package/dist/expectation.d.ts.map +1 -1
  68. package/dist/expectation.js +51 -20
  69. package/dist/failure.d.ts +2 -0
  70. package/dist/failure.d.ts.map +1 -1
  71. package/dist/failure.js +6 -1
  72. package/dist/figures.d.ts.map +1 -1
  73. package/dist/figures.js +4 -2
  74. package/dist/file.d.ts +1 -1
  75. package/dist/file.d.ts.map +1 -1
  76. package/dist/file.js +3 -2
  77. package/dist/host.d.ts +7 -2
  78. package/dist/host.d.ts.map +1 -1
  79. package/dist/host.js +76 -30
  80. package/dist/house-query.d.ts +18 -0
  81. package/dist/house-query.d.ts.map +1 -0
  82. package/dist/house-query.js +54 -0
  83. package/dist/index.d.ts +17 -10
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +11 -5
  86. package/dist/install.d.ts +10 -4
  87. package/dist/install.d.ts.map +1 -1
  88. package/dist/install.js +45 -46
  89. package/dist/lifecycle.d.ts +1 -1
  90. package/dist/lifecycle.d.ts.map +1 -1
  91. package/dist/lifecycle.js +50 -32
  92. package/dist/listing.d.ts +24 -12
  93. package/dist/listing.d.ts.map +1 -1
  94. package/dist/listing.js +50 -21
  95. package/dist/live.d.ts +5 -3
  96. package/dist/live.d.ts.map +1 -1
  97. package/dist/live.js +71 -30
  98. package/dist/loaded.d.ts +7 -0
  99. package/dist/loaded.d.ts.map +1 -0
  100. package/dist/loaded.js +46 -0
  101. package/dist/locks.d.ts.map +1 -1
  102. package/dist/locks.js +4 -3
  103. package/dist/lost.d.ts.map +1 -1
  104. package/dist/lost.js +2 -3
  105. package/dist/media.d.ts +19 -3
  106. package/dist/media.d.ts.map +1 -1
  107. package/dist/media.js +167 -33
  108. package/dist/memory.d.ts +7 -3
  109. package/dist/memory.d.ts.map +1 -1
  110. package/dist/memory.js +63 -19
  111. package/dist/messages.d.ts +17 -3
  112. package/dist/messages.d.ts.map +1 -1
  113. package/dist/messages.js +29 -10
  114. package/dist/modal.d.ts +2 -0
  115. package/dist/modal.d.ts.map +1 -0
  116. package/dist/modal.js +11 -0
  117. package/dist/model.d.ts +4 -2
  118. package/dist/model.d.ts.map +1 -1
  119. package/dist/model.js +7 -1
  120. package/dist/models.d.ts.map +1 -1
  121. package/dist/models.js +5 -8
  122. package/dist/name.d.ts +0 -1
  123. package/dist/name.d.ts.map +1 -1
  124. package/dist/name.js +3 -7
  125. package/dist/observation.d.ts +29 -12
  126. package/dist/observation.d.ts.map +1 -1
  127. package/dist/observation.js +206 -69
  128. package/dist/online.d.ts +7 -0
  129. package/dist/online.d.ts.map +1 -0
  130. package/dist/online.js +29 -0
  131. package/dist/opening.d.ts.map +1 -1
  132. package/dist/opening.js +20 -10
  133. package/dist/outcome.d.ts +24 -4
  134. package/dist/outcome.d.ts.map +1 -1
  135. package/dist/outcome.js +33 -3
  136. package/dist/overlay.d.ts +7 -4
  137. package/dist/overlay.d.ts.map +1 -1
  138. package/dist/overlay.js +11 -9
  139. package/dist/parts.d.ts +4 -9
  140. package/dist/parts.d.ts.map +1 -1
  141. package/dist/parts.js +30 -15
  142. package/dist/preparation.d.ts +33 -7
  143. package/dist/preparation.d.ts.map +1 -1
  144. package/dist/preparation.js +198 -87
  145. package/dist/presence.d.ts +8 -2
  146. package/dist/presence.d.ts.map +1 -1
  147. package/dist/presence.js +24 -13
  148. package/dist/queries.d.ts +2 -2
  149. package/dist/queries.d.ts.map +1 -1
  150. package/dist/queries.js +81 -64
  151. package/dist/query.d.ts +2 -2
  152. package/dist/questions.d.ts +1 -5
  153. package/dist/questions.d.ts.map +1 -1
  154. package/dist/questions.js +3 -8
  155. package/dist/queue.d.ts +2 -2
  156. package/dist/queue.d.ts.map +1 -1
  157. package/dist/queue.js +73 -48
  158. package/dist/reach.d.ts +15 -6
  159. package/dist/reach.d.ts.map +1 -1
  160. package/dist/reach.js +162 -37
  161. package/dist/react.d.ts +10 -11
  162. package/dist/react.d.ts.map +1 -1
  163. package/dist/react.js +22 -4
  164. package/dist/readiness.d.ts +20 -4
  165. package/dist/readiness.d.ts.map +1 -1
  166. package/dist/readiness.js +17 -10
  167. package/dist/reads.d.ts +4 -2
  168. package/dist/reads.d.ts.map +1 -1
  169. package/dist/reads.js +7 -3
  170. package/dist/recovery.d.ts +4 -1
  171. package/dist/recovery.d.ts.map +1 -1
  172. package/dist/recovery.js +31 -8
  173. package/dist/reference-forms.d.ts +4 -0
  174. package/dist/reference-forms.d.ts.map +1 -0
  175. package/dist/reference-forms.js +74 -0
  176. package/dist/refresh.d.ts +1 -1
  177. package/dist/refresh.js +4 -4
  178. package/dist/refusal.d.ts.map +1 -1
  179. package/dist/refusal.js +1 -3
  180. package/dist/replica.d.ts.map +1 -1
  181. package/dist/replica.js +4 -4
  182. package/dist/retried.d.ts +30 -0
  183. package/dist/retried.d.ts.map +1 -0
  184. package/dist/retried.js +72 -0
  185. package/dist/room-draft.d.ts +30 -5
  186. package/dist/room-draft.d.ts.map +1 -1
  187. package/dist/room-draft.js +258 -32
  188. package/dist/room-drafts.d.ts.map +1 -1
  189. package/dist/room-drafts.js +11 -6
  190. package/dist/room-list.d.ts +10 -0
  191. package/dist/room-list.d.ts.map +1 -0
  192. package/dist/room-list.js +45 -0
  193. package/dist/rows.d.ts +2 -1
  194. package/dist/rows.d.ts.map +1 -1
  195. package/dist/rows.js +8 -7
  196. package/dist/running.d.ts +5 -0
  197. package/dist/running.d.ts.map +1 -0
  198. package/dist/running.js +10 -0
  199. package/dist/runtime.d.ts +5 -4
  200. package/dist/runtime.d.ts.map +1 -1
  201. package/dist/save.d.ts +2 -0
  202. package/dist/save.d.ts.map +1 -1
  203. package/dist/save.js +105 -124
  204. package/dist/saves.d.ts +4 -2
  205. package/dist/saves.d.ts.map +1 -1
  206. package/dist/saves.js +65 -21
  207. package/dist/seed.d.ts.map +1 -1
  208. package/dist/seed.js +2 -2
  209. package/dist/shown.d.ts +5 -2
  210. package/dist/shown.d.ts.map +1 -1
  211. package/dist/shown.js +79 -43
  212. package/dist/socket/lanes.d.ts +12 -4
  213. package/dist/socket/lanes.d.ts.map +1 -1
  214. package/dist/socket/lanes.js +34 -8
  215. package/dist/socket/session.d.ts +4 -1
  216. package/dist/socket/session.d.ts.map +1 -1
  217. package/dist/socket/session.js +3 -0
  218. package/dist/socket.d.ts +4 -3
  219. package/dist/socket.d.ts.map +1 -1
  220. package/dist/socket.js +4 -9
  221. package/dist/source.d.ts +7 -7
  222. package/dist/source.d.ts.map +1 -1
  223. package/dist/source.js +15 -2
  224. package/dist/store/installs.d.ts +2 -2
  225. package/dist/store/installs.d.ts.map +1 -1
  226. package/dist/store/installs.js +10 -4
  227. package/dist/store/readiness.d.ts +5 -4
  228. package/dist/store/readiness.d.ts.map +1 -1
  229. package/dist/store/readiness.js +28 -12
  230. package/dist/store/records.d.ts +20 -5
  231. package/dist/store/records.d.ts.map +1 -1
  232. package/dist/store/records.js +60 -22
  233. package/dist/store/rooms-shown.d.ts +8 -0
  234. package/dist/store/rooms-shown.d.ts.map +1 -0
  235. package/dist/store/rooms-shown.js +13 -0
  236. package/dist/store.d.ts +17 -10
  237. package/dist/store.d.ts.map +1 -1
  238. package/dist/store.js +18 -6
  239. package/dist/stored.d.ts +32 -14
  240. package/dist/stored.d.ts.map +1 -1
  241. package/dist/stored.js +185 -49
  242. package/dist/surface.d.ts +14 -8
  243. package/dist/surface.d.ts.map +1 -1
  244. package/dist/surface.js +59 -27
  245. package/dist/sync.d.ts +4 -2
  246. package/dist/sync.d.ts.map +1 -1
  247. package/dist/sync.js +76 -40
  248. package/dist/tables.d.ts +17 -52
  249. package/dist/tables.d.ts.map +1 -1
  250. package/dist/tables.js +87 -324
  251. package/dist/tallies.d.ts.map +1 -1
  252. package/dist/tallies.js +1 -2
  253. package/dist/validation.d.ts.map +1 -1
  254. package/dist/validation.js +3 -9
  255. package/dist/wire.d.ts +38 -15
  256. package/dist/wire.d.ts.map +1 -1
  257. package/dist/wire.js +20 -13
  258. package/package.json +3 -3
  259. package/dist/log.d.ts +0 -6
  260. package/dist/log.d.ts.map +0 -1
  261. package/dist/log.js +0 -14
package/dist/actions.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import { roomTarget, target } from '@agentshouse/mdmodel';
2
- import { resendConversations } from './conversation.js';
2
+ import { CATCHING_UP, holdsSubmission, resendConversations } from './conversation.js';
3
3
  import { listingNow } from './listing.js';
4
4
  import { locked, lockedRooms } from './locks.js';
5
5
  import { scoped } from './models.js';
6
- import { ABSENT_TARGET, calledResult, failure, historyAnswer, LOCKED_UNREADABLE, lockedRoom, undeclared, UNCERTAIN, UNREADABLE, } from './outcome.js';
6
+ import { ABSENT_TARGET, failure, historyAnswer, LOCKED_UNREADABLE, lockedRoom, handedOutcome, UNANSWERED, undeclared, UNCERTAIN, UNREADABLE, } from './outcome.js';
7
7
  import { refuse } from './refusal.js';
8
8
  function operationOf(input) {
9
9
  const operation = input?.operation_id;
10
10
  return typeof operation === 'string' ? operation : null;
11
11
  }
12
12
  export async function readHistory(runtime, locator, path, query = {}) {
13
- const { store, socket, presence, journal } = runtime;
13
+ const { store, socket, presence } = runtime;
14
14
  const { session } = socket;
15
15
  if (socket.closed() || session.now().refusal !== null)
16
16
  return UNCERTAIN;
@@ -27,12 +27,6 @@ export async function readHistory(runtime, locator, path, query = {}) {
27
27
  if (closed || authorization === undefined || refusal !== null)
28
28
  return UNCERTAIN;
29
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
30
  try {
37
31
  const result = await socket.history(authorization, {
38
32
  locator,
@@ -40,7 +34,6 @@ export async function readHistory(runtime, locator, path, query = {}) {
40
34
  ...(query.revision === undefined ? {} : { revision: query.revision }),
41
35
  ...(query.pageToken === undefined ? {} : { pageToken: query.pageToken }),
42
36
  });
43
- journal.record(`outcome history ${result.kind}`);
44
37
  if (presence.lostSince(locator, since))
45
38
  return failure({ kind: 'room-not-readable', locator });
46
39
  if (result.kind === 'scoped-refusal') {
@@ -53,7 +46,6 @@ export async function readHistory(runtime, locator, path, query = {}) {
53
46
  return historyAnswer(result);
54
47
  }
55
48
  catch {
56
- journal.record('outcome history transport-uncertainty');
57
49
  return UNCERTAIN;
58
50
  }
59
51
  }
@@ -94,8 +86,16 @@ export async function resolveReference(runtime, room, path, destination) {
94
86
  ? { kind: 'deleted', ...at, revision: last }
95
87
  : { kind: 'document', ...at };
96
88
  }
97
- async function declaredAction({ store }, name) {
98
- for (const capability of (await (await store.open()).facts()).capabilities) {
89
+ async function declaredActions({ store, socket }) {
90
+ const { unstored } = socket.session.now();
91
+ if (unstored !== null)
92
+ return unstored.capabilities;
93
+ if (!store.needed())
94
+ return [];
95
+ return (await (await store.open()).facts()).capabilities;
96
+ }
97
+ async function declaredAction(runtime, name) {
98
+ for (const capability of await declaredActions(runtime)) {
99
99
  for (const action of capability.actions ?? []) {
100
100
  if (action.name === name)
101
101
  return action;
@@ -103,32 +103,44 @@ async function declaredAction({ store }, name) {
103
103
  }
104
104
  return undefined;
105
105
  }
106
+ async function declaration(runtime, name) {
107
+ const { socket } = runtime;
108
+ const declared = await declaredAction(runtime, name);
109
+ if (declared !== undefined || socket.streamed || socket.session.now().roomsNamed)
110
+ return declared;
111
+ await runtime.discover();
112
+ return declaredAction(runtime, name);
113
+ }
106
114
  async function calledRooms(runtime, name, input) {
107
- const member = (await declaredAction(runtime, name))?.room;
115
+ const member = (await declaration(runtime, name))?.room;
108
116
  if (member === undefined || input === null || typeof input !== 'object')
109
117
  return [];
110
118
  const named = input[member];
111
119
  return (Array.isArray(named) ? named : [named]).filter((room) => typeof room === 'string');
112
120
  }
113
- export async function invokeAction(runtime, name, input, dispatching) {
114
- const { store, socket, journal } = runtime;
121
+ export async function invokeAction(runtime, name, input, { dispatching, attempt } = {}) {
122
+ const { store, socket, retries } = runtime;
115
123
  const { session } = socket;
116
124
  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);
125
+ if (socket.closed() || session.now().refusal !== null) {
126
+ return handedOutcome(retries, attempt, UNANSWERED);
127
+ }
128
+ if ((await declaredAction(runtime, name)) === undefined) {
129
+ return session.now().roomsNamed
130
+ ? undeclared(name)
131
+ : handedOutcome(retries, attempt, UNANSWERED);
132
+ }
121
133
  try {
122
134
  await socket.authorize();
123
135
  }
124
136
  catch {
125
- return UNCERTAIN;
137
+ return handedOutcome(retries, attempt, UNANSWERED);
126
138
  }
127
139
  const { closed, authorization, refusal } = session.now();
128
- if (closed || authorization === undefined || refusal !== null)
129
- return UNCERTAIN;
140
+ if (closed || authorization === undefined || refusal !== null) {
141
+ return handedOutcome(retries, attempt, UNANSWERED);
142
+ }
130
143
  await dispatching?.();
131
- journal.record(`transfer action ${name}`);
132
144
  try {
133
145
  const result = await socket.action(authorization, { name, input });
134
146
  if (result.kind === 'scoped-refusal') {
@@ -138,34 +150,28 @@ export async function invokeAction(runtime, name, input, dispatching) {
138
150
  }
139
151
  if (result.kind === 'revoked-authorization')
140
152
  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);
153
+ return handedOutcome(retries, attempt, result);
145
154
  }
146
- catch {
147
- journal.record('outcome action transport-uncertainty');
148
- return UNCERTAIN;
155
+ catch (error) {
156
+ return handedOutcome(retries, attempt, { kind: 'transport-uncertainty', failure: error });
149
157
  }
150
158
  }
151
159
  export async function readConversationHistory(runtime, request) {
152
- const { socket, journal } = runtime;
160
+ const { socket, retries } = runtime;
161
+ const caught = { step: 'conversations', instance: CATCHING_UP };
153
162
  await socket.ready;
154
163
  const stream = socket.conversations();
155
164
  if (socket.closed() || socket.session.now().refusal !== null || stream?.history === undefined) {
156
- return UNCERTAIN;
165
+ return handedOutcome(retries, caught, UNANSWERED);
157
166
  }
158
- journal.record('transfer conversation history');
159
167
  try {
160
168
  const result = await stream.history(request);
161
169
  if (result.kind === 'revoked-authorization')
162
170
  await refuse(runtime, 'revoked-authorization');
163
- journal.record(`outcome conversation history ${result.kind}`);
164
- return calledResult(result);
171
+ return handedOutcome(retries, caught, result);
165
172
  }
166
- catch {
167
- journal.record('outcome conversation history transport-uncertainty');
168
- return UNCERTAIN;
173
+ catch (error) {
174
+ return handedOutcome(retries, caught, { kind: 'transport-uncertainty', failure: error });
169
175
  }
170
176
  }
171
177
  function unsettled(result) {
@@ -173,59 +179,123 @@ function unsettled(result) {
173
179
  return false;
174
180
  return result.retryable && (result.kind !== 'rejected' || result.reset === undefined);
175
181
  }
176
- async function recoveredAction(runtime, name, input) {
177
- const { store, socket, recovery } = runtime;
182
+ function numberedCall(runtime, name, input, operation, dispatching) {
183
+ return invokeAction(runtime, name, input, {
184
+ dispatching,
185
+ attempt: { step: 'sending', instance: `action ${operation}` },
186
+ });
187
+ }
188
+ function keptSender(runtime, name, input, operation, resent = false) {
189
+ const { store, socket } = runtime;
178
190
  const { lanes } = socket;
191
+ const dispatching = async () => (await store.open()).keepCall({ operation, name, input });
192
+ let waiting = [];
193
+ let last = UNCERTAIN;
194
+ let lost = resent;
195
+ const tell = (result) => {
196
+ last = result;
197
+ const told = waiting;
198
+ waiting = [];
199
+ for (const answer of told)
200
+ answer(result);
201
+ };
202
+ const sender = {
203
+ next: () => new Promise((answer) => waiting.push(answer)),
204
+ async send() {
205
+ let result;
206
+ try {
207
+ result = await numberedCall(runtime, name, input, operation, dispatching);
208
+ }
209
+ catch (error) {
210
+ tell(last);
211
+ throw error;
212
+ }
213
+ if (unsettled(result))
214
+ lost = true;
215
+ else {
216
+ await (await store.open()).dropCall(operation);
217
+ lanes.settle(operation, lost);
218
+ }
219
+ tell(result);
220
+ return result;
221
+ },
222
+ release() {
223
+ lanes.sent(operation, sender);
224
+ tell(last);
225
+ },
226
+ };
227
+ lanes.sending(operation, sender);
228
+ return sender;
229
+ }
230
+ async function recoveredAction(runtime, name, input, attempt) {
231
+ const { socket, recovery } = runtime;
179
232
  const operation = operationOf(input);
180
233
  if (operation === null)
181
- return invokeAction(runtime, name, input);
182
- const kept = async () => (await store.open()).keepCall({ operation, name, input });
183
- lanes.call(operation);
234
+ return invokeAction(runtime, name, input, { attempt });
235
+ const held = socket.lanes.sender(operation);
236
+ if (held !== undefined)
237
+ return held.next();
238
+ const sender = keptSender(runtime, name, input, operation);
239
+ let first;
184
240
  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;
241
+ first = await sender.send();
242
+ }
243
+ catch (error) {
244
+ sender.release();
245
+ throw error;
199
246
  }
200
- finally {
201
- lanes.called(operation);
247
+ if (!unsettled(first)) {
248
+ sender.release();
249
+ return first;
202
250
  }
251
+ void recovery
252
+ .attempt(`action ${operation}`, async () => {
253
+ if (socket.closed() || socket.session.now().refusal !== null)
254
+ return 'done';
255
+ if (!socket.isOpen())
256
+ return 'again';
257
+ return unsettled(await sender.send()) ? 'again' : 'done';
258
+ }, { again: true })
259
+ .finally(() => sender.release());
260
+ return first;
203
261
  }
204
- export async function called(runtime, name, input) {
262
+ export async function called(runtime, name, input, attempt) {
205
263
  await runtime.socket.ready;
206
264
  const lockedNow = await lockedRooms(runtime);
207
265
  const room = (await calledRooms(runtime, name, input)).find((one) => lockedNow.includes(one));
208
- return room === undefined ? recoveredAction(runtime, name, input) : lockedRoom(room);
266
+ return room === undefined ? recoveredAction(runtime, name, input, attempt) : lockedRoom(room);
209
267
  }
210
- export async function resendCalls(runtime, signal) {
268
+ export async function answeredCall(runtime, operation) {
211
269
  const { store, socket } = runtime;
212
270
  const { lanes } = socket;
271
+ const held = () => lanes.sender(operation) !== undefined || lanes.unclaimed(operation);
272
+ if (!held()) {
273
+ const calls = await (await store.open()).calls();
274
+ const kept = calls.some((one) => one.operation === operation) ||
275
+ (await holdsSubmission(runtime.conversations, operation));
276
+ if (!held() && !kept)
277
+ return false;
278
+ }
279
+ await lanes.settled(operation);
280
+ return true;
281
+ }
282
+ export async function resendCalls(runtime, signal) {
283
+ const { store, socket } = runtime;
213
284
  if (!socket.isOpen() || socket.closed() || socket.stopping())
214
285
  return 'done';
215
286
  const local = await store.open();
216
287
  for (const held of await local.calls()) {
217
- if (lanes.calling(held.operation))
288
+ if (socket.lanes.sender(held.operation) !== undefined)
218
289
  continue;
219
290
  if (socket.closed() || signal.aborted)
220
291
  return 'done';
221
- lanes.call(held.operation);
292
+ const sender = keptSender(runtime, held.name, held.input, held.operation, true);
222
293
  try {
223
- if (unsettled(await invokeAction(runtime, held.name, held.input)))
294
+ if (unsettled(await sender.send()))
224
295
  return 'again';
225
- await local.dropCall(held.operation);
226
296
  }
227
297
  finally {
228
- lanes.called(held.operation);
298
+ sender.release();
229
299
  }
230
300
  }
231
301
  return 'done';
package/dist/adapter.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import type { SavedFacts, TypedPath } from '@agentshouse/mdmodel';
1
+ import type { SavedFacts, TypedPath, VerifiedModel } from '@agentshouse/mdmodel';
2
2
  import type { Operation, SessionState } from '@agentshouse/session-content';
3
3
  import type { ModelResult } from './model.js';
4
4
  export type { SavedFacts, TypedPath };
5
5
  import type { Open } from './open.js';
6
6
  import type { ChangeBatch } from './change.js';
7
+ import type { QueryDocument, QueryGroup } from './query.js';
7
8
  export type Authorization = object;
8
9
  export type MdModelIdentity = {
9
10
  identity: string;
@@ -42,15 +43,13 @@ export type Capability = {
42
43
  export type ListedConversation = {
43
44
  conversation: string;
44
45
  agent: string;
45
- agentName: string;
46
- agentRetired: boolean;
47
46
  name: string;
48
47
  created: string;
49
- finished: string | null;
50
48
  outcome: string | null;
51
49
  waiting: boolean;
52
50
  newest: string | null;
53
51
  processEnded: string | null;
52
+ subject: string | null;
54
53
  };
55
54
  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';
56
55
  export type ConversationMessage = {
@@ -146,10 +145,6 @@ export type ConversationEvent = {
146
145
  kind: 'state';
147
146
  conversation: string;
148
147
  state: SessionState | null;
149
- } | {
150
- kind: 'link';
151
- conversation: string;
152
- connected: boolean;
153
148
  } | {
154
149
  kind: 'deliveries';
155
150
  conversation: string;
@@ -164,6 +159,7 @@ export type ConversationEvent = {
164
159
  conversation: string;
165
160
  } | {
166
161
  kind: 'list';
162
+ agents: readonly ListedAgent[];
167
163
  entries: readonly ListedConversation[];
168
164
  whole: boolean;
169
165
  more: boolean;
@@ -171,6 +167,9 @@ export type ConversationEvent = {
171
167
  } | {
172
168
  kind: 'listed';
173
169
  entry: ListedConversation;
170
+ } | {
171
+ kind: 'agent';
172
+ agent: ListedAgent;
174
173
  } | {
175
174
  kind: 'unlisted';
176
175
  conversation: string;
@@ -180,18 +179,56 @@ export type AgentEnvironment = {
180
179
  name: string;
181
180
  state: 'online' | 'offline';
182
181
  };
182
+ export type ListedOwner = {
183
+ readonly user: string;
184
+ readonly name: string;
185
+ };
186
+ export type ListedSpaceRef = {
187
+ readonly space_ref: string;
188
+ readonly name: string;
189
+ };
190
+ export type RoomListEntry = {
191
+ readonly room_ref: string;
192
+ readonly room_handle: string;
193
+ readonly name: string;
194
+ readonly level: 'search' | 'open' | 'keep';
195
+ readonly access: 'owner' | 'manage' | 'write' | 'read' | 'public';
196
+ readonly owner: ListedOwner;
197
+ readonly created: string;
198
+ readonly archived?: string;
199
+ readonly exportable?: true;
200
+ readonly space?: ListedSpaceRef;
201
+ };
202
+ export type SpaceListEntry = ListedSpaceRef & {
203
+ readonly owner: ListedOwner;
204
+ readonly created: string;
205
+ readonly manages?: true;
206
+ };
207
+ export type RoomList = {
208
+ readonly rooms: readonly RoomListEntry[];
209
+ readonly spaces: readonly SpaceListEntry[];
210
+ };
183
211
  export type ListedAgent = {
184
- agent: string;
212
+ id: string;
185
213
  name: string;
186
- retired: boolean;
214
+ revision: number;
215
+ environment: string;
216
+ environment_name: string;
217
+ environment_connected: boolean;
218
+ launch_directory: string;
187
219
  cli: string;
188
- environment: AgentEnvironment;
220
+ model: string | null;
221
+ effort: string | null;
222
+ mode: string | null;
223
+ base_instructions: string;
224
+ in_telegram: boolean;
225
+ created: string;
226
+ retired_at: string | null;
189
227
  };
190
228
  export type ConversationStream = {
191
229
  replicate(conversations: readonly string[]): void;
192
230
  hold(cursor: string | null): void;
193
231
  observe(notify: (event: ConversationEvent) => void): () => void;
194
- agents?(): Promise<readonly ListedAgent[] | null>;
195
232
  history?(request: ConversationHistoryRequest): Promise<ActionResult>;
196
233
  };
197
234
  export type ActionDeclaration = {
@@ -214,6 +251,11 @@ export type Retention = {
214
251
  history: HistoryRetention;
215
252
  refreshHorizon: number;
216
253
  };
254
+ export type QueriedRoom = {
255
+ readonly locator: string;
256
+ readonly handle: string;
257
+ readonly name: string;
258
+ };
217
259
  export type Discovery = {
218
260
  kind: 'discovery';
219
261
  rooms: readonly DiscoveredRoom[];
@@ -221,9 +263,13 @@ export type Discovery = {
221
263
  providerLimits: readonly ProviderLimit[];
222
264
  retention: Retention;
223
265
  member?: Member;
266
+ timeZone?: string | null;
267
+ roomList?: RoomList;
268
+ queriesOnly?: readonly QueriedRoom[];
224
269
  };
225
270
  export type TransportUncertainty = {
226
271
  kind: 'transport-uncertainty';
272
+ failure?: unknown;
227
273
  };
228
274
  export type RoomNotReadable = {
229
275
  kind: 'room-not-readable';
@@ -262,10 +308,12 @@ export type HeadChange = {
262
308
  author: ChangeAuthor | null;
263
309
  time: string;
264
310
  };
265
- export type BinaryFile = {
311
+ export type Attachment = {
266
312
  byteLength: number;
267
313
  mediaType: string;
268
314
  sha256: string;
315
+ width?: number | null;
316
+ height?: number | null;
269
317
  };
270
318
  export type BootstrapRequest = {
271
319
  locator: string;
@@ -294,7 +342,7 @@ export type BootstrapPage = {
294
342
  fileIds?: Readonly<Record<string, string>>;
295
343
  created?: Readonly<Record<string, string>>;
296
344
  changes: Readonly<Record<string, HeadChange>>;
297
- binaryFiles: Readonly<Record<string, BinaryFile>>;
345
+ attachments: Readonly<Record<string, Attachment>>;
298
346
  folders?: readonly string[];
299
347
  pageToken?: PageToken;
300
348
  parts?: readonly BootstrapPart[];
@@ -322,7 +370,7 @@ export type RefreshPage = {
322
370
  fileIds?: Readonly<Record<string, string>>;
323
371
  created?: Readonly<Record<string, string>>;
324
372
  changes: Readonly<Record<string, HeadChange>>;
325
- binaryFiles: Readonly<Record<string, BinaryFile>>;
373
+ attachments: Readonly<Record<string, Attachment>>;
326
374
  removals: readonly string[];
327
375
  folders?: readonly string[];
328
376
  folderRemovals?: readonly string[];
@@ -354,16 +402,13 @@ export type AcceptedRoom = {
354
402
  fileIds?: Readonly<Record<string, string>>;
355
403
  changes: Readonly<Record<string, HeadChange>>;
356
404
  removals: readonly string[];
357
- binaryFiles?: Readonly<Record<string, BinaryFile>>;
405
+ attachments?: Readonly<Record<string, Attachment>>;
358
406
  };
359
407
  export type MutationResult = (AcceptedRoom & {
360
408
  kind: 'accepted';
361
- author?: string;
362
- time?: string;
363
409
  destination?: AcceptedRoom;
364
410
  }) | (ProviderRefusal & {
365
411
  kind: 'conflicted';
366
- roomVersion?: string;
367
412
  affected: Readonly<Record<string, string>>;
368
413
  }) | (ProviderRefusal & {
369
414
  kind: 'rejected';
@@ -380,7 +425,7 @@ export type HistoryRevision = {
380
425
  revision: string;
381
426
  author: HistoryAuthor;
382
427
  time: string;
383
- binaryFile?: BinaryFile;
428
+ attachment?: Attachment;
384
429
  };
385
430
  export type HistoryRequest = {
386
431
  locator: string;
@@ -405,11 +450,21 @@ export type BinaryRequest = {
405
450
  path: string;
406
451
  revision: string;
407
452
  };
453
+ export type KeyedRequest = {
454
+ kind: 'key';
455
+ link: string;
456
+ };
457
+ export type BinaryCopy = {
458
+ url: string;
459
+ width: number;
460
+ };
408
461
  export type BinaryResult = {
409
462
  kind: 'binary';
410
463
  body: ReadableStream<Uint8Array>;
411
464
  mediaType: string;
412
465
  sha256?: string;
466
+ url?: string;
467
+ copies?: readonly BinaryCopy[];
413
468
  } | (ProviderRefusal & {
414
469
  kind: 'rejected';
415
470
  }) | AdapterFailure;
@@ -422,7 +477,7 @@ export type BinaryLinkResult = {
422
477
  kind: 'rejected';
423
478
  }) | AdapterFailure;
424
479
  export type AttachRequest = {
425
- locator: string;
480
+ locator?: string;
426
481
  name: string;
427
482
  mediaType: string;
428
483
  byteLength: number;
@@ -433,6 +488,9 @@ export type AttachResult = {
433
488
  kind: 'attached';
434
489
  path: string;
435
490
  revision: string;
491
+ } | {
492
+ kind: 'linked';
493
+ link: string;
436
494
  } | (ProviderRefusal & {
437
495
  kind: 'rejected';
438
496
  }) | AdapterFailure;
@@ -468,6 +526,27 @@ export type SearchAnswer = {
468
526
  } | (ProviderRefusal & {
469
527
  kind: 'rejected';
470
528
  }) | AdapterFailure;
529
+ export type HouseQueryAsk = {
530
+ room: string;
531
+ query: Readonly<Record<string, unknown>>;
532
+ fresh: boolean;
533
+ };
534
+ export type HouseQueryRows = {
535
+ kind: 'rows';
536
+ documents: readonly QueryDocument[];
537
+ next?: string;
538
+ total?: number;
539
+ totalCapped?: true;
540
+ };
541
+ export type HouseQueryGroups = {
542
+ kind: 'groups';
543
+ groups: readonly QueryGroup[];
544
+ next?: string;
545
+ capped?: true;
546
+ };
547
+ export type HouseQueryAnswer = HouseQueryRows | HouseQueryGroups | (ProviderRefusal & {
548
+ kind: 'rejected';
549
+ }) | AdapterFailure;
471
550
  export type HeldRoom = {
472
551
  locator: string;
473
552
  roomVersion: string | null;
@@ -484,6 +563,10 @@ export type AuthorityChange = {
484
563
  rooms: readonly DiscoveredRoom[];
485
564
  left: readonly string[];
486
565
  member?: Member;
566
+ timeZone?: string | null;
567
+ roomList?: RoomList & {
568
+ readonly left: readonly string[];
569
+ };
487
570
  };
488
571
  export type RoomStreamEvent = {
489
572
  kind: 'opened';
@@ -498,6 +581,8 @@ export type RoomStreamEvent = {
498
581
  } | {
499
582
  kind: 'caught-up';
500
583
  expired: readonly string[];
584
+ } | {
585
+ kind: 'reported';
501
586
  } | AuthorityChange | RoomChange;
502
587
  export type RoomStream = {
503
588
  hold(rooms: readonly HeldRoom[]): void;
@@ -506,8 +591,7 @@ export type RoomStream = {
506
591
  export type PathRule = (path: string) => boolean;
507
592
  export type Adapter = {
508
593
  readonly localSaves?: true;
509
- readonly roomTypes?: string;
510
- readonly nameableRoomTypes?: readonly string[];
594
+ readonly roomTypes?: VerifiedModel;
511
595
  readonly typedPaths?: readonly TypedPath[];
512
596
  readonly pathRule?: PathRule;
513
597
  readonly unkeptReads?: readonly string[];
@@ -519,10 +603,11 @@ export type Adapter = {
519
603
  mutate(authorization: Authorization, request: MutationRequest, keep: (upload: unknown) => Promise<void>): Promise<MutationResult>;
520
604
  history(authorization: Authorization, request: HistoryRequest): Promise<HistoryResult>;
521
605
  binary(authorization: Authorization, request: BinaryRequest): Promise<BinaryResult>;
522
- link(authorization: Authorization, request: BinaryRequest): Promise<BinaryLinkResult>;
606
+ link(authorization: Authorization, request: BinaryRequest | KeyedRequest): Promise<BinaryLinkResult>;
523
607
  attach(authorization: Authorization, request: AttachRequest): Promise<AttachResult>;
524
608
  action(authorization: Authorization, request: ActionRequest): Promise<ActionResult>;
525
609
  search?(authorization: Authorization, request: SearchAsk): Promise<SearchAnswer>;
610
+ queryHouse?(authorization: Authorization, request: HouseQueryAsk): Promise<HouseQueryAnswer>;
526
611
  reached(locator: string, roomVersion: string, target: string): boolean;
527
612
  follows(locator: string, roomVersion: string, next: string): boolean;
528
613
  roomStream?: RoomStream;