@agentshouse/mdruntime 0.1.0-ca7c26c6bc27e → 0.1.0-ca8707258fdde
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/README.md +25 -12
- package/dist/acceptance.d.ts +26 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +384 -0
- package/dist/adapter.d.ts +200 -54
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +7 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +40 -28
- 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 +18 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +37 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +336 -51
- package/dist/chain.d.ts +12 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +9 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -56
- package/dist/change.d.ts +46 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +34 -0
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +2 -0
- package/dist/client.d.ts +50 -18
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +162 -30
- package/dist/collection.d.ts +13 -14
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +52 -56
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +717 -0
- package/dist/connection.d.ts +61 -43
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2377 -1476
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +47 -0
- package/dist/conversation.d.ts +71 -22
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +996 -273
- 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 +10 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +20 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +161 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/figures.d.ts +48 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/host.d.ts +11 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +134 -34
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -1
- package/dist/index.d.ts +31 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/install.d.ts +86 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/live.d.ts +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +165 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +22 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +299 -94
- package/dist/messages.d.ts +52 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +168 -0
- package/dist/model.d.ts +17 -12
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +9 -9
- 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 +22 -4
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +120 -14
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -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 +73 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +84 -1
- package/dist/overlay.d.ts +16 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +147 -180
- package/dist/parts.d.ts +59 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +118 -0
- package/dist/paths.d.ts +1 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -16
- package/dist/query.d.ts +52 -181
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -423
- package/dist/questions.d.ts +32 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +118 -0
- package/dist/reach.d.ts +19 -5
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +309 -92
- package/dist/react.d.ts +46 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +54 -0
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +50 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +27 -0
- package/dist/reads.d.ts +35 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +128 -0
- package/dist/recovery.d.ts +26 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +232 -0
- package/dist/refresh.d.ts +20 -7
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +155 -59
- package/dist/replica.d.ts +58 -34
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +355 -162
- package/dist/room-draft.d.ts +59 -11
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +276 -80
- package/dist/room-drafts.d.ts +29 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +216 -0
- package/dist/rows.d.ts +32 -34
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +65 -87
- package/dist/save.d.ts +74 -6
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +902 -182
- package/dist/saves.d.ts +96 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +999 -0
- package/dist/search.d.ts +15 -54
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -121
- package/dist/seed.d.ts +30 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +141 -0
- package/dist/shared.d.ts +15 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +421 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket.d.ts +43 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +96 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +81 -0
- package/dist/status.d.ts +7 -4
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -15
- package/dist/store/fences.d.ts +16 -0
- package/dist/store/fences.d.ts.map +1 -0
- package/dist/store/fences.js +26 -0
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/records.d.ts +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +408 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/watchers.d.ts +15 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +36 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +77 -93
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +118 -389
- package/dist/stored.d.ts +156 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +637 -0
- package/dist/tables.d.ts +407 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +724 -0
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +104 -0
- package/dist/windows.d.ts +11 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +16 -0
- package/dist/wire.d.ts +185 -45
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +75 -46
- package/package.json +33 -10
- package/AGENTS.md +0 -215
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
- package/dist/read-side.d.ts +0 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -377
package/dist/search.d.ts
CHANGED
|
@@ -1,61 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
export type DocumentPart = 'fields' | 'sections' | 'preamble' | 'path';
|
|
1
|
+
import type { ProviderRefusal, SearchHit } from './adapter.js';
|
|
2
|
+
import type { Failure, Offline } from './outcome.js';
|
|
4
3
|
export type SearchRequest = {
|
|
5
4
|
text: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
conversation: string;
|
|
19
|
-
identity: string;
|
|
20
|
-
score: number;
|
|
21
|
-
matches: Readonly<Record<string, readonly 'text'[]>>;
|
|
22
|
-
};
|
|
23
|
-
export type SearchResult = {
|
|
24
|
-
documents: readonly DocumentHit[];
|
|
25
|
-
messages: readonly MessageHit[];
|
|
26
|
-
};
|
|
27
|
-
export type SearchedDocument = {
|
|
28
|
-
room: string;
|
|
29
|
-
path: string;
|
|
30
|
-
type: string;
|
|
31
|
-
fields: Readonly<Record<string, unknown>>;
|
|
32
|
-
preamble: string;
|
|
33
|
-
sections: Readonly<Record<string, string>>;
|
|
34
|
-
};
|
|
35
|
-
export type SearchedMessage = {
|
|
36
|
-
conversation: string;
|
|
37
|
-
identity: string;
|
|
38
|
-
text: string;
|
|
39
|
-
};
|
|
40
|
-
export type SearchSource = {
|
|
41
|
-
documents(): readonly SearchedDocument[];
|
|
42
|
-
document(room: string, path: string): SearchedDocument | null;
|
|
43
|
-
messages(): readonly SearchedMessage[];
|
|
44
|
-
message(conversation: string, identity: string): SearchedMessage | null;
|
|
45
|
-
};
|
|
5
|
+
rooms?: readonly string[];
|
|
6
|
+
};
|
|
7
|
+
export type { SearchHit } from './adapter.js';
|
|
8
|
+
export type SearchFound = {
|
|
9
|
+
kind: 'found';
|
|
10
|
+
documents: readonly SearchHit[];
|
|
11
|
+
};
|
|
12
|
+
export type SearchResult = SearchFound | Offline | (ProviderRefusal & {
|
|
13
|
+
kind: 'rejected';
|
|
14
|
+
}) | (ProviderRefusal & {
|
|
15
|
+
kind: 'undeclared';
|
|
16
|
+
}) | Failure;
|
|
46
17
|
export type SearchPlan = {
|
|
47
18
|
text: string;
|
|
48
|
-
|
|
49
|
-
conversations: readonly string[] | null;
|
|
50
|
-
limit: number | null;
|
|
51
|
-
};
|
|
52
|
-
export type SearchIndex = {
|
|
53
|
-
changed(set: ChangeSet): void;
|
|
54
|
-
search(plan: SearchPlan, documents: readonly {
|
|
55
|
-
room: string;
|
|
56
|
-
path: string;
|
|
57
|
-
}[] | null): SearchResult;
|
|
19
|
+
rooms: readonly string[] | null;
|
|
58
20
|
};
|
|
59
21
|
export declare function searchPlanOf(input: unknown): SearchPlan;
|
|
60
|
-
export declare function createSearchIndex(source: SearchSource): SearchIndex;
|
|
61
22
|
//# 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":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAExE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,SAAS,SAAS,EAAE,CAAA;CAAE,CAAC;AAE7E,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,OAAO,GACP,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,GACxC,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC,GAC1C,OAAO,CAAC;AAEZ,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAA;CAAE,CAAC;AAE3E,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAYvD"}
|
package/dist/search.js
CHANGED
|
@@ -1,125 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { invalid, known, limitOf, plain } from './query.js';
|
|
3
|
-
const FIELDS = ['fields', 'sections', 'preamble', 'path', 'text'];
|
|
4
|
-
function documentId(room, path) {
|
|
5
|
-
return JSON.stringify(['document', room, path]);
|
|
6
|
-
}
|
|
7
|
-
function messageId(conversation, identity) {
|
|
8
|
-
return JSON.stringify(['message', conversation, identity]);
|
|
9
|
-
}
|
|
10
|
-
function scalars(value) {
|
|
11
|
-
if (value === null || value === undefined)
|
|
12
|
-
return [];
|
|
13
|
-
if (Array.isArray(value))
|
|
14
|
-
return value.flatMap(scalars);
|
|
15
|
-
if (typeof value === 'object')
|
|
16
|
-
return Object.values(value).flatMap(scalars);
|
|
17
|
-
return [String(value)];
|
|
18
|
-
}
|
|
1
|
+
import { invalid, known, plain } from '@agentshouse/mdmodel';
|
|
19
2
|
export function searchPlanOf(input) {
|
|
20
3
|
if (!plain(input))
|
|
21
4
|
invalid('search', 'expects a search object');
|
|
22
|
-
known(input, ['text', '
|
|
23
|
-
if (typeof input.text !== 'string')
|
|
24
|
-
invalid('text', 'expects
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
(!Array.isArray(
|
|
28
|
-
invalid('
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
text: input.text,
|
|
32
|
-
documents: input.documents,
|
|
33
|
-
conversations: conversations ?? null,
|
|
34
|
-
limit: limitOf(input.limit),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
export function createSearchIndex(source) {
|
|
38
|
-
let index = null;
|
|
39
|
-
const documents = new Map();
|
|
40
|
-
const messages = new Map();
|
|
41
|
-
const changedDocuments = new Map();
|
|
42
|
-
const changedMessages = new Map();
|
|
43
|
-
function addDocument(built, document) {
|
|
44
|
-
const id = documentId(document.room, document.path);
|
|
45
|
-
documents.set(id, { room: document.room, path: document.path, type: document.type });
|
|
46
|
-
built.add({
|
|
47
|
-
id,
|
|
48
|
-
fields: scalars(document.fields).join('\n'),
|
|
49
|
-
sections: Object.entries(document.sections)
|
|
50
|
-
.map(([heading, text]) => `${heading}\n${text}`)
|
|
51
|
-
.join('\n'),
|
|
52
|
-
preamble: document.preamble,
|
|
53
|
-
path: document.path,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function addMessage(built, message) {
|
|
57
|
-
const id = messageId(message.conversation, message.identity);
|
|
58
|
-
messages.set(id, { conversation: message.conversation, identity: message.identity });
|
|
59
|
-
built.add({ id, text: message.text });
|
|
60
|
-
}
|
|
61
|
-
function current() {
|
|
62
|
-
if (index === null) {
|
|
63
|
-
const built = new MiniSearch({ fields: FIELDS });
|
|
64
|
-
for (const document of source.documents())
|
|
65
|
-
addDocument(built, document);
|
|
66
|
-
for (const message of source.messages())
|
|
67
|
-
addMessage(built, message);
|
|
68
|
-
index = built;
|
|
69
|
-
return built;
|
|
70
|
-
}
|
|
71
|
-
const built = index;
|
|
72
|
-
for (const [id, { room, path }] of changedDocuments) {
|
|
73
|
-
if (documents.delete(id))
|
|
74
|
-
built.discard(id);
|
|
75
|
-
const document = source.document(room, path);
|
|
76
|
-
if (document !== null)
|
|
77
|
-
addDocument(built, document);
|
|
78
|
-
}
|
|
79
|
-
changedDocuments.clear();
|
|
80
|
-
for (const [id, { conversation, identity }] of changedMessages) {
|
|
81
|
-
if (messages.delete(id))
|
|
82
|
-
built.discard(id);
|
|
83
|
-
const message = source.message(conversation, identity);
|
|
84
|
-
if (message !== null)
|
|
85
|
-
addMessage(built, message);
|
|
86
|
-
}
|
|
87
|
-
changedMessages.clear();
|
|
88
|
-
return built;
|
|
89
|
-
}
|
|
90
|
-
function ranked(built, text, entries, keep, limit) {
|
|
91
|
-
const found = built.search(text, {
|
|
92
|
-
filter: ({ id }) => {
|
|
93
|
-
const entry = entries.get(id);
|
|
94
|
-
return entry !== undefined && keep(entry, id);
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
return (limit === null ? found : found.slice(0, limit)).map(({ id, score, match }) => ({
|
|
98
|
-
...entries.get(id),
|
|
99
|
-
score,
|
|
100
|
-
match,
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
changed(set) {
|
|
105
|
-
if (index === null)
|
|
106
|
-
return;
|
|
107
|
-
for (const { locator, path } of set.documents) {
|
|
108
|
-
changedDocuments.set(documentId(locator, path), { room: locator, path });
|
|
109
|
-
}
|
|
110
|
-
for (const { conversation, identity } of set.messages) {
|
|
111
|
-
changedMessages.set(messageId(conversation, identity), { conversation, identity });
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
search({ text, conversations, limit }, selected) {
|
|
115
|
-
const built = current();
|
|
116
|
-
const chosen = selected === null
|
|
117
|
-
? null
|
|
118
|
-
: new Set(selected.map(({ room, path }) => documentId(room, path)));
|
|
119
|
-
return {
|
|
120
|
-
documents: ranked(built, text, documents, (_entry, id) => chosen === null || chosen.has(id), limit).map(({ match, ...hit }) => ({ ...hit, matches: match })),
|
|
121
|
-
messages: ranked(built, text, messages, ({ conversation }) => conversations === null || conversations.includes(conversation), limit).map(({ match, ...hit }) => ({ ...hit, matches: match })),
|
|
122
|
-
};
|
|
123
|
-
},
|
|
124
|
-
};
|
|
5
|
+
known(input, ['text', 'rooms'], '');
|
|
6
|
+
if (typeof input.text !== 'string' || input.text.trim() === '')
|
|
7
|
+
invalid('text', 'expects words');
|
|
8
|
+
const rooms = input.rooms;
|
|
9
|
+
if (rooms !== undefined &&
|
|
10
|
+
(!Array.isArray(rooms) || rooms.some((named) => typeof named !== 'string'))) {
|
|
11
|
+
invalid('rooms', 'expects a list of Rooms');
|
|
12
|
+
}
|
|
13
|
+
return { text: input.text, rooms: rooms ?? null };
|
|
125
14
|
}
|
package/dist/seed.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Cover } from './live.js';
|
|
2
|
+
import { type KeyedResult } from './observation.js';
|
|
3
|
+
import type { Plan, QueryRows } from './query.js';
|
|
4
|
+
import type { Deliver } from './reach.js';
|
|
5
|
+
import type { HeldCover, Store } from './store.js';
|
|
6
|
+
export type EntrySeed = {
|
|
7
|
+
readonly at: Readonly<Record<string, string>>;
|
|
8
|
+
readonly queries: readonly {
|
|
9
|
+
readonly query: unknown;
|
|
10
|
+
readonly rows: QueryRows;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
export type Seeded = {
|
|
14
|
+
readonly rows: QueryRows;
|
|
15
|
+
readonly at: Readonly<Record<string, string>>;
|
|
16
|
+
};
|
|
17
|
+
export type Seeding = {
|
|
18
|
+
readonly store: Store;
|
|
19
|
+
reached(room: string, version: string, target: string): boolean;
|
|
20
|
+
listed(): boolean;
|
|
21
|
+
declares(room: string): boolean;
|
|
22
|
+
};
|
|
23
|
+
type SeededWatch = (coverOf: (cover: Cover, held: HeldCover) => Cover, deliver: (message: unknown) => void) => () => void;
|
|
24
|
+
export declare function entrySeedOf(value: unknown): EntrySeed | null;
|
|
25
|
+
export declare function seededResult(seed: Seeded): KeyedResult;
|
|
26
|
+
export declare function seedApplies(seeding: Seeding, plan: Plan, held: HeldCover): Seeded | null;
|
|
27
|
+
export declare function keepEntrySeed(store: Store, entry: EntrySeed): void;
|
|
28
|
+
export declare function watchSeeded(seeding: Seeding, plan: Plan, deliver: Deliver, watch: SeededWatch): () => void;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=seed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;A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Ae5D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAoBtD;AAqBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAOxF;AAYD,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAMlE;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,WAAW,GACjB,MAAM,IAAI,CA4BZ"}
|
package/dist/seed.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { queryKey } from '@agentshouse/mdmodel';
|
|
2
|
+
import { whole } from './observation.js';
|
|
3
|
+
import { documentKey } from './rows.js';
|
|
4
|
+
const seedTopic = (key) => `seed\u0000${key}`;
|
|
5
|
+
function plain(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function windowOf(value) {
|
|
9
|
+
const { next, total } = value;
|
|
10
|
+
if (next !== undefined && typeof next !== 'string')
|
|
11
|
+
return null;
|
|
12
|
+
if (total !== undefined && !Number.isSafeInteger(total))
|
|
13
|
+
return null;
|
|
14
|
+
return {
|
|
15
|
+
...(next === undefined ? {} : { next }),
|
|
16
|
+
...(total === undefined ? {} : { total: total }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function rowsOf(value) {
|
|
20
|
+
if (!plain(value))
|
|
21
|
+
return null;
|
|
22
|
+
const window = windowOf(value);
|
|
23
|
+
if (window === null)
|
|
24
|
+
return null;
|
|
25
|
+
if (Array.isArray(value.groups)) {
|
|
26
|
+
const groups = value.groups;
|
|
27
|
+
return groups.every((group) => plain(group) && Array.isArray(group.key) && typeof group.count === 'number')
|
|
28
|
+
? { groups: groups, ...window }
|
|
29
|
+
: null;
|
|
30
|
+
}
|
|
31
|
+
if (!Array.isArray(value.documents))
|
|
32
|
+
return null;
|
|
33
|
+
const documents = value.documents;
|
|
34
|
+
return documents.every((document) => plain(document) && typeof document.room === 'string' && typeof document.path === 'string')
|
|
35
|
+
? { documents: documents, ...window }
|
|
36
|
+
: null;
|
|
37
|
+
}
|
|
38
|
+
export function entrySeedOf(value) {
|
|
39
|
+
if (!plain(value) || !plain(value.at) || !Array.isArray(value.queries))
|
|
40
|
+
return null;
|
|
41
|
+
const at = {};
|
|
42
|
+
for (const [room, version] of Object.entries(value.at)) {
|
|
43
|
+
if (typeof version !== 'string')
|
|
44
|
+
return null;
|
|
45
|
+
at[room] = version;
|
|
46
|
+
}
|
|
47
|
+
const queries = [];
|
|
48
|
+
for (const entry of value.queries) {
|
|
49
|
+
if (!plain(entry) || !plain(entry.query))
|
|
50
|
+
return null;
|
|
51
|
+
const rows = rowsOf(entry.rows);
|
|
52
|
+
if (rows === null)
|
|
53
|
+
return null;
|
|
54
|
+
queries.push({ query: entry.query, rows });
|
|
55
|
+
}
|
|
56
|
+
return { at, queries };
|
|
57
|
+
}
|
|
58
|
+
export function seededResult(seed) {
|
|
59
|
+
const coverage = {
|
|
60
|
+
rooms: Object.entries(seed.at).map(([room, generation]) => ({
|
|
61
|
+
room,
|
|
62
|
+
generation,
|
|
63
|
+
current: false,
|
|
64
|
+
})),
|
|
65
|
+
indexes: [],
|
|
66
|
+
overlay: [],
|
|
67
|
+
};
|
|
68
|
+
if ('groups' in seed.rows) {
|
|
69
|
+
return {
|
|
70
|
+
result: { ...seed.rows, coverage },
|
|
71
|
+
keys: seed.rows.groups.map((_group, index) => index),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
result: { ...seed.rows, coverage },
|
|
76
|
+
keys: seed.rows.documents.map((document) => documentKey(document.room, document.path)),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function seedRoomHeld(seeding, room, version, held) {
|
|
80
|
+
const stored = held.rooms.get(room);
|
|
81
|
+
return (stored !== undefined && stored.indexed && seeding.reached(room, stored.roomVersion, version));
|
|
82
|
+
}
|
|
83
|
+
function seedHeld(seeding, at, held) {
|
|
84
|
+
return Object.entries(at).every(([room, version]) => (seeding.listed() && !seeding.declares(room) && !held.rooms.has(room)) ||
|
|
85
|
+
seedRoomHeld(seeding, room, version, held));
|
|
86
|
+
}
|
|
87
|
+
export function seedApplies(seeding, plan, held) {
|
|
88
|
+
const { seeds } = seeding.store;
|
|
89
|
+
const seed = seeds.of(plan.key);
|
|
90
|
+
if (seed === undefined)
|
|
91
|
+
return null;
|
|
92
|
+
if (!seedHeld(seeding, seed.at, held))
|
|
93
|
+
return seed;
|
|
94
|
+
seeds.drop(plan.key);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
function seedBehind(seeding, plan, cover, held) {
|
|
98
|
+
const seed = seedApplies(seeding, plan, held);
|
|
99
|
+
if (seed === null || 'pending' in cover)
|
|
100
|
+
return cover;
|
|
101
|
+
return {
|
|
102
|
+
pending: Object.entries(seed.at)
|
|
103
|
+
.filter(([room, version]) => !seedRoomHeld(seeding, room, version, held))
|
|
104
|
+
.map(([room]) => ({ room, awaits: 'acquisition' })),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export function keepEntrySeed(store, entry) {
|
|
108
|
+
for (const { query, rows } of entry.queries) {
|
|
109
|
+
const key = queryKey(query);
|
|
110
|
+
store.seeds.keep(key, { rows, at: entry.at });
|
|
111
|
+
for (const watcher of store.watching(seedTopic(key)))
|
|
112
|
+
watcher.answer(null);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function watchSeeded(seeding, plan, deliver, watch) {
|
|
116
|
+
const { store } = seeding;
|
|
117
|
+
let seeded = false;
|
|
118
|
+
let pending = true;
|
|
119
|
+
const shown = () => {
|
|
120
|
+
const seed = store.seeds.of(plan.key);
|
|
121
|
+
if (seed === undefined || seeded || !pending)
|
|
122
|
+
return;
|
|
123
|
+
seeded = true;
|
|
124
|
+
deliver(seededResult(seed));
|
|
125
|
+
};
|
|
126
|
+
const watcher = store.watch(seedTopic(plan.key), shown);
|
|
127
|
+
const stop = watch((cover, held) => seedBehind(seeding, plan, cover, held), (message) => {
|
|
128
|
+
const answered = message;
|
|
129
|
+
pending = whole(answered) && 'pending' in answered.result;
|
|
130
|
+
if (pending && store.seeds.of(plan.key) !== undefined) {
|
|
131
|
+
shown();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
seeded = false;
|
|
135
|
+
deliver(message);
|
|
136
|
+
});
|
|
137
|
+
return () => {
|
|
138
|
+
watcher.stop();
|
|
139
|
+
stop();
|
|
140
|
+
};
|
|
141
|
+
}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Paths<V> = Readonly<Record<string, V>>;
|
|
2
|
+
export declare function entriesIn<V>(map: Paths<V>): Generator<readonly [string, V]>;
|
|
3
|
+
export declare function sortedKeys(map: Paths<unknown>): Generator<number, readonly string[], void>;
|
|
4
|
+
export declare function sorting(keys: Iterable<string>): Generator<number, readonly string[], void>;
|
|
5
|
+
export declare function sharing<V>(map: Paths<V>): Generator<number, Paths<V>, void>;
|
|
6
|
+
export declare function shared<V>(map: Paths<V>): Paths<V>;
|
|
7
|
+
export declare function patched<V>(base: Paths<V>, set: Iterable<readonly [string, V]>, removed?: Iterable<string>): Paths<V>;
|
|
8
|
+
export declare function patching<V>(base: Paths<V>, set: Iterable<readonly [string, V]>, removed?: Iterable<string>): Generator<number, Paths<V>, void>;
|
|
9
|
+
export declare function sizeOf<V>(map: Paths<V>): number;
|
|
10
|
+
export declare function differences<V>(left: Paths<V>, right: Paths<V>, same?: (left: V, right: V) => boolean): Generator<number, ReadonlySet<string>, void>;
|
|
11
|
+
export declare function differing<V>(left: Paths<V>, right: Paths<V>, same?: (left: V, right: V) => boolean): ReadonlySet<string>;
|
|
12
|
+
export declare function drafted<V>(base: Paths<V>): Record<string, V>;
|
|
13
|
+
export declare function settled<V>(draft: Record<string, V>): Paths<V>;
|
|
14
|
+
export declare function settling<V>(draft: Record<string, V>): Generator<number, Paths<V>, void>;
|
|
15
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AA+LnD,wBAAiB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAO5E;AAuCD,wBAAiB,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,CAAC,CAE3F;AAED,wBAAiB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,CAAC,CAoB3F;AAED,wBAAiB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAE5E;AAED,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,CA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