@agentshouse/mdruntime 0.1.0-c1e8a8738a009 → 0.1.0-c1ea23b9ca7c6
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 +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +299 -0
- 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 +26 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +321 -0
- package/dist/adapter.d.ts +192 -109
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -11
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +20 -60
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/bootstrap.d.ts +12 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +213 -89
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +5 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +11 -0
- package/dist/client.d.ts +37 -24
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +48 -59
- package/dist/collection.d.ts +27 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +29 -27
- 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 +8 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +287 -335
- package/dist/connection.d.ts +6 -144
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +114 -5246
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-live.d.ts +152 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +261 -0
- package/dist/conversation-row.d.ts +40 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +66 -0
- package/dist/conversation.d.ts +72 -52
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1007 -906
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +12 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -0
- 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 +20 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +16 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +60 -21
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +8 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +199 -0
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- 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 +24 -8
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +105 -43
- package/dist/house-query.d.ts +15 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +43 -0
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +41 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -5
- package/dist/install.d.ts +60 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +290 -0
- package/dist/listing.d.ts +60 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +168 -0
- package/dist/live.d.ts +9 -6
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +118 -36
- 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 +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +34 -0
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +49 -0
- package/dist/media.d.ts +19 -2
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +131 -31
- package/dist/memory.d.ts +20 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +257 -104
- package/dist/messages.d.ts +35 -5
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +113 -39
- 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 +6 -13
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -23
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -0
- package/dist/observation.d.ts +30 -13
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +218 -81
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +5 -5
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +69 -0
- package/dist/outcome.d.ts +17 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +35 -2
- package/dist/overlay.d.ts +7 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +48 -24
- 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 +6 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +36 -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 +45 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +335 -0
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +287 -0
- package/dist/query.d.ts +14 -210
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/questions.d.ts +30 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +117 -0
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +25 -15
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +329 -152
- package/dist/react.d.ts +21 -3
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +18 -20
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +14 -20
- package/dist/reads.d.ts +38 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +164 -77
- package/dist/recovery.d.ts +4 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +59 -2
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +35 -7
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +11 -17
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +66 -36
- 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 +34 -10
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +331 -111
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +220 -0
- 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 +16 -22
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +49 -186
- 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 +35 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +42 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +332 -228
- package/dist/saves.d.ts +34 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +437 -0
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -105
- package/dist/shown.d.ts +35 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +326 -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 +28 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +103 -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/session.d.ts +41 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +26 -0
- package/dist/socket.d.ts +68 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +165 -0
- package/dist/source.d.ts +59 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +93 -0
- package/dist/status.d.ts +0 -6
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +40 -0
- package/dist/store/readiness.d.ts +11 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +68 -0
- package/dist/store/records.d.ts +227 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +468 -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/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/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 +116 -156
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +174 -394
- package/dist/stored.d.ts +80 -41
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +437 -220
- package/dist/surface.d.ts +94 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +255 -0
- package/dist/sync.d.ts +21 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +557 -0
- package/dist/tables.d.ts +118 -94
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +199 -321
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +128 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +42 -106
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +80 -9
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +32 -10
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -370
- package/dist/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
package/dist/reach.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { QueryError } from '@agentshouse/mdmodel';
|
|
2
|
+
import { selected, typesPrint } from './collection.js';
|
|
1
3
|
import { unheldView } from './conversation.js';
|
|
2
|
-
import { modelTypes, NO_MODEL } from './model.js';
|
|
3
|
-
import { changeOf, digestApplied, digestOf, observing, } from './observation.js';
|
|
4
|
-
import { runtimeError } from './failure.js';
|
|
5
|
-
import { failure, lockedRoom, ROOM_LOCKED, undeclared, UNREADABLE, } from './outcome.js';
|
|
4
|
+
import { modelResult, modelTypes, NO_MODEL } from './model.js';
|
|
5
|
+
import { changeOf, digestApplied, digestOf, observing, unchanged, } from './observation.js';
|
|
6
|
+
import { runtimeError, uncaught } from './failure.js';
|
|
7
|
+
import { absentBinary, failure, lockedRoom, ROOM_LOCKED, undeclared, UNREADABLE, } from './outcome.js';
|
|
6
8
|
import { beneath } from './paths.js';
|
|
7
9
|
import { moveTarget, readParts, staleWrite, } from './room-draft.js';
|
|
8
10
|
import { documentKey } from './rows.js';
|
|
9
|
-
import { undeclaredSearch } from './search.js';
|
|
10
11
|
const UNHELD_TYPES = { collection: modelTypes(NO_MODEL), typedSelection: null };
|
|
11
12
|
function unconversed(name) {
|
|
12
13
|
return () => Promise.resolve(undeclared(name));
|
|
@@ -14,33 +15,66 @@ function unconversed(name) {
|
|
|
14
15
|
const NO_CONVERSATION = {
|
|
15
16
|
list: () => Promise.resolve([]),
|
|
16
17
|
read: (conversation) => Promise.resolve(unheldView(conversation)),
|
|
17
|
-
create: unconversed('
|
|
18
|
-
send: unconversed('
|
|
19
|
-
answer: unconversed('
|
|
20
|
-
interrupt: unconversed('
|
|
21
|
-
kill: unconversed('
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
create: unconversed('conversations/create'),
|
|
19
|
+
send: unconversed('conversations/send'),
|
|
20
|
+
answer: unconversed('conversations/interaction/answer'),
|
|
21
|
+
interrupt: unconversed('conversations/interrupt'),
|
|
22
|
+
kill: unconversed('conversations/kill'),
|
|
23
|
+
delete: unconversed('conversations/delete'),
|
|
24
|
+
takeOut: unconversed('conversations/take-out'),
|
|
25
|
+
decide: unconversed('agent-functions/decide'),
|
|
26
|
+
rename: unconversed('conversations/rename'),
|
|
27
|
+
option: unconversed('conversations/option/set'),
|
|
28
|
+
retry: unconversed('conversations/retry'),
|
|
29
|
+
pin: () => Promise.resolve(),
|
|
30
|
+
openTurn: () => Promise.resolve(),
|
|
31
|
+
dismissSuggestion: () => Promise.resolve(),
|
|
32
|
+
attach: () => Promise.resolve(undeclared('conversation.attach')),
|
|
33
|
+
attachment: (link) => Promise.resolve(absentBinary(link)),
|
|
24
34
|
};
|
|
25
35
|
const NO_CHAT_DRAFT = {
|
|
26
36
|
write: () => Promise.resolve(),
|
|
27
37
|
prepend: () => Promise.resolve(),
|
|
38
|
+
append: () => Promise.resolve(),
|
|
28
39
|
discard: () => Promise.resolve(),
|
|
29
40
|
};
|
|
30
41
|
function areasOf(reach) {
|
|
31
42
|
return reach.areas ?? [];
|
|
32
43
|
}
|
|
33
|
-
function
|
|
34
|
-
return
|
|
44
|
+
export function queriedOf(reach, provided) {
|
|
45
|
+
return reach === null ? provided : (reach.queriesOnly ?? []);
|
|
46
|
+
}
|
|
47
|
+
export function queriedOnly(reach, provided, room) {
|
|
48
|
+
return queriedOf(reach, provided).some((queried) => queried.locator === room);
|
|
49
|
+
}
|
|
50
|
+
function queriedRoom({ name, locator, handle }) {
|
|
51
|
+
return {
|
|
52
|
+
name,
|
|
53
|
+
locator,
|
|
54
|
+
handle,
|
|
55
|
+
queriesOnly: true,
|
|
56
|
+
operations: { write: [], erase: [] },
|
|
57
|
+
replica: { selection: locator, admission: 'unavailable', offline: 'locked' },
|
|
58
|
+
model: modelResult(NO_MODEL, typesPrint),
|
|
59
|
+
typedSelection: null,
|
|
60
|
+
providerOwnedPaths: [],
|
|
61
|
+
authoredPaths: [],
|
|
62
|
+
roomVersion: null,
|
|
63
|
+
documents: 0,
|
|
64
|
+
synchronizationAvailable: false,
|
|
65
|
+
refusal: null,
|
|
66
|
+
locked: false,
|
|
67
|
+
};
|
|
35
68
|
}
|
|
36
69
|
function fenced(reach, room, path) {
|
|
37
|
-
return areasOf(reach).some((area) => area.room === room &&
|
|
70
|
+
return areasOf(reach).some((area) => area.room === room &&
|
|
71
|
+
beneath(area.path, path) &&
|
|
72
|
+
!area.open.some((open) => beneath(open, path)));
|
|
38
73
|
}
|
|
39
74
|
export function holds(reach, room) {
|
|
40
75
|
return (reach === null ||
|
|
41
76
|
reach.rooms.includes(room) ||
|
|
42
|
-
reach.documents.some((document) => document.room === room)
|
|
43
|
-
typedAreas(reach, room).length > 0);
|
|
77
|
+
reach.documents.some((document) => document.room === room));
|
|
44
78
|
}
|
|
45
79
|
function wholly(reach, room) {
|
|
46
80
|
return reach === null || reach.rooms.includes(room);
|
|
@@ -49,14 +83,11 @@ export function governs(reach, room) {
|
|
|
49
83
|
if (wholly(reach, room.locator)) {
|
|
50
84
|
return { collection: true, selection: room.typedSelection !== null };
|
|
51
85
|
}
|
|
52
|
-
const
|
|
53
|
-
const paths =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
...typedAreas(reach, room.locator).map(({ path }) => path),
|
|
58
|
-
];
|
|
59
|
-
return { collection: paths.some((path) => !selected(path)), selection: paths.some(selected) };
|
|
86
|
+
const within = (path) => selected({ selection: room.typedSelection }, path);
|
|
87
|
+
const paths = reach.documents
|
|
88
|
+
.filter((document) => document.room === room.locator)
|
|
89
|
+
.map(({ path }) => path);
|
|
90
|
+
return { collection: paths.some((path) => !within(path)), selection: paths.some(within) };
|
|
60
91
|
}
|
|
61
92
|
function covers(reach, room, path) {
|
|
62
93
|
return (reach === null ||
|
|
@@ -67,6 +98,31 @@ function covers(reach, room, path) {
|
|
|
67
98
|
function conversing(reach) {
|
|
68
99
|
return reach === null || reach.conversations;
|
|
69
100
|
}
|
|
101
|
+
function roomsAwaited(error, reach) {
|
|
102
|
+
return error.code === 'unknown-type' && reach !== null && reach.rooms.length === 0;
|
|
103
|
+
}
|
|
104
|
+
function queriedIn(input, reach, provided) {
|
|
105
|
+
const rooms = input?.rooms;
|
|
106
|
+
return Array.isArray(rooms)
|
|
107
|
+
? rooms.find((room) => typeof room === 'string' && queriedOnly(reach, provided, room))
|
|
108
|
+
: undefined;
|
|
109
|
+
}
|
|
110
|
+
async function planInReach(runtime, input, reach, answered) {
|
|
111
|
+
const queried = queriedIn(input, reach, runtime.queried());
|
|
112
|
+
if (queried !== undefined) {
|
|
113
|
+
if (answered)
|
|
114
|
+
return null;
|
|
115
|
+
throw queriesOnlyError(queried);
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return await runtime.plan(input, reach);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (error instanceof QueryError && (answered || roomsAwaited(error, reach)))
|
|
122
|
+
return null;
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
70
126
|
export function planReach(reach) {
|
|
71
127
|
return reach === null
|
|
72
128
|
? null
|
|
@@ -76,12 +132,35 @@ export function planReach(reach) {
|
|
|
76
132
|
...new Set(reach.documents.map(({ room, path }) => documentKey(room, path))),
|
|
77
133
|
].sort(),
|
|
78
134
|
areas: areasOf(reach)
|
|
79
|
-
.map(({ room, path,
|
|
135
|
+
.map(({ room, path, open }) => ({ room, path, open: [...new Set(open)].sort() }))
|
|
80
136
|
.sort((left, right) => documentKey(left.room, left.path) < documentKey(right.room, right.path) ? -1 : 1),
|
|
81
137
|
};
|
|
82
138
|
}
|
|
83
|
-
function
|
|
84
|
-
|
|
139
|
+
function modelsOf(rooms, models) {
|
|
140
|
+
const named = new Set(rooms.flatMap(({ model, typedSelection }) => [model.types, typedSelection?.model.types]));
|
|
141
|
+
return Object.fromEntries(Object.entries(models).filter(([key]) => named.has(key)));
|
|
142
|
+
}
|
|
143
|
+
function roomsWithin(reach, provided, { rooms, models }) {
|
|
144
|
+
const within = rooms.filter((room) => wholly(reach, room.locator));
|
|
145
|
+
return {
|
|
146
|
+
rooms: [...within, ...queriedOf(reach, provided).map(queriedRoom)],
|
|
147
|
+
models: modelsOf(within, models),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function roomsChangeWithin(reach, provided, { changed, removed, order, models }) {
|
|
151
|
+
const kept = changed.filter(([locator]) => wholly(reach, locator));
|
|
152
|
+
const within = {
|
|
153
|
+
changed: kept,
|
|
154
|
+
removed,
|
|
155
|
+
order: order === null
|
|
156
|
+
? null
|
|
157
|
+
: [
|
|
158
|
+
...order.filter((locator) => wholly(reach, locator)),
|
|
159
|
+
...queriedOf(reach, provided).map(({ locator }) => locator),
|
|
160
|
+
],
|
|
161
|
+
models: modelsOf(kept.map(([, room]) => room), models),
|
|
162
|
+
};
|
|
163
|
+
return unchanged(within) ? null : within;
|
|
85
164
|
}
|
|
86
165
|
function typesWithin(reach, room, types) {
|
|
87
166
|
if (room === undefined)
|
|
@@ -112,12 +191,13 @@ function writeWithin(reach, write) {
|
|
|
112
191
|
function savedWithin(reach, room, result) {
|
|
113
192
|
if (reach === null || result.outcome === 'saved')
|
|
114
193
|
return result;
|
|
115
|
-
const { file, location, referrers, ...refusal } = result;
|
|
194
|
+
const { file, location, line, referrers, ...refusal } = result;
|
|
116
195
|
const hidden = file !== undefined && !covers(reach, room, file);
|
|
117
196
|
return {
|
|
118
197
|
...refusal,
|
|
119
198
|
...(file === undefined || hidden ? {} : { file }),
|
|
120
199
|
...(location === undefined || hidden ? {} : { location }),
|
|
200
|
+
...(line === undefined || hidden ? {} : { line }),
|
|
121
201
|
...(referrers === undefined
|
|
122
202
|
? {}
|
|
123
203
|
: { referrers: referrers.filter((path) => covers(reach, room, path)) }),
|
|
@@ -126,7 +206,7 @@ function savedWithin(reach, room, result) {
|
|
|
126
206
|
function statusWithin(reach, status) {
|
|
127
207
|
return {
|
|
128
208
|
...status,
|
|
129
|
-
attentionRequired: status.attentionRequired.filter((entry) =>
|
|
209
|
+
attentionRequired: status.attentionRequired.filter((entry) => covers(reach, entry.room, entry.path)),
|
|
130
210
|
unsent: status.unsent.filter((change) => covers(reach, change.room, change.path)),
|
|
131
211
|
};
|
|
132
212
|
}
|
|
@@ -144,104 +224,180 @@ function queueWithin(reach, room, entries) {
|
|
|
144
224
|
});
|
|
145
225
|
}
|
|
146
226
|
function unreached(room) {
|
|
147
|
-
return runtimeError('room
|
|
227
|
+
return runtimeError('unknown-room', `Unknown Room ${room}`);
|
|
148
228
|
}
|
|
149
229
|
function lockedError(room) {
|
|
150
230
|
return runtimeError(ROOM_LOCKED, `${room} is locked until House confirms its access`, true);
|
|
151
231
|
}
|
|
152
232
|
function deviceUnreached() {
|
|
153
|
-
return runtimeError('device-unreached', 'Only the panel
|
|
233
|
+
return runtimeError('device-unreached', 'Only the panel reaches this device');
|
|
154
234
|
}
|
|
155
235
|
const ATTACH_REQUIRED = 'attach-required';
|
|
236
|
+
const QUERIES_ONLY = 'queries-only';
|
|
237
|
+
function queriesOnlyError(room) {
|
|
238
|
+
return runtimeError(QUERIES_ONLY, `${room} answers through queryHouse`);
|
|
239
|
+
}
|
|
156
240
|
function attachRequired() {
|
|
157
241
|
return runtimeError(ATTACH_REQUIRED, 'App code takes a file in with binaryFile.attach');
|
|
158
242
|
}
|
|
159
243
|
function carriesFile(parts) {
|
|
160
244
|
return parts !== null && typeof parts === 'object' && Object.hasOwn(parts, 'file');
|
|
161
245
|
}
|
|
162
|
-
export function narrowed(runtime, given,
|
|
246
|
+
export function narrowed(runtime, given, attached) {
|
|
163
247
|
const { md, watch } = runtime;
|
|
164
248
|
let reach = given;
|
|
165
|
-
let port =
|
|
249
|
+
let port = attached;
|
|
166
250
|
const open = new Set();
|
|
167
|
-
|
|
251
|
+
const coded = new Set();
|
|
252
|
+
function following(begin, locking = false, restarts = open) {
|
|
168
253
|
let stop = begin();
|
|
169
254
|
const restart = () => {
|
|
170
255
|
stop();
|
|
171
256
|
stop = begin();
|
|
172
257
|
};
|
|
173
258
|
open.add(restart);
|
|
259
|
+
restarts.add(restart);
|
|
174
260
|
const unwatch = locking ? runtime.watchLocks(restart) : () => { };
|
|
175
261
|
return () => {
|
|
176
262
|
open.delete(restart);
|
|
263
|
+
restarts.delete(restart);
|
|
177
264
|
unwatch();
|
|
178
265
|
stop();
|
|
179
266
|
};
|
|
180
267
|
}
|
|
181
|
-
const unlocking = (rooms) => {
|
|
182
|
-
const
|
|
183
|
-
return
|
|
184
|
-
? null
|
|
185
|
-
: { pending: locked.map((room) => ({ room, awaits: 'unlock' })) };
|
|
268
|
+
const unlocking = (rooms, locked) => {
|
|
269
|
+
const held = (rooms ?? []).filter((room) => locked.includes(room));
|
|
270
|
+
return held.length === 0 ? null : { pending: held.map((room) => ({ room, awaits: 'unlock' })) };
|
|
186
271
|
};
|
|
187
|
-
const unlocked = (entries) => entries.filter((entry) => !
|
|
188
|
-
const intoLocked = (held) =>
|
|
189
|
-
|
|
272
|
+
const unlocked = (entries, locked) => entries.filter((entry) => !locked.includes(entry.room));
|
|
273
|
+
const intoLocked = async (held) => {
|
|
274
|
+
for (const move of held) {
|
|
275
|
+
if (move?.room !== undefined && (await runtime.locked(move.room)))
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
};
|
|
280
|
+
function ordered(deliver) {
|
|
281
|
+
let open = true;
|
|
282
|
+
let shown = Promise.resolve();
|
|
283
|
+
return {
|
|
284
|
+
push(making) {
|
|
285
|
+
shown = shown.then(() => making.then((value) => {
|
|
286
|
+
if (open)
|
|
287
|
+
deliver(value);
|
|
288
|
+
}, uncaught), uncaught);
|
|
289
|
+
},
|
|
290
|
+
stop() {
|
|
291
|
+
open = false;
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function unlockedWatch(topic, input, deliver, fail, within) {
|
|
296
|
+
const shown = ordered(deliver);
|
|
297
|
+
const stop = watch(topic, input, (message) => {
|
|
298
|
+
shown.push(runtime.lockedRooms().then((locked) => within(message, locked)));
|
|
299
|
+
}, fail);
|
|
300
|
+
return () => {
|
|
301
|
+
shown.stop();
|
|
302
|
+
stop();
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function lockedFirst(room, start, shut) {
|
|
306
|
+
let open = true;
|
|
307
|
+
let stop = () => { };
|
|
308
|
+
void (async () => {
|
|
309
|
+
const closed = !holds(reach, room) || (await runtime.locked(room));
|
|
310
|
+
if (!open)
|
|
311
|
+
return;
|
|
312
|
+
if (closed)
|
|
313
|
+
shut();
|
|
314
|
+
else
|
|
315
|
+
stop = start();
|
|
316
|
+
})();
|
|
317
|
+
return () => {
|
|
318
|
+
open = false;
|
|
319
|
+
stop();
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
const within = (topic, input, deliver, fail) => {
|
|
323
|
+
if (topic === 'read' && reach !== null) {
|
|
324
|
+
fail(deviceUnreached());
|
|
325
|
+
return () => { };
|
|
326
|
+
}
|
|
190
327
|
if (topic === 'rooms') {
|
|
191
|
-
return following(() => watch(topic, input, (rooms) =>
|
|
328
|
+
return following(() => watch(topic, input, (rooms) => {
|
|
329
|
+
const shown = 'rooms' in rooms
|
|
330
|
+
? roomsWithin(reach, runtime.queried(), rooms)
|
|
331
|
+
: roomsChangeWithin(reach, runtime.queried(), rooms);
|
|
332
|
+
if (shown !== null)
|
|
333
|
+
deliver(shown);
|
|
334
|
+
}, fail));
|
|
192
335
|
}
|
|
193
336
|
if (topic === 'readiness') {
|
|
194
|
-
return following(() => runtime.watchReadiness(port, reach, deliver));
|
|
337
|
+
return following(() => runtime.watchReadiness(port, reach, deliver), false, coded);
|
|
195
338
|
}
|
|
196
339
|
if (topic === 'sync-status') {
|
|
197
|
-
return following(() =>
|
|
198
|
-
const
|
|
199
|
-
|
|
340
|
+
return following(() => unlockedWatch(topic, input, deliver, fail, (status, locked) => {
|
|
341
|
+
const shown = statusWithin(reach, status);
|
|
342
|
+
return { ...shown, attentionRequired: unlocked(shown.attentionRequired, locked) };
|
|
200
343
|
}), true);
|
|
201
344
|
}
|
|
202
345
|
if (topic === 'room-drafts') {
|
|
203
|
-
return following(() =>
|
|
346
|
+
return following(() => unlockedWatch(topic, input, deliver, fail, (drafts, locked) => unlocked(draftsWithin(reach, drafts), locked)), true);
|
|
204
347
|
}
|
|
205
348
|
if (topic === 'queue') {
|
|
206
349
|
const room = input[0];
|
|
207
|
-
return following(() =>
|
|
208
|
-
if (!holds(reach, room) || runtime.locked(room)) {
|
|
209
|
-
deliver([]);
|
|
210
|
-
return () => { };
|
|
211
|
-
}
|
|
212
|
-
return watch(topic, input, (entries) => deliver(queueWithin(reach, room, entries)));
|
|
213
|
-
}, true);
|
|
350
|
+
return following(() => lockedFirst(room, () => watch(topic, input, (entries) => deliver(queueWithin(reach, room, entries)), fail), () => deliver([])), true);
|
|
214
351
|
}
|
|
215
352
|
if (topic === 'query') {
|
|
216
|
-
const plan = runtime.plan(input[0], reach);
|
|
217
353
|
let held = null;
|
|
354
|
+
let planning = null;
|
|
355
|
+
const waiting = (result) => {
|
|
356
|
+
const answer = { result, keys: [] };
|
|
357
|
+
if (held === null || changeOf(held, answer) !== null)
|
|
358
|
+
deliver(answer);
|
|
359
|
+
held = digestOf(answer);
|
|
360
|
+
};
|
|
218
361
|
return following(() => {
|
|
219
|
-
const locked = unlocking(plan.rooms);
|
|
220
|
-
if (locked !== null) {
|
|
221
|
-
const answer = { result: locked, keys: [] };
|
|
222
|
-
if (held === null || changeOf(held, answer) !== null)
|
|
223
|
-
deliver(answer);
|
|
224
|
-
held = digestOf(answer);
|
|
225
|
-
return () => { };
|
|
226
|
-
}
|
|
227
|
-
let first = true;
|
|
228
362
|
let open = true;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
363
|
+
let stop = () => { };
|
|
364
|
+
if (planning?.reach !== reach) {
|
|
365
|
+
planning = { reach, plan: planInReach(runtime, input[0], reach, held !== null) };
|
|
366
|
+
}
|
|
367
|
+
const planned = planning.plan;
|
|
368
|
+
void (async () => {
|
|
369
|
+
const plan = await planned;
|
|
370
|
+
const locked = await runtime.lockedRooms();
|
|
371
|
+
if (!open)
|
|
233
372
|
return;
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
373
|
+
if (plan === null)
|
|
374
|
+
return waiting({ pending: [] });
|
|
375
|
+
const pending = unlocking(plan.rooms, locked);
|
|
376
|
+
if (pending !== null)
|
|
377
|
+
return waiting(pending);
|
|
378
|
+
let first = true;
|
|
379
|
+
const heard = (message) => {
|
|
380
|
+
if (!first) {
|
|
381
|
+
held = digestApplied(held, message);
|
|
382
|
+
deliver(message);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
first = false;
|
|
386
|
+
const change = held === null ? message : changeOf(held, message);
|
|
387
|
+
held = digestOf(message);
|
|
388
|
+
if (change !== null)
|
|
389
|
+
deliver(change);
|
|
390
|
+
};
|
|
391
|
+
stop = runtime.watchPlan({ ...plan, locked }, (message) => {
|
|
392
|
+
if (open)
|
|
393
|
+
heard(message);
|
|
394
|
+
}, (error) => {
|
|
395
|
+
if (open)
|
|
396
|
+
fail(error);
|
|
397
|
+
});
|
|
398
|
+
})().catch((error) => {
|
|
243
399
|
if (open)
|
|
244
|
-
|
|
400
|
+
fail(error);
|
|
245
401
|
});
|
|
246
402
|
return () => {
|
|
247
403
|
open = false;
|
|
@@ -252,7 +408,7 @@ export function narrowed(runtime, given, told) {
|
|
|
252
408
|
if (topic === 'conversation') {
|
|
253
409
|
return following(() => {
|
|
254
410
|
if (conversing(reach))
|
|
255
|
-
return watch(topic, input, deliver);
|
|
411
|
+
return watch(topic, input, deliver, fail);
|
|
256
412
|
deliver(unheldView(input[0]));
|
|
257
413
|
return () => { };
|
|
258
414
|
});
|
|
@@ -260,12 +416,21 @@ export function narrowed(runtime, given, told) {
|
|
|
260
416
|
if (topic === 'conversations' || topic === 'agents') {
|
|
261
417
|
return following(() => {
|
|
262
418
|
if (conversing(reach))
|
|
263
|
-
return watch(topic, input, deliver);
|
|
419
|
+
return watch(topic, input, deliver, fail);
|
|
264
420
|
deliver([]);
|
|
265
421
|
return () => { };
|
|
266
422
|
});
|
|
267
423
|
}
|
|
268
|
-
|
|
424
|
+
if (topic === 'figures' ||
|
|
425
|
+
topic === 'holdings' ||
|
|
426
|
+
topic === 'listed-agents' ||
|
|
427
|
+
topic === 'room-list') {
|
|
428
|
+
if (reach === null)
|
|
429
|
+
return watch(topic, input, deliver, fail);
|
|
430
|
+
fail(deviceUnreached());
|
|
431
|
+
return () => { };
|
|
432
|
+
}
|
|
433
|
+
return watch(topic, input, deliver, fail);
|
|
269
434
|
};
|
|
270
435
|
const files = new Map();
|
|
271
436
|
let handed = 0;
|
|
@@ -282,34 +447,37 @@ export function narrowed(runtime, given, told) {
|
|
|
282
447
|
const chatDraft = () => (conversing(reach) ? md.chatDraft : NO_CHAT_DRAFT);
|
|
283
448
|
const view = {
|
|
284
449
|
...md,
|
|
285
|
-
rooms: () => md.rooms().then((rooms) => roomsWithin(reach, rooms)),
|
|
286
|
-
query: ((input) => {
|
|
287
|
-
const plan = runtime
|
|
288
|
-
|
|
450
|
+
rooms: () => md.rooms().then((rooms) => roomsWithin(reach, runtime.queried(), rooms)),
|
|
451
|
+
query: (async (input) => {
|
|
452
|
+
const plan = await planInReach(runtime, input, reach, false);
|
|
453
|
+
if (plan === null)
|
|
454
|
+
return { pending: [] };
|
|
455
|
+
const locked = await runtime.lockedRooms();
|
|
456
|
+
return unlocking(plan.rooms, locked) ?? runtime.query({ ...plan, locked });
|
|
289
457
|
}),
|
|
290
|
-
search: (input) =>
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (holds(reach, room) && runtime.locked(room))
|
|
458
|
+
search: (input) => runtime.search(input, reach),
|
|
459
|
+
queryHouse: (input) => runtime.queryHouse(input, reach),
|
|
460
|
+
async types(room) {
|
|
461
|
+
if (holds(reach, room) && (await runtime.locked(room)))
|
|
295
462
|
throw lockedError(room);
|
|
296
463
|
if (wholly(reach, room))
|
|
297
464
|
return md.types(room);
|
|
298
465
|
if (!holds(reach, room))
|
|
299
466
|
return structuredClone(UNHELD_TYPES);
|
|
300
|
-
return typesWithin(reach, runtime.room(room), md.types(room));
|
|
467
|
+
return typesWithin(reach, await runtime.room(room), await md.types(room));
|
|
301
468
|
},
|
|
302
469
|
async save(room, roomDrafts, writtenBy) {
|
|
303
470
|
if (!holds(reach, room))
|
|
304
471
|
throw unreached(room);
|
|
305
|
-
if (runtime.locked(room))
|
|
472
|
+
if (await runtime.locked(room)) {
|
|
306
473
|
return { outcome: 'refused', code: ROOM_LOCKED, retryable: true };
|
|
474
|
+
}
|
|
307
475
|
const held = (await Promise.all(roomDrafts.map(({ path }) => md.roomDraft.read(room, path)))).map((draft) => draft?.parts.move);
|
|
308
476
|
const outside = roomDrafts.find(({ path }, at) => !covers(reach, room, path) || !moves(reach, room, held[at]));
|
|
309
477
|
if (outside !== undefined) {
|
|
310
478
|
return { outcome: 'refused', code: 'stale', retryable: false, file: outside.path };
|
|
311
479
|
}
|
|
312
|
-
if (intoLocked(held))
|
|
480
|
+
if (await intoLocked(held))
|
|
313
481
|
return { outcome: 'refused', code: ROOM_LOCKED, retryable: true };
|
|
314
482
|
return savedWithin(reach, room, await md.save(room, roomDrafts, writtenBy));
|
|
315
483
|
},
|
|
@@ -320,47 +488,48 @@ export function narrowed(runtime, given, told) {
|
|
|
320
488
|
if (filed !== undefined) {
|
|
321
489
|
return { outcome: 'refused', code: ATTACH_REQUIRED, retryable: false, file: filed.path };
|
|
322
490
|
}
|
|
323
|
-
if (runtime.locked(room))
|
|
491
|
+
if (await runtime.locked(room)) {
|
|
324
492
|
return { outcome: 'refused', code: ROOM_LOCKED, retryable: true };
|
|
325
|
-
|
|
493
|
+
}
|
|
494
|
+
const held = parts.map(({ path, parts: one }) => readParts(one, path).move);
|
|
326
495
|
if (parts.some(({ path }, at) => !covers(reach, room, path) || !moves(reach, room, held[at]))) {
|
|
327
496
|
throw unreached(room);
|
|
328
497
|
}
|
|
329
|
-
if (intoLocked(held))
|
|
498
|
+
if (await intoLocked(held))
|
|
330
499
|
return { outcome: 'refused', code: ROOM_LOCKED, retryable: true };
|
|
331
500
|
return savedWithin(reach, room, await md.saveParts(room, parts, writtenBy));
|
|
332
501
|
},
|
|
333
|
-
resolve(room, path, destination) {
|
|
334
|
-
const at = runtime.located(room, path, destination);
|
|
502
|
+
async resolve(room, path, destination) {
|
|
503
|
+
const at = await runtime.located(room, path, destination);
|
|
335
504
|
return at !== null && !covers(reach, at.room, at.path)
|
|
336
|
-
?
|
|
505
|
+
? UNREADABLE
|
|
337
506
|
: md.resolve(room, path, destination);
|
|
338
507
|
},
|
|
339
|
-
history: (room, path, query) => !covers(reach, room, path)
|
|
340
|
-
?
|
|
341
|
-
: runtime.locked(room)
|
|
342
|
-
?
|
|
508
|
+
history: async (room, path, query) => !covers(reach, room, path)
|
|
509
|
+
? failure({ kind: 'room-not-readable', locator: room })
|
|
510
|
+
: (await runtime.locked(room))
|
|
511
|
+
? lockedRoom(room)
|
|
343
512
|
: md.history(room, path, query),
|
|
344
513
|
binaryFile: {
|
|
345
|
-
read: (room, path, revision) => !covers(reach, room, path)
|
|
346
|
-
?
|
|
347
|
-
: runtime.locked(room)
|
|
348
|
-
?
|
|
514
|
+
read: async (room, path, revision) => !covers(reach, room, path)
|
|
515
|
+
? failure({ kind: 'room-not-readable', locator: room })
|
|
516
|
+
: (await runtime.locked(room))
|
|
517
|
+
? lockedRoom(room)
|
|
349
518
|
: hand(md.binaryFile.read(room, path, revision)),
|
|
350
|
-
link: (room, path, revision) => !covers(reach, room, path)
|
|
351
|
-
?
|
|
352
|
-
: runtime.locked(room)
|
|
353
|
-
?
|
|
519
|
+
link: async (room, path, revision) => !covers(reach, room, path)
|
|
520
|
+
? failure({ kind: 'room-not-readable', locator: room })
|
|
521
|
+
: (await runtime.locked(room))
|
|
522
|
+
? lockedRoom(room)
|
|
354
523
|
: md.binaryFile.link(room, path, revision),
|
|
355
|
-
show: (room, path, revision) => !covers(reach, room, path)
|
|
356
|
-
?
|
|
357
|
-
: runtime.locked(room)
|
|
358
|
-
?
|
|
524
|
+
show: async (room, path, revision) => !covers(reach, room, path)
|
|
525
|
+
? failure({ kind: 'room-not-readable', locator: room })
|
|
526
|
+
: (await runtime.locked(room))
|
|
527
|
+
? lockedRoom(room)
|
|
359
528
|
: hand(md.binaryFile.show(room, path, revision)),
|
|
360
|
-
attach: (room, file) => !wholly(reach, room)
|
|
361
|
-
?
|
|
362
|
-
: runtime.locked(room)
|
|
363
|
-
?
|
|
529
|
+
attach: async (room, file) => !wholly(reach, room)
|
|
530
|
+
? failure({ kind: 'room-not-readable', locator: room })
|
|
531
|
+
: (await runtime.locked(room))
|
|
532
|
+
? lockedRoom(room)
|
|
364
533
|
: md.binaryFile.attach(room, file),
|
|
365
534
|
async part(file, part) {
|
|
366
535
|
const key = files.get(file);
|
|
@@ -373,42 +542,38 @@ export function narrowed(runtime, given, told) {
|
|
|
373
542
|
},
|
|
374
543
|
},
|
|
375
544
|
reached: async (room, roomVersion, path) => (path === undefined ? wholly(reach, room) : covers(reach, room, path)) &&
|
|
376
|
-
!runtime.locked(room) &&
|
|
545
|
+
!(await runtime.locked(room)) &&
|
|
377
546
|
(await md.reached(room, roomVersion, path)),
|
|
378
|
-
log: () => (reach === null ? md.log() : ''),
|
|
379
547
|
cleanUp: () => (reach === null ? md.cleanUp() : Promise.reject(deviceUnreached())),
|
|
548
|
+
unsent: () => (reach === null ? md.unsent() : Promise.reject(deviceUnreached())),
|
|
549
|
+
sent: () => (reach === null ? md.sent() : Promise.reject(deviceUnreached())),
|
|
550
|
+
reset: () => (reach === null ? md.reset() : Promise.reject(deviceUnreached())),
|
|
551
|
+
readAgain: () => (reach === null ? md.readAgain() : Promise.reject(deviceUnreached())),
|
|
380
552
|
roomDraft: {
|
|
381
|
-
list: () => md.roomDraft.list()
|
|
553
|
+
list: async () => unlocked(draftsWithin(reach, await md.roomDraft.list()), await runtime.lockedRooms()),
|
|
382
554
|
async read(room, path) {
|
|
383
555
|
if (!covers(reach, room, path))
|
|
384
556
|
return null;
|
|
385
|
-
if (runtime.locked(room))
|
|
557
|
+
if (await runtime.locked(room))
|
|
386
558
|
throw lockedError(room);
|
|
387
559
|
return shownDraft(reach, await md.roomDraft.read(room, path));
|
|
388
560
|
},
|
|
389
|
-
write(room, path, revision, parts, next) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
catch (error) {
|
|
402
|
-
return Promise.reject(error);
|
|
403
|
-
}
|
|
404
|
-
return md.roomDraft
|
|
405
|
-
.write(room, path, revision, parts, next)
|
|
406
|
-
.then((written) => writeWithin(reach, written));
|
|
561
|
+
async write(room, path, revision, parts, next) {
|
|
562
|
+
if (reach !== null && carriesFile(parts))
|
|
563
|
+
throw attachRequired();
|
|
564
|
+
const move = readParts(parts, path).move;
|
|
565
|
+
if (!covers(reach, room, path) || !moves(reach, room, move))
|
|
566
|
+
throw unreached(room);
|
|
567
|
+
if (await runtime.locked(room))
|
|
568
|
+
throw lockedError(room);
|
|
569
|
+
if (await intoLocked([move]))
|
|
570
|
+
throw lockedError(move.room);
|
|
571
|
+
return writeWithin(reach, await md.roomDraft.write(room, path, revision, parts, next));
|
|
407
572
|
},
|
|
408
573
|
async discard(room, path, revision) {
|
|
409
574
|
if (!covers(reach, room, path))
|
|
410
575
|
return staleWrite(null);
|
|
411
|
-
if (runtime.locked(room))
|
|
576
|
+
if (await runtime.locked(room))
|
|
412
577
|
throw lockedError(room);
|
|
413
578
|
return writeWithin(reach, await md.roomDraft.discard(room, path, revision));
|
|
414
579
|
},
|
|
@@ -418,15 +583,25 @@ export function narrowed(runtime, given, told) {
|
|
|
418
583
|
read: (id, options) => conversation().read(id, options),
|
|
419
584
|
create: (input) => conversation().create(input),
|
|
420
585
|
send: (id, operation, draft) => conversation().send(id, operation, draft),
|
|
421
|
-
answer: (id, answer) => conversation().answer(id, answer),
|
|
422
|
-
interrupt: (id) => conversation().interrupt(id),
|
|
423
|
-
kill: (id) => conversation().kill(id),
|
|
424
|
-
|
|
425
|
-
|
|
586
|
+
answer: (id, answer, operation) => conversation().answer(id, answer, operation),
|
|
587
|
+
interrupt: (id, operation) => conversation().interrupt(id, operation),
|
|
588
|
+
kill: (id, operation) => conversation().kill(id, operation),
|
|
589
|
+
delete: (id, operation) => conversation().delete(id, operation),
|
|
590
|
+
takeOut: (id, message, operation) => conversation().takeOut(id, message, operation),
|
|
591
|
+
decide: (request, decision, operation) => conversation().decide(request, decision, operation),
|
|
592
|
+
rename: (id, name, operation) => conversation().rename(id, name, operation),
|
|
593
|
+
option: (id, option, value, operation) => conversation().option(id, option, value, operation),
|
|
594
|
+
retry: (id, message, operation) => conversation().retry(id, message, operation),
|
|
595
|
+
pin: (figures) => conversation().pin(figures),
|
|
596
|
+
openTurn: (id, turn) => conversation().openTurn(id, turn),
|
|
597
|
+
dismissSuggestion: (id, suggestion) => conversation().dismissSuggestion(id, suggestion),
|
|
598
|
+
attach: (file) => conversation().attach(file),
|
|
599
|
+
attachment: (link) => conversation().attachment(link),
|
|
426
600
|
},
|
|
427
601
|
chatDraft: {
|
|
428
602
|
write: (id, draft, revision) => chatDraft().write(id, draft, revision),
|
|
429
603
|
prepend: (id, draft) => chatDraft().prepend(id, draft),
|
|
604
|
+
append: (id, draft) => chatDraft().append(id, draft),
|
|
430
605
|
discard: (id) => chatDraft().discard(id),
|
|
431
606
|
},
|
|
432
607
|
observe: observing(within),
|
|
@@ -439,9 +614,11 @@ export function narrowed(runtime, given, told) {
|
|
|
439
614
|
for (const restart of [...open])
|
|
440
615
|
restart();
|
|
441
616
|
},
|
|
442
|
-
|
|
443
|
-
port
|
|
444
|
-
|
|
617
|
+
code(next) {
|
|
618
|
+
if (port.code === next)
|
|
619
|
+
return;
|
|
620
|
+
port = { ...port, code: next };
|
|
621
|
+
for (const restart of [...coded])
|
|
445
622
|
restart();
|
|
446
623
|
},
|
|
447
624
|
};
|