@agentshouse/mdruntime 0.1.0-c49444f2a8fc6 → 0.1.0-c4d7cf2ec26a6
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/dist/acceptance.d.ts +6 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +386 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +251 -0
- package/dist/adapter.d.ts +6 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.js +1 -0
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- 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 +12 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -0
- package/dist/compile.d.ts +5 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +190 -59
- package/dist/connection.d.ts +5 -143
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +101 -5309
- package/dist/conversation-live.d.ts +136 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +248 -0
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +7 -1
- package/dist/conversation.d.ts +22 -35
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +827 -972
- 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 +9 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/figures.d.ts +49 -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 +1 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +7 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +554 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +268 -0
- package/dist/listing.d.ts +53 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +176 -0
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +0 -2
- 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.map +1 -1
- package/dist/memory.js +1 -0
- package/dist/messages.d.ts +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +3 -3
- package/dist/models.d.ts +14 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +195 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +12 -17
- package/dist/opened.js +3 -3
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +57 -0
- package/dist/outcome.d.ts +4 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -0
- package/dist/parts.d.ts +1 -0
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +8 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -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 +10 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +2 -0
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +5 -1
- package/dist/reach.d.ts +3 -1
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +11 -0
- package/dist/react.d.ts +7 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +0 -1
- package/dist/readiness.d.ts.map +1 -1
- package/dist/reads.d.ts +37 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +171 -0
- 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 +1 -3
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +3 -2
- package/dist/room-draft.d.ts +1 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +2 -2
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/runtime.d.ts +43 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +5 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +12 -14
- package/dist/saves.d.ts +70 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +1005 -0
- 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 -6
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -95
- package/dist/shown.d.ts +31 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +292 -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 +44 -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.map +1 -1
- package/dist/source.js +5 -4
- 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 +431 -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 +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -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 +111 -206
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +142 -398
- package/dist/stored.d.ts +1 -1
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +25 -11
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +223 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +532 -0
- package/dist/tables.d.ts +32 -4
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +42 -8
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/wire.d.ts +8 -1
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +4 -0
- package/package.json +2 -2
|
@@ -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
|
@@ -4,12 +4,21 @@ export type UnsentWork = {
|
|
|
4
4
|
readonly kind: UnsentKind;
|
|
5
5
|
readonly count: number;
|
|
6
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
|
+
};
|
|
7
15
|
export type RuntimeShell = {
|
|
8
16
|
persistence: Persistence;
|
|
9
17
|
generation: string | null;
|
|
10
18
|
keepGeneration(value: string): void | Promise<void>;
|
|
11
19
|
dropGeneration(): void | Promise<void>;
|
|
12
20
|
cleanUp?(): Promise<number>;
|
|
21
|
+
measure?(measured: (app: string, code: AppCode | null) => void): Promise<HeldCode>;
|
|
13
22
|
reset(): Promise<void>;
|
|
14
23
|
};
|
|
15
24
|
export declare function refusedForSpace(error: unknown): boolean;
|
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,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,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,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"}
|
|
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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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 declare const FIGURES_DAY_MS = 86400000;
|
|
15
|
+
export type DayFigures = {
|
|
16
|
+
readonly created: number;
|
|
17
|
+
readonly changed: number;
|
|
18
|
+
readonly chats: number;
|
|
19
|
+
readonly messages: number;
|
|
20
|
+
};
|
|
21
|
+
export type RoomFigures = {
|
|
22
|
+
readonly room: string;
|
|
23
|
+
readonly day: DayFigures;
|
|
24
|
+
readonly total: {
|
|
25
|
+
readonly documents: GroupTotal;
|
|
26
|
+
readonly files: GroupTotal;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export type Figures = {
|
|
30
|
+
readonly rooms: readonly RoomFigures[];
|
|
31
|
+
readonly agentMessages: number;
|
|
32
|
+
};
|
|
33
|
+
export type FiguresResult = Figures | PendingResult;
|
|
34
|
+
export type FiguresCover = PendingResult | {
|
|
35
|
+
readonly rooms: readonly QueryRoom[];
|
|
36
|
+
};
|
|
37
|
+
export type FiguresSources = {
|
|
38
|
+
cover(): Promise<FiguresCover>;
|
|
39
|
+
rooms(rooms: readonly QueryRoom[], since: string): Promise<readonly RoomTally[]>;
|
|
40
|
+
conversations(conversations: readonly string[] | null, since: string): Promise<readonly ConversationTally[]>;
|
|
41
|
+
};
|
|
42
|
+
export type FiguresRead = {
|
|
43
|
+
watch(deliver: Deliver, fail: Fail): () => void;
|
|
44
|
+
touched(set: ChangeSet): void;
|
|
45
|
+
recover(): void;
|
|
46
|
+
close(): void;
|
|
47
|
+
};
|
|
48
|
+
export declare function createFigures(sources: FiguresSources): FiguresRead;
|
|
49
|
+
//# 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,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,eAAO,MAAM,eAAe,UAAU,CAAC;AAEvC,eAAO,MAAM,WAAW;;;;iBAGZ,IAAI;;CACe,CAAC;AAGhC,eAAO,MAAM,cAAc,WAAa,CAAC;AAQzC,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;KAAE,CAAC;CAChF,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;IAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjG,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,aAAa,CAAC;AAEpD,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/B,KAAK,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;IACjF,aAAa,CACX,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,EACvC,KAAK,EAAE,MAAM,GACZ,OAAO,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
|
+
export const FIGURES_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() - FIGURES_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.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAY,MAAM,iBAAiB,CAAC;AAEzD,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,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAA;CAAE,CAAC;AAEtF,MAAM,MAAM,OAAO,GACf,CAAC;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GAAG,OAAO,CAAC,GAChE;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAA;CAAE,CAAC;AAEnE,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,aAAa,CAAC;IACzD,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAA;KAAE,CAAC;IACxE,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC,CAAC;AAIF,eAAO,MAAM,aAAa,YAAY,CAAC;AA6CvC,wBAAgB,aAAa,CAC3B,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAClC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,GACT,MAAM,IAAI,CA4DZ"}
|
package/dist/holdings.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const NO_CODE = { house: 0, apps: [] };
|
|
2
|
+
export const CLEANED_TOPIC = 'cleaned';
|
|
3
|
+
function heldRooms(figures) {
|
|
4
|
+
if ('pending' in figures)
|
|
5
|
+
return figures;
|
|
6
|
+
return figures.rooms.map(({ room, total }) => ({ room, documents: total.documents }));
|
|
7
|
+
}
|
|
8
|
+
function heldApp(app, measured) {
|
|
9
|
+
if (!measured.has(app))
|
|
10
|
+
return { app, state: 'asking' };
|
|
11
|
+
const code = measured.get(app) ?? null;
|
|
12
|
+
return code === null ? { app, state: 'unknown' } : { app, state: 'measured', ...code };
|
|
13
|
+
}
|
|
14
|
+
function summed(values) {
|
|
15
|
+
return values.reduce((sum, value) => sum + value, 0);
|
|
16
|
+
}
|
|
17
|
+
function holdingsOf(rooms, opened, code, measured) {
|
|
18
|
+
const apps = code.apps.map((app) => heldApp(app, measured));
|
|
19
|
+
const known = apps.flatMap((app) => (app.state === 'measured' ? [app] : []));
|
|
20
|
+
const whole = known.length === apps.length;
|
|
21
|
+
const files = {
|
|
22
|
+
count: summed(opened.rooms.map(({ count }) => count)),
|
|
23
|
+
size: summed(opened.rooms.map(({ size }) => size)),
|
|
24
|
+
};
|
|
25
|
+
const documents = 'pending' in rooms ? null : summed(rooms.map(({ documents: d }) => d.size));
|
|
26
|
+
const older = whole ? summed(known.map((app) => app.older)) : null;
|
|
27
|
+
return {
|
|
28
|
+
rooms,
|
|
29
|
+
opened: { ...files, rooms: opened.rooms },
|
|
30
|
+
apps,
|
|
31
|
+
house: code.house,
|
|
32
|
+
total: documents === null || code.house === null || older === null
|
|
33
|
+
? null
|
|
34
|
+
: documents + files.size + summed(known.map((app) => app.running)) + older + code.house,
|
|
35
|
+
cleanUp: older === null ? null : opened.cleanable + older,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function watchHoldings({ store, figures, shell }, deliver, fail) {
|
|
39
|
+
let open = true;
|
|
40
|
+
let asked = 0;
|
|
41
|
+
let rooms = null;
|
|
42
|
+
let opened = null;
|
|
43
|
+
let code = null;
|
|
44
|
+
let measured = new Map();
|
|
45
|
+
function told() {
|
|
46
|
+
if (open && rooms !== null && opened !== null && code !== null) {
|
|
47
|
+
deliver(holdingsOf(rooms, opened, code, measured));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function failed(error) {
|
|
51
|
+
if (!open)
|
|
52
|
+
return;
|
|
53
|
+
stop();
|
|
54
|
+
fail(error);
|
|
55
|
+
}
|
|
56
|
+
function ask() {
|
|
57
|
+
asked += 1;
|
|
58
|
+
const at = asked;
|
|
59
|
+
const current = () => open && at === asked;
|
|
60
|
+
opened = null;
|
|
61
|
+
code = null;
|
|
62
|
+
measured = new Map();
|
|
63
|
+
store.ask({ kind: 'opened.held' }).then((held) => {
|
|
64
|
+
if (!current())
|
|
65
|
+
return;
|
|
66
|
+
opened = held;
|
|
67
|
+
told();
|
|
68
|
+
}, failed);
|
|
69
|
+
const answers = measured;
|
|
70
|
+
const measuring = shell.measure?.((app, answer) => {
|
|
71
|
+
if (!current())
|
|
72
|
+
return;
|
|
73
|
+
answers.set(app, answer);
|
|
74
|
+
told();
|
|
75
|
+
}) ?? Promise.resolve(NO_CODE);
|
|
76
|
+
measuring.then((held) => {
|
|
77
|
+
if (!current())
|
|
78
|
+
return;
|
|
79
|
+
code = held;
|
|
80
|
+
told();
|
|
81
|
+
}, failed);
|
|
82
|
+
}
|
|
83
|
+
const stopFigures = figures.watch((answer) => {
|
|
84
|
+
rooms = heldRooms(answer);
|
|
85
|
+
told();
|
|
86
|
+
}, failed);
|
|
87
|
+
const cleaned = store.watch(CLEANED_TOPIC, ask);
|
|
88
|
+
function stop() {
|
|
89
|
+
open = false;
|
|
90
|
+
stopFigures();
|
|
91
|
+
cleaned.stop();
|
|
92
|
+
}
|
|
93
|
+
ask();
|
|
94
|
+
return stop;
|
|
95
|
+
}
|
package/dist/host.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type AttachedPort = {
|
|
|
14
14
|
};
|
|
15
15
|
export type MdRuntimeHost = {
|
|
16
16
|
attach(port: RuntimePort, app: string, release?: string, reach?: PortReach, code?: CodeAvailability): AttachedPort;
|
|
17
|
+
present(app: string, members: Readonly<Record<string, unknown>>): Promise<void>;
|
|
17
18
|
seed(entry: EntrySeed): void;
|
|
18
19
|
persisted(answer: Persistence): void;
|
|
19
20
|
endAuthorization(holder?: string): Promise<void>;
|
package/dist/host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAIxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EAGL,KAAK,WAAW,EAOjB,MAAM,WAAW,CAAC;AAInB,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,IAAI,IAAI,CAAC;IACf,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAC/B,SAAS,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CAC/D,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CACJ,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,SAAS,EACjB,IAAI,CAAC,EAAE,gBAAgB,GACtB,YAAY,CAAC;IAChB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChF,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAC7B,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IACrC,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAsIF,wBAAgB,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAuL3E;AAED,OAAO,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EACL,cAAc,EACd,UAAU,EACV,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/host.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { queryKey } from '@agentshouse/mdmodel';
|
|
2
|
-
import { composeRuntime
|
|
2
|
+
import { composeRuntime } from './connection.js';
|
|
3
3
|
import { untilAnswered } from './recovery.js';
|
|
4
4
|
import { described } from './failure.js';
|
|
5
|
+
import { answeredResult } from './outcome.js';
|
|
5
6
|
import { AUTHORIZATION_ENDED, request, WIRE, } from './wire.js';
|
|
6
7
|
const NARROWED = new Set(['within', 'whole']);
|
|
7
8
|
function answered(md, app, writtenBy, member, input) {
|
|
@@ -44,6 +45,8 @@ function answered(md, app, writtenBy, member, input) {
|
|
|
44
45
|
return md.unsent();
|
|
45
46
|
case 'reset':
|
|
46
47
|
return md.reset();
|
|
48
|
+
case 'readAgain':
|
|
49
|
+
return md.readAgain();
|
|
47
50
|
case 'persistence':
|
|
48
51
|
return md.persistence();
|
|
49
52
|
case 'retry':
|
|
@@ -96,9 +99,6 @@ function attempted(work) {
|
|
|
96
99
|
return Promise.reject(error);
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
|
-
function answeredResult(value) {
|
|
100
|
-
return typeof value === 'object' && value !== null && !('pending' in value);
|
|
101
|
-
}
|
|
102
102
|
function answeredMessage(value) {
|
|
103
103
|
if (typeof value !== 'object' || value === null)
|
|
104
104
|
return false;
|
|
@@ -260,6 +260,9 @@ export function serveMdRuntime(options) {
|
|
|
260
260
|
}
|
|
261
261
|
return {
|
|
262
262
|
attach,
|
|
263
|
+
present(app, members) {
|
|
264
|
+
return md.presentation.edit(app, members);
|
|
265
|
+
},
|
|
263
266
|
seed(entry) {
|
|
264
267
|
runtime.seed(entry);
|
|
265
268
|
},
|