@agentshouse/mdruntime 0.1.0-cebcd51f70ed1 → 0.1.0-cede5a74284be
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.
- package/AGENTS.md +109 -35
- package/README.md +13 -3
- package/dist/adapter.d.ts +47 -14
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +15 -2
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +57 -0
- package/dist/binary.d.ts +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +17 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +88 -38
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +19 -12
- package/dist/change.d.ts +15 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- package/dist/chat/acts.d.ts +34 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +60 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +20 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +59 -0
- package/dist/chat/markdown.d.ts +19 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +187 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +21 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +151 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +645 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +33 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +14 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +65 -15
- package/dist/collection.d.ts +6 -11
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +56 -19
- package/dist/connection.d.ts +21 -9
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +470 -142
- package/dist/conversation.d.ts +11 -3
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +47 -7
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/host.d.ts +1 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +9 -8
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/memory.d.ts +4 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +60 -20
- package/dist/model.d.ts +10 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +2 -0
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +28 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +41 -1
- package/dist/overlay.d.ts +14 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +75 -37
- package/dist/query.d.ts +4 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +5 -31
- package/dist/reach.d.ts +2 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +43 -19
- package/dist/react.d.ts +25 -16
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +8 -6
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +9 -2
- package/dist/refresh.d.ts +10 -0
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +42 -38
- package/dist/replica.d.ts +8 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +76 -56
- package/dist/room-draft.d.ts +26 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +132 -23
- package/dist/rows.d.ts +5 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +10 -2
- package/dist/save.d.ts +27 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +340 -33
- package/dist/search.d.ts +3 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/status.d.ts +2 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +33 -9
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +273 -164
- package/dist/wire.d.ts +7 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +15 -2
- package/package.json +22 -14
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/replica.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { parse } from '@agentshouse/mdmodel';
|
|
2
|
-
import { immutable } from './change.js';
|
|
3
|
-
import {
|
|
4
|
-
import { overlay, overlayChanged, sameLayerText } from './overlay.js';
|
|
1
|
+
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { immutable, landing } from './change.js';
|
|
3
|
+
import { collectionOf, unreadable, validateCollection, } from './collection.js';
|
|
4
|
+
import { acceptedBinaries, overlay, overlayChanged, sameLayerText, } from './overlay.js';
|
|
5
5
|
import { providerRewritten } from './save.js';
|
|
6
|
-
import { equalValue } from './room-draft.js';
|
|
7
|
-
import { declaredAttachments } from './attachment.js';
|
|
8
6
|
export function compositionOf(record) {
|
|
9
7
|
return {
|
|
10
8
|
model: record.model,
|
|
@@ -13,40 +11,66 @@ export function compositionOf(record) {
|
|
|
13
11
|
: { roots: record.typedSelection.roots, model: record.selectionModel },
|
|
14
12
|
};
|
|
15
13
|
}
|
|
16
|
-
export function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
:
|
|
20
|
-
|
|
21
|
-
? { kind: 'staged', confirmed: { record, collection: read.collection } }
|
|
22
|
-
: read;
|
|
14
|
+
export function confirmedOf(record, previous) {
|
|
15
|
+
return {
|
|
16
|
+
record,
|
|
17
|
+
collection: collectionOf(record.documents, compositionOf(record), previous?.collection),
|
|
18
|
+
};
|
|
23
19
|
}
|
|
24
20
|
export function sameMembership(record, other) {
|
|
25
21
|
return (JSON.stringify(record.typedSelection?.roots ?? null) ===
|
|
26
22
|
JSON.stringify(other.typedSelection?.roots ?? null));
|
|
27
23
|
}
|
|
28
24
|
export function readStaged(record, previous) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
record.
|
|
34
|
-
|
|
25
|
+
const textChanged = previous === undefined || !sameLayerText(record, previous.record);
|
|
26
|
+
const modeled = record.model.status !== 'unavailable' || record.selectionModel.status !== 'unavailable';
|
|
27
|
+
if (modeled &&
|
|
28
|
+
(textChanged ||
|
|
29
|
+
record.model !== previous?.record.model ||
|
|
30
|
+
record.selectionModel !== previous?.record.selectionModel)) {
|
|
31
|
+
const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
35
32
|
if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
|
|
36
33
|
return { kind: 'refused', refusal: verdict };
|
|
37
34
|
}
|
|
35
|
+
if (verdict.verdict === 'refuse') {
|
|
36
|
+
const refused = unreadable(record.documents, previous?.record.documents);
|
|
37
|
+
if (refused !== null)
|
|
38
|
+
return refused;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (textChanged) {
|
|
42
|
+
const refused = unreadable(record.documents, previous?.record.documents);
|
|
43
|
+
if (refused !== null)
|
|
44
|
+
return refused;
|
|
38
45
|
}
|
|
39
|
-
return
|
|
46
|
+
return { kind: 'staged', confirmed: confirmedOf(record, previous) };
|
|
40
47
|
}
|
|
41
48
|
export function readReclassified(record, previous) {
|
|
42
|
-
const verdict = validateCollection(record.documents, record.
|
|
49
|
+
const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
43
50
|
if (verdict.verdict !== 'refuse')
|
|
44
|
-
return
|
|
51
|
+
return { kind: 'staged', confirmed: confirmedOf(record, previous) };
|
|
45
52
|
return verdict.rule === 'model-unavailable'
|
|
46
53
|
? { kind: 'deferred' }
|
|
47
54
|
: { kind: 'refused', refusal: verdict };
|
|
48
55
|
}
|
|
49
|
-
|
|
56
|
+
function returnedBinaries(held, submitted, accepted) {
|
|
57
|
+
const binaries = { ...held };
|
|
58
|
+
for (const change of submitted.changes) {
|
|
59
|
+
if (change.kind !== 'move')
|
|
60
|
+
continue;
|
|
61
|
+
const moved = binaries[change.path];
|
|
62
|
+
if (moved === undefined || accepted.revisions[change.to] === undefined)
|
|
63
|
+
continue;
|
|
64
|
+
binaries[change.to] = moved;
|
|
65
|
+
delete binaries[change.path];
|
|
66
|
+
}
|
|
67
|
+
Object.assign(binaries, acceptedBinaries(accepted.binaryFiles ?? {}));
|
|
68
|
+
for (const path of accepted.removals)
|
|
69
|
+
delete binaries[path];
|
|
70
|
+
return binaries;
|
|
71
|
+
}
|
|
72
|
+
export function applyReturned(confirmed, submitted, accepted, roomVersion, writtenAt) {
|
|
73
|
+
const { documents, revisions, changes, removals } = accepted;
|
|
50
74
|
const nextDocuments = { ...confirmed.record.documents, ...documents };
|
|
51
75
|
const nextRevisions = { ...confirmed.record.revisions, ...revisions };
|
|
52
76
|
const nextChanges = { ...confirmed.record.changes };
|
|
@@ -54,17 +78,16 @@ export function applyReturned(confirmed, documents, revisions, removals, attachm
|
|
|
54
78
|
...confirmed.record.written,
|
|
55
79
|
...Object.fromEntries(Object.keys(documents).map((path) => [path, writtenAt])),
|
|
56
80
|
};
|
|
57
|
-
const binaryTargets = new Set(confirmed.record.binaryTargets);
|
|
58
81
|
for (const [path, revision] of Object.entries(revisions)) {
|
|
59
82
|
if (confirmed.record.revisions[path] !== revision)
|
|
60
83
|
delete nextChanges[path];
|
|
61
84
|
}
|
|
85
|
+
Object.assign(nextChanges, changes);
|
|
62
86
|
for (const path of removals) {
|
|
63
87
|
delete nextDocuments[path];
|
|
64
88
|
delete nextRevisions[path];
|
|
65
89
|
delete nextChanges[path];
|
|
66
90
|
delete nextWritten[path];
|
|
67
|
-
binaryTargets.delete(path);
|
|
68
91
|
}
|
|
69
92
|
return readStaged({
|
|
70
93
|
...confirmed.record,
|
|
@@ -73,10 +96,7 @@ export function applyReturned(confirmed, documents, revisions, removals, attachm
|
|
|
73
96
|
revisions: nextRevisions,
|
|
74
97
|
changes: nextChanges,
|
|
75
98
|
written: nextWritten,
|
|
76
|
-
|
|
77
|
-
attachments: attachments === undefined
|
|
78
|
-
? confirmed.record.attachments
|
|
79
|
-
: declaredAttachments([attachments]),
|
|
99
|
+
binaries: returnedBinaries(confirmed.record.binaries, submitted, accepted),
|
|
80
100
|
}, confirmed);
|
|
81
101
|
}
|
|
82
102
|
function predicted(confirmed, batches, previous) {
|
|
@@ -97,9 +117,7 @@ function predicted(confirmed, batches, previous) {
|
|
|
97
117
|
const collection = hasMove
|
|
98
118
|
? reuseRewrite
|
|
99
119
|
? old.collection
|
|
100
|
-
:
|
|
101
|
-
? { text: confirmed.record.documents, collection: confirmed.collection }
|
|
102
|
-
: { text: old.before.documents, collection: old.collection })
|
|
120
|
+
: collectionOf(before.documents, composition, old?.collection ?? confirmed.collection)
|
|
103
121
|
: undefined;
|
|
104
122
|
const effective = collection === undefined
|
|
105
123
|
? batch
|
|
@@ -128,7 +146,7 @@ export function replicaOf(confirmed, queue, previous) {
|
|
|
128
146
|
queue: batches,
|
|
129
147
|
visible: {
|
|
130
148
|
documents: confirmed.record.documents,
|
|
131
|
-
|
|
149
|
+
binaries: confirmed.record.binaries,
|
|
132
150
|
revisions: confirmed.record.revisions,
|
|
133
151
|
changes: confirmed.record.changes,
|
|
134
152
|
collection: confirmed.collection,
|
|
@@ -143,14 +161,12 @@ export function replicaOf(confirmed, queue, previous) {
|
|
|
143
161
|
replay,
|
|
144
162
|
visible: {
|
|
145
163
|
...layer,
|
|
146
|
-
collection:
|
|
147
|
-
? undefined
|
|
148
|
-
: { text: previous.visible.documents, collection: previous.visible.collection }),
|
|
164
|
+
collection: collectionOf(layer.documents, compositionOf(confirmed.record), previous?.visible.collection ?? confirmed.collection),
|
|
149
165
|
},
|
|
150
166
|
};
|
|
151
167
|
}
|
|
152
168
|
function present(layer, path) {
|
|
153
|
-
return layer.documents[path] !== undefined || layer.
|
|
169
|
+
return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
|
|
154
170
|
}
|
|
155
171
|
function holds(layer, preconditions) {
|
|
156
172
|
const parsed = new Map();
|
|
@@ -171,6 +187,8 @@ function holds(layer, preconditions) {
|
|
|
171
187
|
if (precondition.kind === 'revision') {
|
|
172
188
|
return present(layer, path) && layer.revisions[path] === precondition.revision;
|
|
173
189
|
}
|
|
190
|
+
if (precondition.kind === 'content')
|
|
191
|
+
return layer.documents[path] === precondition.content;
|
|
174
192
|
const document = documentAt(path);
|
|
175
193
|
if (document === null)
|
|
176
194
|
return false;
|
|
@@ -215,36 +233,30 @@ function effects(change) {
|
|
|
215
233
|
{ kind: 'present', path: change.to },
|
|
216
234
|
];
|
|
217
235
|
}
|
|
236
|
+
if (change.kind === 'binary')
|
|
237
|
+
return [{ kind: 'present', path }];
|
|
218
238
|
return [{ kind: 'absent', path }];
|
|
219
239
|
}
|
|
220
|
-
function
|
|
221
|
-
|
|
222
|
-
for (const change of changes.slice(index + 1)) {
|
|
223
|
-
if (change.path !== at)
|
|
224
|
-
continue;
|
|
225
|
-
if (change.kind === 'remove')
|
|
226
|
-
return null;
|
|
227
|
-
if (change.kind === 'move')
|
|
228
|
-
at = change.to;
|
|
229
|
-
}
|
|
230
|
-
return at;
|
|
231
|
-
}
|
|
232
|
-
export function landed(batch, confirmed) {
|
|
233
|
-
const layer = confirmed.record;
|
|
240
|
+
export function landed(batch, confirmed, current = {}) {
|
|
241
|
+
const layer = { ...confirmed.record, documents: { ...confirmed.record.documents, ...current } };
|
|
234
242
|
return batch.changes.every((change, index) => {
|
|
235
243
|
if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
|
|
236
|
-
const at =
|
|
244
|
+
const at = landing(batch.changes, index, change.path);
|
|
237
245
|
return at === null || layer.documents[at] === change.content;
|
|
238
246
|
}
|
|
247
|
+
if (change.kind === 'binary') {
|
|
248
|
+
const at = landing(batch.changes, index, change.path);
|
|
249
|
+
return at === null || layer.binaries[at]?.sha256 === change.sha256;
|
|
250
|
+
}
|
|
239
251
|
return effects(change).every((effect) => {
|
|
240
252
|
if (effect.kind === 'absent')
|
|
241
253
|
return holds(layer, [effect]);
|
|
242
|
-
const at =
|
|
254
|
+
const at = landing(batch.changes, index, effect.path);
|
|
243
255
|
return at === null || holds(layer, [{ ...effect, path: at }]);
|
|
244
256
|
});
|
|
245
257
|
});
|
|
246
258
|
}
|
|
247
|
-
export function withdrawals(confirmed, queue, withdrawable) {
|
|
259
|
+
export function withdrawals(confirmed, queue, withdrawable, local) {
|
|
248
260
|
if (!queue.some(withdrawable))
|
|
249
261
|
return [];
|
|
250
262
|
const composition = compositionOf(confirmed.record);
|
|
@@ -258,10 +270,18 @@ export function withdrawals(confirmed, queue, withdrawable) {
|
|
|
258
270
|
const effective = batch.changes.some((change) => change.kind === 'move')
|
|
259
271
|
? providerRewritten(batch, {
|
|
260
272
|
...layer,
|
|
261
|
-
collection:
|
|
273
|
+
collection: collectionOf(layer.documents, composition),
|
|
262
274
|
})
|
|
263
275
|
: batch;
|
|
264
|
-
|
|
276
|
+
let unapplied = false;
|
|
277
|
+
const next = overlay(layer, [effective], () => {
|
|
278
|
+
unapplied = true;
|
|
279
|
+
});
|
|
280
|
+
if (local && unapplied) {
|
|
281
|
+
withdrawn.push(batch);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
layer = next;
|
|
265
285
|
}
|
|
266
286
|
return withdrawn;
|
|
267
287
|
}
|
package/dist/room-draft.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProviderRefusal } from './adapter.js';
|
|
2
|
+
import type { Open } from './open.js';
|
|
2
3
|
import type { Change, Precondition } from './change.js';
|
|
3
4
|
import type { VisibleLayer } from './replica.js';
|
|
4
5
|
export type FieldValue = {
|
|
@@ -36,6 +37,17 @@ export type RoomDraftParts = {
|
|
|
36
37
|
readonly removal?: {
|
|
37
38
|
readonly base?: string | null;
|
|
38
39
|
};
|
|
40
|
+
readonly file?: {
|
|
41
|
+
readonly blob: Blob;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type HeldFile = {
|
|
45
|
+
readonly blob: Blob;
|
|
46
|
+
readonly localId: string;
|
|
47
|
+
readonly byteLength: number;
|
|
48
|
+
readonly mediaType: string;
|
|
49
|
+
readonly sha256: string;
|
|
50
|
+
readonly base: string | null;
|
|
39
51
|
};
|
|
40
52
|
type HeldParts = {
|
|
41
53
|
readonly fields?: Readonly<Record<string, {
|
|
@@ -62,6 +74,7 @@ type HeldParts = {
|
|
|
62
74
|
readonly removal?: {
|
|
63
75
|
readonly base: string | null;
|
|
64
76
|
};
|
|
77
|
+
readonly file?: HeldFile;
|
|
65
78
|
};
|
|
66
79
|
type ChangedUnderneath = {
|
|
67
80
|
readonly fields?: Readonly<Record<string, FieldValue>>;
|
|
@@ -71,14 +84,12 @@ type ChangedUnderneath = {
|
|
|
71
84
|
readonly creation?: string;
|
|
72
85
|
readonly move?: string | null;
|
|
73
86
|
readonly removal?: string | null;
|
|
87
|
+
readonly file?: string | null;
|
|
74
88
|
};
|
|
75
|
-
export type ReturnReason =
|
|
76
|
-
readonly kind: 'conflicted' | 'rejected';
|
|
77
|
-
}) | {
|
|
78
|
-
readonly kind: 'expired';
|
|
79
|
-
} | {
|
|
80
|
-
readonly kind: 'withdrawn';
|
|
89
|
+
export type ReturnReason = ProviderRefusal & {
|
|
90
|
+
readonly kind: 'conflicted' | 'rejected' | 'expired' | 'withdrawn';
|
|
81
91
|
};
|
|
92
|
+
export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
|
|
82
93
|
export type RoomDraft = {
|
|
83
94
|
readonly room: string;
|
|
84
95
|
readonly path: string;
|
|
@@ -92,11 +103,14 @@ export type RoomDraftWrite = {
|
|
|
92
103
|
readonly roomDraft: RoomDraft | null;
|
|
93
104
|
} | {
|
|
94
105
|
readonly outcome: 'stale';
|
|
106
|
+
readonly code: string;
|
|
107
|
+
readonly retryable: boolean;
|
|
95
108
|
readonly current: RoomDraft | null;
|
|
96
109
|
};
|
|
110
|
+
export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
|
|
97
111
|
export type ChangedPart = {
|
|
98
112
|
readonly path: string;
|
|
99
|
-
readonly part: 'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal'
|
|
113
|
+
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal' | 'file'>;
|
|
100
114
|
readonly name?: string;
|
|
101
115
|
};
|
|
102
116
|
export type RoomDraftRecord = {
|
|
@@ -111,9 +125,10 @@ export type SavedDraft = {
|
|
|
111
125
|
readonly parts: HeldParts;
|
|
112
126
|
};
|
|
113
127
|
export declare function readParts(value: unknown): RoomDraftParts;
|
|
114
|
-
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts): HeldParts;
|
|
115
|
-
export declare function equalValue(left: unknown, right: unknown): boolean;
|
|
128
|
+
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
|
|
116
129
|
export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
|
|
130
|
+
export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
|
|
131
|
+
export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
|
|
117
132
|
export declare function changedParts(path: string, report: ChangedUnderneath): readonly ChangedPart[];
|
|
118
133
|
export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
|
|
119
134
|
export declare function moveTarget(move: {
|
|
@@ -123,5 +138,7 @@ export declare function changesOf(path: string, parts: HeldParts): {
|
|
|
123
138
|
changes: readonly Change[];
|
|
124
139
|
bases: readonly Precondition[];
|
|
125
140
|
};
|
|
141
|
+
export declare function joinedDraft(carried: SavedDraft, saved: readonly SavedDraft[]): SavedDraft;
|
|
142
|
+
export declare function withdrawnDrafts(drafts: readonly SavedDraft[], changes: readonly Change[]): readonly SavedDraft[];
|
|
126
143
|
export {};
|
|
127
144
|
//# sourceMappingURL=room-draft.d.ts.map
|
package/dist/room-draft.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-draft.d.ts","sourceRoot":"","sources":["../src/room-draft.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"room-draft.d.ts","sourceRoot":"","sources":["../src/room-draft.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GACzB;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD,GACD;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CACxB,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CA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AAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAUjF;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEzF;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,SAAS,WAAW,EAAE,CAW5F;AAsCD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,SAAS,CA2B5F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAGhE;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS,GACf;IAAE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAA;CAAE,CA2ChE;AAkBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAkBzF;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,UAAU,EAAE,CAqBvB"}
|
package/dist/room-draft.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { apply, parse, serialize } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, equalValue, frontmatterValue, parse, serialize } from '@agentshouse/mdmodel';
|
|
2
|
+
import { runtimeError } from './failure.js';
|
|
3
|
+
import { hexDigest } from './file.js';
|
|
4
|
+
import { binaryLocalId } from './identity.js';
|
|
2
5
|
import { normalize } from './paths.js';
|
|
6
|
+
export function returnedBy(kind) {
|
|
7
|
+
return { kind, code: kind, fields: {}, retryable: false };
|
|
8
|
+
}
|
|
9
|
+
export function staleWrite(current) {
|
|
10
|
+
return { outcome: 'stale', code: 'stale', retryable: false, current };
|
|
11
|
+
}
|
|
3
12
|
function malformed() {
|
|
4
|
-
throw
|
|
13
|
+
throw runtimeError('room-draft-malformed');
|
|
5
14
|
}
|
|
6
15
|
function plain(value) {
|
|
7
16
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
8
17
|
}
|
|
9
|
-
function frontmatterValue(value) {
|
|
10
|
-
if (Array.isArray(value))
|
|
11
|
-
return value.every(frontmatterValue);
|
|
12
|
-
return (value === null ||
|
|
13
|
-
typeof value === 'string' ||
|
|
14
|
-
typeof value === 'boolean' ||
|
|
15
|
-
(typeof value === 'number' && Number.isFinite(value)));
|
|
16
|
-
}
|
|
17
18
|
function text(value) {
|
|
18
19
|
return typeof value === 'string' ? value : malformed();
|
|
19
20
|
}
|
|
@@ -61,6 +62,7 @@ const PART_NAMES = new Set([
|
|
|
61
62
|
'creation',
|
|
62
63
|
'move',
|
|
63
64
|
'removal',
|
|
65
|
+
'file',
|
|
64
66
|
]);
|
|
65
67
|
export function readParts(value) {
|
|
66
68
|
if (!plain(value) || Object.keys(value).some((name) => !PART_NAMES.has(name)))
|
|
@@ -96,6 +98,13 @@ export function readParts(value) {
|
|
|
96
98
|
const base = markdownBase(value.removal.base);
|
|
97
99
|
parts.removal = base === undefined ? {} : { base };
|
|
98
100
|
}
|
|
101
|
+
if (value.file !== undefined) {
|
|
102
|
+
if (!plain(value.file) || !(value.file.blob instanceof Blob))
|
|
103
|
+
malformed();
|
|
104
|
+
if (Object.keys(value).length > 1)
|
|
105
|
+
throw runtimeError('room-draft-file-exclusive');
|
|
106
|
+
parts.file = { blob: value.file.blob };
|
|
107
|
+
}
|
|
99
108
|
return parts;
|
|
100
109
|
}
|
|
101
110
|
function named(record) {
|
|
@@ -108,7 +117,7 @@ function kept(prior, base) {
|
|
|
108
117
|
if (prior !== undefined)
|
|
109
118
|
return prior.base;
|
|
110
119
|
if (base === undefined)
|
|
111
|
-
throw
|
|
120
|
+
throw runtimeError('room-draft-base-missing');
|
|
112
121
|
return base;
|
|
113
122
|
}
|
|
114
123
|
function editsText(parts) {
|
|
@@ -116,9 +125,32 @@ function editsText(parts) {
|
|
|
116
125
|
named(parts.fields).length > 0 ||
|
|
117
126
|
named(parts.sections).length > 0);
|
|
118
127
|
}
|
|
119
|
-
export function held(current, parts) {
|
|
128
|
+
export function held(current, parts, file) {
|
|
120
129
|
if (parts.markdown !== undefined && editsText(parts)) {
|
|
121
|
-
throw
|
|
130
|
+
throw runtimeError('room-draft-markdown-exclusive');
|
|
131
|
+
}
|
|
132
|
+
if (file !== undefined) {
|
|
133
|
+
if (current !== undefined && current.file === undefined) {
|
|
134
|
+
throw runtimeError('room-draft-file-exclusive');
|
|
135
|
+
}
|
|
136
|
+
return { file: { ...file, base: current?.file === undefined ? file.base : current.file.base } };
|
|
137
|
+
}
|
|
138
|
+
if (current?.file !== undefined) {
|
|
139
|
+
if (editsText(parts) ||
|
|
140
|
+
parts.markdown !== undefined ||
|
|
141
|
+
parts.creation !== undefined ||
|
|
142
|
+
(parts.move === undefined && parts.removal === undefined)) {
|
|
143
|
+
throw runtimeError('room-draft-file-exclusive');
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
file: current.file,
|
|
147
|
+
...(parts.move === undefined
|
|
148
|
+
? {}
|
|
149
|
+
: { move: { to: parts.move.to, base: kept(current.move, parts.move.base) } }),
|
|
150
|
+
...(parts.removal === undefined
|
|
151
|
+
? {}
|
|
152
|
+
: { removal: { base: kept(current.removal, parts.removal.base) } }),
|
|
153
|
+
};
|
|
122
154
|
}
|
|
123
155
|
const next = {};
|
|
124
156
|
const fields = named(parts.fields);
|
|
@@ -156,17 +188,9 @@ export function held(current, parts) {
|
|
|
156
188
|
next.removal = { base: kept(current?.removal, parts.removal.base) };
|
|
157
189
|
}
|
|
158
190
|
if (Object.keys(next).length === 0)
|
|
159
|
-
throw
|
|
191
|
+
throw runtimeError('room-draft-empty');
|
|
160
192
|
return next;
|
|
161
193
|
}
|
|
162
|
-
export function equalValue(left, right) {
|
|
163
|
-
if (left === right)
|
|
164
|
-
return true;
|
|
165
|
-
return (Array.isArray(left) &&
|
|
166
|
-
Array.isArray(right) &&
|
|
167
|
-
left.length === right.length &&
|
|
168
|
-
left.every((item, index) => equalValue(item, right[index])));
|
|
169
|
-
}
|
|
170
194
|
function sameField(left, right) {
|
|
171
195
|
if (left === null || right === null)
|
|
172
196
|
return left === right;
|
|
@@ -174,7 +198,7 @@ function sameField(left, right) {
|
|
|
174
198
|
}
|
|
175
199
|
export function underneath(parts, path, visible) {
|
|
176
200
|
const markdown = visible?.documents[path] ?? null;
|
|
177
|
-
const document = visible?.collection.
|
|
201
|
+
const document = visible?.collection.document(path);
|
|
178
202
|
const report = {};
|
|
179
203
|
const fields = {};
|
|
180
204
|
for (const [name, part] of named(parts.fields)) {
|
|
@@ -207,8 +231,28 @@ export function underneath(parts, path, visible) {
|
|
|
207
231
|
report.move = markdown;
|
|
208
232
|
if (parts.removal !== undefined && markdown !== parts.removal.base)
|
|
209
233
|
report.removal = markdown;
|
|
234
|
+
if (parts.file !== undefined) {
|
|
235
|
+
const file = binaryBase(visible, path);
|
|
236
|
+
if (file !== parts.file.base || markdown !== null)
|
|
237
|
+
report.file = file;
|
|
238
|
+
}
|
|
210
239
|
return report;
|
|
211
240
|
}
|
|
241
|
+
const UNTYPED_MEDIA_TYPE = 'application/octet-stream';
|
|
242
|
+
export async function heldFile(blob, base) {
|
|
243
|
+
const bytes = await blob.arrayBuffer();
|
|
244
|
+
return {
|
|
245
|
+
blob,
|
|
246
|
+
localId: binaryLocalId(),
|
|
247
|
+
byteLength: bytes.byteLength,
|
|
248
|
+
mediaType: blob.type === '' ? UNTYPED_MEDIA_TYPE : blob.type,
|
|
249
|
+
sha256: hexDigest(await crypto.subtle.digest('SHA-256', bytes)),
|
|
250
|
+
base,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
export function binaryBase(visible, path) {
|
|
254
|
+
return visible?.binaries[path] === undefined ? null : (visible.revisions[path] ?? null);
|
|
255
|
+
}
|
|
212
256
|
export function changedParts(path, report) {
|
|
213
257
|
return [
|
|
214
258
|
...(report.creation === undefined ? [] : [{ path, part: 'creation' }]),
|
|
@@ -218,6 +262,7 @@ export function changedParts(path, report) {
|
|
|
218
262
|
...(report.markdown === undefined ? [] : [{ path, part: 'markdown' }]),
|
|
219
263
|
...(report.move === undefined ? [] : [{ path, part: 'move' }]),
|
|
220
264
|
...(report.removal === undefined ? [] : [{ path, part: 'removal' }]),
|
|
265
|
+
...(report.file === undefined ? [] : [{ path, part: 'file' }]),
|
|
221
266
|
];
|
|
222
267
|
}
|
|
223
268
|
function joined(existing, returned) {
|
|
@@ -280,12 +325,15 @@ export function returnedInto(existing, returned) {
|
|
|
280
325
|
const creation = existing.creation ?? returned.creation;
|
|
281
326
|
const move = existing.move ?? returned.move;
|
|
282
327
|
const removal = existing.removal ?? returned.removal;
|
|
328
|
+
const file = existing.file ?? returned.file;
|
|
283
329
|
if (creation !== undefined)
|
|
284
330
|
next.creation = creation;
|
|
285
331
|
if (move !== undefined)
|
|
286
332
|
next.move = move;
|
|
287
333
|
if (removal !== undefined)
|
|
288
334
|
next.removal = removal;
|
|
335
|
+
if (file !== undefined)
|
|
336
|
+
next.file = file;
|
|
289
337
|
return next;
|
|
290
338
|
}
|
|
291
339
|
export function moveTarget(move) {
|
|
@@ -321,9 +369,70 @@ export function changesOf(path, parts) {
|
|
|
321
369
|
if (parts.markdown !== undefined) {
|
|
322
370
|
changes.push({ kind: 'replace', path, content: parts.markdown.value });
|
|
323
371
|
}
|
|
372
|
+
if (parts.file !== undefined && parts.removal === undefined) {
|
|
373
|
+
const { base, ...file } = parts.file;
|
|
374
|
+
const at = parts.move === undefined ? path : moveTarget(parts.move);
|
|
375
|
+
if (base !== null && at !== path)
|
|
376
|
+
changes.push({ kind: 'move', path, to: at });
|
|
377
|
+
changes.push({ kind: 'binary', path: at, ...file });
|
|
378
|
+
if (base === null && at !== path)
|
|
379
|
+
bases.push({ kind: 'absent', path: at });
|
|
380
|
+
return { changes, bases };
|
|
381
|
+
}
|
|
382
|
+
if (parts.file?.base === null)
|
|
383
|
+
return { changes, bases };
|
|
324
384
|
if (parts.move !== undefined)
|
|
325
385
|
changes.push({ kind: 'move', path, to: moveTarget(parts.move) });
|
|
326
386
|
if (parts.removal !== undefined)
|
|
327
387
|
changes.push({ kind: 'remove', path });
|
|
328
388
|
return { changes, bases };
|
|
329
389
|
}
|
|
390
|
+
function rebased(before, after) {
|
|
391
|
+
return before === undefined ? after : { ...after, base: before.base };
|
|
392
|
+
}
|
|
393
|
+
function rebasedAll(before, after) {
|
|
394
|
+
return {
|
|
395
|
+
...before,
|
|
396
|
+
...Object.fromEntries(Object.entries(after).map(([name, part]) => [name, rebased(before?.[name], part)])),
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
export function joinedDraft(carried, saved) {
|
|
400
|
+
const draft = saved.find((item) => item.path === carried.path);
|
|
401
|
+
if (draft === undefined)
|
|
402
|
+
return carried;
|
|
403
|
+
const held = carried.parts;
|
|
404
|
+
const next = draft.parts;
|
|
405
|
+
return {
|
|
406
|
+
path: carried.path,
|
|
407
|
+
parts: {
|
|
408
|
+
...held,
|
|
409
|
+
...next,
|
|
410
|
+
...(next.fields === undefined ? {} : { fields: rebasedAll(held.fields, next.fields) }),
|
|
411
|
+
...(next.sections === undefined
|
|
412
|
+
? {}
|
|
413
|
+
: { sections: rebasedAll(held.sections, next.sections) }),
|
|
414
|
+
...(next.preamble === undefined ? {} : { preamble: rebased(held.preamble, next.preamble) }),
|
|
415
|
+
...(next.markdown === undefined ? {} : { markdown: rebased(held.markdown, next.markdown) }),
|
|
416
|
+
},
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
export function withdrawnDrafts(drafts, changes) {
|
|
420
|
+
return drafts.flatMap((draft) => {
|
|
421
|
+
const file = draft.parts.file;
|
|
422
|
+
const at = draft.parts.move?.to ?? draft.path;
|
|
423
|
+
const change = changes.find((item) => (item.kind === 'move' || item.kind === 'remove') && item.path === at);
|
|
424
|
+
if (file === undefined || change === undefined)
|
|
425
|
+
return [draft];
|
|
426
|
+
if (change.kind === 'move') {
|
|
427
|
+
return [
|
|
428
|
+
{
|
|
429
|
+
path: draft.path,
|
|
430
|
+
parts: change.to === draft.path ? { file } : { file, move: { to: change.to, base: null } },
|
|
431
|
+
},
|
|
432
|
+
];
|
|
433
|
+
}
|
|
434
|
+
return file.base === null
|
|
435
|
+
? []
|
|
436
|
+
: [{ path: draft.path, parts: { file, removal: { base: null } } }];
|
|
437
|
+
});
|
|
438
|
+
}
|
package/dist/rows.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Document } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { HeadChange } from './adapter.js';
|
|
3
|
+
import type { BinaryFileRecord } from './binary.js';
|
|
3
4
|
import { type Composition } from './collection.js';
|
|
4
5
|
type Fields = Readonly<Record<string, unknown>>;
|
|
5
6
|
export type DocumentRow = {
|
|
@@ -14,6 +15,7 @@ export type DocumentRow = {
|
|
|
14
15
|
directories: readonly string[];
|
|
15
16
|
body: string;
|
|
16
17
|
change: HeadChange | null;
|
|
18
|
+
binary: BinaryFileRecord | null;
|
|
17
19
|
};
|
|
18
20
|
export type BodyRow = {
|
|
19
21
|
key: string;
|
|
@@ -37,6 +39,8 @@ export type ReferenceRow = {
|
|
|
37
39
|
};
|
|
38
40
|
export type Row = DocumentRow | BodyRow | ReferenceRow;
|
|
39
41
|
export declare function documentKey(room: string, path: string): string;
|
|
40
|
-
export declare function
|
|
42
|
+
export declare function roomOfKey(key: string): string;
|
|
43
|
+
export declare function markdownPath(path: string): boolean;
|
|
44
|
+
export declare function rowsOf(room: string, path: string, document: Document | null, composition: Composition, change: HeadChange | null, binary: BinaryFileRecord | null): readonly Row[];
|
|
41
45
|
export {};
|
|
42
46
|
//# sourceMappingURL=rows.d.ts.map
|
package/dist/rows.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,KAAK,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,CAAC;IACtD,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,KAAK,MAAM,GAAG,QAAQ,CAAC,MA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