@agentshouse/mdruntime 0.1.0-c806ecaf4afed → 0.1.0-c83bc1fac9b35
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 +21 -19
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +15 -24
- package/dist/act-lanes.d.ts +11 -14
- package/dist/act-lanes.d.ts.map +1 -1
- package/dist/act-lanes.js +53 -5
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +138 -68
- package/dist/adapter.d.ts +86 -14
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +0 -5
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/change.d.ts +4 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +3 -0
- package/dist/chat-types.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +0 -2
- package/dist/client.d.ts +14 -11
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +18 -46
- package/dist/collection.d.ts +5 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +16 -8
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +2 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +17 -5
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +21 -16
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +23 -7
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +18 -6
- package/dist/conversation-row.d.ts +8 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +20 -7
- package/dist/conversation.d.ts +20 -7
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +238 -174
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +36 -9
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +5 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +5 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +23 -12
- 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 +6 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +4 -2
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/host.d.ts +6 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +50 -16
- package/dist/house-query.d.ts +21 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +41 -0
- package/dist/index.d.ts +14 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/install.d.ts +10 -4
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +45 -46
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +50 -32
- package/dist/listing.d.ts +24 -12
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +50 -21
- package/dist/live.d.ts +5 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +71 -30
- package/dist/loaded.d.ts +5 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +40 -0
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +4 -3
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +2 -3
- package/dist/media.d.ts +18 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +102 -24
- package/dist/memory.d.ts +5 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +58 -14
- package/dist/messages.d.ts +12 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +24 -10
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +4 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +5 -8
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +206 -69
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +20 -10
- package/dist/outcome.d.ts +13 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +32 -2
- package/dist/overlay.d.ts +4 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +11 -9
- package/dist/parts.d.ts +4 -9
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -15
- package/dist/preparation.d.ts +32 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +189 -87
- package/dist/presence.d.ts +8 -2
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +24 -13
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +81 -64
- package/dist/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +1 -7
- package/dist/queue.d.ts +2 -2
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +73 -48
- package/dist/reach.d.ts +14 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +142 -30
- package/dist/react.d.ts +10 -11
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +22 -4
- package/dist/readiness.d.ts +16 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +10 -10
- package/dist/reads.d.ts +4 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +7 -3
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +1 -3
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +2 -2
- 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 +30 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +253 -30
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +5 -2
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +2 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +6 -6
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +5 -4
- 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 -124
- package/dist/saves.d.ts +2 -0
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +42 -18
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/shown.d.ts +5 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +79 -43
- 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/session.d.ts +4 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +4 -3
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +4 -9
- package/dist/source.d.ts +5 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +13 -2
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +20 -5
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +60 -22
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store.d.ts +17 -10
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +18 -6
- package/dist/stored.d.ts +25 -13
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +80 -27
- package/dist/surface.d.ts +12 -6
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +58 -26
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +75 -39
- package/dist/tables.d.ts +16 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +86 -324
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +1 -2
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +3 -9
- package/dist/wire.d.ts +33 -10
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +15 -8
- package/package.json +3 -3
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
package/dist/queries.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { identityOf } from '@agentshouse/mdmodel';
|
|
2
2
|
import { ROOM_TOTALS } from './figures.js';
|
|
3
3
|
import { roomInFlight } from './install.js';
|
|
4
|
-
import {
|
|
4
|
+
import { readerOf } from './live.js';
|
|
5
|
+
import { compositionFor, roomFacts } from './listing.js';
|
|
5
6
|
import { lockedRooms } from './locks.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import { askedOnline, offline } from './online.js';
|
|
8
|
+
import { OFFLINE, UNCERTAIN, failure, undeclared } from './outcome.js';
|
|
9
|
+
import { prepare } from './preparation.js';
|
|
8
10
|
import { planWithin, } from './query.js';
|
|
9
11
|
import { planReach } from './reach.js';
|
|
10
|
-
import {
|
|
11
|
-
import { documentKey } from './rows.js';
|
|
12
|
+
import { documentKey, roomsOfReach } from './rows.js';
|
|
12
13
|
import { searchPlanOf } from './search.js';
|
|
13
14
|
import { seedApplies, seededResult, watchSeeded } from './seed.js';
|
|
14
15
|
import { capped, MAXIMUM_WINDOW } from './windows.js';
|
|
@@ -22,35 +23,47 @@ function everyRoom({ presence }, held) {
|
|
|
22
23
|
]),
|
|
23
24
|
];
|
|
24
25
|
}
|
|
26
|
+
function anyHeld({ presence }, held, locator) {
|
|
27
|
+
return (presence.room(locator) !== undefined || held.rooms.has(locator) || held.queues.has(locator));
|
|
28
|
+
}
|
|
29
|
+
function anyRoom(plan) {
|
|
30
|
+
return plan.rooms === null && plan.reach === null;
|
|
31
|
+
}
|
|
32
|
+
function reaching(runtime, plan, reads, held) {
|
|
33
|
+
if (!anyRoom(plan))
|
|
34
|
+
return reads;
|
|
35
|
+
return (locator) => reads(locator) && anyHeld(runtime, held, locator);
|
|
36
|
+
}
|
|
25
37
|
function reachedRooms(runtime, plan, held) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
return [...new Set(named)]
|
|
29
|
-
.filter((locator) => (reached === null || reached.has(locator)) && !plan.locked.includes(locator))
|
|
30
|
-
.sort();
|
|
38
|
+
const named = plan.rooms ?? (plan.reach === null ? everyRoom(runtime, held) : roomsOfReach(plan.reach));
|
|
39
|
+
return [...new Set(named)].filter(reaching(runtime, plan, readerOf(plan), held)).sort();
|
|
31
40
|
}
|
|
32
41
|
function awaited({ socket, presence }, locator) {
|
|
33
42
|
return (!socket.session.now().roomsListed || presence.room(locator)?.replica.admission === 'admitted');
|
|
34
43
|
}
|
|
44
|
+
function awaitsOf(runtime, locator, held) {
|
|
45
|
+
const replica = held.rooms.get(locator);
|
|
46
|
+
if (replica === undefined)
|
|
47
|
+
return awaited(runtime, locator) ? 'acquisition' : null;
|
|
48
|
+
return replica.indexed ? null : 'preparation';
|
|
49
|
+
}
|
|
35
50
|
function coveredRooms(runtime, locators, whole, held) {
|
|
36
51
|
const { store, socket } = runtime;
|
|
37
|
-
if (
|
|
52
|
+
if (whole &&
|
|
53
|
+
!socket.session.now().roomsListed &&
|
|
54
|
+
(locators.length === 0 || !store.device.now().completedWhenOpened))
|
|
38
55
|
return { pending: [] };
|
|
39
56
|
const pending = [];
|
|
40
57
|
const coverage = [];
|
|
41
58
|
const overlay = [];
|
|
42
59
|
const read = [];
|
|
43
60
|
for (const locator of locators) {
|
|
61
|
+
const awaits = awaitsOf(runtime, locator, held);
|
|
62
|
+
if (awaits !== null)
|
|
63
|
+
pending.push({ room: locator, awaits });
|
|
44
64
|
const replica = held.rooms.get(locator);
|
|
45
|
-
if (replica === undefined)
|
|
46
|
-
if (awaited(runtime, locator))
|
|
47
|
-
pending.push({ room: locator, awaits: 'acquisition' });
|
|
65
|
+
if (awaits !== null || replica === undefined)
|
|
48
66
|
continue;
|
|
49
|
-
}
|
|
50
|
-
if (!replica.indexed) {
|
|
51
|
-
pending.push({ room: locator, awaits: 'preparation' });
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
67
|
coverage.push({
|
|
55
68
|
room: locator,
|
|
56
69
|
generation: replica.transfer,
|
|
@@ -65,7 +78,19 @@ function coveredRooms(runtime, locators, whole, held) {
|
|
|
65
78
|
return { coverage: { rooms: coverage, overlay }, rooms: read };
|
|
66
79
|
}
|
|
67
80
|
function covered(runtime, plan, held) {
|
|
68
|
-
return coveredRooms(runtime, reachedRooms(runtime, plan, held), plan
|
|
81
|
+
return coveredRooms(runtime, reachedRooms(runtime, plan, held), anyRoom(plan), held);
|
|
82
|
+
}
|
|
83
|
+
function pendingAt(runtime, plan, reads, held, rooms) {
|
|
84
|
+
const reached = reaching(runtime, plan, reads, held);
|
|
85
|
+
const at = new Map();
|
|
86
|
+
for (const room of rooms) {
|
|
87
|
+
const awaits = reached(room) ? awaitsOf(runtime, room, held) : null;
|
|
88
|
+
at.set(room, awaits === null ? null : { room, awaits });
|
|
89
|
+
}
|
|
90
|
+
awaitPreparation(runtime, {
|
|
91
|
+
pending: [...at.values()].filter((room) => room !== null),
|
|
92
|
+
});
|
|
93
|
+
return at;
|
|
69
94
|
}
|
|
70
95
|
function awaitPreparation(runtime, cover) {
|
|
71
96
|
if (!('pending' in cover))
|
|
@@ -117,7 +142,22 @@ async function windowRows(local, plan, rooms, unchanged) {
|
|
|
117
142
|
}
|
|
118
143
|
return null;
|
|
119
144
|
}
|
|
120
|
-
|
|
145
|
+
function freeTextAsked(plan) {
|
|
146
|
+
return plan.shape.kind === 'documents' && (plan.shape.sections !== null || plan.shape.preamble);
|
|
147
|
+
}
|
|
148
|
+
async function composedRooms(runtime, plan, rooms) {
|
|
149
|
+
if (!freeTextAsked(plan))
|
|
150
|
+
return rooms;
|
|
151
|
+
const held = await runtime.store.rooms(rooms.map(({ locator }) => locator));
|
|
152
|
+
return rooms.map((room) => {
|
|
153
|
+
const stored = held.get(room.locator);
|
|
154
|
+
return stored === undefined
|
|
155
|
+
? room
|
|
156
|
+
: { ...room, composition: compositionFor(runtime, stored.record) };
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
async function coveredRows(runtime, plan, cover) {
|
|
160
|
+
const { store } = runtime;
|
|
121
161
|
for (;;) {
|
|
122
162
|
const before = await cover();
|
|
123
163
|
if ('pending' in before)
|
|
@@ -126,7 +166,7 @@ async function coveredRows({ store }, plan, cover) {
|
|
|
126
166
|
const keys = before.rooms.map(({ key }) => key);
|
|
127
167
|
const changes = local.changes(keys);
|
|
128
168
|
const current = () => local.changes(keys) === changes;
|
|
129
|
-
const rows = await windowRows(local, plan, before.rooms, current);
|
|
169
|
+
const rows = await windowRows(local, plan, await composedRooms(runtime, plan, before.rooms), current);
|
|
130
170
|
const after = await cover();
|
|
131
171
|
if (rows !== null && sameCover(before, after))
|
|
132
172
|
return { rows, cover: before, current };
|
|
@@ -189,11 +229,14 @@ export async function roomTallies(runtime, rooms, since) {
|
|
|
189
229
|
});
|
|
190
230
|
}
|
|
191
231
|
export function watchPlan(runtime, plan, deliver, fail) {
|
|
232
|
+
const reads = readerOf(plan);
|
|
192
233
|
return watchSeeded(runtime, plan, deliver, (behind, answered) => runtime.liveQueries.watch(plan, identityOf(plan), (held) => {
|
|
193
234
|
const cover = covered(runtime, plan, held);
|
|
194
235
|
awaitPreparation(runtime, cover);
|
|
195
236
|
return behind(cover, held);
|
|
196
|
-
},
|
|
237
|
+
}, (held, rooms) => runtime.store.seeds.of(plan.key) === undefined
|
|
238
|
+
? pendingAt(runtime, plan, reads, held, rooms)
|
|
239
|
+
: null, answered, fail));
|
|
197
240
|
}
|
|
198
241
|
export function watchPlanned(runtime, planning, deliver, fail) {
|
|
199
242
|
let stop = null;
|
|
@@ -211,22 +254,13 @@ export function watchPlanned(runtime, planning, deliver, fail) {
|
|
|
211
254
|
};
|
|
212
255
|
}
|
|
213
256
|
export async function searched(runtime, input, reach) {
|
|
214
|
-
const { store, socket
|
|
215
|
-
const { session } = socket;
|
|
257
|
+
const { store, socket } = runtime;
|
|
216
258
|
const asked = searchPlanOf(input);
|
|
217
259
|
await socket.ready;
|
|
218
260
|
const search = socket.search();
|
|
219
|
-
if (search === undefined)
|
|
220
|
-
return
|
|
221
|
-
|
|
222
|
-
code: 'action-undeclared',
|
|
223
|
-
fields: { name: 'search' },
|
|
224
|
-
retryable: false,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
if (socket.closed() ||
|
|
228
|
-
session.now().refusal !== null ||
|
|
229
|
-
(await connectionNow(runtime)) !== 'connected')
|
|
261
|
+
if (search === undefined)
|
|
262
|
+
return undeclared('search');
|
|
263
|
+
if (await offline(runtime))
|
|
230
264
|
return OFFLINE;
|
|
231
265
|
const reached = reach === null ? null : new Set(reach.rooms);
|
|
232
266
|
const named = asked.rooms === null
|
|
@@ -238,33 +272,16 @@ export async function searched(runtime, input, reach) {
|
|
|
238
272
|
const rooms = named === null ? null : named.filter((room) => held.has(room)).sort();
|
|
239
273
|
if (rooms !== null && rooms.length === 0)
|
|
240
274
|
return { kind: 'found', documents: [] };
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
catch {
|
|
275
|
+
const result = await askedOnline(runtime, (authorization) => search(authorization, { text: asked.text, rooms }));
|
|
276
|
+
if (result === null)
|
|
245
277
|
return UNCERTAIN;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
journal.record(`outcome search ${result.kind}`);
|
|
256
|
-
if (result.kind === 'rejected')
|
|
257
|
-
return result;
|
|
258
|
-
if (result.kind !== 'found')
|
|
259
|
-
return failure(result);
|
|
260
|
-
const kept = rooms === null ? null : new Set(rooms);
|
|
261
|
-
return {
|
|
262
|
-
kind: 'found',
|
|
263
|
-
documents: result.documents.filter((hit) => kept === null || kept.has(hit.room)),
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
catch {
|
|
267
|
-
journal.record('outcome search transport-uncertainty');
|
|
268
|
-
return UNCERTAIN;
|
|
269
|
-
}
|
|
278
|
+
if (result.kind === 'rejected')
|
|
279
|
+
return result;
|
|
280
|
+
if (result.kind !== 'found')
|
|
281
|
+
return failure(result);
|
|
282
|
+
const kept = rooms === null ? null : new Set(rooms);
|
|
283
|
+
return {
|
|
284
|
+
kind: 'found',
|
|
285
|
+
documents: result.documents.filter((hit) => kept === null || kept.has(hit.room)),
|
|
286
|
+
};
|
|
270
287
|
}
|
package/dist/questions.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type ChatQuestion = {
|
|
|
16
16
|
readonly interaction: string;
|
|
17
17
|
readonly asked: string | null;
|
|
18
18
|
readonly secret: boolean;
|
|
19
|
+
readonly page: string | null;
|
|
19
20
|
readonly message: string;
|
|
20
21
|
readonly fields: readonly ChatField[];
|
|
21
22
|
readonly undelivered: boolean;
|
|
@@ -26,9 +27,4 @@ export declare function entered(field: ChatField): boolean;
|
|
|
26
27
|
export declare function questionsOf(view: Pick<ConversationView, 'questions'> | null): readonly ChatQuestion[];
|
|
27
28
|
export declare function openQuestion(questions: readonly unknown[]): string | null;
|
|
28
29
|
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
30
|
//# 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;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,cAAc,CAAC;IAC5E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MA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IAC9B,QAAQ,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE3D,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAuCF,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAEjD;AA2DD,wBAAgB,WAAW,CACzB,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,CAAC,GAAG,IAAI,GAC/C,SAAS,YAAY,EAAE,CAkBzB;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
|
@@ -97,6 +97,7 @@ export function questionsOf(view) {
|
|
|
97
97
|
interaction,
|
|
98
98
|
asked: text(one, 'asked_at'),
|
|
99
99
|
secret: one.secret === true,
|
|
100
|
+
page: one.secret === true ? text(one, 'page') : null,
|
|
100
101
|
undelivered: one.telegram_undelivered === true,
|
|
101
102
|
...asked,
|
|
102
103
|
},
|
|
@@ -113,10 +114,3 @@ export function openQuestion(questions) {
|
|
|
113
114
|
export function questionAsked(questions) {
|
|
114
115
|
return questionsOf({ questions })[0]?.asked ?? null;
|
|
115
116
|
}
|
|
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,9 +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'>;
|
|
10
|
+
readonly presence: Pick<Runtime['presence'], 'lost' | 'unheldModel' | 'room'>;
|
|
11
11
|
};
|
|
12
12
|
export type Restand = {
|
|
13
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":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAmC,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAA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O,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,10 +1,11 @@
|
|
|
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';
|
|
7
|
-
import { returnedBy, returnedInto } from './room-draft.js';
|
|
8
|
+
import { joinedOver, marksOver, returnedBy, returnedInto, } from './room-draft.js';
|
|
8
9
|
import { documentKey } from './rows.js';
|
|
9
10
|
import { stepped } from './turn.js';
|
|
10
11
|
export function withdrawable(states) {
|
|
@@ -37,25 +38,39 @@ async function landedWhole(store, record, batch, confirmedLayer, current) {
|
|
|
37
38
|
return false;
|
|
38
39
|
return landed(half, await sliceAt(store, other.record, 'confirmed', [half]), store.composed(other.record));
|
|
39
40
|
}
|
|
40
|
-
async function returnedDrafts(store, locator, work, leaving, composition) {
|
|
41
|
+
async function returnedDrafts(store, locator, work, leaving, composition, visible) {
|
|
41
42
|
const written = new Map();
|
|
42
43
|
for (const { batch, returned } of leaving) {
|
|
43
44
|
if (returned === null || batch.between?.destination.room === locator)
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
const parts = returnedInto(existing?.parts, saved.parts, composition === undefined ? undefined : definitionsAt(composition, saved.path));
|
|
49
|
+
const record = parts === null
|
|
50
|
+
? { ...existing, returned }
|
|
51
|
+
: {
|
|
52
|
+
locator,
|
|
53
|
+
path: saved.path,
|
|
54
|
+
revision: roomDraftRevision(),
|
|
55
|
+
parts,
|
|
56
|
+
marks: existing?.marks ?? {},
|
|
57
|
+
returned,
|
|
58
|
+
};
|
|
59
|
+
const join = visible === undefined ? null : joinedOver(record.parts, record.marks, saved.path, visible);
|
|
60
|
+
written.set(saved.path, join === null ? record : { ...record, ...join, revision: roomDraftRevision() });
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
63
|
return written;
|
|
57
64
|
}
|
|
58
|
-
|
|
65
|
+
function unheldComposition({ store, presence }, locator) {
|
|
66
|
+
const model = presence.unheldModel(locator);
|
|
67
|
+
const listed = presence.room(locator);
|
|
68
|
+
if (model === null || listed === undefined)
|
|
69
|
+
return undefined;
|
|
70
|
+
return store.composed({ model, declaration: declared(listed) });
|
|
71
|
+
}
|
|
72
|
+
async function carriedBack(runtime, locator, unlanded, written) {
|
|
73
|
+
const { store } = runtime;
|
|
59
74
|
const back = new Map();
|
|
60
75
|
const taken = [];
|
|
61
76
|
for (const batch of unlanded) {
|
|
@@ -74,12 +89,17 @@ async function carriedBack(store, locator, unlanded, written) {
|
|
|
74
89
|
const [into, key] = source === locator ? [written, path] : [back, documentKey(source, path)];
|
|
75
90
|
const existing = into.get(key) ?? (await store.draft(source, path));
|
|
76
91
|
const held = await store.record(source);
|
|
92
|
+
const composition = held === undefined ? unheldComposition(runtime, source) : store.composed(held);
|
|
93
|
+
const parts = returnedInto(existing?.parts, record.parts, composition === undefined ? undefined : definitionsAt(composition, path));
|
|
94
|
+
if (parts === null)
|
|
95
|
+
continue;
|
|
77
96
|
taken.push({ locator: destination, path: to });
|
|
78
97
|
into.set(key, {
|
|
79
98
|
locator: source,
|
|
80
99
|
path,
|
|
81
100
|
revision: roomDraftRevision(),
|
|
82
|
-
parts
|
|
101
|
+
parts,
|
|
102
|
+
marks: marksOver(existing?.marks ?? {}, record.marks),
|
|
83
103
|
returned: existing?.returned ?? null,
|
|
84
104
|
});
|
|
85
105
|
}
|
|
@@ -156,7 +176,7 @@ async function together(runtime, local, settlements) {
|
|
|
156
176
|
return mergeChangeSets(all.map((one) => one.apply(answer)));
|
|
157
177
|
}
|
|
158
178
|
async function settlement(runtime, local, locator, work, record, queue, settling = {}) {
|
|
159
|
-
const { store,
|
|
179
|
+
const { store, localSaves } = runtime;
|
|
160
180
|
const before = work.replica;
|
|
161
181
|
const view = settling.view ?? 'confirmed';
|
|
162
182
|
const previousQueue = work.queue;
|
|
@@ -165,37 +185,47 @@ async function settlement(runtime, local, locator, work, record, queue, settling
|
|
|
165
185
|
...(before !== undefined && before.record.key === record.key ? before.overlaid : []),
|
|
166
186
|
...(overrides?.set.map(({ path }) => path) ?? []),
|
|
167
187
|
...(overrides?.removed ?? []),
|
|
188
|
+
...[...work.states.values()].flatMap(({ drafts }) => drafts.map(({ path }) => path)),
|
|
168
189
|
]);
|
|
169
190
|
const confirmedLayer = overrides === undefined
|
|
170
191
|
? read
|
|
171
192
|
: await stepped(slicingWith(read, overrides.set, overrides.removed));
|
|
172
193
|
const composition = store.composed(record);
|
|
173
194
|
const shown = queue.filter((batch) => {
|
|
174
|
-
const held = store.
|
|
195
|
+
const held = store.conflicted.of(locator, batch.id);
|
|
175
196
|
return (held !== undefined &&
|
|
176
|
-
Object.entries(held).some(([path, revision]) => confirmedLayer.revisions[path] !== revision));
|
|
197
|
+
Object.entries(held.revisions).some(([path, revision]) => confirmedLayer.revisions[path] !== revision));
|
|
177
198
|
});
|
|
178
199
|
const unshown = queue.filter((batch) => !shown.includes(batch));
|
|
179
200
|
const { withdrawn, kept } = await stepped(standing(confirmedLayer, unshown, withdrawable(work.states), localSaves, locator, composition));
|
|
180
201
|
const founded = kept.filter((batch) => !unshown.includes(batch));
|
|
181
202
|
const queueChanged = kept.length !== previousQueue.length || founded.length > 0;
|
|
182
|
-
const unqueued = shown.map((batch) =>
|
|
203
|
+
const unqueued = shown.map((batch) => {
|
|
204
|
+
const { returned } = store.conflicted.of(locator, batch.id);
|
|
205
|
+
return {
|
|
206
|
+
batch,
|
|
207
|
+
returned: returned === null || landed(batch, confirmedLayer, composition) ? null : returned,
|
|
208
|
+
};
|
|
209
|
+
});
|
|
183
210
|
for (const batch of withdrawn) {
|
|
184
|
-
|
|
211
|
+
const held = await landedWhole(store, record, batch, confirmedLayer);
|
|
212
|
+
unqueued.push({ batch, returned: held ? null : returnedBy() });
|
|
185
213
|
}
|
|
186
214
|
const returning = [
|
|
187
|
-
...[...unqueued].reverse().map(({ batch,
|
|
215
|
+
...[...unqueued].reverse().map(({ batch, returned }) => ({
|
|
188
216
|
batch,
|
|
189
|
-
returned: localSaves
|
|
217
|
+
returned: localSaves ? null : returned,
|
|
190
218
|
})),
|
|
191
219
|
...(settling.leaving ?? []),
|
|
192
220
|
];
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
|
|
221
|
+
const replayedLayer = await replayed(store, record, confirmedLayer, kept);
|
|
222
|
+
const written = await returnedDrafts(store, locator, work, returning, composition, replayedLayer.visible);
|
|
223
|
+
const carried = await carriedBack(runtime, locator, [
|
|
224
|
+
...[...unqueued]
|
|
225
|
+
.reverse()
|
|
226
|
+
.flatMap(({ batch, returned }) => (returned === null ? [] : [batch])),
|
|
196
227
|
...(settling.leaving ?? []).flatMap(({ batch, returned }) => returned === null ? [] : [batch]),
|
|
197
228
|
], written);
|
|
198
|
-
const replayedLayer = await replayed(store, record, confirmedLayer, kept);
|
|
199
229
|
const { overlay } = await overlayDiff(record, before, replayedLayer.visible, replayedLayer.touched);
|
|
200
230
|
const commit = {
|
|
201
231
|
rooms: [
|
|
@@ -232,13 +262,9 @@ async function settlement(runtime, local, locator, work, record, queue, settling
|
|
|
232
262
|
apply: (answer) => {
|
|
233
263
|
for (const batch of previousQueue) {
|
|
234
264
|
if (!staying.has(batch.id))
|
|
235
|
-
store.
|
|
265
|
+
store.conflicted.drop(locator, batch.id);
|
|
236
266
|
}
|
|
237
267
|
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
268
|
const changed = answer.changed[locator];
|
|
243
269
|
if (settling.commit?.published !== undefined ||
|
|
244
270
|
settling.commit?.refreshed === true ||
|
|
@@ -260,29 +286,20 @@ async function settlement(runtime, local, locator, work, record, queue, settling
|
|
|
260
286
|
};
|
|
261
287
|
}
|
|
262
288
|
async function unpairing(runtime, local, locator, batches) {
|
|
263
|
-
const { store,
|
|
289
|
+
const { store, localSaves } = runtime;
|
|
264
290
|
const ids = new Set(batches.map(({ id }) => id));
|
|
265
291
|
const leaving = batches.map((batch) => ({
|
|
266
292
|
batch,
|
|
267
293
|
returned: !localSaves && leavingIn(batch, locator) ? returnedBy() : null,
|
|
268
294
|
}));
|
|
269
|
-
const outcome = localSaves ? 'dropped' : 'unpaired';
|
|
270
295
|
const work = await store.work(locator);
|
|
271
296
|
const current = work.replica;
|
|
272
297
|
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
|
-
};
|
|
298
|
+
return settlement(runtime, local, locator, work, current.record, current.queue.filter((one) => !ids.has(one.id)), { leaving });
|
|
282
299
|
}
|
|
283
300
|
const queue = work.queue.filter((one) => !ids.has(one.id));
|
|
284
|
-
const written = await returnedDrafts(store, locator, work, leaving, undefined);
|
|
285
|
-
const carried = await carriedBack(
|
|
301
|
+
const written = await returnedDrafts(store, locator, work, leaving, unheldComposition(runtime, locator), undefined);
|
|
302
|
+
const carried = await carriedBack(runtime, locator, leaving.flatMap(({ batch, returned }) => (returned === null ? [] : [batch])), written);
|
|
286
303
|
return {
|
|
287
304
|
locator,
|
|
288
305
|
left: batches,
|
|
@@ -300,8 +317,6 @@ async function unpairing(runtime, local, locator, batches) {
|
|
|
300
317
|
],
|
|
301
318
|
},
|
|
302
319
|
apply() {
|
|
303
|
-
for (const batch of batches)
|
|
304
|
-
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
305
320
|
return mergeChangeSets([
|
|
306
321
|
changeSet(locator, {
|
|
307
322
|
queue: true,
|
|
@@ -368,6 +383,12 @@ export function settle(runtime, locators, decide) {
|
|
|
368
383
|
await settled(runtime, local, settlements, decided.flatMap(({ after }) => (after === undefined ? [] : [after])));
|
|
369
384
|
});
|
|
370
385
|
}
|
|
386
|
+
function awaited(head, confirmedLayer, composition, { affected }, held) {
|
|
387
|
+
const touched = [...touchedBy([head])];
|
|
388
|
+
if (held)
|
|
389
|
+
return landed(head, confirmedLayer, composition) ? [] : touched;
|
|
390
|
+
return touched.filter((path) => Object.hasOwn(affected, path) && confirmedLayer.documents[path] !== affected[path]);
|
|
391
|
+
}
|
|
371
392
|
export function answered(runtime, locator, head, answer) {
|
|
372
393
|
const { store, socket } = runtime;
|
|
373
394
|
return store.exclusive(async () => {
|
|
@@ -381,18 +402,22 @@ export function answered(runtime, locator, head, answer) {
|
|
|
381
402
|
const confirmedLayer = await sliceAt(store, current.record, 'confirmed', [head]);
|
|
382
403
|
const held = answer.kind === 'conflicted' &&
|
|
383
404
|
(await landedWhole(store, current.record, head, confirmedLayer, answer.affected));
|
|
384
|
-
if (held &&
|
|
385
|
-
partnerOf(head, locator) === null &&
|
|
386
|
-
!landed(head, confirmedLayer, store.composed(current.record))) {
|
|
387
|
-
store.landed.hold(locator, head.id, Object.fromEntries([...touchedBy([head])].map((path) => [path, confirmedLayer.revisions[path]])));
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
405
|
const returned = {
|
|
391
406
|
kind: answer.kind,
|
|
392
407
|
code: answer.code,
|
|
393
408
|
fields: answer.fields,
|
|
394
409
|
retryable: answer.retryable,
|
|
395
410
|
};
|
|
411
|
+
if (answer.kind === 'conflicted' && partnerOf(head, locator) === null) {
|
|
412
|
+
const behind = awaited(head, confirmedLayer, store.composed(current.record), answer, held);
|
|
413
|
+
if (behind.length > 0) {
|
|
414
|
+
store.conflicted.hold(locator, head.id, {
|
|
415
|
+
revisions: Object.fromEntries(behind.map((path) => [path, confirmedLayer.revisions[path]])),
|
|
416
|
+
returned: held ? null : returned,
|
|
417
|
+
});
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
396
421
|
await settled(runtime, local, [
|
|
397
422
|
await settlement(runtime, local, locator, work, current.record, current.queue.filter((batch) => batch.id !== head.id), { leaving: [{ batch: head, returned: held ? null : returned }] }),
|
|
398
423
|
], []);
|
package/dist/reach.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ReadinessPort } from './preparation.js';
|
|
1
|
+
import type { ListedRoom } from './listing.js';
|
|
2
|
+
import type { ReadinessMessage, ReadinessPort } from './preparation.js';
|
|
3
|
+
import type { CodeAvailability } from './readiness.js';
|
|
3
4
|
import type { MdRuntime, RuntimeTopic } from './surface.js';
|
|
5
|
+
import type { QueriedRoom } from './adapter.js';
|
|
4
6
|
import type { Plan, PlanReach, QueryResult } from './query.js';
|
|
5
|
-
import type { Readiness } from './readiness.js';
|
|
6
7
|
import type { SearchResult } from './search.js';
|
|
8
|
+
import type { HouseQueryResult } from './house-query.js';
|
|
7
9
|
export type ReachedDocument = {
|
|
8
10
|
readonly room: string;
|
|
9
11
|
readonly path: string;
|
|
@@ -17,6 +19,7 @@ export type PortReach = {
|
|
|
17
19
|
readonly rooms: readonly string[];
|
|
18
20
|
readonly documents: readonly ReachedDocument[];
|
|
19
21
|
readonly areas?: readonly ReachedArea[];
|
|
22
|
+
readonly queriesOnly?: readonly QueriedRoom[];
|
|
20
23
|
readonly conversations: boolean;
|
|
21
24
|
};
|
|
22
25
|
export type Deliver = (message: unknown) => void;
|
|
@@ -28,19 +31,24 @@ export type RuntimeView = {
|
|
|
28
31
|
};
|
|
29
32
|
export type NarrowedView = RuntimeView & {
|
|
30
33
|
narrow(reach: PortReach | null): void;
|
|
34
|
+
code(code: CodeAvailability): void;
|
|
31
35
|
};
|
|
32
36
|
export type Reachable = RuntimeView & {
|
|
33
37
|
plan(input: unknown, reach: PortReach | null): Promise<Plan>;
|
|
34
38
|
query(plan: Plan): Promise<QueryResult>;
|
|
35
39
|
watchPlan(plan: Plan, deliver: Deliver, fail: Fail): () => void;
|
|
36
40
|
search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
|
37
|
-
|
|
41
|
+
queryHouse(input: unknown, reach: PortReach | null): Promise<HouseQueryResult>;
|
|
42
|
+
queried(): readonly QueriedRoom[];
|
|
43
|
+
watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: ReadinessMessage) => void): () => void;
|
|
38
44
|
locked(room: string): Promise<boolean>;
|
|
39
45
|
lockedRooms(): Promise<readonly string[]>;
|
|
40
46
|
watchLocks(notify: () => void): () => void;
|
|
41
47
|
located(room: string, path: string, destination: string): Promise<ReachedDocument | null>;
|
|
42
|
-
room(locator: string): Promise<
|
|
48
|
+
room(locator: string): Promise<ListedRoom | undefined>;
|
|
43
49
|
};
|
|
50
|
+
export declare function queriedOf(reach: PortReach | null, provided: readonly QueriedRoom[]): readonly QueriedRoom[];
|
|
51
|
+
export declare function queriedOnly(reach: PortReach | null, provided: readonly QueriedRoom[], room: string): boolean;
|
|
44
52
|
export declare function holds(reach: PortReach | null, room: string): boolean;
|
|
45
53
|
export declare function governs(reach: PortReach | null, room: {
|
|
46
54
|
readonly locator: string;
|
|
@@ -52,5 +60,5 @@ export declare function governs(reach: PortReach | null, room: {
|
|
|
52
60
|
readonly selection: boolean;
|
|
53
61
|
};
|
|
54
62
|
export declare function planReach(reach: PortReach | null): PlanReach | null;
|
|
55
|
-
export declare function narrowed(runtime: Reachable, given: PortReach | null,
|
|
63
|
+
export declare function narrowed(runtime: Reachable, given: PortReach | null, attached: ReadinessPort): NarrowedView;
|
|
56
64
|
//# sourceMappingURL=reach.d.ts.map
|
package/dist/reach.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,UAAU,EAA4B,MAAM,cAAc,CAAC;AACvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC;AAEzE,OAAO,KAAK,EAAsB,WAAW,EAAE,MAAM,cAAc,CAAC;AA4BpE,OAAO,KAAK,EAAiB,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAS9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,MAAM,MAAM,eAAe,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC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