@agentshouse/mdruntime 0.1.0-c26d7e158e11b → 0.1.0-c27d511fb284d

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