@agentshouse/mdruntime 0.1.0-cf08ada271a7f → 0.1.0-cf08df9b663d8
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 +57 -38
- 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 +173 -83
- package/dist/adapter.d.ts +210 -30
- 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 +2 -7
- package/dist/{binary.d.ts → attachment.d.ts} +8 -4
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change.d.ts +6 -2
- 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 +2 -4
- package/dist/client.d.ts +29 -24
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +49 -64
- package/dist/collection.d.ts +6 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +23 -9
- 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 +4 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +88 -44
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +32 -17
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +26 -11
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +24 -11
- package/dist/conversation-row.d.ts +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +37 -8
- package/dist/conversation.d.ts +45 -11
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +337 -203
- package/dist/declaration.js +3 -3
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +46 -48
- 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 +6 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- 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 +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +6 -4
- 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.map +1 -1
- package/dist/holdings.js +5 -3
- package/dist/host.d.ts +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +94 -30
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +27 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -9
- package/dist/install.d.ts +10 -5
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +49 -55
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +74 -51
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +13 -0
- package/dist/listing.d.ts +27 -20
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +68 -69
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +94 -36
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +10 -38
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +8 -20
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +181 -34
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +99 -37
- package/dist/messages.d.ts +21 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +48 -16
- 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 +10 -7
- 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 +18 -35
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- 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/opened.d.ts +6 -6
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +4 -4
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +22 -10
- package/dist/outcome.d.ts +33 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +36 -6
- package/dist/overlay.d.ts +21 -7
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +112 -39
- 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 +5 -9
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -15
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +207 -96
- 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 +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +137 -79
- package/dist/query.d.ts +2 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -8
- package/dist/queue.d.ts +2 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +76 -49
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +196 -37
- package/dist/react.d.ts +17 -5
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +28 -5
- package/dist/readiness.d.ts +23 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +5 -3
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +26 -14
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +2 -4
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -5
- 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 +31 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +262 -36
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +12 -7
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +47 -0
- package/dist/rows.d.ts +11 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +25 -11
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +98 -0
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/runtime.d.ts +11 -5
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +120 -135
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +116 -65
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -4
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shown.d.ts +8 -5
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +95 -67
- 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 +9 -6
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +17 -16
- package/dist/source.d.ts +42 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +76 -9
- 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 +31 -7
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +70 -24
- 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 +24 -14
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +49 -17
- package/dist/stored.d.ts +41 -16
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +215 -57
- package/dist/surface.d.ts +20 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +66 -32
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +109 -82
- package/dist/tables.d.ts +40 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +109 -326
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +3 -4
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +50 -10
- package/dist/wire.d.ts +68 -8
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +28 -11
- package/package.json +4 -4
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- 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
package/dist/presence.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
export function lockingMode(mode) {
|
|
2
|
+
return mode === 'locked';
|
|
3
|
+
}
|
|
4
|
+
const UNANSWERED = {
|
|
5
|
+
stale: false,
|
|
6
|
+
repairable: null,
|
|
7
|
+
repairing: false,
|
|
8
|
+
reloadDue: false,
|
|
9
|
+
refusal: null,
|
|
10
|
+
unreading: false,
|
|
11
|
+
unreadable: false,
|
|
12
|
+
unheldModel: null,
|
|
13
|
+
confirmed: false,
|
|
14
|
+
};
|
|
15
|
+
// 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.
|
|
16
|
+
const LOCK_GRACE_MS = 120_000;
|
|
17
|
+
export function createPresence(notReadyWaitMs) {
|
|
18
|
+
const listed = new Map();
|
|
19
|
+
const lockable = new Set();
|
|
20
|
+
let listings = 0;
|
|
21
|
+
const answered = new Map();
|
|
22
|
+
const marks = new Map();
|
|
23
|
+
const lastLost = new Map();
|
|
24
|
+
const unready = new Map();
|
|
25
|
+
let lossCount = 0;
|
|
26
|
+
let lockGrace = null;
|
|
27
|
+
function answer(locator) {
|
|
28
|
+
return answered.get(locator) ?? UNANSWERED;
|
|
29
|
+
}
|
|
30
|
+
function change(locator, next) {
|
|
31
|
+
answered.set(locator, { ...answer(locator), ...next });
|
|
32
|
+
}
|
|
33
|
+
function heard(locator, next) {
|
|
34
|
+
if (!marks.has(locator))
|
|
35
|
+
change(locator, next);
|
|
36
|
+
}
|
|
37
|
+
function readied(locator) {
|
|
38
|
+
const held = unready.get(locator);
|
|
39
|
+
if (held === undefined)
|
|
40
|
+
return;
|
|
41
|
+
if (held.timer !== null)
|
|
42
|
+
clearTimeout(held.timer);
|
|
43
|
+
unready.delete(locator);
|
|
44
|
+
}
|
|
45
|
+
function stopAsking(locator) {
|
|
46
|
+
for (const held of locator === undefined ? [...unready.keys()] : [locator])
|
|
47
|
+
readied(held);
|
|
48
|
+
}
|
|
49
|
+
function connectionLive() {
|
|
50
|
+
if (lockGrace !== null)
|
|
51
|
+
clearTimeout(lockGrace);
|
|
52
|
+
lockGrace = null;
|
|
53
|
+
}
|
|
54
|
+
function readable(locator) {
|
|
55
|
+
const { unreadable, unreading } = answer(locator);
|
|
56
|
+
if (!unreadable || marks.has(locator))
|
|
57
|
+
return false;
|
|
58
|
+
change(locator, {
|
|
59
|
+
unreadable: false,
|
|
60
|
+
...(unreading ? { refusal: null, unreading: false } : {}),
|
|
61
|
+
});
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
function locks(locator, mode) {
|
|
65
|
+
return lockingMode(mode) && !answer(locator).confirmed && !marks.has(locator);
|
|
66
|
+
}
|
|
67
|
+
function liftable(locator, discovery) {
|
|
68
|
+
const mark = marks.get(locator);
|
|
69
|
+
return mark === undefined || mark.during < discovery;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
list(found, { whole, live }) {
|
|
73
|
+
listings += 1;
|
|
74
|
+
const kept = found.filter(({ locator }) => !marks.has(locator));
|
|
75
|
+
if (whole) {
|
|
76
|
+
listed.clear();
|
|
77
|
+
lockable.clear();
|
|
78
|
+
}
|
|
79
|
+
for (const room of kept) {
|
|
80
|
+
listed.set(room.locator, room);
|
|
81
|
+
if (lockingMode(room.replica.offline))
|
|
82
|
+
lockable.add(room.locator);
|
|
83
|
+
else
|
|
84
|
+
lockable.delete(room.locator);
|
|
85
|
+
change(room.locator, {
|
|
86
|
+
refusal: null,
|
|
87
|
+
unreading: false,
|
|
88
|
+
...(live && room.replica.admission === 'admitted' ? { confirmed: true } : {}),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return kept;
|
|
92
|
+
},
|
|
93
|
+
room: (locator) => listed.get(locator),
|
|
94
|
+
rooms: () => [...listed.values()],
|
|
95
|
+
available(locator, selection) {
|
|
96
|
+
if (marks.has(locator))
|
|
97
|
+
return false;
|
|
98
|
+
const room = listed.get(locator);
|
|
99
|
+
if (room === undefined)
|
|
100
|
+
return true;
|
|
101
|
+
return ((selection === undefined || selection === room.replica.selection) &&
|
|
102
|
+
room.replica.admission === 'admitted' &&
|
|
103
|
+
!answer(locator).unreadable);
|
|
104
|
+
},
|
|
105
|
+
refusal: (locator) => answer(locator).refusal,
|
|
106
|
+
unheldModel: (locator) => answer(locator).unheldModel,
|
|
107
|
+
refused(locator, refusal) {
|
|
108
|
+
if (refusal === null) {
|
|
109
|
+
heard(locator, { unreadable: true });
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const unreading = refusal.scope !== 'operation' && refusal.scope !== 'model';
|
|
113
|
+
heard(locator, {
|
|
114
|
+
refusal: { code: refusal.code, fields: refusal.fields, retryable: refusal.retryable },
|
|
115
|
+
unreading,
|
|
116
|
+
...(unreading ? { unreadable: true } : {}),
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
readable,
|
|
120
|
+
modelled(locator, model) {
|
|
121
|
+
heard(locator, { unheldModel: model });
|
|
122
|
+
},
|
|
123
|
+
installed(locator, bootstrapped) {
|
|
124
|
+
if (marks.has(locator))
|
|
125
|
+
return;
|
|
126
|
+
if (bootstrapped) {
|
|
127
|
+
readied(locator);
|
|
128
|
+
change(locator, { unheldModel: null });
|
|
129
|
+
}
|
|
130
|
+
change(locator, { stale: false });
|
|
131
|
+
readable(locator);
|
|
132
|
+
},
|
|
133
|
+
async locked(locator, stored) {
|
|
134
|
+
if (marks.has(locator) || answer(locator).confirmed)
|
|
135
|
+
return false;
|
|
136
|
+
return locks(locator, (await stored()) ?? listed.get(locator)?.replica.offline);
|
|
137
|
+
},
|
|
138
|
+
lockedAs: locks,
|
|
139
|
+
lockedAmong(stored, locking) {
|
|
140
|
+
return [...new Set([...lockable, ...locking])]
|
|
141
|
+
.filter((locator) => locks(locator, stored.get(locator)?.offline ?? listed.get(locator)?.replica.offline))
|
|
142
|
+
.sort();
|
|
143
|
+
},
|
|
144
|
+
connectionLost(lapsed) {
|
|
145
|
+
if (lockGrace !== null)
|
|
146
|
+
return;
|
|
147
|
+
lockGrace = setTimeout(() => {
|
|
148
|
+
lockGrace = null;
|
|
149
|
+
lapsed();
|
|
150
|
+
}, LOCK_GRACE_MS);
|
|
151
|
+
},
|
|
152
|
+
connectionLive,
|
|
153
|
+
lapse() {
|
|
154
|
+
for (const [locator, held] of answered) {
|
|
155
|
+
if (held.confirmed)
|
|
156
|
+
answered.set(locator, { ...held, confirmed: false });
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
stood(locator, stale, repairable) {
|
|
160
|
+
heard(locator, { stale, ...(repairable === undefined ? {} : { repairable }) });
|
|
161
|
+
},
|
|
162
|
+
repairing(locator, running) {
|
|
163
|
+
change(locator, { repairing: running });
|
|
164
|
+
},
|
|
165
|
+
reload(locator, due) {
|
|
166
|
+
change(locator, { reloadDue: due });
|
|
167
|
+
},
|
|
168
|
+
standing(locator) {
|
|
169
|
+
const { stale, repairable, repairing, reloadDue } = answer(locator);
|
|
170
|
+
return { stale, repairable, repairing, reloadDue };
|
|
171
|
+
},
|
|
172
|
+
settled: () => ![...answered].some(([locator, { stale }]) => stale && !marks.has(locator)),
|
|
173
|
+
repairsOwed: () => [...answered]
|
|
174
|
+
.filter(([locator, { stale, repairable }]) => stale && repairable !== null && !marks.has(locator))
|
|
175
|
+
.map(([locator]) => locator),
|
|
176
|
+
askAgain(locator, ask) {
|
|
177
|
+
const held = unready.get(locator) ?? { tries: 0, timer: null };
|
|
178
|
+
unready.set(locator, held);
|
|
179
|
+
if (held.timer !== null)
|
|
180
|
+
return;
|
|
181
|
+
const wait = notReadyWaitMs(held.tries);
|
|
182
|
+
held.tries += 1;
|
|
183
|
+
held.timer = setTimeout(() => {
|
|
184
|
+
held.timer = null;
|
|
185
|
+
ask();
|
|
186
|
+
}, wait);
|
|
187
|
+
},
|
|
188
|
+
stopAsking,
|
|
189
|
+
lose(locator, during) {
|
|
190
|
+
if (marks.has(locator))
|
|
191
|
+
return false;
|
|
192
|
+
marks.set(locator, { during, written: false });
|
|
193
|
+
lastLost.set(locator, ++lossCount);
|
|
194
|
+
listings += 1;
|
|
195
|
+
listed.delete(locator);
|
|
196
|
+
lockable.delete(locator);
|
|
197
|
+
readied(locator);
|
|
198
|
+
const { repairing, reloadDue } = answer(locator);
|
|
199
|
+
answered.set(locator, { ...UNANSWERED, repairing, reloadDue });
|
|
200
|
+
return true;
|
|
201
|
+
},
|
|
202
|
+
writing(locator) {
|
|
203
|
+
const mark = marks.get(locator);
|
|
204
|
+
if (mark === undefined || mark.written)
|
|
205
|
+
return false;
|
|
206
|
+
marks.set(locator, { ...mark, written: true });
|
|
207
|
+
return true;
|
|
208
|
+
},
|
|
209
|
+
unwritten(locator) {
|
|
210
|
+
const mark = marks.get(locator);
|
|
211
|
+
if (mark !== undefined)
|
|
212
|
+
marks.set(locator, { ...mark, written: false });
|
|
213
|
+
},
|
|
214
|
+
lost: (locator) => marks.has(locator),
|
|
215
|
+
losing: () => marks.size > 0,
|
|
216
|
+
listing: () => listings,
|
|
217
|
+
losses: () => lossCount,
|
|
218
|
+
lostSince: (locator, losses) => marks.has(locator) || (lastLost.get(locator) ?? 0) > losses,
|
|
219
|
+
liftable,
|
|
220
|
+
lift(locator, discovery, unfenced) {
|
|
221
|
+
const mark = marks.get(locator);
|
|
222
|
+
if (mark !== undefined && liftable(locator, discovery) && (unfenced || !mark.written)) {
|
|
223
|
+
marks.delete(locator);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
close() {
|
|
227
|
+
stopAsking();
|
|
228
|
+
connectionLive();
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
package/dist/queries.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FiguresCover } from './figures.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type Cover, type Ran } from './live.js';
|
|
3
3
|
import { type Plan, type QueryResult } from './query.js';
|
|
4
4
|
import { type Deliver, type Fail, type PortReach } from './reach.js';
|
|
5
5
|
import type { Runtime } from './runtime.js';
|
|
@@ -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,
|
|
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,EAIL,KAAK,KAAK,EAGV,KAAK,GAAG,EACT,MAAM,WAAW,CAAC;AAMnB,OAAO,EAKL,KAAK,IAAI,EACT,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAa,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEhF,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;AA4IrE,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAa1E;AAqID,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,GAC1B,OAAO,CAAC,GAAG,CAAC,CAWd;AAQD,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAWlF;AAED,wBAAsB,OAAO,CAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,SAAS,GAAG,IAAI,GACtB,OAAO,CAAC,IAAI,CAAC,CAOf;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,wDAO7F;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,IAAI,CAmBhG;AAED,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,EACvB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,GACT,MAAM,IAAI,CAeZ;AAED,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,SAAS,GAAG,IAAI,GACtB,OAAO,CAAC,YAAY,CAAC,CA4BvB"}
|
package/dist/queries.js
CHANGED
|
@@ -1,58 +1,69 @@
|
|
|
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 { hearerOf, 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';
|
|
15
16
|
const QUERY_BYTES = 1 << 20;
|
|
16
|
-
function everyRoom({
|
|
17
|
+
function everyRoom({ presence }, held) {
|
|
17
18
|
return [
|
|
18
19
|
...new Set([
|
|
19
|
-
...
|
|
20
|
+
...presence.rooms().map(({ locator }) => locator),
|
|
20
21
|
...held.rooms.keys(),
|
|
21
22
|
...held.queues.keys(),
|
|
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
|
-
function awaited({ socket }, locator) {
|
|
33
|
-
return (!socket.session.now().roomsListed ||
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
function awaited({ socket, presence }, locator) {
|
|
42
|
+
return (!socket.session.now().roomsListed || presence.room(locator)?.replica.admission === 'admitted');
|
|
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';
|
|
36
49
|
}
|
|
37
50
|
function coveredRooms(runtime, locators, whole, held) {
|
|
38
51
|
const { store, socket } = runtime;
|
|
39
|
-
if (
|
|
52
|
+
if (whole &&
|
|
53
|
+
!socket.session.now().roomsListed &&
|
|
54
|
+
(locators.length === 0 || !store.device.now().completedWhenOpened))
|
|
40
55
|
return { pending: [] };
|
|
41
56
|
const pending = [];
|
|
42
57
|
const coverage = [];
|
|
43
58
|
const overlay = [];
|
|
44
59
|
const read = [];
|
|
45
60
|
for (const locator of locators) {
|
|
61
|
+
const awaits = awaitsOf(runtime, locator, held);
|
|
62
|
+
if (awaits !== null)
|
|
63
|
+
pending.push({ room: locator, awaits });
|
|
46
64
|
const replica = held.rooms.get(locator);
|
|
47
|
-
if (replica === undefined)
|
|
48
|
-
if (awaited(runtime, locator))
|
|
49
|
-
pending.push({ room: locator, awaits: 'acquisition' });
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (!replica.indexed) {
|
|
53
|
-
pending.push({ room: locator, awaits: 'preparation' });
|
|
65
|
+
if (awaits !== null || replica === undefined)
|
|
54
66
|
continue;
|
|
55
|
-
}
|
|
56
67
|
coverage.push({
|
|
57
68
|
room: locator,
|
|
58
69
|
generation: replica.transfer,
|
|
@@ -66,8 +77,43 @@ function coveredRooms(runtime, locators, whole, held) {
|
|
|
66
77
|
return { pending };
|
|
67
78
|
return { coverage: { rooms: coverage, overlay }, rooms: read };
|
|
68
79
|
}
|
|
80
|
+
const UNFOLLOWED = { held: [], awaiting: [] };
|
|
81
|
+
function followsOf(runtime, plan, held) {
|
|
82
|
+
if (plan.hop === null)
|
|
83
|
+
return UNFOLLOWED;
|
|
84
|
+
const reached = plan.reach === null ? everyRoom(runtime, held) : roomsOfReach(plan.reach);
|
|
85
|
+
const reads = hearerOf(plan);
|
|
86
|
+
const follows = [];
|
|
87
|
+
const awaiting = [];
|
|
88
|
+
for (const locator of [...new Set(reached)].filter(reads).sort()) {
|
|
89
|
+
const replica = held.rooms.get(locator);
|
|
90
|
+
const awaits = awaitsOf(runtime, locator, held);
|
|
91
|
+
if (awaits === null) {
|
|
92
|
+
if (replica !== undefined)
|
|
93
|
+
follows.push({ locator, key: replica.key });
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const handle = replica?.handle ?? runtime.presence.room(locator)?.handle;
|
|
97
|
+
if (handle !== undefined)
|
|
98
|
+
awaiting.push({ room: locator, awaits, handle });
|
|
99
|
+
}
|
|
100
|
+
return { held: follows, awaiting };
|
|
101
|
+
}
|
|
69
102
|
function covered(runtime, plan, held) {
|
|
70
|
-
|
|
103
|
+
const cover = coveredRooms(runtime, reachedRooms(runtime, plan, held), anyRoom(plan), held);
|
|
104
|
+
return 'pending' in cover ? cover : { ...cover, follows: followsOf(runtime, plan, held) };
|
|
105
|
+
}
|
|
106
|
+
function pendingAt(runtime, plan, reads, held, rooms) {
|
|
107
|
+
const reached = reaching(runtime, plan, reads, held);
|
|
108
|
+
const at = new Map();
|
|
109
|
+
for (const room of rooms) {
|
|
110
|
+
const awaits = reached(room) ? awaitsOf(runtime, room, held) : null;
|
|
111
|
+
at.set(room, awaits === null ? null : { room, awaits });
|
|
112
|
+
}
|
|
113
|
+
awaitPreparation(runtime, {
|
|
114
|
+
pending: [...at.values()].filter((room) => room !== null),
|
|
115
|
+
});
|
|
116
|
+
return at;
|
|
71
117
|
}
|
|
72
118
|
function awaitPreparation(runtime, cover) {
|
|
73
119
|
if (!('pending' in cover))
|
|
@@ -89,8 +135,8 @@ export async function figuresCover(runtime) {
|
|
|
89
135
|
function sameCover(left, right) {
|
|
90
136
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
91
137
|
}
|
|
92
|
-
async function windowRows(local, plan, rooms, unchanged) {
|
|
93
|
-
const first = await local.query(plan, rooms, QUERY_BYTES);
|
|
138
|
+
async function windowRows(local, plan, rooms, follows, unchanged) {
|
|
139
|
+
const first = await local.query(plan, rooms, follows, QUERY_BYTES);
|
|
94
140
|
if (first.more === undefined || !('documents' in first)) {
|
|
95
141
|
const { more: _more, ...rows } = first;
|
|
96
142
|
return rows;
|
|
@@ -104,7 +150,7 @@ async function windowRows(local, plan, rooms, unchanged) {
|
|
|
104
150
|
after: { text: more, values: JSON.parse(more) },
|
|
105
151
|
limit: plan.limit === null ? null : plan.limit - documents.length,
|
|
106
152
|
total: false,
|
|
107
|
-
}, rooms, QUERY_BYTES);
|
|
153
|
+
}, rooms, follows, QUERY_BYTES);
|
|
108
154
|
if (!('documents' in page))
|
|
109
155
|
return null;
|
|
110
156
|
documents.push(...page.documents);
|
|
@@ -119,16 +165,48 @@ async function windowRows(local, plan, rooms, unchanged) {
|
|
|
119
165
|
}
|
|
120
166
|
return null;
|
|
121
167
|
}
|
|
122
|
-
|
|
168
|
+
function freeTextAsked(plan) {
|
|
169
|
+
return plan.shape.kind === 'documents' && (plan.shape.sections !== null || plan.shape.preamble);
|
|
170
|
+
}
|
|
171
|
+
async function composedRooms(runtime, plan, rooms) {
|
|
172
|
+
if (!freeTextAsked(plan))
|
|
173
|
+
return rooms;
|
|
174
|
+
const held = await runtime.store.rooms(rooms.map(({ locator }) => locator));
|
|
175
|
+
return rooms.map((room) => {
|
|
176
|
+
const stored = held.get(room.locator);
|
|
177
|
+
return stored === undefined
|
|
178
|
+
? room
|
|
179
|
+
: { ...room, composition: compositionFor(runtime, stored.record) };
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
async function awaitedFollows(runtime, local, plan, cover) {
|
|
183
|
+
const { awaiting } = cover.follows;
|
|
184
|
+
if (awaiting.length === 0)
|
|
185
|
+
return [];
|
|
186
|
+
const named = new Set(await local.named(plan, cover.rooms, awaiting.map(({ handle }) => handle)));
|
|
187
|
+
const pending = awaiting
|
|
188
|
+
.filter(({ handle }) => named.has(handle))
|
|
189
|
+
.map(({ room, awaits }) => ({ room, awaits }));
|
|
190
|
+
awaitPreparation(runtime, { pending });
|
|
191
|
+
return pending;
|
|
192
|
+
}
|
|
193
|
+
async function coveredRows(runtime, plan, cover) {
|
|
194
|
+
const { store } = runtime;
|
|
123
195
|
for (;;) {
|
|
124
196
|
const before = await cover();
|
|
125
197
|
if ('pending' in before)
|
|
126
|
-
return { pending: before };
|
|
198
|
+
return { pending: before, cover: before };
|
|
127
199
|
const local = await store.open();
|
|
128
|
-
const
|
|
200
|
+
const awaited = await awaitedFollows(runtime, local, plan, before);
|
|
201
|
+
if (awaited.length > 0) {
|
|
202
|
+
if (sameCover(before, await cover()))
|
|
203
|
+
return { pending: { pending: awaited }, cover: before };
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const keys = [...before.rooms, ...before.follows.held].map(({ key }) => key);
|
|
129
207
|
const changes = local.changes(keys);
|
|
130
208
|
const current = () => local.changes(keys) === changes;
|
|
131
|
-
const rows = await windowRows(local, plan, before.rooms, current);
|
|
209
|
+
const rows = await windowRows(local, plan, await composedRooms(runtime, plan, before.rooms), before.follows.held, current);
|
|
132
210
|
const after = await cover();
|
|
133
211
|
if (rows !== null && sameCover(before, after))
|
|
134
212
|
return { rows, cover: before, current };
|
|
@@ -149,11 +227,14 @@ function keyedOf(rows, coverage) {
|
|
|
149
227
|
export async function answeredPlan(runtime, plan, cover) {
|
|
150
228
|
const answered = await coveredRows(runtime, plan, cover);
|
|
151
229
|
if ('pending' in answered) {
|
|
152
|
-
|
|
153
|
-
return { result: pending, keys: [], current: () => true };
|
|
230
|
+
return { result: answered.pending, keys: [], current: () => true, cover: answered.cover };
|
|
154
231
|
}
|
|
155
232
|
const held = answered.cover;
|
|
156
|
-
return {
|
|
233
|
+
return {
|
|
234
|
+
...keyedOf(answered.rows, held.coverage),
|
|
235
|
+
current: answered.current,
|
|
236
|
+
cover: answered.cover,
|
|
237
|
+
};
|
|
157
238
|
}
|
|
158
239
|
async function coverNow(runtime, plan) {
|
|
159
240
|
const cover = covered(runtime, plan, await runtime.store.covering());
|
|
@@ -191,11 +272,14 @@ export async function roomTallies(runtime, rooms, since) {
|
|
|
191
272
|
});
|
|
192
273
|
}
|
|
193
274
|
export function watchPlan(runtime, plan, deliver, fail) {
|
|
275
|
+
const reads = readerOf(plan);
|
|
194
276
|
return watchSeeded(runtime, plan, deliver, (behind, answered) => runtime.liveQueries.watch(plan, identityOf(plan), (held) => {
|
|
195
277
|
const cover = covered(runtime, plan, held);
|
|
196
278
|
awaitPreparation(runtime, cover);
|
|
197
279
|
return behind(cover, held);
|
|
198
|
-
},
|
|
280
|
+
}, (held, rooms) => runtime.store.seeds.of(plan.key) === undefined
|
|
281
|
+
? pendingAt(runtime, plan, reads, held, rooms)
|
|
282
|
+
: null, answered, fail));
|
|
199
283
|
}
|
|
200
284
|
export function watchPlanned(runtime, planning, deliver, fail) {
|
|
201
285
|
let stop = null;
|
|
@@ -213,22 +297,13 @@ export function watchPlanned(runtime, planning, deliver, fail) {
|
|
|
213
297
|
};
|
|
214
298
|
}
|
|
215
299
|
export async function searched(runtime, input, reach) {
|
|
216
|
-
const { store, socket
|
|
217
|
-
const
|
|
300
|
+
const { store, socket } = runtime;
|
|
301
|
+
const search = socket.search();
|
|
302
|
+
if (search === undefined)
|
|
303
|
+
return undeclared('search');
|
|
218
304
|
const asked = searchPlanOf(input);
|
|
219
305
|
await socket.ready;
|
|
220
|
-
|
|
221
|
-
if (search === undefined) {
|
|
222
|
-
return {
|
|
223
|
-
kind: 'undeclared',
|
|
224
|
-
code: 'action-undeclared',
|
|
225
|
-
fields: { name: 'search' },
|
|
226
|
-
retryable: false,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
if (socket.closed() ||
|
|
230
|
-
session.now().refusal !== null ||
|
|
231
|
-
(await connectionNow(runtime)) !== 'connected')
|
|
306
|
+
if (await offline(runtime))
|
|
232
307
|
return OFFLINE;
|
|
233
308
|
const reached = reach === null ? null : new Set(reach.rooms);
|
|
234
309
|
const named = asked.rooms === null
|
|
@@ -240,33 +315,16 @@ export async function searched(runtime, input, reach) {
|
|
|
240
315
|
const rooms = named === null ? null : named.filter((room) => held.has(room)).sort();
|
|
241
316
|
if (rooms !== null && rooms.length === 0)
|
|
242
317
|
return { kind: 'found', documents: [] };
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
catch {
|
|
318
|
+
const result = await askedOnline(runtime, (authorization) => search(authorization, { text: asked.text, rooms }));
|
|
319
|
+
if (result === null)
|
|
247
320
|
return UNCERTAIN;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
return
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
journal.record(`outcome search ${result.kind}`);
|
|
258
|
-
if (result.kind === 'rejected')
|
|
259
|
-
return result;
|
|
260
|
-
if (result.kind !== 'found')
|
|
261
|
-
return failure(result);
|
|
262
|
-
const kept = rooms === null ? null : new Set(rooms);
|
|
263
|
-
return {
|
|
264
|
-
kind: 'found',
|
|
265
|
-
documents: result.documents.filter((hit) => kept === null || kept.has(hit.room)),
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
catch {
|
|
269
|
-
journal.record('outcome search transport-uncertainty');
|
|
270
|
-
return UNCERTAIN;
|
|
271
|
-
}
|
|
321
|
+
if (result.kind === 'rejected')
|
|
322
|
+
return result;
|
|
323
|
+
if (result.kind !== 'found')
|
|
324
|
+
return failure(result);
|
|
325
|
+
const kept = rooms === null ? null : new Set(rooms);
|
|
326
|
+
return {
|
|
327
|
+
kind: 'found',
|
|
328
|
+
documents: result.documents.filter((hit) => kept === null || kept.has(hit.room)),
|
|
329
|
+
};
|
|
272
330
|
}
|
package/dist/query.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HeldRooms, type QueryPlan } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { HeadChange } from './adapter.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AttachmentRecord } from './attachment.js';
|
|
4
4
|
import type { Open } from './open.js';
|
|
5
5
|
export type Backlink = {
|
|
6
6
|
path: string;
|
|
@@ -19,7 +19,7 @@ export type QueryDocument = {
|
|
|
19
19
|
change?: HeadChange | null;
|
|
20
20
|
fileId?: string | null;
|
|
21
21
|
revision?: string | null;
|
|
22
|
-
|
|
22
|
+
attachment?: AttachmentRecord;
|
|
23
23
|
size?: number | null;
|
|
24
24
|
created?: string | null;
|
|
25
25
|
};
|
package/dist/query.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,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AAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG;IAC7B,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,GAAE,SAAS,GAAG,IAAW,GAAG,IAAI,CAEjG"}
|
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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AAE,SAAS,GAAG,OAAO,CAEjD;AA4DD,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
|
@@ -54,8 +54,9 @@ function askedOf(request) {
|
|
|
54
54
|
const params = record(request.params);
|
|
55
55
|
const method = text(request, 'method');
|
|
56
56
|
if (method === 'session/request_permission') {
|
|
57
|
+
const air = record(record(record(params._meta).jetbrains).air);
|
|
57
58
|
return {
|
|
58
|
-
message: '',
|
|
59
|
+
message: text(record(air.permission), 'description') ?? '',
|
|
59
60
|
fields: [
|
|
60
61
|
{
|
|
61
62
|
name: OPTION,
|
|
@@ -97,6 +98,7 @@ export function questionsOf(view) {
|
|
|
97
98
|
interaction,
|
|
98
99
|
asked: text(one, 'asked_at'),
|
|
99
100
|
secret: one.secret === true,
|
|
101
|
+
page: one.secret === true ? text(one, 'page') : null,
|
|
100
102
|
undelivered: one.telegram_undelivered === true,
|
|
101
103
|
...asked,
|
|
102
104
|
},
|
|
@@ -113,10 +115,3 @@ export function openQuestion(questions) {
|
|
|
113
115
|
export function questionAsked(questions) {
|
|
114
116
|
return questionsOf({ questions })[0]?.asked ?? null;
|
|
115
117
|
}
|
|
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
|
-
}
|