@agentshouse/mdruntime 0.1.0-c8eac46931574 → 0.1.0-c8f07dbee1c62
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/acceptance.d.ts +6 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +389 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +250 -0
- package/dist/adapter.d.ts +23 -25
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +21 -56
- package/dist/bootstrap.d.ts +8 -4
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +209 -78
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/chat-types.d.ts +5 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +13 -0
- package/dist/client.d.ts +17 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -0
- package/dist/collection.d.ts +2 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/compile.d.ts +7 -7
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +229 -301
- package/dist/connection.d.ts +5 -141
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +98 -5279
- 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 +53 -0
- package/dist/conversation.d.ts +16 -6
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +364 -212
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -0
- package/dist/durability.d.ts +15 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +17 -8
- package/dist/figures.d.ts +48 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +2 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +13 -13
- 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 +19 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +560 -0
- package/dist/job.d.ts +26 -1
- package/dist/job.d.ts.map +1 -1
- package/dist/job.js +41 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +267 -0
- package/dist/listing.d.ts +53 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +175 -0
- package/dist/live.d.ts +4 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +53 -15
- package/dist/locks.d.ts +9 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +61 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +61 -0
- package/dist/memory.d.ts +4 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +43 -4
- package/dist/messages.d.ts +25 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +84 -5
- package/dist/model.d.ts +2 -9
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -9
- package/dist/models.d.ts +14 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +193 -0
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +56 -0
- package/dist/outcome.d.ts +4 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -0
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +11 -0
- package/dist/parts.d.ts +59 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +118 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +226 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +272 -0
- package/dist/query.d.ts +13 -212
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -524
- package/dist/questions.d.ts +34 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +122 -0
- package/dist/reach.d.ts +9 -8
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +160 -107
- package/dist/react.d.ts +9 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/reads.d.ts +36 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +150 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +9 -1
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +8 -20
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +56 -0
- package/dist/replica.d.ts +8 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +52 -19
- package/dist/room-draft.d.ts +2 -2
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +216 -0
- package/dist/rows.d.ts +14 -22
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +48 -189
- package/dist/runtime.d.ts +42 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +13 -10
- package/dist/saves.d.ts +70 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +1004 -0
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +1 -1
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -0
- package/dist/shared.d.ts +1 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +9 -5
- package/dist/shown.d.ts +31 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +294 -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/lanes.d.ts +20 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +77 -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/rooms.d.ts +43 -0
- package/dist/socket/rooms.d.ts.map +1 -0
- package/dist/socket/rooms.js +90 -0
- package/dist/socket/session.d.ts +39 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +70 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +175 -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 +0 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- 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/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -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/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +43 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +57 -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 +107 -153
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +143 -396
- package/dist/stored.d.ts +58 -64
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +244 -156
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +222 -0
- package/dist/sync.d.ts +20 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +531 -0
- package/dist/tables.d.ts +111 -49
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +209 -54
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +7 -4
- 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 +16 -1
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +6 -0
- package/package.json +2 -2
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/phrase.d.ts +0 -3
- package/dist/phrase.d.ts.map +0 -1
- package/dist/phrase.js +0 -8
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Discovery, DiscoveredRoom, Member } from './adapter.js';
|
|
2
|
+
import type { Runtime } from './runtime.js';
|
|
3
|
+
import type { Live } from './socket.js';
|
|
4
|
+
import type { CycleProgress } from './status.js';
|
|
5
|
+
import type { RuntimeStore } from './store.js';
|
|
6
|
+
export declare function malformed(listed: readonly DiscoveredRoom[]): string | null;
|
|
7
|
+
export declare function applyDiscovery(runtime: Runtime, found: readonly DiscoveredRoom[], started: number, left?: readonly string[]): Promise<readonly DiscoveredRoom[]>;
|
|
8
|
+
export declare function signIn(runtime: Runtime, local: RuntimeStore, signedIn: Member | null): Promise<void>;
|
|
9
|
+
export declare function discoverRooms(runtime: Runtime, local: RuntimeStore, progress: CycleProgress, live: Live, found: Discovery | null): Promise<readonly DiscoveredRoom[] | null>;
|
|
10
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EACT,cAAc,EACd,MAAM,EAEP,MAAM,cAAc,CAAC;AAQtB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAkB/C,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,GAAG,IAAI,CAsB1E;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,GACvB,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CAoEpC;AAUD,wBAAsB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,iBAI1F;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,GAAG,IAAI,GACtB,OAAO,CAAC,SAAS,cAAc,EAAE,GAAG,IAAI,CAAC,CA+D3C"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { validRoot } from './collection.js';
|
|
2
|
+
import { admitted, list, listHeld } from './listing.js';
|
|
3
|
+
import { confirmLocks, lockedRooms, relocked } from './locks.js';
|
|
4
|
+
import { loseRooms } from './lost.js';
|
|
5
|
+
import { cachedModels } from './models.js';
|
|
6
|
+
import { beneath } from './paths.js';
|
|
7
|
+
import { refuse } from './refusal.js';
|
|
8
|
+
import { emitMember, emitRefusal, emitRooms, moveTo, transferring } from './shown.js';
|
|
9
|
+
function within(root, path) {
|
|
10
|
+
return root === '' || beneath(root, path);
|
|
11
|
+
}
|
|
12
|
+
function declaredSelection(room) {
|
|
13
|
+
const selection = room.typedSelection;
|
|
14
|
+
if (selection === undefined)
|
|
15
|
+
return true;
|
|
16
|
+
if (!Array.isArray(selection.roots) || selection.roots.length === 0)
|
|
17
|
+
return false;
|
|
18
|
+
return selection.roots.every((root, index) => validRoot(root) &&
|
|
19
|
+
root !== '' &&
|
|
20
|
+
selection.roots.every((other, at) => at === index || !within(other, root)));
|
|
21
|
+
}
|
|
22
|
+
export function malformed(listed) {
|
|
23
|
+
for (const room of listed) {
|
|
24
|
+
if (room.operations === undefined ||
|
|
25
|
+
!['write', 'erase'].every((operation) => Array.isArray(room.operations[operation]) &&
|
|
26
|
+
room.operations[operation].every((scope) => typeof scope === 'string')) ||
|
|
27
|
+
room.replica === undefined ||
|
|
28
|
+
typeof room.replica.selection !== 'string' ||
|
|
29
|
+
room.replica.selection.length === 0 ||
|
|
30
|
+
!['admitted', 'unavailable'].includes(room.replica.admission) ||
|
|
31
|
+
!['locked', 'open'].includes(room.replica.offline)) {
|
|
32
|
+
return `invalid model or replica declaration ${room.locator}`;
|
|
33
|
+
}
|
|
34
|
+
if (!declaredSelection(room))
|
|
35
|
+
return `invalid typed selection declaration ${room.locator}`;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
export async function applyDiscovery(runtime, found, started, left) {
|
|
40
|
+
const { store, socket } = runtime;
|
|
41
|
+
const { rooms } = socket;
|
|
42
|
+
const lockedBefore = await lockedRooms(runtime);
|
|
43
|
+
const local = await store.open();
|
|
44
|
+
const stillFenced = new Set(await local.fences());
|
|
45
|
+
const relisting = found
|
|
46
|
+
.map(({ locator }) => locator)
|
|
47
|
+
.filter((locator) => {
|
|
48
|
+
const fence = store.fences.of(locator);
|
|
49
|
+
return stillFenced.has(locator) && (fence === undefined || fence.at < started);
|
|
50
|
+
});
|
|
51
|
+
const relisted = relisting.length === 0
|
|
52
|
+
? new Set()
|
|
53
|
+
: await store.durably((held) => held.unfence(relisting));
|
|
54
|
+
for (const { locator } of found) {
|
|
55
|
+
const fence = store.fences.of(locator);
|
|
56
|
+
if (fence === undefined || fence.at >= started)
|
|
57
|
+
continue;
|
|
58
|
+
if (relisted.has(locator) || (!stillFenced.has(locator) && !fence.written)) {
|
|
59
|
+
store.fences.lift(locator);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const kept = await local.held();
|
|
63
|
+
await loseRooms(runtime, found
|
|
64
|
+
.filter((room) => room.replica.admission !== 'admitted' &&
|
|
65
|
+
(kept.held.has(room.locator) || store.installs.of(room.locator).transfer !== null))
|
|
66
|
+
.map((room) => room.locator));
|
|
67
|
+
const listed = found.filter(({ locator }) => !store.fences.has(locator) && (!stillFenced.has(locator) || relisted.has(locator)));
|
|
68
|
+
const listedLocatorsNow = new Set(listed.map((room) => room.locator));
|
|
69
|
+
for (const locator of listedLocatorsNow)
|
|
70
|
+
rooms.stand(locator, { refusal: null });
|
|
71
|
+
if (left === undefined)
|
|
72
|
+
rooms.undiscoverAll();
|
|
73
|
+
for (const room of listed)
|
|
74
|
+
rooms.discover(room);
|
|
75
|
+
const named = new Set(found.map((room) => room.locator));
|
|
76
|
+
await loseRooms(runtime, left ??
|
|
77
|
+
[
|
|
78
|
+
...new Set([
|
|
79
|
+
...rooms.declarations().keys(),
|
|
80
|
+
...kept.held,
|
|
81
|
+
...store.installs.transferring(),
|
|
82
|
+
]),
|
|
83
|
+
].filter((locator) => !named.has(locator)));
|
|
84
|
+
const held = await store.rooms(listed.map((room) => room.locator));
|
|
85
|
+
for (const room of listed) {
|
|
86
|
+
const record = held.get(room.locator)?.record;
|
|
87
|
+
if (record !== undefined && record.replica.selection !== room.replica.selection) {
|
|
88
|
+
listHeld(runtime, room.locator);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
list(runtime, room, admitted(runtime, room));
|
|
92
|
+
}
|
|
93
|
+
confirmLocks(runtime, listed);
|
|
94
|
+
socket.session.set({ roomsListed: true });
|
|
95
|
+
emitRooms(runtime);
|
|
96
|
+
await relocked(runtime, lockedBefore);
|
|
97
|
+
return listed;
|
|
98
|
+
}
|
|
99
|
+
async function asked({ socket }, authorized) {
|
|
100
|
+
try {
|
|
101
|
+
return (await socket.discover(authorized)) ?? { kind: 'transport-uncertainty' };
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return { kind: 'transport-uncertainty' };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export async function signIn(runtime, local, signedIn) {
|
|
108
|
+
if (JSON.stringify(signedIn) === JSON.stringify((await local.facts()).member))
|
|
109
|
+
return;
|
|
110
|
+
await local.fact('member', signedIn);
|
|
111
|
+
emitMember(runtime, signedIn);
|
|
112
|
+
}
|
|
113
|
+
export async function discoverRooms(runtime, local, progress, live, found) {
|
|
114
|
+
const { socket, journal } = runtime;
|
|
115
|
+
const { session } = socket;
|
|
116
|
+
const { closed, authorization } = session.now();
|
|
117
|
+
if (closed || authorization === undefined) {
|
|
118
|
+
socket.notifyReady();
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
moveTo(runtime, transferring(runtime));
|
|
122
|
+
const started = session.now().discoveries + 1;
|
|
123
|
+
session.set({ discoveries: started });
|
|
124
|
+
const result = found ?? (await asked(runtime, authorization));
|
|
125
|
+
if (result.kind === 'discovery')
|
|
126
|
+
session.set({ roomsNamed: true });
|
|
127
|
+
if (!live()) {
|
|
128
|
+
progress.complete = false;
|
|
129
|
+
socket.notifyReady();
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
journal.record(`connection discover ${result.kind}`);
|
|
133
|
+
if (result.kind === 'transport-uncertainty') {
|
|
134
|
+
await cachedModels(runtime, local);
|
|
135
|
+
progress.reachable = false;
|
|
136
|
+
progress.complete = false;
|
|
137
|
+
socket.notifyReady();
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
if (result.kind === 'contract-unavailable') {
|
|
141
|
+
journal.record(`connection contract unavailable ${result.code}`);
|
|
142
|
+
await refuse(runtime, 'missing-required-guarantee', {
|
|
143
|
+
code: result.code,
|
|
144
|
+
fields: result.fields,
|
|
145
|
+
retryable: result.retryable,
|
|
146
|
+
});
|
|
147
|
+
socket.notifyReady();
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
if (result.kind === 'revoked-authorization') {
|
|
151
|
+
await refuse(runtime, 'revoked-authorization');
|
|
152
|
+
socket.notifyReady();
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
const invalid = malformed(result.rooms);
|
|
156
|
+
if (invalid !== null) {
|
|
157
|
+
journal.record(invalid);
|
|
158
|
+
await refuse(runtime, 'missing-required-guarantee');
|
|
159
|
+
socket.notifyReady();
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
if (session.now().refusal !== null) {
|
|
163
|
+
session.set({ refusal: null });
|
|
164
|
+
emitRefusal(runtime);
|
|
165
|
+
}
|
|
166
|
+
const held = await local.facts();
|
|
167
|
+
if (JSON.stringify(result.providerLimits) !== JSON.stringify(held.providerLimits) ||
|
|
168
|
+
JSON.stringify(result.capabilities) !== JSON.stringify(held.capabilities)) {
|
|
169
|
+
await local.fact('providerLimits', result.providerLimits);
|
|
170
|
+
await local.fact('capabilities', result.capabilities);
|
|
171
|
+
}
|
|
172
|
+
socket.notifyReady();
|
|
173
|
+
await signIn(runtime, local, result.member ?? null);
|
|
174
|
+
return applyDiscovery(runtime, result.rooms, started);
|
|
175
|
+
}
|
package/dist/durability.d.ts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import type { Persistence } from './readiness.js';
|
|
2
|
+
export type UnsentKind = 'pending-change' | 'call' | 'room-draft' | 'chat-draft';
|
|
3
|
+
export type UnsentWork = {
|
|
4
|
+
readonly kind: UnsentKind;
|
|
5
|
+
readonly count: number;
|
|
6
|
+
};
|
|
7
|
+
export type AppCode = {
|
|
8
|
+
readonly running: number;
|
|
9
|
+
readonly older: number;
|
|
10
|
+
};
|
|
11
|
+
export type HeldCode = {
|
|
12
|
+
readonly house: number | null;
|
|
13
|
+
readonly apps: readonly string[];
|
|
14
|
+
};
|
|
2
15
|
export type RuntimeShell = {
|
|
3
16
|
persistence: Persistence;
|
|
4
17
|
generation: string | null;
|
|
5
18
|
keepGeneration(value: string): void | Promise<void>;
|
|
6
19
|
dropGeneration(): void | Promise<void>;
|
|
7
20
|
cleanUp?(): Promise<number>;
|
|
21
|
+
measure?(measured: (app: string, code: AppCode | null) => void): Promise<HeldCode>;
|
|
22
|
+
reset(): Promise<void>;
|
|
8
23
|
};
|
|
9
24
|
export declare function refusedForSpace(error: unknown): boolean;
|
|
10
25
|
export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
|
package/dist/durability.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durability.d.ts","sourceRoot":"","sources":["../src/durability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"durability.d.ts","sourceRoot":"","sources":["../src/durability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,MAAM,GAAG,YAAY,GAAG,YAAY,CAAC;AAEjF,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3F,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5B,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAMvD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAG/F;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAGrF"}
|
package/dist/entry.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type VerifiedModel } from '@agentshouse/mdmodel';
|
|
2
2
|
import { type QueryRows } from './query.js';
|
|
3
3
|
import type { Connection } from './tables.js';
|
|
4
|
-
export { QueryError } from '
|
|
4
|
+
export { QueryError } from '@agentshouse/mdmodel';
|
|
5
5
|
export type EntryRoom = {
|
|
6
6
|
locator: string;
|
|
7
7
|
schema: string | null;
|
package/dist/entry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAAyB,KAAK,S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ryError, } from '@agentshouse/mdmodel';
|
|
1
2
|
import { attachedModel } from './attached-model.js';
|
|
2
3
|
import { answerQuery } from './compile.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { planWithin } from './query.js';
|
|
5
|
+
import { writtenFacts } from './rows.js';
|
|
5
6
|
import { entered, REPLICA_TABLES } from './stored.js';
|
|
6
|
-
export { QueryError } from '
|
|
7
|
+
export { QueryError } from '@agentshouse/mdmodel';
|
|
7
8
|
const PARAMETER = '$param';
|
|
8
9
|
const KIND = 'as';
|
|
9
10
|
const INTEGER = /^-?(?:0|[1-9][0-9]*)$/u;
|
|
@@ -83,6 +84,7 @@ const SAMPLED = {
|
|
|
83
84
|
$all: 'entry',
|
|
84
85
|
$size: 0,
|
|
85
86
|
$exists: true,
|
|
87
|
+
$prefix: 'entry',
|
|
86
88
|
$gt: 0,
|
|
87
89
|
$gte: 0,
|
|
88
90
|
$lt: 0,
|
|
@@ -98,9 +100,15 @@ function sampled(template, key) {
|
|
|
98
100
|
}
|
|
99
101
|
return template;
|
|
100
102
|
}
|
|
103
|
+
function entryPlan(query, facts) {
|
|
104
|
+
const plan = planWithin(query, facts);
|
|
105
|
+
if (plan.fileIds !== null)
|
|
106
|
+
invalid('fileIds', 'an entry Room holds no file IDs');
|
|
107
|
+
return plan;
|
|
108
|
+
}
|
|
101
109
|
export function entryRefusal(template) {
|
|
102
110
|
try {
|
|
103
|
-
|
|
111
|
+
entryPlan(sampled(template, ''), { listed: false, rooms: [] });
|
|
104
112
|
return null;
|
|
105
113
|
}
|
|
106
114
|
catch (error) {
|
|
@@ -117,22 +125,23 @@ export function entryScope(rooms, roomTypes, connection) {
|
|
|
117
125
|
const model = attachedModel({
|
|
118
126
|
kind: 'model',
|
|
119
127
|
snapshot: { identity: room.locator, version: '', schema: room.schema, revision: null },
|
|
120
|
-
},
|
|
128
|
+
}, roomTypes);
|
|
121
129
|
held.push({
|
|
122
130
|
locator: room.locator,
|
|
123
131
|
available: model.status !== 'unavailable',
|
|
124
132
|
types: model.status === 'unavailable' ? [] : Object.values(model.types),
|
|
125
133
|
});
|
|
126
|
-
const composition = { model, selection: null };
|
|
134
|
+
const composition = { model, selection: null, typedPaths: [] };
|
|
127
135
|
const key = entered(connection, room.locator, composition, Object.keys(room.documents)
|
|
128
136
|
.sort()
|
|
129
137
|
.map((path) => ({
|
|
130
138
|
path,
|
|
131
139
|
content: room.documents[path],
|
|
132
|
-
|
|
140
|
+
facts: writtenFacts(path, room.documents[path], composition),
|
|
133
141
|
binary: null,
|
|
134
142
|
revision: room.revisions?.[path] ?? null,
|
|
135
143
|
fileId: null,
|
|
144
|
+
created: null,
|
|
136
145
|
change: null,
|
|
137
146
|
written: null,
|
|
138
147
|
})));
|
|
@@ -143,7 +152,7 @@ export function entryScope(rooms, roomTypes, connection) {
|
|
|
143
152
|
async results(queries) {
|
|
144
153
|
const results = {};
|
|
145
154
|
for (const [name, query] of Object.entries(queries)) {
|
|
146
|
-
const plan =
|
|
155
|
+
const plan = entryPlan(query, planned);
|
|
147
156
|
results[name] = answerQuery(connection, plan, keys.filter(({ locator }) => plan.rooms === null || plan.rooms.includes(locator)));
|
|
148
157
|
}
|
|
149
158
|
return results;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ChangeSet } from './change-set.js';
|
|
2
|
+
import type { GroupTotal, PendingResult } from './query.js';
|
|
3
|
+
import type { Deliver, Fail } from './reach.js';
|
|
4
|
+
import type { ConversationTally, RoomTally } from './tallies.js';
|
|
5
|
+
import type { QueryRoom } from './tables.js';
|
|
6
|
+
export declare const HOUSE_DIRECTORY = "house";
|
|
7
|
+
export declare const ROOM_TOTALS: {
|
|
8
|
+
readonly outside: readonly ["house"];
|
|
9
|
+
readonly groupBy: readonly ["room"];
|
|
10
|
+
readonly select: {
|
|
11
|
+
readonly size: true;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type DayFigures = {
|
|
15
|
+
readonly created: number;
|
|
16
|
+
readonly changed: number;
|
|
17
|
+
readonly chats: number;
|
|
18
|
+
readonly messages: number;
|
|
19
|
+
};
|
|
20
|
+
export type RoomFigures = {
|
|
21
|
+
readonly room: string;
|
|
22
|
+
readonly day: DayFigures;
|
|
23
|
+
readonly total: {
|
|
24
|
+
readonly documents: GroupTotal;
|
|
25
|
+
readonly files: GroupTotal;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type Figures = {
|
|
29
|
+
readonly rooms: readonly RoomFigures[];
|
|
30
|
+
readonly agentMessages: number;
|
|
31
|
+
};
|
|
32
|
+
export type FiguresResult = Figures | PendingResult;
|
|
33
|
+
export type FiguresCover = PendingResult | {
|
|
34
|
+
readonly rooms: readonly QueryRoom[];
|
|
35
|
+
};
|
|
36
|
+
export type FiguresSources = {
|
|
37
|
+
cover(): Promise<FiguresCover>;
|
|
38
|
+
rooms(rooms: readonly QueryRoom[], since: string): Promise<readonly RoomTally[]>;
|
|
39
|
+
conversations(conversations: readonly string[] | null, since: string): Promise<readonly ConversationTally[]>;
|
|
40
|
+
};
|
|
41
|
+
export type FiguresRead = {
|
|
42
|
+
watch(deliver: Deliver, fail: Fail): () => void;
|
|
43
|
+
touched(set: ChangeSet): void;
|
|
44
|
+
recover(): void;
|
|
45
|
+
close(): void;
|
|
46
|
+
};
|
|
47
|
+
export declare function createFigures(sources: FiguresSources): FiguresRead;
|
|
48
|
+
//# sourceMappingURL=figures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figures.d.ts","sourceRoot":"","sources":["../src/figures.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CA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CAAC,SAAS,iBAAiB,EAAE,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,IAAI,CAAC;IAChD,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC9B,OAAO,IAAI,IAAI,CAAC;IAChB,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAgDF,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,WAAW,CAsIlE"}
|
package/dist/figures.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { instantKey } from '@agentshouse/mdmodel';
|
|
2
|
+
export const HOUSE_DIRECTORY = 'house';
|
|
3
|
+
export const ROOM_TOTALS = {
|
|
4
|
+
outside: [HOUSE_DIRECTORY],
|
|
5
|
+
groupBy: ['room'],
|
|
6
|
+
select: { size: true },
|
|
7
|
+
};
|
|
8
|
+
// Today's Last 24 hours is the day that ends as the read answers.
|
|
9
|
+
const DAY_MS = 86_400_000;
|
|
10
|
+
// An install or a catch-up commits many times a second, so the figures answer again once changes rest this long, never per commit.
|
|
11
|
+
const SETTLED_MS = 1_000;
|
|
12
|
+
// Changes that never rest, such as an Agent writing all afternoon, still reach the figures this long after the first of them.
|
|
13
|
+
const LONGEST_UNSETTLED_MS = 5_000;
|
|
14
|
+
function dayOf(tally, since) {
|
|
15
|
+
const after = (at) => at !== null && at >= since;
|
|
16
|
+
return {
|
|
17
|
+
created: tally.documentTimes.filter(([created]) => after(created)).length,
|
|
18
|
+
changed: tally.documentTimes.filter(([created, changed]) => !after(created) && after(changed))
|
|
19
|
+
.length,
|
|
20
|
+
chats: tally.chatTimes.filter(after).length,
|
|
21
|
+
messages: tally.messageTimes.filter(after).length,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function figuresOf(rooms, held, since) {
|
|
25
|
+
return {
|
|
26
|
+
rooms: rooms.map(({ locator }) => {
|
|
27
|
+
const tally = held.rooms.get(locator);
|
|
28
|
+
return {
|
|
29
|
+
room: locator,
|
|
30
|
+
day: dayOf(tally, since),
|
|
31
|
+
total: { documents: tally.documents, files: tally.files },
|
|
32
|
+
};
|
|
33
|
+
}),
|
|
34
|
+
agentMessages: [...held.said.values()].reduce((sum, said) => sum + said.filter((at) => at >= since).length, 0),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function unheld() {
|
|
38
|
+
return {
|
|
39
|
+
rooms: new Map(),
|
|
40
|
+
said: new Map(),
|
|
41
|
+
staleRooms: new Set(),
|
|
42
|
+
staleConversations: new Set(),
|
|
43
|
+
everyConversation: true,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function createFigures(sources) {
|
|
47
|
+
const listeners = new Map();
|
|
48
|
+
const answered = new Set();
|
|
49
|
+
let held = unheld();
|
|
50
|
+
let shown = null;
|
|
51
|
+
let running = false;
|
|
52
|
+
let again = false;
|
|
53
|
+
let quiet = null;
|
|
54
|
+
let longest = null;
|
|
55
|
+
let closed = false;
|
|
56
|
+
function unscheduled() {
|
|
57
|
+
if (quiet !== null)
|
|
58
|
+
clearTimeout(quiet);
|
|
59
|
+
if (longest !== null)
|
|
60
|
+
clearTimeout(longest);
|
|
61
|
+
quiet = null;
|
|
62
|
+
longest = null;
|
|
63
|
+
}
|
|
64
|
+
function deliver(answer) {
|
|
65
|
+
const text = JSON.stringify(answer);
|
|
66
|
+
const changed = text !== shown;
|
|
67
|
+
shown = text;
|
|
68
|
+
for (const listener of listeners.keys()) {
|
|
69
|
+
if (changed || !answered.has(listener))
|
|
70
|
+
listener(structuredClone(answer));
|
|
71
|
+
answered.add(listener);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function tallied(rooms, since) {
|
|
75
|
+
for (const locator of held.rooms.keys()) {
|
|
76
|
+
if (!rooms.some((room) => room.locator === locator))
|
|
77
|
+
held.rooms.delete(locator);
|
|
78
|
+
}
|
|
79
|
+
const asked = rooms.filter(({ locator, key }) => held.staleRooms.has(locator) || held.rooms.get(locator)?.key !== key);
|
|
80
|
+
for (const { locator } of asked)
|
|
81
|
+
held.staleRooms.delete(locator);
|
|
82
|
+
const every = held.everyConversation;
|
|
83
|
+
const conversations = every ? null : [...held.staleConversations];
|
|
84
|
+
held.everyConversation = false;
|
|
85
|
+
held.staleConversations.clear();
|
|
86
|
+
const kept = held;
|
|
87
|
+
const [roomTallies, said] = await Promise.all([
|
|
88
|
+
asked.length === 0 ? [] : sources.rooms(asked, since),
|
|
89
|
+
conversations?.length === 0 ? [] : sources.conversations(conversations, since),
|
|
90
|
+
]);
|
|
91
|
+
if (kept !== held)
|
|
92
|
+
return false;
|
|
93
|
+
for (const tally of roomTallies) {
|
|
94
|
+
const room = asked.find(({ key }) => key === tally.key);
|
|
95
|
+
if (room !== undefined)
|
|
96
|
+
held.rooms.set(room.locator, tally);
|
|
97
|
+
}
|
|
98
|
+
if (every)
|
|
99
|
+
held.said.clear();
|
|
100
|
+
for (const { conversation, said: times } of said) {
|
|
101
|
+
if (times.length === 0)
|
|
102
|
+
held.said.delete(conversation);
|
|
103
|
+
else
|
|
104
|
+
held.said.set(conversation, times);
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
async function answer() {
|
|
109
|
+
const window = new Date(Date.now() - DAY_MS).toISOString();
|
|
110
|
+
const cover = await sources.cover();
|
|
111
|
+
if ('pending' in cover)
|
|
112
|
+
return cover;
|
|
113
|
+
if (!(await tallied(cover.rooms, window)))
|
|
114
|
+
return null;
|
|
115
|
+
return figuresOf(cover.rooms, held, instantKey(window));
|
|
116
|
+
}
|
|
117
|
+
async function run() {
|
|
118
|
+
if (running) {
|
|
119
|
+
again = true;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
running = true;
|
|
123
|
+
try {
|
|
124
|
+
do {
|
|
125
|
+
again = false;
|
|
126
|
+
const result = await answer();
|
|
127
|
+
if (closed || listeners.size === 0)
|
|
128
|
+
return;
|
|
129
|
+
if (result === null)
|
|
130
|
+
again = true;
|
|
131
|
+
else
|
|
132
|
+
deliver(result);
|
|
133
|
+
} while (again && !closed && listeners.size > 0);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
for (const [listener, failed] of listeners) {
|
|
137
|
+
if (!answered.has(listener))
|
|
138
|
+
failed(error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
running = false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function stop(listener) {
|
|
146
|
+
return () => {
|
|
147
|
+
listeners.delete(listener);
|
|
148
|
+
answered.delete(listener);
|
|
149
|
+
if (listeners.size > 0)
|
|
150
|
+
return;
|
|
151
|
+
unscheduled();
|
|
152
|
+
held = unheld();
|
|
153
|
+
shown = null;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function settle() {
|
|
157
|
+
if (closed || listeners.size === 0)
|
|
158
|
+
return;
|
|
159
|
+
const now = () => {
|
|
160
|
+
unscheduled();
|
|
161
|
+
void run();
|
|
162
|
+
};
|
|
163
|
+
if (quiet !== null)
|
|
164
|
+
clearTimeout(quiet);
|
|
165
|
+
quiet = setTimeout(now, SETTLED_MS);
|
|
166
|
+
longest ??= setTimeout(now, LONGEST_UNSETTLED_MS);
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
watch(listener, failed) {
|
|
170
|
+
listeners.set(listener, failed);
|
|
171
|
+
void run();
|
|
172
|
+
return stop(listener);
|
|
173
|
+
},
|
|
174
|
+
touched(set) {
|
|
175
|
+
if (listeners.size === 0)
|
|
176
|
+
return;
|
|
177
|
+
for (const { locator } of set.documents)
|
|
178
|
+
held.staleRooms.add(locator);
|
|
179
|
+
for (const locator of set.rooms)
|
|
180
|
+
held.staleRooms.add(locator);
|
|
181
|
+
for (const conversation of set.conversations)
|
|
182
|
+
held.staleConversations.add(conversation);
|
|
183
|
+
if (set.documents.length + set.rooms.length + set.conversations.length > 0)
|
|
184
|
+
settle();
|
|
185
|
+
},
|
|
186
|
+
recover() {
|
|
187
|
+
if (listeners.size > 0)
|
|
188
|
+
settle();
|
|
189
|
+
},
|
|
190
|
+
close() {
|
|
191
|
+
closed = true;
|
|
192
|
+
unscheduled();
|
|
193
|
+
listeners.clear();
|
|
194
|
+
answered.clear();
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AppCode } from './durability.js';
|
|
2
|
+
import type { GroupTotal, PendingResult } from './query.js';
|
|
3
|
+
import type { Deliver, Fail } from './reach.js';
|
|
4
|
+
import type { Runtime } from './runtime.js';
|
|
5
|
+
import type { OpenedRoom } from './tables.js';
|
|
6
|
+
export type RoomDocuments = {
|
|
7
|
+
readonly room: string;
|
|
8
|
+
readonly documents: GroupTotal;
|
|
9
|
+
};
|
|
10
|
+
export type HeldApp = ({
|
|
11
|
+
readonly app: string;
|
|
12
|
+
readonly state: 'measured';
|
|
13
|
+
} & AppCode) | {
|
|
14
|
+
readonly app: string;
|
|
15
|
+
readonly state: 'asking' | 'unknown';
|
|
16
|
+
};
|
|
17
|
+
export type Holdings = {
|
|
18
|
+
readonly rooms: readonly RoomDocuments[] | PendingResult;
|
|
19
|
+
readonly opened: GroupTotal & {
|
|
20
|
+
readonly rooms: readonly OpenedRoom[];
|
|
21
|
+
};
|
|
22
|
+
readonly apps: readonly HeldApp[];
|
|
23
|
+
readonly house: number | null;
|
|
24
|
+
readonly total: number | null;
|
|
25
|
+
readonly cleanUp: number | null;
|
|
26
|
+
};
|
|
27
|
+
export declare const CLEANED_TOPIC = "cleaned";
|
|
28
|
+
export declare function watchHoldings({ store, figures, shell }: Runtime, deliver: Deliver, fail: Fail): () => void;
|
|
29
|
+
//# sourceMappingURL=holdings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"holdings.d.ts","sourceRoot":"","sources":["../src/holdings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