@agentshouse/mdruntime 0.1.0-ce131cb435f8b → 0.1.0-ce9f29a01a271
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/dist/adapter.d.ts +12 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/change-set.d.ts +5 -2
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -1
- package/dist/chat/list.d.ts +2 -1
- package/dist/chat/list.d.ts.map +1 -1
- package/dist/chat/list.js +2 -2
- package/dist/chat/markdown.d.ts +1 -0
- package/dist/chat/markdown.d.ts.map +1 -1
- package/dist/chat/markdown.js +78 -20
- package/dist/chat/message.d.ts.map +1 -1
- package/dist/chat/message.js +9 -2
- package/dist/chat/messages.d.ts.map +1 -1
- package/dist/chat/messages.js +36 -16
- package/dist/chat/overlay.d.ts +1 -0
- package/dist/chat/overlay.d.ts.map +1 -1
- package/dist/chat/overlay.js +10 -0
- package/dist/chat/pieces.d.ts +62 -0
- package/dist/chat/pieces.d.ts.map +1 -0
- package/dist/chat/pieces.js +1110 -0
- package/dist/chat/provider.d.ts +1 -0
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +12 -3
- package/dist/chat/ready.d.ts +1 -1
- package/dist/chat/ready.d.ts.map +1 -1
- package/dist/chat/ready.js +1 -1
- package/dist/chat/steady.d.ts +3 -0
- package/dist/chat/steady.d.ts.map +1 -0
- package/dist/chat/steady.js +26 -0
- package/dist/chat.d.ts +2 -2
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +2 -2
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +45 -30
- package/dist/conversation.d.ts +5 -0
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +35 -1
- package/dist/host.d.ts +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +1 -1
- package/dist/overlay.d.ts +3 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +178 -141
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +4 -2
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +34 -15
- package/dist/replica.d.ts +2 -1
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +18 -15
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +8 -9
- package/dist/save.d.ts +1 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +154 -92
- package/dist/shared.d.ts +1 -0
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +5 -1
- package/dist/store.d.ts +2 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +387 -339
- package/dist/turn.d.ts +1 -1
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +4 -4
- package/package.json +2 -2
package/dist/replica.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
2
|
import { immutable, landing } from './change.js';
|
|
3
|
-
import { changedCleanly, collecting,
|
|
4
|
-
import { acceptedBinaries,
|
|
3
|
+
import { changedCleanly, collecting, unreadable, validateCollection, } from './collection.js';
|
|
4
|
+
import { acceptedBinaries, overlayChanged, overlaying, sameText, } from './overlay.js';
|
|
5
5
|
import { providerRewritten } from './save.js';
|
|
6
6
|
import { drafted, patched, settled, sharing } from './shared.js';
|
|
7
7
|
import { finished, stepped } from './turn.js';
|
|
@@ -142,7 +142,7 @@ export function applyReturned(confirmed, submitted, accepted, roomVersion, writt
|
|
|
142
142
|
binaries: returnedBinaries(confirmed.record.binaries, submitted, accepted),
|
|
143
143
|
}, confirmed);
|
|
144
144
|
}
|
|
145
|
-
function
|
|
145
|
+
function* predicting(confirmed, batches, previous) {
|
|
146
146
|
const composition = compositionOf(confirmed.record);
|
|
147
147
|
let layer = confirmed.record;
|
|
148
148
|
const replay = [];
|
|
@@ -152,7 +152,7 @@ function predicted(confirmed, batches, previous) {
|
|
|
152
152
|
const old = prior.get(batch.id);
|
|
153
153
|
const hasMove = batch.changes.some((change) => change.kind === 'move');
|
|
154
154
|
const reuseRewrite = old?.collection !== undefined &&
|
|
155
|
-
|
|
155
|
+
(yield* sameText(before, old.before)) &&
|
|
156
156
|
old.collection.composition.model === composition.model &&
|
|
157
157
|
old.collection.composition.selection?.model === composition.selection?.model &&
|
|
158
158
|
JSON.stringify(old.collection.composition.selection?.roots) ===
|
|
@@ -160,17 +160,17 @@ function predicted(confirmed, batches, previous) {
|
|
|
160
160
|
const collection = hasMove
|
|
161
161
|
? reuseRewrite
|
|
162
162
|
? old.collection
|
|
163
|
-
:
|
|
163
|
+
: yield* collecting(before.documents, composition, old?.collection ?? confirmed.collection)
|
|
164
164
|
: undefined;
|
|
165
165
|
const effective = collection === undefined
|
|
166
166
|
? batch
|
|
167
167
|
: reuseRewrite
|
|
168
168
|
? old.effective
|
|
169
|
-
: providerRewritten(batch, { ...before, collection });
|
|
169
|
+
: yield* providerRewritten(batch, { ...before, collection });
|
|
170
170
|
layer =
|
|
171
171
|
old === undefined
|
|
172
|
-
?
|
|
173
|
-
: overlayChanged(before,
|
|
172
|
+
? yield* overlaying(before, [effective])
|
|
173
|
+
: yield* overlayChanged(before, effective, old.before, old.effective, old.after);
|
|
174
174
|
replay.push({
|
|
175
175
|
id: batch.id,
|
|
176
176
|
before,
|
|
@@ -181,7 +181,7 @@ function predicted(confirmed, batches, previous) {
|
|
|
181
181
|
}
|
|
182
182
|
return { layer, replay };
|
|
183
183
|
}
|
|
184
|
-
export function
|
|
184
|
+
export function* replicating(confirmed, queue, previous) {
|
|
185
185
|
const batches = Object.freeze(queue.map(immutable));
|
|
186
186
|
if (batches.length === 0) {
|
|
187
187
|
return {
|
|
@@ -198,17 +198,20 @@ export function replicaOf(confirmed, queue, previous) {
|
|
|
198
198
|
replay: [],
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
-
const { layer, replay } =
|
|
201
|
+
const { layer, replay } = yield* predicting(confirmed, batches, previous);
|
|
202
202
|
return {
|
|
203
203
|
confirmed,
|
|
204
204
|
queue: batches,
|
|
205
205
|
replay,
|
|
206
206
|
visible: {
|
|
207
207
|
...layer,
|
|
208
|
-
collection:
|
|
208
|
+
collection: yield* collecting(layer.documents, compositionOf(confirmed.record), previous?.visible.collection ?? confirmed.collection),
|
|
209
209
|
},
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
|
+
export function replicaOf(confirmed, queue, previous) {
|
|
213
|
+
return finished(replicating(confirmed, queue, previous));
|
|
214
|
+
}
|
|
212
215
|
function present(layer, path) {
|
|
213
216
|
return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
|
|
214
217
|
}
|
|
@@ -317,7 +320,7 @@ function founded(batch, layer) {
|
|
|
317
320
|
});
|
|
318
321
|
return changed ? immutable({ ...batch, preconditions }) : batch;
|
|
319
322
|
}
|
|
320
|
-
export function standing(confirmed, queue, withdrawable, local) {
|
|
323
|
+
export function* standing(confirmed, queue, withdrawable, local) {
|
|
321
324
|
if (!queue.some(withdrawable))
|
|
322
325
|
return { withdrawn: [], kept: queue };
|
|
323
326
|
const composition = compositionOf(confirmed.record);
|
|
@@ -330,13 +333,13 @@ export function standing(confirmed, queue, withdrawable, local) {
|
|
|
330
333
|
continue;
|
|
331
334
|
}
|
|
332
335
|
const effective = batch.changes.some((change) => change.kind === 'move')
|
|
333
|
-
? providerRewritten(batch, {
|
|
336
|
+
? yield* providerRewritten(batch, {
|
|
334
337
|
...layer,
|
|
335
|
-
collection:
|
|
338
|
+
collection: yield* collecting(layer.documents, composition),
|
|
336
339
|
})
|
|
337
340
|
: batch;
|
|
338
341
|
let unapplied = false;
|
|
339
|
-
const next =
|
|
342
|
+
const next = yield* overlaying(layer, [effective], () => {
|
|
340
343
|
unapplied = true;
|
|
341
344
|
});
|
|
342
345
|
if (local && unapplied) {
|
package/dist/room-draft.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-draft.d.ts","sourceRoot":"","sources":["../src/room-draft.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|
1
|
+
import { apply, equalValue, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { runtimeError } from './failure.js';
|
|
3
3
|
import { hexDigest } from './file.js';
|
|
4
4
|
import { binaryLocalId } from './identity.js';
|
|
@@ -279,14 +279,13 @@ function frontmatterOf(fields) {
|
|
|
279
279
|
const opened = parse('---\n---\n');
|
|
280
280
|
if (!opened.ok)
|
|
281
281
|
return malformed();
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return serialize(document);
|
|
282
|
+
const next = apply(opened.document, fields.map(([name, part]) => ({
|
|
283
|
+
kind: 'field',
|
|
284
|
+
name,
|
|
285
|
+
value: part.value,
|
|
286
|
+
prior: undefined,
|
|
287
|
+
})));
|
|
288
|
+
return next.outcome === 'applied' ? serialize(next.document) : malformed();
|
|
290
289
|
}
|
|
291
290
|
export function partsAfter(markdown, parts) {
|
|
292
291
|
const fields = named(parts.fields);
|
package/dist/save.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export type BatchResult = {
|
|
|
38
38
|
kind: 'refused';
|
|
39
39
|
refusal: SaveRefusal;
|
|
40
40
|
};
|
|
41
|
-
export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): ChangeBatch
|
|
41
|
+
export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
|
|
42
42
|
export declare function queuedDocuments(queue: readonly ChangeBatch[]): ReadonlySet<string>;
|
|
43
43
|
export type Requeued = {
|
|
44
44
|
kind: 'requeued';
|
package/dist/save.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,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AAE,EAC1B,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,EAC3C,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,KAAK,YAAY,GACrD,QAAQ,CA+DV;AAUD,wBAAgB,MAAM,CACpB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,WAAW,GACjB,OAAO,CAsCT;AAED,wBAAgB,SAAS,CACvB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,KAAK,YAAY,GACrD,WAAW,GAAG,IAAI,CAWpB;AAmHD,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,CAE/D"}
|
package/dist/save.js
CHANGED
|
@@ -3,10 +3,10 @@ import { apply, ATTACHMENT, links, parse, pointerSegments, references, relative,
|
|
|
3
3
|
import { immutable, queuedFile, departure, } from './change.js';
|
|
4
4
|
import { available, changedCleanly, collectionOf, documentsOf, governing, referring, validateCollection, } from './collection.js';
|
|
5
5
|
import { changeBatchIdentity } from './identity.js';
|
|
6
|
-
import {
|
|
6
|
+
import { overlaying } from './overlay.js';
|
|
7
7
|
import { covered, normalize } from './paths.js';
|
|
8
8
|
import { differences } from './shared.js';
|
|
9
|
-
import { ROW_WEIGHT, stepped } from './turn.js';
|
|
9
|
+
import { finished, ROW_WEIGHT, stepped } from './turn.js';
|
|
10
10
|
function refuse(code, file, location) {
|
|
11
11
|
return {
|
|
12
12
|
kind: 'refused',
|
|
@@ -22,7 +22,7 @@ function repointed(document, definition, from, to, moves, settled) {
|
|
|
22
22
|
const parsed = parse(document.content, from);
|
|
23
23
|
if (!parsed.ok)
|
|
24
24
|
return [];
|
|
25
|
-
|
|
25
|
+
const changes = [];
|
|
26
26
|
const names = new Set();
|
|
27
27
|
for (const { pointer, value } of definition === undefined
|
|
28
28
|
? []
|
|
@@ -34,38 +34,39 @@ function repointed(document, definition, from, to, moves, settled) {
|
|
|
34
34
|
const destination = moves.get(named) ?? named;
|
|
35
35
|
if (target(to, value) === destination)
|
|
36
36
|
continue;
|
|
37
|
-
|
|
37
|
+
changes.push({
|
|
38
38
|
kind: 'reference',
|
|
39
39
|
pointer,
|
|
40
40
|
value: retarget(value, relative(to, destination)),
|
|
41
41
|
prior: value,
|
|
42
42
|
});
|
|
43
|
-
if (applied.outcome !== 'applied')
|
|
44
|
-
continue;
|
|
45
|
-
next = applied.document;
|
|
46
43
|
names.add(name);
|
|
47
44
|
}
|
|
45
|
+
if (changes.length === 0)
|
|
46
|
+
return [];
|
|
47
|
+
const applied = apply(parsed.document, changes);
|
|
48
|
+
if (applied.outcome !== 'applied')
|
|
49
|
+
return [];
|
|
50
|
+
const next = applied.document;
|
|
48
51
|
return [...names].map((name) => ({ kind: 'field', path: from, name, value: next.fields[name] }));
|
|
49
52
|
}
|
|
50
|
-
function edited(document,
|
|
51
|
-
|
|
53
|
+
function edited(document, changes) {
|
|
54
|
+
const parts = new Map();
|
|
52
55
|
for (const change of changes) {
|
|
53
|
-
if (change.
|
|
54
|
-
|
|
55
|
-
if (change.kind
|
|
56
|
-
|
|
57
|
-
const applied = apply(next, change.kind === 'preamble'
|
|
58
|
-
? { kind: 'preamble', value: change.value, prior: next.preamble }
|
|
59
|
-
: {
|
|
56
|
+
if (change.kind === 'preamble')
|
|
57
|
+
parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
58
|
+
if (change.kind === 'section')
|
|
59
|
+
parts.set(`section ${change.name}`, {
|
|
60
60
|
kind: 'section',
|
|
61
61
|
name: change.name,
|
|
62
62
|
value: change.value,
|
|
63
|
-
prior:
|
|
63
|
+
prior: document.sections[change.name] ?? '',
|
|
64
64
|
});
|
|
65
|
-
if (applied.outcome === 'applied')
|
|
66
|
-
next = applied.document;
|
|
67
65
|
}
|
|
68
|
-
|
|
66
|
+
if (parts.size === 0)
|
|
67
|
+
return document;
|
|
68
|
+
const applied = apply(document, [...parts.values()]);
|
|
69
|
+
return applied.outcome === 'applied' ? applied.document : document;
|
|
69
70
|
}
|
|
70
71
|
function bodies(path, before, after) {
|
|
71
72
|
const changes = [];
|
|
@@ -80,7 +81,7 @@ function bodies(path, before, after) {
|
|
|
80
81
|
return changes;
|
|
81
82
|
}
|
|
82
83
|
function relinks(path, moved, before, moves) {
|
|
83
|
-
|
|
84
|
+
const changes = [];
|
|
84
85
|
for (const link of links(before, path)) {
|
|
85
86
|
const destination = moves.get(link.target) ?? link.target;
|
|
86
87
|
if (destination === link.target && moved === path)
|
|
@@ -88,20 +89,23 @@ function relinks(path, moved, before, moves) {
|
|
|
88
89
|
const to = relative(moved, destination);
|
|
89
90
|
if (to === relative(path, link.target))
|
|
90
91
|
continue;
|
|
91
|
-
|
|
92
|
-
if (applied.outcome === 'refuse') {
|
|
93
|
-
return {
|
|
94
|
-
kind: 'refused',
|
|
95
|
-
refusal: {
|
|
96
|
-
code: applied.refusal.rule,
|
|
97
|
-
retryable: false,
|
|
98
|
-
file: path,
|
|
99
|
-
...(applied.refusal.location === undefined ? {} : { location: applied.refusal.location }),
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
after = applied.document;
|
|
92
|
+
changes.push({ kind: 'link', href: link.href, to });
|
|
104
93
|
}
|
|
94
|
+
if (changes.length === 0)
|
|
95
|
+
return { kind: 'changes', changes: [] };
|
|
96
|
+
const applied = apply(before, changes);
|
|
97
|
+
if (applied.outcome === 'refuse') {
|
|
98
|
+
return {
|
|
99
|
+
kind: 'refused',
|
|
100
|
+
refusal: {
|
|
101
|
+
code: applied.refusal.rule,
|
|
102
|
+
retryable: false,
|
|
103
|
+
file: path,
|
|
104
|
+
...(applied.refusal.location === undefined ? {} : { location: applied.refusal.location }),
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const after = applied.document;
|
|
105
109
|
if (after === before)
|
|
106
110
|
return { kind: 'changes', changes: [] };
|
|
107
111
|
if (before.type === undefined) {
|
|
@@ -109,19 +113,14 @@ function relinks(path, moved, before, moves) {
|
|
|
109
113
|
}
|
|
110
114
|
return { kind: 'changes', changes: bodies(path, before, after) };
|
|
111
115
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
114
|
-
const item = merged[index];
|
|
115
|
-
if (item.path !== path)
|
|
116
|
-
continue;
|
|
117
|
-
if (item.kind === 'section' || item.kind === 'preamble')
|
|
118
|
-
merged.splice(index, 1);
|
|
119
|
-
}
|
|
116
|
+
function partKey(change) {
|
|
117
|
+
return change.kind === 'section' ? `section ${change.name}` : change.kind;
|
|
120
118
|
}
|
|
121
|
-
function rewrites(changes, visible) {
|
|
119
|
+
function* rewrites(changes, visible) {
|
|
122
120
|
const moves = new Map();
|
|
123
121
|
const settled = new Set();
|
|
124
|
-
|
|
122
|
+
const parts = new Map();
|
|
123
|
+
for (const [index, change] of changes.entries()) {
|
|
125
124
|
if (change.kind === 'move')
|
|
126
125
|
moves.set(change.path, change.to);
|
|
127
126
|
if (change.kind === 'remove' ||
|
|
@@ -132,6 +131,13 @@ function rewrites(changes, visible) {
|
|
|
132
131
|
}
|
|
133
132
|
if (change.kind === 'field')
|
|
134
133
|
settled.add(`${change.path} ${change.name}`);
|
|
134
|
+
if (isPart(change)) {
|
|
135
|
+
const held = parts.get(change.path);
|
|
136
|
+
if (held === undefined)
|
|
137
|
+
parts.set(change.path, [index]);
|
|
138
|
+
else
|
|
139
|
+
held.push(index);
|
|
140
|
+
}
|
|
135
141
|
}
|
|
136
142
|
if (moves.size === 0)
|
|
137
143
|
return { kind: 'changes', changes };
|
|
@@ -143,40 +149,54 @@ function rewrites(changes, visible) {
|
|
|
143
149
|
const moved = moves.get(path) ?? path;
|
|
144
150
|
const definition = definitionOf(governing(visible.collection.composition, path), document.type);
|
|
145
151
|
added.push(...repointed(document, definition, path, moved, moves, settled));
|
|
146
|
-
const
|
|
152
|
+
const own = parts.get(path) ?? [];
|
|
153
|
+
const relinked = relinks(path, moved, edited(document, own.map((index) => merged[index])), moves);
|
|
147
154
|
if (relinked.kind === 'refused')
|
|
148
155
|
return relinked;
|
|
156
|
+
const keyed = new Map();
|
|
157
|
+
for (const index of own) {
|
|
158
|
+
const key = partKey(merged[index]);
|
|
159
|
+
if (!keyed.has(key))
|
|
160
|
+
keyed.set(key, index);
|
|
161
|
+
}
|
|
149
162
|
for (const change of relinked.changes) {
|
|
150
163
|
if (change.kind === 'replace') {
|
|
151
|
-
|
|
164
|
+
for (const index of own) {
|
|
165
|
+
const kind = merged[index]?.kind;
|
|
166
|
+
if (kind === 'section' || kind === 'preamble')
|
|
167
|
+
merged[index] = null;
|
|
168
|
+
}
|
|
152
169
|
added.push(change);
|
|
153
170
|
continue;
|
|
154
171
|
}
|
|
155
|
-
const index =
|
|
156
|
-
|
|
157
|
-
(change.kind !== 'section' || (item.kind === 'section' && item.name === change.name)));
|
|
158
|
-
if (index === -1)
|
|
172
|
+
const index = keyed.get(partKey(change));
|
|
173
|
+
if (index === undefined)
|
|
159
174
|
added.push(change);
|
|
160
175
|
else
|
|
161
176
|
merged[index] = change;
|
|
162
177
|
}
|
|
178
|
+
yield ROW_WEIGHT + visible.collection.text[path].length;
|
|
163
179
|
}
|
|
164
|
-
return {
|
|
180
|
+
return {
|
|
181
|
+
kind: 'changes',
|
|
182
|
+
changes: [...added, ...merged.filter((change) => change !== null)],
|
|
183
|
+
};
|
|
165
184
|
}
|
|
166
|
-
function anticipated(changes, preconditions, rewritten, visible) {
|
|
167
|
-
const
|
|
185
|
+
function* anticipated(changes, preconditions, rewritten, visible) {
|
|
186
|
+
const given = new Set(changes);
|
|
187
|
+
const derived = rewritten.filter((change) => !given.has(change));
|
|
168
188
|
return {
|
|
169
189
|
changes: rewritten,
|
|
170
|
-
preconditions: [...preconditionsOf(derived, visible, []), ...preconditions],
|
|
190
|
+
preconditions: [...(yield* preconditionsOf(derived, visible, [])), ...preconditions],
|
|
171
191
|
};
|
|
172
192
|
}
|
|
173
|
-
export function providerRewritten(batch, visible) {
|
|
174
|
-
const rewritten = rewrites(batch.changes, visible);
|
|
193
|
+
export function* providerRewritten(batch, visible) {
|
|
194
|
+
const rewritten = yield* rewrites(batch.changes, visible);
|
|
175
195
|
if (rewritten.kind === 'refused')
|
|
176
196
|
return batch;
|
|
177
197
|
return {
|
|
178
198
|
...batch,
|
|
179
|
-
...anticipated(batch.changes, batch.preconditions, rewritten.changes, visible),
|
|
199
|
+
...(yield* anticipated(batch.changes, batch.preconditions, rewritten.changes, visible)),
|
|
180
200
|
};
|
|
181
201
|
}
|
|
182
202
|
function* incoming(collection, removed, candidates) {
|
|
@@ -335,7 +355,7 @@ function sameTarget(precondition, change) {
|
|
|
335
355
|
return ((precondition.kind !== 'field' && precondition.kind !== 'section') ||
|
|
336
356
|
((change.kind === 'field' || change.kind === 'section') && precondition.name === change.name));
|
|
337
357
|
}
|
|
338
|
-
function preconditionsOf(changes, visible, bases) {
|
|
358
|
+
function* preconditionsOf(changes, visible, bases) {
|
|
339
359
|
const preconditions = [];
|
|
340
360
|
const seen = new Set();
|
|
341
361
|
const add = (precondition) => {
|
|
@@ -346,6 +366,7 @@ function preconditionsOf(changes, visible, bases) {
|
|
|
346
366
|
preconditions.push(precondition);
|
|
347
367
|
};
|
|
348
368
|
for (const change of changes) {
|
|
369
|
+
yield ROW_WEIGHT;
|
|
349
370
|
if (change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble') {
|
|
350
371
|
const based = bases.find((base) => sameTarget(base, change));
|
|
351
372
|
if (based !== undefined) {
|
|
@@ -393,7 +414,7 @@ function preconditionsOf(changes, visible, bases) {
|
|
|
393
414
|
function depth(path) {
|
|
394
415
|
return path.split('/').length;
|
|
395
416
|
}
|
|
396
|
-
function
|
|
417
|
+
function* exceeding(limits, changes, effective, resulting) {
|
|
397
418
|
const written = effective.map((change) => (change.kind === 'move' ? change.to : change.path));
|
|
398
419
|
const created = changes
|
|
399
420
|
.filter((change) => change.kind === 'create' || change.kind === 'move' || change.kind === 'binary')
|
|
@@ -410,9 +431,13 @@ function exceeded(limits, changes, effective, resulting) {
|
|
|
410
431
|
return refuse('provider-limit', undefined, limit.name);
|
|
411
432
|
}
|
|
412
433
|
if (limit.name === 'document-size') {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
434
|
+
for (const path of written) {
|
|
435
|
+
const text = resulting.documents[path] ?? '';
|
|
436
|
+
if (new TextEncoder().encode(text).byteLength > value) {
|
|
437
|
+
return refuse('provider-limit', path, limit.name);
|
|
438
|
+
}
|
|
439
|
+
yield ROW_WEIGHT + text.length;
|
|
440
|
+
}
|
|
416
441
|
}
|
|
417
442
|
if (limit.name === 'path-length') {
|
|
418
443
|
const long = created.find((path) => path.length > value);
|
|
@@ -442,7 +467,7 @@ function relativeField(path, name, value, handle, definition) {
|
|
|
442
467
|
!opened.ok ||
|
|
443
468
|
!JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
|
|
444
469
|
return value;
|
|
445
|
-
const held = apply(opened.document, { kind: 'field', name, value, prior: undefined });
|
|
470
|
+
const held = apply(opened.document, [{ kind: 'field', name, value, prior: undefined }]);
|
|
446
471
|
if (held.outcome !== 'applied')
|
|
447
472
|
return value;
|
|
448
473
|
const result = relativize(held.document, path, handle, definition);
|
|
@@ -499,29 +524,44 @@ function isPart(change) {
|
|
|
499
524
|
function touched(change) {
|
|
500
525
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
501
526
|
}
|
|
502
|
-
function
|
|
527
|
+
function partsApplied(content, path, changes) {
|
|
503
528
|
const parsed = parse(content, path);
|
|
504
529
|
if (!parsed.ok)
|
|
505
530
|
return null;
|
|
506
531
|
const document = parsed.document;
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
532
|
+
const parts = new Map();
|
|
533
|
+
for (const change of changes) {
|
|
534
|
+
if (change.kind === 'field')
|
|
535
|
+
parts.set(`field ${change.name}`, {
|
|
536
|
+
kind: 'field',
|
|
537
|
+
name: change.name,
|
|
538
|
+
value: change.value,
|
|
539
|
+
prior: document.fields[change.name],
|
|
540
|
+
});
|
|
541
|
+
else if (change.kind === 'section')
|
|
542
|
+
parts.set(`section ${change.name}`, {
|
|
516
543
|
kind: 'section',
|
|
517
544
|
name: change.name,
|
|
518
545
|
value: change.value,
|
|
519
|
-
prior: document.sections[change.name],
|
|
520
|
-
}
|
|
521
|
-
|
|
546
|
+
prior: document.sections[change.name] ?? '',
|
|
547
|
+
});
|
|
548
|
+
else
|
|
549
|
+
parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
550
|
+
}
|
|
551
|
+
const applied = apply(document, [...parts.values()]);
|
|
522
552
|
return applied.outcome === 'applied' ? serialize(applied.document) : null;
|
|
523
553
|
}
|
|
524
|
-
function
|
|
554
|
+
function settledParts(changes, deferred) {
|
|
555
|
+
for (const [held, parts] of deferred) {
|
|
556
|
+
const content = partsApplied(held.content, held.path, parts);
|
|
557
|
+
if (content === null)
|
|
558
|
+
return held.path;
|
|
559
|
+
changes[changes.indexOf(held)] = { ...held, content };
|
|
560
|
+
}
|
|
561
|
+
deferred.clear();
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
function folded(changes, change, appending, deferred) {
|
|
525
565
|
const held = changes.find((item) => item.path === change.path && (item.kind === 'create' || item.kind === 'replace'));
|
|
526
566
|
const whole = held === undefined ? -1 : changes.indexOf(held);
|
|
527
567
|
const occupied = changes.some((item) => !isPart(item) && item !== held && touched(item).includes(change.path));
|
|
@@ -542,10 +582,11 @@ function folded(changes, change, appending) {
|
|
|
542
582
|
return 'appended';
|
|
543
583
|
}
|
|
544
584
|
if ('content' in held) {
|
|
545
|
-
const
|
|
546
|
-
if (
|
|
547
|
-
|
|
548
|
-
|
|
585
|
+
const parts = deferred.get(held);
|
|
586
|
+
if (parts === undefined)
|
|
587
|
+
deferred.set(held, [change]);
|
|
588
|
+
else
|
|
589
|
+
parts.push(change);
|
|
549
590
|
return 'folded';
|
|
550
591
|
}
|
|
551
592
|
if (change.kind === 'preamble')
|
|
@@ -577,16 +618,20 @@ function folded(changes, change, appending) {
|
|
|
577
618
|
return 'appended';
|
|
578
619
|
}
|
|
579
620
|
function relinked(batch, move, before, after, appending) {
|
|
580
|
-
const derived = rewrites([move], after);
|
|
621
|
+
const derived = finished(rewrites([move], after));
|
|
581
622
|
if (derived.kind === 'refused')
|
|
582
623
|
return derived;
|
|
583
624
|
const changes = [...batch.changes];
|
|
584
625
|
const appended = [];
|
|
585
626
|
let changed = false;
|
|
627
|
+
const deferred = new Map();
|
|
586
628
|
for (const change of derived.changes) {
|
|
587
629
|
if (change === move)
|
|
588
630
|
continue;
|
|
589
|
-
const
|
|
631
|
+
const unsettled = isPart(change) ? null : settledParts(changes, deferred);
|
|
632
|
+
if (unsettled !== null)
|
|
633
|
+
return unqueueable(unsettled);
|
|
634
|
+
const outcome = folded(changes, change, appending, deferred);
|
|
590
635
|
if (outcome === 'refused')
|
|
591
636
|
return unqueueable(change.path);
|
|
592
637
|
if (outcome === 'appended')
|
|
@@ -594,6 +639,9 @@ function relinked(batch, move, before, after, appending) {
|
|
|
594
639
|
if (outcome !== 'skipped')
|
|
595
640
|
changed = true;
|
|
596
641
|
}
|
|
642
|
+
const unsettled = settledParts(changes, deferred);
|
|
643
|
+
if (unsettled !== null)
|
|
644
|
+
return unqueueable(unsettled);
|
|
597
645
|
if (!changed)
|
|
598
646
|
return { kind: 'relinked', batch };
|
|
599
647
|
const held = new Set(batch.preconditions.map(identity));
|
|
@@ -605,7 +653,7 @@ function relinked(batch, move, before, after, appending) {
|
|
|
605
653
|
changes,
|
|
606
654
|
preconditions: [
|
|
607
655
|
...batch.preconditions,
|
|
608
|
-
...preconditionsOf(appended, before, []).filter((precondition) => !held.has(identity(precondition))),
|
|
656
|
+
...finished(preconditionsOf(appended, before, [])).filter((precondition) => !held.has(identity(precondition))),
|
|
609
657
|
],
|
|
610
658
|
}),
|
|
611
659
|
};
|
|
@@ -727,10 +775,17 @@ export function joined(queue, owner, extra) {
|
|
|
727
775
|
if (clash !== undefined)
|
|
728
776
|
return unqueueable(clash);
|
|
729
777
|
const changes = [...owner.changes];
|
|
778
|
+
const deferred = new Map();
|
|
730
779
|
for (const change of extra.changes) {
|
|
731
|
-
|
|
780
|
+
const unsettled = isPart(change) ? null : settledParts(changes, deferred);
|
|
781
|
+
if (unsettled !== null)
|
|
782
|
+
return unqueueable(unsettled);
|
|
783
|
+
if (folded(changes, change, true, deferred) === 'refused')
|
|
732
784
|
return unqueueable(change.path);
|
|
733
785
|
}
|
|
786
|
+
const unsettled = settledParts(changes, deferred);
|
|
787
|
+
if (unsettled !== null)
|
|
788
|
+
return unqueueable(unsettled);
|
|
734
789
|
const held = new Set(owner.preconditions.map(covering));
|
|
735
790
|
const written = new Set(owner.changes.flatMap((change) => change.kind === 'create' || change.kind === 'replace' ? [change.path] : []));
|
|
736
791
|
const preconditions = [
|
|
@@ -751,7 +806,7 @@ export function joined(queue, owner, extra) {
|
|
|
751
806
|
}
|
|
752
807
|
export function limitedIn(queue, batch, limits, state) {
|
|
753
808
|
const at = queue.indexOf(batch);
|
|
754
|
-
const limited =
|
|
809
|
+
const limited = finished(exceeding(limits, batch.changes, finished(providerRewritten(batch, state(queue.slice(0, at)))).changes, state(queue.slice(0, at + 1))));
|
|
755
810
|
return limited?.kind === 'refused' ? limited.refusal : null;
|
|
756
811
|
}
|
|
757
812
|
function* batching(input) {
|
|
@@ -762,15 +817,15 @@ function* batching(input) {
|
|
|
762
817
|
return refuse('model-unavailable', structural.path);
|
|
763
818
|
if (changes.length === 0)
|
|
764
819
|
return refuse('no-change');
|
|
765
|
-
const rewritten = rewrites(changes, input.visible);
|
|
820
|
+
const rewritten = yield* rewrites(changes, input.visible);
|
|
766
821
|
if (rewritten.kind === 'refused')
|
|
767
822
|
return rewritten;
|
|
768
823
|
const refusal = guard(changes, input);
|
|
769
824
|
if (refusal !== null)
|
|
770
825
|
return refusal;
|
|
771
|
-
const preconditions = preconditionsOf(changes, input.visible, input.bases);
|
|
772
|
-
const predicted = anticipated(changes, preconditions, rewritten.changes, input.visible);
|
|
773
|
-
const resulting =
|
|
826
|
+
const preconditions = yield* preconditionsOf(changes, input.visible, input.bases);
|
|
827
|
+
const predicted = yield* anticipated(changes, preconditions, rewritten.changes, input.visible);
|
|
828
|
+
const resulting = yield* overlaying(input.visible, [
|
|
774
829
|
{ id: '', baseRoomVersion: input.baseRoomVersion, ...predicted },
|
|
775
830
|
]);
|
|
776
831
|
const clean = input.clean !== undefined && available(input.composition) ? input.clean : null;
|
|
@@ -790,7 +845,14 @@ function* batching(input) {
|
|
|
790
845
|
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
791
846
|
};
|
|
792
847
|
const touched = [...new Set(predicted.changes.flatMap(affected))];
|
|
793
|
-
const typedPaths =
|
|
848
|
+
const typedPaths = [];
|
|
849
|
+
for (const path of touched) {
|
|
850
|
+
const before = input.visible.documents[path];
|
|
851
|
+
const after = resulting.documents[path];
|
|
852
|
+
if (typed(before) || typed(after))
|
|
853
|
+
typedPaths.push(path);
|
|
854
|
+
yield ROW_WEIGHT + (before?.length ?? 0) + (after?.length ?? 0);
|
|
855
|
+
}
|
|
794
856
|
const needsModel = typedPaths.length > 0;
|
|
795
857
|
const withoutModel = typedPaths.find((path) => governing(input.composition, path).status === 'unavailable');
|
|
796
858
|
if (withoutModel !== undefined)
|
|
@@ -815,7 +877,7 @@ function* batching(input) {
|
|
|
815
877
|
},
|
|
816
878
|
};
|
|
817
879
|
}
|
|
818
|
-
const limited =
|
|
880
|
+
const limited = yield* exceeding(input.providerLimits, changes, predicted.changes, resulting);
|
|
819
881
|
if (limited !== null)
|
|
820
882
|
return limited;
|
|
821
883
|
const validated = typedPaths
|