@agentshouse/mdruntime 0.1.0-cedb03eaa48b6 → 0.1.0-cee9c8aa4cd86
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 +86 -71
- package/README.md +9 -8
- package/dist/adapter.d.ts +44 -18
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +4 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +13 -3
- package/dist/bootstrap.d.ts +13 -6
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +90 -61
- package/dist/chain.d.ts +11 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +9 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -89
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/chat/house.d.ts +25 -0
- package/dist/chat/house.d.ts.map +1 -0
- package/dist/chat/house.js +38 -0
- package/dist/chat/input.d.ts +3 -1
- package/dist/chat/input.d.ts.map +1 -1
- package/dist/chat/input.js +11 -18
- package/dist/chat/list.d.ts +2 -1
- package/dist/chat/list.d.ts.map +1 -1
- package/dist/chat/list.js +7 -3
- 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 +1 -0
- package/dist/chat/message.d.ts.map +1 -1
- package/dist/chat/message.js +73 -11
- package/dist/chat/messages.d.ts +14 -1
- package/dist/chat/messages.d.ts.map +1 -1
- package/dist/chat/messages.js +79 -24
- package/dist/chat/name.d.ts +1 -0
- package/dist/chat/name.d.ts.map +1 -1
- package/dist/chat/name.js +1 -1
- package/dist/chat/opened.d.ts +1 -0
- package/dist/chat/opened.d.ts.map +1 -1
- package/dist/chat/opened.js +2 -0
- package/dist/chat/overlay.d.ts +1 -0
- package/dist/chat/overlay.d.ts.map +1 -1
- package/dist/chat/overlay.js +11 -5
- package/dist/chat/parts.d.ts +1 -0
- package/dist/chat/parts.d.ts.map +1 -1
- package/dist/chat/parts.js +3 -2
- 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 +8 -1
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +88 -81
- package/dist/chat/ready.d.ts +5 -2
- package/dist/chat/ready.d.ts.map +1 -1
- package/dist/chat/ready.js +7 -5
- package/dist/chat/room-file.d.ts +8 -0
- package/dist/chat/room-file.d.ts.map +1 -0
- package/dist/chat/room-file.js +72 -0
- 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/style.d.ts.map +1 -1
- package/dist/chat/style.js +5 -0
- package/dist/chat.d.ts +3 -2
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +2 -2
- package/dist/client.d.ts +6 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +29 -2
- package/dist/collection.d.ts +6 -19
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +30 -317
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +718 -0
- package/dist/connection.d.ts +11 -5
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1931 -706
- package/dist/conversation.d.ts +9 -3
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +85 -61
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +2 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +3 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +18 -24
- package/dist/file.d.ts +2 -10
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -120
- package/dist/fulltext.d.ts +27 -0
- package/dist/fulltext.d.ts.map +1 -0
- package/dist/fulltext.js +368 -0
- package/dist/host.d.ts +0 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +10 -3
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/live.d.ts +22 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +123 -0
- package/dist/memory.d.ts +1 -0
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +22 -6
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +90 -0
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +12 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +84 -0
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +29 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +25 -0
- package/dist/overlay.d.ts +2 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +86 -171
- package/dist/query.d.ts +2 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +1 -0
- package/dist/reach.d.ts +5 -1
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +158 -52
- package/dist/readiness.d.ts +3 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/reads.js +1 -1
- package/dist/recovery.d.ts +2 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +8 -7
- package/dist/refresh.d.ts +10 -13
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +74 -51
- package/dist/replica.d.ts +54 -36
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +277 -184
- package/dist/room-draft.d.ts +3 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +29 -22
- package/dist/rows.d.ts +29 -31
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +113 -69
- package/dist/save.d.ts +50 -14
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +502 -178
- package/dist/search.d.ts +11 -43
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +0 -213
- package/dist/shared.d.ts +8 -3
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +129 -66
- package/dist/store.d.ts +79 -93
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +318 -687
- package/dist/stored.d.ts +138 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +544 -0
- package/dist/tables.d.ts +332 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +570 -0
- package/dist/turn.d.ts +4 -2
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +46 -22
- package/dist/validation.d.ts +30 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +162 -0
- package/dist/windows.d.ts +2 -6
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +30 -34
- package/dist/wire.d.ts +16 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +4 -0
- package/dist/words.d.ts +19 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +150 -0
- package/package.json +10 -4
- package/dist/read-side.d.ts +0 -27
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -824
package/dist/search.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ProviderRefusal } from './adapter.js';
|
|
2
|
-
import type { ChangeSet } from './change-set.js';
|
|
3
2
|
import { type CoveredRoom, type Filter, type PendingRoom } from './query.js';
|
|
4
3
|
import type { Open } from './open.js';
|
|
5
4
|
export type DocumentPart = Open<'fields' | 'sections' | 'preamble' | 'path'>;
|
|
@@ -12,29 +11,32 @@ export type SearchRequest = {
|
|
|
12
11
|
after?: string;
|
|
13
12
|
total?: true;
|
|
14
13
|
};
|
|
14
|
+
export type MessagePart = Open<'text'>;
|
|
15
|
+
export type Snippet<Part extends string> = {
|
|
16
|
+
part: Part;
|
|
17
|
+
text: string;
|
|
18
|
+
at: readonly [number, number];
|
|
19
|
+
};
|
|
15
20
|
export type DocumentHit = {
|
|
16
21
|
room: string;
|
|
17
22
|
path: string;
|
|
18
23
|
type: string;
|
|
19
24
|
score: number;
|
|
20
25
|
matches: Readonly<Record<string, readonly DocumentPart[]>>;
|
|
26
|
+
snippet?: Snippet<DocumentPart>;
|
|
21
27
|
};
|
|
22
28
|
export type MessageHit = {
|
|
23
29
|
conversation: string;
|
|
24
30
|
identity: string;
|
|
25
31
|
score: number;
|
|
26
|
-
matches: Readonly<Record<string, readonly
|
|
32
|
+
matches: Readonly<Record<string, readonly MessagePart[]>>;
|
|
33
|
+
snippet?: Snippet<MessagePart>;
|
|
27
34
|
};
|
|
28
35
|
export type SearchCoverage = {
|
|
29
36
|
rooms: readonly CoveredRoom[];
|
|
30
37
|
conversations: readonly string[];
|
|
31
|
-
index: string;
|
|
32
38
|
overlay: readonly string[];
|
|
33
39
|
};
|
|
34
|
-
export type PendingConversation = {
|
|
35
|
-
conversation: string;
|
|
36
|
-
awaits: Open<'index'>;
|
|
37
|
-
};
|
|
38
40
|
export type SearchHits = {
|
|
39
41
|
documents: readonly DocumentHit[];
|
|
40
42
|
messages: readonly MessageHit[];
|
|
@@ -47,7 +49,7 @@ export type SearchWindow = SearchHits & {
|
|
|
47
49
|
};
|
|
48
50
|
};
|
|
49
51
|
export type SearchPending = SearchHits & {
|
|
50
|
-
pending: readonly
|
|
52
|
+
pending: readonly PendingRoom[];
|
|
51
53
|
coverage: SearchCoverage;
|
|
52
54
|
};
|
|
53
55
|
export type SearchUndeclared = ProviderRefusal & {
|
|
@@ -57,24 +59,7 @@ export type SearchResult = (SearchWindow & {
|
|
|
57
59
|
coverage: SearchCoverage;
|
|
58
60
|
}) | SearchPending | SearchUndeclared;
|
|
59
61
|
export declare function undeclaredSearch(): SearchUndeclared;
|
|
60
|
-
export type
|
|
61
|
-
room: string;
|
|
62
|
-
path: string;
|
|
63
|
-
type: string;
|
|
64
|
-
fields: Readonly<Record<string, unknown>>;
|
|
65
|
-
preamble: string;
|
|
66
|
-
sections: Readonly<Record<string, string>>;
|
|
67
|
-
};
|
|
68
|
-
export type SearchedMessage = {
|
|
69
|
-
conversation: string;
|
|
70
|
-
identity: string;
|
|
71
|
-
text: string;
|
|
72
|
-
};
|
|
73
|
-
export type SearchSource = {
|
|
74
|
-
room(room: string): readonly string[];
|
|
75
|
-
document(room: string, path: string): SearchedDocument | null;
|
|
76
|
-
};
|
|
77
|
-
type HitCursor = readonly [number, string, string] | readonly [] | null;
|
|
62
|
+
export type HitCursor = readonly [number, string, string] | readonly [] | null;
|
|
78
63
|
export type SearchPlan = {
|
|
79
64
|
text: string;
|
|
80
65
|
documents: unknown;
|
|
@@ -84,22 +69,5 @@ export type SearchPlan = {
|
|
|
84
69
|
after: readonly [HitCursor, HitCursor] | null;
|
|
85
70
|
total: boolean;
|
|
86
71
|
};
|
|
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;
|
|
94
|
-
changed(set: ChangeSet): void;
|
|
95
|
-
changes(): number;
|
|
96
|
-
caughtUp(): Promise<void>;
|
|
97
|
-
search(plan: SearchPlan, documents: readonly {
|
|
98
|
-
room: string;
|
|
99
|
-
path: string;
|
|
100
|
-
}[] | null, conversations: readonly string[], rooms: ReadonlySet<string> | null, selections: ReadonlyMap<string, readonly string[]> | null): SearchWindow;
|
|
101
|
-
};
|
|
102
72
|
export declare function searchPlanOf(input: unknown): SearchPlan;
|
|
103
|
-
export declare function createSearchIndex(source: SearchSource): SearchIndex;
|
|
104
|
-
export {};
|
|
105
73
|
//# sourceMappingURL=search.d.ts.map
|
package/dist/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"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"}
|
package/dist/search.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import MiniSearch from 'minisearch';
|
|
2
|
-
import { indexGeneration } from './identity.js';
|
|
3
1
|
import { flag, invalid, known, limitOf, plain, } from './query.js';
|
|
4
|
-
import { beneath } from './paths.js';
|
|
5
|
-
import { inUnits, ROW_WEIGHT } from './turn.js';
|
|
6
2
|
import { decodedCursor } from './windows.js';
|
|
7
3
|
export function undeclaredSearch() {
|
|
8
4
|
return {
|
|
@@ -12,22 +8,6 @@ export function undeclaredSearch() {
|
|
|
12
8
|
retryable: false,
|
|
13
9
|
};
|
|
14
10
|
}
|
|
15
|
-
const FIELDS = ['fields', 'sections', 'preamble', 'path', 'text'];
|
|
16
|
-
function documentId(room, path) {
|
|
17
|
-
return JSON.stringify(['document', room, path]);
|
|
18
|
-
}
|
|
19
|
-
function messageId(conversation, identity) {
|
|
20
|
-
return JSON.stringify(['message', conversation, identity]);
|
|
21
|
-
}
|
|
22
|
-
function scalars(value) {
|
|
23
|
-
if (value === null || value === undefined)
|
|
24
|
-
return [];
|
|
25
|
-
if (Array.isArray(value))
|
|
26
|
-
return value.flatMap(scalars);
|
|
27
|
-
if (typeof value === 'object')
|
|
28
|
-
return Object.values(value).flatMap(scalars);
|
|
29
|
-
return [String(value)];
|
|
30
|
-
}
|
|
31
11
|
function hitCursor(input) {
|
|
32
12
|
if (input === null)
|
|
33
13
|
return null;
|
|
@@ -75,196 +55,3 @@ export function searchPlanOf(input) {
|
|
|
75
55
|
total: flag(input.total, 'total'),
|
|
76
56
|
};
|
|
77
57
|
}
|
|
78
|
-
function pair(left, right) {
|
|
79
|
-
if (left[0] !== right[0])
|
|
80
|
-
return left[0] < right[0] ? -1 : 1;
|
|
81
|
-
if (left[1] !== right[1])
|
|
82
|
-
return left[1] < right[1] ? -1 : 1;
|
|
83
|
-
return 0;
|
|
84
|
-
}
|
|
85
|
-
function hitWindow(found, cursor, limit, tie) {
|
|
86
|
-
if (cursor === null)
|
|
87
|
-
return { kept: [], cursor: null };
|
|
88
|
-
const start = cursor.length === 0
|
|
89
|
-
? 0
|
|
90
|
-
: found.findIndex((hit) => hit.score < cursor[0] ||
|
|
91
|
-
(hit.score === cursor[0] && pair(tie(hit), [cursor[1], cursor[2]]) > 0));
|
|
92
|
-
const following = start === -1 ? [] : found.slice(start);
|
|
93
|
-
if (limit === null || following.length <= limit)
|
|
94
|
-
return { kept: following, cursor: null };
|
|
95
|
-
const kept = following.slice(0, limit);
|
|
96
|
-
const last = kept[kept.length - 1];
|
|
97
|
-
return { kept, cursor: last === undefined ? cursor : [last.score, ...tie(last)] };
|
|
98
|
-
}
|
|
99
|
-
export function createSearchIndex(source) {
|
|
100
|
-
const generation = indexGeneration();
|
|
101
|
-
const index = new MiniSearch({ fields: FIELDS });
|
|
102
|
-
const documents = new Map();
|
|
103
|
-
const messages = new Map();
|
|
104
|
-
const rooms = new Set();
|
|
105
|
-
const filling = new Set();
|
|
106
|
-
const conversations = new Set();
|
|
107
|
-
const acquiring = new Set();
|
|
108
|
-
const changedDocuments = new Map();
|
|
109
|
-
let changes = 0;
|
|
110
|
-
function addDocument(document) {
|
|
111
|
-
const id = documentId(document.room, document.path);
|
|
112
|
-
discard(id, documents);
|
|
113
|
-
index.add({
|
|
114
|
-
id,
|
|
115
|
-
fields: scalars(document.fields).join('\n'),
|
|
116
|
-
sections: Object.entries(document.sections)
|
|
117
|
-
.map(([heading, text]) => `${heading}\n${text}`)
|
|
118
|
-
.join('\n'),
|
|
119
|
-
preamble: document.preamble,
|
|
120
|
-
path: document.path,
|
|
121
|
-
});
|
|
122
|
-
documents.set(id, { room: document.room, path: document.path, type: document.type });
|
|
123
|
-
}
|
|
124
|
-
function addMessage(message) {
|
|
125
|
-
const id = messageId(message.conversation, message.identity);
|
|
126
|
-
discard(id, messages);
|
|
127
|
-
index.add({ id, text: message.text });
|
|
128
|
-
messages.set(id, { conversation: message.conversation, identity: message.identity });
|
|
129
|
-
}
|
|
130
|
-
function discard(id, entries) {
|
|
131
|
-
if (entries.delete(id))
|
|
132
|
-
index.discard(id);
|
|
133
|
-
}
|
|
134
|
-
function* pending() {
|
|
135
|
-
for (;;) {
|
|
136
|
-
const next = changedDocuments.entries().next();
|
|
137
|
-
if (next.done === true)
|
|
138
|
-
return;
|
|
139
|
-
changedDocuments.delete(next.value[0]);
|
|
140
|
-
yield next.value;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
let catching = null;
|
|
144
|
-
function caughtUp() {
|
|
145
|
-
if (catching !== null)
|
|
146
|
-
return catching;
|
|
147
|
-
const running = inUnits(pending(), ([id, { room, path }]) => {
|
|
148
|
-
discard(id, documents);
|
|
149
|
-
const document = source.document(room, path);
|
|
150
|
-
if (document === null)
|
|
151
|
-
return ROW_WEIGHT;
|
|
152
|
-
addDocument(document);
|
|
153
|
-
return Object.values(document.sections).reduce((total, text) => total + text.length, ROW_WEIGHT + document.preamble.length);
|
|
154
|
-
});
|
|
155
|
-
if (!(running instanceof Promise))
|
|
156
|
-
return Promise.resolve();
|
|
157
|
-
catching = running.finally(() => {
|
|
158
|
-
catching = null;
|
|
159
|
-
});
|
|
160
|
-
return catching;
|
|
161
|
-
}
|
|
162
|
-
function ranked(text, entries, keep, tie) {
|
|
163
|
-
const found = index.search(text, {
|
|
164
|
-
filter: ({ id }) => {
|
|
165
|
-
const entry = entries.get(id);
|
|
166
|
-
return entry !== undefined && keep(entry, id);
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
found.sort((left, right) => right.score - left.score ||
|
|
170
|
-
pair(tie(entries.get(left.id)), tie(entries.get(right.id))));
|
|
171
|
-
return found.map(({ id, score, match }) => ({
|
|
172
|
-
...entries.get(id),
|
|
173
|
-
score,
|
|
174
|
-
match,
|
|
175
|
-
}));
|
|
176
|
-
}
|
|
177
|
-
return {
|
|
178
|
-
generation: () => generation,
|
|
179
|
-
rooms: () => rooms,
|
|
180
|
-
conversations: () => conversations,
|
|
181
|
-
async indexRoom(room) {
|
|
182
|
-
if (rooms.has(room) || filling.has(room))
|
|
183
|
-
return;
|
|
184
|
-
filling.add(room);
|
|
185
|
-
try {
|
|
186
|
-
await inUnits(source.room(room), (path) => {
|
|
187
|
-
const document = filling.has(room) ? source.document(room, path) : null;
|
|
188
|
-
if (document === null)
|
|
189
|
-
return ROW_WEIGHT;
|
|
190
|
-
addDocument(document);
|
|
191
|
-
return Object.values(document.sections).reduce((total, text) => total + text.length, ROW_WEIGHT + document.preamble.length);
|
|
192
|
-
});
|
|
193
|
-
if (filling.has(room))
|
|
194
|
-
rooms.add(room);
|
|
195
|
-
}
|
|
196
|
-
finally {
|
|
197
|
-
filling.delete(room);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
indexMessages(conversation, arriving, whole) {
|
|
201
|
-
for (const message of arriving)
|
|
202
|
-
addMessage(message);
|
|
203
|
-
if (!whole) {
|
|
204
|
-
acquiring.add(conversation);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
acquiring.delete(conversation);
|
|
208
|
-
conversations.add(conversation);
|
|
209
|
-
},
|
|
210
|
-
forget(leaving) {
|
|
211
|
-
const gone = new Set(leaving);
|
|
212
|
-
for (const [id, entry] of documents)
|
|
213
|
-
if (gone.has(entry.room))
|
|
214
|
-
discard(id, documents);
|
|
215
|
-
for (const room of leaving) {
|
|
216
|
-
rooms.delete(room);
|
|
217
|
-
filling.delete(room);
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
changed(set) {
|
|
221
|
-
changes += 1;
|
|
222
|
-
for (const { locator, path } of set.documents) {
|
|
223
|
-
if (rooms.has(locator) || filling.has(locator)) {
|
|
224
|
-
changedDocuments.set(documentId(locator, path), { room: locator, path });
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
for (const { conversation, identity, text } of set.messages) {
|
|
228
|
-
if (!conversations.has(conversation) && !acquiring.has(conversation))
|
|
229
|
-
continue;
|
|
230
|
-
const id = messageId(conversation, identity);
|
|
231
|
-
if (text === null)
|
|
232
|
-
discard(id, messages);
|
|
233
|
-
else
|
|
234
|
-
addMessage({ conversation, identity, text });
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
changes: () => changes,
|
|
238
|
-
caughtUp,
|
|
239
|
-
search({ text, limit, after, total }, selected, named, within, selections) {
|
|
240
|
-
const chosen = selected === null
|
|
241
|
-
? null
|
|
242
|
-
: new Set(selected.map(({ room, path }) => documentId(room, path)));
|
|
243
|
-
const asked = new Set(named);
|
|
244
|
-
const documentTie = ({ room, path }) => [room, path];
|
|
245
|
-
const messageTie = ({ conversation, identity }) => [conversation, identity];
|
|
246
|
-
const foundDocuments = ranked(text, documents, ({ room, path }, id) => (chosen === null || chosen.has(id)) &&
|
|
247
|
-
(within === null || within.has(room)) &&
|
|
248
|
-
!(selections?.get(room) ?? []).some((root) => beneath(root, path)), documentTie);
|
|
249
|
-
const foundMessages = ranked(text, messages, ({ conversation }) => asked.has(conversation), messageTie);
|
|
250
|
-
const [documentsAfter, messagesAfter] = after ?? [[], []];
|
|
251
|
-
const documentWindow = hitWindow(foundDocuments, documentsAfter, limit, documentTie);
|
|
252
|
-
const messageWindow = hitWindow(foundMessages, messagesAfter, limit, messageTie);
|
|
253
|
-
const more = documentWindow.cursor !== null || messageWindow.cursor !== null;
|
|
254
|
-
return {
|
|
255
|
-
documents: documentWindow.kept.map(({ match, ...hit }) => ({
|
|
256
|
-
...hit,
|
|
257
|
-
matches: match,
|
|
258
|
-
})),
|
|
259
|
-
messages: messageWindow.kept.map(({ match, ...hit }) => ({
|
|
260
|
-
...hit,
|
|
261
|
-
matches: match,
|
|
262
|
-
})),
|
|
263
|
-
...(more ? { next: JSON.stringify([documentWindow.cursor, messageWindow.cursor]) } : {}),
|
|
264
|
-
...(total
|
|
265
|
-
? { total: { documents: foundDocuments.length, messages: foundMessages.length } }
|
|
266
|
-
: {}),
|
|
267
|
-
};
|
|
268
|
-
},
|
|
269
|
-
};
|
|
270
|
-
}
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
export type Paths<V> = Readonly<Record<string, V>>;
|
|
2
|
-
|
|
2
|
+
export declare function entriesIn<V>(map: Paths<V>): Generator<readonly [string, V]>;
|
|
3
|
+
export declare function keysIn(...maps: readonly Paths<unknown>[]): Generator<number, Set<string>, void>;
|
|
4
|
+
export declare function sortedKeys(map: Paths<unknown>): Generator<number, readonly string[], void>;
|
|
5
|
+
export declare function sorting(keys: Iterable<string>): Generator<number, readonly string[], void>;
|
|
6
|
+
export declare function sharing<V>(map: Paths<V>): Generator<number, Paths<V>, void>;
|
|
3
7
|
export declare function shared<V>(map: Paths<V>): Paths<V>;
|
|
4
8
|
export declare function patched<V>(base: Paths<V>, set: Iterable<readonly [string, V]>, removed?: Iterable<string>): Paths<V>;
|
|
5
|
-
export declare function
|
|
9
|
+
export declare function patching<V>(base: Paths<V>, set: Iterable<readonly [string, V]>, removed?: Iterable<string>): Generator<number, Paths<V>, void>;
|
|
6
10
|
export declare function sizeOf<V>(map: Paths<V>): number;
|
|
11
|
+
export declare function differences<V>(left: Paths<V>, right: Paths<V>, same?: (left: V, right: V) => boolean): Generator<number, ReadonlySet<string>, void>;
|
|
7
12
|
export declare function differing<V>(left: Paths<V>, right: Paths<V>, same?: (left: V, right: V) => boolean): ReadonlySet<string>;
|
|
8
13
|
export declare function drafted<V>(base: Paths<V>): Record<string, V>;
|
|
9
14
|
export declare function settled<V>(draft: Record<string, V>): Paths<V>;
|
|
10
|
-
export
|
|
15
|
+
export declare function settling<V>(draft: Record<string, V>): Generator<number, Paths<V>, void>;
|
|
11
16
|
//# sourceMappingURL=shared.d.ts.map
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"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"}
|
package/dist/shared.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { finished, ROW_WEIGHT } from './turn.js';
|
|
1
2
|
const BITS = 5;
|
|
2
3
|
const MASK = (1 << BITS) - 1;
|
|
3
4
|
const roots = new WeakMap();
|
|
4
|
-
const tallies = new WeakMap();
|
|
5
5
|
function hashOf(key) {
|
|
6
6
|
let hash = 0x811c9dc5;
|
|
7
7
|
for (let index = 0; index < key.length; index += 1) {
|
|
@@ -179,33 +179,94 @@ function facade(root) {
|
|
|
179
179
|
roots.set(map, root);
|
|
180
180
|
return map;
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
export function* entriesIn(map) {
|
|
183
|
+
const root = roots.get(map);
|
|
184
|
+
if (root === undefined) {
|
|
185
|
+
for (const key of Object.keys(map))
|
|
186
|
+
yield [key, map[key]];
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
for (const leaf of leavesOf(root.node))
|
|
190
|
+
yield [leaf.key, leaf.value];
|
|
191
|
+
}
|
|
192
|
+
function* rooted(map) {
|
|
183
193
|
const held = roots.get(map);
|
|
184
194
|
if (held !== undefined)
|
|
185
195
|
return held;
|
|
186
196
|
let node;
|
|
187
197
|
let size = 0;
|
|
188
|
-
for (const [key, value] of
|
|
198
|
+
for (const [key, value] of entriesIn(map)) {
|
|
189
199
|
node = put(node, { key, hash: hashOf(key), value }, 0);
|
|
190
200
|
size += 1;
|
|
201
|
+
yield ROW_WEIGHT;
|
|
191
202
|
}
|
|
192
203
|
return { node, size };
|
|
193
204
|
}
|
|
205
|
+
export function* keysIn(...maps) {
|
|
206
|
+
const keys = new Set();
|
|
207
|
+
for (const map of maps) {
|
|
208
|
+
for (const [key] of entriesIn(map)) {
|
|
209
|
+
keys.add(key);
|
|
210
|
+
yield ROW_WEIGHT;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return keys;
|
|
214
|
+
}
|
|
215
|
+
const RUN = 1 << 10;
|
|
216
|
+
function* merged(left, right) {
|
|
217
|
+
const into = [];
|
|
218
|
+
let at = 0;
|
|
219
|
+
let from = 0;
|
|
220
|
+
while (at < left.length || from < right.length) {
|
|
221
|
+
into.push(from === right.length || (at < left.length && left[at] < right[from])
|
|
222
|
+
? left[at++]
|
|
223
|
+
: right[from++]);
|
|
224
|
+
yield ROW_WEIGHT;
|
|
225
|
+
}
|
|
226
|
+
return into;
|
|
227
|
+
}
|
|
228
|
+
function* pathsOf(map) {
|
|
229
|
+
for (const [key] of entriesIn(map))
|
|
230
|
+
yield key;
|
|
231
|
+
}
|
|
232
|
+
export function* sortedKeys(map) {
|
|
233
|
+
return yield* sorting(pathsOf(map));
|
|
234
|
+
}
|
|
235
|
+
export function* sorting(keys) {
|
|
236
|
+
let runs = [];
|
|
237
|
+
let run = [];
|
|
238
|
+
for (const key of keys) {
|
|
239
|
+
run.push(key);
|
|
240
|
+
yield ROW_WEIGHT;
|
|
241
|
+
if (run.length === RUN) {
|
|
242
|
+
runs.push(run.sort());
|
|
243
|
+
run = [];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (run.length > 0)
|
|
247
|
+
runs.push(run.sort());
|
|
248
|
+
while (runs.length > 1) {
|
|
249
|
+
const next = [];
|
|
250
|
+
for (let at = 0; at < runs.length; at += 2) {
|
|
251
|
+
next.push(at + 1 === runs.length ? runs[at] : yield* merged(runs[at], runs[at + 1]));
|
|
252
|
+
}
|
|
253
|
+
runs = next;
|
|
254
|
+
}
|
|
255
|
+
return runs[0] ?? [];
|
|
256
|
+
}
|
|
257
|
+
export function* sharing(map) {
|
|
258
|
+
return roots.has(map) ? map : facade(yield* rooted(map));
|
|
259
|
+
}
|
|
194
260
|
export function shared(map) {
|
|
195
|
-
return
|
|
261
|
+
return finished(sharing(map));
|
|
196
262
|
}
|
|
197
263
|
export function patched(base, set, removed = []) {
|
|
198
|
-
|
|
199
|
-
|
|
264
|
+
return finished(patching(base, set, removed));
|
|
265
|
+
}
|
|
266
|
+
export function* patching(base, set, removed = []) {
|
|
267
|
+
const root = yield* rooted(base);
|
|
200
268
|
let node = root.node;
|
|
201
269
|
let size = root.size;
|
|
202
|
-
const shift = (key, before, after) => {
|
|
203
|
-
for (const entry of weighed) {
|
|
204
|
-
entry[1] +=
|
|
205
|
-
(after === undefined ? 0 : entry[0](key, after)) -
|
|
206
|
-
(before === undefined ? 0 : entry[0](key, before.value));
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
270
|
for (const key of removed) {
|
|
210
271
|
if (node === undefined)
|
|
211
272
|
break;
|
|
@@ -214,88 +275,86 @@ export function patched(base, set, removed = []) {
|
|
|
214
275
|
continue;
|
|
215
276
|
node = taken(node, before.hash, key, 0);
|
|
216
277
|
size -= 1;
|
|
217
|
-
|
|
278
|
+
yield ROW_WEIGHT;
|
|
218
279
|
}
|
|
219
280
|
for (const [key, value] of set) {
|
|
220
281
|
const before = lookup({ node, size }, key);
|
|
221
282
|
node = put(node, { key, hash: hashOf(key), value }, 0);
|
|
222
283
|
if (before === undefined)
|
|
223
284
|
size += 1;
|
|
224
|
-
|
|
285
|
+
yield ROW_WEIGHT;
|
|
225
286
|
}
|
|
226
287
|
if (node === root.node && roots.has(base))
|
|
227
288
|
return base;
|
|
228
|
-
|
|
229
|
-
if (weighed.length > 0)
|
|
230
|
-
tallies.set(map, new Map(weighed));
|
|
231
|
-
return map;
|
|
232
|
-
}
|
|
233
|
-
export function tally(map, weigh) {
|
|
234
|
-
const held = tallies.get(map);
|
|
235
|
-
const known = held?.get(weigh);
|
|
236
|
-
if (known !== undefined)
|
|
237
|
-
return known;
|
|
238
|
-
let total = 0;
|
|
239
|
-
for (const [key, value] of Object.entries(map))
|
|
240
|
-
total += weigh(key, value);
|
|
241
|
-
if (roots.has(map)) {
|
|
242
|
-
const kept = held ?? new Map();
|
|
243
|
-
kept.set(weigh, total);
|
|
244
|
-
tallies.set(map, kept);
|
|
245
|
-
}
|
|
246
|
-
return total;
|
|
289
|
+
return facade({ node, size });
|
|
247
290
|
}
|
|
248
291
|
export function sizeOf(map) {
|
|
249
292
|
return roots.get(map)?.size ?? Object.keys(map).length;
|
|
250
293
|
}
|
|
251
|
-
function
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
294
|
+
function* compared(left, right, same, into) {
|
|
295
|
+
const pending = [[left, right]];
|
|
296
|
+
for (let pair = pending.pop(); pair !== undefined; pair = pending.pop()) {
|
|
297
|
+
const [one, other] = pair;
|
|
298
|
+
if (one === other)
|
|
299
|
+
continue;
|
|
300
|
+
if (one !== undefined &&
|
|
301
|
+
other !== undefined &&
|
|
302
|
+
!isLeaf(one) &&
|
|
303
|
+
!isCollision(one) &&
|
|
304
|
+
!isLeaf(other) &&
|
|
305
|
+
!isCollision(other)) {
|
|
306
|
+
const children = [];
|
|
307
|
+
for (let remaining = one.bitmap | other.bitmap; remaining !== 0; remaining &= remaining - 1) {
|
|
308
|
+
const bit = remaining & -remaining;
|
|
309
|
+
children.push([
|
|
310
|
+
(one.bitmap & bit) === 0 ? undefined : one.children[slot(one.bitmap, bit)],
|
|
311
|
+
(other.bitmap & bit) === 0 ? undefined : other.children[slot(other.bitmap, bit)],
|
|
312
|
+
]);
|
|
313
|
+
}
|
|
314
|
+
pending.push(...children.reverse());
|
|
315
|
+
continue;
|
|
267
316
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
317
|
+
const before = new Map();
|
|
318
|
+
for (const leaf of leavesOf(one)) {
|
|
319
|
+
before.set(leaf.key, leaf.value);
|
|
320
|
+
yield ROW_WEIGHT;
|
|
321
|
+
}
|
|
322
|
+
for (const leaf of leavesOf(other)) {
|
|
323
|
+
const held = before.get(leaf.key);
|
|
324
|
+
before.delete(leaf.key);
|
|
325
|
+
if (held === undefined || !same(held, leaf.value))
|
|
326
|
+
into.add(leaf.key);
|
|
327
|
+
yield ROW_WEIGHT;
|
|
328
|
+
}
|
|
329
|
+
for (const key of before.keys())
|
|
330
|
+
into.add(key);
|
|
276
331
|
}
|
|
277
|
-
for (const key of before.keys())
|
|
278
|
-
into.add(key);
|
|
279
332
|
}
|
|
280
|
-
export function
|
|
333
|
+
export function* differences(left, right, same = Object.is) {
|
|
281
334
|
const into = new Set();
|
|
282
335
|
if (left === right)
|
|
283
336
|
return into;
|
|
284
337
|
const leftRoot = roots.get(left);
|
|
285
338
|
const rightRoot = roots.get(right);
|
|
286
339
|
if (leftRoot !== undefined && rightRoot !== undefined) {
|
|
287
|
-
compared(leftRoot.node, rightRoot.node,
|
|
340
|
+
yield* compared(leftRoot.node, rightRoot.node, same, into);
|
|
288
341
|
return into;
|
|
289
342
|
}
|
|
290
|
-
for (const key of
|
|
291
|
-
if (!Object.hasOwn(right, key) || !same(
|
|
343
|
+
for (const [key, value] of entriesIn(left)) {
|
|
344
|
+
if (!Object.hasOwn(right, key) || !same(value, right[key]))
|
|
292
345
|
into.add(key);
|
|
346
|
+
yield ROW_WEIGHT;
|
|
293
347
|
}
|
|
294
|
-
for (const key of
|
|
348
|
+
for (const [key] of entriesIn(right)) {
|
|
295
349
|
if (!Object.hasOwn(left, key))
|
|
296
350
|
into.add(key);
|
|
351
|
+
yield ROW_WEIGHT;
|
|
352
|
+
}
|
|
297
353
|
return into;
|
|
298
354
|
}
|
|
355
|
+
export function differing(left, right, same = Object.is) {
|
|
356
|
+
return finished(differences(left, right, same));
|
|
357
|
+
}
|
|
299
358
|
const drafts = new WeakMap();
|
|
300
359
|
const GONE = Symbol('gone');
|
|
301
360
|
export function drafted(base) {
|
|
@@ -355,6 +414,9 @@ export function drafted(base) {
|
|
|
355
414
|
return draft;
|
|
356
415
|
}
|
|
357
416
|
export function settled(draft) {
|
|
417
|
+
return finished(settling(draft));
|
|
418
|
+
}
|
|
419
|
+
export function* settling(draft) {
|
|
358
420
|
const held = drafts.get(draft);
|
|
359
421
|
const set = [];
|
|
360
422
|
const removed = [];
|
|
@@ -363,6 +425,7 @@ export function settled(draft) {
|
|
|
363
425
|
removed.push(key);
|
|
364
426
|
else
|
|
365
427
|
set.push([key, value]);
|
|
428
|
+
yield ROW_WEIGHT;
|
|
366
429
|
}
|
|
367
|
-
return
|
|
430
|
+
return yield* patching(held.base, set, removed);
|
|
368
431
|
}
|