@agentshouse/mdruntime 0.1.0-c382efc9f3695 → 0.1.0-c38dcfe165d81
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 +1 -1
- package/dist/adapter.d.ts +23 -9
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +2 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +9 -8
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/client.d.ts +5 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/collection.d.ts +2 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/compile.d.ts +1 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +58 -258
- package/dist/connection.d.ts +5 -5
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +154 -191
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation.d.ts +5 -4
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +25 -36
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +13 -5
- package/dist/host.d.ts +3 -5
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +12 -18
- 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 +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/job.d.ts +14 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +28 -0
- package/dist/live.d.ts +2 -1
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +9 -5
- package/dist/memory.d.ts +3 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +5 -5
- package/dist/messages.d.ts +2 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +15 -16
- package/dist/model.d.ts +1 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -3
- package/dist/observation.d.ts +2 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +7 -2
- package/dist/query.d.ts +3 -208
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/reach.d.ts +6 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +16 -22
- package/dist/react.d.ts +3 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +0 -2
- package/dist/readiness.d.ts.map +1 -1
- package/dist/replica.d.ts +2 -1
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +2 -1
- package/dist/room-draft.d.ts +4 -3
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +65 -52
- package/dist/rows.d.ts +1 -17
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +4 -137
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/store.d.ts +3 -6
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +8 -13
- package/dist/stored.d.ts +0 -1
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +34 -99
- package/dist/tables.d.ts +6 -5
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +8 -12
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +4 -1
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +1 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +1 -0
- package/package.json +2 -2
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -370
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
package/dist/connection.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { parseFrontmatter, roomTarget, target } from '@agentshouse/mdmodel';
|
|
1
|
+
import { identityOf, parseFrontmatter, plain, queryKey, roomTarget, target, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { attachedModel, builtInModel, roomTypesOf } from './attached-model.js';
|
|
3
3
|
import { cached, modelTypes, NO_MODEL, sameModel, } from './model.js';
|
|
4
4
|
import { observing, whole } from './observation.js';
|
|
5
|
-
import {
|
|
5
|
+
import { planWithin, } from './query.js';
|
|
6
6
|
import { createLiveQueries } from './live.js';
|
|
7
7
|
import { seededResult } from './seed.js';
|
|
8
8
|
import { documentKey, roomOfKey } from './rows.js';
|
|
@@ -30,7 +30,7 @@ import { readinessOf, } from './readiness.js';
|
|
|
30
30
|
import { FencedMap } from './fence.js';
|
|
31
31
|
import { sameBinary } from './overlay.js';
|
|
32
32
|
import { paced, ROW_WEIGHT, stepped, yielded } from './turn.js';
|
|
33
|
-
import {
|
|
33
|
+
import { roomDraftRevision } from './identity.js';
|
|
34
34
|
import { ancestors, beneath, normalize } from './paths.js';
|
|
35
35
|
import { openRuntimeStore, } from './store.js';
|
|
36
36
|
import { validatedNeighbourhood } from './validation.js';
|
|
@@ -104,6 +104,7 @@ export function composeRuntime(options) {
|
|
|
104
104
|
const usableWhenHeld = options.usableWhenHeld ?? [];
|
|
105
105
|
const queuesWithoutReplica = new FencedMap(isFenced);
|
|
106
106
|
const pendings = new Map();
|
|
107
|
+
const landedAhead = new Map();
|
|
107
108
|
const seeds = new Map();
|
|
108
109
|
const seedWatchers = new Map();
|
|
109
110
|
const roomDrafts = new FencedMap(isFenced);
|
|
@@ -115,6 +116,7 @@ export function composeRuntime(options) {
|
|
|
115
116
|
const counted = new Map();
|
|
116
117
|
const unreadable = new Set();
|
|
117
118
|
const builtIn = builtInModel(roomTypes);
|
|
119
|
+
const typedPaths = options.adapter.typedPaths ?? [];
|
|
118
120
|
const models = new FencedMap(isFenced);
|
|
119
121
|
const liveModels = new FencedMap(isFenced);
|
|
120
122
|
const invalidModels = new Set();
|
|
@@ -141,7 +143,7 @@ export function composeRuntime(options) {
|
|
|
141
143
|
: modelOf(locator);
|
|
142
144
|
}
|
|
143
145
|
function composed(record) {
|
|
144
|
-
return compositionOf(record, builtIn);
|
|
146
|
+
return compositionOf(record, builtIn, typedPaths);
|
|
145
147
|
}
|
|
146
148
|
function compositionFor(record) {
|
|
147
149
|
return composed({ ...record, model: savedModel(record.locator) });
|
|
@@ -162,7 +164,6 @@ export function composeRuntime(options) {
|
|
|
162
164
|
const repairing = new Set();
|
|
163
165
|
const calling = new Set();
|
|
164
166
|
const repairable = new Map();
|
|
165
|
-
let outcomeRetention = null;
|
|
166
167
|
const answering = new Map();
|
|
167
168
|
let complete = false;
|
|
168
169
|
let recorded = false;
|
|
@@ -191,6 +192,7 @@ export function composeRuntime(options) {
|
|
|
191
192
|
let currencyQueued = null;
|
|
192
193
|
let socketOpen = false;
|
|
193
194
|
let announced = false;
|
|
195
|
+
let missedChange = false;
|
|
194
196
|
const confirmed = new Set();
|
|
195
197
|
let lockGrace = null;
|
|
196
198
|
const lockListeners = new Set();
|
|
@@ -200,6 +202,8 @@ export function composeRuntime(options) {
|
|
|
200
202
|
const serviceModeListeners = new Set();
|
|
201
203
|
let member = null;
|
|
202
204
|
const memberListeners = new Set();
|
|
205
|
+
let authorityChanges = 0;
|
|
206
|
+
const authorityChangeListeners = new Set();
|
|
203
207
|
const unpreparedDemand = new Set();
|
|
204
208
|
const unpreparable = new Set();
|
|
205
209
|
let preparing = false;
|
|
@@ -257,7 +261,6 @@ export function composeRuntime(options) {
|
|
|
257
261
|
full: () => full,
|
|
258
262
|
closed: () => closed,
|
|
259
263
|
unanswered: resendLater,
|
|
260
|
-
expired: (operation) => pastHorizon(operation),
|
|
261
264
|
});
|
|
262
265
|
const journal = createLog();
|
|
263
266
|
const keptFiles = openedFiles(database, isFenced);
|
|
@@ -350,9 +353,9 @@ export function composeRuntime(options) {
|
|
|
350
353
|
return value === undefined ? null : structuredClone(value);
|
|
351
354
|
}
|
|
352
355
|
async function writtenRoomDraft(room, path, revision, input, next) {
|
|
353
|
-
const parts = readParts(input);
|
|
356
|
+
const parts = readParts(input, path);
|
|
354
357
|
if (path === '' || normalize(path) !== path)
|
|
355
|
-
throw runtimeError('room-draft-malformed');
|
|
358
|
+
throw runtimeError('room-draft-malformed', `room-draft-malformed at ${path}: a path inside the Room, such as notes/a.md`);
|
|
356
359
|
const local = await openLocal();
|
|
357
360
|
const current = roomDrafts.get(room)?.get(path);
|
|
358
361
|
if ((current?.revision ?? null) !== revision) {
|
|
@@ -791,7 +794,6 @@ export function composeRuntime(options) {
|
|
|
791
794
|
}
|
|
792
795
|
function readinessFor(port, reach) {
|
|
793
796
|
const required = requiredRooms(reach);
|
|
794
|
-
const search = port.search === 'required';
|
|
795
797
|
const coverage = required.rooms.map((room) => ({ room, state: roomState(room) }));
|
|
796
798
|
const preparing = coverage
|
|
797
799
|
.filter((room) => room.state === 'preparing' && !unpreparable.has(room.room))
|
|
@@ -804,12 +806,11 @@ export function composeRuntime(options) {
|
|
|
804
806
|
listed: required.listed,
|
|
805
807
|
rooms: coverage,
|
|
806
808
|
conversations: conversationCoverage(reach),
|
|
807
|
-
search: search ? 'required' : 'unused',
|
|
808
809
|
},
|
|
809
810
|
persistence,
|
|
810
811
|
connection: connectionOf(),
|
|
811
812
|
house: refusal !== null ? 'refused' : writesHeld() ? 'write-halted' : 'open',
|
|
812
|
-
space: full ? 'full' :
|
|
813
|
+
space: full ? 'full' : null,
|
|
813
814
|
installation: installationOf(coverage),
|
|
814
815
|
lost: storageLoss !== null,
|
|
815
816
|
established: targets[port.target]?.established === true ||
|
|
@@ -1199,8 +1200,10 @@ export function composeRuntime(options) {
|
|
|
1199
1200
|
fences.set(locator, { at: discoveries, erased: false });
|
|
1200
1201
|
lastFenced.set(locator, ++fencings);
|
|
1201
1202
|
confirmed.delete(locator);
|
|
1202
|
-
for (const batch of replicas.get(locator)?.queue ?? queuesWithoutReplica.get(locator) ?? [])
|
|
1203
|
+
for (const batch of replicas.get(locator)?.queue ?? queuesWithoutReplica.get(locator) ?? []) {
|
|
1203
1204
|
pendings.delete(pendingKey(locator, batch.id));
|
|
1205
|
+
landedAhead.delete(pendingKey(locator, batch.id));
|
|
1206
|
+
}
|
|
1204
1207
|
replicas.delete(locator);
|
|
1205
1208
|
highest.delete(locator);
|
|
1206
1209
|
beyondHorizon.delete(locator);
|
|
@@ -1319,6 +1322,7 @@ export function composeRuntime(options) {
|
|
|
1319
1322
|
presentations.set(record.app, record.value);
|
|
1320
1323
|
conversations.hydrate(heldConversations, chatDrafts, held.conversationList, held.conversationCursor);
|
|
1321
1324
|
pendings.clear();
|
|
1325
|
+
landedAhead.clear();
|
|
1322
1326
|
for (const queue of queues) {
|
|
1323
1327
|
for (const { batch, state } of queue.pending) {
|
|
1324
1328
|
pendings.set(pendingKey(queue.locator, batch.id), state);
|
|
@@ -1611,10 +1615,16 @@ export function composeRuntime(options) {
|
|
|
1611
1615
|
? read
|
|
1612
1616
|
: await stepped(slicingWith(read, overrides.set, overrides.removed));
|
|
1613
1617
|
const composition = composed(record);
|
|
1614
|
-
const
|
|
1615
|
-
|
|
1618
|
+
const shown = queue.filter((batch) => {
|
|
1619
|
+
const held = landedAhead.get(pendingKey(locator, batch.id));
|
|
1620
|
+
return (held !== undefined &&
|
|
1621
|
+
Object.entries(held).some(([path, revision]) => confirmedLayer.revisions[path] !== revision));
|
|
1622
|
+
});
|
|
1623
|
+
const unshown = queue.filter((batch) => !shown.includes(batch));
|
|
1624
|
+
const { withdrawn, kept } = await stepped(standing(confirmedLayer, unshown, withdrawable(locator), localSaves, locator, composition));
|
|
1625
|
+
const founded = kept.filter((batch) => !unshown.includes(batch));
|
|
1616
1626
|
const queueChanged = kept.length !== previousQueue.length || founded.length > 0;
|
|
1617
|
-
const unqueued =
|
|
1627
|
+
const unqueued = shown.map((batch) => ({ batch, landed: true }));
|
|
1618
1628
|
for (const batch of withdrawn) {
|
|
1619
1629
|
unqueued.push({ batch, landed: await landedWhole(locator, batch, confirmedLayer) });
|
|
1620
1630
|
}
|
|
@@ -1679,8 +1689,10 @@ export function composeRuntime(options) {
|
|
|
1679
1689
|
commit,
|
|
1680
1690
|
apply: (answer) => {
|
|
1681
1691
|
for (const batch of previousQueue) {
|
|
1682
|
-
if (
|
|
1683
|
-
|
|
1692
|
+
if (staying.has(batch.id))
|
|
1693
|
+
continue;
|
|
1694
|
+
pendings.delete(pendingKey(locator, batch.id));
|
|
1695
|
+
landedAhead.delete(pendingKey(locator, batch.id));
|
|
1684
1696
|
}
|
|
1685
1697
|
for (const draft of written.values())
|
|
1686
1698
|
rememberRoomDraft(draft);
|
|
@@ -1815,7 +1827,7 @@ export function composeRuntime(options) {
|
|
|
1815
1827
|
const replica = replicas.get(locator);
|
|
1816
1828
|
const room = rooms.get(locator);
|
|
1817
1829
|
if (replica === undefined || room === undefined) {
|
|
1818
|
-
throw runtimeError('room
|
|
1830
|
+
throw runtimeError('unknown-room', `Unknown Room ${locator}`);
|
|
1819
1831
|
}
|
|
1820
1832
|
return { local, replica, room };
|
|
1821
1833
|
}
|
|
@@ -2041,7 +2053,7 @@ export function composeRuntime(options) {
|
|
|
2041
2053
|
const target = replicas.get(destination);
|
|
2042
2054
|
const listedRoom = rooms.get(destination);
|
|
2043
2055
|
if (target === undefined || listedRoom === undefined) {
|
|
2044
|
-
throw runtimeError('room
|
|
2056
|
+
throw runtimeError('unknown-room', `Unknown Room ${destination}`);
|
|
2045
2057
|
}
|
|
2046
2058
|
const arriving = await savingIn(target, [], moves.map(({ to }) => to));
|
|
2047
2059
|
const built = await buildMove({
|
|
@@ -2104,10 +2116,10 @@ export function composeRuntime(options) {
|
|
|
2104
2116
|
return { outcome: 'refused', code: 'durable-write', retryable: true };
|
|
2105
2117
|
const { answer, touched } = committedBoth;
|
|
2106
2118
|
if (answer.fenced !== null) {
|
|
2107
|
-
throw runtimeError('room
|
|
2119
|
+
throw runtimeError('unknown-room', `Unknown Room ${answer.fenced}`);
|
|
2108
2120
|
}
|
|
2109
2121
|
if (fences.has(locator) || fences.has(destination)) {
|
|
2110
|
-
throw runtimeError('room
|
|
2122
|
+
throw runtimeError('unknown-room', `Unknown Room ${locator}`);
|
|
2111
2123
|
}
|
|
2112
2124
|
pendings.set(pendingKey(locator, id), {
|
|
2113
2125
|
drafts: saved,
|
|
@@ -2278,10 +2290,10 @@ export function composeRuntime(options) {
|
|
|
2278
2290
|
return { outcome: 'refused', code: 'durable-write', retryable: true };
|
|
2279
2291
|
const { answer, touched } = done;
|
|
2280
2292
|
if (answer.fenced !== null) {
|
|
2281
|
-
throw runtimeError('room
|
|
2293
|
+
throw runtimeError('unknown-room', `Unknown Room ${answer.fenced}`);
|
|
2282
2294
|
}
|
|
2283
2295
|
if (fences.has(locator))
|
|
2284
|
-
throw runtimeError('room
|
|
2296
|
+
throw runtimeError('unknown-room', `Unknown Room ${locator}`);
|
|
2285
2297
|
for (const origin of withdrawn.keys())
|
|
2286
2298
|
pendings.delete(pendingKey(locator, origin));
|
|
2287
2299
|
for (const [id, drafts] of drafted) {
|
|
@@ -2330,7 +2342,7 @@ export function composeRuntime(options) {
|
|
|
2330
2342
|
throw new Error('connection refused');
|
|
2331
2343
|
await local.keepUpload(locator, identifier, upload);
|
|
2332
2344
|
if (fences.has(locator))
|
|
2333
|
-
throw runtimeError('room
|
|
2345
|
+
throw runtimeError('unknown-room', `Unknown Room ${locator}`);
|
|
2334
2346
|
const key = pendingKey(locator, identifier);
|
|
2335
2347
|
pendings.set(key, { ...pendings.get(key), upload });
|
|
2336
2348
|
if (!continuing())
|
|
@@ -2711,10 +2723,6 @@ export function composeRuntime(options) {
|
|
|
2711
2723
|
continue;
|
|
2712
2724
|
if (closed || signal.aborted)
|
|
2713
2725
|
return 'done';
|
|
2714
|
-
if (pastHorizon(held.operation)) {
|
|
2715
|
-
await local.dropCall(held.operation);
|
|
2716
|
-
continue;
|
|
2717
|
-
}
|
|
2718
2726
|
calling.add(held.operation);
|
|
2719
2727
|
try {
|
|
2720
2728
|
if (unsettled(await invokeAction(held.name, held.input)))
|
|
@@ -3140,7 +3148,7 @@ export function composeRuntime(options) {
|
|
|
3140
3148
|
liveQueries.recover();
|
|
3141
3149
|
}
|
|
3142
3150
|
try {
|
|
3143
|
-
const result = await bootstrapRoom(reads, authorized, room, { collection: modelOf(room.locator) }, builtIn, (models, held) => (liveness() ? remodel(room.locator, models, held) : held), liveness, staging(local, liveness), reusable(room, local));
|
|
3151
|
+
const result = await bootstrapRoom(reads, authorized, room, { collection: modelOf(room.locator) }, builtIn, typedPaths, (models, held) => (liveness() ? remodel(room.locator, models, held) : held), liveness, staging(local, liveness), reusable(room, local));
|
|
3144
3152
|
const detail = result.kind === 'staged' ? result.record.roomVersion : result.kind;
|
|
3145
3153
|
journal.record(`transfer bootstrap ${room.locator} ${detail}`);
|
|
3146
3154
|
if (result.kind === 'staged' && older(room.locator, result.record.roomVersion)) {
|
|
@@ -3274,8 +3282,6 @@ export function composeRuntime(options) {
|
|
|
3274
3282
|
}
|
|
3275
3283
|
}
|
|
3276
3284
|
function leaving(batch, result) {
|
|
3277
|
-
if (result.kind === 'expired')
|
|
3278
|
-
return { batch, returned: returnedBy('expired') };
|
|
3279
3285
|
return {
|
|
3280
3286
|
batch,
|
|
3281
3287
|
returned: {
|
|
@@ -3476,15 +3482,10 @@ export function composeRuntime(options) {
|
|
|
3476
3482
|
return;
|
|
3477
3483
|
moveTo({ ...status, ...attention() });
|
|
3478
3484
|
}
|
|
3479
|
-
async function discardHeld(head, room, local, signal) {
|
|
3480
|
-
const partner = partnerOf(head, room.locator);
|
|
3481
|
-
const other = partner === null ? undefined : discovered.get(partner);
|
|
3482
|
-
await discardPending(other === undefined ? [room] : [room, other], local, signal);
|
|
3483
|
-
}
|
|
3484
3485
|
async function submitRoom(room, local, authorized, progress, signal) {
|
|
3485
3486
|
while (continuing() && authorization !== undefined && !signal.aborted) {
|
|
3486
3487
|
const replica = replicas.get(room.locator);
|
|
3487
|
-
const head = replica?.queue
|
|
3488
|
+
const head = replica?.queue.find((batch) => !landedAhead.has(pendingKey(room.locator, batch.id)));
|
|
3488
3489
|
if (replica === undefined || head === undefined)
|
|
3489
3490
|
return 'done';
|
|
3490
3491
|
const state = pendings.get(pendingKey(room.locator, head.id));
|
|
@@ -3511,10 +3512,6 @@ export function composeRuntime(options) {
|
|
|
3511
3512
|
return 'done';
|
|
3512
3513
|
}
|
|
3513
3514
|
const lost = earlier || submission.state === 'submitted';
|
|
3514
|
-
if (lost && pastHorizon(head.id)) {
|
|
3515
|
-
await discardHeld(head, room, local, signal);
|
|
3516
|
-
return 'done';
|
|
3517
|
-
}
|
|
3518
3515
|
let result;
|
|
3519
3516
|
journal.record(`submission ${room.locator} ${head.id}`);
|
|
3520
3517
|
await exclusive(() => mark(local, room.locator, head, { state: 'submitted' }, lost));
|
|
@@ -3592,32 +3589,12 @@ export function composeRuntime(options) {
|
|
|
3592
3589
|
const other = partner === null ? undefined : discovered.get(partner);
|
|
3593
3590
|
if (result.kind === 'conflicted' ||
|
|
3594
3591
|
result.kind === 'rejected' ||
|
|
3595
|
-
result.kind === 'expired' ||
|
|
3596
3592
|
result.kind === 'retryable-refusal') {
|
|
3597
|
-
if (result.kind === 'expired' && lost && result.restored !== true) {
|
|
3598
|
-
journal.record(`outcome ${room.locator} ${head.id} expired`);
|
|
3599
|
-
await discardHeld(head, room, local, signal);
|
|
3600
|
-
return 'done';
|
|
3601
|
-
}
|
|
3602
|
-
if (result.kind === 'expired') {
|
|
3603
|
-
await exclusive(() => mark(local, room.locator, head, { state: 'waiting' }, partner !== null && lost));
|
|
3604
|
-
const there = other === undefined ? null : await advanced(other, local, authorized);
|
|
3605
|
-
if (other !== undefined && there !== null) {
|
|
3606
|
-
await withhold(there, other, local, progress);
|
|
3607
|
-
return 'done';
|
|
3608
|
-
}
|
|
3609
|
-
const withheld = await advanced(room, local, authorized);
|
|
3610
|
-
if (withheld !== null) {
|
|
3611
|
-
await withhold(withheld, room, local, progress);
|
|
3612
|
-
return 'done';
|
|
3613
|
-
}
|
|
3614
|
-
}
|
|
3615
3593
|
journal.record(`outcome ${room.locator} ${head.id} ${result.kind}` +
|
|
3616
3594
|
(result.kind === 'conflicted' && result.roomVersion !== undefined
|
|
3617
3595
|
? ` ${result.roomVersion}`
|
|
3618
3596
|
: ''));
|
|
3619
|
-
|
|
3620
|
-
journal.record(`refusal ${result.kind} ${result.code}`);
|
|
3597
|
+
journal.record(`refusal ${result.kind} ${result.code}`);
|
|
3621
3598
|
}
|
|
3622
3599
|
if (result.kind === 'retryable-refusal') {
|
|
3623
3600
|
const reset = result.reset;
|
|
@@ -3625,7 +3602,7 @@ export function composeRuntime(options) {
|
|
|
3625
3602
|
await exclusive(() => mark(local, room.locator, head, reset === undefined ? { state: 'waiting' } : { state: 'reset', reset }, lost));
|
|
3626
3603
|
return reset === undefined ? 'again' : { at: Date.parse(reset) };
|
|
3627
3604
|
}
|
|
3628
|
-
if (result.kind === 'conflicted' || result.kind === 'rejected'
|
|
3605
|
+
if (result.kind === 'conflicted' || result.kind === 'rejected') {
|
|
3629
3606
|
const left = leaving(head, result);
|
|
3630
3607
|
const refreshed = async () => ({
|
|
3631
3608
|
there: other === undefined ? null : await advanced(other, local, authorized),
|
|
@@ -3649,16 +3626,19 @@ export function composeRuntime(options) {
|
|
|
3649
3626
|
return;
|
|
3650
3627
|
}
|
|
3651
3628
|
const confirmedLayer = await sliceAt(current.record, 'confirmed', [head]);
|
|
3652
|
-
const held =
|
|
3653
|
-
(await landedWhole(room.locator, head, confirmedLayer))
|
|
3654
|
-
|
|
3655
|
-
|
|
3629
|
+
const held = result.kind === 'conflicted' &&
|
|
3630
|
+
(await landedWhole(room.locator, head, confirmedLayer, result.affected));
|
|
3631
|
+
if (held &&
|
|
3632
|
+
result.kind === 'conflicted' &&
|
|
3633
|
+
partner === null &&
|
|
3634
|
+
!landed(head, confirmedLayer)) {
|
|
3635
|
+
landedAhead.set(pendingKey(room.locator, head.id), Object.fromEntries([...touchedBy([head])].map((path) => [path, confirmedLayer.revisions[path]])));
|
|
3636
|
+
return;
|
|
3637
|
+
}
|
|
3656
3638
|
publishChangeSet(await settle(local, room.locator, current, current.record, current.queue.filter((batch) => batch.id !== head.id), { leaving: [held ? { ...left, returned: null } : left] }));
|
|
3657
3639
|
await unpair(local);
|
|
3658
3640
|
moveTo({ ...status, ...attention() });
|
|
3659
3641
|
});
|
|
3660
|
-
if (result.kind === 'expired')
|
|
3661
|
-
continue;
|
|
3662
3642
|
const { there, here } = judged ?? (await refreshed());
|
|
3663
3643
|
if (other !== undefined && there !== null)
|
|
3664
3644
|
await withhold(there, other, local, progress);
|
|
@@ -3678,67 +3658,6 @@ export function composeRuntime(options) {
|
|
|
3678
3658
|
}
|
|
3679
3659
|
return 'done';
|
|
3680
3660
|
}
|
|
3681
|
-
function pastHorizon(identity) {
|
|
3682
|
-
return (outcomeRetention !== null && identityTime(identity) + outcomeRetention * 1000 <= Date.now());
|
|
3683
|
-
}
|
|
3684
|
-
async function discardPending(rooms, local, signal) {
|
|
3685
|
-
const discarded = await exclusive(async () => {
|
|
3686
|
-
const held = rooms
|
|
3687
|
-
.filter(({ locator }) => !fences.has(locator))
|
|
3688
|
-
.map((room) => ({
|
|
3689
|
-
room,
|
|
3690
|
-
before: replicas.get(room.locator),
|
|
3691
|
-
queue: queueIn(room.locator),
|
|
3692
|
-
}));
|
|
3693
|
-
if (held.length === 0)
|
|
3694
|
-
return [];
|
|
3695
|
-
const answer = await local.commit({
|
|
3696
|
-
rooms: held.flatMap(({ room, before }) => before === undefined
|
|
3697
|
-
? []
|
|
3698
|
-
: [
|
|
3699
|
-
{
|
|
3700
|
-
locator: room.locator,
|
|
3701
|
-
key: before.record.key,
|
|
3702
|
-
roots: before.record.typedSelection?.roots ?? [],
|
|
3703
|
-
composed: composedOf(composed(before.record)),
|
|
3704
|
-
overlay: { set: [], cleared: [...before.overlaid] },
|
|
3705
|
-
},
|
|
3706
|
-
]),
|
|
3707
|
-
discards: held.map(({ room }) => room.locator),
|
|
3708
|
-
});
|
|
3709
|
-
for (const { room, before, queue } of held) {
|
|
3710
|
-
const { locator } = room;
|
|
3711
|
-
lastFenced.set(locator, ++fencings);
|
|
3712
|
-
for (const batch of queue)
|
|
3713
|
-
pendings.delete(pendingKey(locator, batch.id));
|
|
3714
|
-
queuesWithoutReplica.delete(locator);
|
|
3715
|
-
if (before !== undefined) {
|
|
3716
|
-
replicas.set(locator, {
|
|
3717
|
-
...before,
|
|
3718
|
-
queue: [],
|
|
3719
|
-
overlaid: new Set(),
|
|
3720
|
-
count: answer.counts[locator] ?? before.count,
|
|
3721
|
-
});
|
|
3722
|
-
}
|
|
3723
|
-
journal.record(`room discarded ${locator}`);
|
|
3724
|
-
}
|
|
3725
|
-
publishChangeSet(mergeChangeSets(held.map(({ room }) => changeSet(room.locator, {
|
|
3726
|
-
documents: answer.changed[room.locator] ?? [],
|
|
3727
|
-
queue: true,
|
|
3728
|
-
}))));
|
|
3729
|
-
moveTo({ ...status, ...attention() });
|
|
3730
|
-
return held.map(({ room }) => room);
|
|
3731
|
-
});
|
|
3732
|
-
for (const room of discarded) {
|
|
3733
|
-
if (signal.aborted)
|
|
3734
|
-
return;
|
|
3735
|
-
const progress = { complete: true, reachable: true };
|
|
3736
|
-
await roomTask(room.locator, (live) => reload(room, local, progress, live));
|
|
3737
|
-
if (signal.aborted)
|
|
3738
|
-
return;
|
|
3739
|
-
await rest(progress);
|
|
3740
|
-
}
|
|
3741
|
-
}
|
|
3742
3661
|
function awaitingAnswer(locator) {
|
|
3743
3662
|
answering.get(locator)?.release();
|
|
3744
3663
|
let release = () => { };
|
|
@@ -3760,6 +3679,30 @@ export function composeRuntime(options) {
|
|
|
3760
3679
|
JSON.stringify(held.replica) === JSON.stringify(room.replica) &&
|
|
3761
3680
|
JSON.stringify(held.typedSelection) === JSON.stringify(room.typedSelection ?? null)));
|
|
3762
3681
|
}
|
|
3682
|
+
async function keepNaming(local, room) {
|
|
3683
|
+
const held = replicas.get(room.locator)?.record;
|
|
3684
|
+
if (held === undefined || (held.name === room.name && held.handle === room.handle))
|
|
3685
|
+
return;
|
|
3686
|
+
await exclusive(async () => {
|
|
3687
|
+
if (!continuing())
|
|
3688
|
+
return;
|
|
3689
|
+
const replica = replicas.get(room.locator);
|
|
3690
|
+
if (replica === undefined)
|
|
3691
|
+
return;
|
|
3692
|
+
const record = { ...replica.record, name: room.name, handle: room.handle };
|
|
3693
|
+
await local.commit({
|
|
3694
|
+
rooms: [
|
|
3695
|
+
{
|
|
3696
|
+
locator: room.locator,
|
|
3697
|
+
key: record.key,
|
|
3698
|
+
record: storedRecord(record),
|
|
3699
|
+
composed: composedOf(composed(record)),
|
|
3700
|
+
},
|
|
3701
|
+
],
|
|
3702
|
+
});
|
|
3703
|
+
replicas.set(room.locator, { ...replica, record });
|
|
3704
|
+
});
|
|
3705
|
+
}
|
|
3763
3706
|
async function retainModel(local, room, next) {
|
|
3764
3707
|
const key = room.locator;
|
|
3765
3708
|
const previous = modelOf(room.locator);
|
|
@@ -3777,6 +3720,8 @@ export function composeRuntime(options) {
|
|
|
3777
3720
|
if (held !== undefined) {
|
|
3778
3721
|
const record = {
|
|
3779
3722
|
...held.record,
|
|
3723
|
+
name: room.name,
|
|
3724
|
+
handle: room.handle,
|
|
3780
3725
|
operations: room.operations,
|
|
3781
3726
|
replica: room.replica,
|
|
3782
3727
|
typedSelection: room.typedSelection ?? null,
|
|
@@ -3906,6 +3851,8 @@ export function composeRuntime(options) {
|
|
|
3906
3851
|
}
|
|
3907
3852
|
if (prior !== undefined)
|
|
3908
3853
|
await retainModel(local, room, modelOf(room.locator));
|
|
3854
|
+
if (prior !== undefined)
|
|
3855
|
+
await keepNaming(local, room);
|
|
3909
3856
|
if (discoveryPaused || authorization === undefined)
|
|
3910
3857
|
return false;
|
|
3911
3858
|
return room.replica.admission === 'admitted';
|
|
@@ -4043,7 +3990,6 @@ export function composeRuntime(options) {
|
|
|
4043
3990
|
}
|
|
4044
3991
|
const previousCapabilities = capabilities;
|
|
4045
3992
|
capabilities = result.capabilities;
|
|
4046
|
-
outcomeRetention = result.retention.outcome;
|
|
4047
3993
|
notifyReady();
|
|
4048
3994
|
if (JSON.stringify(result.providerLimits) !== JSON.stringify(limits) ||
|
|
4049
3995
|
JSON.stringify(result.capabilities) !== JSON.stringify(previousCapabilities)) {
|
|
@@ -4182,10 +4128,16 @@ export function composeRuntime(options) {
|
|
|
4182
4128
|
await finishOpening(progress, live);
|
|
4183
4129
|
});
|
|
4184
4130
|
}
|
|
4131
|
+
function countAuthorityChange() {
|
|
4132
|
+
authorityChanges += 1;
|
|
4133
|
+
for (const listener of authorityChangeListeners)
|
|
4134
|
+
listener(authorityChanges);
|
|
4135
|
+
}
|
|
4185
4136
|
function changeAuthority(change) {
|
|
4186
4137
|
return task(OPENING_LANE, async (live) => {
|
|
4187
4138
|
if (!live() || !announced)
|
|
4188
4139
|
return;
|
|
4140
|
+
countAuthorityChange();
|
|
4189
4141
|
const progress = { complete: true, reachable: true };
|
|
4190
4142
|
moveTo(transferring(status));
|
|
4191
4143
|
try {
|
|
@@ -4214,11 +4166,12 @@ export function composeRuntime(options) {
|
|
|
4214
4166
|
await rest(progress, live);
|
|
4215
4167
|
});
|
|
4216
4168
|
}
|
|
4217
|
-
function closedSocket(revoked, lost) {
|
|
4169
|
+
function closedSocket(revoked, lost, authorityChanged) {
|
|
4218
4170
|
notifyReady();
|
|
4219
4171
|
const opened = announced;
|
|
4220
4172
|
socketOpen = false;
|
|
4221
4173
|
announced = false;
|
|
4174
|
+
missedChange ||= authorityChanged;
|
|
4222
4175
|
handed = false;
|
|
4223
4176
|
naming = 0;
|
|
4224
4177
|
connectionLost();
|
|
@@ -4234,7 +4187,7 @@ export function composeRuntime(options) {
|
|
|
4234
4187
|
moveTo({
|
|
4235
4188
|
...status,
|
|
4236
4189
|
state: status.state === 'synced' ? 'syncing' : status.state,
|
|
4237
|
-
providerUnreachable: status.providerUnreachable || !opened,
|
|
4190
|
+
providerUnreachable: status.providerUnreachable || (!opened && lost),
|
|
4238
4191
|
});
|
|
4239
4192
|
void closing(opened);
|
|
4240
4193
|
}
|
|
@@ -4564,10 +4517,14 @@ export function composeRuntime(options) {
|
|
|
4564
4517
|
if (!socketOpen)
|
|
4565
4518
|
return;
|
|
4566
4519
|
announced = true;
|
|
4520
|
+
if (missedChange) {
|
|
4521
|
+
missedChange = false;
|
|
4522
|
+
countAuthorityChange();
|
|
4523
|
+
}
|
|
4567
4524
|
void sync('opened', event.discovery);
|
|
4568
4525
|
}
|
|
4569
4526
|
else if (event.kind === 'closed')
|
|
4570
|
-
closedSocket(event.revoked, event.lost);
|
|
4527
|
+
closedSocket(event.revoked, event.lost, event.authorityChanged);
|
|
4571
4528
|
else if (event.kind === 'caught-up')
|
|
4572
4529
|
void caughtUpRooms(event.expired);
|
|
4573
4530
|
else if (event.kind === 'authority-changed')
|
|
@@ -4664,6 +4621,7 @@ export function composeRuntime(options) {
|
|
|
4664
4621
|
statusListeners.clear();
|
|
4665
4622
|
serviceModeListeners.clear();
|
|
4666
4623
|
memberListeners.clear();
|
|
4624
|
+
authorityChangeListeners.clear();
|
|
4667
4625
|
liveQueries.close();
|
|
4668
4626
|
queueSubscriptions.clear();
|
|
4669
4627
|
roomDraftListeners.clear();
|
|
@@ -4692,13 +4650,13 @@ export function composeRuntime(options) {
|
|
|
4692
4650
|
if (options.adapter.roomStream === undefined)
|
|
4693
4651
|
void sync('unstreamed', null);
|
|
4694
4652
|
function planned(input, reach) {
|
|
4695
|
-
const plan =
|
|
4653
|
+
const plan = planWithin(input, roomFacts(reach), planReach(reach));
|
|
4696
4654
|
const named = plan.paths !== null &&
|
|
4697
4655
|
plan.rooms !== null &&
|
|
4698
4656
|
plan.paths.length * plan.rooms.length <= MAXIMUM_WINDOW;
|
|
4699
4657
|
return plan.limit === null && named ? plan : { ...plan, limit: capped(plan.limit) };
|
|
4700
4658
|
}
|
|
4701
|
-
function watchPlan(plan, deliver) {
|
|
4659
|
+
function watchPlan(plan, deliver, fail) {
|
|
4702
4660
|
let seeded = false;
|
|
4703
4661
|
let pending = true;
|
|
4704
4662
|
const shown = () => {
|
|
@@ -4724,7 +4682,7 @@ export function composeRuntime(options) {
|
|
|
4724
4682
|
}
|
|
4725
4683
|
seeded = false;
|
|
4726
4684
|
deliver(message);
|
|
4727
|
-
});
|
|
4685
|
+
}, fail);
|
|
4728
4686
|
return () => {
|
|
4729
4687
|
watchers.delete(shown);
|
|
4730
4688
|
if (watchers.size === 0)
|
|
@@ -4732,61 +4690,59 @@ export function composeRuntime(options) {
|
|
|
4732
4690
|
stop();
|
|
4733
4691
|
};
|
|
4734
4692
|
}
|
|
4735
|
-
async function searched(input, reach
|
|
4693
|
+
async function searched(input, reach) {
|
|
4736
4694
|
const asked = searchPlanOf(input);
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
const cover = covered(filter);
|
|
4746
|
-
awaitPreparation(cover);
|
|
4747
|
-
const pending = [...unlocking, ...('pending' in cover ? cover.pending : [])];
|
|
4748
|
-
const complete = pending.length === 0 && !('pending' in cover);
|
|
4749
|
-
const awaited = new Set('pending' in cover ? cover.pending.map(({ room }) => room) : []);
|
|
4750
|
-
const answering = complete
|
|
4751
|
-
? filter
|
|
4752
|
-
: { ...filter, rooms: reachedRooms(filter).filter((room) => !awaited.has(room)) };
|
|
4753
|
-
const answered = covered(answering);
|
|
4754
|
-
if ('pending' in answered)
|
|
4755
|
-
continue;
|
|
4756
|
-
const listed = conversations.searchable();
|
|
4757
|
-
const named = reach !== null && !reach.conversations
|
|
4758
|
-
? []
|
|
4759
|
-
: (asked.conversations ?? listed).filter((one) => listed.includes(one) && conversations.acquired(one));
|
|
4760
|
-
const hits = await (await openLocal()).search({
|
|
4761
|
-
text: asked.text,
|
|
4762
|
-
limit: capped(asked.limit),
|
|
4763
|
-
after: asked.after,
|
|
4764
|
-
total: asked.total,
|
|
4765
|
-
documents: {
|
|
4766
|
-
plan: answering,
|
|
4767
|
-
rooms: answered.rooms,
|
|
4768
|
-
beneath: asked.collection
|
|
4769
|
-
? answered.rooms.map(({ locator, key }) => ({
|
|
4770
|
-
key,
|
|
4771
|
-
roots: replicas.get(locator)?.record.typedSelection?.roots ?? [],
|
|
4772
|
-
}))
|
|
4773
|
-
: [],
|
|
4774
|
-
},
|
|
4775
|
-
conversations: named,
|
|
4776
|
-
});
|
|
4777
|
-
if (JSON.stringify(covered(answering)) !== JSON.stringify(answered))
|
|
4778
|
-
continue;
|
|
4779
|
-
const coverage = {
|
|
4780
|
-
rooms: answered.coverage.rooms,
|
|
4781
|
-
conversations: named,
|
|
4782
|
-
overlay: answered.coverage.overlay,
|
|
4695
|
+
await ready;
|
|
4696
|
+
const search = options.adapter.search;
|
|
4697
|
+
if (search === undefined) {
|
|
4698
|
+
return {
|
|
4699
|
+
kind: 'undeclared',
|
|
4700
|
+
code: 'action-undeclared',
|
|
4701
|
+
fields: { name: 'search' },
|
|
4702
|
+
retryable: false,
|
|
4783
4703
|
};
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4704
|
+
}
|
|
4705
|
+
if (closed || refusal !== null || connectionOf() !== 'connected')
|
|
4706
|
+
return OFFLINE;
|
|
4707
|
+
const reached = reach === null ? null : new Set(reach.rooms);
|
|
4708
|
+
const named = asked.rooms === null
|
|
4709
|
+
? reached === null
|
|
4710
|
+
? null
|
|
4711
|
+
: [...reached]
|
|
4712
|
+
: asked.rooms.filter((room) => reached === null || reached.has(room));
|
|
4713
|
+
const rooms = named === null ? null : named.filter((room) => replicas.has(room)).sort();
|
|
4714
|
+
if (rooms !== null && rooms.length === 0)
|
|
4715
|
+
return { kind: 'found', documents: [] };
|
|
4716
|
+
try {
|
|
4717
|
+
await ensureAuthorization();
|
|
4718
|
+
}
|
|
4719
|
+
catch {
|
|
4720
|
+
return UNCERTAIN;
|
|
4721
|
+
}
|
|
4722
|
+
if (closed || authorization === undefined || refusal !== null)
|
|
4723
|
+
return UNCERTAIN;
|
|
4724
|
+
journal.record('transfer search');
|
|
4725
|
+
try {
|
|
4726
|
+
const result = await search(authorization, { text: asked.text, rooms });
|
|
4727
|
+
if (result.kind === 'revoked-authorization')
|
|
4728
|
+
await refuse('revoked-authorization');
|
|
4729
|
+
journal.record(`outcome search ${result.kind}`);
|
|
4730
|
+
if (result.kind === 'rejected')
|
|
4731
|
+
return result;
|
|
4732
|
+
if (result.kind !== 'found')
|
|
4733
|
+
return failure(result);
|
|
4734
|
+
const kept = rooms === null ? null : new Set(rooms);
|
|
4735
|
+
return {
|
|
4736
|
+
kind: 'found',
|
|
4737
|
+
documents: result.documents.filter((hit) => kept === null || kept.has(hit.room)),
|
|
4738
|
+
};
|
|
4739
|
+
}
|
|
4740
|
+
catch {
|
|
4741
|
+
journal.record('outcome search transport-uncertainty');
|
|
4742
|
+
return UNCERTAIN;
|
|
4787
4743
|
}
|
|
4788
4744
|
}
|
|
4789
|
-
const watch = (topic, input, deliver) => {
|
|
4745
|
+
const watch = (topic, input, deliver, fail) => {
|
|
4790
4746
|
if (topic === 'room-drafts') {
|
|
4791
4747
|
const listener = { notify: deliver, ready: false };
|
|
4792
4748
|
roomDraftListeners.add(listener);
|
|
@@ -4835,7 +4791,7 @@ export function composeRuntime(options) {
|
|
|
4835
4791
|
};
|
|
4836
4792
|
}
|
|
4837
4793
|
if (topic === 'readiness') {
|
|
4838
|
-
return watchReadiness({ target: '', code: 'stored'
|
|
4794
|
+
return watchReadiness({ target: '', code: 'stored' }, null, deliver);
|
|
4839
4795
|
}
|
|
4840
4796
|
if (topic === 'rooms') {
|
|
4841
4797
|
unlistedRooms.add(deliver);
|
|
@@ -4880,6 +4836,13 @@ export function composeRuntime(options) {
|
|
|
4880
4836
|
memberListeners.delete(deliver);
|
|
4881
4837
|
};
|
|
4882
4838
|
}
|
|
4839
|
+
if (topic === 'authority-changes') {
|
|
4840
|
+
authorityChangeListeners.add(deliver);
|
|
4841
|
+
deliver(authorityChanges);
|
|
4842
|
+
return () => {
|
|
4843
|
+
authorityChangeListeners.delete(deliver);
|
|
4844
|
+
};
|
|
4845
|
+
}
|
|
4883
4846
|
if (topic === 'queue') {
|
|
4884
4847
|
const queue = { locator: input[0], notify: deliver };
|
|
4885
4848
|
queueSubscriptions.add(queue);
|
|
@@ -4888,7 +4851,7 @@ export function composeRuntime(options) {
|
|
|
4888
4851
|
queueSubscriptions.delete(queue);
|
|
4889
4852
|
};
|
|
4890
4853
|
}
|
|
4891
|
-
return watchPlan(planned(input[0], null), deliver);
|
|
4854
|
+
return watchPlan(planned(input[0], null), deliver, fail);
|
|
4892
4855
|
};
|
|
4893
4856
|
const md = {
|
|
4894
4857
|
loaded() {
|
|
@@ -4908,7 +4871,7 @@ export function composeRuntime(options) {
|
|
|
4908
4871
|
});
|
|
4909
4872
|
},
|
|
4910
4873
|
query: ((input) => rowsQuery(planned(input, null))),
|
|
4911
|
-
search: (input) => searched(input, null
|
|
4874
|
+
search: (input) => searched(input, null),
|
|
4912
4875
|
types(locator) {
|
|
4913
4876
|
return {
|
|
4914
4877
|
collection: modelTypes(modelOf(locator)),
|