@agentshouse/mdruntime 0.1.0-cec6690d5712e → 0.1.0-cedb03eaa48b6
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 +277 -271
- package/README.md +8 -8
- package/dist/adapter.d.ts +85 -20
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attempt.d.ts.map +1 -1
- package/dist/attempt.js +14 -1
- 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 +3 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +37 -14
- package/dist/change-set.d.ts +2 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +40 -13
- package/dist/change.d.ts +11 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- package/dist/chat/acts.d.ts +3 -4
- package/dist/chat/acts.d.ts.map +1 -1
- package/dist/chat/acts.js +10 -10
- package/dist/chat/earlier.d.ts +10 -0
- package/dist/chat/earlier.d.ts.map +1 -0
- package/dist/chat/earlier.js +54 -0
- package/dist/chat/kit.d.ts +2 -1
- package/dist/chat/kit.d.ts.map +1 -1
- package/dist/chat/kit.js +3 -3
- package/dist/chat/list.d.ts +8 -1
- package/dist/chat/list.d.ts.map +1 -1
- package/dist/chat/list.js +48 -8
- package/dist/chat/markdown.d.ts +2 -1
- package/dist/chat/markdown.d.ts.map +1 -1
- package/dist/chat/markdown.js +7 -6
- package/dist/chat/message.d.ts.map +1 -1
- package/dist/chat/message.js +2 -2
- package/dist/chat/messages.d.ts +1 -0
- package/dist/chat/messages.d.ts.map +1 -1
- package/dist/chat/messages.js +4 -0
- package/dist/chat/provider.d.ts +1 -1
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +62 -79
- package/dist/chat/question.d.ts +1 -1
- package/dist/chat/question.d.ts.map +1 -1
- package/dist/chat/question.js +7 -18
- package/dist/chat/ready.d.ts +1 -0
- package/dist/chat/ready.d.ts.map +1 -1
- package/dist/chat/ready.js +4 -4
- package/dist/chat/style.js +5 -5
- package/dist/client.d.ts +22 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +23 -6
- package/dist/collection.d.ts +17 -3
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +260 -19
- package/dist/connection.d.ts +39 -12
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1769 -385
- package/dist/conversation.d.ts +20 -7
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +474 -163
- package/dist/durability.d.ts +7 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +17 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +157 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/host.d.ts +15 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +98 -12
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +9 -0
- package/dist/index.d.ts +12 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/memory.d.ts +10 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +64 -17
- package/dist/model.d.ts +4 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +10 -1
- package/dist/observation.d.ts +7 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +29 -12
- package/dist/outcome.d.ts +17 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +10 -0
- package/dist/overlay.d.ts +15 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +99 -62
- package/dist/query.d.ts +58 -4
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +36 -7
- package/dist/reach.d.ts +8 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +53 -6
- package/dist/react.d.ts +8 -6
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +7 -17
- package/dist/read-side.d.ts +16 -7
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +493 -102
- package/dist/readiness.d.ts +53 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +33 -0
- package/dist/reads.d.ts +11 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +98 -0
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +197 -0
- package/dist/refresh.d.ts +4 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +27 -25
- package/dist/replica.d.ts +11 -4
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +106 -48
- package/dist/room-draft.d.ts +32 -3
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +121 -3
- package/dist/rows.d.ts +8 -13
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +12 -13
- package/dist/save.d.ts +29 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +358 -30
- package/dist/search.d.ts +49 -6
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +192 -47
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +11 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +368 -0
- package/dist/status.d.ts +4 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/store.d.ts +68 -21
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +463 -206
- package/dist/turn.d.ts +7 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +51 -0
- package/dist/windows.d.ts +26 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +93 -0
- package/dist/wire.d.ts +152 -30
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +52 -29
- package/package.json +12 -8
- 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,9 +1,9 @@
|
|
|
1
1
|
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
|
-
import { immutable } from './change.js';
|
|
3
|
-
import { collectionOf, unreadable, validateCollection, } from './collection.js';
|
|
4
|
-
import { overlay, overlayChanged, sameLayerText } from './overlay.js';
|
|
2
|
+
import { immutable, landing } from './change.js';
|
|
3
|
+
import { changedCleanly, collectionOf, unreadable, validateCollection, } from './collection.js';
|
|
4
|
+
import { acceptedBinaries, overlay, overlayChanged, sameLayerText, } from './overlay.js';
|
|
5
5
|
import { providerRewritten } from './save.js';
|
|
6
|
-
import {
|
|
6
|
+
import { drafted, patched, settled, shared } from './shared.js';
|
|
7
7
|
export function compositionOf(record) {
|
|
8
8
|
return {
|
|
9
9
|
model: record.model,
|
|
@@ -12,24 +12,49 @@ export function compositionOf(record) {
|
|
|
12
12
|
: { roots: record.typedSelection.roots, model: record.selectionModel },
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
+
function held(record) {
|
|
16
|
+
const documents = shared(record.documents);
|
|
17
|
+
const binaries = shared(record.binaries);
|
|
18
|
+
const revisions = shared(record.revisions);
|
|
19
|
+
const fileIds = shared(record.fileIds);
|
|
20
|
+
const changes = shared(record.changes);
|
|
21
|
+
const written = shared(record.written);
|
|
22
|
+
return documents === record.documents &&
|
|
23
|
+
binaries === record.binaries &&
|
|
24
|
+
revisions === record.revisions &&
|
|
25
|
+
fileIds === record.fileIds &&
|
|
26
|
+
changes === record.changes &&
|
|
27
|
+
written === record.written
|
|
28
|
+
? record
|
|
29
|
+
: { ...record, documents, binaries, revisions, fileIds, changes, written };
|
|
30
|
+
}
|
|
15
31
|
export function confirmedOf(record, previous) {
|
|
32
|
+
const kept = held(record);
|
|
16
33
|
return {
|
|
17
|
-
record,
|
|
18
|
-
collection: collectionOf(
|
|
34
|
+
record: kept,
|
|
35
|
+
collection: collectionOf(kept.documents, compositionOf(kept), previous?.collection),
|
|
19
36
|
};
|
|
20
37
|
}
|
|
21
38
|
export function sameMembership(record, other) {
|
|
22
39
|
return (JSON.stringify(record.typedSelection?.roots ?? null) ===
|
|
23
40
|
JSON.stringify(other.typedSelection?.roots ?? null));
|
|
24
41
|
}
|
|
25
|
-
|
|
42
|
+
function cleanly(record, previous) {
|
|
43
|
+
if (previous === undefined)
|
|
44
|
+
return false;
|
|
45
|
+
const before = previous.record;
|
|
46
|
+
return changedCleanly({ text: record.documents, binaries: record.binaries }, { text: before.documents, binaries: before.binaries, composition: compositionOf(before) }, compositionOf(record));
|
|
47
|
+
}
|
|
48
|
+
export function readStaged(staged, previous) {
|
|
49
|
+
const record = held(staged);
|
|
26
50
|
const textChanged = previous === undefined || !sameLayerText(record, previous.record);
|
|
27
51
|
const modeled = record.model.status !== 'unavailable' || record.selectionModel.status !== 'unavailable';
|
|
28
52
|
if (modeled &&
|
|
29
53
|
(textChanged ||
|
|
30
54
|
record.model !== previous?.record.model ||
|
|
31
|
-
record.selectionModel !== previous?.record.selectionModel)
|
|
32
|
-
|
|
55
|
+
record.selectionModel !== previous?.record.selectionModel) &&
|
|
56
|
+
!cleanly(record, previous)) {
|
|
57
|
+
const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
33
58
|
if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
|
|
34
59
|
return { kind: 'refused', refusal: verdict };
|
|
35
60
|
}
|
|
@@ -47,22 +72,43 @@ export function readStaged(record, previous) {
|
|
|
47
72
|
return { kind: 'staged', confirmed: confirmedOf(record, previous) };
|
|
48
73
|
}
|
|
49
74
|
export function readReclassified(record, previous) {
|
|
50
|
-
const verdict = validateCollection(record.documents, record.
|
|
75
|
+
const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
51
76
|
if (verdict.verdict !== 'refuse')
|
|
52
77
|
return { kind: 'staged', confirmed: confirmedOf(record, previous) };
|
|
53
78
|
return verdict.rule === 'model-unavailable'
|
|
54
79
|
? { kind: 'deferred' }
|
|
55
80
|
: { kind: 'refused', refusal: verdict };
|
|
56
81
|
}
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
82
|
+
function returnedBinaries(held, submitted, accepted) {
|
|
83
|
+
const binaries = drafted(held);
|
|
84
|
+
for (const change of submitted.changes) {
|
|
85
|
+
if (change.kind !== 'move')
|
|
86
|
+
continue;
|
|
87
|
+
const moved = binaries[change.path];
|
|
88
|
+
if (moved === undefined || accepted.revisions[change.to] === undefined)
|
|
89
|
+
continue;
|
|
90
|
+
binaries[change.to] = moved;
|
|
91
|
+
delete binaries[change.path];
|
|
92
|
+
}
|
|
93
|
+
Object.assign(binaries, acceptedBinaries(accepted.binaryFiles ?? {}));
|
|
94
|
+
for (const path of accepted.removals)
|
|
95
|
+
delete binaries[path];
|
|
96
|
+
return settled(binaries);
|
|
97
|
+
}
|
|
98
|
+
export function applyReturned(confirmed, submitted, accepted, roomVersion, writtenAt) {
|
|
99
|
+
const { documents, revisions, fileIds, changes, removals } = accepted;
|
|
100
|
+
const nextDocuments = drafted(confirmed.record.documents);
|
|
101
|
+
const nextRevisions = drafted(confirmed.record.revisions);
|
|
102
|
+
const nextFileIds = drafted(confirmed.record.fileIds);
|
|
103
|
+
const nextChanges = drafted(confirmed.record.changes);
|
|
104
|
+
const nextWritten = drafted(confirmed.record.written);
|
|
105
|
+
Object.assign(nextDocuments, documents);
|
|
106
|
+
Object.assign(nextRevisions, revisions);
|
|
107
|
+
for (const path of Object.keys({ ...documents, ...revisions }))
|
|
108
|
+
delete nextFileIds[path];
|
|
109
|
+
Object.assign(nextFileIds, fileIds);
|
|
110
|
+
for (const path of Object.keys(documents))
|
|
111
|
+
nextWritten[path] = writtenAt;
|
|
66
112
|
for (const [path, revision] of Object.entries(revisions)) {
|
|
67
113
|
if (confirmed.record.revisions[path] !== revision)
|
|
68
114
|
delete nextChanges[path];
|
|
@@ -71,21 +117,19 @@ export function applyReturned(confirmed, documents, revisions, changes, removals
|
|
|
71
117
|
for (const path of removals) {
|
|
72
118
|
delete nextDocuments[path];
|
|
73
119
|
delete nextRevisions[path];
|
|
120
|
+
delete nextFileIds[path];
|
|
74
121
|
delete nextChanges[path];
|
|
75
122
|
delete nextWritten[path];
|
|
76
|
-
binaryTargets.delete(path);
|
|
77
123
|
}
|
|
78
124
|
return readStaged({
|
|
79
125
|
...confirmed.record,
|
|
80
126
|
roomVersion,
|
|
81
|
-
documents: nextDocuments,
|
|
82
|
-
revisions: nextRevisions,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
? confirmed.record.attachments
|
|
88
|
-
: declaredAttachments([attachments]),
|
|
127
|
+
documents: settled(nextDocuments),
|
|
128
|
+
revisions: settled(nextRevisions),
|
|
129
|
+
fileIds: settled(nextFileIds),
|
|
130
|
+
changes: settled(nextChanges),
|
|
131
|
+
written: settled(nextWritten),
|
|
132
|
+
binaries: returnedBinaries(confirmed.record.binaries, submitted, accepted),
|
|
89
133
|
}, confirmed);
|
|
90
134
|
}
|
|
91
135
|
function predicted(confirmed, batches, previous) {
|
|
@@ -135,8 +179,9 @@ export function replicaOf(confirmed, queue, previous) {
|
|
|
135
179
|
queue: batches,
|
|
136
180
|
visible: {
|
|
137
181
|
documents: confirmed.record.documents,
|
|
138
|
-
|
|
182
|
+
binaries: confirmed.record.binaries,
|
|
139
183
|
revisions: confirmed.record.revisions,
|
|
184
|
+
fileIds: confirmed.record.fileIds,
|
|
140
185
|
changes: confirmed.record.changes,
|
|
141
186
|
collection: confirmed.collection,
|
|
142
187
|
},
|
|
@@ -155,7 +200,7 @@ export function replicaOf(confirmed, queue, previous) {
|
|
|
155
200
|
};
|
|
156
201
|
}
|
|
157
202
|
function present(layer, path) {
|
|
158
|
-
return layer.documents[path] !== undefined || layer.
|
|
203
|
+
return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
|
|
159
204
|
}
|
|
160
205
|
function holds(layer, preconditions) {
|
|
161
206
|
const parsed = new Map();
|
|
@@ -222,41 +267,53 @@ function effects(change) {
|
|
|
222
267
|
{ kind: 'present', path: change.to },
|
|
223
268
|
];
|
|
224
269
|
}
|
|
270
|
+
if (change.kind === 'binary')
|
|
271
|
+
return [{ kind: 'present', path }];
|
|
225
272
|
return [{ kind: 'absent', path }];
|
|
226
273
|
}
|
|
227
|
-
function after(changes, index, path) {
|
|
228
|
-
let at = path;
|
|
229
|
-
for (const change of changes.slice(index + 1)) {
|
|
230
|
-
if (change.path !== at)
|
|
231
|
-
continue;
|
|
232
|
-
if (change.kind === 'remove')
|
|
233
|
-
return null;
|
|
234
|
-
if (change.kind === 'move')
|
|
235
|
-
at = change.to;
|
|
236
|
-
}
|
|
237
|
-
return at;
|
|
238
|
-
}
|
|
239
274
|
export function landed(batch, confirmed, current = {}) {
|
|
240
|
-
const layer = {
|
|
275
|
+
const layer = {
|
|
276
|
+
...confirmed.record,
|
|
277
|
+
documents: patched(confirmed.record.documents, Object.entries(current)),
|
|
278
|
+
};
|
|
241
279
|
return batch.changes.every((change, index) => {
|
|
242
280
|
if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
|
|
243
|
-
const at =
|
|
281
|
+
const at = landing(batch.changes, index, change.path);
|
|
244
282
|
return at === null || layer.documents[at] === change.content;
|
|
245
283
|
}
|
|
284
|
+
if (change.kind === 'binary') {
|
|
285
|
+
const at = landing(batch.changes, index, change.path);
|
|
286
|
+
return at === null || layer.binaries[at]?.sha256 === change.sha256;
|
|
287
|
+
}
|
|
246
288
|
return effects(change).every((effect) => {
|
|
247
289
|
if (effect.kind === 'absent')
|
|
248
290
|
return holds(layer, [effect]);
|
|
249
|
-
const at =
|
|
291
|
+
const at = landing(batch.changes, index, effect.path);
|
|
250
292
|
return at === null || holds(layer, [{ ...effect, path: at }]);
|
|
251
293
|
});
|
|
252
294
|
});
|
|
253
295
|
}
|
|
254
|
-
|
|
296
|
+
function founded(batch, layer) {
|
|
297
|
+
let changed = false;
|
|
298
|
+
const preconditions = batch.preconditions.map((precondition) => {
|
|
299
|
+
if (precondition.kind !== 'content')
|
|
300
|
+
return precondition;
|
|
301
|
+
const revision = layer.revisions[precondition.path];
|
|
302
|
+
if (revision === undefined || layer.documents[precondition.path] !== precondition.content) {
|
|
303
|
+
return precondition;
|
|
304
|
+
}
|
|
305
|
+
changed = true;
|
|
306
|
+
return { kind: 'revision', path: precondition.path, revision };
|
|
307
|
+
});
|
|
308
|
+
return changed ? immutable({ ...batch, preconditions }) : batch;
|
|
309
|
+
}
|
|
310
|
+
export function standing(confirmed, queue, withdrawable, local) {
|
|
255
311
|
if (!queue.some(withdrawable))
|
|
256
|
-
return [];
|
|
312
|
+
return { withdrawn: [], kept: queue };
|
|
257
313
|
const composition = compositionOf(confirmed.record);
|
|
258
314
|
let layer = confirmed.record;
|
|
259
315
|
const withdrawn = [];
|
|
316
|
+
const kept = [];
|
|
260
317
|
for (const batch of queue) {
|
|
261
318
|
if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
|
|
262
319
|
withdrawn.push(batch);
|
|
@@ -276,7 +333,8 @@ export function withdrawals(confirmed, queue, withdrawable, local) {
|
|
|
276
333
|
withdrawn.push(batch);
|
|
277
334
|
continue;
|
|
278
335
|
}
|
|
336
|
+
kept.push(local || !withdrawable(batch) ? batch : founded(batch, layer));
|
|
279
337
|
layer = next;
|
|
280
338
|
}
|
|
281
|
-
return withdrawn;
|
|
339
|
+
return { withdrawn, kept };
|
|
282
340
|
}
|
package/dist/room-draft.d.ts
CHANGED
|
@@ -37,6 +37,17 @@ export type RoomDraftParts = {
|
|
|
37
37
|
readonly removal?: {
|
|
38
38
|
readonly base?: string | null;
|
|
39
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;
|
|
40
51
|
};
|
|
41
52
|
type HeldParts = {
|
|
42
53
|
readonly fields?: Readonly<Record<string, {
|
|
@@ -63,6 +74,7 @@ type HeldParts = {
|
|
|
63
74
|
readonly removal?: {
|
|
64
75
|
readonly base: string | null;
|
|
65
76
|
};
|
|
77
|
+
readonly file?: HeldFile;
|
|
66
78
|
};
|
|
67
79
|
type ChangedUnderneath = {
|
|
68
80
|
readonly fields?: Readonly<Record<string, FieldValue>>;
|
|
@@ -72,9 +84,10 @@ type ChangedUnderneath = {
|
|
|
72
84
|
readonly creation?: string;
|
|
73
85
|
readonly move?: string | null;
|
|
74
86
|
readonly removal?: string | null;
|
|
87
|
+
readonly file?: string | null;
|
|
75
88
|
};
|
|
76
89
|
export type ReturnReason = ProviderRefusal & {
|
|
77
|
-
readonly kind: 'conflicted' | 'rejected' | 'expired' | 'withdrawn'
|
|
90
|
+
readonly kind: Open<'conflicted' | 'rejected' | 'expired' | 'withdrawn'>;
|
|
78
91
|
};
|
|
79
92
|
export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
|
|
80
93
|
export type RoomDraft = {
|
|
@@ -97,7 +110,7 @@ export type RoomDraftWrite = {
|
|
|
97
110
|
export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
|
|
98
111
|
export type ChangedPart = {
|
|
99
112
|
readonly path: string;
|
|
100
|
-
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal'>;
|
|
113
|
+
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal' | 'file'>;
|
|
101
114
|
readonly name?: string;
|
|
102
115
|
};
|
|
103
116
|
export type RoomDraftRecord = {
|
|
@@ -112,9 +125,23 @@ export type SavedDraft = {
|
|
|
112
125
|
readonly parts: HeldParts;
|
|
113
126
|
};
|
|
114
127
|
export declare function readParts(value: unknown): RoomDraftParts;
|
|
115
|
-
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts): HeldParts;
|
|
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[];
|
|
133
|
+
export type TextParts = {
|
|
134
|
+
readonly fields?: Readonly<Record<string, {
|
|
135
|
+
readonly value: unknown;
|
|
136
|
+
}>>;
|
|
137
|
+
readonly sections?: Readonly<Record<string, {
|
|
138
|
+
readonly value: string;
|
|
139
|
+
}>>;
|
|
140
|
+
readonly preamble?: {
|
|
141
|
+
readonly value: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
export declare function partsAfter(markdown: string, parts: TextParts): string;
|
|
118
145
|
export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
|
|
119
146
|
export declare function moveTarget(move: {
|
|
120
147
|
readonly to: string;
|
|
@@ -123,5 +150,7 @@ export declare function changesOf(path: string, parts: HeldParts): {
|
|
|
123
150
|
changes: readonly Change[];
|
|
124
151
|
bases: readonly Precondition[];
|
|
125
152
|
};
|
|
153
|
+
export declare function joinedDraft(carried: SavedDraft, saved: readonly SavedDraft[]): SavedDraft;
|
|
154
|
+
export declare function withdrawnDrafts(drafts: readonly SavedDraft[], changes: readonly Change[]): readonly SavedDraft[];
|
|
126
155
|
export {};
|
|
127
156
|
//# sourceMappingURL=room-draft.d.ts.map
|
package/dist/room-draft.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-draft.d.ts","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S,UAAU,EAAE,EAC7B,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,UAAU,EAAE,CAqBvB"}
|
package/dist/room-draft.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { apply, equalValue, frontmatterValue, parse, serialize } from '@agentshouse/mdmodel';
|
|
2
2
|
import { runtimeError } from './failure.js';
|
|
3
|
+
import { hexDigest } from './file.js';
|
|
4
|
+
import { binaryLocalId } from './identity.js';
|
|
3
5
|
import { normalize } from './paths.js';
|
|
4
6
|
export function returnedBy(kind) {
|
|
5
7
|
return { kind, code: kind, fields: {}, retryable: false };
|
|
@@ -60,6 +62,7 @@ const PART_NAMES = new Set([
|
|
|
60
62
|
'creation',
|
|
61
63
|
'move',
|
|
62
64
|
'removal',
|
|
65
|
+
'file',
|
|
63
66
|
]);
|
|
64
67
|
export function readParts(value) {
|
|
65
68
|
if (!plain(value) || Object.keys(value).some((name) => !PART_NAMES.has(name)))
|
|
@@ -95,6 +98,13 @@ export function readParts(value) {
|
|
|
95
98
|
const base = markdownBase(value.removal.base);
|
|
96
99
|
parts.removal = base === undefined ? {} : { base };
|
|
97
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
|
+
}
|
|
98
108
|
return parts;
|
|
99
109
|
}
|
|
100
110
|
function named(record) {
|
|
@@ -115,10 +125,33 @@ function editsText(parts) {
|
|
|
115
125
|
named(parts.fields).length > 0 ||
|
|
116
126
|
named(parts.sections).length > 0);
|
|
117
127
|
}
|
|
118
|
-
export function held(current, parts) {
|
|
128
|
+
export function held(current, parts, file) {
|
|
119
129
|
if (parts.markdown !== undefined && editsText(parts)) {
|
|
120
130
|
throw runtimeError('room-draft-markdown-exclusive');
|
|
121
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
|
+
};
|
|
154
|
+
}
|
|
122
155
|
const next = {};
|
|
123
156
|
const fields = named(parts.fields);
|
|
124
157
|
if (fields.length > 0) {
|
|
@@ -198,8 +231,28 @@ export function underneath(parts, path, visible) {
|
|
|
198
231
|
report.move = markdown;
|
|
199
232
|
if (parts.removal !== undefined && markdown !== parts.removal.base)
|
|
200
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
|
+
}
|
|
201
239
|
return report;
|
|
202
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
|
+
}
|
|
203
256
|
export function changedParts(path, report) {
|
|
204
257
|
return [
|
|
205
258
|
...(report.creation === undefined ? [] : [{ path, part: 'creation' }]),
|
|
@@ -209,6 +262,7 @@ export function changedParts(path, report) {
|
|
|
209
262
|
...(report.markdown === undefined ? [] : [{ path, part: 'markdown' }]),
|
|
210
263
|
...(report.move === undefined ? [] : [{ path, part: 'move' }]),
|
|
211
264
|
...(report.removal === undefined ? [] : [{ path, part: 'removal' }]),
|
|
265
|
+
...(report.file === undefined ? [] : [{ path, part: 'file' }]),
|
|
212
266
|
];
|
|
213
267
|
}
|
|
214
268
|
function joined(existing, returned) {
|
|
@@ -234,7 +288,7 @@ function frontmatterOf(fields) {
|
|
|
234
288
|
}
|
|
235
289
|
return serialize(document);
|
|
236
290
|
}
|
|
237
|
-
function
|
|
291
|
+
export function partsAfter(markdown, parts) {
|
|
238
292
|
const fields = named(parts.fields);
|
|
239
293
|
const pieces = [
|
|
240
294
|
...(fields.length === 0 ? [] : [frontmatterOf(fields)]),
|
|
@@ -265,18 +319,21 @@ export function returnedInto(existing, returned) {
|
|
|
265
319
|
delete next.fields;
|
|
266
320
|
delete next.sections;
|
|
267
321
|
delete next.preamble;
|
|
268
|
-
const value =
|
|
322
|
+
const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned);
|
|
269
323
|
next.markdown = { value, base: whole.base };
|
|
270
324
|
}
|
|
271
325
|
const creation = existing.creation ?? returned.creation;
|
|
272
326
|
const move = existing.move ?? returned.move;
|
|
273
327
|
const removal = existing.removal ?? returned.removal;
|
|
328
|
+
const file = existing.file ?? returned.file;
|
|
274
329
|
if (creation !== undefined)
|
|
275
330
|
next.creation = creation;
|
|
276
331
|
if (move !== undefined)
|
|
277
332
|
next.move = move;
|
|
278
333
|
if (removal !== undefined)
|
|
279
334
|
next.removal = removal;
|
|
335
|
+
if (file !== undefined)
|
|
336
|
+
next.file = file;
|
|
280
337
|
return next;
|
|
281
338
|
}
|
|
282
339
|
export function moveTarget(move) {
|
|
@@ -312,9 +369,70 @@ export function changesOf(path, parts) {
|
|
|
312
369
|
if (parts.markdown !== undefined) {
|
|
313
370
|
changes.push({ kind: 'replace', path, content: parts.markdown.value });
|
|
314
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 };
|
|
315
384
|
if (parts.move !== undefined)
|
|
316
385
|
changes.push({ kind: 'move', path, to: moveTarget(parts.move) });
|
|
317
386
|
if (parts.removal !== undefined)
|
|
318
387
|
changes.push({ kind: 'remove', path });
|
|
319
388
|
return { changes, bases };
|
|
320
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
|
-
import { type
|
|
1
|
+
import { type Frontmatter } 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 = {
|
|
@@ -12,17 +13,11 @@ export type DocumentRow = {
|
|
|
12
13
|
values: Fields;
|
|
13
14
|
reached: Readonly<Record<string, readonly unknown[]>>;
|
|
14
15
|
directories: readonly string[];
|
|
15
|
-
|
|
16
|
+
folder: string;
|
|
17
|
+
text: string | null;
|
|
16
18
|
change: HeadChange | null;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
key: string;
|
|
20
|
-
kind: 'body';
|
|
21
|
-
room: string;
|
|
22
|
-
path: string;
|
|
23
|
-
preamble: string;
|
|
24
|
-
sections: Readonly<Record<string, string>>;
|
|
25
|
-
markdown: string;
|
|
19
|
+
fileId: string | null;
|
|
20
|
+
binary: BinaryFileRecord | null;
|
|
26
21
|
};
|
|
27
22
|
export type ReferenceRow = {
|
|
28
23
|
key: string;
|
|
@@ -35,10 +30,10 @@ export type ReferenceRow = {
|
|
|
35
30
|
path: string;
|
|
36
31
|
type: string;
|
|
37
32
|
};
|
|
38
|
-
export type Row = DocumentRow |
|
|
33
|
+
export type Row = DocumentRow | ReferenceRow;
|
|
39
34
|
export declare function documentKey(room: string, path: string): string;
|
|
40
35
|
export declare function roomOfKey(key: string): string;
|
|
41
36
|
export declare function markdownPath(path: string): boolean;
|
|
42
|
-
export declare function rowsOf(room: string, path: string, document:
|
|
37
|
+
export declare function rowsOf(room: string, path: string, document: Frontmatter | null, composition: Composition, change: HeadChange | null, fileId: string | null, binary: BinaryFileRecord | null): readonly Row[];
|
|
43
38
|
export {};
|
|
44
39
|
//# 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,
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,W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WAAW,GAAG,YAAY,CAAC;AAM7C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAuFD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,WAAW,GAAG,IAAI,EAC5B,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,MAAM,EAAE,gBAAgB,GAAG,IAAI,GAC9B,SAAS,GAAG,EAAE,CAmEhB"}
|
package/dist/rows.js
CHANGED
|
@@ -64,6 +64,9 @@ function walk(reading, node, forms, exact) {
|
|
|
64
64
|
: [{ text: `${form.text}/${segment}`, through: form.through, pending: false }]), `${exact}/${segment}`);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
function folderOf(path) {
|
|
68
|
+
return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
|
|
69
|
+
}
|
|
67
70
|
function directoriesOf(path) {
|
|
68
71
|
const parts = path.split('/').slice(0, -1);
|
|
69
72
|
return ['', ...parts.map((_, index) => parts.slice(0, index + 1).join('/'))];
|
|
@@ -71,9 +74,8 @@ function directoriesOf(path) {
|
|
|
71
74
|
export function markdownPath(path) {
|
|
72
75
|
return path.endsWith('.md');
|
|
73
76
|
}
|
|
74
|
-
export function rowsOf(room, path, document, composition, change) {
|
|
77
|
+
export function rowsOf(room, path, document, composition, change, fileId, binary) {
|
|
75
78
|
const key = documentKey(room, path);
|
|
76
|
-
const body = keyOf('b', room, path);
|
|
77
79
|
if (document === null || !markdownPath(path)) {
|
|
78
80
|
return [
|
|
79
81
|
{
|
|
@@ -86,8 +88,11 @@ export function rowsOf(room, path, document, composition, change) {
|
|
|
86
88
|
values: {},
|
|
87
89
|
reached: {},
|
|
88
90
|
directories: directoriesOf(path),
|
|
89
|
-
|
|
91
|
+
folder: folderOf(path),
|
|
92
|
+
text: null,
|
|
90
93
|
change,
|
|
94
|
+
fileId,
|
|
95
|
+
binary,
|
|
91
96
|
},
|
|
92
97
|
];
|
|
93
98
|
}
|
|
@@ -116,17 +121,11 @@ export function rowsOf(room, path, document, composition, change) {
|
|
|
116
121
|
values,
|
|
117
122
|
reached,
|
|
118
123
|
directories: directoriesOf(path),
|
|
119
|
-
|
|
124
|
+
folder: folderOf(path),
|
|
125
|
+
text: document.content,
|
|
120
126
|
change,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
key: body,
|
|
124
|
-
kind: 'body',
|
|
125
|
-
room,
|
|
126
|
-
path,
|
|
127
|
-
preamble: document.preamble,
|
|
128
|
-
sections: document.sections,
|
|
129
|
-
markdown: document.content,
|
|
127
|
+
fileId,
|
|
128
|
+
binary,
|
|
130
129
|
},
|
|
131
130
|
...[...reading.targets.values()].map(({ field, target: found, forms }) => ({
|
|
132
131
|
key: keyOf('r', room, path, field, found),
|