@agentshouse/mdruntime 0.1.0-c3b593308e82b → 0.1.0-c3fa75348e547
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 +82 -90
- package/dist/adapter.d.ts +3 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +2 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/chat/kit.js +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +9 -2
- package/dist/connection.d.ts +2 -0
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +249 -30
- package/dist/conversation.d.ts +1 -0
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +40 -5
- package/dist/host.d.ts +4 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +37 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/memory.d.ts +5 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +10 -5
- package/dist/query.d.ts +3 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +5 -1
- package/dist/react.d.ts +2 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +6 -4
- package/dist/reads.d.ts +11 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +98 -0
- package/dist/refresh.d.ts +4 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/room-draft.d.ts +12 -0
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +2 -2
- package/dist/search.d.ts +3 -1
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +21 -6
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +61 -0
- package/dist/store.d.ts +9 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +17 -1
- package/package.json +2 -2
package/dist/connection.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { attachedModel } from './attached-model.js';
|
|
2
2
|
import { cached, modelTypes, NO_MODEL, sameModel, } from './model.js';
|
|
3
|
-
import { observing } from './observation.js';
|
|
4
|
-
import { filterOf, identityOf, planOf, } from './query.js';
|
|
3
|
+
import { observing, whole } from './observation.js';
|
|
4
|
+
import { filterOf, identityOf, planOf, queryKey, } from './query.js';
|
|
5
5
|
import { createReadSide } from './read-side.js';
|
|
6
|
+
import { seededResult } from './seed.js';
|
|
6
7
|
import { markdownPath, roomOfKey } from './rows.js';
|
|
7
8
|
import { createSearchIndex, searchPlanOf, } from './search.js';
|
|
8
9
|
import { bootstrapRoom } from './bootstrap.js';
|
|
@@ -15,6 +16,7 @@ import { createLog } from './log.js';
|
|
|
15
16
|
import { binaryRecord } from './binary.js';
|
|
16
17
|
import { absentBinary, binaryAnswer, calledResult, failure, historyAnswer, undeclared, UNCERTAIN, } from './outcome.js';
|
|
17
18
|
import { createRecovery } from './recovery.js';
|
|
19
|
+
import { doorReads } from './reads.js';
|
|
18
20
|
import { refreshRoom } from './refresh.js';
|
|
19
21
|
import { buildBatch, joined, limitedIn, requeued } from './save.js';
|
|
20
22
|
import { applyReturned, compositionOf, confirmedOf, landed, readReclassified, replicaOf, sameMembership, withdrawals, } from './replica.js';
|
|
@@ -31,6 +33,14 @@ import { beneath, normalize } from './paths.js';
|
|
|
31
33
|
import { openRuntimeStore, } from './store.js';
|
|
32
34
|
import { unconfirmed } from './transfer.js';
|
|
33
35
|
import { governs, holds, narrowed, planReach, } from './reach.js';
|
|
36
|
+
function roomsAlone(plan) {
|
|
37
|
+
return (plan.reach === null &&
|
|
38
|
+
plan.root.types === null &&
|
|
39
|
+
plan.root.where === null &&
|
|
40
|
+
plan.root.pathPrefix === null &&
|
|
41
|
+
plan.hop === null &&
|
|
42
|
+
plan.backlinks === null);
|
|
43
|
+
}
|
|
34
44
|
function within(root, path) {
|
|
35
45
|
return root === '' || beneath(root, path);
|
|
36
46
|
}
|
|
@@ -48,6 +58,10 @@ const OPENING_LANE = 'opening';
|
|
|
48
58
|
const CONVERSATION_LANE = 'conversations';
|
|
49
59
|
const ROOM_READS = 256;
|
|
50
60
|
const ROOM_ATTEMPTS = 16;
|
|
61
|
+
function operationOf(input) {
|
|
62
|
+
const operation = input?.operation_id;
|
|
63
|
+
return typeof operation === 'string' ? operation : null;
|
|
64
|
+
}
|
|
51
65
|
const outside = new Map();
|
|
52
66
|
function outsideOf(roots) {
|
|
53
67
|
const key = JSON.stringify(roots);
|
|
@@ -87,6 +101,8 @@ export function composeRuntime(options) {
|
|
|
87
101
|
const replicas = new FencedMap(isFenced);
|
|
88
102
|
const queuesWithoutReplica = new FencedMap(isFenced);
|
|
89
103
|
const pendings = new Map();
|
|
104
|
+
const seeds = new Map();
|
|
105
|
+
const seedWatchers = new Map();
|
|
90
106
|
const roomDrafts = new FencedMap(isFenced);
|
|
91
107
|
const presentations = new Map();
|
|
92
108
|
let limits = [];
|
|
@@ -99,6 +115,7 @@ export function composeRuntime(options) {
|
|
|
99
115
|
const liveModels = new FencedMap(isModelFenced);
|
|
100
116
|
const invalidModels = new Set();
|
|
101
117
|
const discovered = new Map();
|
|
118
|
+
const reads = doorReads(options.adapter, (locator) => discovered.get(locator), () => generation);
|
|
102
119
|
let roomsListed = false;
|
|
103
120
|
const scopedRefusals = new Map();
|
|
104
121
|
const sourceRefusals = new Map();
|
|
@@ -135,6 +152,7 @@ export function composeRuntime(options) {
|
|
|
135
152
|
let handed = false;
|
|
136
153
|
const recovery = (options.recovery ?? createRecovery()).scope(ROOM_ATTEMPTS);
|
|
137
154
|
const repairing = new Set();
|
|
155
|
+
const calling = new Set();
|
|
138
156
|
const repairable = new Map();
|
|
139
157
|
let outcomeRetention = null;
|
|
140
158
|
const answering = new Map();
|
|
@@ -484,7 +502,8 @@ export function composeRuntime(options) {
|
|
|
484
502
|
return [...new Set(named)].filter((locator) => reached === null || reached.has(locator)).sort();
|
|
485
503
|
}
|
|
486
504
|
function awaited(locator) {
|
|
487
|
-
return
|
|
505
|
+
return (!roomsListed ||
|
|
506
|
+
(rooms.has(locator) && discovered.get(locator)?.replica.admission === 'admitted'));
|
|
488
507
|
}
|
|
489
508
|
function covered(plan) {
|
|
490
509
|
const locators = reachedRooms(plan);
|
|
@@ -535,20 +554,28 @@ export function composeRuntime(options) {
|
|
|
535
554
|
.map((room) => room.locator)
|
|
536
555
|
.sort();
|
|
537
556
|
}
|
|
557
|
+
function heldLocators(acquired) {
|
|
558
|
+
return demand.whole ? acquired : [...new Set([...acquired, ...demand.rooms])].sort();
|
|
559
|
+
}
|
|
538
560
|
function heldDemand(acquired) {
|
|
539
561
|
if (demand.whole)
|
|
540
562
|
return null;
|
|
541
|
-
return {
|
|
563
|
+
return {
|
|
564
|
+
rooms: heldLocators(acquired.map((room) => room.locator)),
|
|
565
|
+
conversations: demand.conversations,
|
|
566
|
+
};
|
|
542
567
|
}
|
|
543
568
|
function applyDemand(next) {
|
|
544
|
-
const before = acquiredLocators();
|
|
545
|
-
const conversed = demand
|
|
569
|
+
const before = heldLocators(acquiredLocators());
|
|
570
|
+
const { whole, conversations: conversed } = demand;
|
|
546
571
|
demand = next;
|
|
547
|
-
const after = acquiredLocators();
|
|
572
|
+
const after = heldLocators(acquiredLocators());
|
|
548
573
|
queueReadiness();
|
|
549
574
|
if (!conversed && next.conversations)
|
|
550
575
|
scheduleCurrency();
|
|
551
|
-
if (JSON.stringify(before) === JSON.stringify(after) &&
|
|
576
|
+
if (JSON.stringify(before) === JSON.stringify(after) &&
|
|
577
|
+
whole === next.whole &&
|
|
578
|
+
conversed === next.conversations)
|
|
552
579
|
return;
|
|
553
580
|
journal.record(`acquisition ${next.whole ? 'whole' : after.length}`);
|
|
554
581
|
if (options.adapter.roomStream === undefined)
|
|
@@ -801,9 +828,47 @@ export function composeRuntime(options) {
|
|
|
801
828
|
const available = await estimated().catch(() => null);
|
|
802
829
|
pause(locator, { cause: 'quota-exceeded', needed: bytes, available });
|
|
803
830
|
}
|
|
831
|
+
function seedRoomHeld(room, version) {
|
|
832
|
+
return prepared.has(room) && reachedBy(room, version);
|
|
833
|
+
}
|
|
834
|
+
function seedHeld(at) {
|
|
835
|
+
return Object.entries(at).every(([room, version]) => (roomsListed && !rooms.has(room)) || seedRoomHeld(room, version));
|
|
836
|
+
}
|
|
837
|
+
function seedApplies(plan) {
|
|
838
|
+
const seed = seeds.get(plan.key);
|
|
839
|
+
if (seed === undefined)
|
|
840
|
+
return null;
|
|
841
|
+
if (!seedHeld(seed.at))
|
|
842
|
+
return seed;
|
|
843
|
+
seeds.delete(plan.key);
|
|
844
|
+
return null;
|
|
845
|
+
}
|
|
846
|
+
function seedBehind(plan, cover) {
|
|
847
|
+
const seed = seedApplies(plan);
|
|
848
|
+
if (seed === null || 'pending' in cover)
|
|
849
|
+
return cover;
|
|
850
|
+
return {
|
|
851
|
+
pending: Object.entries(seed.at)
|
|
852
|
+
.filter(([room, version]) => !seedRoomHeld(room, version))
|
|
853
|
+
.map(([room]) => ({ room, awaits: 'acquisition' })),
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
function seed(entry) {
|
|
857
|
+
if (seedHeld(entry.at))
|
|
858
|
+
return;
|
|
859
|
+
for (const { query, rows } of entry.queries) {
|
|
860
|
+
const key = queryKey(query);
|
|
861
|
+
seeds.set(key, { rows, at: entry.at });
|
|
862
|
+
for (const shown of seedWatchers.get(key) ?? [])
|
|
863
|
+
shown();
|
|
864
|
+
}
|
|
865
|
+
}
|
|
804
866
|
async function rowsQuery(plan) {
|
|
805
867
|
const before = covered(plan);
|
|
806
868
|
awaitPreparation(before);
|
|
869
|
+
const seeded = seedApplies(plan);
|
|
870
|
+
if (seeded !== null)
|
|
871
|
+
return seededResult(seeded).result;
|
|
807
872
|
if ('pending' in before)
|
|
808
873
|
return before;
|
|
809
874
|
const { rows, at: cover } = await readSide.query(plan, () => covered(plan));
|
|
@@ -962,6 +1027,9 @@ export function composeRuntime(options) {
|
|
|
962
1027
|
if (fence !== undefined && fence.erased && fence.at < started)
|
|
963
1028
|
fences.delete(room.locator);
|
|
964
1029
|
}
|
|
1030
|
+
await loseRooms(found
|
|
1031
|
+
.filter((room) => room.replica.admission !== 'admitted' && heldLocally(room.locator))
|
|
1032
|
+
.map((room) => room.locator));
|
|
965
1033
|
const listed = found.filter((room) => !fences.has(room.locator));
|
|
966
1034
|
const listedLocators = new Set(listed.map((room) => room.locator));
|
|
967
1035
|
for (const locator of listedLocators)
|
|
@@ -986,6 +1054,12 @@ export function composeRuntime(options) {
|
|
|
986
1054
|
emitRooms();
|
|
987
1055
|
return listed;
|
|
988
1056
|
}
|
|
1057
|
+
function heldLocally(locator) {
|
|
1058
|
+
return (replicas.has(locator) ||
|
|
1059
|
+
roomDrafts.has(locator) ||
|
|
1060
|
+
transfers.has(locator) ||
|
|
1061
|
+
queuesWithoutReplica.has(locator));
|
|
1062
|
+
}
|
|
989
1063
|
function unlistedHeld(listed) {
|
|
990
1064
|
return [
|
|
991
1065
|
...new Set([
|
|
@@ -1702,7 +1776,7 @@ export function composeRuntime(options) {
|
|
|
1702
1776
|
}
|
|
1703
1777
|
return undefined;
|
|
1704
1778
|
}
|
|
1705
|
-
async function invokeAction(name, input) {
|
|
1779
|
+
async function invokeAction(name, input, dispatching) {
|
|
1706
1780
|
await ready;
|
|
1707
1781
|
if (closed || refusal !== null)
|
|
1708
1782
|
return UNCERTAIN;
|
|
@@ -1716,6 +1790,7 @@ export function composeRuntime(options) {
|
|
|
1716
1790
|
}
|
|
1717
1791
|
if (closed || authorization === undefined || refusal !== null)
|
|
1718
1792
|
return UNCERTAIN;
|
|
1793
|
+
await dispatching?.();
|
|
1719
1794
|
journal.record(`transfer action ${name}`);
|
|
1720
1795
|
try {
|
|
1721
1796
|
const result = await options.adapter.action(authorization, { name, input });
|
|
@@ -1736,6 +1811,60 @@ export function composeRuntime(options) {
|
|
|
1736
1811
|
return UNCERTAIN;
|
|
1737
1812
|
}
|
|
1738
1813
|
}
|
|
1814
|
+
function unsettled(result) {
|
|
1815
|
+
return result.kind !== 'action' && result.retryable;
|
|
1816
|
+
}
|
|
1817
|
+
async function recoveredAction(name, input) {
|
|
1818
|
+
const operation = operationOf(input);
|
|
1819
|
+
if (operation === null)
|
|
1820
|
+
return invokeAction(name, input);
|
|
1821
|
+
const kept = async () => (await openLocal()).keepCall({ operation, name, input });
|
|
1822
|
+
calling.add(operation);
|
|
1823
|
+
try {
|
|
1824
|
+
let result = await invokeAction(name, input, kept);
|
|
1825
|
+
if (unsettled(result)) {
|
|
1826
|
+
await recovery.attempt(`action ${operation}`, async () => {
|
|
1827
|
+
if (closed || refusal !== null)
|
|
1828
|
+
return 'done';
|
|
1829
|
+
if (!socketOpen)
|
|
1830
|
+
return 'again';
|
|
1831
|
+
result = await invokeAction(name, input, kept);
|
|
1832
|
+
return unsettled(result) ? 'again' : 'done';
|
|
1833
|
+
}, { again: true });
|
|
1834
|
+
}
|
|
1835
|
+
if (!unsettled(result))
|
|
1836
|
+
await (await openLocal()).dropCall(operation);
|
|
1837
|
+
return result;
|
|
1838
|
+
}
|
|
1839
|
+
finally {
|
|
1840
|
+
calling.delete(operation);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
async function resendCalls(signal) {
|
|
1844
|
+
if (!socketOpen || closed || stopping)
|
|
1845
|
+
return 'done';
|
|
1846
|
+
const local = await openLocal();
|
|
1847
|
+
for (const held of await local.calls()) {
|
|
1848
|
+
if (calling.has(held.operation))
|
|
1849
|
+
continue;
|
|
1850
|
+
if (closed || signal.aborted)
|
|
1851
|
+
return 'done';
|
|
1852
|
+
if (pastHorizon(held.operation)) {
|
|
1853
|
+
await local.dropCall(held.operation);
|
|
1854
|
+
continue;
|
|
1855
|
+
}
|
|
1856
|
+
calling.add(held.operation);
|
|
1857
|
+
try {
|
|
1858
|
+
if (unsettled(await invokeAction(held.name, held.input)))
|
|
1859
|
+
return 'again';
|
|
1860
|
+
await local.dropCall(held.operation);
|
|
1861
|
+
}
|
|
1862
|
+
finally {
|
|
1863
|
+
calling.delete(held.operation);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
return 'done';
|
|
1867
|
+
}
|
|
1739
1868
|
function continuing() {
|
|
1740
1869
|
return !closed && !discoveryPaused;
|
|
1741
1870
|
}
|
|
@@ -1753,8 +1882,9 @@ export function composeRuntime(options) {
|
|
|
1753
1882
|
async function pullRefresh(authorized, confirmed, live) {
|
|
1754
1883
|
if (!live())
|
|
1755
1884
|
return unconfirmed;
|
|
1885
|
+
const turn = generation;
|
|
1756
1886
|
try {
|
|
1757
|
-
const result = await refreshRoom(
|
|
1887
|
+
const result = await refreshRoom(reads, authorized, confirmed, (models, held) => (live() ? remodel(confirmed.record.locator, models, held) : held), live);
|
|
1758
1888
|
const detail = result.kind === 'advanced' ? result.confirmed.record.roomVersion : result.kind;
|
|
1759
1889
|
journal.record(`transfer refresh ${confirmed.record.locator} ${detail}`);
|
|
1760
1890
|
return result;
|
|
@@ -1763,6 +1893,9 @@ export function composeRuntime(options) {
|
|
|
1763
1893
|
journal.record(`transfer refresh ${confirmed.record.locator} transport-uncertainty`);
|
|
1764
1894
|
throw error;
|
|
1765
1895
|
}
|
|
1896
|
+
finally {
|
|
1897
|
+
reads.finished(confirmed.record.locator, turn);
|
|
1898
|
+
}
|
|
1766
1899
|
}
|
|
1767
1900
|
function staging(local, live) {
|
|
1768
1901
|
return {
|
|
@@ -1805,12 +1938,13 @@ export function composeRuntime(options) {
|
|
|
1805
1938
|
async function pullBootstrap(authorized, room, local, live) {
|
|
1806
1939
|
if (!live())
|
|
1807
1940
|
return unconfirmed;
|
|
1941
|
+
const turn = generation;
|
|
1808
1942
|
if (replicas.has(room.locator)) {
|
|
1809
1943
|
catching.add(room.locator);
|
|
1810
1944
|
readSide.recover();
|
|
1811
1945
|
}
|
|
1812
1946
|
try {
|
|
1813
|
-
const result = await bootstrapRoom(
|
|
1947
|
+
const result = await bootstrapRoom(reads, authorized, room, {
|
|
1814
1948
|
collection: modelOf(room.locator),
|
|
1815
1949
|
selection: modelOf(room.locator, 'typed-selection'),
|
|
1816
1950
|
}, (models, held) => (live() ? remodel(room.locator, models, held) : held), live, staging(local, live), reusable(room));
|
|
@@ -1825,12 +1959,28 @@ export function composeRuntime(options) {
|
|
|
1825
1959
|
caughtUpTo(room.locator);
|
|
1826
1960
|
throw error;
|
|
1827
1961
|
}
|
|
1962
|
+
finally {
|
|
1963
|
+
reads.finished(room.locator, turn);
|
|
1964
|
+
}
|
|
1828
1965
|
}
|
|
1829
1966
|
function caughtUpTo(locator) {
|
|
1830
1967
|
if (catching.delete(locator))
|
|
1831
1968
|
readSide.recover();
|
|
1832
1969
|
}
|
|
1970
|
+
function behind(room) {
|
|
1971
|
+
const held = replicas.get(room.locator)?.confirmed.record.roomVersion;
|
|
1972
|
+
return (held !== undefined &&
|
|
1973
|
+
[announced.get(room.locator), room.roomVersion].some((later) => later !== undefined && !options.adapter.reached(room.locator, held, later)));
|
|
1974
|
+
}
|
|
1833
1975
|
async function advance(room, local, authorized, live) {
|
|
1976
|
+
const carried = reads.carried(room.locator);
|
|
1977
|
+
const withheld = await advanceOnce(room, local, authorized, live);
|
|
1978
|
+
if (withheld !== null || reads.carried(room.locator) === carried || !behind(room)) {
|
|
1979
|
+
return withheld;
|
|
1980
|
+
}
|
|
1981
|
+
return advanceOnce(room, local, authorized, live);
|
|
1982
|
+
}
|
|
1983
|
+
async function advanceOnce(room, local, authorized, live) {
|
|
1834
1984
|
await referenced(room.locator);
|
|
1835
1985
|
if (!live() || paused.has(room.locator))
|
|
1836
1986
|
return unconfirmed;
|
|
@@ -2267,6 +2417,11 @@ export function composeRuntime(options) {
|
|
|
2267
2417
|
});
|
|
2268
2418
|
}
|
|
2269
2419
|
async function scoped(result, room, local) {
|
|
2420
|
+
if ((result.scope === 'content' || result.scope === 'sync') && !result.retryable) {
|
|
2421
|
+
journal.record(`scoped refusal ${room.locator} ${result.scope} ${result.code}`);
|
|
2422
|
+
await loseRooms([room.locator]);
|
|
2423
|
+
return;
|
|
2424
|
+
}
|
|
2270
2425
|
scopedRefusals.set(room.locator, {
|
|
2271
2426
|
code: result.code,
|
|
2272
2427
|
fields: result.fields,
|
|
@@ -2350,19 +2505,10 @@ export function composeRuntime(options) {
|
|
|
2350
2505
|
await retainModel(local, room, 'collection', modelOf(room.locator));
|
|
2351
2506
|
if (discoveryPaused || authorization === undefined)
|
|
2352
2507
|
return false;
|
|
2353
|
-
|
|
2354
|
-
if (replicas.has(room.locator))
|
|
2355
|
-
progress.complete = false;
|
|
2356
|
-
return false;
|
|
2357
|
-
}
|
|
2358
|
-
return true;
|
|
2508
|
+
return room.replica.admission === 'admitted';
|
|
2359
2509
|
}
|
|
2360
2510
|
async function caughtUp(room, local, progress, live) {
|
|
2361
|
-
|
|
2362
|
-
if (held === undefined || authorization === undefined || !live())
|
|
2363
|
-
return;
|
|
2364
|
-
const behind = [announced.get(room.locator), room.roomVersion].some((later) => later !== undefined && !options.adapter.reached(room.locator, held, later));
|
|
2365
|
-
if (!behind)
|
|
2511
|
+
if (authorization === undefined || !live() || !behind(room))
|
|
2366
2512
|
return;
|
|
2367
2513
|
const withheld = await advance(room, local, authorization, live);
|
|
2368
2514
|
if (withheld !== null)
|
|
@@ -2590,9 +2736,43 @@ export function composeRuntime(options) {
|
|
|
2590
2736
|
options.adapter.roomStream?.reopen();
|
|
2591
2737
|
});
|
|
2592
2738
|
}
|
|
2593
|
-
function
|
|
2739
|
+
function rediscover() {
|
|
2740
|
+
return task(OPENING_LANE, async (live) => {
|
|
2741
|
+
if (!live() || !socketOpen)
|
|
2742
|
+
return;
|
|
2743
|
+
const progress = { complete: true, reachable: true };
|
|
2744
|
+
const gate = discover();
|
|
2745
|
+
moveTo(transferring(status));
|
|
2746
|
+
try {
|
|
2747
|
+
const local = await openLocal();
|
|
2748
|
+
if (!live())
|
|
2749
|
+
return;
|
|
2750
|
+
await ensureAuthorization();
|
|
2751
|
+
if (!live())
|
|
2752
|
+
return;
|
|
2753
|
+
await discoverRooms(local, progress, 'authorized', live);
|
|
2754
|
+
}
|
|
2755
|
+
catch {
|
|
2756
|
+
progress.complete = false;
|
|
2757
|
+
}
|
|
2758
|
+
finally {
|
|
2759
|
+
gate.release();
|
|
2760
|
+
notifyReady();
|
|
2761
|
+
}
|
|
2762
|
+
if (!live())
|
|
2763
|
+
return;
|
|
2764
|
+
if (!progress.complete)
|
|
2765
|
+
complete = false;
|
|
2766
|
+
await rest(progress, live);
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
function closedSocket(revoked, lost) {
|
|
2594
2770
|
const opened = socketOpen;
|
|
2595
2771
|
socketOpen = false;
|
|
2772
|
+
if (lost) {
|
|
2773
|
+
reads.lost();
|
|
2774
|
+
conversations.lost();
|
|
2775
|
+
}
|
|
2596
2776
|
if (revoked) {
|
|
2597
2777
|
void refuse('revoked-authorization');
|
|
2598
2778
|
return;
|
|
@@ -2779,6 +2959,7 @@ export function composeRuntime(options) {
|
|
|
2779
2959
|
progress.complete = false;
|
|
2780
2960
|
return;
|
|
2781
2961
|
}
|
|
2962
|
+
reads.applied();
|
|
2782
2963
|
submitAll();
|
|
2783
2964
|
for (const locator of stale)
|
|
2784
2965
|
if (repairable.has(locator))
|
|
@@ -2791,6 +2972,8 @@ export function composeRuntime(options) {
|
|
|
2791
2972
|
await conversations.catchUp(reading);
|
|
2792
2973
|
if (progress.reachable && reading.reachable)
|
|
2793
2974
|
await conversations.resend(reading);
|
|
2975
|
+
if (progress.reachable)
|
|
2976
|
+
void recovery.attempt('calls', resendCalls);
|
|
2794
2977
|
if (!reading.reachable) {
|
|
2795
2978
|
progress.reachable = false;
|
|
2796
2979
|
resendLater();
|
|
@@ -2903,14 +3086,17 @@ export function composeRuntime(options) {
|
|
|
2903
3086
|
if (event.kind === 'opened') {
|
|
2904
3087
|
socketOpen = true;
|
|
2905
3088
|
generation += 1;
|
|
3089
|
+
reads.opened();
|
|
2906
3090
|
conversations.reopened();
|
|
2907
3091
|
recovery.resume();
|
|
2908
3092
|
void sync('opened');
|
|
2909
3093
|
}
|
|
2910
3094
|
else if (event.kind === 'closed')
|
|
2911
|
-
closedSocket(event.revoked);
|
|
3095
|
+
closedSocket(event.revoked, event.lost);
|
|
2912
3096
|
else if (event.kind === 'opening')
|
|
2913
3097
|
void applyOpening(event.expired);
|
|
3098
|
+
else if (event.kind === 'authority-changed')
|
|
3099
|
+
void rediscover();
|
|
2914
3100
|
else
|
|
2915
3101
|
void applyRoom(event.locator, event.roomVersion);
|
|
2916
3102
|
}, receipts);
|
|
@@ -3035,11 +3221,38 @@ export function composeRuntime(options) {
|
|
|
3035
3221
|
return planOf(input, roomFacts(reach), planReach(reach));
|
|
3036
3222
|
}
|
|
3037
3223
|
function watchPlan(plan, deliver) {
|
|
3038
|
-
|
|
3224
|
+
let seeded = false;
|
|
3225
|
+
let pending = true;
|
|
3226
|
+
const shown = () => {
|
|
3227
|
+
const seed = seeds.get(plan.key);
|
|
3228
|
+
if (seed === undefined || seeded || !pending)
|
|
3229
|
+
return;
|
|
3230
|
+
seeded = true;
|
|
3231
|
+
deliver(seededResult(seed));
|
|
3232
|
+
};
|
|
3233
|
+
const watchers = seedWatchers.get(plan.key) ?? new Set();
|
|
3234
|
+
seedWatchers.set(plan.key, watchers);
|
|
3235
|
+
watchers.add(shown);
|
|
3236
|
+
const stop = readSide.watch(plan, identityOf(plan), () => {
|
|
3039
3237
|
const cover = covered(plan);
|
|
3040
3238
|
awaitPreparation(cover);
|
|
3041
|
-
return cover;
|
|
3042
|
-
},
|
|
3239
|
+
return seedBehind(plan, cover);
|
|
3240
|
+
}, (message) => {
|
|
3241
|
+
const answered = message;
|
|
3242
|
+
pending = whole(answered) && 'pending' in answered.result;
|
|
3243
|
+
if (pending && seeds.has(plan.key)) {
|
|
3244
|
+
shown();
|
|
3245
|
+
return;
|
|
3246
|
+
}
|
|
3247
|
+
seeded = false;
|
|
3248
|
+
deliver(message);
|
|
3249
|
+
});
|
|
3250
|
+
return () => {
|
|
3251
|
+
watchers.delete(shown);
|
|
3252
|
+
if (watchers.size === 0)
|
|
3253
|
+
seedWatchers.delete(plan.key);
|
|
3254
|
+
stop();
|
|
3255
|
+
};
|
|
3043
3256
|
}
|
|
3044
3257
|
async function searched(input, reach) {
|
|
3045
3258
|
const plan = searchPlanOf(input);
|
|
@@ -3083,13 +3296,18 @@ export function composeRuntime(options) {
|
|
|
3083
3296
|
const searchedConversations = named.filter((one) => searchIndex.conversations().has(one));
|
|
3084
3297
|
const seen = searchIndex.changes();
|
|
3085
3298
|
await searchIndex.caughtUp();
|
|
3086
|
-
const selected =
|
|
3299
|
+
const selected = roomsAlone(answering) ? null : await rowsQuery(answering);
|
|
3087
3300
|
if (selected !== null && 'pending' in selected)
|
|
3088
3301
|
continue;
|
|
3089
3302
|
if (searchIndex.changes() !== seen ||
|
|
3090
3303
|
JSON.stringify(covered(answering)) !== JSON.stringify(answered))
|
|
3091
3304
|
continue;
|
|
3092
|
-
const hits = searchIndex.search(plan, selected === null ? null : selected.documents, searchedConversations,
|
|
3305
|
+
const hits = searchIndex.search(plan, selected === null ? null : selected.documents, searchedConversations, answering.rooms === null ? null : new Set(answering.rooms), plan.collection
|
|
3306
|
+
? new Map(answered.coverage.rooms.map(({ room }) => [
|
|
3307
|
+
room,
|
|
3308
|
+
replicas.get(room)?.confirmed.record.typedSelection?.roots ?? [],
|
|
3309
|
+
]))
|
|
3310
|
+
: null);
|
|
3093
3311
|
const coverage = {
|
|
3094
3312
|
rooms: answered.coverage.rooms,
|
|
3095
3313
|
conversations: searchedConversations,
|
|
@@ -3301,7 +3519,7 @@ export function composeRuntime(options) {
|
|
|
3301
3519
|
readReference: readBinaryReference,
|
|
3302
3520
|
},
|
|
3303
3521
|
call(name, input) {
|
|
3304
|
-
return
|
|
3522
|
+
return recoveredAction(name, input);
|
|
3305
3523
|
},
|
|
3306
3524
|
reached(locator, roomVersion, path) {
|
|
3307
3525
|
return path === undefined
|
|
@@ -3349,6 +3567,7 @@ export function composeRuntime(options) {
|
|
|
3349
3567
|
};
|
|
3350
3568
|
return {
|
|
3351
3569
|
md,
|
|
3570
|
+
seed,
|
|
3352
3571
|
stop,
|
|
3353
3572
|
lose: loseRooms,
|
|
3354
3573
|
watch,
|
package/dist/conversation.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ export type ConversationStore = {
|
|
|
89
89
|
known(): boolean;
|
|
90
90
|
reconnected(): void;
|
|
91
91
|
reopened(): void;
|
|
92
|
+
lost(): void;
|
|
92
93
|
watch(conversation: string, options: ConversationOptions, deliver: (view: ConversationView) => void): () => void;
|
|
93
94
|
watchList(deliver: (entries: readonly ConversationEntry[]) => void): () => void;
|
|
94
95
|
watchAgents(deliver: (agents: readonly ConversationAgent[]) => void): () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EAEjB,mBAAmB,EACnB,kBAAkB,EAElB,cAAc,EACd,aAAa,EACb,WAAW,EAEZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAyB,KAAK,SAAS,EAAsB,MAAM,iBAAiB,CAAC;AAE5F,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAW,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAkB,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAElG,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC,CAAC;AA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|
const sending = new Map();
|
|
208
208
|
const behind = new Set();
|
|
209
|
+
const catching = new Map();
|
|
209
210
|
const gaps = new Map();
|
|
210
211
|
const lives = new Map();
|
|
211
212
|
const views = new Map();
|
|
@@ -442,7 +443,7 @@ export function createConversationStore(deps) {
|
|
|
442
443
|
deps.publish(conversationChangeSet(changesOf(conversation, [message]), [conversation]));
|
|
443
444
|
});
|
|
444
445
|
}
|
|
445
|
-
async function readHistories(conversations) {
|
|
446
|
+
async function readHistories(conversations, ended) {
|
|
446
447
|
const generations = new Map(conversations.map((one) => [one, gaps.get(one) ?? 0]));
|
|
447
448
|
let asking = conversations.map((conversation) => ({
|
|
448
449
|
conversation,
|
|
@@ -468,10 +469,33 @@ export function createConversationStore(deps) {
|
|
|
468
469
|
following.push({ conversation: page.conversation, after: page.next });
|
|
469
470
|
}
|
|
470
471
|
}
|
|
472
|
+
for (const { conversation } of asking) {
|
|
473
|
+
if (!following.some((next) => next.conversation === conversation))
|
|
474
|
+
ended(conversation);
|
|
475
|
+
}
|
|
471
476
|
asking = following;
|
|
472
477
|
}
|
|
473
478
|
return null;
|
|
474
479
|
}
|
|
480
|
+
function caughtUp(conversations) {
|
|
481
|
+
const ends = new Map();
|
|
482
|
+
for (const conversation of conversations) {
|
|
483
|
+
const held = new Promise((end) => ends.set(conversation, end));
|
|
484
|
+
catching.set(conversation, held);
|
|
485
|
+
void held.then(() => {
|
|
486
|
+
if (catching.get(conversation) === held)
|
|
487
|
+
catching.delete(conversation);
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
const ended = (conversation) => ends.get(conversation)?.();
|
|
491
|
+
const read = readHistories(conversations, ended);
|
|
492
|
+
const endAll = () => {
|
|
493
|
+
for (const conversation of conversations)
|
|
494
|
+
ended(conversation);
|
|
495
|
+
};
|
|
496
|
+
read.then(endAll, endAll);
|
|
497
|
+
return read;
|
|
498
|
+
}
|
|
475
499
|
function keepPage(conversation, arriving, from, next, generation) {
|
|
476
500
|
return deps.durably(async (local) => {
|
|
477
501
|
if (!replicated.has(conversation))
|
|
@@ -781,12 +805,20 @@ export function createConversationStore(deps) {
|
|
|
781
805
|
await remove(leaving);
|
|
782
806
|
},
|
|
783
807
|
async catchUp(progress) {
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
|
|
808
|
+
const owed = (conversation) => behind.has(conversation) && replicated.has(conversation);
|
|
809
|
+
const read = async (conversations) => {
|
|
810
|
+
if (conversations.length === 0 || deps.closed())
|
|
811
|
+
return;
|
|
812
|
+
const failed = await caughtUp(conversations);
|
|
787
813
|
if (failed?.kind === 'transport-uncertainty')
|
|
788
814
|
progress.reachable = false;
|
|
789
|
-
}
|
|
815
|
+
};
|
|
816
|
+
const asking = [...behind].filter(owed).sort();
|
|
817
|
+
const awaited = asking.filter((conversation) => catching.has(conversation));
|
|
818
|
+
await Promise.all([
|
|
819
|
+
read(asking.filter((conversation) => !catching.has(conversation))),
|
|
820
|
+
Promise.all(awaited.map((conversation) => catching.get(conversation))).then(() => read(awaited.filter((conversation) => owed(conversation) && !catching.has(conversation)))),
|
|
821
|
+
]);
|
|
790
822
|
if (behind.size > 0)
|
|
791
823
|
progress.complete = false;
|
|
792
824
|
},
|
|
@@ -828,6 +860,9 @@ export function createConversationStore(deps) {
|
|
|
828
860
|
reopened() {
|
|
829
861
|
sending.clear();
|
|
830
862
|
},
|
|
863
|
+
lost() {
|
|
864
|
+
catching.clear();
|
|
865
|
+
},
|
|
831
866
|
watch(conversation, options, deliver) {
|
|
832
867
|
const limit = limitOf(options);
|
|
833
868
|
const key = JSON.stringify([conversation, limit ?? null]);
|
package/dist/host.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type MdRuntimeOptions } from './connection.js';
|
|
|
2
2
|
import type { RuntimeDemand } from './acquisition.js';
|
|
3
3
|
import type { PortReach } from './reach.js';
|
|
4
4
|
import type { CapacityCause, CodeAvailability, Persistence, Readiness, SearchObligation } from './readiness.js';
|
|
5
|
+
import type { EntrySeed } from './seed.js';
|
|
5
6
|
import { type RuntimePort } from './wire.js';
|
|
6
7
|
export type MdRuntimeHostOptions = MdRuntimeOptions & {
|
|
7
8
|
deploymentFacts?: unknown;
|
|
@@ -10,12 +11,14 @@ export type AttachedPort = {
|
|
|
10
11
|
detach(): void;
|
|
11
12
|
narrow(reach: PortReach): void;
|
|
12
13
|
readiness(deliver: (readiness: Readiness) => void): () => void;
|
|
14
|
+
answered(queries: readonly unknown[], done: () => void): void;
|
|
13
15
|
code(code: CodeAvailability, capacity: CapacityCause | null): void;
|
|
14
16
|
search(search: SearchObligation): void;
|
|
15
17
|
};
|
|
16
18
|
export type MdRuntimeHost = {
|
|
17
19
|
attach(port: RuntimePort, app: string, release?: string, reach?: PortReach, code?: CodeAvailability, search?: SearchObligation): AttachedPort;
|
|
18
20
|
acquire(demand: RuntimeDemand): void;
|
|
21
|
+
seed(entry: EntrySeed): void;
|
|
19
22
|
persisted(answer: Persistence): void;
|
|
20
23
|
endAuthorization(holder?: string): Promise<void>;
|
|
21
24
|
lose(locators: readonly string[]): Promise<void>;
|
|
@@ -23,6 +26,7 @@ export type MdRuntimeHost = {
|
|
|
23
26
|
};
|
|
24
27
|
export declare function serveMdRuntime(options: MdRuntimeHostOptions): MdRuntimeHost;
|
|
25
28
|
export type { RuntimeDemand } from './acquisition.js';
|
|
29
|
+
export { entrySeedOf, type EntrySeed } from './seed.js';
|
|
26
30
|
export type { PortReach, ReachedDocument } from './reach.js';
|
|
27
31
|
export type { CapacityCause, CodeAvailability, Persistence, SearchObligation, } from './readiness.js';
|
|
28
32
|
export { createRecovery, retryDelay, type Attempt, type Attempted, type AttemptOptions, type Recovery, type RecoveryOptions, } from './recovery.js';
|
package/dist/host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,gBAAgB,EAGtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAA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