@agentshouse/mdruntime 0.1.0-cb8a03985803b → 0.1.0-cb9a984171ffb
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 +14 -13
- package/dist/acceptance.js +1 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -6
- package/dist/adapter.d.ts +113 -21
- 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/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +347 -0
- package/dist/binary.d.ts +6 -2
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +10 -3
- 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 +17 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +24 -54
- 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 +2 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +72 -41
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +11 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +18 -9
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +17 -8
- 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 +16 -11
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +183 -139
- package/dist/declaration.js +1 -1
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +30 -5
- 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 +1 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +3 -0
- package/dist/entry.d.ts +14 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +45 -16
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -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 +68 -27
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +67 -0
- package/dist/index.d.ts +13 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/install.d.ts +8 -2
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +40 -33
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +38 -25
- 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 +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.map +1 -1
- package/dist/locks.js +4 -2
- package/dist/lost.js +1 -1
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +167 -33
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +60 -20
- package/dist/messages.d.ts +8 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +14 -3
- 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 +3 -3
- 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 +26 -10
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +200 -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 +18 -2
- package/dist/outcome.d.ts +21 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +18 -3
- package/dist/overlay.d.ts +4 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +3 -5
- package/dist/parts.d.ts +3 -1
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -7
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +195 -78
- 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 +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +114 -66
- package/dist/query.d.ts +2 -2
- package/dist/questions.d.ts +1 -0
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +51 -21
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +122 -23
- package/dist/react.d.ts +6 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +19 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +17 -10
- package/dist/reads.d.ts +1 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +2 -2
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +2 -1
- package/dist/reference-forms.d.ts +4 -0
- package/dist/reference-forms.d.ts.map +1 -0
- package/dist/reference-forms.js +74 -0
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +4 -4
- package/dist/room-draft.d.ts +28 -3
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +235 -14
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +11 -6
- 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 +11 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +24 -10
- 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 +4 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +17 -86
- package/dist/saves.d.ts +4 -2
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +75 -22
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/shown.d.ts +3 -1
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +72 -41
- 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 +1 -0
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +1 -0
- package/dist/source.d.ts +7 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +15 -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 +18 -3
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +57 -21
- 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 +14 -9
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +12 -5
- package/dist/stored.d.ts +38 -14
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +210 -52
- package/dist/surface.d.ts +13 -7
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +52 -17
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +49 -27
- package/dist/tables.d.ts +22 -49
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +70 -325
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +1 -2
- 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 +28 -13
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +17 -12
- package/package.json +3 -3
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 { hearerOf, readerOf, } from './live.js';
|
|
4
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,
|
|
@@ -64,8 +77,43 @@ function coveredRooms(runtime, locators, whole, held) {
|
|
|
64
77
|
return { pending };
|
|
65
78
|
return { coverage: { rooms: coverage, overlay }, rooms: read };
|
|
66
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
|
+
}
|
|
67
102
|
function covered(runtime, plan, held) {
|
|
68
|
-
|
|
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;
|
|
69
117
|
}
|
|
70
118
|
function awaitPreparation(runtime, cover) {
|
|
71
119
|
if (!('pending' in cover))
|
|
@@ -87,8 +135,8 @@ export async function figuresCover(runtime) {
|
|
|
87
135
|
function sameCover(left, right) {
|
|
88
136
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
89
137
|
}
|
|
90
|
-
async function windowRows(local, plan, rooms, unchanged) {
|
|
91
|
-
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);
|
|
92
140
|
if (first.more === undefined || !('documents' in first)) {
|
|
93
141
|
const { more: _more, ...rows } = first;
|
|
94
142
|
return rows;
|
|
@@ -102,7 +150,7 @@ async function windowRows(local, plan, rooms, unchanged) {
|
|
|
102
150
|
after: { text: more, values: JSON.parse(more) },
|
|
103
151
|
limit: plan.limit === null ? null : plan.limit - documents.length,
|
|
104
152
|
total: false,
|
|
105
|
-
}, rooms, QUERY_BYTES);
|
|
153
|
+
}, rooms, follows, QUERY_BYTES);
|
|
106
154
|
if (!('documents' in page))
|
|
107
155
|
return null;
|
|
108
156
|
documents.push(...page.documents);
|
|
@@ -131,17 +179,34 @@ async function composedRooms(runtime, plan, rooms) {
|
|
|
131
179
|
: { ...room, composition: compositionFor(runtime, stored.record) };
|
|
132
180
|
});
|
|
133
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
|
+
}
|
|
134
193
|
async function coveredRows(runtime, plan, cover) {
|
|
135
194
|
const { store } = runtime;
|
|
136
195
|
for (;;) {
|
|
137
196
|
const before = await cover();
|
|
138
197
|
if ('pending' in before)
|
|
139
|
-
return { pending: before };
|
|
198
|
+
return { pending: before, cover: before };
|
|
140
199
|
const local = await store.open();
|
|
141
|
-
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);
|
|
142
207
|
const changes = local.changes(keys);
|
|
143
208
|
const current = () => local.changes(keys) === changes;
|
|
144
|
-
const rows = await windowRows(local, plan, await composedRooms(runtime, plan, before.rooms), current);
|
|
209
|
+
const rows = await windowRows(local, plan, await composedRooms(runtime, plan, before.rooms), before.follows.held, current);
|
|
145
210
|
const after = await cover();
|
|
146
211
|
if (rows !== null && sameCover(before, after))
|
|
147
212
|
return { rows, cover: before, current };
|
|
@@ -162,11 +227,14 @@ function keyedOf(rows, coverage) {
|
|
|
162
227
|
export async function answeredPlan(runtime, plan, cover) {
|
|
163
228
|
const answered = await coveredRows(runtime, plan, cover);
|
|
164
229
|
if ('pending' in answered) {
|
|
165
|
-
|
|
166
|
-
return { result: pending, keys: [], current: () => true };
|
|
230
|
+
return { result: answered.pending, keys: [], current: () => true, cover: answered.cover };
|
|
167
231
|
}
|
|
168
232
|
const held = answered.cover;
|
|
169
|
-
return {
|
|
233
|
+
return {
|
|
234
|
+
...keyedOf(answered.rows, held.coverage),
|
|
235
|
+
current: answered.current,
|
|
236
|
+
cover: answered.cover,
|
|
237
|
+
};
|
|
170
238
|
}
|
|
171
239
|
async function coverNow(runtime, plan) {
|
|
172
240
|
const cover = covered(runtime, plan, await runtime.store.covering());
|
|
@@ -204,11 +272,14 @@ export async function roomTallies(runtime, rooms, since) {
|
|
|
204
272
|
});
|
|
205
273
|
}
|
|
206
274
|
export function watchPlan(runtime, plan, deliver, fail) {
|
|
275
|
+
const reads = readerOf(plan);
|
|
207
276
|
return watchSeeded(runtime, plan, deliver, (behind, answered) => runtime.liveQueries.watch(plan, identityOf(plan), (held) => {
|
|
208
277
|
const cover = covered(runtime, plan, held);
|
|
209
278
|
awaitPreparation(runtime, cover);
|
|
210
279
|
return behind(cover, held);
|
|
211
|
-
},
|
|
280
|
+
}, (held, rooms) => runtime.store.seeds.of(plan.key) === undefined
|
|
281
|
+
? pendingAt(runtime, plan, reads, held, rooms)
|
|
282
|
+
: null, answered, fail));
|
|
212
283
|
}
|
|
213
284
|
export function watchPlanned(runtime, planning, deliver, fail) {
|
|
214
285
|
let stop = null;
|
|
@@ -227,21 +298,12 @@ export function watchPlanned(runtime, planning, deliver, fail) {
|
|
|
227
298
|
}
|
|
228
299
|
export async function searched(runtime, input, reach) {
|
|
229
300
|
const { store, socket } = runtime;
|
|
230
|
-
const { session } = socket;
|
|
231
301
|
const asked = searchPlanOf(input);
|
|
232
302
|
await socket.ready;
|
|
233
303
|
const search = socket.search();
|
|
234
|
-
if (search === undefined)
|
|
235
|
-
return
|
|
236
|
-
|
|
237
|
-
code: 'action-undeclared',
|
|
238
|
-
fields: { name: 'search' },
|
|
239
|
-
retryable: false,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
if (socket.closed() ||
|
|
243
|
-
session.now().refusal !== null ||
|
|
244
|
-
(await connectionNow(runtime)) !== 'connected')
|
|
304
|
+
if (search === undefined)
|
|
305
|
+
return undeclared('search');
|
|
306
|
+
if (await offline(runtime))
|
|
245
307
|
return OFFLINE;
|
|
246
308
|
const reached = reach === null ? null : new Set(reach.rooms);
|
|
247
309
|
const named = asked.rooms === null
|
|
@@ -253,30 +315,16 @@ export async function searched(runtime, input, reach) {
|
|
|
253
315
|
const rooms = named === null ? null : named.filter((room) => held.has(room)).sort();
|
|
254
316
|
if (rooms !== null && rooms.length === 0)
|
|
255
317
|
return { kind: 'found', documents: [] };
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
return UNCERTAIN;
|
|
261
|
-
}
|
|
262
|
-
const { closed, authorization, refusal } = session.now();
|
|
263
|
-
if (closed || authorization === undefined || refusal !== null)
|
|
264
|
-
return UNCERTAIN;
|
|
265
|
-
try {
|
|
266
|
-
const result = await search(authorization, { text: asked.text, rooms });
|
|
267
|
-
if (result.kind === 'revoked-authorization')
|
|
268
|
-
await refuse(runtime, 'revoked-authorization');
|
|
269
|
-
if (result.kind === 'rejected')
|
|
270
|
-
return result;
|
|
271
|
-
if (result.kind !== 'found')
|
|
272
|
-
return failure(result);
|
|
273
|
-
const kept = rooms === null ? null : new Set(rooms);
|
|
274
|
-
return {
|
|
275
|
-
kind: 'found',
|
|
276
|
-
documents: result.documents.filter((hit) => kept === null || kept.has(hit.room)),
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
catch {
|
|
318
|
+
const result = await askedOnline(runtime, (authorization) => search(authorization, { text: asked.text, rooms }));
|
|
319
|
+
if (result === null)
|
|
280
320
|
return UNCERTAIN;
|
|
281
|
-
|
|
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
|
+
};
|
|
282
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 './binary.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/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;
|
package/dist/questions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file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AAgB,OAAO,CAAC,KAAK,EAAE,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
|
},
|
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;AAKhF,OAAO,EAUL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,KAAK,EAEX,MAAM,cAAc,CAAC;
|
|
1
|
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AAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CA+Cf;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvD;AAED,wBAAsB,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CA4DzF"}
|
package/dist/queue.js
CHANGED
|
@@ -5,7 +5,7 @@ import { declared } from './declaration.js';
|
|
|
5
5
|
import { runtimeError } from './failure.js';
|
|
6
6
|
import { roomDraftRevision } from './identity.js';
|
|
7
7
|
import { landed, movedBy, overlayOf, replaying, slicing, slicingWith, standing, storedRecord, touchedBy, } from './replica.js';
|
|
8
|
-
import { returnedBy, returnedInto } from './room-draft.js';
|
|
8
|
+
import { joinedOver, marksOver, returnedBy, returnedInto, } from './room-draft.js';
|
|
9
9
|
import { documentKey } from './rows.js';
|
|
10
10
|
import { stepped } from './turn.js';
|
|
11
11
|
export function withdrawable(states) {
|
|
@@ -38,7 +38,7 @@ async function landedWhole(store, record, batch, confirmedLayer, current) {
|
|
|
38
38
|
return false;
|
|
39
39
|
return landed(half, await sliceAt(store, other.record, 'confirmed', [half]), store.composed(other.record));
|
|
40
40
|
}
|
|
41
|
-
async function returnedDrafts(store, locator, work, leaving, composition) {
|
|
41
|
+
async function returnedDrafts(store, locator, work, leaving, composition, visible) {
|
|
42
42
|
const written = new Map();
|
|
43
43
|
for (const { batch, returned } of leaving) {
|
|
44
44
|
if (returned === null || batch.between?.destination.room === locator)
|
|
@@ -46,9 +46,18 @@ async function returnedDrafts(store, locator, work, leaving, composition) {
|
|
|
46
46
|
for (const saved of work.states.get(batch.id)?.drafts ?? []) {
|
|
47
47
|
const existing = written.get(saved.path) ?? (await store.draft(locator, saved.path));
|
|
48
48
|
const parts = returnedInto(existing?.parts, saved.parts, composition === undefined ? undefined : definitionsAt(composition, saved.path));
|
|
49
|
-
|
|
49
|
+
const record = parts === null
|
|
50
50
|
? { ...existing, returned }
|
|
51
|
-
: {
|
|
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() });
|
|
52
61
|
}
|
|
53
62
|
}
|
|
54
63
|
return written;
|
|
@@ -90,6 +99,7 @@ async function carriedBack(runtime, locator, unlanded, written) {
|
|
|
90
99
|
path,
|
|
91
100
|
revision: roomDraftRevision(),
|
|
92
101
|
parts,
|
|
102
|
+
marks: marksOver(existing?.marks ?? {}, record.marks),
|
|
93
103
|
returned: existing?.returned ?? null,
|
|
94
104
|
});
|
|
95
105
|
}
|
|
@@ -175,37 +185,47 @@ async function settlement(runtime, local, locator, work, record, queue, settling
|
|
|
175
185
|
...(before !== undefined && before.record.key === record.key ? before.overlaid : []),
|
|
176
186
|
...(overrides?.set.map(({ path }) => path) ?? []),
|
|
177
187
|
...(overrides?.removed ?? []),
|
|
188
|
+
...[...work.states.values()].flatMap(({ drafts }) => drafts.map(({ path }) => path)),
|
|
178
189
|
]);
|
|
179
190
|
const confirmedLayer = overrides === undefined
|
|
180
191
|
? read
|
|
181
192
|
: await stepped(slicingWith(read, overrides.set, overrides.removed));
|
|
182
193
|
const composition = store.composed(record);
|
|
183
194
|
const shown = queue.filter((batch) => {
|
|
184
|
-
const held = store.
|
|
195
|
+
const held = store.conflicted.of(locator, batch.id);
|
|
185
196
|
return (held !== undefined &&
|
|
186
|
-
Object.entries(held).some(([path, revision]) => confirmedLayer.revisions[path] !== revision));
|
|
197
|
+
Object.entries(held.revisions).some(([path, revision]) => confirmedLayer.revisions[path] !== revision));
|
|
187
198
|
});
|
|
188
199
|
const unshown = queue.filter((batch) => !shown.includes(batch));
|
|
189
200
|
const { withdrawn, kept } = await stepped(standing(confirmedLayer, unshown, withdrawable(work.states), localSaves, locator, composition));
|
|
190
201
|
const founded = kept.filter((batch) => !unshown.includes(batch));
|
|
191
202
|
const queueChanged = kept.length !== previousQueue.length || founded.length > 0;
|
|
192
|
-
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
|
+
});
|
|
193
210
|
for (const batch of withdrawn) {
|
|
194
|
-
|
|
211
|
+
const held = await landedWhole(store, record, batch, confirmedLayer);
|
|
212
|
+
unqueued.push({ batch, returned: held ? null : returnedBy() });
|
|
195
213
|
}
|
|
196
214
|
const returning = [
|
|
197
|
-
...[...unqueued].reverse().map(({ batch,
|
|
215
|
+
...[...unqueued].reverse().map(({ batch, returned }) => ({
|
|
198
216
|
batch,
|
|
199
|
-
returned: localSaves
|
|
217
|
+
returned: localSaves ? null : returned,
|
|
200
218
|
})),
|
|
201
219
|
...(settling.leaving ?? []),
|
|
202
220
|
];
|
|
203
|
-
const
|
|
221
|
+
const replayedLayer = await replayed(store, record, confirmedLayer, kept);
|
|
222
|
+
const written = await returnedDrafts(store, locator, work, returning, composition, replayedLayer.visible);
|
|
204
223
|
const carried = await carriedBack(runtime, locator, [
|
|
205
|
-
...[...unqueued]
|
|
224
|
+
...[...unqueued]
|
|
225
|
+
.reverse()
|
|
226
|
+
.flatMap(({ batch, returned }) => (returned === null ? [] : [batch])),
|
|
206
227
|
...(settling.leaving ?? []).flatMap(({ batch, returned }) => returned === null ? [] : [batch]),
|
|
207
228
|
], written);
|
|
208
|
-
const replayedLayer = await replayed(store, record, confirmedLayer, kept);
|
|
209
229
|
const { overlay } = await overlayDiff(record, before, replayedLayer.visible, replayedLayer.touched);
|
|
210
230
|
const commit = {
|
|
211
231
|
rooms: [
|
|
@@ -242,7 +262,7 @@ async function settlement(runtime, local, locator, work, record, queue, settling
|
|
|
242
262
|
apply: (answer) => {
|
|
243
263
|
for (const batch of previousQueue) {
|
|
244
264
|
if (!staying.has(batch.id))
|
|
245
|
-
store.
|
|
265
|
+
store.conflicted.drop(locator, batch.id);
|
|
246
266
|
}
|
|
247
267
|
const drafts = [...written.keys(), ...carried.taken];
|
|
248
268
|
const changed = answer.changed[locator];
|
|
@@ -278,7 +298,7 @@ async function unpairing(runtime, local, locator, batches) {
|
|
|
278
298
|
return settlement(runtime, local, locator, work, current.record, current.queue.filter((one) => !ids.has(one.id)), { leaving });
|
|
279
299
|
}
|
|
280
300
|
const queue = work.queue.filter((one) => !ids.has(one.id));
|
|
281
|
-
const written = await returnedDrafts(store, locator, work, leaving, unheldComposition(runtime, locator));
|
|
301
|
+
const written = await returnedDrafts(store, locator, work, leaving, unheldComposition(runtime, locator), undefined);
|
|
282
302
|
const carried = await carriedBack(runtime, locator, leaving.flatMap(({ batch, returned }) => (returned === null ? [] : [batch])), written);
|
|
283
303
|
return {
|
|
284
304
|
locator,
|
|
@@ -363,6 +383,12 @@ export function settle(runtime, locators, decide) {
|
|
|
363
383
|
await settled(runtime, local, settlements, decided.flatMap(({ after }) => (after === undefined ? [] : [after])));
|
|
364
384
|
});
|
|
365
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
|
+
}
|
|
366
392
|
export function answered(runtime, locator, head, answer) {
|
|
367
393
|
const { store, socket } = runtime;
|
|
368
394
|
return store.exclusive(async () => {
|
|
@@ -376,18 +402,22 @@ export function answered(runtime, locator, head, answer) {
|
|
|
376
402
|
const confirmedLayer = await sliceAt(store, current.record, 'confirmed', [head]);
|
|
377
403
|
const held = answer.kind === 'conflicted' &&
|
|
378
404
|
(await landedWhole(store, current.record, head, confirmedLayer, answer.affected));
|
|
379
|
-
if (held &&
|
|
380
|
-
partnerOf(head, locator) === null &&
|
|
381
|
-
!landed(head, confirmedLayer, store.composed(current.record))) {
|
|
382
|
-
store.landed.hold(locator, head.id, Object.fromEntries([...touchedBy([head])].map((path) => [path, confirmedLayer.revisions[path]])));
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
405
|
const returned = {
|
|
386
406
|
kind: answer.kind,
|
|
387
407
|
code: answer.code,
|
|
388
408
|
fields: answer.fields,
|
|
389
409
|
retryable: answer.retryable,
|
|
390
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
|
+
}
|
|
391
421
|
await settled(runtime, local, [
|
|
392
422
|
await settlement(runtime, local, locator, work, current.record, current.queue.filter((batch) => batch.id !== head.id), { leaving: [{ batch: head, returned: held ? null : returned }] }),
|
|
393
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,25 @@ export type RuntimeView = {
|
|
|
28
31
|
};
|
|
29
32
|
export type NarrowedView = RuntimeView & {
|
|
30
33
|
narrow(reach: PortReach | null): void;
|
|
34
|
+
code(code: CodeAvailability): void;
|
|
35
|
+
close(): void;
|
|
31
36
|
};
|
|
32
37
|
export type Reachable = RuntimeView & {
|
|
33
38
|
plan(input: unknown, reach: PortReach | null): Promise<Plan>;
|
|
34
39
|
query(plan: Plan): Promise<QueryResult>;
|
|
35
40
|
watchPlan(plan: Plan, deliver: Deliver, fail: Fail): () => void;
|
|
36
41
|
search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
|
37
|
-
|
|
42
|
+
queryHouse(input: unknown, reach: PortReach | null, options: unknown): Promise<HouseQueryResult>;
|
|
43
|
+
queried(): readonly QueriedRoom[];
|
|
44
|
+
watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: ReadinessMessage) => void): () => void;
|
|
38
45
|
locked(room: string): Promise<boolean>;
|
|
39
46
|
lockedRooms(): Promise<readonly string[]>;
|
|
40
47
|
watchLocks(notify: () => void): () => void;
|
|
41
48
|
located(room: string, path: string, destination: string): Promise<ReachedDocument | null>;
|
|
42
|
-
room(locator: string): Promise<
|
|
49
|
+
room(locator: string): Promise<ListedRoom | undefined>;
|
|
43
50
|
};
|
|
51
|
+
export declare function queriedOf(reach: PortReach | null, provided: readonly QueriedRoom[]): readonly QueriedRoom[];
|
|
52
|
+
export declare function queriedOnly(reach: PortReach | null, provided: readonly QueriedRoom[], room: string): boolean;
|
|
44
53
|
export declare function holds(reach: PortReach | null, room: string): boolean;
|
|
45
54
|
export declare function governs(reach: PortReach | null, room: {
|
|
46
55
|
readonly locator: string;
|
|
@@ -52,5 +61,5 @@ export declare function governs(reach: PortReach | null, room: {
|
|
|
52
61
|
readonly selection: boolean;
|
|
53
62
|
};
|
|
54
63
|
export declare function planReach(reach: PortReach | null): PlanReach | null;
|
|
55
|
-
export declare function narrowed(runtime: Reachable, given: PortReach | null,
|
|
64
|
+
export declare function narrowed(runtime: Reachable, given: PortReach | null, attached: ReadinessPort): NarrowedView;
|
|
56
65
|
//# 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":"AACA,OAAO,KAAK,
|
|
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,EAA4B,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEjF,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,Y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