@agentshouse/mdruntime 0.1.0-alpha.25 → 0.1.0-alpha.27
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 +37 -8
- package/dist/client.d.ts +15 -11
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +60 -59
- package/dist/client.js.map +1 -1
- package/dist/connection.d.ts +19 -10
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +113 -91
- package/dist/connection.js.map +1 -1
- package/dist/conversation.d.ts +4 -1
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +19 -2
- package/dist/conversation.js.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +19 -39
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/observation.d.ts +25 -0
- package/dist/observation.d.ts.map +1 -0
- package/dist/observation.js +92 -0
- package/dist/observation.js.map +1 -0
- package/dist/query.d.ts +7 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +23 -10
- package/dist/query.js.map +1 -1
- package/dist/read-side.d.ts +5 -1
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +92 -21
- package/dist/read-side.js.map +1 -1
- package/dist/search.d.ts +61 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +155 -0
- package/dist/search.js.map +1 -0
- package/dist/wire.d.ts +3 -2
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +3 -1
- package/dist/wire.js.map +1 -1
- package/package.json +3 -2
package/dist/connection.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { verify } from '@agentshouse/mdmodel';
|
|
2
2
|
import { cached, modelTypes, NO_MODEL, sameModel } from './model.js';
|
|
3
|
-
import {
|
|
3
|
+
import { opened } from './observation.js';
|
|
4
|
+
import { filterOf, identityOf, planOf } from './query.js';
|
|
4
5
|
import { createReadSide } from './read-side.js';
|
|
6
|
+
import { createSearchIndex, searchPlanOf } from './search.js';
|
|
5
7
|
import { ROOM_CONTRACT_VERSION, VERSION_1_CAPABILITIES } from './adapter.js';
|
|
6
8
|
import { bootstrapRoom } from './bootstrap.js';
|
|
7
9
|
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
@@ -36,6 +38,9 @@ function declaredSelection(room) {
|
|
|
36
38
|
return selection.roots.every((root, index)=>validRoot(root) && root !== '' && !within(room.collectionRoot, root) && selection.roots.every((other, at)=>at === index || !within(other, root)));
|
|
37
39
|
}
|
|
38
40
|
export function createMdRuntime(options) {
|
|
41
|
+
return composeRuntime(options).md;
|
|
42
|
+
}
|
|
43
|
+
export function composeRuntime(options) {
|
|
39
44
|
const period = options.discoveryIntervalMs ?? DEFAULT_DISCOVERY_INTERVAL_MS;
|
|
40
45
|
let authorization = options.authorization;
|
|
41
46
|
let opening;
|
|
@@ -119,6 +124,12 @@ export function createMdRuntime(options) {
|
|
|
119
124
|
publish: publishChangeSet,
|
|
120
125
|
closed: ()=>closed
|
|
121
126
|
});
|
|
127
|
+
const searchIndex = createSearchIndex({
|
|
128
|
+
documents: ()=>readSide.documents(),
|
|
129
|
+
document: (room, path)=>readSide.document(room, path),
|
|
130
|
+
messages: ()=>conversations.messages(),
|
|
131
|
+
message: (conversation, identity)=>conversations.message(conversation, identity)
|
|
132
|
+
});
|
|
122
133
|
const journal = createLog();
|
|
123
134
|
let notifyReady = ()=>{};
|
|
124
135
|
const ready = new Promise((resolve)=>{
|
|
@@ -295,8 +306,12 @@ export function createMdRuntime(options) {
|
|
|
295
306
|
if (subscription.locator === locator) subscription.notify(entries);
|
|
296
307
|
}
|
|
297
308
|
}
|
|
298
|
-
function
|
|
309
|
+
function applyChangeSet(set) {
|
|
299
310
|
readSide.apply(set);
|
|
311
|
+
searchIndex.changed(set);
|
|
312
|
+
}
|
|
313
|
+
function publishChangeSet(set) {
|
|
314
|
+
applyChangeSet(set);
|
|
300
315
|
if (set.rooms.length > 0) emitRooms();
|
|
301
316
|
for (const locator of set.queues)emitQueue(locator);
|
|
302
317
|
if (set.drafts.length > 0 || set.documents.some((change)=>roomDrafts.get(change.locator)?.has(change.path) === true)) {
|
|
@@ -576,7 +591,7 @@ export function createMdRuntime(options) {
|
|
|
576
591
|
}
|
|
577
592
|
async function readState(opened) {
|
|
578
593
|
const { lastCompleted, locators, read } = await hydrate(opened);
|
|
579
|
-
|
|
594
|
+
applyChangeSet(read);
|
|
580
595
|
if (replicas.size > 0) emitRooms();
|
|
581
596
|
for (const locator of locators)emitQueue(locator);
|
|
582
597
|
publishRoomDrafts(false);
|
|
@@ -1758,7 +1773,89 @@ export function createMdRuntime(options) {
|
|
|
1758
1773
|
notifyReady();
|
|
1759
1774
|
});
|
|
1760
1775
|
void enqueue();
|
|
1761
|
-
|
|
1776
|
+
function watch(topic, input, deliver) {
|
|
1777
|
+
if (topic === 'room-drafts') {
|
|
1778
|
+
const listener = {
|
|
1779
|
+
notify: deliver,
|
|
1780
|
+
ready: false
|
|
1781
|
+
};
|
|
1782
|
+
roomDraftListeners.add(listener);
|
|
1783
|
+
void exclusive(async ()=>{
|
|
1784
|
+
await openLocal();
|
|
1785
|
+
if (closed || !roomDraftListeners.has(listener)) return;
|
|
1786
|
+
listener.ready = true;
|
|
1787
|
+
}).then(()=>{
|
|
1788
|
+
if (closed || !listener.ready || !roomDraftListeners.has(listener)) return;
|
|
1789
|
+
listener.notify(snapshotRoomDrafts());
|
|
1790
|
+
}, ()=>{});
|
|
1791
|
+
return ()=>{
|
|
1792
|
+
roomDraftListeners.delete(listener);
|
|
1793
|
+
};
|
|
1794
|
+
}
|
|
1795
|
+
if (topic === 'conversation') {
|
|
1796
|
+
return conversations.watch(input[0], input[1], deliver);
|
|
1797
|
+
}
|
|
1798
|
+
if (topic === 'presentation') {
|
|
1799
|
+
const listener = {
|
|
1800
|
+
app: input[0],
|
|
1801
|
+
notify: deliver,
|
|
1802
|
+
ready: false
|
|
1803
|
+
};
|
|
1804
|
+
presentationListeners.add(listener);
|
|
1805
|
+
void exclusive(async ()=>{
|
|
1806
|
+
await openLocal();
|
|
1807
|
+
}).then(()=>{
|
|
1808
|
+
if (closed || !presentationListeners.has(listener)) return;
|
|
1809
|
+
listener.ready = true;
|
|
1810
|
+
listener.notify(presentationOf(listener.app));
|
|
1811
|
+
}, ()=>{});
|
|
1812
|
+
return ()=>{
|
|
1813
|
+
presentationListeners.delete(listener);
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
if (topic === 'rooms') {
|
|
1817
|
+
roomListeners.add(deliver);
|
|
1818
|
+
deliver(listed());
|
|
1819
|
+
return ()=>{
|
|
1820
|
+
roomListeners.delete(deliver);
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
if (topic === 'connection-refusal') {
|
|
1824
|
+
refusalListeners.add(deliver);
|
|
1825
|
+
deliver(refusal);
|
|
1826
|
+
return ()=>{
|
|
1827
|
+
refusalListeners.delete(deliver);
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
if (topic === 'storage-loss') {
|
|
1831
|
+
storageLossListeners.add(deliver);
|
|
1832
|
+
deliver(storageLoss);
|
|
1833
|
+
return ()=>{
|
|
1834
|
+
storageLossListeners.delete(deliver);
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
if (topic === 'sync-status') {
|
|
1838
|
+
statusListeners.add(deliver);
|
|
1839
|
+
deliver(shown);
|
|
1840
|
+
return ()=>{
|
|
1841
|
+
statusListeners.delete(deliver);
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
if (topic === 'queue') {
|
|
1845
|
+
const queue = {
|
|
1846
|
+
locator: input[0],
|
|
1847
|
+
notify: deliver
|
|
1848
|
+
};
|
|
1849
|
+
queueSubscriptions.add(queue);
|
|
1850
|
+
queue.notify(entriesOf(queue.locator));
|
|
1851
|
+
return ()=>{
|
|
1852
|
+
queueSubscriptions.delete(queue);
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
const plan = planOf(input[0], roomFacts());
|
|
1856
|
+
return readSide.watch(plan, identityOf(plan), deliver);
|
|
1857
|
+
}
|
|
1858
|
+
const md = {
|
|
1762
1859
|
loaded () {
|
|
1763
1860
|
return openLocal().then(()=>undefined);
|
|
1764
1861
|
},
|
|
@@ -1769,6 +1866,11 @@ export function createMdRuntime(options) {
|
|
|
1769
1866
|
return slotted();
|
|
1770
1867
|
},
|
|
1771
1868
|
query: (input)=>readSide.query(planOf(input, roomFacts())),
|
|
1869
|
+
async search (input) {
|
|
1870
|
+
const plan = searchPlanOf(input);
|
|
1871
|
+
const selected = plan.documents === undefined ? null : (await readSide.query(filterOf(plan.documents, roomFacts()))).documents;
|
|
1872
|
+
return searchIndex.search(plan, selected);
|
|
1873
|
+
},
|
|
1772
1874
|
types (locator) {
|
|
1773
1875
|
return {
|
|
1774
1876
|
collection: modelTypes(modelOf(locator)),
|
|
@@ -1897,93 +1999,9 @@ export function createMdRuntime(options) {
|
|
|
1897
1999
|
persistence () {
|
|
1898
2000
|
return options.shell.persistentStorage;
|
|
1899
2001
|
},
|
|
1900
|
-
observe (topic,
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
const listener = {
|
|
1904
|
-
notify,
|
|
1905
|
-
ready: false
|
|
1906
|
-
};
|
|
1907
|
-
roomDraftListeners.add(listener);
|
|
1908
|
-
void exclusive(async ()=>{
|
|
1909
|
-
await openLocal();
|
|
1910
|
-
if (closed || !roomDraftListeners.has(listener)) return;
|
|
1911
|
-
listener.ready = true;
|
|
1912
|
-
}).then(()=>{
|
|
1913
|
-
if (closed || !listener.ready || !roomDraftListeners.has(listener)) return;
|
|
1914
|
-
listener.notify(snapshotRoomDrafts());
|
|
1915
|
-
}, ()=>{});
|
|
1916
|
-
return ()=>{
|
|
1917
|
-
roomDraftListeners.delete(listener);
|
|
1918
|
-
};
|
|
1919
|
-
}
|
|
1920
|
-
if (topic === 'conversation') {
|
|
1921
|
-
return conversations.observe(second, third, fourth);
|
|
1922
|
-
}
|
|
1923
|
-
if (topic === 'presentation') {
|
|
1924
|
-
const listener = {
|
|
1925
|
-
app: second,
|
|
1926
|
-
notify: third,
|
|
1927
|
-
ready: false
|
|
1928
|
-
};
|
|
1929
|
-
presentationListeners.add(listener);
|
|
1930
|
-
void exclusive(async ()=>{
|
|
1931
|
-
await openLocal();
|
|
1932
|
-
}).then(()=>{
|
|
1933
|
-
if (closed || !presentationListeners.has(listener)) return;
|
|
1934
|
-
listener.ready = true;
|
|
1935
|
-
listener.notify(presentationOf(listener.app));
|
|
1936
|
-
}, ()=>{});
|
|
1937
|
-
return ()=>{
|
|
1938
|
-
presentationListeners.delete(listener);
|
|
1939
|
-
};
|
|
1940
|
-
}
|
|
1941
|
-
if (topic === 'rooms') {
|
|
1942
|
-
const notify = second;
|
|
1943
|
-
roomListeners.add(notify);
|
|
1944
|
-
notify(listed());
|
|
1945
|
-
return ()=>{
|
|
1946
|
-
roomListeners.delete(notify);
|
|
1947
|
-
};
|
|
1948
|
-
}
|
|
1949
|
-
if (topic === 'connection-refusal') {
|
|
1950
|
-
const notify = second;
|
|
1951
|
-
refusalListeners.add(notify);
|
|
1952
|
-
notify(refusal);
|
|
1953
|
-
return ()=>{
|
|
1954
|
-
refusalListeners.delete(notify);
|
|
1955
|
-
};
|
|
1956
|
-
}
|
|
1957
|
-
if (topic === 'storage-loss') {
|
|
1958
|
-
const notify = second;
|
|
1959
|
-
storageLossListeners.add(notify);
|
|
1960
|
-
notify(storageLoss);
|
|
1961
|
-
return ()=>{
|
|
1962
|
-
storageLossListeners.delete(notify);
|
|
1963
|
-
};
|
|
1964
|
-
}
|
|
1965
|
-
if (topic === 'sync-status') {
|
|
1966
|
-
const notify = second;
|
|
1967
|
-
statusListeners.add(notify);
|
|
1968
|
-
notify(shown);
|
|
1969
|
-
return ()=>{
|
|
1970
|
-
statusListeners.delete(notify);
|
|
1971
|
-
};
|
|
1972
|
-
}
|
|
1973
|
-
if (topic === 'queue') {
|
|
1974
|
-
const queue = {
|
|
1975
|
-
locator: second,
|
|
1976
|
-
notify: third
|
|
1977
|
-
};
|
|
1978
|
-
queueSubscriptions.add(queue);
|
|
1979
|
-
queue.notify(entriesOf(queue.locator));
|
|
1980
|
-
return ()=>{
|
|
1981
|
-
queueSubscriptions.delete(queue);
|
|
1982
|
-
};
|
|
1983
|
-
}
|
|
1984
|
-
const plan = planOf(second, roomFacts());
|
|
1985
|
-
return readSide.observe(plan, identityOf(plan), third);
|
|
1986
|
-
},
|
|
2002
|
+
observe: (topic, ...input)=>opened((deliver)=>watch(topic, input, (message)=>{
|
|
2003
|
+
deliver(structuredClone(message));
|
|
2004
|
+
}), topic === 'query'),
|
|
1987
2005
|
async reauthorize () {
|
|
1988
2006
|
if (refusal === null || !refusal.reauthorizationOffered) return;
|
|
1989
2007
|
journal.record('connection reauthorize');
|
|
@@ -1993,6 +2011,10 @@ export function createMdRuntime(options) {
|
|
|
1993
2011
|
await enqueue();
|
|
1994
2012
|
}
|
|
1995
2013
|
};
|
|
2014
|
+
return {
|
|
2015
|
+
md,
|
|
2016
|
+
watch
|
|
2017
|
+
};
|
|
1996
2018
|
}
|
|
1997
2019
|
|
|
1998
2020
|
//# sourceMappingURL=connection.js.map
|