@agentshouse/mdruntime 0.1.0-c806ecaf4afed → 0.1.0-c83bc1fac9b35

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 (248) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +15 -24
  4. package/dist/act-lanes.d.ts +11 -14
  5. package/dist/act-lanes.d.ts.map +1 -1
  6. package/dist/act-lanes.js +53 -5
  7. package/dist/actions.d.ts +8 -2
  8. package/dist/actions.d.ts.map +1 -1
  9. package/dist/actions.js +138 -68
  10. package/dist/adapter.d.ts +86 -14
  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 +0 -5
  15. package/dist/authored.d.ts +88 -0
  16. package/dist/authored.d.ts.map +1 -0
  17. package/dist/authored.js +345 -0
  18. package/dist/change.d.ts +4 -0
  19. package/dist/change.d.ts.map +1 -1
  20. package/dist/change.js +3 -0
  21. package/dist/chat-types.d.ts +0 -2
  22. package/dist/chat-types.d.ts.map +1 -1
  23. package/dist/chat-types.js +0 -2
  24. package/dist/client.d.ts +14 -11
  25. package/dist/client.d.ts.map +1 -1
  26. package/dist/client.js +18 -46
  27. package/dist/collection.d.ts +5 -1
  28. package/dist/collection.d.ts.map +1 -1
  29. package/dist/collection.js +16 -8
  30. package/dist/column.d.ts +5 -0
  31. package/dist/column.d.ts.map +1 -0
  32. package/dist/column.js +9 -0
  33. package/dist/compile.d.ts +2 -0
  34. package/dist/compile.d.ts.map +1 -1
  35. package/dist/compile.js +17 -5
  36. package/dist/connection.d.ts +1 -1
  37. package/dist/connection.d.ts.map +1 -1
  38. package/dist/connection.js +21 -16
  39. package/dist/context.d.ts.map +1 -1
  40. package/dist/context.js +1 -1
  41. package/dist/conversation-live.d.ts +23 -7
  42. package/dist/conversation-live.d.ts.map +1 -1
  43. package/dist/conversation-live.js +18 -6
  44. package/dist/conversation-row.d.ts +8 -1
  45. package/dist/conversation-row.d.ts.map +1 -1
  46. package/dist/conversation-row.js +20 -7
  47. package/dist/conversation.d.ts +20 -7
  48. package/dist/conversation.d.ts.map +1 -1
  49. package/dist/conversation.js +238 -174
  50. package/dist/discovery.d.ts +3 -1
  51. package/dist/discovery.d.ts.map +1 -1
  52. package/dist/discovery.js +36 -9
  53. package/dist/download.d.ts +6 -0
  54. package/dist/download.d.ts.map +1 -0
  55. package/dist/download.js +42 -0
  56. package/dist/durability.d.ts +5 -0
  57. package/dist/durability.d.ts.map +1 -1
  58. package/dist/durability.js +7 -0
  59. package/dist/entry.d.ts +5 -0
  60. package/dist/entry.d.ts.map +1 -1
  61. package/dist/entry.js +23 -12
  62. package/dist/expectation.d.ts +25 -14
  63. package/dist/expectation.d.ts.map +1 -1
  64. package/dist/expectation.js +51 -20
  65. package/dist/failure.d.ts +2 -0
  66. package/dist/failure.d.ts.map +1 -1
  67. package/dist/failure.js +6 -1
  68. package/dist/figures.d.ts.map +1 -1
  69. package/dist/figures.js +4 -2
  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 +6 -2
  74. package/dist/host.d.ts.map +1 -1
  75. package/dist/host.js +50 -16
  76. package/dist/house-query.d.ts +21 -0
  77. package/dist/house-query.d.ts.map +1 -0
  78. package/dist/house-query.js +41 -0
  79. package/dist/index.d.ts +14 -7
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +10 -4
  82. package/dist/install.d.ts +10 -4
  83. package/dist/install.d.ts.map +1 -1
  84. package/dist/install.js +45 -46
  85. package/dist/lifecycle.d.ts +1 -1
  86. package/dist/lifecycle.d.ts.map +1 -1
  87. package/dist/lifecycle.js +50 -32
  88. package/dist/listing.d.ts +24 -12
  89. package/dist/listing.d.ts.map +1 -1
  90. package/dist/listing.js +50 -21
  91. package/dist/live.d.ts +5 -3
  92. package/dist/live.d.ts.map +1 -1
  93. package/dist/live.js +71 -30
  94. package/dist/loaded.d.ts +5 -0
  95. package/dist/loaded.d.ts.map +1 -0
  96. package/dist/loaded.js +40 -0
  97. package/dist/locks.d.ts.map +1 -1
  98. package/dist/locks.js +4 -3
  99. package/dist/lost.d.ts.map +1 -1
  100. package/dist/lost.js +2 -3
  101. package/dist/media.d.ts +18 -1
  102. package/dist/media.d.ts.map +1 -1
  103. package/dist/media.js +102 -24
  104. package/dist/memory.d.ts +5 -1
  105. package/dist/memory.d.ts.map +1 -1
  106. package/dist/memory.js +58 -14
  107. package/dist/messages.d.ts +12 -3
  108. package/dist/messages.d.ts.map +1 -1
  109. package/dist/messages.js +24 -10
  110. package/dist/modal.d.ts +2 -0
  111. package/dist/modal.d.ts.map +1 -0
  112. package/dist/modal.js +11 -0
  113. package/dist/model.d.ts +4 -2
  114. package/dist/model.d.ts.map +1 -1
  115. package/dist/model.js +7 -1
  116. package/dist/models.d.ts.map +1 -1
  117. package/dist/models.js +5 -8
  118. package/dist/observation.d.ts +29 -12
  119. package/dist/observation.d.ts.map +1 -1
  120. package/dist/observation.js +206 -69
  121. package/dist/online.d.ts +7 -0
  122. package/dist/online.d.ts.map +1 -0
  123. package/dist/online.js +29 -0
  124. package/dist/opening.d.ts.map +1 -1
  125. package/dist/opening.js +20 -10
  126. package/dist/outcome.d.ts +13 -1
  127. package/dist/outcome.d.ts.map +1 -1
  128. package/dist/outcome.js +32 -2
  129. package/dist/overlay.d.ts +4 -1
  130. package/dist/overlay.d.ts.map +1 -1
  131. package/dist/overlay.js +11 -9
  132. package/dist/parts.d.ts +4 -9
  133. package/dist/parts.d.ts.map +1 -1
  134. package/dist/parts.js +30 -15
  135. package/dist/preparation.d.ts +32 -7
  136. package/dist/preparation.d.ts.map +1 -1
  137. package/dist/preparation.js +189 -87
  138. package/dist/presence.d.ts +8 -2
  139. package/dist/presence.d.ts.map +1 -1
  140. package/dist/presence.js +24 -13
  141. package/dist/queries.d.ts +2 -2
  142. package/dist/queries.d.ts.map +1 -1
  143. package/dist/queries.js +81 -64
  144. package/dist/questions.d.ts +1 -5
  145. package/dist/questions.d.ts.map +1 -1
  146. package/dist/questions.js +1 -7
  147. package/dist/queue.d.ts +2 -2
  148. package/dist/queue.d.ts.map +1 -1
  149. package/dist/queue.js +73 -48
  150. package/dist/reach.d.ts +14 -6
  151. package/dist/reach.d.ts.map +1 -1
  152. package/dist/reach.js +142 -30
  153. package/dist/react.d.ts +10 -11
  154. package/dist/react.d.ts.map +1 -1
  155. package/dist/react.js +22 -4
  156. package/dist/readiness.d.ts +16 -4
  157. package/dist/readiness.d.ts.map +1 -1
  158. package/dist/readiness.js +10 -10
  159. package/dist/reads.d.ts +4 -2
  160. package/dist/reads.d.ts.map +1 -1
  161. package/dist/reads.js +7 -3
  162. package/dist/recovery.d.ts +4 -1
  163. package/dist/recovery.d.ts.map +1 -1
  164. package/dist/recovery.js +31 -8
  165. package/dist/refusal.d.ts.map +1 -1
  166. package/dist/refusal.js +1 -3
  167. package/dist/replica.d.ts.map +1 -1
  168. package/dist/replica.js +2 -2
  169. package/dist/retried.d.ts +30 -0
  170. package/dist/retried.d.ts.map +1 -0
  171. package/dist/retried.js +72 -0
  172. package/dist/room-draft.d.ts +30 -5
  173. package/dist/room-draft.d.ts.map +1 -1
  174. package/dist/room-draft.js +253 -30
  175. package/dist/room-drafts.d.ts.map +1 -1
  176. package/dist/room-drafts.js +5 -2
  177. package/dist/room-list.d.ts +10 -0
  178. package/dist/room-list.d.ts.map +1 -0
  179. package/dist/room-list.js +45 -0
  180. package/dist/rows.d.ts +2 -1
  181. package/dist/rows.d.ts.map +1 -1
  182. package/dist/rows.js +6 -6
  183. package/dist/running.d.ts +5 -0
  184. package/dist/running.d.ts.map +1 -0
  185. package/dist/running.js +10 -0
  186. package/dist/runtime.d.ts +5 -4
  187. package/dist/runtime.d.ts.map +1 -1
  188. package/dist/save.d.ts +1 -0
  189. package/dist/save.d.ts.map +1 -1
  190. package/dist/save.js +105 -124
  191. package/dist/saves.d.ts +2 -0
  192. package/dist/saves.d.ts.map +1 -1
  193. package/dist/saves.js +42 -18
  194. package/dist/seed.d.ts.map +1 -1
  195. package/dist/seed.js +2 -2
  196. package/dist/shown.d.ts +5 -2
  197. package/dist/shown.d.ts.map +1 -1
  198. package/dist/shown.js +79 -43
  199. package/dist/socket/lanes.d.ts +12 -4
  200. package/dist/socket/lanes.d.ts.map +1 -1
  201. package/dist/socket/lanes.js +34 -8
  202. package/dist/socket/session.d.ts +4 -1
  203. package/dist/socket/session.d.ts.map +1 -1
  204. package/dist/socket/session.js +3 -0
  205. package/dist/socket.d.ts +4 -3
  206. package/dist/socket.d.ts.map +1 -1
  207. package/dist/socket.js +4 -9
  208. package/dist/source.d.ts +5 -7
  209. package/dist/source.d.ts.map +1 -1
  210. package/dist/source.js +13 -2
  211. package/dist/store/installs.d.ts +2 -2
  212. package/dist/store/installs.d.ts.map +1 -1
  213. package/dist/store/installs.js +10 -4
  214. package/dist/store/readiness.d.ts +5 -4
  215. package/dist/store/readiness.d.ts.map +1 -1
  216. package/dist/store/readiness.js +28 -12
  217. package/dist/store/records.d.ts +20 -5
  218. package/dist/store/records.d.ts.map +1 -1
  219. package/dist/store/records.js +60 -22
  220. package/dist/store/rooms-shown.d.ts +8 -0
  221. package/dist/store/rooms-shown.d.ts.map +1 -0
  222. package/dist/store/rooms-shown.js +13 -0
  223. package/dist/store.d.ts +17 -10
  224. package/dist/store.d.ts.map +1 -1
  225. package/dist/store.js +18 -6
  226. package/dist/stored.d.ts +25 -13
  227. package/dist/stored.d.ts.map +1 -1
  228. package/dist/stored.js +80 -27
  229. package/dist/surface.d.ts +12 -6
  230. package/dist/surface.d.ts.map +1 -1
  231. package/dist/surface.js +58 -26
  232. package/dist/sync.d.ts +4 -2
  233. package/dist/sync.d.ts.map +1 -1
  234. package/dist/sync.js +75 -39
  235. package/dist/tables.d.ts +16 -52
  236. package/dist/tables.d.ts.map +1 -1
  237. package/dist/tables.js +86 -324
  238. package/dist/tallies.d.ts.map +1 -1
  239. package/dist/tallies.js +1 -2
  240. package/dist/validation.d.ts.map +1 -1
  241. package/dist/validation.js +3 -9
  242. package/dist/wire.d.ts +33 -10
  243. package/dist/wire.d.ts.map +1 -1
  244. package/dist/wire.js +15 -8
  245. package/package.json +3 -3
  246. package/dist/log.d.ts +0 -6
  247. package/dist/log.d.ts.map +0 -1
  248. package/dist/log.js +0 -14
package/dist/save.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { apply, ARRAY_INDEX, ATTACHMENT, create, links, parse, pointerSegments, references, relative, relativize, retarget, roomReferences, serialize, target, } from '@agentshouse/mdmodel';
2
- import { immutable, leaving, queuedFile, departure, } from './change.js';
3
- import { collectionOf, definitionsAt, documentsOf, governing, } from './collection.js';
2
+ import { immutable, isPart, leaving, queuedFile, departure, } from './change.js';
3
+ import { collectionOf, definitionsAt, documentsOf, governing, textType, typedText, } from './collection.js';
4
4
  import { changeBatchIdentity, roomDraftRevision } from './identity.js';
5
- import { overlaying } from './overlay.js';
5
+ import { composed, overlaying } from './overlay.js';
6
6
  import { ancestors } from './paths.js';
7
7
  import { entriesIn, sorting } from './shared.js';
8
- import { changedParts, changesOf, moveTarget, withdrawnDrafts, } from './room-draft.js';
8
+ import { applyParts, changedParts, changesOf, moveTarget, partsBetween, withdrawnDrafts, } from './room-draft.js';
9
9
  import { paced, ROW_WEIGHT, stepped } from './turn.js';
10
10
  import { validatedCollection } from './validation.js';
11
- function refuse(code, file, location) {
11
+ function refuse(code, file, location, line) {
12
12
  return {
13
13
  kind: 'refused',
14
14
  refusal: {
@@ -16,9 +16,13 @@ function refuse(code, file, location) {
16
16
  retryable: false,
17
17
  ...(file === undefined ? {} : { file }),
18
18
  ...(location === undefined ? {} : { location }),
19
+ ...(line === undefined ? {} : { line }),
19
20
  },
20
21
  };
21
22
  }
23
+ function refusedBy(refusal, file) {
24
+ return refuse(refusal.rule, file, refusal.location, refusal.line);
25
+ }
22
26
  function repointed(document, definition, from, to, moves, settled) {
23
27
  const changes = [];
24
28
  const names = new Set();
@@ -48,36 +52,6 @@ function repointed(document, definition, from, to, moves, settled) {
48
52
  const next = applied.document;
49
53
  return [...names].map((name) => ({ kind: 'field', path: from, name, value: next.fields[name] }));
50
54
  }
51
- function edited(document, changes, definition) {
52
- const parts = new Map();
53
- for (const change of changes) {
54
- if (change.kind === 'preamble')
55
- parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
56
- if (change.kind === 'section')
57
- parts.set(`section ${change.name}`, {
58
- kind: 'section',
59
- name: change.name,
60
- value: change.value,
61
- prior: document.sections[change.name] ?? '',
62
- });
63
- }
64
- if (parts.size === 0)
65
- return document;
66
- const applied = apply(document, [...parts.values()], definition);
67
- return applied.outcome === 'applied' ? applied.document : document;
68
- }
69
- function bodies(path, before, after) {
70
- const changes = [];
71
- if (after.preamble !== before.preamble) {
72
- changes.push({ kind: 'preamble', path, value: after.preamble });
73
- }
74
- for (const [name, value] of Object.entries(after.sections)) {
75
- if (before.sections[name] === value)
76
- continue;
77
- changes.push({ kind: 'section', path, name, value });
78
- }
79
- return changes;
80
- }
81
55
  function relinks(path, moved, before, moves, definition) {
82
56
  const changes = [];
83
57
  for (const link of links(before, path)) {
@@ -92,27 +66,20 @@ function relinks(path, moved, before, moves, definition) {
92
66
  if (changes.length === 0)
93
67
  return { kind: 'changes', changes: [] };
94
68
  const applied = apply(before, changes, definition);
95
- if (applied.outcome === 'refuse') {
96
- return {
97
- kind: 'refused',
98
- refusal: {
99
- code: applied.refusal.rule,
100
- retryable: false,
101
- file: path,
102
- ...(applied.refusal.location === undefined ? {} : { location: applied.refusal.location }),
103
- },
104
- };
105
- }
69
+ if (applied.outcome === 'refuse')
70
+ return refusedBy(applied.refusal, path);
106
71
  const after = applied.document;
107
72
  if (after === before)
108
73
  return { kind: 'changes', changes: [] };
109
74
  if (before.type === undefined) {
110
75
  return { kind: 'changes', changes: [{ kind: 'replace', path, content: serialize(after) }] };
111
76
  }
112
- return { kind: 'changes', changes: bodies(path, before, after) };
77
+ return { kind: 'changes', changes: partsBetween(path, before, after) };
113
78
  }
114
79
  function partKey(change) {
115
- return change.kind === 'section' ? `section ${change.name}` : change.kind;
80
+ return change.kind === 'section' || change.kind === 'field'
81
+ ? `${change.kind} ${change.name}`
82
+ : change.kind;
116
83
  }
117
84
  const NAMES_A_SKIP_TESTS = 64;
118
85
  const ENCODED = /[%&\\]/u;
@@ -159,9 +126,10 @@ function* rewrites(changes, visible) {
159
126
  const repointing = repointed(document, definition, path, moved, moves, settled);
160
127
  added.push(...repointing);
161
128
  const own = parts.get(path) ?? [];
129
+ const edited = applyParts(document, own.map((index) => merged[index]), definition);
162
130
  const relinked = moved === path && own.length === 0 && cannotLink(document.content, names)
163
131
  ? { kind: 'changes', changes: [] }
164
- : relinks(path, moved, edited(document, own.map((index) => merged[index]), definition), moves, definition);
132
+ : relinks(path, moved, edited.outcome === 'applied' ? edited.document : document, moves, definition);
165
133
  if (relinked.kind === 'refused')
166
134
  return relinked;
167
135
  const keyed = new Map();
@@ -174,7 +142,7 @@ function* rewrites(changes, visible) {
174
142
  if (change.kind === 'replace') {
175
143
  for (const index of own) {
176
144
  const kind = merged[index]?.kind;
177
- if (kind === 'section' || kind === 'preamble')
145
+ if (kind === 'field' || kind === 'section' || kind === 'preamble')
178
146
  merged[index] = null;
179
147
  }
180
148
  added.push(change);
@@ -239,11 +207,7 @@ function rewritten(path, document, changes, definition) {
239
207
  const after = applied.document;
240
208
  if (document.type === undefined)
241
209
  return [{ kind: 'replace', path, content: serialize(after) }];
242
- const names = new Set(changes.flatMap((change) => change.kind === 'reference' ? [pointerSegments(change.pointer)[0] ?? ''] : []));
243
- return [
244
- ...[...names].map((name) => ({ kind: 'field', path, name, value: after.fields[name] })),
245
- ...bodies(path, document, after),
246
- ];
210
+ return partsBetween(path, document, after);
247
211
  }
248
212
  function roomPathOf(handle, path) {
249
213
  return `/rooms/${handle}/${path}`;
@@ -453,7 +417,7 @@ function* preconditionsOf(changes, visible, bases) {
453
417
  };
454
418
  for (const change of changes) {
455
419
  yield ROW_WEIGHT;
456
- if (change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble') {
420
+ if (isPart(change)) {
457
421
  const based = bases.find((base) => sameTarget(base, change));
458
422
  if (based !== undefined) {
459
423
  add(based);
@@ -560,71 +524,81 @@ function relativeField(path, name, value, handle, definition) {
560
524
  return result.outcome === 'applied' ? result.document.fields[name] : value;
561
525
  }
562
526
  function relativeChanges(input) {
527
+ const changes = [];
528
+ for (const change of input.changes) {
529
+ const next = relativeChange(change, input);
530
+ if ('refusal' in next)
531
+ return next;
532
+ changes.push(next.change);
533
+ }
534
+ return { kind: 'changes', changes };
535
+ }
536
+ function relativeChange(change, input) {
563
537
  const { handle, composition, visible } = input;
564
- const typed = (path) => definitionsAt(composition, path);
565
538
  const body = (path, text) => shellRelative(text, path, handle, () => undefined)?.content ?? text;
566
- return input.changes.map((change) => {
567
- const definition = typed(change.path);
568
- if (change.kind === 'field') {
569
- const type = visible.collection.document(change.path)?.type;
570
- const value = relativeField(change.path, change.name, change.value, handle, definition(type));
571
- return value === change.value ? change : { ...change, value };
572
- }
573
- if (change.kind === 'section' || change.kind === 'preamble') {
574
- const value = body(change.path, change.value);
575
- return value === change.value ? change : { ...change, value };
576
- }
577
- if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
578
- const content = shellRelative(change.content, change.path, handle, definition)?.content ?? change.content;
579
- return content === change.content ? change : { ...change, content };
580
- }
581
- if (change.kind !== 'create')
582
- return change;
583
- const type = typeof change.fields.type === 'string' ? change.fields.type : undefined;
584
- const fields = Object.fromEntries(Object.entries(change.fields).map(([name, value]) => [
585
- name,
586
- relativeField(change.path, name, value, handle, definition(type)),
587
- ]));
588
- const sections = Object.fromEntries(Object.entries(change.sections).map(([name, value]) => [name, body(change.path, value)]));
589
- return { ...change, fields, sections };
590
- });
539
+ const definition = definitionsAt(composition, change.path);
540
+ if (change.kind === 'field') {
541
+ const type = visible.collection.document(change.path)?.type;
542
+ const value = relativeField(change.path, change.name, change.value, handle, definition(type));
543
+ return { change: value === change.value ? change : { ...change, value } };
544
+ }
545
+ if (change.kind === 'section' || change.kind === 'preamble') {
546
+ const value = body(change.path, change.value);
547
+ return { change: value === change.value ? change : { ...change, value } };
548
+ }
549
+ if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
550
+ const content = shellRelative(change.content, change.path, handle, definition)?.content ?? change.content;
551
+ return { change: content === change.content ? change : { ...change, content } };
552
+ }
553
+ if (change.kind !== 'create')
554
+ return { change };
555
+ const type = typeof change.fields.type === 'string' ? change.fields.type : undefined;
556
+ const fields = Object.fromEntries(Object.entries(change.fields).map(([name, value]) => [
557
+ name,
558
+ relativeField(change.path, name, value, handle, definition(type)),
559
+ ]));
560
+ const sections = Object.fromEntries(Object.entries(change.sections).map(([name, value]) => [name, body(change.path, value)]));
561
+ const written = composed(change.path, fields, sections, composition);
562
+ if (written.outcome === 'refuse')
563
+ return refusedBy(written.refusal, change.path);
564
+ if (written.outcome === 'stale')
565
+ throw new Error(`the creation of ${change.path} is stale`);
566
+ if (Object.keys(sections).length === 0)
567
+ return { change: { ...change, fields, sections } };
568
+ return {
569
+ change: { kind: 'create', path: change.path, content: serialize(written.document) },
570
+ };
591
571
  }
592
572
  function unqueueable(file) {
593
573
  return refuse('unknown-revision', file);
594
574
  }
595
- function isPart(change) {
596
- return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
597
- }
598
575
  function touched(change) {
599
576
  return change.kind === 'move' ? [change.path, change.to] : [change.path];
600
577
  }
601
578
  function partsApplied(content, path, changes, composition) {
602
- const definitions = definitionsAt(composition, path);
603
- const parsed = parse(content, path, definitions);
604
- if (!parsed.ok)
605
- return null;
606
- const document = parsed.document;
607
- const parts = new Map();
579
+ const applied = partsResult(content, path, changes, composition);
580
+ return applied?.outcome === 'applied' ? serialize(applied.document) : null;
581
+ }
582
+ function unapplied(changes, visible, composition) {
583
+ const parted = new Map();
608
584
  for (const change of changes) {
609
- if (change.kind === 'field')
610
- parts.set(`field ${change.name}`, {
611
- kind: 'field',
612
- name: change.name,
613
- value: change.value,
614
- prior: document.fields[change.name],
615
- });
616
- else if (change.kind === 'section')
617
- parts.set(`section ${change.name}`, {
618
- kind: 'section',
619
- name: change.name,
620
- value: change.value,
621
- prior: document.sections[change.name] ?? '',
622
- });
623
- else
624
- parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
585
+ if (isPart(change))
586
+ parted.set(change.path, [...(parted.get(change.path) ?? []), change]);
625
587
  }
626
- const applied = apply(document, [...parts.values()], definitions(document.type));
627
- return applied.outcome === 'applied' ? serialize(applied.document) : null;
588
+ for (const [path, parts] of parted) {
589
+ const content = visible.documents[path];
590
+ if (content === undefined)
591
+ continue;
592
+ const applied = partsResult(content, path, parts, composition);
593
+ if (applied?.outcome === 'refuse')
594
+ return refusedBy(applied.refusal, path);
595
+ }
596
+ return null;
597
+ }
598
+ function partsResult(content, path, changes, composition) {
599
+ const definitions = definitionsAt(composition, path);
600
+ const parsed = parse(content, path, definitions);
601
+ return parsed.ok ? applyParts(parsed.document, changes, definitions(parsed.document.type)) : null;
628
602
  }
629
603
  function settledParts(changes, deferred, composition) {
630
604
  for (const [held, parts] of deferred) {
@@ -843,11 +817,8 @@ function* limiting(queue, batch, limits, state) {
843
817
  const limited = yield* exceeding(limits, batch.changes, rewritten.changes, yield* state(queue.slice(0, at + 1)));
844
818
  return limited?.refusal ?? null;
845
819
  }
846
- function typedText(content) {
847
- if (content === undefined)
848
- return false;
849
- const parsed = parse(content);
850
- return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
820
+ function typedContent(content) {
821
+ return content !== undefined && typedText(parse(content));
851
822
  }
852
823
  function touchedLibrary(resulting, touched, composition) {
853
824
  const entries = touched
@@ -867,9 +838,9 @@ function touchedLibrary(resulting, touched, composition) {
867
838
  if (binaries.has(path))
868
839
  known.set(path, { type: undefined, binary: true });
869
840
  else if (content !== undefined && content !== null) {
870
- const read = parse(content, path, definitionsAt(composition, path));
871
- if (read.ok)
872
- known.set(path, { type: read.document.type ?? 'any', binary: false });
841
+ const type = textType(parse(content, path, definitionsAt(composition, path)));
842
+ if (type !== undefined)
843
+ known.set(path, { type, binary: false });
873
844
  await pace(content.length + ROW_WEIGHT);
874
845
  }
875
846
  }
@@ -887,7 +858,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
887
858
  for (const path of touched) {
888
859
  const before = visible.documents[path];
889
860
  const after = resulting.documents[path];
890
- if (typedText(before) || typedText(after))
861
+ if (typedContent(before) || typedContent(after))
891
862
  typedPaths.push(path);
892
863
  await pace((before?.length ?? 0) + (after?.length ?? 0) + ROW_WEIGHT);
893
864
  }
@@ -905,6 +876,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
905
876
  retryable: false,
906
877
  file: verdict.file,
907
878
  ...(verdict.location === undefined ? {} : { location: verdict.location }),
879
+ ...(verdict.line === undefined ? {} : { line: verdict.line }),
908
880
  ...(verdict.referrers === undefined ? {} : { referrers: verdict.referrers }),
909
881
  },
910
882
  };
@@ -920,8 +892,6 @@ function placed(reference) {
920
892
  const key = roomPathOf(reference.handle, reference.path);
921
893
  if (reference.kind === 'link')
922
894
  return `link ${key}`;
923
- if (reference.kind === 'item')
924
- return `section ${reference.section} ${key}`;
925
895
  const pointer = reference.pointer
926
896
  .split('/')
927
897
  .map((segment) => (ARRAY_INDEX.test(segment) ? '-' : segment))
@@ -953,7 +923,7 @@ function* admittedRooms(changes, visible, resulting, composition) {
953
923
  continue;
954
924
  if (held.has(placed(reference)))
955
925
  continue;
956
- return refuse('unresolved-reference', path, reference.kind === 'field' ? reference.pointer : reference.section);
926
+ return refuse('unresolved-reference', path, reference.pointer);
957
927
  }
958
928
  yield ROW_WEIGHT + now.length;
959
929
  }
@@ -971,7 +941,10 @@ function validationOf(validated) {
971
941
  };
972
942
  }
973
943
  async function batching(input) {
974
- const changes = relativeChanges(input);
944
+ const relative = relativeChanges(input);
945
+ if (relative.kind === 'refused')
946
+ return relative;
947
+ const { changes } = relative;
975
948
  const structural = changes.find((change) => change.kind === 'move' || change.kind === 'remove');
976
949
  if (structural !== undefined && input.unmodeled) {
977
950
  return refuse('model-unavailable', structural.path);
@@ -981,7 +954,7 @@ async function batching(input) {
981
954
  const rewritten = await stepped(rewrites(changes, input.visible));
982
955
  if (rewritten.kind === 'refused')
983
956
  return rewritten;
984
- const refusal = guard(changes, input, WRITE);
957
+ const refusal = guard(changes, input, WRITE) ?? unapplied(changes, input.visible, input.composition);
985
958
  if (refusal !== null)
986
959
  return refusal;
987
960
  const preconditions = await stepped(preconditionsOf(changes, input.visible, input.bases));
@@ -1120,6 +1093,14 @@ async function moving(input) {
1120
1093
  return limited;
1121
1094
  return { kind: 'moved', leaving: immutable(leavingBatch), arriving: immutable(arrivingBatch) };
1122
1095
  }
1096
+ function unreadable(saved, visible, composition) {
1097
+ const path = saved.find(({ path: at, parts }) => (parts.fields !== undefined ||
1098
+ parts.sections !== undefined ||
1099
+ parts.preamble !== undefined) &&
1100
+ typedContent(visible.documents[at]) &&
1101
+ governing(composition, at).status === 'unavailable')?.path;
1102
+ return path === undefined ? null : refuse('model-unavailable', path);
1103
+ }
1123
1104
  function changedUnderneath(saved, visible) {
1124
1105
  const parts = saved.flatMap(({ path, parts: held }) => changedParts(path, held, visible));
1125
1106
  return parts.length === 0
@@ -1201,7 +1182,7 @@ async function plannedMove(ask, source, into) {
1201
1182
  async function plannedWithin(ask, room) {
1202
1183
  const { record } = room;
1203
1184
  const visible = await stepped(room.replay(room.queue));
1204
- const changed = changedUnderneath(ask.saved, visible);
1185
+ const changed = unreadable(ask.saved, visible, room.composition) ?? changedUnderneath(ask.saved, visible);
1205
1186
  if (changed !== null)
1206
1187
  return changed;
1207
1188
  const parts = ask.saved.map(({ path, parts: held }) => changesOf(path, held));
package/dist/saves.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type ChangeBatch, type WrittenBy } from './change.js';
2
+ import type { ConversationFiles } from './conversation.js';
2
3
  import { type AttachAnswer, type BinaryLinkAnswer, type HeldBinaryAnswer, type HeldShownAnswer } from './outcome.js';
3
4
  import { type RoomDraftParts } from './room-draft.js';
4
5
  import type { Runtime } from './runtime.js';
@@ -28,5 +29,6 @@ export type BinaryFileSurface = {
28
29
  export declare function saveRoomDrafts(runtime: Runtime, locator: string, named: readonly SavedRoomDraft[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
29
30
  export declare function saveParts(runtime: Runtime, locator: string, named: readonly SavedParts[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
30
31
  export declare function batchFile(store: Store, batch: ChangeBatch): (localId: string) => Promise<Blob>;
32
+ export declare function conversationFiles(runtime: Runtime): ConversationFiles;
31
33
  export declare function binaryFileSurface(runtime: Runtime): BinaryFileSurface;
32
34
  //# sourceMappingURL=saves.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"saves.d.ts","sourceRoot":"","sources":["../src/saves.ts"],"names":[],"mappings":"AAGA,OAAO,EAA2B,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAOxF,OAAO,EAQL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AAatB,OAAO,EAOL,KAAK,cAAc,EAEpB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAsB,KAAK,EAAoB,MAAM,YAAY,CAAC;AAK9E,MAAM,MAAM,UAAU,GAClB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACxC,CAAC;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,GAAG,WAAW,CAAC,CAAC;AAE3C,MAAM,MAAM,cAAc,GAAG;IAAE,QA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js CHANGED
@@ -1,18 +1,20 @@
1
- import { parseFrontmatter } from '@agentshouse/mdmodel';
1
+ import { isImageType, parse } from '@agentshouse/mdmodel';
2
2
  import { binaryRecord } from './binary.js';
3
+ import { changeSet } from './change-set.js';
3
4
  import { queuedFile } from './change.js';
4
- import { available } from './collection.js';
5
+ import { available, textType } from './collection.js';
5
6
  import { runtimeError } from './failure.js';
6
7
  import { attachedFile } from './file.js';
8
+ import { roomDraftRevision } from './identity.js';
7
9
  import { compositionFor } from './listing.js';
8
10
  import { scoped } from './models.js';
9
- import { absentBinary, attachAnswer, binaryAnswer, binaryLinkAnswer, failure, OFFLINE, UNCERTAIN, } from './outcome.js';
11
+ import { absentBinary, attachAnswer, binaryAnswer, binaryLinkAnswer, failure, linkedAnswer, OFFLINE, UNCERTAIN, } from './outcome.js';
10
12
  import { sameBinary } from './overlay.js';
11
13
  import { ancestors } from './paths.js';
12
14
  import { connectionNow } from './preparation.js';
13
15
  import { append, sliceAt, withdrawable } from './queue.js';
14
16
  import { entryAt, replaying, slicing, } from './replica.js';
15
- import { binaryBase, changesOf, held, heldFile, moveTarget, readSavedParts, } from './room-draft.js';
17
+ import { binaryBase, changesOf, held, heldFile, joinedOver, moveTarget, readSavedParts, } from './room-draft.js';
16
18
  import { refuse } from './refusal.js';
17
19
  import { visibleOf } from './room-drafts.js';
18
20
  import { destination, planSave, } from './save.js';
@@ -43,9 +45,24 @@ export function saveRoomDrafts(runtime, locator, named, writtenBy) {
43
45
  if (!saved.some((draft) => draft.path === path))
44
46
  saved.push({ path, parts: record.parts });
45
47
  }
46
- return loaded(runtime, locator, replica, saved, new Set(saved.map(({ path }) => path)), [], writtenBy);
48
+ const result = await loaded(runtime, locator, replica, saved, new Set(saved.map(({ path }) => path)), [], writtenBy);
49
+ if (result.outcome !== 'refused' || result.code !== 'changed-underneath')
50
+ return result;
51
+ return joinedUnderneath(runtime, locator, saved.map(({ path }) => drafts.get(path)), result);
47
52
  });
48
53
  }
54
+ async function joinedUnderneath({ store }, locator, records, refused) {
55
+ const visible = (await visibleOf(store, locator, records.map(({ path }) => path)));
56
+ const joined = records.flatMap((record) => {
57
+ const join = joinedOver(record.parts, record.marks, record.path, visible);
58
+ return join === null ? [] : [{ ...record, ...join, revision: roomDraftRevision() }];
59
+ });
60
+ if (joined.length === 0)
61
+ return refused;
62
+ await (await store.open()).commit({ rooms: [], writes: [{ locator, roomDrafts: joined }] });
63
+ await store.changed(changeSet(locator, { drafts: joined.map(({ path }) => path) }));
64
+ return refused;
65
+ }
49
66
  export function saveParts(runtime, locator, named, writtenBy) {
50
67
  const { store } = runtime;
51
68
  return store.exclusive(async () => {
@@ -162,8 +179,7 @@ function lookupOf(local, key, view) {
162
179
  function declaredOf(entry) {
163
180
  if (entry.binary !== null)
164
181
  return { type: undefined, binary: true };
165
- const read = parseFrontmatter(entry.content ?? '');
166
- return { type: read.ok ? (read.frontmatter.type ?? 'any') : undefined, binary: false };
182
+ return { type: textType(parse(entry.content ?? '')), binary: false };
167
183
  }
168
184
  function overriddenLookup(lookup, overrides) {
169
185
  return async (paths) => {
@@ -230,7 +246,7 @@ export function batchFile(store, batch) {
230
246
  };
231
247
  }
232
248
  async function transferBinary(runtime, request, transfer, answer) {
233
- const { store, socket, presence, journal } = runtime;
249
+ const { store, socket, presence } = runtime;
234
250
  const { session } = socket;
235
251
  if (socket.closed() || session.now().refusal !== null)
236
252
  return UNCERTAIN;
@@ -247,12 +263,10 @@ async function transferBinary(runtime, request, transfer, answer) {
247
263
  if (closed || authorization === undefined || refusal !== null)
248
264
  return UNCERTAIN;
249
265
  const since = presence.losses();
250
- journal.record(`transfer binary ${request.locator} ${request.path}`);
251
266
  try {
252
267
  const result = await transfer(authorization);
253
268
  const settled = result;
254
- journal.record(`outcome binary ${settled.kind}`);
255
- if (presence.lostSince(request.locator, since))
269
+ if (request.locator !== null && presence.lostSince(request.locator, since))
256
270
  return failure({ kind: 'room-not-readable', locator: request.locator });
257
271
  if (settled.kind === 'scoped-refusal') {
258
272
  const room = await store.record(settled.locator);
@@ -264,7 +278,6 @@ async function transferBinary(runtime, request, transfer, answer) {
264
278
  return answer(result);
265
279
  }
266
280
  catch {
267
- journal.record('outcome binary transport-uncertainty');
268
281
  return UNCERTAIN;
269
282
  }
270
283
  }
@@ -377,11 +390,11 @@ async function showBinaryPath(runtime, locator, path, revision) {
377
390
  if (kept !== null)
378
391
  return kept;
379
392
  const mediaType = await heldMediaType(store, locator, path);
380
- if (mediaType?.startsWith('image/') === true)
393
+ if (mediaType !== undefined && isImageType(mediaType))
381
394
  return fetchBinary(runtime, asked, name);
382
395
  return linkOf(runtime, asked, revision === undefined ? mediaType : undefined);
383
396
  }
384
- async function attachBinary(runtime, locator, file) {
397
+ async function attachFile(runtime, locator, file, answer) {
385
398
  const { store, socket } = runtime;
386
399
  await socket.ready;
387
400
  await socket.firstDiscovery;
@@ -391,16 +404,27 @@ async function attachBinary(runtime, locator, file) {
391
404
  socket.session.now().refusal !== null)
392
405
  return OFFLINE;
393
406
  const request = await attachedFile(locator, file);
394
- return transferBinary(runtime, { locator, path: file.name }, async (held) => {
407
+ return transferBinary(runtime, { locator }, async (held) => {
395
408
  const result = await socket.attach(held, request);
396
- if (result.kind === 'attached') {
409
+ if (result.kind === 'attached' && locator !== null) {
397
410
  store.attached.hold(locator, result.path, {
398
411
  revision: result.revision,
399
412
  mediaType: request.mediaType,
400
413
  });
401
414
  }
402
415
  return result;
403
- }, attachAnswer);
416
+ }, answer);
417
+ }
418
+ async function keyedAttachment(runtime, link) {
419
+ await runtime.socket.ready;
420
+ const asked = { kind: 'key', link };
421
+ return transferBinary(runtime, { locator: null }, (authorization) => runtime.socket.link(authorization, asked), (result) => binaryLinkAnswer(result));
422
+ }
423
+ export function conversationFiles(runtime) {
424
+ return {
425
+ attach: (file) => attachFile(runtime, null, file, linkedAnswer),
426
+ attachment: (link) => keyedAttachment(runtime, link),
427
+ };
404
428
  }
405
429
  export function binaryFileSurface(runtime) {
406
430
  return {
@@ -408,6 +432,6 @@ export function binaryFileSurface(runtime) {
408
432
  read: (room, path, revision) => readBinaryPath(runtime, room, path, revision),
409
433
  link: (room, path, revision) => linkBinaryPath(runtime, room, path, revision),
410
434
  show: (room, path, revision) => showBinaryPath(runtime, room, path, revision),
411
- attach: (room, file) => attachBinary(runtime, room, file),
435
+ attach: (room, file) => attachFile(runtime, room, file, attachAnswer),
412
436
  };
413
437
  }
@@ -1 +1 @@
1
- {"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAS,KAAK,WAAW,EAAqB,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,IAAI,EAA4C,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,SAAS;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;KAAE,EAAE,CAAC;CACpF,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAEjG,KAAK,WAAW,GAAG,CACjB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS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,CAAC,IAAI,EAAE,SAAS,CAAA;KAAE,EAAE,CAAC;CACpF,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAEjG,KAAK,WAAW,GAAG,CACjB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,KAAK,KAAK,EACjD,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAChC,MAAM,IAAI,CAAC;AA0ChB,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAe5D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAmBtD;AA+BD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAOxF;AAYD,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAMlE;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,WAAW,GACjB,MAAM,IAAI,CA4BZ"}
package/dist/seed.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { queryKey } from '@agentshouse/mdmodel';
2
- import { whole } from './observation.js';
2
+ import { pendingChange, whole } from './observation.js';
3
3
  import { documentKey } from './rows.js';
4
4
  const seedTopic = (key) => `seed\u0000${key}`;
5
5
  function plain(value) {
@@ -130,7 +130,7 @@ export function watchSeeded(runtime, plan, deliver, watch) {
130
130
  const watcher = store.watch(seedTopic(plan.key), shown);
131
131
  const stop = watch((cover, held) => seedBehind(runtime, plan, cover, held), (message) => {
132
132
  const answered = message;
133
- pending = whole(answered) && 'pending' in answered.result;
133
+ pending = whole(answered) ? 'pending' in answered.result : pendingChange(answered);
134
134
  if (pending && store.seeds.of(plan.key) !== undefined) {
135
135
  shown();
136
136
  return;
package/dist/shown.d.ts CHANGED
@@ -10,15 +10,18 @@ export declare const REFUSAL_TOPIC = "connection-refusal";
10
10
  export declare const STORAGE_LOSS_TOPIC = "storage-loss";
11
11
  export declare const SERVICE_MODE_TOPIC = "service-mode";
12
12
  export declare const MEMBER_TOPIC = "member";
13
+ export declare const TIME_ZONE_TOPIC = "time-zone";
13
14
  export declare const AUTHORITY_TOPIC = "authority-changes";
14
15
  export declare const LOCKS_TOPIC = "locks";
15
16
  export declare const queueTopic: (locator: string) => string;
16
- export declare function recoverReads({ liveQueries, figures }: Runtime): void;
17
+ export declare function recoverReads({ liveQueries, figures }: Runtime, locators?: readonly string[]): void;
17
18
  export declare function emitRooms(runtime: Runtime, changed?: readonly string[]): Promise<void>;
18
19
  export declare function emitKnownRooms(runtime: Runtime): void;
19
20
  export declare function emitRefusal(runtime: Runtime): void;
20
- export declare function emitStorageLoss({ store }: Runtime): void;
21
+ export declare function storageLossNow({ store }: Runtime): string | null;
22
+ export declare function emitStorageLoss(runtime: Runtime): void;
21
23
  export declare function emitMember({ store }: Runtime, member: Member | null): void;
24
+ export declare function emitTimeZone({ store }: Runtime, zone: string | null): void;
22
25
  export declare function show(runtime: Runtime): Promise<void>;
23
26
  export declare function moveTo(runtime: Runtime, next: Moving): Promise<void>;
24
27
  export declare function statusShown(runtime: Runtime): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"shown.d.ts","sourceRoot":"","sources":["../src/shown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cA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