@agentshouse/mdruntime 0.1.0-c967d1ca66fee → 0.1.0-c969b8dee6cc8
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 +280 -244
- package/README.md +18 -8
- package/dist/acquisition.d.ts +14 -0
- package/dist/acquisition.d.ts.map +1 -0
- package/dist/acquisition.js +24 -0
- package/dist/adapter.d.ts +85 -20
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -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 +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 +33 -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/earlier.d.ts +10 -0
- package/dist/chat/earlier.d.ts.map +1 -0
- package/dist/chat/earlier.js +54 -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 +61 -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 +27 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +99 -0
- package/dist/chat/markdown.d.ts +20 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +188 -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 +22 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +155 -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 +628 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +69 -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 +34 -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 +26 -11
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +27 -4
- package/dist/collection.d.ts +17 -3
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +230 -19
- package/dist/connection.d.ts +43 -13
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1827 -386
- package/dist/conversation.d.ts +29 -9
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +492 -164
- 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 +156 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -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 +18 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +102 -13
- package/dist/identity.d.ts +4 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +12 -0
- package/dist/index.d.ts +15 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/memory.d.ts +11 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +67 -18
- 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 +55 -8
- package/dist/react.d.ts +10 -7
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +7 -17
- package/dist/read-side.d.ts +13 -6
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +428 -94
- 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 +360 -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 +69 -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 +45 -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 +153 -30
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +53 -29
- package/package.json +26 -14
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/save.d.ts
CHANGED
|
@@ -22,7 +22,13 @@ export type SaveInput = {
|
|
|
22
22
|
handle: string;
|
|
23
23
|
changes: readonly Change[];
|
|
24
24
|
bases: readonly Precondition[];
|
|
25
|
+
queued?: ReadonlySet<string>;
|
|
25
26
|
writtenBy?: WrittenBy;
|
|
27
|
+
clean?: {
|
|
28
|
+
text: Readonly<Record<string, string>>;
|
|
29
|
+
binaries: Readonly<Record<string, unknown>>;
|
|
30
|
+
composition: Composition;
|
|
31
|
+
};
|
|
26
32
|
};
|
|
27
33
|
export type BatchResult = {
|
|
28
34
|
kind: 'batch';
|
|
@@ -32,5 +38,28 @@ export type BatchResult = {
|
|
|
32
38
|
refusal: SaveRefusal;
|
|
33
39
|
};
|
|
34
40
|
export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): ChangeBatch;
|
|
41
|
+
export declare function queuedDocuments(queue: readonly ChangeBatch[]): ReadonlySet<string>;
|
|
42
|
+
export type Requeued = {
|
|
43
|
+
kind: 'requeued';
|
|
44
|
+
queue: readonly ChangeBatch[];
|
|
45
|
+
changes: readonly Change[];
|
|
46
|
+
queued: ReadonlySet<string>;
|
|
47
|
+
withdrawn: ReadonlyMap<string, ChangeBatch | null>;
|
|
48
|
+
owners: ReadonlySet<string>;
|
|
49
|
+
} | {
|
|
50
|
+
kind: 'refused';
|
|
51
|
+
refusal: SaveRefusal;
|
|
52
|
+
};
|
|
53
|
+
export type Joining = {
|
|
54
|
+
kind: 'joined';
|
|
55
|
+
batch: ChangeBatch;
|
|
56
|
+
queue: readonly ChangeBatch[];
|
|
57
|
+
} | {
|
|
58
|
+
kind: 'refused';
|
|
59
|
+
refusal: SaveRefusal;
|
|
60
|
+
};
|
|
61
|
+
export declare function requeued(queue: readonly ChangeBatch[], changes: readonly Change[], visible: VisibleLayer, changeable: (batch: ChangeBatch) => boolean, state: (queue: readonly ChangeBatch[]) => VisibleLayer): Requeued;
|
|
62
|
+
export declare function joined(queue: readonly ChangeBatch[], owner: ChangeBatch, extra: ChangeBatch): Joining;
|
|
63
|
+
export declare function limitedIn(queue: readonly ChangeBatch[], batch: ChangeBatch, limits: readonly ProviderLimit[], state: (queue: readonly ChangeBatch[]) => VisibleLayer): SaveRefusal | null;
|
|
35
64
|
export declare function buildBatch(input: SaveInput): BatchResult;
|
|
36
65
|
//# sourceMappingURL=save.d.ts.map
|
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":"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"}
|
package/dist/save.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { definitionOf } from './model.js';
|
|
2
2
|
import { apply, ATTACHMENT, links, parse, pointerSegments, references, relative, relativize, retarget, serialize, target, } from '@agentshouse/mdmodel';
|
|
3
|
-
import { immutable, } from './change.js';
|
|
4
|
-
import { collectionOf, documentsOf, governing, validateCollection, } from './collection.js';
|
|
3
|
+
import { immutable, queuedFile, departure, } from './change.js';
|
|
4
|
+
import { available, changedCleanly, collectionOf, documentsOf, governing, referring, validateCollection, } from './collection.js';
|
|
5
5
|
import { changeBatchIdentity } from './identity.js';
|
|
6
6
|
import { overlay } from './overlay.js';
|
|
7
7
|
import { covered, normalize } from './paths.js';
|
|
@@ -122,7 +122,10 @@ function rewrites(changes, visible) {
|
|
|
122
122
|
for (const change of changes) {
|
|
123
123
|
if (change.kind === 'move')
|
|
124
124
|
moves.set(change.path, change.to);
|
|
125
|
-
if (change.kind === 'remove' ||
|
|
125
|
+
if (change.kind === 'remove' ||
|
|
126
|
+
change.kind === 'replace' ||
|
|
127
|
+
change.kind === 'create' ||
|
|
128
|
+
change.kind === 'binary') {
|
|
126
129
|
settled.add(change.path);
|
|
127
130
|
}
|
|
128
131
|
if (change.kind === 'field')
|
|
@@ -174,7 +177,7 @@ export function providerRewritten(batch, visible) {
|
|
|
174
177
|
...anticipated(batch.changes, batch.preconditions, rewritten.changes, visible),
|
|
175
178
|
};
|
|
176
179
|
}
|
|
177
|
-
function incoming(collection, removed) {
|
|
180
|
+
function incoming(collection, removed, candidates) {
|
|
178
181
|
const found = new Map();
|
|
179
182
|
const note = (target, file) => {
|
|
180
183
|
if (!removed.has(target))
|
|
@@ -183,7 +186,13 @@ function incoming(collection, removed) {
|
|
|
183
186
|
referrers.add(file);
|
|
184
187
|
found.set(target, referrers);
|
|
185
188
|
};
|
|
186
|
-
|
|
189
|
+
const read = candidates === null
|
|
190
|
+
? documentsOf(collection)
|
|
191
|
+
: [...new Set(candidates)].sort().flatMap((path) => {
|
|
192
|
+
const document = collection.document(path);
|
|
193
|
+
return document === undefined ? [] : [[path, document]];
|
|
194
|
+
});
|
|
195
|
+
for (const [path, document] of read) {
|
|
187
196
|
const definition = definitionOf(governing(collection.composition, path), document.type);
|
|
188
197
|
for (const { value, to } of definition === undefined ? [] : references(document, definition)) {
|
|
189
198
|
if (to.includes(ATTACHMENT))
|
|
@@ -214,11 +223,14 @@ function affected(change) {
|
|
|
214
223
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
215
224
|
}
|
|
216
225
|
function guard(changes, input) {
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
226
|
+
const overridden = new Map();
|
|
227
|
+
const existing = {
|
|
228
|
+
has: (path) => overridden.get(path) ??
|
|
229
|
+
(Object.hasOwn(input.visible.documents, path) || Object.hasOwn(input.visible.binaries, path)),
|
|
230
|
+
add: (path) => void overridden.set(path, true),
|
|
231
|
+
delete: (path) => void overridden.set(path, false),
|
|
232
|
+
};
|
|
233
|
+
for (const [index, change] of changes.entries()) {
|
|
222
234
|
for (const path of affected(change)) {
|
|
223
235
|
const normalized = normalize(path);
|
|
224
236
|
if (normalized === null || normalized === '')
|
|
@@ -236,12 +248,26 @@ function guard(changes, input) {
|
|
|
236
248
|
existing.add(change.path);
|
|
237
249
|
continue;
|
|
238
250
|
}
|
|
251
|
+
if (change.kind === 'binary') {
|
|
252
|
+
if (input.visible.documents[change.path] !== undefined ||
|
|
253
|
+
(existing.has(change.path) &&
|
|
254
|
+
input.bases.some((base) => base.kind === 'absent' && base.path === change.path))) {
|
|
255
|
+
return refuse('path-collision', change.path);
|
|
256
|
+
}
|
|
257
|
+
if (!input.local &&
|
|
258
|
+
existing.has(change.path) &&
|
|
259
|
+
input.visible.revisions[departure(changes, index)] === undefined) {
|
|
260
|
+
return refuse('unknown-revision', change.path);
|
|
261
|
+
}
|
|
262
|
+
existing.add(change.path);
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
239
265
|
if (change.kind === 'move') {
|
|
240
266
|
if (!existing.has(change.path))
|
|
241
267
|
return refuse('path-absent', change.path);
|
|
242
268
|
if (existing.has(change.to))
|
|
243
269
|
return refuse('path-collision', change.to);
|
|
244
|
-
if (
|
|
270
|
+
if (unrevised(input, change.path)) {
|
|
245
271
|
return refuse('unknown-revision', change.path);
|
|
246
272
|
}
|
|
247
273
|
existing.delete(change.path);
|
|
@@ -251,14 +277,14 @@ function guard(changes, input) {
|
|
|
251
277
|
if (!existing.has(change.path))
|
|
252
278
|
return refuse('path-absent', change.path);
|
|
253
279
|
if (change.kind === 'remove') {
|
|
254
|
-
if (
|
|
280
|
+
if (unrevised(input, change.path)) {
|
|
255
281
|
return refuse('unknown-revision', change.path);
|
|
256
282
|
}
|
|
257
283
|
existing.delete(change.path);
|
|
258
284
|
continue;
|
|
259
285
|
}
|
|
260
286
|
if (change.kind === 'replace') {
|
|
261
|
-
if (
|
|
287
|
+
if (unrevised(input, change.path)) {
|
|
262
288
|
return refuse('unknown-revision', change.path);
|
|
263
289
|
}
|
|
264
290
|
continue;
|
|
@@ -269,8 +295,28 @@ function guard(changes, input) {
|
|
|
269
295
|
}
|
|
270
296
|
return null;
|
|
271
297
|
}
|
|
272
|
-
function
|
|
273
|
-
return visible.revisions[path] === undefined
|
|
298
|
+
function unrevised(input, path) {
|
|
299
|
+
return (!input.local && input.queued?.has(path) !== true && input.visible.revisions[path] === undefined);
|
|
300
|
+
}
|
|
301
|
+
export function queuedDocuments(queue) {
|
|
302
|
+
const paths = new Set();
|
|
303
|
+
for (const batch of queue) {
|
|
304
|
+
for (const change of batch.changes) {
|
|
305
|
+
if (change.kind === 'binary')
|
|
306
|
+
continue;
|
|
307
|
+
if (change.kind === 'remove')
|
|
308
|
+
paths.delete(change.path);
|
|
309
|
+
else if (change.kind !== 'move')
|
|
310
|
+
paths.add(change.path);
|
|
311
|
+
else if (paths.delete(change.path))
|
|
312
|
+
paths.add(change.to);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return paths;
|
|
316
|
+
}
|
|
317
|
+
function identity(precondition) {
|
|
318
|
+
const part = precondition.kind === 'field' || precondition.kind === 'section' ? precondition.name : '';
|
|
319
|
+
return `${precondition.kind} ${precondition.path} ${part}`;
|
|
274
320
|
}
|
|
275
321
|
function existence(visible, path) {
|
|
276
322
|
const revision = visible.revisions[path];
|
|
@@ -289,11 +335,10 @@ function preconditionsOf(changes, visible, bases) {
|
|
|
289
335
|
const preconditions = [];
|
|
290
336
|
const seen = new Set();
|
|
291
337
|
const add = (precondition) => {
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
if (seen.has(identity))
|
|
338
|
+
const held = identity(precondition);
|
|
339
|
+
if (seen.has(held))
|
|
295
340
|
return;
|
|
296
|
-
seen.add(
|
|
341
|
+
seen.add(held);
|
|
297
342
|
preconditions.push(precondition);
|
|
298
343
|
};
|
|
299
344
|
for (const change of changes) {
|
|
@@ -328,6 +373,13 @@ function preconditionsOf(changes, visible, bases) {
|
|
|
328
373
|
add({ kind: 'absent', path: change.path });
|
|
329
374
|
continue;
|
|
330
375
|
}
|
|
376
|
+
if (change.kind === 'binary') {
|
|
377
|
+
const revision = visible.revisions[change.path];
|
|
378
|
+
add(visible.binaries[change.path] === undefined || revision === undefined
|
|
379
|
+
? { kind: 'absent', path: change.path }
|
|
380
|
+
: { kind: 'revision', path: change.path, revision });
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
331
383
|
add(existence(visible, change.path));
|
|
332
384
|
if (change.kind === 'move')
|
|
333
385
|
add({ kind: 'absent', path: change.to });
|
|
@@ -337,10 +389,10 @@ function preconditionsOf(changes, visible, bases) {
|
|
|
337
389
|
function depth(path) {
|
|
338
390
|
return path.split('/').length;
|
|
339
391
|
}
|
|
340
|
-
function exceeded(limits, changes, resulting) {
|
|
341
|
-
const written =
|
|
392
|
+
function exceeded(limits, changes, effective, resulting) {
|
|
393
|
+
const written = effective.map((change) => (change.kind === 'move' ? change.to : change.path));
|
|
342
394
|
const created = changes
|
|
343
|
-
.filter((change) => change.kind === 'create' || change.kind === 'move')
|
|
395
|
+
.filter((change) => change.kind === 'create' || change.kind === 'move' || change.kind === 'binary')
|
|
344
396
|
.map((change) => (change.kind === 'move' ? change.to : change.path));
|
|
345
397
|
for (const limit of limits) {
|
|
346
398
|
const value = limit.value;
|
|
@@ -354,7 +406,7 @@ function exceeded(limits, changes, resulting) {
|
|
|
354
406
|
return refuse('provider-limit', undefined, limit.name);
|
|
355
407
|
}
|
|
356
408
|
if (limit.name === 'document-size') {
|
|
357
|
-
const large = written.find((path) => (resulting.documents[path] ?? '').
|
|
409
|
+
const large = written.find((path) => new TextEncoder().encode(resulting.documents[path] ?? '').byteLength > value);
|
|
358
410
|
if (large !== undefined)
|
|
359
411
|
return refuse('provider-limit', large, limit.name);
|
|
360
412
|
}
|
|
@@ -423,6 +475,8 @@ function relativeChanges(input) {
|
|
|
423
475
|
});
|
|
424
476
|
}
|
|
425
477
|
function unmodeledType(collection, composition) {
|
|
478
|
+
if (available(composition))
|
|
479
|
+
return false;
|
|
426
480
|
for (const [path, document] of documentsOf(collection)) {
|
|
427
481
|
if (document.type !== undefined &&
|
|
428
482
|
document.type !== 'any' &&
|
|
@@ -431,6 +485,270 @@ function unmodeledType(collection, composition) {
|
|
|
431
485
|
}
|
|
432
486
|
return false;
|
|
433
487
|
}
|
|
488
|
+
function unqueueable(file) {
|
|
489
|
+
return { kind: 'refused', refusal: { code: 'unknown-revision', retryable: false, file } };
|
|
490
|
+
}
|
|
491
|
+
function isPart(change) {
|
|
492
|
+
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
493
|
+
}
|
|
494
|
+
function touched(change) {
|
|
495
|
+
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
496
|
+
}
|
|
497
|
+
function partApplied(content, path, change) {
|
|
498
|
+
const parsed = parse(content, path);
|
|
499
|
+
if (!parsed.ok)
|
|
500
|
+
return null;
|
|
501
|
+
const document = parsed.document;
|
|
502
|
+
const applied = apply(document, change.kind === 'field'
|
|
503
|
+
? {
|
|
504
|
+
kind: 'field',
|
|
505
|
+
name: change.name,
|
|
506
|
+
value: change.value,
|
|
507
|
+
prior: document.fields[change.name],
|
|
508
|
+
}
|
|
509
|
+
: change.kind === 'section'
|
|
510
|
+
? {
|
|
511
|
+
kind: 'section',
|
|
512
|
+
name: change.name,
|
|
513
|
+
value: change.value,
|
|
514
|
+
prior: document.sections[change.name],
|
|
515
|
+
}
|
|
516
|
+
: { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
517
|
+
return applied.outcome === 'applied' ? serialize(applied.document) : null;
|
|
518
|
+
}
|
|
519
|
+
function folded(changes, change, appending) {
|
|
520
|
+
const held = changes.find((item) => item.path === change.path && (item.kind === 'create' || item.kind === 'replace'));
|
|
521
|
+
const whole = held === undefined ? -1 : changes.indexOf(held);
|
|
522
|
+
const occupied = changes.some((item) => !isPart(item) && item !== held && touched(item).includes(change.path));
|
|
523
|
+
if (isPart(change)) {
|
|
524
|
+
const same = changes.findIndex((item) => item.kind === change.kind &&
|
|
525
|
+
item.path === change.path &&
|
|
526
|
+
(change.kind === 'preamble' || ('name' in item && item.name === change.name)));
|
|
527
|
+
if (same !== -1) {
|
|
528
|
+
changes[same] = change;
|
|
529
|
+
return 'folded';
|
|
530
|
+
}
|
|
531
|
+
if (held === undefined) {
|
|
532
|
+
if (!appending)
|
|
533
|
+
return 'skipped';
|
|
534
|
+
if (occupied)
|
|
535
|
+
return 'refused';
|
|
536
|
+
changes.push(change);
|
|
537
|
+
return 'appended';
|
|
538
|
+
}
|
|
539
|
+
if ('content' in held) {
|
|
540
|
+
const content = partApplied(held.content, held.path, change);
|
|
541
|
+
if (content === null)
|
|
542
|
+
return 'refused';
|
|
543
|
+
changes[whole] = { ...held, content };
|
|
544
|
+
return 'folded';
|
|
545
|
+
}
|
|
546
|
+
if (change.kind === 'preamble')
|
|
547
|
+
return 'refused';
|
|
548
|
+
changes[whole] =
|
|
549
|
+
change.kind === 'field'
|
|
550
|
+
? { ...held, fields: { ...held.fields, [change.name]: change.value } }
|
|
551
|
+
: { ...held, sections: { ...held.sections, [change.name]: change.value } };
|
|
552
|
+
return 'folded';
|
|
553
|
+
}
|
|
554
|
+
if (change.kind === 'replace') {
|
|
555
|
+
if (held !== undefined) {
|
|
556
|
+
if (!('content' in held))
|
|
557
|
+
return 'refused';
|
|
558
|
+
changes[whole] = { ...held, content: change.content };
|
|
559
|
+
return 'folded';
|
|
560
|
+
}
|
|
561
|
+
const parts = changes.filter((item) => isPart(item) && item.path === change.path);
|
|
562
|
+
if (parts.length === 0 && !appending)
|
|
563
|
+
return 'skipped';
|
|
564
|
+
if (occupied)
|
|
565
|
+
return 'refused';
|
|
566
|
+
changes.splice(0, changes.length, ...changes.filter((item) => !parts.includes(item)), change);
|
|
567
|
+
return 'appended';
|
|
568
|
+
}
|
|
569
|
+
if (changes.some((item) => touched(change).some((path) => touched(item).includes(path))))
|
|
570
|
+
return 'refused';
|
|
571
|
+
changes.push(change);
|
|
572
|
+
return 'appended';
|
|
573
|
+
}
|
|
574
|
+
function relinked(batch, move, before, after, appending) {
|
|
575
|
+
const derived = rewrites([move], after);
|
|
576
|
+
if (derived.kind === 'refused')
|
|
577
|
+
return derived;
|
|
578
|
+
const changes = [...batch.changes];
|
|
579
|
+
const appended = [];
|
|
580
|
+
let changed = false;
|
|
581
|
+
for (const change of derived.changes) {
|
|
582
|
+
if (change === move)
|
|
583
|
+
continue;
|
|
584
|
+
const outcome = folded(changes, change, appending);
|
|
585
|
+
if (outcome === 'refused')
|
|
586
|
+
return unqueueable(change.path);
|
|
587
|
+
if (outcome === 'appended')
|
|
588
|
+
appended.push(change);
|
|
589
|
+
if (outcome !== 'skipped')
|
|
590
|
+
changed = true;
|
|
591
|
+
}
|
|
592
|
+
if (!changed)
|
|
593
|
+
return { kind: 'relinked', batch };
|
|
594
|
+
const held = new Set(batch.preconditions.map(identity));
|
|
595
|
+
return {
|
|
596
|
+
kind: 'relinked',
|
|
597
|
+
batch: immutable({
|
|
598
|
+
...batch,
|
|
599
|
+
id: changeBatchIdentity(),
|
|
600
|
+
changes,
|
|
601
|
+
preconditions: [
|
|
602
|
+
...batch.preconditions,
|
|
603
|
+
...preconditionsOf(appended, before, []).filter((precondition) => !held.has(identity(precondition))),
|
|
604
|
+
],
|
|
605
|
+
}),
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function leading(changes, at) {
|
|
609
|
+
const from = departure(changes, at);
|
|
610
|
+
return new Set(changes.filter((change, index) => index < at && change.kind === 'move' && departure(changes, index) === from));
|
|
611
|
+
}
|
|
612
|
+
function created(batch, at) {
|
|
613
|
+
const file = batch.changes[at];
|
|
614
|
+
return (leading(batch.changes, at).size === 0 &&
|
|
615
|
+
batch.preconditions.some((precondition) => precondition.kind === 'absent' && precondition.path === file.path));
|
|
616
|
+
}
|
|
617
|
+
function withdrawnFile(batch, change, at) {
|
|
618
|
+
const file = batch.changes[at];
|
|
619
|
+
const from = departure(batch.changes, at);
|
|
620
|
+
const moves = leading(batch.changes, at);
|
|
621
|
+
const fresh = created(batch, at);
|
|
622
|
+
const vacated = new Set([...moves].map((move) => move.to));
|
|
623
|
+
if (fresh)
|
|
624
|
+
vacated.add(file.path);
|
|
625
|
+
const replaced = fresh
|
|
626
|
+
? change.kind === 'remove'
|
|
627
|
+
? []
|
|
628
|
+
: [{ ...file, path: change.to }]
|
|
629
|
+
: change.kind === 'remove'
|
|
630
|
+
? [{ kind: 'remove', path: from }]
|
|
631
|
+
: change.to === from
|
|
632
|
+
? [{ ...file, path: from }]
|
|
633
|
+
: [
|
|
634
|
+
{ kind: 'move', path: from, to: change.to },
|
|
635
|
+
{ ...file, path: change.to },
|
|
636
|
+
];
|
|
637
|
+
const added = change.kind === 'move' && (fresh || change.to !== from)
|
|
638
|
+
? [{ kind: 'absent', path: change.to }]
|
|
639
|
+
: [];
|
|
640
|
+
const changes = batch.changes.flatMap((item) => item === file ? replaced : item.kind === 'move' && moves.has(item) ? [] : [item]);
|
|
641
|
+
if (changes.length === 0)
|
|
642
|
+
return null;
|
|
643
|
+
const preconditions = [
|
|
644
|
+
...added,
|
|
645
|
+
...batch.preconditions.filter((precondition) => precondition.kind !== 'absent' || !vacated.has(precondition.path)),
|
|
646
|
+
];
|
|
647
|
+
return immutable({ ...batch, id: changeBatchIdentity(), changes, preconditions });
|
|
648
|
+
}
|
|
649
|
+
export function requeued(queue, changes, visible, changeable, state) {
|
|
650
|
+
const next = [...queue];
|
|
651
|
+
const origins = new Map();
|
|
652
|
+
const withdrawn = new Map();
|
|
653
|
+
const owners = new Set();
|
|
654
|
+
const queued = new Set();
|
|
655
|
+
const kept = [];
|
|
656
|
+
const originOf = (batch) => origins.get(batch) ?? batch.id;
|
|
657
|
+
const open = (batch) => origins.has(batch) || changeable(batch);
|
|
658
|
+
for (const change of changes) {
|
|
659
|
+
const held = visible.binaries[change.path];
|
|
660
|
+
if ((change.kind !== 'move' && change.kind !== 'remove') || held?.state !== 'pending') {
|
|
661
|
+
kept.push(change);
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
let index = next.length - 1;
|
|
665
|
+
while (index >= 0 && queuedFile(next[index], change.path, held.localId) === -1)
|
|
666
|
+
index -= 1;
|
|
667
|
+
const owner = next[index];
|
|
668
|
+
if (owner === undefined || !open(owner))
|
|
669
|
+
return unqueueable(change.path);
|
|
670
|
+
const following = next.slice(index);
|
|
671
|
+
const rebuilt = [];
|
|
672
|
+
let before = change.kind === 'move' ? state(next.slice(0, index)) : visible;
|
|
673
|
+
for (const [offset, batch] of following.entries()) {
|
|
674
|
+
let current = batch;
|
|
675
|
+
if (change.kind === 'move') {
|
|
676
|
+
const after = state(next.slice(0, index + offset + 1));
|
|
677
|
+
const appending = offset === 0 && created(batch, queuedFile(batch, change.path, held.localId));
|
|
678
|
+
const relinking = relinked(batch, change, before, after, appending);
|
|
679
|
+
if (relinking.kind === 'refused')
|
|
680
|
+
return relinking;
|
|
681
|
+
current = relinking.batch;
|
|
682
|
+
before = after;
|
|
683
|
+
}
|
|
684
|
+
if (current !== batch && !open(batch))
|
|
685
|
+
return unqueueable(change.path);
|
|
686
|
+
rebuilt.push(offset === 0
|
|
687
|
+
? withdrawnFile(current, change, queuedFile(current, change.path, held.localId))
|
|
688
|
+
: current);
|
|
689
|
+
}
|
|
690
|
+
for (const [offset, batch] of following.entries()) {
|
|
691
|
+
const replaced = rebuilt[offset];
|
|
692
|
+
if (replaced === batch)
|
|
693
|
+
continue;
|
|
694
|
+
const origin = originOf(batch);
|
|
695
|
+
withdrawn.set(origin, replaced);
|
|
696
|
+
if (replaced !== null)
|
|
697
|
+
origins.set(replaced, origin);
|
|
698
|
+
}
|
|
699
|
+
owners.add(originOf(owner));
|
|
700
|
+
next.splice(index, following.length, ...rebuilt.filter((batch) => batch !== null));
|
|
701
|
+
queued.add(change.path);
|
|
702
|
+
}
|
|
703
|
+
return {
|
|
704
|
+
kind: 'requeued',
|
|
705
|
+
queue: withdrawn.size === 0 ? queue : next,
|
|
706
|
+
changes: kept,
|
|
707
|
+
queued,
|
|
708
|
+
withdrawn,
|
|
709
|
+
owners,
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
function covering(precondition) {
|
|
713
|
+
return precondition.kind === 'field' ||
|
|
714
|
+
precondition.kind === 'section' ||
|
|
715
|
+
precondition.kind === 'preamble'
|
|
716
|
+
? identity(precondition)
|
|
717
|
+
: `path ${precondition.path}`;
|
|
718
|
+
}
|
|
719
|
+
export function joined(queue, owner, extra) {
|
|
720
|
+
const later = new Set(queue.slice(queue.indexOf(owner) + 1).flatMap((batch) => batch.changes.flatMap(touched)));
|
|
721
|
+
const clash = extra.changes.flatMap(touched).find((path) => later.has(path));
|
|
722
|
+
if (clash !== undefined)
|
|
723
|
+
return unqueueable(clash);
|
|
724
|
+
const changes = [...owner.changes];
|
|
725
|
+
for (const change of extra.changes) {
|
|
726
|
+
if (folded(changes, change, true) === 'refused')
|
|
727
|
+
return unqueueable(change.path);
|
|
728
|
+
}
|
|
729
|
+
const held = new Set(owner.preconditions.map(covering));
|
|
730
|
+
const written = new Set(owner.changes.flatMap((change) => change.kind === 'create' || change.kind === 'replace' ? [change.path] : []));
|
|
731
|
+
const preconditions = [
|
|
732
|
+
...owner.preconditions,
|
|
733
|
+
...extra.preconditions.filter((precondition) => {
|
|
734
|
+
const key = covering(precondition);
|
|
735
|
+
return (!held.has(key) && (key === `path ${precondition.path}` || !written.has(precondition.path)));
|
|
736
|
+
}),
|
|
737
|
+
];
|
|
738
|
+
const batch = immutable({
|
|
739
|
+
...owner,
|
|
740
|
+
...(extra.validation === undefined ? {} : { validation: extra.validation }),
|
|
741
|
+
id: changeBatchIdentity(),
|
|
742
|
+
changes,
|
|
743
|
+
preconditions,
|
|
744
|
+
});
|
|
745
|
+
return { kind: 'joined', batch, queue: queue.map((item) => (item === owner ? batch : item)) };
|
|
746
|
+
}
|
|
747
|
+
export function limitedIn(queue, batch, limits, state) {
|
|
748
|
+
const at = queue.indexOf(batch);
|
|
749
|
+
const limited = exceeded(limits, batch.changes, providerRewritten(batch, state(queue.slice(0, at))).changes, state(queue.slice(0, at + 1)));
|
|
750
|
+
return limited?.kind === 'refused' ? limited.refusal : null;
|
|
751
|
+
}
|
|
434
752
|
export function buildBatch(input) {
|
|
435
753
|
const changes = relativeChanges(input);
|
|
436
754
|
const structural = changes.find((change) => change.kind === 'move' || change.kind === 'remove');
|
|
@@ -449,9 +767,16 @@ export function buildBatch(input) {
|
|
|
449
767
|
const resulting = overlay(input.visible, [
|
|
450
768
|
{ id: '', baseRoomVersion: input.baseRoomVersion, ...predicted },
|
|
451
769
|
]);
|
|
770
|
+
const clean = input.clean !== undefined &&
|
|
771
|
+
input.clean.text === input.visible.documents &&
|
|
772
|
+
input.clean.binaries === input.visible.binaries &&
|
|
773
|
+
available(input.composition)
|
|
774
|
+
? input.clean
|
|
775
|
+
: null;
|
|
452
776
|
const removed = new Set(changes.filter((change) => change.kind === 'remove').map((change) => change.path));
|
|
453
777
|
if (removed.size > 0) {
|
|
454
|
-
const
|
|
778
|
+
const referrers = clean === null ? null : referring(clean, input.composition, removed);
|
|
779
|
+
const referenced = incoming(collectionOf(resulting.documents, input.composition), removed, referrers === null ? null : [...referrers, ...predicted.changes.flatMap(affected)]);
|
|
455
780
|
if (referenced !== null)
|
|
456
781
|
return referenced;
|
|
457
782
|
}
|
|
@@ -461,15 +786,20 @@ export function buildBatch(input) {
|
|
|
461
786
|
const parsed = parse(content);
|
|
462
787
|
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
463
788
|
};
|
|
464
|
-
const
|
|
789
|
+
const touched = [...new Set(predicted.changes.flatMap(affected))];
|
|
790
|
+
const typedPaths = touched.filter((path) => typed(input.visible.documents[path]) || typed(resulting.documents[path]));
|
|
465
791
|
const needsModel = typedPaths.length > 0;
|
|
466
792
|
const withoutModel = typedPaths.find((path) => governing(input.composition, path).status === 'unavailable');
|
|
467
793
|
if (withoutModel !== undefined)
|
|
468
794
|
return refuse('model-unavailable', withoutModel);
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
795
|
+
const verdict = clean !== null &&
|
|
796
|
+
changedCleanly({ text: resulting.documents, binaries: resulting.binaries }, clean, input.composition)
|
|
797
|
+
? { verdict: 'accept' }
|
|
798
|
+
: validateCollection(needsModel
|
|
799
|
+
? resulting.documents
|
|
800
|
+
: Object.fromEntries(touched.flatMap((path) => resulting.documents[path] === undefined
|
|
801
|
+
? []
|
|
802
|
+
: [[path, resulting.documents[path]]])), Object.keys(resulting.binaries), input.composition);
|
|
473
803
|
if (verdict.verdict === 'refuse') {
|
|
474
804
|
return {
|
|
475
805
|
kind: 'refused',
|
|
@@ -482,7 +812,7 @@ export function buildBatch(input) {
|
|
|
482
812
|
},
|
|
483
813
|
};
|
|
484
814
|
}
|
|
485
|
-
const limited = exceeded(input.providerLimits, changes, resulting);
|
|
815
|
+
const limited = exceeded(input.providerLimits, changes, predicted.changes, resulting);
|
|
486
816
|
if (limited !== null)
|
|
487
817
|
return limited;
|
|
488
818
|
const validated = typedPaths
|
package/dist/search.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import type { ProviderRefusal } from './adapter.js';
|
|
1
2
|
import type { ChangeSet } from './change-set.js';
|
|
2
|
-
import { type Filter } from './query.js';
|
|
3
|
+
import { type CoveredRoom, type Filter, type PendingRoom } from './query.js';
|
|
3
4
|
import type { Open } from './open.js';
|
|
4
5
|
export type DocumentPart = Open<'fields' | 'sections' | 'preamble' | 'path'>;
|
|
5
6
|
export type SearchRequest = {
|
|
6
7
|
text: string;
|
|
7
8
|
documents?: Filter;
|
|
9
|
+
collection?: true;
|
|
8
10
|
conversations?: readonly string[];
|
|
9
11
|
limit?: number;
|
|
12
|
+
after?: string;
|
|
13
|
+
total?: true;
|
|
10
14
|
};
|
|
11
15
|
export type DocumentHit = {
|
|
12
16
|
room: string;
|
|
@@ -21,10 +25,38 @@ export type MessageHit = {
|
|
|
21
25
|
score: number;
|
|
22
26
|
matches: Readonly<Record<string, readonly Open<'text'>[]>>;
|
|
23
27
|
};
|
|
24
|
-
export type
|
|
28
|
+
export type SearchCoverage = {
|
|
29
|
+
rooms: readonly CoveredRoom[];
|
|
30
|
+
conversations: readonly string[];
|
|
31
|
+
index: string;
|
|
32
|
+
overlay: readonly string[];
|
|
33
|
+
};
|
|
34
|
+
export type PendingConversation = {
|
|
35
|
+
conversation: string;
|
|
36
|
+
awaits: Open<'index'>;
|
|
37
|
+
};
|
|
38
|
+
export type SearchHits = {
|
|
25
39
|
documents: readonly DocumentHit[];
|
|
26
40
|
messages: readonly MessageHit[];
|
|
27
41
|
};
|
|
42
|
+
export type SearchWindow = SearchHits & {
|
|
43
|
+
next?: string;
|
|
44
|
+
total?: {
|
|
45
|
+
documents: number;
|
|
46
|
+
messages: number;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export type SearchPending = SearchHits & {
|
|
50
|
+
pending: readonly (PendingRoom | PendingConversation)[];
|
|
51
|
+
coverage: SearchCoverage;
|
|
52
|
+
};
|
|
53
|
+
export type SearchUndeclared = ProviderRefusal & {
|
|
54
|
+
kind: 'undeclared';
|
|
55
|
+
};
|
|
56
|
+
export type SearchResult = (SearchWindow & {
|
|
57
|
+
coverage: SearchCoverage;
|
|
58
|
+
}) | SearchPending | SearchUndeclared;
|
|
59
|
+
export declare function undeclaredSearch(): SearchUndeclared;
|
|
28
60
|
export type SearchedDocument = {
|
|
29
61
|
room: string;
|
|
30
62
|
path: string;
|
|
@@ -39,24 +71,35 @@ export type SearchedMessage = {
|
|
|
39
71
|
text: string;
|
|
40
72
|
};
|
|
41
73
|
export type SearchSource = {
|
|
42
|
-
|
|
74
|
+
room(room: string): readonly string[];
|
|
43
75
|
document(room: string, path: string): SearchedDocument | null;
|
|
44
|
-
messages(): readonly SearchedMessage[];
|
|
45
|
-
message(conversation: string, identity: string): SearchedMessage | null;
|
|
46
76
|
};
|
|
77
|
+
type HitCursor = readonly [number, string, string] | readonly [] | null;
|
|
47
78
|
export type SearchPlan = {
|
|
48
79
|
text: string;
|
|
49
80
|
documents: unknown;
|
|
81
|
+
collection: boolean;
|
|
50
82
|
conversations: readonly string[] | null;
|
|
51
83
|
limit: number | null;
|
|
84
|
+
after: readonly [HitCursor, HitCursor] | null;
|
|
85
|
+
total: boolean;
|
|
52
86
|
};
|
|
53
87
|
export type SearchIndex = {
|
|
88
|
+
generation(): string;
|
|
89
|
+
rooms(): ReadonlySet<string>;
|
|
90
|
+
conversations(): ReadonlySet<string>;
|
|
91
|
+
indexRoom(room: string): Promise<void>;
|
|
92
|
+
indexMessages(conversation: string, messages: readonly SearchedMessage[], whole: boolean): void;
|
|
93
|
+
forget(rooms: readonly string[]): void;
|
|
54
94
|
changed(set: ChangeSet): void;
|
|
95
|
+
changes(): number;
|
|
96
|
+
caughtUp(): Promise<void>;
|
|
55
97
|
search(plan: SearchPlan, documents: readonly {
|
|
56
98
|
room: string;
|
|
57
99
|
path: string;
|
|
58
|
-
}[] | null):
|
|
100
|
+
}[] | null, conversations: readonly string[], rooms: ReadonlySet<string> | null, selections: ReadonlyMap<string, readonly string[]> | null): SearchWindow;
|
|
59
101
|
};
|
|
60
102
|
export declare function searchPlanOf(input: unknown): SearchPlan;
|
|
61
103
|
export declare function createSearchIndex(source: SearchSource): SearchIndex;
|
|
104
|
+
export {};
|
|
62
105
|
//# sourceMappingURL=search.d.ts.map
|