@agentshouse/mdruntime 0.1.0-c56daf494ecb4 → 0.1.0-c5d09b1c896fb
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 +261 -261
- 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 +37 -9
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +2 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +26 -4
- package/dist/change-set.d.ts +2 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +36 -10
- 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/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 +2 -1
- package/dist/chat/list.d.ts.map +1 -1
- package/dist/chat/list.js +4 -3
- 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 +51 -67
- package/dist/chat/ready.d.ts +1 -0
- package/dist/chat/ready.d.ts.map +1 -1
- package/dist/chat/ready.js +2 -2
- package/dist/client.d.ts +12 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -1
- 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 +22 -7
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1253 -309
- package/dist/conversation.d.ts +14 -7
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +328 -137
- package/dist/durability.d.ts +7 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +3 -3
- 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 +13 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +49 -7
- package/dist/identity.d.ts +2 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +6 -0
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/memory.d.ts +4 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +23 -2
- 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 +5 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +22 -11
- package/dist/outcome.d.ts +4 -0
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +1 -0
- package/dist/overlay.d.ts +2 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +58 -55
- package/dist/query.d.ts +32 -3
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -1
- package/dist/reach.d.ts +6 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +17 -5
- package/dist/react.d.ts +7 -4
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +6 -4
- package/dist/read-side.d.ts +13 -6
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +285 -83
- package/dist/readiness.d.ts +53 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +33 -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.map +1 -1
- package/dist/refresh.js +17 -10
- package/dist/replica.d.ts +1 -1
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +57 -20
- package/dist/room-draft.d.ts +13 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +2 -2
- package/dist/rows.d.ts +5 -13
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +5 -13
- package/dist/save.d.ts +5 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +36 -13
- package/dist/search.d.ts +34 -6
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +116 -45
- 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 +42 -11
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +276 -83
- package/dist/turn.d.ts +7 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +45 -0
- package/dist/wire.d.ts +136 -32
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +48 -31
- package/package.json +2 -2
package/dist/rows.js
CHANGED
|
@@ -71,9 +71,8 @@ function directoriesOf(path) {
|
|
|
71
71
|
export function markdownPath(path) {
|
|
72
72
|
return path.endsWith('.md');
|
|
73
73
|
}
|
|
74
|
-
export function rowsOf(room, path, document, composition, change, binary) {
|
|
74
|
+
export function rowsOf(room, path, document, composition, change, fileId, binary) {
|
|
75
75
|
const key = documentKey(room, path);
|
|
76
|
-
const body = keyOf('b', room, path);
|
|
77
76
|
if (document === null || !markdownPath(path)) {
|
|
78
77
|
return [
|
|
79
78
|
{
|
|
@@ -86,8 +85,9 @@ export function rowsOf(room, path, document, composition, change, binary) {
|
|
|
86
85
|
values: {},
|
|
87
86
|
reached: {},
|
|
88
87
|
directories: directoriesOf(path),
|
|
89
|
-
|
|
88
|
+
text: null,
|
|
90
89
|
change,
|
|
90
|
+
fileId,
|
|
91
91
|
binary,
|
|
92
92
|
},
|
|
93
93
|
];
|
|
@@ -117,19 +117,11 @@ export function rowsOf(room, path, document, composition, change, binary) {
|
|
|
117
117
|
values,
|
|
118
118
|
reached,
|
|
119
119
|
directories: directoriesOf(path),
|
|
120
|
-
|
|
120
|
+
text: document.content,
|
|
121
121
|
change,
|
|
122
|
+
fileId,
|
|
122
123
|
binary,
|
|
123
124
|
},
|
|
124
|
-
{
|
|
125
|
-
key: body,
|
|
126
|
-
kind: 'body',
|
|
127
|
-
room,
|
|
128
|
-
path,
|
|
129
|
-
preamble: document.preamble,
|
|
130
|
-
sections: document.sections,
|
|
131
|
-
markdown: document.content,
|
|
132
|
-
},
|
|
133
125
|
...[...reading.targets.values()].map(({ field, target: found, forms }) => ({
|
|
134
126
|
key: keyOf('r', room, path, field, found),
|
|
135
127
|
kind: 'reference',
|
package/dist/save.d.ts
CHANGED
|
@@ -24,6 +24,11 @@ export type SaveInput = {
|
|
|
24
24
|
bases: readonly Precondition[];
|
|
25
25
|
queued?: ReadonlySet<string>;
|
|
26
26
|
writtenBy?: WrittenBy;
|
|
27
|
+
clean?: {
|
|
28
|
+
text: Readonly<Record<string, string>>;
|
|
29
|
+
binaries: Readonly<Record<string, unknown>>;
|
|
30
|
+
composition: Composition;
|
|
31
|
+
};
|
|
27
32
|
};
|
|
28
33
|
export type BatchResult = {
|
|
29
34
|
kind: 'batch';
|
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":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAIL,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EASL,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAA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,SAAS,WAAW,EAAE,KAAK,YAAY,GACrD,WAAW,GAAG,IAAI,CASpB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,CA4GxD"}
|
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
3
|
import { immutable, queuedFile, departure, } from './change.js';
|
|
4
|
-
import { collectionOf, documentsOf, governing, validateCollection, } from './collection.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';
|
|
@@ -177,7 +177,7 @@ export function providerRewritten(batch, visible) {
|
|
|
177
177
|
...anticipated(batch.changes, batch.preconditions, rewritten.changes, visible),
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
-
function incoming(collection, removed) {
|
|
180
|
+
function incoming(collection, removed, candidates) {
|
|
181
181
|
const found = new Map();
|
|
182
182
|
const note = (target, file) => {
|
|
183
183
|
if (!removed.has(target))
|
|
@@ -186,7 +186,13 @@ function incoming(collection, removed) {
|
|
|
186
186
|
referrers.add(file);
|
|
187
187
|
found.set(target, referrers);
|
|
188
188
|
};
|
|
189
|
-
|
|
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) {
|
|
190
196
|
const definition = definitionOf(governing(collection.composition, path), document.type);
|
|
191
197
|
for (const { value, to } of definition === undefined ? [] : references(document, definition)) {
|
|
192
198
|
if (to.includes(ATTACHMENT))
|
|
@@ -217,10 +223,13 @@ function affected(change) {
|
|
|
217
223
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
218
224
|
}
|
|
219
225
|
function guard(changes, input) {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
+
};
|
|
224
233
|
for (const [index, change] of changes.entries()) {
|
|
225
234
|
for (const path of affected(change)) {
|
|
226
235
|
const normalized = normalize(path);
|
|
@@ -450,6 +459,8 @@ function relativeChanges(input) {
|
|
|
450
459
|
});
|
|
451
460
|
}
|
|
452
461
|
function unmodeledType(collection, composition) {
|
|
462
|
+
if (available(composition))
|
|
463
|
+
return false;
|
|
453
464
|
for (const [path, document] of documentsOf(collection)) {
|
|
454
465
|
if (document.type !== undefined &&
|
|
455
466
|
document.type !== 'any' &&
|
|
@@ -740,9 +751,16 @@ export function buildBatch(input) {
|
|
|
740
751
|
const resulting = overlay(input.visible, [
|
|
741
752
|
{ id: '', baseRoomVersion: input.baseRoomVersion, ...predicted },
|
|
742
753
|
]);
|
|
754
|
+
const clean = input.clean !== undefined &&
|
|
755
|
+
input.clean.text === input.visible.documents &&
|
|
756
|
+
input.clean.binaries === input.visible.binaries &&
|
|
757
|
+
available(input.composition)
|
|
758
|
+
? input.clean
|
|
759
|
+
: null;
|
|
743
760
|
const removed = new Set(changes.filter((change) => change.kind === 'remove').map((change) => change.path));
|
|
744
761
|
if (removed.size > 0) {
|
|
745
|
-
const
|
|
762
|
+
const referrers = clean === null ? null : referring(clean, input.composition, removed);
|
|
763
|
+
const referenced = incoming(collectionOf(resulting.documents, input.composition), removed, referrers === null ? null : [...referrers, ...predicted.changes.flatMap(affected)]);
|
|
746
764
|
if (referenced !== null)
|
|
747
765
|
return referenced;
|
|
748
766
|
}
|
|
@@ -752,15 +770,20 @@ export function buildBatch(input) {
|
|
|
752
770
|
const parsed = parse(content);
|
|
753
771
|
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
754
772
|
};
|
|
755
|
-
const
|
|
773
|
+
const touched = [...new Set(predicted.changes.flatMap(affected))];
|
|
774
|
+
const typedPaths = touched.filter((path) => typed(input.visible.documents[path]) || typed(resulting.documents[path]));
|
|
756
775
|
const needsModel = typedPaths.length > 0;
|
|
757
776
|
const withoutModel = typedPaths.find((path) => governing(input.composition, path).status === 'unavailable');
|
|
758
777
|
if (withoutModel !== undefined)
|
|
759
778
|
return refuse('model-unavailable', withoutModel);
|
|
760
|
-
const
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
779
|
+
const verdict = clean !== null &&
|
|
780
|
+
changedCleanly({ text: resulting.documents, binaries: resulting.binaries }, clean, input.composition)
|
|
781
|
+
? { verdict: 'accept' }
|
|
782
|
+
: validateCollection(needsModel
|
|
783
|
+
? resulting.documents
|
|
784
|
+
: Object.fromEntries(touched.flatMap((path) => resulting.documents[path] === undefined
|
|
785
|
+
? []
|
|
786
|
+
: [[path, resulting.documents[path]]])), Object.keys(resulting.binaries), input.composition);
|
|
764
787
|
if (verdict.verdict === 'refuse') {
|
|
765
788
|
return {
|
|
766
789
|
kind: 'refused',
|
package/dist/search.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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 = {
|
|
@@ -21,10 +22,31 @@ export type MessageHit = {
|
|
|
21
22
|
score: number;
|
|
22
23
|
matches: Readonly<Record<string, readonly Open<'text'>[]>>;
|
|
23
24
|
};
|
|
24
|
-
export type
|
|
25
|
+
export type SearchCoverage = {
|
|
26
|
+
rooms: readonly CoveredRoom[];
|
|
27
|
+
conversations: readonly string[];
|
|
28
|
+
index: string;
|
|
29
|
+
overlay: readonly string[];
|
|
30
|
+
};
|
|
31
|
+
export type PendingConversation = {
|
|
32
|
+
conversation: string;
|
|
33
|
+
awaits: Open<'index'>;
|
|
34
|
+
};
|
|
35
|
+
export type SearchHits = {
|
|
25
36
|
documents: readonly DocumentHit[];
|
|
26
37
|
messages: readonly MessageHit[];
|
|
27
38
|
};
|
|
39
|
+
export type SearchPending = SearchHits & {
|
|
40
|
+
pending: readonly (PendingRoom | PendingConversation)[];
|
|
41
|
+
coverage: SearchCoverage;
|
|
42
|
+
};
|
|
43
|
+
export type SearchUndeclared = ProviderRefusal & {
|
|
44
|
+
kind: 'undeclared';
|
|
45
|
+
};
|
|
46
|
+
export type SearchResult = (SearchHits & {
|
|
47
|
+
coverage: SearchCoverage;
|
|
48
|
+
}) | SearchPending | SearchUndeclared;
|
|
49
|
+
export declare function undeclaredSearch(): SearchUndeclared;
|
|
28
50
|
export type SearchedDocument = {
|
|
29
51
|
room: string;
|
|
30
52
|
path: string;
|
|
@@ -39,10 +61,8 @@ export type SearchedMessage = {
|
|
|
39
61
|
text: string;
|
|
40
62
|
};
|
|
41
63
|
export type SearchSource = {
|
|
42
|
-
|
|
64
|
+
room(room: string): readonly string[];
|
|
43
65
|
document(room: string, path: string): SearchedDocument | null;
|
|
44
|
-
messages(): readonly SearchedMessage[];
|
|
45
|
-
message(conversation: string, identity: string): SearchedMessage | null;
|
|
46
66
|
};
|
|
47
67
|
export type SearchPlan = {
|
|
48
68
|
text: string;
|
|
@@ -51,11 +71,19 @@ export type SearchPlan = {
|
|
|
51
71
|
limit: number | null;
|
|
52
72
|
};
|
|
53
73
|
export type SearchIndex = {
|
|
74
|
+
generation(): string;
|
|
75
|
+
rooms(): ReadonlySet<string>;
|
|
76
|
+
conversations(): ReadonlySet<string>;
|
|
77
|
+
indexRoom(room: string): Promise<void>;
|
|
78
|
+
indexMessages(conversation: string, messages: readonly SearchedMessage[], whole: boolean): void;
|
|
79
|
+
forget(rooms: readonly string[]): void;
|
|
54
80
|
changed(set: ChangeSet): void;
|
|
81
|
+
changes(): number;
|
|
82
|
+
caughtUp(): Promise<void>;
|
|
55
83
|
search(plan: SearchPlan, documents: readonly {
|
|
56
84
|
room: string;
|
|
57
85
|
path: string;
|
|
58
|
-
}[] | null):
|
|
86
|
+
}[] | null, conversations: readonly string[], rooms: ReadonlySet<string> | null): SearchHits;
|
|
59
87
|
};
|
|
60
88
|
export declare function searchPlanOf(input: unknown): SearchPlan;
|
|
61
89
|
export declare function createSearchIndex(source: SearchSource): SearchIndex;
|
package/dist/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;AAE7E,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,M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AM,CAAC,CAAC;IACrC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,eAAe,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAChG,MAAM,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IACvC,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC9B,OAAO,IAAI,MAAM,CAAC;IAClB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,MAAM,CACJ,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,SAAS;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,IAAI,EAC3D,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,GAChC,UAAU,CAAC;CACf,CAAC;AA4BF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAiBvD;AAMD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW,CAkKnE"}
|
package/dist/search.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import MiniSearch from 'minisearch';
|
|
2
|
-
import {
|
|
2
|
+
import { indexGeneration } from './identity.js';
|
|
3
|
+
import { invalid, known, limitOf, plain, } from './query.js';
|
|
4
|
+
import { inUnits, ROW_WEIGHT } from './turn.js';
|
|
5
|
+
export function undeclaredSearch() {
|
|
6
|
+
return {
|
|
7
|
+
kind: 'undeclared',
|
|
8
|
+
code: 'search-undeclared',
|
|
9
|
+
fields: { name: 'local_search' },
|
|
10
|
+
retryable: false,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
3
13
|
const FIELDS = ['fields', 'sections', 'preamble', 'path', 'text'];
|
|
4
14
|
function documentId(room, path) {
|
|
5
15
|
return JSON.stringify(['document', room, path]);
|
|
@@ -35,15 +45,20 @@ export function searchPlanOf(input) {
|
|
|
35
45
|
};
|
|
36
46
|
}
|
|
37
47
|
export function createSearchIndex(source) {
|
|
38
|
-
|
|
48
|
+
const generation = indexGeneration();
|
|
49
|
+
const index = new MiniSearch({ fields: FIELDS });
|
|
39
50
|
const documents = new Map();
|
|
40
51
|
const messages = new Map();
|
|
52
|
+
const rooms = new Set();
|
|
53
|
+
const filling = new Set();
|
|
54
|
+
const conversations = new Set();
|
|
55
|
+
const acquiring = new Set();
|
|
41
56
|
const changedDocuments = new Map();
|
|
42
|
-
|
|
43
|
-
function addDocument(
|
|
57
|
+
let changes = 0;
|
|
58
|
+
function addDocument(document) {
|
|
44
59
|
const id = documentId(document.room, document.path);
|
|
45
|
-
|
|
46
|
-
|
|
60
|
+
discard(id, documents);
|
|
61
|
+
index.add({
|
|
47
62
|
id,
|
|
48
63
|
fields: scalars(document.fields).join('\n'),
|
|
49
64
|
sections: Object.entries(document.sections)
|
|
@@ -52,43 +67,48 @@ export function createSearchIndex(source) {
|
|
|
52
67
|
preamble: document.preamble,
|
|
53
68
|
path: document.path,
|
|
54
69
|
});
|
|
70
|
+
documents.set(id, { room: document.room, path: document.path, type: document.type });
|
|
55
71
|
}
|
|
56
|
-
function addMessage(
|
|
72
|
+
function addMessage(message) {
|
|
57
73
|
const id = messageId(message.conversation, message.identity);
|
|
74
|
+
discard(id, messages);
|
|
75
|
+
index.add({ id, text: message.text });
|
|
58
76
|
messages.set(id, { conversation: message.conversation, identity: message.identity });
|
|
59
|
-
built.add({ id, text: message.text });
|
|
60
77
|
}
|
|
61
|
-
function
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
function discard(id, entries) {
|
|
79
|
+
if (entries.delete(id))
|
|
80
|
+
index.discard(id);
|
|
81
|
+
}
|
|
82
|
+
function* pending() {
|
|
83
|
+
for (;;) {
|
|
84
|
+
const next = changedDocuments.entries().next();
|
|
85
|
+
if (next.done === true)
|
|
86
|
+
return;
|
|
87
|
+
changedDocuments.delete(next.value[0]);
|
|
88
|
+
yield next.value;
|
|
70
89
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
90
|
+
}
|
|
91
|
+
let catching = null;
|
|
92
|
+
function caughtUp() {
|
|
93
|
+
if (catching !== null)
|
|
94
|
+
return catching;
|
|
95
|
+
const running = inUnits(pending(), ([id, { room, path }]) => {
|
|
96
|
+
discard(id, documents);
|
|
75
97
|
const document = source.document(room, path);
|
|
76
|
-
if (document
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
changedMessages.clear();
|
|
88
|
-
return built;
|
|
98
|
+
if (document === null)
|
|
99
|
+
return ROW_WEIGHT;
|
|
100
|
+
addDocument(document);
|
|
101
|
+
return Object.values(document.sections).reduce((total, text) => total + text.length, ROW_WEIGHT + document.preamble.length);
|
|
102
|
+
});
|
|
103
|
+
if (!(running instanceof Promise))
|
|
104
|
+
return Promise.resolve();
|
|
105
|
+
catching = running.finally(() => {
|
|
106
|
+
catching = null;
|
|
107
|
+
});
|
|
108
|
+
return catching;
|
|
89
109
|
}
|
|
90
|
-
function ranked(
|
|
91
|
-
const found =
|
|
110
|
+
function ranked(text, entries, keep, limit) {
|
|
111
|
+
const found = index.search(text, {
|
|
92
112
|
filter: ({ id }) => {
|
|
93
113
|
const entry = entries.get(id);
|
|
94
114
|
return entry !== undefined && keep(entry, id);
|
|
@@ -101,24 +121,75 @@ export function createSearchIndex(source) {
|
|
|
101
121
|
}));
|
|
102
122
|
}
|
|
103
123
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
124
|
+
generation: () => generation,
|
|
125
|
+
rooms: () => rooms,
|
|
126
|
+
conversations: () => conversations,
|
|
127
|
+
async indexRoom(room) {
|
|
128
|
+
if (rooms.has(room) || filling.has(room))
|
|
129
|
+
return;
|
|
130
|
+
filling.add(room);
|
|
131
|
+
try {
|
|
132
|
+
await inUnits(source.room(room), (path) => {
|
|
133
|
+
const document = filling.has(room) ? source.document(room, path) : null;
|
|
134
|
+
if (document === null)
|
|
135
|
+
return ROW_WEIGHT;
|
|
136
|
+
addDocument(document);
|
|
137
|
+
return Object.values(document.sections).reduce((total, text) => total + text.length, ROW_WEIGHT + document.preamble.length);
|
|
138
|
+
});
|
|
139
|
+
if (filling.has(room))
|
|
140
|
+
rooms.add(room);
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
filling.delete(room);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
indexMessages(conversation, arriving, whole) {
|
|
147
|
+
for (const message of arriving)
|
|
148
|
+
addMessage(message);
|
|
149
|
+
if (!whole) {
|
|
150
|
+
acquiring.add(conversation);
|
|
106
151
|
return;
|
|
152
|
+
}
|
|
153
|
+
acquiring.delete(conversation);
|
|
154
|
+
conversations.add(conversation);
|
|
155
|
+
},
|
|
156
|
+
forget(leaving) {
|
|
157
|
+
const gone = new Set(leaving);
|
|
158
|
+
for (const [id, entry] of documents)
|
|
159
|
+
if (gone.has(entry.room))
|
|
160
|
+
discard(id, documents);
|
|
161
|
+
for (const room of leaving) {
|
|
162
|
+
rooms.delete(room);
|
|
163
|
+
filling.delete(room);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
changed(set) {
|
|
167
|
+
changes += 1;
|
|
107
168
|
for (const { locator, path } of set.documents) {
|
|
108
|
-
|
|
169
|
+
if (rooms.has(locator) || filling.has(locator)) {
|
|
170
|
+
changedDocuments.set(documentId(locator, path), { room: locator, path });
|
|
171
|
+
}
|
|
109
172
|
}
|
|
110
|
-
for (const { conversation, identity } of set.messages) {
|
|
111
|
-
|
|
173
|
+
for (const { conversation, identity, text } of set.messages) {
|
|
174
|
+
if (!conversations.has(conversation) && !acquiring.has(conversation))
|
|
175
|
+
continue;
|
|
176
|
+
const id = messageId(conversation, identity);
|
|
177
|
+
if (text === null)
|
|
178
|
+
discard(id, messages);
|
|
179
|
+
else
|
|
180
|
+
addMessage({ conversation, identity, text });
|
|
112
181
|
}
|
|
113
182
|
},
|
|
114
|
-
|
|
115
|
-
|
|
183
|
+
changes: () => changes,
|
|
184
|
+
caughtUp,
|
|
185
|
+
search({ text, limit }, selected, named, within) {
|
|
116
186
|
const chosen = selected === null
|
|
117
187
|
? null
|
|
118
188
|
: new Set(selected.map(({ room, path }) => documentId(room, path)));
|
|
189
|
+
const asked = new Set(named);
|
|
119
190
|
return {
|
|
120
|
-
documents: ranked(
|
|
121
|
-
messages: ranked(
|
|
191
|
+
documents: ranked(text, documents, ({ room }, id) => (chosen === null || chosen.has(id)) && (within === null || within.has(room)), limit).map(({ match, ...hit }) => ({ ...hit, matches: match })),
|
|
192
|
+
messages: ranked(text, messages, ({ conversation }) => asked.has(conversation), limit).map(({ match, ...hit }) => ({ ...hit, matches: match })),
|
|
122
193
|
};
|
|
123
194
|
},
|
|
124
195
|
};
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Paths<V> = Readonly<Record<string, V>>;
|
|
2
|
+
type Weigh<V> = (key: string, value: V) => number;
|
|
3
|
+
export declare function shared<V>(map: Paths<V>): Paths<V>;
|
|
4
|
+
export declare function patched<V>(base: Paths<V>, set: Iterable<readonly [string, V]>, removed?: Iterable<string>): Paths<V>;
|
|
5
|
+
export declare function tally<V>(map: Paths<V>, weigh: Weigh<V>): number;
|
|
6
|
+
export declare function sizeOf<V>(map: Paths<V>): number;
|
|
7
|
+
export declare function differing<V>(left: Paths<V>, right: Paths<V>, same?: (left: V, right: V) => boolean): ReadonlySet<string>;
|
|
8
|
+
export declare function drafted<V>(base: Paths<V>): Record<string, V>;
|
|
9
|
+
export declare function settled<V>(draft: Record<string, V>): Paths<V>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAkBnD,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;AA6LlD,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAEjD;AAED,wBAAgB,OAAO,CAAC,CAAC,EACvB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EACnC,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAM,GAC7B,KAAK,CAAC,CAAC,CAAC,CA8BV;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAY/D;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAE/C;AAuCD,wBAAgB,SAAS,CAAC,CAAC,EACzB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,IAAI,GAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,OAAmB,GAC/C,WAAW,CAAC,MAAM,CAAC,CAcrB;AAMD,wBAAgB,OAAO,CAAC,CAAC,EA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