@agentshouse/mdruntime 0.1.0-cf08ada271a7f → 0.1.0-cf0c43fc48aad
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 +12 -12
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +25 -35
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +116 -65
- package/dist/adapter.d.ts +11 -4
- package/dist/adapter.d.ts.map +1 -1
- package/dist/client.d.ts +6 -17
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +26 -11
- package/dist/compile.d.ts +2 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +17 -4
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +15 -10
- package/dist/conversation-live.d.ts +7 -2
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +6 -3
- package/dist/conversation.d.ts +25 -5
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +157 -76
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +18 -45
- package/dist/durability.d.ts +3 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.js +1 -1
- package/dist/expectation.d.ts +25 -14
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +51 -20
- package/dist/failure.d.ts +2 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +29 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/install.d.ts +2 -3
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +9 -22
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +32 -26
- package/dist/listing.d.ts +4 -9
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +21 -51
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +8 -38
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +7 -19
- package/dist/media.js +1 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +36 -17
- package/dist/messages.d.ts +9 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +20 -10
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +15 -32
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +2 -2
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +3 -9
- package/dist/outcome.d.ts +3 -0
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +15 -0
- package/dist/overlay.d.ts +3 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +8 -4
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +2 -9
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +6 -14
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +15 -21
- package/dist/presence.d.ts +52 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +220 -0
- package/dist/queries.d.ts +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +23 -13
- package/dist/questions.d.ts +0 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +0 -7
- package/dist/queue.d.ts +2 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +26 -31
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +62 -18
- package/dist/react.d.ts +5 -4
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +28 -5
- package/dist/reads.d.ts +3 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +5 -1
- package/dist/recovery.d.ts +3 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +29 -7
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +2 -4
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +2 -2
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +24 -19
- package/dist/runtime.d.ts +4 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +105 -55
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +8 -11
- package/dist/seed.js +2 -2
- package/dist/shown.d.ts +2 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +14 -23
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- package/dist/socket.d.ts +3 -5
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +3 -14
- package/dist/source.d.ts +0 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/store/records.d.ts +7 -3
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +12 -2
- package/dist/store.d.ts +10 -5
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +37 -12
- package/dist/stored.d.ts +1 -0
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +5 -5
- package/dist/surface.d.ts +1 -1
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +9 -13
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +63 -58
- package/dist/tables.d.ts +6 -3
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +34 -10
- package/dist/wire.d.ts +47 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +12 -1
- package/package.json +3 -3
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/job.d.ts +0 -5
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -7
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/socket/rooms.d.ts +0 -41
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { DiscoveredRoom, ProviderRefusal, ScopedRefusal } from './adapter.js';
|
|
2
|
+
import type { ModelState } from './model.js';
|
|
3
|
+
type Repairable = {
|
|
4
|
+
readonly reset: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
type Standing = {
|
|
7
|
+
readonly stale: boolean;
|
|
8
|
+
readonly repairable: Repairable | null;
|
|
9
|
+
readonly repairing: boolean;
|
|
10
|
+
readonly reloadDue: boolean;
|
|
11
|
+
};
|
|
12
|
+
type Listing = {
|
|
13
|
+
readonly whole: boolean;
|
|
14
|
+
readonly live: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type Presence = {
|
|
17
|
+
list(found: readonly DiscoveredRoom[], how: Listing): readonly DiscoveredRoom[];
|
|
18
|
+
room(locator: string): DiscoveredRoom | undefined;
|
|
19
|
+
rooms(): readonly DiscoveredRoom[];
|
|
20
|
+
available(locator: string, selection?: string): boolean;
|
|
21
|
+
refusal(locator: string): ProviderRefusal | null;
|
|
22
|
+
unheldModel(locator: string): ModelState | null;
|
|
23
|
+
refused(locator: string, refusal: ScopedRefusal | null): void;
|
|
24
|
+
readable(locator: string): boolean;
|
|
25
|
+
modelled(locator: string, model: ModelState | null): void;
|
|
26
|
+
installed(locator: string, bootstrapped: boolean): void;
|
|
27
|
+
locked(locator: string, stored: () => Promise<string | null>): Promise<boolean>;
|
|
28
|
+
lockedAmong(stored: ReadonlyMap<string, string>): readonly string[];
|
|
29
|
+
connectionLost(lapsed: () => void): void;
|
|
30
|
+
connectionLive(): void;
|
|
31
|
+
lapse(): void;
|
|
32
|
+
stood(locator: string, stale: boolean, repairable?: Repairable | null): void;
|
|
33
|
+
repairing(locator: string, running: boolean): void;
|
|
34
|
+
reload(locator: string, due: boolean): void;
|
|
35
|
+
standing(locator: string): Standing;
|
|
36
|
+
settled(): boolean;
|
|
37
|
+
repairsOwed(): readonly string[];
|
|
38
|
+
askAgain(locator: string, ask: () => void): void;
|
|
39
|
+
stopAsking(locator?: string): void;
|
|
40
|
+
lose(locator: string, during: number): boolean;
|
|
41
|
+
writing(locator: string): boolean;
|
|
42
|
+
unwritten(locator: string): void;
|
|
43
|
+
lost(locator: string): boolean;
|
|
44
|
+
losses(): number;
|
|
45
|
+
lostSince(locator: string, losses: number): boolean;
|
|
46
|
+
liftable(locator: string, discovery: number): boolean;
|
|
47
|
+
lift(locator: string, discovery: number, unfenced: boolean): void;
|
|
48
|
+
close(): void;
|
|
49
|
+
};
|
|
50
|
+
export declare function createPresence(): Presence;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../src/presence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,KAAK,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEzD,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B,CAAC;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|
|
|
1
|
+
const UNANSWERED = {
|
|
2
|
+
stale: false,
|
|
3
|
+
repairable: null,
|
|
4
|
+
repairing: false,
|
|
5
|
+
reloadDue: false,
|
|
6
|
+
refusal: null,
|
|
7
|
+
unreading: false,
|
|
8
|
+
unreadable: false,
|
|
9
|
+
unheldModel: null,
|
|
10
|
+
confirmed: false,
|
|
11
|
+
};
|
|
12
|
+
// A Room the Provider answers not ready is asked again after these waits, the last repeating, so a chunk build that catches up within seconds installs at once and a long one is asked every 15 seconds.
|
|
13
|
+
const NOT_READY_MS = [1_000, 2_000, 3_000, 5_000, 8_000, 11_000, 15_000];
|
|
14
|
+
// A Room that locks offline stays readable this long after the connection drops, so a laptop waking or changing network keeps working while a disconnected device locks soon after.
|
|
15
|
+
const LOCK_GRACE_MS = 120_000;
|
|
16
|
+
export function createPresence() {
|
|
17
|
+
const listed = new Map();
|
|
18
|
+
const answered = new Map();
|
|
19
|
+
const marks = new Map();
|
|
20
|
+
const lastLost = new Map();
|
|
21
|
+
const unready = new Map();
|
|
22
|
+
let lossCount = 0;
|
|
23
|
+
let lockGrace = null;
|
|
24
|
+
function answer(locator) {
|
|
25
|
+
return answered.get(locator) ?? UNANSWERED;
|
|
26
|
+
}
|
|
27
|
+
function change(locator, next) {
|
|
28
|
+
answered.set(locator, { ...answer(locator), ...next });
|
|
29
|
+
}
|
|
30
|
+
function heard(locator, next) {
|
|
31
|
+
if (!marks.has(locator))
|
|
32
|
+
change(locator, next);
|
|
33
|
+
}
|
|
34
|
+
function readied(locator) {
|
|
35
|
+
const held = unready.get(locator);
|
|
36
|
+
if (held === undefined)
|
|
37
|
+
return;
|
|
38
|
+
if (held.timer !== null)
|
|
39
|
+
clearTimeout(held.timer);
|
|
40
|
+
unready.delete(locator);
|
|
41
|
+
}
|
|
42
|
+
function stopAsking(locator) {
|
|
43
|
+
for (const held of locator === undefined ? [...unready.keys()] : [locator])
|
|
44
|
+
readied(held);
|
|
45
|
+
}
|
|
46
|
+
function connectionLive() {
|
|
47
|
+
if (lockGrace !== null)
|
|
48
|
+
clearTimeout(lockGrace);
|
|
49
|
+
lockGrace = null;
|
|
50
|
+
}
|
|
51
|
+
function readable(locator) {
|
|
52
|
+
const { unreadable, unreading } = answer(locator);
|
|
53
|
+
if (!unreadable || marks.has(locator))
|
|
54
|
+
return false;
|
|
55
|
+
change(locator, {
|
|
56
|
+
unreadable: false,
|
|
57
|
+
...(unreading ? { refusal: null, unreading: false } : {}),
|
|
58
|
+
});
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
function locks(locator, mode) {
|
|
62
|
+
return mode === 'locked' && !answer(locator).confirmed && !marks.has(locator);
|
|
63
|
+
}
|
|
64
|
+
function liftable(locator, discovery) {
|
|
65
|
+
const mark = marks.get(locator);
|
|
66
|
+
return mark === undefined || mark.during < discovery;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
list(found, { whole, live }) {
|
|
70
|
+
const kept = found.filter(({ locator }) => !marks.has(locator));
|
|
71
|
+
if (whole)
|
|
72
|
+
listed.clear();
|
|
73
|
+
for (const room of kept) {
|
|
74
|
+
listed.set(room.locator, room);
|
|
75
|
+
change(room.locator, {
|
|
76
|
+
refusal: null,
|
|
77
|
+
unreading: false,
|
|
78
|
+
...(live && room.replica.admission === 'admitted' ? { confirmed: true } : {}),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return kept;
|
|
82
|
+
},
|
|
83
|
+
room: (locator) => listed.get(locator),
|
|
84
|
+
rooms: () => [...listed.values()],
|
|
85
|
+
available(locator, selection) {
|
|
86
|
+
if (marks.has(locator))
|
|
87
|
+
return false;
|
|
88
|
+
const room = listed.get(locator);
|
|
89
|
+
if (room === undefined)
|
|
90
|
+
return true;
|
|
91
|
+
return ((selection === undefined || selection === room.replica.selection) &&
|
|
92
|
+
room.replica.admission === 'admitted' &&
|
|
93
|
+
!answer(locator).unreadable);
|
|
94
|
+
},
|
|
95
|
+
refusal: (locator) => answer(locator).refusal,
|
|
96
|
+
unheldModel: (locator) => answer(locator).unheldModel,
|
|
97
|
+
refused(locator, refusal) {
|
|
98
|
+
if (refusal === null) {
|
|
99
|
+
heard(locator, { unreadable: true });
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const unreading = refusal.scope !== 'operation' && refusal.scope !== 'model';
|
|
103
|
+
heard(locator, {
|
|
104
|
+
refusal: { code: refusal.code, fields: refusal.fields, retryable: refusal.retryable },
|
|
105
|
+
unreading,
|
|
106
|
+
...(unreading ? { unreadable: true } : {}),
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
readable,
|
|
110
|
+
modelled(locator, model) {
|
|
111
|
+
heard(locator, { unheldModel: model });
|
|
112
|
+
},
|
|
113
|
+
installed(locator, bootstrapped) {
|
|
114
|
+
if (marks.has(locator))
|
|
115
|
+
return;
|
|
116
|
+
if (bootstrapped) {
|
|
117
|
+
readied(locator);
|
|
118
|
+
change(locator, { unheldModel: null });
|
|
119
|
+
}
|
|
120
|
+
change(locator, { stale: false });
|
|
121
|
+
readable(locator);
|
|
122
|
+
},
|
|
123
|
+
async locked(locator, stored) {
|
|
124
|
+
if (marks.has(locator) || answer(locator).confirmed)
|
|
125
|
+
return false;
|
|
126
|
+
return locks(locator, (await stored()) ?? listed.get(locator)?.replica.offline);
|
|
127
|
+
},
|
|
128
|
+
lockedAmong(stored) {
|
|
129
|
+
const modes = new Map([...listed].map(([locator, room]) => [locator, room.replica.offline]));
|
|
130
|
+
for (const [locator, mode] of stored)
|
|
131
|
+
modes.set(locator, mode);
|
|
132
|
+
return [...modes]
|
|
133
|
+
.filter(([locator, mode]) => locks(locator, mode))
|
|
134
|
+
.map(([locator]) => locator)
|
|
135
|
+
.sort();
|
|
136
|
+
},
|
|
137
|
+
connectionLost(lapsed) {
|
|
138
|
+
if (lockGrace !== null)
|
|
139
|
+
return;
|
|
140
|
+
lockGrace = setTimeout(() => {
|
|
141
|
+
lockGrace = null;
|
|
142
|
+
lapsed();
|
|
143
|
+
}, LOCK_GRACE_MS);
|
|
144
|
+
},
|
|
145
|
+
connectionLive,
|
|
146
|
+
lapse() {
|
|
147
|
+
for (const [locator, held] of answered) {
|
|
148
|
+
if (held.confirmed)
|
|
149
|
+
answered.set(locator, { ...held, confirmed: false });
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
stood(locator, stale, repairable) {
|
|
153
|
+
heard(locator, { stale, ...(repairable === undefined ? {} : { repairable }) });
|
|
154
|
+
},
|
|
155
|
+
repairing(locator, running) {
|
|
156
|
+
change(locator, { repairing: running });
|
|
157
|
+
},
|
|
158
|
+
reload(locator, due) {
|
|
159
|
+
change(locator, { reloadDue: due });
|
|
160
|
+
},
|
|
161
|
+
standing(locator) {
|
|
162
|
+
const { stale, repairable, repairing, reloadDue } = answer(locator);
|
|
163
|
+
return { stale, repairable, repairing, reloadDue };
|
|
164
|
+
},
|
|
165
|
+
settled: () => ![...answered].some(([locator, { stale }]) => stale && !marks.has(locator)),
|
|
166
|
+
repairsOwed: () => [...answered]
|
|
167
|
+
.filter(([locator, { stale, repairable }]) => stale && repairable !== null && !marks.has(locator))
|
|
168
|
+
.map(([locator]) => locator),
|
|
169
|
+
askAgain(locator, ask) {
|
|
170
|
+
const held = unready.get(locator) ?? { tries: 0, timer: null };
|
|
171
|
+
unready.set(locator, held);
|
|
172
|
+
if (held.timer !== null)
|
|
173
|
+
return;
|
|
174
|
+
const wait = NOT_READY_MS[Math.min(held.tries, NOT_READY_MS.length - 1)];
|
|
175
|
+
held.tries += 1;
|
|
176
|
+
held.timer = setTimeout(() => {
|
|
177
|
+
held.timer = null;
|
|
178
|
+
ask();
|
|
179
|
+
}, wait);
|
|
180
|
+
},
|
|
181
|
+
stopAsking,
|
|
182
|
+
lose(locator, during) {
|
|
183
|
+
if (marks.has(locator))
|
|
184
|
+
return false;
|
|
185
|
+
marks.set(locator, { during, written: false });
|
|
186
|
+
lastLost.set(locator, ++lossCount);
|
|
187
|
+
listed.delete(locator);
|
|
188
|
+
readied(locator);
|
|
189
|
+
const { repairing, reloadDue } = answer(locator);
|
|
190
|
+
answered.set(locator, { ...UNANSWERED, repairing, reloadDue });
|
|
191
|
+
return true;
|
|
192
|
+
},
|
|
193
|
+
writing(locator) {
|
|
194
|
+
const mark = marks.get(locator);
|
|
195
|
+
if (mark === undefined || mark.written)
|
|
196
|
+
return false;
|
|
197
|
+
marks.set(locator, { ...mark, written: true });
|
|
198
|
+
return true;
|
|
199
|
+
},
|
|
200
|
+
unwritten(locator) {
|
|
201
|
+
const mark = marks.get(locator);
|
|
202
|
+
if (mark !== undefined)
|
|
203
|
+
marks.set(locator, { ...mark, written: false });
|
|
204
|
+
},
|
|
205
|
+
lost: (locator) => marks.has(locator),
|
|
206
|
+
losses: () => lossCount,
|
|
207
|
+
lostSince: (locator, losses) => marks.has(locator) || (lastLost.get(locator) ?? 0) > losses,
|
|
208
|
+
liftable,
|
|
209
|
+
lift(locator, discovery, unfenced) {
|
|
210
|
+
const mark = marks.get(locator);
|
|
211
|
+
if (mark !== undefined && liftable(locator, discovery) && (unfenced || !mark.written)) {
|
|
212
|
+
marks.delete(locator);
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
close() {
|
|
216
|
+
stopAsking();
|
|
217
|
+
connectionLive();
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
package/dist/queries.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare function figuresCover(runtime: Runtime): Promise<FiguresCover>;
|
|
|
9
9
|
export declare function answeredPlan(runtime: Runtime, plan: Plan, cover: () => Promise<Cover>): Promise<Ran>;
|
|
10
10
|
export declare function rowsQuery(runtime: Runtime, plan: Plan): Promise<QueryResult>;
|
|
11
11
|
export declare function planned(runtime: Runtime, input: unknown, reach: PortReach | null): Promise<Plan>;
|
|
12
|
-
export declare function roomTallies(runtime: Runtime, rooms: readonly QueryRoom[], since: string): Promise<readonly import("./tallies.
|
|
12
|
+
export declare function roomTallies(runtime: Runtime, rooms: readonly QueryRoom[], since: string): Promise<readonly import("./tallies.ts").RoomTally[]>;
|
|
13
13
|
export declare function watchPlan(runtime: Runtime, plan: Plan, deliver: Deliver, fail: Fail): () => void;
|
|
14
14
|
export declare function watchPlanned(runtime: Runtime, planning: Promise<Plan>, deliver: Deliver, fail: Fail): () => void;
|
|
15
15
|
export declare function searched(runtime: Runtime, input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
package/dist/queries.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAK5C,OAAO,EAIL,KAAK,IAAI,EACT,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAa,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAGhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,KAAK,EAAa,SAAS,EAAgB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAK5C,OAAO,EAIL,KAAK,IAAI,EACT,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAa,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAGhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAA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/mdmodel';
|
|
2
2
|
import { ROOM_TOTALS } from './figures.js';
|
|
3
3
|
import { roomInFlight } from './install.js';
|
|
4
|
-
import { roomFacts } from './listing.js';
|
|
4
|
+
import { compositionFor, roomFacts } from './listing.js';
|
|
5
5
|
import { lockedRooms } from './locks.js';
|
|
6
6
|
import { OFFLINE, UNCERTAIN, failure } from './outcome.js';
|
|
7
7
|
import { connectionNow, prepare, roomsOfReach } from './preparation.js';
|
|
@@ -13,10 +13,10 @@ import { searchPlanOf } from './search.js';
|
|
|
13
13
|
import { seedApplies, seededResult, watchSeeded } from './seed.js';
|
|
14
14
|
import { capped, MAXIMUM_WINDOW } from './windows.js';
|
|
15
15
|
const QUERY_BYTES = 1 << 20;
|
|
16
|
-
function everyRoom({
|
|
16
|
+
function everyRoom({ presence }, held) {
|
|
17
17
|
return [
|
|
18
18
|
...new Set([
|
|
19
|
-
...
|
|
19
|
+
...presence.rooms().map(({ locator }) => locator),
|
|
20
20
|
...held.rooms.keys(),
|
|
21
21
|
...held.queues.keys(),
|
|
22
22
|
]),
|
|
@@ -29,10 +29,8 @@ function reachedRooms(runtime, plan, held) {
|
|
|
29
29
|
.filter((locator) => (reached === null || reached.has(locator)) && !plan.locked.includes(locator))
|
|
30
30
|
.sort();
|
|
31
31
|
}
|
|
32
|
-
function awaited({ socket }, locator) {
|
|
33
|
-
return (!socket.session.now().roomsListed ||
|
|
34
|
-
(socket.rooms.declared(locator) !== undefined &&
|
|
35
|
-
socket.rooms.discovered(locator)?.replica.admission === 'admitted'));
|
|
32
|
+
function awaited({ socket, presence }, locator) {
|
|
33
|
+
return (!socket.session.now().roomsListed || presence.room(locator)?.replica.admission === 'admitted');
|
|
36
34
|
}
|
|
37
35
|
function coveredRooms(runtime, locators, whole, held) {
|
|
38
36
|
const { store, socket } = runtime;
|
|
@@ -119,7 +117,22 @@ async function windowRows(local, plan, rooms, unchanged) {
|
|
|
119
117
|
}
|
|
120
118
|
return null;
|
|
121
119
|
}
|
|
122
|
-
|
|
120
|
+
function freeTextAsked(plan) {
|
|
121
|
+
return plan.shape.kind === 'documents' && (plan.shape.sections !== null || plan.shape.preamble);
|
|
122
|
+
}
|
|
123
|
+
async function composedRooms(runtime, plan, rooms) {
|
|
124
|
+
if (!freeTextAsked(plan))
|
|
125
|
+
return rooms;
|
|
126
|
+
const held = await runtime.store.rooms(rooms.map(({ locator }) => locator));
|
|
127
|
+
return rooms.map((room) => {
|
|
128
|
+
const stored = held.get(room.locator);
|
|
129
|
+
return stored === undefined
|
|
130
|
+
? room
|
|
131
|
+
: { ...room, composition: compositionFor(runtime, stored.record) };
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async function coveredRows(runtime, plan, cover) {
|
|
135
|
+
const { store } = runtime;
|
|
123
136
|
for (;;) {
|
|
124
137
|
const before = await cover();
|
|
125
138
|
if ('pending' in before)
|
|
@@ -128,7 +141,7 @@ async function coveredRows({ store }, plan, cover) {
|
|
|
128
141
|
const keys = before.rooms.map(({ key }) => key);
|
|
129
142
|
const changes = local.changes(keys);
|
|
130
143
|
const current = () => local.changes(keys) === changes;
|
|
131
|
-
const rows = await windowRows(local, plan, before.rooms, current);
|
|
144
|
+
const rows = await windowRows(local, plan, await composedRooms(runtime, plan, before.rooms), current);
|
|
132
145
|
const after = await cover();
|
|
133
146
|
if (rows !== null && sameCover(before, after))
|
|
134
147
|
return { rows, cover: before, current };
|
|
@@ -213,7 +226,7 @@ export function watchPlanned(runtime, planning, deliver, fail) {
|
|
|
213
226
|
};
|
|
214
227
|
}
|
|
215
228
|
export async function searched(runtime, input, reach) {
|
|
216
|
-
const { store, socket
|
|
229
|
+
const { store, socket } = runtime;
|
|
217
230
|
const { session } = socket;
|
|
218
231
|
const asked = searchPlanOf(input);
|
|
219
232
|
await socket.ready;
|
|
@@ -249,12 +262,10 @@ export async function searched(runtime, input, reach) {
|
|
|
249
262
|
const { closed, authorization, refusal } = session.now();
|
|
250
263
|
if (closed || authorization === undefined || refusal !== null)
|
|
251
264
|
return UNCERTAIN;
|
|
252
|
-
journal.record('transfer search');
|
|
253
265
|
try {
|
|
254
266
|
const result = await search(authorization, { text: asked.text, rooms });
|
|
255
267
|
if (result.kind === 'revoked-authorization')
|
|
256
268
|
await refuse(runtime, 'revoked-authorization');
|
|
257
|
-
journal.record(`outcome search ${result.kind}`);
|
|
258
269
|
if (result.kind === 'rejected')
|
|
259
270
|
return result;
|
|
260
271
|
if (result.kind !== 'found')
|
|
@@ -266,7 +277,6 @@ export async function searched(runtime, input, reach) {
|
|
|
266
277
|
};
|
|
267
278
|
}
|
|
268
279
|
catch {
|
|
269
|
-
journal.record('outcome search transport-uncertainty');
|
|
270
280
|
return UNCERTAIN;
|
|
271
281
|
}
|
|
272
282
|
}
|
package/dist/questions.d.ts
CHANGED
|
@@ -26,9 +26,4 @@ export declare function entered(field: ChatField): boolean;
|
|
|
26
26
|
export declare function questionsOf(view: Pick<ConversationView, 'questions'> | null): readonly ChatQuestion[];
|
|
27
27
|
export declare function openQuestion(questions: readonly unknown[]): string | null;
|
|
28
28
|
export declare function questionAsked(questions: readonly unknown[]): string | null;
|
|
29
|
-
export type ChatLone = {
|
|
30
|
-
readonly question: ChatQuestion;
|
|
31
|
-
readonly field: ChatField;
|
|
32
|
-
};
|
|
33
|
-
export declare function loneOf(questions: readonly ChatQuestion[]): ChatLone | null;
|
|
34
29
|
//# sourceMappingURL=questions.d.ts.map
|
package/dist/questions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"questions.d.ts","sourceRoot":"","sources":["../src/questions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG1D,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AA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,wBAAgB,WAAW,CACzB,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,CAAC,GAAG,IAAI,GAC/C,SAAS,YAAY,EAAE,CAiBzB;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,GAAG,IAAI,CAKzE;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,GAAG,IAAI,CAE1E"}
|
package/dist/questions.js
CHANGED
|
@@ -113,10 +113,3 @@ export function openQuestion(questions) {
|
|
|
113
113
|
export function questionAsked(questions) {
|
|
114
114
|
return questionsOf({ questions })[0]?.asked ?? null;
|
|
115
115
|
}
|
|
116
|
-
export function loneOf(questions) {
|
|
117
|
-
const asked = questions.length === 1 && !questions[0].secret ? questions[0] : undefined;
|
|
118
|
-
const only = asked?.fields.length === 1 ? asked.fields[0] : undefined;
|
|
119
|
-
return asked !== undefined && only !== undefined && entered(only)
|
|
120
|
-
? { question: asked, field: only }
|
|
121
|
-
: null;
|
|
122
|
-
}
|
package/dist/queue.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ import type { Runtime } from './runtime.js';
|
|
|
5
5
|
import type { SavePlan } from './save.js';
|
|
6
6
|
import type { SaveResult } from './saves.js';
|
|
7
7
|
import type { PendingState, RoomCommit, Store, StoredFile, View, Work } from './store.js';
|
|
8
|
-
export type Queueing = Pick<Runtime, 'store' | '
|
|
8
|
+
export type Queueing = Pick<Runtime, 'store' | 'localSaves'> & {
|
|
9
9
|
readonly socket: Pick<Runtime['socket'], 'continuing'>;
|
|
10
|
+
readonly presence: Pick<Runtime['presence'], 'lost' | 'unheldModel' | 'room'>;
|
|
10
11
|
};
|
|
11
12
|
export type Restand = {
|
|
12
13
|
readonly locator: string;
|
package/dist/queue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AA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C,SAAS,OAAO,EAAE,CAAC,GACvE,OAAO,CAAC,IAAI,CAAC,CAoCf;AAED,wBAAgB,QAAQ,CACtB,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAiDf;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvD;AAED,wBAAsB,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CA4DzF"}
|
package/dist/queue.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
2
2
|
import { leaving as leavingIn, partnerOf } from './change.js';
|
|
3
3
|
import { composedOf, definitionsAt } from './collection.js';
|
|
4
|
+
import { declared } from './declaration.js';
|
|
4
5
|
import { runtimeError } from './failure.js';
|
|
5
6
|
import { roomDraftRevision } from './identity.js';
|
|
6
7
|
import { landed, movedBy, overlayOf, replaying, slicing, slicingWith, standing, storedRecord, touchedBy, } from './replica.js';
|
|
@@ -44,18 +45,23 @@ async function returnedDrafts(store, locator, work, leaving, composition) {
|
|
|
44
45
|
continue;
|
|
45
46
|
for (const saved of work.states.get(batch.id)?.drafts ?? []) {
|
|
46
47
|
const existing = written.get(saved.path) ?? (await store.draft(locator, saved.path));
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
revision: roomDraftRevision(),
|
|
51
|
-
parts: returnedInto(existing?.parts, saved.parts, composition === undefined ? undefined : definitionsAt(composition, saved.path)),
|
|
52
|
-
returned,
|
|
53
|
-
});
|
|
48
|
+
const parts = returnedInto(existing?.parts, saved.parts, composition === undefined ? undefined : definitionsAt(composition, saved.path));
|
|
49
|
+
written.set(saved.path, parts === null
|
|
50
|
+
? { ...existing, returned }
|
|
51
|
+
: { locator, path: saved.path, revision: roomDraftRevision(), parts, returned });
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
return written;
|
|
57
55
|
}
|
|
58
|
-
|
|
56
|
+
function unheldComposition({ store, presence }, locator) {
|
|
57
|
+
const model = presence.unheldModel(locator);
|
|
58
|
+
const listed = presence.room(locator);
|
|
59
|
+
if (model === null || listed === undefined)
|
|
60
|
+
return undefined;
|
|
61
|
+
return store.composed({ model, declaration: declared(listed) });
|
|
62
|
+
}
|
|
63
|
+
async function carriedBack(runtime, locator, unlanded, written) {
|
|
64
|
+
const { store } = runtime;
|
|
59
65
|
const back = new Map();
|
|
60
66
|
const taken = [];
|
|
61
67
|
for (const batch of unlanded) {
|
|
@@ -74,12 +80,16 @@ async function carriedBack(store, locator, unlanded, written) {
|
|
|
74
80
|
const [into, key] = source === locator ? [written, path] : [back, documentKey(source, path)];
|
|
75
81
|
const existing = into.get(key) ?? (await store.draft(source, path));
|
|
76
82
|
const held = await store.record(source);
|
|
83
|
+
const composition = held === undefined ? unheldComposition(runtime, source) : store.composed(held);
|
|
84
|
+
const parts = returnedInto(existing?.parts, record.parts, composition === undefined ? undefined : definitionsAt(composition, path));
|
|
85
|
+
if (parts === null)
|
|
86
|
+
continue;
|
|
77
87
|
taken.push({ locator: destination, path: to });
|
|
78
88
|
into.set(key, {
|
|
79
89
|
locator: source,
|
|
80
90
|
path,
|
|
81
91
|
revision: roomDraftRevision(),
|
|
82
|
-
parts
|
|
92
|
+
parts,
|
|
83
93
|
returned: existing?.returned ?? null,
|
|
84
94
|
});
|
|
85
95
|
}
|
|
@@ -156,7 +166,7 @@ async function together(runtime, local, settlements) {
|
|
|
156
166
|
return mergeChangeSets(all.map((one) => one.apply(answer)));
|
|
157
167
|
}
|
|
158
168
|
async function settlement(runtime, local, locator, work, record, queue, settling = {}) {
|
|
159
|
-
const { store,
|
|
169
|
+
const { store, localSaves } = runtime;
|
|
160
170
|
const before = work.replica;
|
|
161
171
|
const view = settling.view ?? 'confirmed';
|
|
162
172
|
const previousQueue = work.queue;
|
|
@@ -191,7 +201,7 @@ async function settlement(runtime, local, locator, work, record, queue, settling
|
|
|
191
201
|
...(settling.leaving ?? []),
|
|
192
202
|
];
|
|
193
203
|
const written = await returnedDrafts(store, locator, work, returning, composition);
|
|
194
|
-
const carried = await carriedBack(
|
|
204
|
+
const carried = await carriedBack(runtime, locator, [
|
|
195
205
|
...[...unqueued].reverse().flatMap(({ batch, landed: held }) => (held ? [] : [batch])),
|
|
196
206
|
...(settling.leaving ?? []).flatMap(({ batch, returned }) => returned === null ? [] : [batch]),
|
|
197
207
|
], written);
|
|
@@ -235,10 +245,6 @@ async function settlement(runtime, local, locator, work, record, queue, settling
|
|
|
235
245
|
store.landed.drop(locator, batch.id);
|
|
236
246
|
}
|
|
237
247
|
const drafts = [...written.keys(), ...carried.taken];
|
|
238
|
-
for (const { batch, landed: held } of unqueued) {
|
|
239
|
-
const outcome = localSaves ? 'dropped' : held ? 'landed' : 'withdrawn';
|
|
240
|
-
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
241
|
-
}
|
|
242
248
|
const changed = answer.changed[locator];
|
|
243
249
|
if (settling.commit?.published !== undefined ||
|
|
244
250
|
settling.commit?.refreshed === true ||
|
|
@@ -260,29 +266,20 @@ async function settlement(runtime, local, locator, work, record, queue, settling
|
|
|
260
266
|
};
|
|
261
267
|
}
|
|
262
268
|
async function unpairing(runtime, local, locator, batches) {
|
|
263
|
-
const { store,
|
|
269
|
+
const { store, localSaves } = runtime;
|
|
264
270
|
const ids = new Set(batches.map(({ id }) => id));
|
|
265
271
|
const leaving = batches.map((batch) => ({
|
|
266
272
|
batch,
|
|
267
273
|
returned: !localSaves && leavingIn(batch, locator) ? returnedBy() : null,
|
|
268
274
|
}));
|
|
269
|
-
const outcome = localSaves ? 'dropped' : 'unpaired';
|
|
270
275
|
const work = await store.work(locator);
|
|
271
276
|
const current = work.replica;
|
|
272
277
|
if (current !== undefined) {
|
|
273
|
-
|
|
274
|
-
return {
|
|
275
|
-
...settled,
|
|
276
|
-
apply(answer) {
|
|
277
|
-
for (const batch of batches)
|
|
278
|
-
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
279
|
-
return settled.apply(answer);
|
|
280
|
-
},
|
|
281
|
-
};
|
|
278
|
+
return settlement(runtime, local, locator, work, current.record, current.queue.filter((one) => !ids.has(one.id)), { leaving });
|
|
282
279
|
}
|
|
283
280
|
const queue = work.queue.filter((one) => !ids.has(one.id));
|
|
284
|
-
const written = await returnedDrafts(store, locator, work, leaving,
|
|
285
|
-
const carried = await carriedBack(
|
|
281
|
+
const written = await returnedDrafts(store, locator, work, leaving, unheldComposition(runtime, locator));
|
|
282
|
+
const carried = await carriedBack(runtime, locator, leaving.flatMap(({ batch, returned }) => (returned === null ? [] : [batch])), written);
|
|
286
283
|
return {
|
|
287
284
|
locator,
|
|
288
285
|
left: batches,
|
|
@@ -300,8 +297,6 @@ async function unpairing(runtime, local, locator, batches) {
|
|
|
300
297
|
],
|
|
301
298
|
},
|
|
302
299
|
apply() {
|
|
303
|
-
for (const batch of batches)
|
|
304
|
-
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
305
300
|
return mergeChangeSets([
|
|
306
301
|
changeSet(locator, {
|
|
307
302
|
queue: true,
|
|
@@ -437,7 +432,7 @@ export async function append(runtime, appending) {
|
|
|
437
432
|
catch {
|
|
438
433
|
return { outcome: 'refused', code: 'durable-write', retryable: true };
|
|
439
434
|
}
|
|
440
|
-
const lost = answer.fenced ?? plan.rooms.find(({ locator }) =>
|
|
435
|
+
const lost = answer.fenced ?? plan.rooms.find(({ locator }) => runtime.presence.lost(locator))?.locator;
|
|
441
436
|
if (lost !== undefined)
|
|
442
437
|
throw runtimeError('unknown-room', `Unknown Room ${lost}`);
|
|
443
438
|
const [saving] = plan.rooms;
|
package/dist/reach.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":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