@agentshouse/mdruntime 0.1.0-cef76ea952695 → 0.1.0-cefb45338245d

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 (295) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts +0 -3
  3. package/dist/acceptance.d.ts.map +1 -1
  4. package/dist/acceptance.js +72 -158
  5. package/dist/act-lanes.d.ts +30 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +225 -0
  8. package/dist/actions.d.ts +8 -2
  9. package/dist/actions.d.ts.map +1 -1
  10. package/dist/actions.js +174 -75
  11. package/dist/adapter.d.ts +149 -34
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +0 -1
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +2 -7
  16. package/dist/authored.d.ts +88 -0
  17. package/dist/authored.d.ts.map +1 -0
  18. package/dist/authored.js +347 -0
  19. package/dist/binary.d.ts +6 -2
  20. package/dist/binary.d.ts.map +1 -1
  21. package/dist/binary.js +10 -3
  22. package/dist/bootstrap.d.ts +1 -1
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +6 -19
  25. package/dist/chain.d.ts +1 -1
  26. package/dist/chain.d.ts.map +1 -1
  27. package/dist/chain.js +5 -2
  28. package/dist/change-set.d.ts +4 -0
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +6 -0
  31. package/dist/change.d.ts +6 -2
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +3 -0
  34. package/dist/chat-types.d.ts +0 -2
  35. package/dist/chat-types.d.ts.map +1 -1
  36. package/dist/chat-types.js +2 -4
  37. package/dist/client.d.ts +22 -23
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +51 -66
  40. package/dist/collection.d.ts +27 -4
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +34 -10
  43. package/dist/column.d.ts +5 -0
  44. package/dist/column.d.ts.map +1 -0
  45. package/dist/column.js +9 -0
  46. package/dist/compile.d.ts +4 -1
  47. package/dist/compile.d.ts.map +1 -1
  48. package/dist/compile.js +87 -43
  49. package/dist/connection.d.ts +1 -1
  50. package/dist/connection.d.ts.map +1 -1
  51. package/dist/connection.js +36 -27
  52. package/dist/context.d.ts.map +1 -1
  53. package/dist/context.js +1 -1
  54. package/dist/conversation-live.d.ts +25 -11
  55. package/dist/conversation-live.d.ts.map +1 -1
  56. package/dist/conversation-live.js +23 -11
  57. package/dist/conversation-row.d.ts +8 -1
  58. package/dist/conversation-row.d.ts.map +1 -1
  59. package/dist/conversation-row.js +20 -7
  60. package/dist/conversation.d.ts +43 -11
  61. package/dist/conversation.d.ts.map +1 -1
  62. package/dist/conversation.js +312 -184
  63. package/dist/declaration.d.ts +10 -0
  64. package/dist/declaration.d.ts.map +1 -0
  65. package/dist/declaration.js +24 -0
  66. package/dist/discovery.d.ts +3 -1
  67. package/dist/discovery.d.ts.map +1 -1
  68. package/dist/discovery.js +47 -47
  69. package/dist/download.d.ts +6 -0
  70. package/dist/download.d.ts.map +1 -0
  71. package/dist/download.js +42 -0
  72. package/dist/durability.d.ts +5 -0
  73. package/dist/durability.d.ts.map +1 -1
  74. package/dist/durability.js +7 -0
  75. package/dist/entry.d.ts +22 -1
  76. package/dist/entry.d.ts.map +1 -1
  77. package/dist/entry.js +91 -34
  78. package/dist/expectation.d.ts +25 -14
  79. package/dist/expectation.d.ts.map +1 -1
  80. package/dist/expectation.js +51 -20
  81. package/dist/failure.d.ts +2 -0
  82. package/dist/failure.d.ts.map +1 -1
  83. package/dist/failure.js +6 -1
  84. package/dist/figures.d.ts.map +1 -1
  85. package/dist/figures.js +4 -2
  86. package/dist/file.d.ts +1 -1
  87. package/dist/file.d.ts.map +1 -1
  88. package/dist/file.js +3 -2
  89. package/dist/host.d.ts +24 -4
  90. package/dist/host.d.ts.map +1 -1
  91. package/dist/host.js +108 -32
  92. package/dist/house-query.d.ts +24 -0
  93. package/dist/house-query.d.ts.map +1 -0
  94. package/dist/house-query.js +102 -0
  95. package/dist/index.d.ts +23 -14
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +16 -8
  98. package/dist/install.d.ts +10 -6
  99. package/dist/install.d.ts.map +1 -1
  100. package/dist/install.js +89 -108
  101. package/dist/lifecycle.d.ts +2 -2
  102. package/dist/lifecycle.d.ts.map +1 -1
  103. package/dist/lifecycle.js +74 -54
  104. package/dist/listing.d.ts +29 -22
  105. package/dist/listing.d.ts.map +1 -1
  106. package/dist/listing.js +71 -79
  107. package/dist/live.d.ts +19 -3
  108. package/dist/live.d.ts.map +1 -1
  109. package/dist/live.js +94 -36
  110. package/dist/loaded.d.ts +7 -0
  111. package/dist/loaded.d.ts.map +1 -0
  112. package/dist/loaded.js +46 -0
  113. package/dist/locks.d.ts +2 -4
  114. package/dist/locks.d.ts.map +1 -1
  115. package/dist/locks.js +10 -38
  116. package/dist/lost.d.ts.map +1 -1
  117. package/dist/lost.js +11 -23
  118. package/dist/media.d.ts +19 -3
  119. package/dist/media.d.ts.map +1 -1
  120. package/dist/media.js +167 -33
  121. package/dist/memory.d.ts +10 -4
  122. package/dist/memory.d.ts.map +1 -1
  123. package/dist/memory.js +98 -37
  124. package/dist/messages.d.ts +17 -3
  125. package/dist/messages.d.ts.map +1 -1
  126. package/dist/messages.js +34 -13
  127. package/dist/modal.d.ts +2 -0
  128. package/dist/modal.d.ts.map +1 -0
  129. package/dist/modal.js +11 -0
  130. package/dist/model.d.ts +4 -3
  131. package/dist/model.d.ts.map +1 -1
  132. package/dist/model.js +6 -5
  133. package/dist/models.d.ts +4 -8
  134. package/dist/models.d.ts.map +1 -1
  135. package/dist/models.js +94 -138
  136. package/dist/name.d.ts +0 -1
  137. package/dist/name.d.ts.map +1 -1
  138. package/dist/name.js +3 -7
  139. package/dist/observation.d.ts +29 -12
  140. package/dist/observation.d.ts.map +1 -1
  141. package/dist/observation.js +206 -69
  142. package/dist/online.d.ts +7 -0
  143. package/dist/online.d.ts.map +1 -0
  144. package/dist/online.js +29 -0
  145. package/dist/opened.d.ts +1 -1
  146. package/dist/opened.d.ts.map +1 -1
  147. package/dist/opened.js +2 -2
  148. package/dist/opening.d.ts.map +1 -1
  149. package/dist/opening.js +21 -12
  150. package/dist/outcome.d.ts +24 -4
  151. package/dist/outcome.d.ts.map +1 -1
  152. package/dist/outcome.js +33 -3
  153. package/dist/overlay.d.ts +9 -5
  154. package/dist/overlay.d.ts.map +1 -1
  155. package/dist/overlay.js +37 -24
  156. package/dist/page-metadata.d.ts +8 -0
  157. package/dist/page-metadata.d.ts.map +1 -0
  158. package/dist/page-metadata.js +19 -0
  159. package/dist/parts.d.ts +4 -9
  160. package/dist/parts.d.ts.map +1 -1
  161. package/dist/parts.js +30 -15
  162. package/dist/preparation.d.ts +33 -7
  163. package/dist/preparation.d.ts.map +1 -1
  164. package/dist/preparation.js +207 -96
  165. package/dist/presence.d.ts +58 -0
  166. package/dist/presence.d.ts.map +1 -0
  167. package/dist/presence.js +231 -0
  168. package/dist/queries.d.ts +2 -2
  169. package/dist/queries.d.ts.map +1 -1
  170. package/dist/queries.js +136 -78
  171. package/dist/query.d.ts +2 -2
  172. package/dist/questions.d.ts +1 -5
  173. package/dist/questions.d.ts.map +1 -1
  174. package/dist/questions.js +3 -8
  175. package/dist/queue.d.ts +40 -0
  176. package/dist/queue.d.ts.map +1 -0
  177. package/dist/queue.js +480 -0
  178. package/dist/reach.d.ts +15 -6
  179. package/dist/reach.d.ts.map +1 -1
  180. package/dist/reach.js +182 -38
  181. package/dist/react.d.ts +11 -5
  182. package/dist/react.d.ts.map +1 -1
  183. package/dist/react.js +28 -5
  184. package/dist/readiness.d.ts +20 -4
  185. package/dist/readiness.d.ts.map +1 -1
  186. package/dist/readiness.js +17 -10
  187. package/dist/reads.d.ts +4 -2
  188. package/dist/reads.d.ts.map +1 -1
  189. package/dist/reads.js +9 -4
  190. package/dist/recovery.d.ts +4 -1
  191. package/dist/recovery.d.ts.map +1 -1
  192. package/dist/recovery.js +31 -8
  193. package/dist/reference-forms.d.ts +4 -0
  194. package/dist/reference-forms.d.ts.map +1 -0
  195. package/dist/reference-forms.js +74 -0
  196. package/dist/refresh.d.ts +1 -1
  197. package/dist/refresh.js +6 -6
  198. package/dist/refusal.d.ts.map +1 -1
  199. package/dist/refusal.js +2 -4
  200. package/dist/replica.d.ts +5 -11
  201. package/dist/replica.d.ts.map +1 -1
  202. package/dist/replica.js +16 -18
  203. package/dist/retried.d.ts +30 -0
  204. package/dist/retried.d.ts.map +1 -0
  205. package/dist/retried.js +72 -0
  206. package/dist/room-draft.d.ts +30 -5
  207. package/dist/room-draft.d.ts.map +1 -1
  208. package/dist/room-draft.js +275 -65
  209. package/dist/room-drafts.d.ts.map +1 -1
  210. package/dist/room-drafts.js +11 -6
  211. package/dist/room-list.d.ts +10 -0
  212. package/dist/room-list.d.ts.map +1 -0
  213. package/dist/room-list.js +45 -0
  214. package/dist/rows.d.ts +11 -2
  215. package/dist/rows.d.ts.map +1 -1
  216. package/dist/rows.js +27 -14
  217. package/dist/running.d.ts +5 -0
  218. package/dist/running.d.ts.map +1 -0
  219. package/dist/running.js +10 -0
  220. package/dist/runtime.d.ts +13 -19
  221. package/dist/runtime.d.ts.map +1 -1
  222. package/dist/save.d.ts +43 -90
  223. package/dist/save.d.ts.map +1 -1
  224. package/dist/save.js +314 -223
  225. package/dist/saves.d.ts +6 -42
  226. package/dist/saves.d.ts.map +1 -1
  227. package/dist/saves.js +176 -718
  228. package/dist/seed.d.ts.map +1 -1
  229. package/dist/seed.js +4 -4
  230. package/dist/shown.d.ts +9 -5
  231. package/dist/shown.d.ts.map +1 -1
  232. package/dist/shown.js +93 -57
  233. package/dist/socket/lanes.d.ts +12 -4
  234. package/dist/socket/lanes.d.ts.map +1 -1
  235. package/dist/socket/lanes.js +34 -8
  236. package/dist/socket/session.d.ts +4 -1
  237. package/dist/socket/session.d.ts.map +1 -1
  238. package/dist/socket/session.js +3 -0
  239. package/dist/socket.d.ts +4 -6
  240. package/dist/socket.d.ts.map +1 -1
  241. package/dist/socket.js +4 -14
  242. package/dist/source.d.ts +7 -7
  243. package/dist/source.d.ts.map +1 -1
  244. package/dist/source.js +15 -2
  245. package/dist/store/installs.d.ts +2 -2
  246. package/dist/store/installs.d.ts.map +1 -1
  247. package/dist/store/installs.js +10 -4
  248. package/dist/store/readiness.d.ts +5 -4
  249. package/dist/store/readiness.d.ts.map +1 -1
  250. package/dist/store/readiness.js +28 -12
  251. package/dist/store/records.d.ts +24 -5
  252. package/dist/store/records.d.ts.map +1 -1
  253. package/dist/store/records.js +68 -22
  254. package/dist/store/rooms-shown.d.ts +8 -0
  255. package/dist/store/rooms-shown.d.ts.map +1 -0
  256. package/dist/store/rooms-shown.js +13 -0
  257. package/dist/store.d.ts +25 -15
  258. package/dist/store.d.ts.map +1 -1
  259. package/dist/store.js +50 -18
  260. package/dist/stored.d.ts +39 -14
  261. package/dist/stored.d.ts.map +1 -1
  262. package/dist/stored.js +217 -59
  263. package/dist/surface.d.ts +14 -8
  264. package/dist/surface.d.ts.map +1 -1
  265. package/dist/surface.js +65 -34
  266. package/dist/sync.d.ts +4 -2
  267. package/dist/sync.d.ts.map +1 -1
  268. package/dist/sync.js +127 -102
  269. package/dist/tables.d.ts +28 -52
  270. package/dist/tables.d.ts.map +1 -1
  271. package/dist/tables.js +95 -326
  272. package/dist/tallies.d.ts.map +1 -1
  273. package/dist/tallies.js +1 -2
  274. package/dist/validation.d.ts +2 -0
  275. package/dist/validation.d.ts.map +1 -1
  276. package/dist/validation.js +51 -11
  277. package/dist/wire.d.ts +71 -12
  278. package/dist/wire.d.ts.map +1 -1
  279. package/dist/wire.js +30 -14
  280. package/package.json +4 -4
  281. package/dist/attempt.d.ts +0 -16
  282. package/dist/attempt.d.ts.map +0 -1
  283. package/dist/attempt.js +0 -70
  284. package/dist/job.d.ts +0 -5
  285. package/dist/job.d.ts.map +0 -1
  286. package/dist/job.js +0 -7
  287. package/dist/log.d.ts +0 -6
  288. package/dist/log.d.ts.map +0 -1
  289. package/dist/log.js +0 -14
  290. package/dist/socket/rooms.d.ts +0 -44
  291. package/dist/socket/rooms.d.ts.map +0 -1
  292. package/dist/socket/rooms.js +0 -90
  293. package/dist/store/fences.d.ts +0 -16
  294. package/dist/store/fences.d.ts.map +0 -1
  295. package/dist/store/fences.js +0 -26
package/dist/reads.js CHANGED
@@ -25,7 +25,8 @@ export function readAnswers(options) {
25
25
  const leading = new Set(options.leading);
26
26
  const reads = new Map();
27
27
  function leads(read) {
28
- return leading.has(read.at.name);
28
+ const op = read.asked?.op;
29
+ return (leading.has(read.at.name) || (typeof op === 'string' && leading.has(`${read.at.name}.${op}`)));
29
30
  }
30
31
  function show(read, shown) {
31
32
  read.shown = shown;
@@ -47,7 +48,11 @@ export function readAnswers(options) {
47
48
  read.owed = true;
48
49
  return;
49
50
  }
50
- const result = await options.call(read.at.name, read.asked).catch(() => UNCERTAIN);
51
+ const attempt = { step: 'reading', instance: read.key };
52
+ const result = await options.call(read.at.name, read.asked, attempt).catch((error) => {
53
+ options.retries.failed(attempt.step, attempt.instance, error);
54
+ return UNCERTAIN;
55
+ });
51
56
  if (options.closed())
52
57
  return;
53
58
  read.owed = !answered(result);
@@ -151,9 +156,9 @@ export function readAnswers(options) {
151
156
  reads.delete(key);
152
157
  };
153
158
  },
154
- again() {
159
+ again(first = Promise.resolve()) {
155
160
  const all = [...reads.values()];
156
- const led = Promise.all(all.filter(leads).map((read) => ask(read)));
161
+ const led = Promise.all([first, ...all.filter(leads).map((read) => ask(read, first))]);
157
162
  for (const read of all)
158
163
  if (!leads(read))
159
164
  void ask(read, led);
@@ -5,6 +5,7 @@ export type Attempt = (signal: AbortSignal) => Promise<Attempted>;
5
5
  export type AttemptOptions = {
6
6
  readonly at?: number;
7
7
  readonly again?: boolean;
8
+ readonly attempts?: number;
8
9
  };
9
10
  export type RecoveryOptions = {
10
11
  readonly firstMs?: number;
@@ -16,11 +17,13 @@ export type Recovery = {
16
17
  attempt(intent: string, run: Attempt, options?: AttemptOptions): Promise<boolean>;
17
18
  pending(intent: string): boolean;
18
19
  resume(): void;
20
+ again(): void;
21
+ waits(wake: () => void): () => void;
19
22
  cancel(intent: string): void;
20
23
  scope(inFlight?: number): Recovery;
21
24
  retire(): Promise<void>;
22
25
  };
23
26
  export declare function retryDelay(tries: number, firstMs?: number, maxMs?: number): number;
24
- export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean): Promise<T>;
27
+ export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean, owner?: Recovery): Promise<T>;
25
28
  export declare function createRecovery(options?: RecoveryOptions): Recovery;
26
29
  //# sourceMappingURL=recovery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../src/recovery.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAElE,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEhF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,CAAC,MAA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s, firstMs * 2 ** tries);
8
8
  return longest / 2 + (Math.random() * longest) / 2;
9
9
  }
10
- export async function untilAnswered(ask, signal, answered = () => true) {
10
+ export async function untilAnswered(ask, signal, answered = () => true, owner) {
11
11
  for (let tries = 0;; tries += 1) {
12
12
  try {
13
13
  const answer = await ask();
@@ -19,16 +19,16 @@ export async function untilAnswered(ask, signal, answered = () => true) {
19
19
  throw error;
20
20
  }
21
21
  await new Promise((resume) => {
22
- const stop = () => {
22
+ const done = () => {
23
23
  clearTimeout(again);
24
+ signal.removeEventListener('abort', done);
25
+ unheld();
24
26
  resume();
25
27
  };
26
28
  // A read that failed is asked again on the doubling backoff, so its asker is answered once the failure clears.
27
- const again = setTimeout(() => {
28
- signal.removeEventListener('abort', stop);
29
- resume();
30
- }, retryDelay(tries));
31
- signal.addEventListener('abort', stop, { once: true });
29
+ const again = setTimeout(done, retryDelay(tries));
30
+ signal.addEventListener('abort', done, { once: true });
31
+ const unheld = owner?.waits(done) ?? (() => { });
32
32
  });
33
33
  signal.throwIfAborted();
34
34
  }
@@ -38,6 +38,7 @@ function owner(backoff, inFlight, release = () => { }) {
38
38
  const children = new Set();
39
39
  const running = new Set();
40
40
  const queued = [];
41
+ const waiting = new Set();
41
42
  let free = inFlight;
42
43
  let retired = false;
43
44
  function finish(key, intent, done) {
@@ -105,7 +106,7 @@ function owner(backoff, inFlight, release = () => { }) {
105
106
  return;
106
107
  }
107
108
  intent.tries += 1;
108
- if (intent.tries >= backoff.attempts) {
109
+ if (intent.tries >= intent.attempts) {
109
110
  if (again === null) {
110
111
  finish(key, intent, false);
111
112
  return;
@@ -157,6 +158,7 @@ function owner(backoff, inFlight, release = () => { }) {
157
158
  const intent = {
158
159
  run,
159
160
  tries: 0,
161
+ attempts: options.attempts ?? backoff.attempts,
160
162
  timer: null,
161
163
  due: null,
162
164
  guided: false,
@@ -195,6 +197,27 @@ function owner(backoff, inFlight, release = () => { }) {
195
197
  launch(key, intent);
196
198
  }
197
199
  },
200
+ again() {
201
+ if (retired)
202
+ return;
203
+ for (const [key, intent] of [...intents]) {
204
+ if (intent.timer === null || intent.guided)
205
+ continue;
206
+ clearTimeout(intent.timer);
207
+ intent.timer = null;
208
+ launch(key, intent);
209
+ }
210
+ for (const wake of [...waiting])
211
+ wake();
212
+ for (const child of [...children])
213
+ child.again();
214
+ },
215
+ waits(wake) {
216
+ waiting.add(wake);
217
+ return () => {
218
+ waiting.delete(wake);
219
+ };
220
+ },
198
221
  cancel(key) {
199
222
  const intent = intents.get(key);
200
223
  if (intent === undefined)
@@ -0,0 +1,4 @@
1
+ import type { Connection } from './tables.js';
2
+ export declare function kindedRevision(value: string): string;
3
+ export declare function kindedReferences(connection: Connection): void;
4
+ //# sourceMappingURL=reference-forms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-forms.d.ts","sourceRoot":"","sources":["../src/reference-forms.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,aAAa,CAAC;AAuBrD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGpD;AAuCD,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAuB7D"}
@@ -0,0 +1,74 @@
1
+ import { ATTACHMENT_REFERENCE_PREFIX, CROCKFORD_CHARACTER, CROCKFORD_LEADING_CHARACTER, DOCUMENT_REFERENCE_PREFIX, REVISION_REFERENCE_PREFIX, } from '@agentshouse/mdmodel';
2
+ import { text, texts } from './column.js';
3
+ import { markdownPath } from './rows.js';
4
+ const ORDINAL = `${CROCKFORD_LEADING_CHARACTER}${CROCKFORD_CHARACTER}*`;
5
+ const OLD_REVISION = new RegExp(`^fr_(${ORDINAL}\\.${ORDINAL}\\.${CROCKFORD_CHARACTER})$`, 'u');
6
+ const OLD_ENTRY = new RegExp(`^af_(${ORDINAL})\\.(${CROCKFORD_CHARACTER})$`, 'u');
7
+ const RECORDS = [
8
+ ['authored_pending', 'batch', ['locator', 'id']],
9
+ ['authored_pending', 'state', ['locator', 'id']],
10
+ ['authored_room_drafts', 'record', ['locator', 'path']],
11
+ ['authored_chat_drafts', 'record', ['conversation']],
12
+ ['authored_calls', 'record', ['operation']],
13
+ ];
14
+ const REVISIONS = [
15
+ ['replica_entries', 'revision'],
16
+ ['opened_files', 'revision'],
17
+ ];
18
+ export function kindedRevision(value) {
19
+ const revision = OLD_REVISION.exec(value);
20
+ return revision === null ? value : `${REVISION_REFERENCE_PREFIX}${revision[1]}`;
21
+ }
22
+ function kindedReference(value, paths) {
23
+ const revised = kindedRevision(value);
24
+ if (revised !== value)
25
+ return revised;
26
+ const entry = OLD_ENTRY.exec(value);
27
+ const path = entry === null ? undefined : paths.get(entry[1]);
28
+ if (entry === null || path === undefined)
29
+ return value;
30
+ const prefix = markdownPath(path) ? DOCUMENT_REFERENCE_PREFIX : ATTACHMENT_REFERENCE_PREFIX;
31
+ return `${prefix}${entry[1]}.${entry[2]}`;
32
+ }
33
+ function kinded(value, paths) {
34
+ if (typeof value === 'string')
35
+ return kindedReference(value, paths);
36
+ if (Array.isArray(value))
37
+ return value.map((item) => kinded(item, paths));
38
+ if (value === null || typeof value !== 'object')
39
+ return value;
40
+ return Object.fromEntries(Object.entries(value).map(([name, item]) => [name, kinded(item, paths)]));
41
+ }
42
+ function heldColumns(connection, table) {
43
+ return new Set(texts(connection.rows('SELECT name FROM pragma_table_info(?)', [table]), 'name'));
44
+ }
45
+ function heldPaths(connection) {
46
+ const columns = heldColumns(connection, 'replica_entries');
47
+ if (!columns.has('file_id') || !columns.has('path'))
48
+ return new Map();
49
+ return new Map(connection
50
+ .rows('SELECT DISTINCT file_id, path FROM replica_entries WHERE file_id IS NOT NULL')
51
+ .map((row) => [text(row.file_id), text(row.path)]));
52
+ }
53
+ function holdingOldForm(column) {
54
+ return `(${column} LIKE '%"fr\\_%' ESCAPE '\\' OR ${column} LIKE '%"af\\_%' ESCAPE '\\')`;
55
+ }
56
+ export function kindedReferences(connection) {
57
+ for (const [table, column] of REVISIONS) {
58
+ if (!heldColumns(connection, table).has(column))
59
+ continue;
60
+ connection.run(`UPDATE ${table} SET ${column} = '${REVISION_REFERENCE_PREFIX}' || substr(${column}, 4) WHERE ${column} LIKE 'fr\\_%' ESCAPE '\\'`);
61
+ }
62
+ let paths = null;
63
+ for (const [table, column, keys] of RECORDS) {
64
+ const held = connection.rows(`SELECT ${keys.join(', ')}, ${column} AS value FROM ${table} WHERE ${holdingOldForm(column)}`);
65
+ for (const row of held) {
66
+ paths ??= heldPaths(connection);
67
+ const value = JSON.parse(text(row.value));
68
+ const written = JSON.stringify(kinded(value, paths));
69
+ if (written === JSON.stringify(value))
70
+ continue;
71
+ connection.run(`UPDATE ${table} SET ${column} = ? WHERE ${keys.map((key) => `${key} = ?`).join(' AND ')}`, [written, ...keys.map((key) => row[key])]);
72
+ }
73
+ }
74
+ }
package/dist/refresh.d.ts CHANGED
@@ -20,7 +20,7 @@ export type Refreshing = {
20
20
  later(paths: readonly string[], roomVersion: string): Promise<ReadonlySet<string>>;
21
21
  stage(page: RefreshedPage): Promise<boolean>;
22
22
  };
23
- type PageContent = Pick<RefreshPage, 'documents' | 'facts' | 'revisions' | 'fileIds' | 'created' | 'changes' | 'binaryFiles'>;
23
+ type PageContent = Pick<RefreshPage, 'documents' | 'facts' | 'revisions' | 'fileIds' | 'created' | 'changes' | 'attachments'>;
24
24
  export declare function pageEntries(page: PageContent, removals: readonly string[], roomVersion: string, prior: (paths: readonly string[]) => Promise<ReadonlyMap<string, HeldEntry>>): Promise<StoredEntry[]>;
25
25
  export declare function advancement(refresh: Refresher, authorization: Authorization, held: ReplicaRecord, remodel: Remodel, continuing: () => boolean, staging: Refreshing): Promise<Advancement>;
26
26
  export {};
package/dist/refresh.js CHANGED
@@ -12,7 +12,7 @@ function* listing(page, removals) {
12
12
  const written = new Set();
13
13
  for (const [kept, named] of [
14
14
  [documents, page.documents],
15
- [binaries, page.binaryFiles],
15
+ [binaries, page.attachments],
16
16
  ]) {
17
17
  for (const path of Object.keys(named)) {
18
18
  yield ROW_WEIGHT;
@@ -60,7 +60,7 @@ function* entering(page, roomVersion, listed, prior) {
60
60
  path,
61
61
  content: null,
62
62
  facts: null,
63
- binary: { state: 'accepted', ...page.binaryFiles[path] },
63
+ binary: { state: 'accepted', ...page.attachments[path] },
64
64
  revision: page.revisions[path] ?? prior.get(path)?.revision ?? null,
65
65
  fileId: page.fileIds?.[path] ?? null,
66
66
  created: page.created?.[path] ?? null,
@@ -104,14 +104,14 @@ function unwritten(page, kept) {
104
104
  ...(page.fileIds === undefined ? {} : { fileIds: without(page.fileIds, kept) }),
105
105
  ...(page.created === undefined ? {} : { created: without(page.created, kept) }),
106
106
  changes: without(page.changes, kept),
107
- binaryFiles: without(page.binaryFiles, kept),
107
+ attachments: without(page.attachments, kept),
108
108
  removals: page.removals.filter((path) => !kept.has(path)),
109
109
  };
110
110
  }
111
111
  async function pageOf(answered, roomVersion, staging) {
112
112
  const page = unwritten(answered, await staging.later([
113
113
  ...Object.keys(answered.documents),
114
- ...Object.keys(answered.binaryFiles),
114
+ ...Object.keys(answered.attachments),
115
115
  ...answered.removals,
116
116
  ], roomVersion));
117
117
  return {
@@ -129,7 +129,7 @@ export async function advancement(refresh, authorization, held, remodel, continu
129
129
  return unconfirmed;
130
130
  const first = await refresh(authorization, {
131
131
  locator,
132
- selection: held.replica.selection,
132
+ selection: held.declaration.replica.selection,
133
133
  fromRoomVersion,
134
134
  });
135
135
  if (first.kind !== 'net-advancement')
@@ -154,7 +154,7 @@ export async function advancement(refresh, authorization, held, remodel, continu
154
154
  return unconfirmed;
155
155
  const page = await refresh(authorization, {
156
156
  locator,
157
- selection: held.replica.selection,
157
+ selection: held.declaration.replica.selection,
158
158
  fromRoomVersion,
159
159
  pageToken,
160
160
  });
@@ -1 +1 @@
1
- {"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAQpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,wBAAsB,MAAM,CAC1B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,aAAa,EACrB,QAAQ,GAAE,eAAe,GAAG,IAAW,iBAmDxC"}
1
+ {"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAQpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,wBAAsB,MAAM,CAC1B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,aAAa,EACrB,QAAQ,GAAE,eAAe,GAAG,IAAW,iBAiDxC"}
package/dist/refusal.js CHANGED
@@ -6,7 +6,7 @@ import { prepare } from './preparation.js';
6
6
  import { storedRecord } from './replica.js';
7
7
  import { emitRefusal } from './shown.js';
8
8
  export async function refuse(runtime, reason, provider = null) {
9
- const { store, socket, journal } = runtime;
9
+ const { store, socket, presence } = runtime;
10
10
  socket.session.set({ paused: true });
11
11
  socket.abortReads();
12
12
  try {
@@ -30,13 +30,12 @@ export async function refuse(runtime, reason, provider = null) {
30
30
  });
31
31
  }
32
32
  catch (error) {
33
- journal.record('model revocation persistence failed');
34
33
  uncaught(error);
35
34
  }
36
35
  const listedNow = listedLocators(runtime, held);
37
36
  for (const locator of listedNow) {
38
37
  if (!held.has(locator))
39
- socket.rooms.stand(locator, { unheldModel: revoked });
38
+ presence.modelled(locator, revoked);
40
39
  }
41
40
  store.changed(mergeChangeSets(listedNow.map((locator) => changeSet(locator, { documents: null, room: true }))));
42
41
  prepare(runtime);
@@ -51,7 +50,6 @@ export async function refuse(runtime, reason, provider = null) {
51
50
  refusal: provider,
52
51
  },
53
52
  });
54
- journal.record(`connection refused ${reason}`);
55
53
  emitRefusal(runtime);
56
54
  }
57
55
  }
package/dist/replica.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type TypedPath } from '@agentshouse/mdmodel';
2
- import type { BootstrapInventory, SavedFacts, MutationResult, OperationScopes, ReplicaAdmission, TypedSelection } from './adapter.js';
2
+ import type { BootstrapInventory, SavedFacts, MutationResult, RoomDeclaration, TypedSelection } from './adapter.js';
3
3
  import { type ChangeBatch, type Precondition } from './change.js';
4
4
  import { type Collection, type Composition } from './collection.js';
5
5
  import { type ModelState } from './model.js';
@@ -7,14 +7,8 @@ import { type Layer } from './overlay.js';
7
7
  import type { HeldEntry, OverlayEntry, StoredEntry } from './tables.js';
8
8
  export type ReplicaRecord = {
9
9
  readonly locator: string;
10
- readonly name: string;
11
- readonly handle: string;
12
- readonly operations: OperationScopes;
13
- readonly replica: ReplicaAdmission;
10
+ readonly declaration: RoomDeclaration;
14
11
  readonly model: ModelState;
15
- readonly typedSelection: TypedSelection | null;
16
- readonly providerOwnedPaths: readonly string[];
17
- readonly authoredPaths?: readonly string[];
18
12
  readonly roomVersion: string;
19
13
  readonly transfer: string;
20
14
  readonly inventory: BootstrapInventory;
@@ -33,7 +27,7 @@ export type Slice = Layer & {
33
27
  readonly facts: Readonly<Record<string, SavedFacts>>;
34
28
  readonly held: ReadonlySet<string>;
35
29
  };
36
- export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
30
+ export declare function compositionOf(model: ModelState, typedSelection: TypedSelection | null, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
37
31
  export declare function storedRecord(record: ReplicaRecord): string;
38
32
  export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
39
33
  export type LayerEntry = Omit<StoredEntry, 'facts'>;
@@ -49,8 +43,8 @@ export type Replayed = {
49
43
  };
50
44
  export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
51
45
  export declare function overlayOf(visible: VisibleLayer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
52
- export declare function holds(layer: Layer, preconditions: readonly Precondition[]): boolean;
53
- export declare function landed(batch: ChangeBatch, confirmed: Layer, current?: Readonly<Record<string, string>>): boolean;
46
+ export declare function holds(layer: Layer, preconditions: readonly Precondition[], composition: Composition): boolean;
47
+ export declare function landed(batch: ChangeBatch, confirmed: Layer, composition: Composition, current?: Readonly<Record<string, string>>): boolean;
54
48
  export type Standing = {
55
49
  readonly withdrawn: readonly ChangeBatch[];
56
50
  readonly kept: readonly ChangeBatch[];
@@ -1 +1 @@
1
- {"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EAEV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAmC,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAgB,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAiD,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAIzF,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGxE,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,eAAe,CA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,EAAE,SAAS,WAAW,EAAE,CAAC;CACvC,CAAC;AAEF,wBAAiB,QAAQ,CACvB,SAAS,EAAE,KAAK,EAChB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,YAAY,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,EAC7C,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,GACvB,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CA4BnC;AAED,KAAK,QAAQ,GAAG,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AAE9D,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,GAAG,EAAE,SAAS,WAAW,EAAE,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF,wBAAgB,aAAa,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAiBrF;AAED,wBAAiB,SAAS,CACxB,SAAS,EAAE,KAAK,EAChB,SAAS,EAAE,WAAW,EACtB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,WAAW,GACvB,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CA6FnC"}
package/dist/replica.js CHANGED
@@ -1,18 +1,16 @@
1
1
  import { equalValue, parse } from '@agentshouse/mdmodel';
2
- import { immutable, landing } from './change.js';
3
- import { collectionOf } from './collection.js';
2
+ import { immutable, isPart, landing, } from './change.js';
3
+ import { collectionOf, definitionsAt } from './collection.js';
4
4
  import { storedModel } from './model.js';
5
5
  import { acceptedBinaries, overlaying } from './overlay.js';
6
6
  import { writtenFacts } from './rows.js';
7
7
  import { effectiveIn, rewriting } from './save.js';
8
8
  import { guarding } from './shared.js';
9
9
  import { ROW_WEIGHT } from './turn.js';
10
- export function compositionOf(record, builtIn, typedPaths) {
10
+ export function compositionOf(model, typedSelection, builtIn, typedPaths) {
11
11
  return {
12
- model: record.model,
13
- selection: record.typedSelection === null
14
- ? null
15
- : { roots: record.typedSelection.roots, model: builtIn },
12
+ model,
13
+ selection: typedSelection === null ? null : { roots: typedSelection.roots, model: builtIn },
16
14
  typedPaths,
17
15
  };
18
16
  }
@@ -171,7 +169,7 @@ export function* replaying(confirmed, queue, locator, composition) {
171
169
  for (const change of effective.changes)
172
170
  for (const path of changePaths(change))
173
171
  touched.add(path);
174
- layer = yield* overlaying(layer, [effective]);
172
+ layer = yield* overlaying(layer, [effective], composition);
175
173
  yield ROW_WEIGHT;
176
174
  }
177
175
  return {
@@ -210,12 +208,12 @@ export function* overlayOf(visible, touched) {
210
208
  function present(layer, path) {
211
209
  return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
212
210
  }
213
- export function holds(layer, preconditions) {
211
+ export function holds(layer, preconditions, composition) {
214
212
  const parsed = new Map();
215
213
  const documentAt = (path) => {
216
214
  if (!parsed.has(path)) {
217
215
  const text = layer.documents[path];
218
- const opened = text === undefined ? null : parse(text, path);
216
+ const opened = text === undefined ? null : parse(text, path, definitionsAt(composition, path));
219
217
  parsed.set(path, opened?.ok === true ? opened.document : null);
220
218
  }
221
219
  return parsed.get(path) ?? null;
@@ -249,7 +247,7 @@ export function holds(layer, preconditions) {
249
247
  }
250
248
  function effects(change) {
251
249
  const path = change.path;
252
- if (change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble') {
250
+ if (isPart(change)) {
253
251
  return [change];
254
252
  }
255
253
  if (change.kind === 'create' && !('content' in change)) {
@@ -279,7 +277,7 @@ function effects(change) {
279
277
  return [{ kind: 'present', path }];
280
278
  return [{ kind: 'absent', path }];
281
279
  }
282
- export function landed(batch, confirmed, current = {}) {
280
+ export function landed(batch, confirmed, composition, current = {}) {
283
281
  const documents = new Proxy(confirmed.documents, {
284
282
  get(target, property, receiver) {
285
283
  if (typeof property === 'string' && Object.hasOwn(current, property))
@@ -299,9 +297,9 @@ export function landed(batch, confirmed, current = {}) {
299
297
  }
300
298
  return effects(change).every((effect) => {
301
299
  if (effect.kind === 'absent')
302
- return holds(layer, [effect]);
300
+ return holds(layer, [effect], composition);
303
301
  const at = landing(batch.changes, index, effect.path);
304
- return at === null || holds(layer, [{ ...effect, path: at }]);
302
+ return at === null || holds(layer, [{ ...effect, path: at }], composition);
305
303
  });
306
304
  });
307
305
  }
@@ -326,7 +324,7 @@ export function* standing(confirmed, queue, withdrawable, local, locator, compos
326
324
  const withdrawn = [];
327
325
  const kept = [];
328
326
  for (const batch of queue) {
329
- if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
327
+ if (withdrawable(batch) && !holds(layer, batch.preconditions, composition)) {
330
328
  withdrawn.push(batch);
331
329
  continue;
332
330
  }
@@ -337,7 +335,7 @@ export function* standing(confirmed, queue, withdrawable, local, locator, compos
337
335
  })
338
336
  : batch;
339
337
  let unapplied = false;
340
- const next = yield* overlaying(layer, [effective], () => {
338
+ const next = yield* overlaying(layer, [effective], composition, () => {
341
339
  unapplied = true;
342
340
  });
343
341
  if (local && unapplied) {
@@ -355,7 +353,7 @@ export function returnedPaths(submitted, accepted) {
355
353
  ...Object.keys(accepted.revisions),
356
354
  ...Object.keys(accepted.fileIds ?? {}),
357
355
  ...Object.keys(accepted.changes),
358
- ...Object.keys(accepted.binaryFiles ?? {}),
356
+ ...Object.keys(accepted.attachments ?? {}),
359
357
  ...accepted.removals,
360
358
  ]);
361
359
  for (const change of submitted.changes) {
@@ -422,7 +420,7 @@ export function* returning(confirmed, submitted, accepted, writtenAt, compositio
422
420
  binaries.set(change.to, moved);
423
421
  binaries.set(change.path, undefined);
424
422
  }
425
- for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {}))
423
+ for (const [path, binary] of acceptedBinaries(accepted.attachments ?? {}))
426
424
  binaries.set(path, binary);
427
425
  for (const path of accepted.removals) {
428
426
  binaries.set(path, undefined);
@@ -0,0 +1,30 @@
1
+ import { type RuntimeShell } from './durability.js';
2
+ export declare const STEPS: readonly ['database', 'sign_in', 'connection', 'code', 'download', 'conversations', 'sending', 'reading'];
3
+ export type Step = (typeof STEPS)[number];
4
+ export type RetriedFailure = {
5
+ readonly step: Step;
6
+ readonly answered: false;
7
+ } | {
8
+ readonly step: Step;
9
+ readonly answered: true;
10
+ readonly error: unknown;
11
+ };
12
+ export type Uncertain = {
13
+ readonly failure?: unknown;
14
+ };
15
+ export type Attempt = {
16
+ readonly step: Step;
17
+ readonly instance: string;
18
+ };
19
+ export declare class Unanswered extends Error {
20
+ }
21
+ export declare function uncertainError(uncertainty: Uncertain): unknown;
22
+ export type Retries = {
23
+ failed(step: Step, instance: string, error: unknown): void;
24
+ unanswered(step: Step, instance: string): void;
25
+ uncertain(step: Step, instance: string, uncertainty: Uncertain): void;
26
+ succeeded(step: Step, instance: string): void;
27
+ };
28
+ export declare function createRetries(shell: Pick<RuntimeShell, 'retried' | 'succeeded'>): Retries;
29
+ export declare function retrying<T>(retries: Retries, step: Step, instance: string, ask: () => Promise<T>): () => Promise<T>;
30
+ //# sourceMappingURL=retried.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retried.d.ts","sourceRoot":"","sources":["../src/retried.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAErE,eAAO,MAAM,KAAK,YAChB,UAAU,EACV,SAAS,EACT,YAAY,EACZ,MAAM,EACN,UAAU,EACV,eAAe,EACf,SAAS,EACT,SAAS,CACD,CAAC;AAEX,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1C,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,IAAI,EAAE,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 'sign_in',
5
+ 'connection',
6
+ 'code',
7
+ 'download',
8
+ 'conversations',
9
+ 'sending',
10
+ 'reading',
11
+ ];
12
+ export class Unanswered extends Error {
13
+ }
14
+ export function uncertainError(uncertainty) {
15
+ return 'failure' in uncertainty ? uncertainty.failure : new Unanswered();
16
+ }
17
+ export function createRetries(shell) {
18
+ const failing = new Map();
19
+ const handedErrors = new WeakSet();
20
+ function failingIn(step, instance) {
21
+ const instances = failing.get(step) ?? new Set();
22
+ instances.add(instance);
23
+ failing.set(step, instances);
24
+ }
25
+ function handed(failure, instance) {
26
+ failingIn(failure.step, instance);
27
+ shell.retried?.(failure);
28
+ }
29
+ const retries = {
30
+ failed(step, instance, error) {
31
+ if (refusedForSpace(error))
32
+ return;
33
+ if (typeof error === 'object' && error !== null) {
34
+ if (handedErrors.has(error)) {
35
+ failingIn(step, instance);
36
+ return;
37
+ }
38
+ handedErrors.add(error);
39
+ }
40
+ if (error instanceof Unanswered)
41
+ retries.unanswered(step, instance);
42
+ else
43
+ handed({ step, answered: true, error }, instance);
44
+ },
45
+ unanswered(step, instance) {
46
+ handed({ step, answered: false }, instance);
47
+ },
48
+ uncertain(step, instance, uncertainty) {
49
+ if ('failure' in uncertainty)
50
+ retries.failed(step, instance, uncertainty.failure);
51
+ else
52
+ retries.unanswered(step, instance);
53
+ },
54
+ succeeded(step, instance) {
55
+ const instances = failing.get(step);
56
+ if (instances === undefined || !instances.delete(instance) || instances.size > 0)
57
+ return;
58
+ failing.delete(step);
59
+ shell.succeeded?.(step);
60
+ },
61
+ };
62
+ return retries;
63
+ }
64
+ export function retrying(retries, step, instance, ask) {
65
+ return () => ask().then((answer) => {
66
+ retries.succeeded(step, instance);
67
+ return answer;
68
+ }, (error) => {
69
+ retries.failed(step, instance, error);
70
+ throw error;
71
+ });
72
+ }