@agentshouse/mdruntime 0.1.0-c26a54071744b → 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 (266) hide show
  1. package/README.md +18 -16
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +32 -22
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +51 -28
  6. package/dist/adapter.d.ts +136 -29
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/attached-model.d.ts +0 -1
  9. package/dist/attached-model.d.ts.map +1 -1
  10. package/dist/attached-model.js +2 -7
  11. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  12. package/dist/attachment.d.ts.map +1 -0
  13. package/dist/attachment.js +15 -0
  14. package/dist/authored.d.ts +88 -0
  15. package/dist/authored.d.ts.map +1 -0
  16. package/dist/authored.js +347 -0
  17. package/dist/chain.d.ts +1 -1
  18. package/dist/chain.d.ts.map +1 -1
  19. package/dist/chain.js +5 -2
  20. package/dist/change.d.ts +6 -2
  21. package/dist/change.d.ts.map +1 -1
  22. package/dist/change.js +3 -0
  23. package/dist/chat-types.d.ts +0 -2
  24. package/dist/chat-types.d.ts.map +1 -1
  25. package/dist/chat-types.js +2 -4
  26. package/dist/client.d.ts +20 -15
  27. package/dist/client.d.ts.map +1 -1
  28. package/dist/client.js +28 -57
  29. package/dist/collection.d.ts +6 -1
  30. package/dist/collection.d.ts.map +1 -1
  31. package/dist/collection.js +23 -9
  32. package/dist/column.d.ts +5 -0
  33. package/dist/column.d.ts.map +1 -0
  34. package/dist/column.js +9 -0
  35. package/dist/compile.d.ts +2 -1
  36. package/dist/compile.d.ts.map +1 -1
  37. package/dist/compile.js +73 -42
  38. package/dist/connection.d.ts +1 -1
  39. package/dist/connection.d.ts.map +1 -1
  40. package/dist/connection.js +14 -14
  41. package/dist/context.d.ts.map +1 -1
  42. package/dist/context.js +1 -1
  43. package/dist/conversation-live.d.ts +19 -9
  44. package/dist/conversation-live.d.ts.map +1 -1
  45. package/dist/conversation-live.js +18 -8
  46. package/dist/conversation-row.d.ts +8 -1
  47. package/dist/conversation-row.d.ts.map +1 -1
  48. package/dist/conversation-row.js +20 -7
  49. package/dist/conversation.d.ts +29 -12
  50. package/dist/conversation.d.ts.map +1 -1
  51. package/dist/conversation.js +241 -177
  52. package/dist/declaration.js +3 -3
  53. package/dist/discovery.d.ts +3 -1
  54. package/dist/discovery.d.ts.map +1 -1
  55. package/dist/discovery.js +30 -8
  56. package/dist/download.d.ts +6 -0
  57. package/dist/download.d.ts.map +1 -0
  58. package/dist/download.js +42 -0
  59. package/dist/durability.d.ts +2 -0
  60. package/dist/durability.d.ts.map +1 -1
  61. package/dist/durability.js +7 -0
  62. package/dist/entry.d.ts +25 -1
  63. package/dist/entry.d.ts.map +1 -1
  64. package/dist/entry.js +111 -34
  65. package/dist/failure.d.ts.map +1 -1
  66. package/dist/failure.js +3 -1
  67. package/dist/figures.d.ts +1 -1
  68. package/dist/figures.d.ts.map +1 -1
  69. package/dist/figures.js +6 -4
  70. package/dist/file.d.ts +1 -1
  71. package/dist/file.d.ts.map +1 -1
  72. package/dist/file.js +3 -2
  73. package/dist/host.d.ts +7 -2
  74. package/dist/host.d.ts.map +1 -1
  75. package/dist/host.js +75 -31
  76. package/dist/house-query.d.ts +24 -0
  77. package/dist/house-query.d.ts.map +1 -0
  78. package/dist/house-query.js +102 -0
  79. package/dist/identity.d.ts +1 -1
  80. package/dist/identity.d.ts.map +1 -1
  81. package/dist/identity.js +1 -1
  82. package/dist/index.d.ts +20 -12
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +12 -6
  85. package/dist/install.d.ts +9 -3
  86. package/dist/install.d.ts.map +1 -1
  87. package/dist/install.js +44 -46
  88. package/dist/lifecycle.d.ts +1 -1
  89. package/dist/lifecycle.d.ts.map +1 -1
  90. package/dist/lifecycle.js +40 -29
  91. package/dist/listing.d.ts +24 -12
  92. package/dist/listing.d.ts.map +1 -1
  93. package/dist/listing.js +50 -21
  94. package/dist/live.d.ts +19 -3
  95. package/dist/live.d.ts.map +1 -1
  96. package/dist/live.js +94 -36
  97. package/dist/loaded.d.ts +7 -0
  98. package/dist/loaded.d.ts.map +1 -0
  99. package/dist/loaded.js +46 -0
  100. package/dist/locks.d.ts.map +1 -1
  101. package/dist/locks.js +4 -3
  102. package/dist/lost.d.ts.map +1 -1
  103. package/dist/lost.js +2 -3
  104. package/dist/media.d.ts +19 -3
  105. package/dist/media.d.ts.map +1 -1
  106. package/dist/media.js +181 -34
  107. package/dist/memory.d.ts +7 -3
  108. package/dist/memory.d.ts.map +1 -1
  109. package/dist/memory.js +63 -23
  110. package/dist/messages.d.ts +17 -3
  111. package/dist/messages.d.ts.map +1 -1
  112. package/dist/messages.js +29 -10
  113. package/dist/modal.d.ts +2 -0
  114. package/dist/modal.d.ts.map +1 -0
  115. package/dist/modal.js +11 -0
  116. package/dist/model.d.ts +10 -7
  117. package/dist/model.d.ts.map +1 -1
  118. package/dist/model.js +7 -1
  119. package/dist/models.d.ts.map +1 -1
  120. package/dist/models.js +5 -8
  121. package/dist/name.d.ts +0 -1
  122. package/dist/name.d.ts.map +1 -1
  123. package/dist/name.js +3 -7
  124. package/dist/observation.d.ts +29 -12
  125. package/dist/observation.d.ts.map +1 -1
  126. package/dist/observation.js +206 -69
  127. package/dist/online.d.ts +7 -0
  128. package/dist/online.d.ts.map +1 -0
  129. package/dist/online.js +29 -0
  130. package/dist/opened.d.ts +5 -5
  131. package/dist/opened.d.ts.map +1 -1
  132. package/dist/opened.js +2 -2
  133. package/dist/opening.d.ts.map +1 -1
  134. package/dist/opening.js +20 -10
  135. package/dist/outcome.d.ts +30 -13
  136. package/dist/outcome.d.ts.map +1 -1
  137. package/dist/outcome.js +21 -6
  138. package/dist/overlay.d.ts +20 -9
  139. package/dist/overlay.d.ts.map +1 -1
  140. package/dist/overlay.js +110 -41
  141. package/dist/parts.d.ts +3 -0
  142. package/dist/parts.d.ts.map +1 -1
  143. package/dist/parts.js +31 -5
  144. package/dist/paths.d.ts +1 -1
  145. package/dist/paths.js +1 -1
  146. package/dist/preparation.d.ts +33 -7
  147. package/dist/preparation.d.ts.map +1 -1
  148. package/dist/preparation.js +198 -87
  149. package/dist/presence.d.ts +8 -2
  150. package/dist/presence.d.ts.map +1 -1
  151. package/dist/presence.js +24 -13
  152. package/dist/queries.d.ts +1 -1
  153. package/dist/queries.d.ts.map +1 -1
  154. package/dist/queries.js +116 -71
  155. package/dist/query.d.ts +2 -2
  156. package/dist/query.d.ts.map +1 -1
  157. package/dist/questions.d.ts +1 -0
  158. package/dist/questions.d.ts.map +1 -1
  159. package/dist/questions.js +3 -1
  160. package/dist/queue.d.ts +1 -1
  161. package/dist/queue.d.ts.map +1 -1
  162. package/dist/queue.js +54 -39
  163. package/dist/reach.d.ts +15 -6
  164. package/dist/reach.d.ts.map +1 -1
  165. package/dist/reach.js +162 -38
  166. package/dist/react.d.ts +6 -1
  167. package/dist/react.d.ts.map +1 -1
  168. package/dist/readiness.d.ts +23 -4
  169. package/dist/readiness.d.ts.map +1 -1
  170. package/dist/readiness.js +18 -10
  171. package/dist/reads.d.ts +1 -1
  172. package/dist/reads.d.ts.map +1 -1
  173. package/dist/reads.js +17 -6
  174. package/dist/recovery.d.ts +1 -0
  175. package/dist/recovery.d.ts.map +1 -1
  176. package/dist/recovery.js +2 -1
  177. package/dist/reference-forms.d.ts +4 -0
  178. package/dist/reference-forms.d.ts.map +1 -0
  179. package/dist/reference-forms.js +74 -0
  180. package/dist/refresh.d.ts +1 -1
  181. package/dist/refresh.js +4 -4
  182. package/dist/refusal.d.ts.map +1 -1
  183. package/dist/refusal.js +1 -3
  184. package/dist/replica.d.ts +3 -8
  185. package/dist/replica.d.ts.map +1 -1
  186. package/dist/replica.js +5 -5
  187. package/dist/room-draft.d.ts +29 -4
  188. package/dist/room-draft.d.ts.map +1 -1
  189. package/dist/room-draft.js +239 -18
  190. package/dist/room-drafts.d.ts.map +1 -1
  191. package/dist/room-drafts.js +12 -7
  192. package/dist/room-list.d.ts +10 -0
  193. package/dist/room-list.d.ts.map +1 -0
  194. package/dist/room-list.js +45 -0
  195. package/dist/rows.d.ts +11 -2
  196. package/dist/rows.d.ts.map +1 -1
  197. package/dist/rows.js +24 -10
  198. package/dist/running.d.ts +5 -0
  199. package/dist/running.d.ts.map +1 -0
  200. package/dist/running.js +10 -0
  201. package/dist/runtime.d.ts +5 -4
  202. package/dist/runtime.d.ts.map +1 -1
  203. package/dist/save.d.ts +1 -0
  204. package/dist/save.d.ts.map +1 -1
  205. package/dist/save.js +17 -86
  206. package/dist/saves.d.ts +7 -5
  207. package/dist/saves.d.ts.map +1 -1
  208. package/dist/saves.js +107 -57
  209. package/dist/seed.d.ts.map +1 -1
  210. package/dist/seed.js +2 -2
  211. package/dist/selector.d.ts +3 -0
  212. package/dist/selector.d.ts.map +1 -0
  213. package/dist/selector.js +22 -0
  214. package/dist/shown.d.ts +5 -2
  215. package/dist/shown.d.ts.map +1 -1
  216. package/dist/shown.js +79 -43
  217. package/dist/socket/session.d.ts +4 -1
  218. package/dist/socket/session.d.ts.map +1 -1
  219. package/dist/socket/session.js +3 -0
  220. package/dist/socket.d.ts +2 -2
  221. package/dist/socket.d.ts.map +1 -1
  222. package/dist/socket.js +3 -9
  223. package/dist/source.d.ts +7 -0
  224. package/dist/source.d.ts.map +1 -1
  225. package/dist/source.js +15 -2
  226. package/dist/store/installs.d.ts +2 -2
  227. package/dist/store/installs.d.ts.map +1 -1
  228. package/dist/store/installs.js +10 -4
  229. package/dist/store/readiness.d.ts +5 -4
  230. package/dist/store/readiness.d.ts.map +1 -1
  231. package/dist/store/readiness.js +28 -12
  232. package/dist/store/records.d.ts +30 -8
  233. package/dist/store/records.d.ts.map +1 -1
  234. package/dist/store/records.js +70 -26
  235. package/dist/store/rooms-shown.d.ts +8 -0
  236. package/dist/store/rooms-shown.d.ts.map +1 -0
  237. package/dist/store/rooms-shown.js +13 -0
  238. package/dist/store.d.ts +15 -10
  239. package/dist/store.d.ts.map +1 -1
  240. package/dist/store.js +12 -5
  241. package/dist/stored.d.ts +41 -16
  242. package/dist/stored.d.ts.map +1 -1
  243. package/dist/stored.js +215 -57
  244. package/dist/surface.d.ts +13 -8
  245. package/dist/surface.d.ts.map +1 -1
  246. package/dist/surface.js +57 -26
  247. package/dist/sync.d.ts +4 -2
  248. package/dist/sync.d.ts.map +1 -1
  249. package/dist/sync.js +52 -35
  250. package/dist/tables.d.ts +28 -52
  251. package/dist/tables.d.ts.map +1 -1
  252. package/dist/tables.js +95 -326
  253. package/dist/tallies.d.ts.map +1 -1
  254. package/dist/tallies.js +3 -4
  255. package/dist/validation.d.ts +2 -0
  256. package/dist/validation.d.ts.map +1 -1
  257. package/dist/validation.js +50 -10
  258. package/dist/wire.d.ts +36 -17
  259. package/dist/wire.d.ts.map +1 -1
  260. package/dist/wire.js +20 -14
  261. package/package.json +4 -4
  262. package/dist/binary.d.ts.map +0 -1
  263. package/dist/binary.js +0 -8
  264. package/dist/log.d.ts +0 -6
  265. package/dist/log.d.ts.map +0 -1
  266. package/dist/log.js +0 -14
package/README.md CHANGED
@@ -12,14 +12,14 @@ npm install @agentshouse/mdruntime
12
12
 
13
13
  ## Entries
14
14
 
15
- | Entry | For |
16
- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
17
- | `@agentshouse/mdruntime/client` | The host's client: `connectMdRuntime(port)` |
18
- | `@agentshouse/mdruntime/host` | The host that serves a Runtime: `serveMdRuntime` |
19
- | `@agentshouse/mdruntime` | Shared types |
20
- | `@agentshouse/mdruntime/memory` | Tests: `createMemoryAdapter`, an in-memory Adapter |
21
- | `@agentshouse/mdruntime/tables` | The host's database: the Authored store's and opened files' tables, `answerRuntime` |
22
- | `@agentshouse/mdruntime/react` | React over the client: `useObserve`, `useSave`; `useExpected`, a reader of an expectation store; `useLane`, a reader of an act lane |
15
+ | Entry | For |
16
+ | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
+ | `@agentshouse/mdruntime/client` | The host's client: `connectMdRuntime(port)` |
18
+ | `@agentshouse/mdruntime/host` | The host that serves a Runtime: `serveMdRuntime` |
19
+ | `@agentshouse/mdruntime` | Shared types |
20
+ | `@agentshouse/mdruntime/memory` | Tests: `createMemoryAdapter`, an in-memory Adapter |
21
+ | `@agentshouse/mdruntime/tables` | The host's database: `formatted` lays it out for a device format, keeping the Authored store's tables and creating any it lacks, and `answerRuntime` answers it |
22
+ | `@agentshouse/mdruntime/react` | React over the client: `useObserve`, `useSave`; `useExpected`, a reader of an expectation store; `useLane`, a reader of an act lane |
23
23
 
24
24
  ## Usage
25
25
 
@@ -33,24 +33,26 @@ const rooms = await runtime.rooms();
33
33
  const notes = await runtime.query({ types: ['note'], select: 'all', limit: 20 });
34
34
  ```
35
35
 
36
- `observe('storage-loss')` reports `null` or the stable code
37
- `storage-loss` when unsynchronized Room Drafts and Pending Changes were lost.
38
- The host supplies the user-facing wording.
36
+ `observe('storage-loss')` reports `null`, the stable code `storage-loss` when
37
+ unsynchronized Room Drafts and Pending Changes were lost, or `visit` while the host holds
38
+ the database in memory, which ends with the visit; the readiness `persistence` answer is then
39
+ `memory`. The host supplies the user-facing wording.
39
40
 
40
41
  In House the bridge object the page holds as `window.houseBridge` places the Chat, which
41
42
  House serves with the page: install and bundle nothing for it. Mount it in an element it
42
- fills, on one chat, themed by CSS custom properties on that element:
43
+ fills, where it lays out the User's chats by the element's width, themed by CSS custom
44
+ properties on that element, or as the Chat button, House's dot that opens it in a sheet:
43
45
 
44
46
  ```ts
45
47
  const chat = await window.houseBridge.chat.mount(element, { conversation });
46
48
  element.style.setProperty('--chat-accent', '#2a6cf0');
47
49
  chat.update({ conversation: null, agent });
48
- chat.unmount();
50
+ const button = await window.houseBridge.chat.mountButton({});
51
+ button.open({ agent });
49
52
  ```
50
53
 
51
- The rules an App's agent follows, including Local Query, search, Room
52
- Draft, Save and the Chat, are the `apps/` pages of House's Guide, which House's
53
- `guide/open` opens.
54
+ The rules an App's agent follows, including Local Query, search, Room Draft, Save and the
55
+ Chat, are the `apps/` pages of House's Guide, which House's `guide` tool opens.
54
56
 
55
57
  ## License
56
58
 
@@ -1 +1 @@
1
- {"version":3,"file":"acceptance.d.ts","sourceRoot":"","sources":["../src/acceptance.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAyX5C,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,QAK5D"}
1
+ {"version":3,"file":"acceptance.d.ts","sourceRoot":"","sources":["../src/acceptance.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA0Y5C,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,QAK5D"}
@@ -6,7 +6,8 @@ import { olderThan, showing } from './install.js';
6
6
  import { scoped } from './models.js';
7
7
  import { answered, settle } from './queue.js';
8
8
  import { refuse } from './refusal.js';
9
- import { returnedPaths, returning, slicing } from './replica.js';
9
+ import { writtenDocuments } from './overlay.js';
10
+ import { returnedPaths, returning, slicing, touchedBy, } from './replica.js';
10
11
  import { batchFile } from './saves.js';
11
12
  import { rest, roomUnreadable, statusShown } from './shown.js';
12
13
  import { advanced, withhold } from './sync.js';
@@ -39,11 +40,6 @@ async function keepUpload({ socket, presence }, local, locator, identifier, uplo
39
40
  if (!socket.continuing())
40
41
  throw new Error();
41
42
  }
42
- function logAccepted({ journal }, locator, submitted, accepted) {
43
- journal.record(`outcome ${locator} ${submitted.id} accepted ${accepted.roomVersion}` +
44
- (accepted.author === undefined ? '' : ` author ${accepted.author}`) +
45
- (accepted.time === undefined ? '' : ` time ${accepted.time}`));
46
- }
47
43
  function restands(adoptions) {
48
44
  return adoptions.flatMap((one) => (one === null || !('record' in one) ? [] : [one]));
49
45
  }
@@ -55,7 +51,6 @@ async function adoption(runtime, room, current, local, submitted, accepted) {
55
51
  return null;
56
52
  }
57
53
  const held = current.record.roomVersion;
58
- logAccepted(runtime, room.locator, submitted, accepted);
59
54
  let record = current.record;
60
55
  let adopted;
61
56
  if (!socket.reads.reached(room.locator, held, accepted.roomVersion) &&
@@ -110,6 +105,25 @@ async function adoptedMove(runtime, room, partner, local, submitted, accepted) {
110
105
  submitLater(runtime, partner);
111
106
  return kept;
112
107
  }
108
+ async function writtenOf({ store }, local, locator, batch) {
109
+ const record = (await store.record(locator));
110
+ const paths = [...touchedBy([batch])];
111
+ const confirmed = await stepped(slicing(await local.entries(record.key, 'confirmed', paths), paths));
112
+ return stepped(writtenDocuments(confirmed, batch, store.composed(record)));
113
+ }
114
+ const STALE_BASES = new Set(['base_revision_stale', 'merge_conflict']);
115
+ function staleOnly(fields) {
116
+ const { conflicts } = fields;
117
+ return (Array.isArray(conflicts) &&
118
+ conflicts.length > 0 &&
119
+ conflicts.every((conflict) => typeof conflict === 'object' &&
120
+ conflict !== null &&
121
+ STALE_BASES.has(conflict.code)));
122
+ }
123
+ function rebuilt(sent, again) {
124
+ return (again.every((document) => document === null || !document.stale) &&
125
+ JSON.stringify(again) !== JSON.stringify(sent));
126
+ }
113
127
  async function behindIn({ store }, locator, batch) {
114
128
  const local = await store.open();
115
129
  const [order, { room }] = await Promise.all([
@@ -119,11 +133,11 @@ async function behindIn({ store }, locator, batch) {
119
133
  return room ? order.indexOf(batch.id) > 0 : order.length > 0;
120
134
  }
121
135
  async function submitRoom(runtime, room, local, authorized, progress, signal) {
122
- const { store, socket, presence, journal } = runtime;
136
+ const { store, socket, presence } = runtime;
123
137
  while (socket.continuing() &&
124
138
  socket.session.now().authorization !== undefined &&
125
139
  !signal.aborted) {
126
- const headId = (await local.order(room.locator)).find((id) => store.landed.of(room.locator, id) === undefined);
140
+ const headId = (await local.order(room.locator)).find((id) => store.conflicted.of(room.locator, id) === undefined);
127
141
  if (headId === undefined)
128
142
  return 'done';
129
143
  const [head, pending] = await Promise.all([
@@ -152,12 +166,11 @@ async function submitRoom(runtime, room, local, authorized, progress, signal) {
152
166
  }
153
167
  if (socket.writesHeld()) {
154
168
  progress.complete = false;
155
- journal.record(`submission ${room.locator} ${head.id} held`);
156
169
  return 'done';
157
170
  }
158
171
  const lost = earlier || submission.state === 'submitted';
159
172
  let result;
160
- journal.record(`submission ${room.locator} ${head.id}`);
173
+ const written = await writtenOf(runtime, local, room.locator, head);
161
174
  await store.exclusive(() => mark(runtime, local, room.locator, head, { state: 'submitted' }, lost));
162
175
  if (socket.session.now().paused || presence.lost(room.locator))
163
176
  return 'done';
@@ -166,7 +179,6 @@ async function submitRoom(runtime, room, local, authorized, progress, signal) {
166
179
  if (signal.aborted)
167
180
  return 'done';
168
181
  progress.complete = false;
169
- journal.record(`submission ${room.locator} ${head.id} held`);
170
182
  return 'done';
171
183
  }
172
184
  const opensBefore = socket.session.now().openSignals;
@@ -180,6 +192,7 @@ async function submitRoom(runtime, room, local, authorized, progress, signal) {
180
192
  result = await socket.mutate(authorized, {
181
193
  locator: room.locator,
182
194
  changeBatch: head,
195
+ written,
183
196
  file: batchFile(store, head),
184
197
  ...(state?.upload === undefined ? {} : { upload: state.upload }),
185
198
  }, (upload) => store.exclusive(() => keepUpload(runtime, local, room.locator, head.id, upload)));
@@ -223,7 +236,6 @@ async function submitRoom(runtime, room, local, authorized, progress, signal) {
223
236
  return 'done';
224
237
  }
225
238
  if (result.kind === 'write-halted') {
226
- journal.record(`outcome ${room.locator} ${head.id} write-halted`);
227
239
  await store.exclusive(() => mark(runtime, local, room.locator, head, { state: 'waiting' }, lost));
228
240
  if (!socket.haltedSince(opensBefore))
229
241
  continue;
@@ -231,15 +243,6 @@ async function submitRoom(runtime, room, local, authorized, progress, signal) {
231
243
  return 'done';
232
244
  }
233
245
  const other = partner === null ? undefined : presence.room(partner);
234
- if (result.kind === 'conflicted' ||
235
- result.kind === 'rejected' ||
236
- result.kind === 'retryable-refusal') {
237
- journal.record(`outcome ${room.locator} ${head.id} ${result.kind}` +
238
- (result.kind === 'conflicted' && result.roomVersion !== undefined
239
- ? ` ${result.roomVersion}`
240
- : ''));
241
- journal.record(`refusal ${result.kind} ${result.code}`);
242
- }
243
246
  if (result.kind === 'retryable-refusal') {
244
247
  runtime.retries.failed('sending', submitting(room.locator), refusalError(result));
245
248
  const reset = result.reset;
@@ -247,6 +250,13 @@ async function submitRoom(runtime, room, local, authorized, progress, signal) {
247
250
  await store.exclusive(() => mark(runtime, local, room.locator, head, reset === undefined ? { state: 'waiting' } : { state: 'reset', reset }, lost));
248
251
  return reset === undefined ? 'again' : { at: Date.parse(reset) };
249
252
  }
253
+ if (result.kind === 'conflicted' && partner === null && staleOnly(result.fields)) {
254
+ const here = await advanced(runtime, room, local, authorized);
255
+ if (here === null && rebuilt(written, await writtenOf(runtime, local, room.locator, head))) {
256
+ await store.exclusive(() => mark(runtime, local, room.locator, head, { state: 'waiting' }, lost));
257
+ continue;
258
+ }
259
+ }
250
260
  if (result.kind === 'conflicted' || result.kind === 'rejected') {
251
261
  const refreshed = async () => ({
252
262
  there: other === undefined ? null : await advanced(runtime, other, local, authorized),
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAM/D,OAAO,EAWL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAOF,wBAAsB,WAAW,CAC/B,OAAO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,CAAC,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,EAAE,WAAW,EAAE,OAAO,EAAE,GAAE,OAAY,GACrC,OAAO,CAAC,UAAU,CAAC,CAiCrB;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,UAAU,CAAC,CAerB;AA4GD,wBAAsB,MAAM,CAC1B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,UAAU,CAAC,CAKrB;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAaxF;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAkB3F;AAiBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,QAG3C"}
package/dist/actions.js CHANGED
@@ -5,12 +5,13 @@ 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
  }
@@ -286,7 +306,10 @@ export async function resendCalls(runtime, signal) {
286
306
  continue;
287
307
  if (socket.closed() || signal.aborted)
288
308
  return 'done';
289
- const sender = keptSender(runtime, held.name, held.input, held.operation, true);
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);
290
313
  try {
291
314
  if (unsettled(await sender.send()))
292
315
  return 'again';