@agentshouse/mdruntime 0.1.0-c1db74d14e5fa → 0.1.0-c1f45f238a4a6
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 +19 -16
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +309 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +251 -0
- package/dist/adapter.d.ts +166 -121
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +7 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +40 -41
- package/dist/binary.d.ts +0 -5
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +1 -1
- package/dist/bootstrap.d.ts +31 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +309 -109
- 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 +12 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +13 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +17 -88
- package/dist/change.d.ts +32 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +14 -3
- package/dist/chat-types.d.ts +5 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +13 -0
- package/dist/client.d.ts +38 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +105 -15
- package/dist/collection.d.ts +29 -21
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +48 -290
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +711 -0
- package/dist/connection.d.ts +7 -129
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +99 -3343
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/{chat/context.js → context.js} +1 -4
- package/dist/conversation-live.d.ts +135 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +247 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +53 -0
- package/dist/conversation.d.ts +54 -45
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +981 -691
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +177 -0
- package/dist/durability.d.ts +16 -4
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +5 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +33 -28
- package/dist/expectation.d.ts +4 -2
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +33 -11
- package/dist/failure.d.ts +1 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- 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 -10
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +116 -27
- package/dist/identity.d.ts +0 -2
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -6
- package/dist/index.d.ts +35 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/install.d.ts +55 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +543 -0
- package/dist/job.d.ts +5 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +7 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +271 -0
- package/dist/listing.d.ts +52 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +168 -0
- package/dist/live.d.ts +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +165 -0
- package/dist/locks.d.ts +9 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +62 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +61 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +22 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +253 -105
- package/dist/messages.d.ts +49 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +148 -0
- package/dist/model.d.ts +11 -13
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -24
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +170 -0
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +17 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +107 -17
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +59 -0
- package/dist/outcome.d.ts +49 -8
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +42 -0
- package/dist/overlay.d.ts +5 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +127 -166
- package/dist/parts.d.ts +11 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +21 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +26 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +233 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +272 -0
- package/dist/query.d.ts +27 -186
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -464
- package/dist/{chat/questions.d.ts → questions.d.ts} +5 -2
- package/dist/questions.d.ts.map +1 -0
- package/dist/{chat/questions.js → questions.js} +13 -2
- package/dist/queue.d.ts +32 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +402 -0
- package/dist/reach.d.ts +19 -9
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +291 -102
- package/dist/react.d.ts +16 -4
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +17 -18
- package/dist/{chat/read.d.ts → read.d.ts} +2 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/{chat/read.js → read.js} +4 -0
- package/dist/readiness.d.ts +13 -17
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +2 -8
- package/dist/reads.d.ts +37 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +174 -0
- package/dist/recovery.d.ts +3 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +43 -8
- package/dist/refresh.d.ts +17 -14
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +145 -54
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +57 -0
- package/dist/replica.d.ts +50 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +338 -189
- package/dist/room-draft.d.ts +39 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +186 -86
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/rows.d.ts +31 -29
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +60 -118
- package/dist/runtime.d.ts +32 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +54 -16
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +557 -209
- package/dist/saves.d.ts +32 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +679 -0
- package/dist/search.d.ts +15 -77
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -184
- package/dist/seed.d.ts +25 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +145 -0
- package/dist/shared.d.ts +6 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +75 -104
- package/dist/shown.d.ts +32 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +299 -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 +20 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +77 -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/rooms.d.ts +41 -0
- package/dist/socket/rooms.d.ts.map +1 -0
- package/dist/socket/rooms.js +90 -0
- package/dist/socket/session.d.ts +38 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +69 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +175 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +82 -0
- package/dist/status.d.ts +4 -5
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -7
- package/dist/store/fences.d.ts +16 -0
- package/dist/store/fences.d.ts.map +1 -0
- package/dist/store/fences.js +26 -0
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -0
- package/dist/store/records.d.ts +210 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +428 -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/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 +106 -148
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +136 -700
- package/dist/stored.d.ts +156 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +649 -0
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +224 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +530 -0
- package/dist/tables.d.ts +412 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +737 -0
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +5 -3
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +51 -21
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +104 -0
- package/dist/windows.d.ts +11 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +16 -0
- package/dist/wire.d.ts +183 -37
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +63 -34
- package/package.json +19 -19
- package/AGENTS.md +0 -300
- package/dist/acquisition.d.ts +0 -14
- package/dist/acquisition.d.ts.map +0 -1
- package/dist/acquisition.js +0 -24
- package/dist/chat/acts.d.ts +0 -33
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/context.d.ts +0 -3
- package/dist/chat/context.d.ts.map +0 -1
- package/dist/chat/input.d.ts +0 -9
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -99
- package/dist/chat/kit.d.ts +0 -60
- package/dist/chat/kit.d.ts.map +0 -1
- package/dist/chat/kit.js +0 -123
- package/dist/chat/lasting.d.ts +0 -6
- package/dist/chat/lasting.d.ts.map +0 -1
- package/dist/chat/lasting.js +0 -19
- package/dist/chat/list.d.ts +0 -26
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -62
- package/dist/chat/markdown.d.ts +0 -20
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -188
- package/dist/chat/message.d.ts +0 -6
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -192
- package/dist/chat/messages.d.ts +0 -21
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -151
- package/dist/chat/name.d.ts +0 -6
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -11
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -17
- package/dist/chat/overlay.d.ts +0 -31
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -97
- package/dist/chat/parts.d.ts +0 -57
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -119
- package/dist/chat/process.d.ts +0 -20
- package/dist/chat/process.d.ts.map +0 -1
- package/dist/chat/process.js +0 -32
- package/dist/chat/provider.d.ts +0 -63
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -620
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -80
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/ready.d.ts +0 -33
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -91
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -302
- package/dist/chat.d.ts +0 -14
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/read-side.d.ts +0 -25
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -639
package/dist/client.js
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
+
import { shownBy } from './media.js';
|
|
1
2
|
import { observed } from './observation.js';
|
|
2
3
|
import { runtimeError } from './failure.js';
|
|
3
|
-
import {
|
|
4
|
+
import { AUTHORIZATION_ENDED, PORT_CLOSED, wireAnswer, } from './wire.js';
|
|
5
|
+
// React renders an arrived value in a later task and opens what that render observes as it commits, so this many frames opening nothing mean the page drew what it observes.
|
|
6
|
+
const SETTLED_FRAMES = 2;
|
|
7
|
+
// A browser reads a download's address only after the click that hands it returns, so a copy's address is released a minute later.
|
|
8
|
+
const HANDED_COPY_MS = 60_000;
|
|
9
|
+
const PAGE = /\.html?$/iu;
|
|
10
|
+
const STARTED = { kind: 'started' };
|
|
11
|
+
const BLOCKED = {
|
|
12
|
+
kind: 'blocked',
|
|
13
|
+
code: 'popup-blocked',
|
|
14
|
+
fields: {},
|
|
15
|
+
retryable: true,
|
|
16
|
+
};
|
|
17
|
+
function handed(url, name) {
|
|
18
|
+
const anchor = document.createElement('a');
|
|
19
|
+
anchor.href = url;
|
|
20
|
+
anchor.download = name;
|
|
21
|
+
anchor.click();
|
|
22
|
+
}
|
|
4
23
|
function refused(refusal) {
|
|
5
|
-
return runtimeError(refusal.code
|
|
24
|
+
return runtimeError(refusal.code);
|
|
6
25
|
}
|
|
7
|
-
|
|
26
|
+
const UNBUILT = () => Promise.resolve(null);
|
|
27
|
+
export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
8
28
|
let sequence = 0;
|
|
9
29
|
let refusal = null;
|
|
10
30
|
let ended = null;
|
|
@@ -60,7 +80,7 @@ export function connectMdRuntime(port) {
|
|
|
60
80
|
drawing?.();
|
|
61
81
|
}
|
|
62
82
|
port.addEventListener('message', (event) => {
|
|
63
|
-
const message =
|
|
83
|
+
const message = wireAnswer(event.data);
|
|
64
84
|
if (message === null)
|
|
65
85
|
return;
|
|
66
86
|
if (message.kind === 'refusal') {
|
|
@@ -131,6 +151,57 @@ export function connectMdRuntime(port) {
|
|
|
131
151
|
drawing?.();
|
|
132
152
|
});
|
|
133
153
|
}
|
|
154
|
+
function streamed(answer) {
|
|
155
|
+
if (answer.kind !== 'binary')
|
|
156
|
+
return answer;
|
|
157
|
+
const { file, byteLength, mediaType } = answer;
|
|
158
|
+
let part = 0;
|
|
159
|
+
let received = 0;
|
|
160
|
+
const stream = new ReadableStream({
|
|
161
|
+
async pull(controller) {
|
|
162
|
+
const bytes = await ask('binaryFile.part', [file, part]);
|
|
163
|
+
if (bytes === null) {
|
|
164
|
+
if (received === byteLength)
|
|
165
|
+
controller.close();
|
|
166
|
+
else
|
|
167
|
+
controller.error(runtimeError('binary-file-absent', 'The file ended early'));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
part += 1;
|
|
171
|
+
received += bytes.byteLength;
|
|
172
|
+
controller.enqueue(bytes);
|
|
173
|
+
},
|
|
174
|
+
}, { highWaterMark: 0 });
|
|
175
|
+
return { kind: 'binary', stream, byteLength, mediaType };
|
|
176
|
+
}
|
|
177
|
+
async function download(room, path, revision) {
|
|
178
|
+
const tab = PAGE.test(path) ? globalThis.open('', '_blank') : null;
|
|
179
|
+
const linked = await ask('binaryFile.link', [room, path, revision]);
|
|
180
|
+
if (linked.kind === 'link' && PAGE.test(linked.name)) {
|
|
181
|
+
const away = tab ?? globalThis.open('', '_blank');
|
|
182
|
+
if (away === null)
|
|
183
|
+
return BLOCKED;
|
|
184
|
+
away.location.replace(linked.url);
|
|
185
|
+
return STARTED;
|
|
186
|
+
}
|
|
187
|
+
tab?.close();
|
|
188
|
+
if (linked.kind === 'link') {
|
|
189
|
+
handed(linked.url, linked.name);
|
|
190
|
+
return STARTED;
|
|
191
|
+
}
|
|
192
|
+
if (linked.kind !== 'absent')
|
|
193
|
+
return linked;
|
|
194
|
+
const read = streamed(await ask('binaryFile.read', [room, path, revision]));
|
|
195
|
+
if (read.kind !== 'binary')
|
|
196
|
+
return read;
|
|
197
|
+
const copy = await new Response(read.stream, {
|
|
198
|
+
headers: { 'content-type': read.mediaType },
|
|
199
|
+
}).blob();
|
|
200
|
+
const url = URL.createObjectURL(copy);
|
|
201
|
+
handed(url, path.slice(path.lastIndexOf('/') + 1));
|
|
202
|
+
setTimeout(() => URL.revokeObjectURL(url), HANDED_COPY_MS);
|
|
203
|
+
return STARTED;
|
|
204
|
+
}
|
|
134
205
|
function settled() {
|
|
135
206
|
if (settling !== null)
|
|
136
207
|
return settling;
|
|
@@ -141,21 +212,28 @@ export function connectMdRuntime(port) {
|
|
|
141
212
|
if (opening.size > 0)
|
|
142
213
|
return;
|
|
143
214
|
const at = moved;
|
|
144
|
-
|
|
215
|
+
const waited = (frames) => {
|
|
145
216
|
requestAnimationFrame(() => {
|
|
217
|
+
if (frames < SETTLED_FRAMES) {
|
|
218
|
+
waited(frames + 1);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
146
221
|
if (moved !== at || opening.size > 0)
|
|
147
222
|
return;
|
|
148
223
|
drawing = null;
|
|
149
224
|
resolve();
|
|
150
225
|
});
|
|
151
|
-
}
|
|
226
|
+
};
|
|
227
|
+
waited(1);
|
|
152
228
|
};
|
|
153
229
|
drawing = check;
|
|
154
230
|
check();
|
|
155
231
|
});
|
|
156
232
|
return settling;
|
|
157
233
|
}
|
|
158
|
-
|
|
234
|
+
const show = (room, path, revision) => ask('binaryFile.show', [room, path, revision]).then((shown) => streamed(shown));
|
|
235
|
+
return shownBy(show, {
|
|
236
|
+
buildFile,
|
|
159
237
|
rooms: () => ask('rooms', []),
|
|
160
238
|
query: ((query) => ask('query', [query])),
|
|
161
239
|
search: (request) => ask('search', [request]),
|
|
@@ -163,13 +241,15 @@ export function connectMdRuntime(port) {
|
|
|
163
241
|
roomDraft: {
|
|
164
242
|
list: () => ask('roomDraft.list', []),
|
|
165
243
|
read: (room, path) => ask('roomDraft.read', [room, path]),
|
|
166
|
-
write: (room, path, revision, parts) => ask('roomDraft.write', [room, path, revision, parts]),
|
|
244
|
+
write: (room, path, revision, parts, next) => ask('roomDraft.write', next === undefined ? [room, path, revision, parts] : [room, path, revision, parts, next]),
|
|
167
245
|
discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
|
|
168
246
|
},
|
|
169
247
|
save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
|
|
248
|
+
saveParts: (room, parts) => ask('saveParts', [room, parts]),
|
|
170
249
|
presentation: {
|
|
171
250
|
read: () => ask('presentation.read', []),
|
|
172
251
|
write: (value) => ask('presentation.write', [value]),
|
|
252
|
+
edit: (members) => ask('presentation.edit', [members]),
|
|
173
253
|
},
|
|
174
254
|
conversation: {
|
|
175
255
|
list: () => ask('conversation.list', []),
|
|
@@ -179,31 +259,41 @@ export function connectMdRuntime(port) {
|
|
|
179
259
|
answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
|
|
180
260
|
interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
|
|
181
261
|
kill: (conversation) => ask('conversation.kill', [conversation]),
|
|
182
|
-
cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
|
|
183
262
|
delete: (conversation) => ask('conversation.delete', [conversation]),
|
|
184
263
|
},
|
|
185
264
|
chatDraft: {
|
|
186
265
|
write: (conversation, draft, revision) => ask('chatDraft.write', [conversation, draft, revision]),
|
|
266
|
+
prepend: (conversation, draft) => ask('chatDraft.prepend', [conversation, draft]),
|
|
187
267
|
discard: (conversation) => ask('chatDraft.discard', [conversation]),
|
|
188
268
|
},
|
|
189
269
|
history: (locator, path, query) => ask('history', [locator, path, query]),
|
|
270
|
+
resolve: (room, path, destination) => ask('resolve', [room, path, destination]),
|
|
190
271
|
binaryFile: {
|
|
191
|
-
read: (room, path, revision) => ask('binaryFile.read', [room, path, revision]),
|
|
192
|
-
|
|
272
|
+
read: (room, path, revision) => ask('binaryFile.read', [room, path, revision]).then((read) => streamed(read)),
|
|
273
|
+
attach: (room, file) => ask('binaryFile.attach', [room, file]),
|
|
274
|
+
download,
|
|
193
275
|
},
|
|
194
276
|
call: (name, input) => ask('call', [name, input]),
|
|
195
277
|
reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
|
|
196
278
|
log: () => ask('log', []),
|
|
197
279
|
persistence: () => ask('persistence', []),
|
|
198
280
|
retry: () => ask('retry', []),
|
|
281
|
+
cleanUp: () => ask('cleanUp', []),
|
|
282
|
+
unsent: () => ask('unsent', []),
|
|
283
|
+
reset: () => ask('reset', []),
|
|
284
|
+
readAgain: () => ask('readAgain', []),
|
|
199
285
|
observe: ((topic, ...input) => watch(topic, input)),
|
|
200
286
|
reauthorize: () => ask('reauthorize', []),
|
|
201
287
|
settled,
|
|
202
|
-
};
|
|
288
|
+
});
|
|
203
289
|
}
|
|
204
290
|
const turns = new WeakMap();
|
|
205
291
|
export function inTurn(client, work) {
|
|
206
|
-
const
|
|
207
|
-
turns.set(client,
|
|
208
|
-
return
|
|
292
|
+
const turn = (turns.get(client) ?? Promise.resolve()).then(work);
|
|
293
|
+
turns.set(client, turn.then(() => undefined, () => undefined));
|
|
294
|
+
return turn;
|
|
209
295
|
}
|
|
296
|
+
export { chainedWindows } from './chain.js';
|
|
297
|
+
export { roomDraftRevision } from './identity.js';
|
|
298
|
+
export { defineRoomMedia, ROOM_MEDIA } from './media.js';
|
|
299
|
+
export { unanswered } from './wire.js';
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
1
|
+
import { type DefinitionOf, type Document, type TypedPath } from '@agentshouse/mdmodel';
|
|
2
|
+
import type { ModelState, TypesResult } from './model.js';
|
|
3
|
+
import type { AppTypedSelection } from './listing.js';
|
|
3
4
|
import type { MdModelIdentity } from './adapter.js';
|
|
4
|
-
import { type Paths } from './shared.js';
|
|
5
|
-
import type { Refused } from './transfer.js';
|
|
6
|
-
import { type Later } from './turn.js';
|
|
7
5
|
export declare const MD_MODEL: MdModelIdentity;
|
|
8
6
|
export type Collection = {
|
|
9
7
|
text: Readonly<Record<string, string>>;
|
|
@@ -16,24 +14,34 @@ export type Composition = {
|
|
|
16
14
|
roots: readonly string[];
|
|
17
15
|
model: ModelState;
|
|
18
16
|
} | null;
|
|
17
|
+
typedPaths: readonly TypedPath[];
|
|
19
18
|
};
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export declare function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
export type Composed = {
|
|
20
|
+
readonly composition: Composition;
|
|
21
|
+
readonly fingerprint: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function composedOf(composition: Composition): Composed;
|
|
24
|
+
type Selecting<M> = {
|
|
25
|
+
readonly model: M;
|
|
26
|
+
readonly selection: {
|
|
27
|
+
readonly roots: readonly string[];
|
|
28
|
+
readonly model: M;
|
|
29
|
+
} | null;
|
|
30
30
|
};
|
|
31
|
-
export declare function
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
export declare function selected(composition: {
|
|
32
|
+
readonly selection: {
|
|
33
|
+
readonly roots: readonly string[];
|
|
34
|
+
} | null;
|
|
35
|
+
}, path: string): boolean;
|
|
36
|
+
export declare function governing<M>(composition: Selecting<M>, path: string): M;
|
|
37
|
+
export declare function definitionsAt(composition: Composition, path: string): DefinitionOf;
|
|
38
|
+
export declare function definitionsIn(room: {
|
|
39
|
+
readonly model: TypesResult;
|
|
40
|
+
readonly typedSelection: AppTypedSelection | null;
|
|
41
|
+
}, path: string, typedPaths: readonly TypedPath[]): DefinitionOf;
|
|
42
|
+
export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition): Collection;
|
|
43
|
+
export declare function documentsOf(collection: Collection): Generator<number, Iterable<readonly [string, Document]>, void>;
|
|
44
|
+
export declare function validRoot(root: unknown): root is string;
|
|
34
45
|
export declare function available(composition: Composition): boolean;
|
|
35
|
-
export declare function changedCleanly(next: Held, previous: Held & {
|
|
36
|
-
composition: Composition;
|
|
37
|
-
}, composition: Composition): boolean;
|
|
38
46
|
export {};
|
|
39
47
|
//# sourceMappingURL=collection.d.ts.map
|
package/dist/collection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,SAAS,EAEf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAEhG,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvC,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE;QAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI,CAAC;IAClE,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAc3F,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,GAAG,QAAQ,CAS7D;AAED,KAAK,SAAS,CAAC,CAAC,IAAI;IAClB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,QAAQ,CAAC,SAAS,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;KAAE,GAAG,IAAI,CAAC;CACrF,CAAC;AAEF,wBAAgB,QAAQ,CACtB,WAAW,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,EACjF,IAAI,EAAE,MAAM,GACX,OAAO,CAKT;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAIvE;AAYD,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAIlF;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,cAAc,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAAE,EACxF,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,YAAY,CAQd;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,GACvB,UAAU,CAcZ;AAED,wBAAiB,WAAW,CAC1B,UAAU,EAAE,UAAU,GACrB,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAQhE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEvD;AAED,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAE3D"}
|
package/dist/collection.js
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { definitionAt, parse, VERSION, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { beneath, normalize } from './paths.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { inUnits, ROW_WEIGHT } from './turn.js';
|
|
3
|
+
import { hashed } from './observation.js';
|
|
4
|
+
import { sortedKeys } from './shared.js';
|
|
6
5
|
export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
|
|
7
|
-
const
|
|
8
|
-
function
|
|
6
|
+
const typesPrinted = new WeakMap();
|
|
7
|
+
function typesPrint(model) {
|
|
8
|
+
if (model.status === 'unavailable')
|
|
9
|
+
return '';
|
|
10
|
+
let print = typesPrinted.get(model.types);
|
|
11
|
+
if (print === undefined) {
|
|
12
|
+
print = hashed(JSON.stringify(model.types)).toString(36);
|
|
13
|
+
typesPrinted.set(model.types, print);
|
|
14
|
+
}
|
|
15
|
+
return print;
|
|
16
|
+
}
|
|
17
|
+
export function composedOf(composition) {
|
|
18
|
+
const { model, selection } = composition;
|
|
19
|
+
return {
|
|
20
|
+
composition,
|
|
21
|
+
fingerprint: JSON.stringify([
|
|
22
|
+
typesPrint(model),
|
|
23
|
+
selection === null ? null : [selection.roots, typesPrint(selection.model)],
|
|
24
|
+
]),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function selected(composition, path) {
|
|
9
28
|
return (composition.selection !== null &&
|
|
10
29
|
composition.selection.roots.some((root) => beneath(root, path)));
|
|
11
30
|
}
|
|
@@ -14,307 +33,46 @@ export function governing(composition, path) {
|
|
|
14
33
|
? composition.selection.model
|
|
15
34
|
: composition.model;
|
|
16
35
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (held === undefined)
|
|
21
|
-
return shared({});
|
|
22
|
-
const kept = patched(held.base, held.added);
|
|
23
|
-
held.base = kept;
|
|
24
|
-
held.added = new Map();
|
|
25
|
-
return patched(kept, [], differing(previous.text, text));
|
|
36
|
+
function definitionsUnder(composition, path, typedPaths, typesOf) {
|
|
37
|
+
const types = typesOf(governing(composition, path));
|
|
38
|
+
return types === null ? () => undefined : definitionAt({ types }, path, typedPaths);
|
|
26
39
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
if (held === undefined)
|
|
30
|
-
return undefined;
|
|
31
|
-
if (held.added.has(path))
|
|
32
|
-
return held.added.get(path);
|
|
33
|
-
return Object.hasOwn(held.base, path) ? held.base[path] : undefined;
|
|
40
|
+
export function definitionsAt(composition, path) {
|
|
41
|
+
return definitionsUnder(composition, path, composition.typedPaths, (model) => model.status === 'unavailable' ? null : model.types);
|
|
34
42
|
}
|
|
35
|
-
export function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
export function definitionsIn(room, path, typedPaths) {
|
|
44
|
+
return definitionsUnder({ model: room.model, selection: room.typedSelection }, path, typedPaths, ({ types }) => types === null ? null : Object.fromEntries(types.map((type) => [type.name, type])));
|
|
45
|
+
}
|
|
46
|
+
export function collectionOf(text, composition) {
|
|
47
|
+
const parsed = new Map();
|
|
48
|
+
return {
|
|
41
49
|
text,
|
|
42
50
|
composition,
|
|
43
51
|
document(path) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return held ?? undefined;
|
|
52
|
+
if (parsed.has(path))
|
|
53
|
+
return parsed.get(path) ?? undefined;
|
|
47
54
|
const content = text[path];
|
|
48
55
|
if (content === undefined)
|
|
49
56
|
return undefined;
|
|
50
|
-
const read = parse(content, path);
|
|
51
|
-
parsed.
|
|
57
|
+
const read = parse(content, path, definitionsAt(composition, path));
|
|
58
|
+
parsed.set(path, read.ok ? read.document : null);
|
|
52
59
|
return read.ok ? read.document : undefined;
|
|
53
60
|
},
|
|
54
61
|
};
|
|
55
|
-
parsedIn.set(collection, parsed);
|
|
56
|
-
return collection;
|
|
57
|
-
}
|
|
58
|
-
export function passingFrontmatter(collection, path) {
|
|
59
|
-
const held = cachedIn(collection, path);
|
|
60
|
-
if (held !== undefined)
|
|
61
|
-
return held ?? undefined;
|
|
62
|
-
const content = collection.text[path];
|
|
63
|
-
if (content === undefined)
|
|
64
|
-
return undefined;
|
|
65
|
-
const read = parseFrontmatter(content, path);
|
|
66
|
-
return read.ok ? read.frontmatter : undefined;
|
|
67
62
|
}
|
|
68
63
|
export function* documentsOf(collection) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
continue;
|
|
64
|
+
const paths = yield* sortedKeys(collection.text);
|
|
65
|
+
return (function* () {
|
|
66
|
+
for (const path of paths) {
|
|
67
|
+
const document = collection.document(path);
|
|
68
|
+
if (document !== undefined)
|
|
69
|
+
yield [path, document];
|
|
76
70
|
}
|
|
77
|
-
|
|
78
|
-
if (read.ok)
|
|
79
|
-
yield [path, read.document];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export function unreadable(text, previous) {
|
|
83
|
-
const paths = previous === undefined
|
|
84
|
-
? Object.keys(text)
|
|
85
|
-
: [...differing(previous, text)].filter((path) => text[path] !== undefined);
|
|
86
|
-
for (const path of paths.sort()) {
|
|
87
|
-
const read = parse(text[path], path);
|
|
88
|
-
if (!read.ok)
|
|
89
|
-
return { kind: 'refused', refusal: read.refusal };
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
71
|
+
})();
|
|
92
72
|
}
|
|
93
73
|
export function validRoot(root) {
|
|
94
74
|
return typeof root === 'string' && normalize(root) === root;
|
|
95
75
|
}
|
|
96
|
-
function validateAgainst(documents, binaryTargets, model) {
|
|
97
|
-
if (model.status === 'unavailable') {
|
|
98
|
-
const typed = Object.entries(documents).find(([, content]) => {
|
|
99
|
-
const parsed = parse(content);
|
|
100
|
-
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
101
|
-
});
|
|
102
|
-
if (typed !== undefined)
|
|
103
|
-
return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
|
|
104
|
-
}
|
|
105
|
-
return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
|
|
106
|
-
}
|
|
107
|
-
export function validateCollection(text, binaryTargets, composition) {
|
|
108
|
-
const collection = {};
|
|
109
|
-
const selection = {};
|
|
110
|
-
for (const [path, content] of Object.entries(text)) {
|
|
111
|
-
if (selected(composition, path))
|
|
112
|
-
selection[path] = content;
|
|
113
|
-
else
|
|
114
|
-
collection[path] = content;
|
|
115
|
-
}
|
|
116
|
-
const verdicts = [
|
|
117
|
-
validateAgainst(collection, binaryTargets.filter((path) => !selected(composition, path)), composition.model),
|
|
118
|
-
];
|
|
119
|
-
if (composition.selection !== null) {
|
|
120
|
-
verdicts.push(validateAgainst(selection, binaryTargets.filter((path) => selected(composition, path)), composition.selection.model));
|
|
121
|
-
}
|
|
122
|
-
const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
|
|
123
|
-
if (refusals.length === 0)
|
|
124
|
-
return verdicts[0];
|
|
125
|
-
return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
|
|
126
|
-
}
|
|
127
|
-
const referrersOf = new WeakMap();
|
|
128
|
-
function typing(left, right) {
|
|
129
|
-
return (sameTyping(left.model, right.model) &&
|
|
130
|
-
(left.selection === null || right.selection === null
|
|
131
|
-
? left.selection === right.selection
|
|
132
|
-
: sameTyping(left.selection.model, right.selection.model)) &&
|
|
133
|
-
JSON.stringify(left.selection?.roots ?? null) === JSON.stringify(right.selection?.roots ?? null));
|
|
134
|
-
}
|
|
135
|
-
function declared(content) {
|
|
136
|
-
if (content === undefined)
|
|
137
|
-
return undefined;
|
|
138
|
-
const read = parseFrontmatter(content);
|
|
139
|
-
return read.ok ? (read.frontmatter.type ?? 'any') : undefined;
|
|
140
|
-
}
|
|
141
|
-
function typedIn(content) {
|
|
142
|
-
const type = declared(content);
|
|
143
|
-
return type !== undefined && type !== 'any';
|
|
144
|
-
}
|
|
145
|
-
function modelOf(composition, path) {
|
|
146
|
-
const model = governing(composition, path);
|
|
147
|
-
return model.status === 'unavailable' ? null : { types: model.types };
|
|
148
|
-
}
|
|
149
|
-
function checked(path, content, composition) {
|
|
150
|
-
return checkDocument(path, content, modelOf(composition, path) ?? NO_TYPES);
|
|
151
|
-
}
|
|
152
|
-
function targetsOf(check) {
|
|
153
|
-
if (!check.ok)
|
|
154
|
-
return [];
|
|
155
|
-
return [...new Set(check.references.flatMap(({ target }) => (target === null ? [] : [target])))];
|
|
156
|
-
}
|
|
157
|
-
function referencedBy(path, content, composition) {
|
|
158
|
-
const model = modelOf(composition, path);
|
|
159
|
-
if (model === null)
|
|
160
|
-
return [];
|
|
161
|
-
const read = parseFrontmatter(content, path);
|
|
162
|
-
const type = read.ok ? read.frontmatter.type : undefined;
|
|
163
|
-
if (!read.ok || type === undefined || !Object.hasOwn(model.types, type))
|
|
164
|
-
return [];
|
|
165
|
-
const definition = model.types[type];
|
|
166
|
-
return [
|
|
167
|
-
...new Set([
|
|
168
|
-
...references(read.frontmatter, definition).flatMap(({ value }) => {
|
|
169
|
-
const found = target(path, value);
|
|
170
|
-
return found === null ? [] : [found];
|
|
171
|
-
}),
|
|
172
|
-
...sectionReferences(path, content, definition).flatMap(({ target }) => target === null ? [] : [target]),
|
|
173
|
-
]),
|
|
174
|
-
];
|
|
175
|
-
}
|
|
176
|
-
function reindexed(index, changed) {
|
|
177
|
-
const referrers = new Map();
|
|
178
|
-
const touch = (target) => {
|
|
179
|
-
let held = referrers.get(target);
|
|
180
|
-
if (held === undefined) {
|
|
181
|
-
held = new Set(Object.hasOwn(index.referrers, target) ? index.referrers[target] : []);
|
|
182
|
-
referrers.set(target, held);
|
|
183
|
-
}
|
|
184
|
-
return held;
|
|
185
|
-
};
|
|
186
|
-
for (const [path, found] of changed) {
|
|
187
|
-
const before = Object.hasOwn(index.targets, path) ? index.targets[path] : [];
|
|
188
|
-
for (const target of before)
|
|
189
|
-
touch(target).delete(path);
|
|
190
|
-
for (const target of found)
|
|
191
|
-
touch(target).add(path);
|
|
192
|
-
}
|
|
193
|
-
const emptied = [...referrers].filter(([, held]) => held.size === 0).map(([target]) => target);
|
|
194
|
-
return {
|
|
195
|
-
composition: index.composition,
|
|
196
|
-
targets: patched(index.targets, [...changed].filter(([, found]) => found.length > 0), [...changed].filter(([, found]) => found.length === 0).map(([path]) => path)),
|
|
197
|
-
referrers: patched(index.referrers, [...referrers]
|
|
198
|
-
.filter(([, held]) => held.size > 0)
|
|
199
|
-
.map(([target, held]) => [target, [...held]]), emptied),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function heldIndex(held, composition) {
|
|
203
|
-
const index = referrersOf.get(held.text);
|
|
204
|
-
return index !== undefined && typing(index.composition, composition) ? index : null;
|
|
205
|
-
}
|
|
206
|
-
const indexing = new WeakMap();
|
|
207
|
-
export function indexReferrers(held, composition) {
|
|
208
|
-
if (heldIndex(held, composition) !== null)
|
|
209
|
-
return;
|
|
210
|
-
const running = indexing.get(held.text);
|
|
211
|
-
if (running !== undefined)
|
|
212
|
-
return running;
|
|
213
|
-
const targets = new Map();
|
|
214
|
-
const referrers = new Map();
|
|
215
|
-
const filled = inUnits(Object.keys(held.text), (path) => {
|
|
216
|
-
const content = held.text[path];
|
|
217
|
-
const found = referencedBy(path, content, composition);
|
|
218
|
-
if (found.length > 0)
|
|
219
|
-
targets.set(path, found);
|
|
220
|
-
for (const target of found)
|
|
221
|
-
referrers.set(target, [...(referrers.get(target) ?? []), path]);
|
|
222
|
-
return ROW_WEIGHT + content.length;
|
|
223
|
-
});
|
|
224
|
-
const indexed = () => {
|
|
225
|
-
referrersOf.set(held.text, {
|
|
226
|
-
composition,
|
|
227
|
-
targets: patched(shared({}), targets),
|
|
228
|
-
referrers: patched(shared({}), referrers),
|
|
229
|
-
});
|
|
230
|
-
};
|
|
231
|
-
if (!(filled instanceof Promise))
|
|
232
|
-
return indexed();
|
|
233
|
-
const building = filled.then(indexed).finally(() => indexing.delete(held.text));
|
|
234
|
-
indexing.set(held.text, building);
|
|
235
|
-
return building;
|
|
236
|
-
}
|
|
237
|
-
export function referencesIndexed(held, composition) {
|
|
238
|
-
return heldIndex(held, composition) !== null;
|
|
239
|
-
}
|
|
240
|
-
export function referring(held, composition, targets) {
|
|
241
|
-
const index = heldIndex(held, composition);
|
|
242
|
-
if (index === null)
|
|
243
|
-
return null;
|
|
244
|
-
const found = new Set();
|
|
245
|
-
for (const target of targets) {
|
|
246
|
-
if (!Object.hasOwn(index.referrers, target))
|
|
247
|
-
continue;
|
|
248
|
-
for (const file of index.referrers[target])
|
|
249
|
-
found.add(file);
|
|
250
|
-
}
|
|
251
|
-
return found;
|
|
252
|
-
}
|
|
253
76
|
export function available(composition) {
|
|
254
|
-
return
|
|
255
|
-
(composition.selection === null || composition.selection.model.status !== 'unavailable'));
|
|
256
|
-
}
|
|
257
|
-
export function changedCleanly(next, previous, composition) {
|
|
258
|
-
if (!typing(previous.composition, composition))
|
|
259
|
-
return false;
|
|
260
|
-
const paths = new Set([
|
|
261
|
-
...differing(previous.text, next.text),
|
|
262
|
-
...differing(previous.binaries, next.binaries, () => true),
|
|
263
|
-
]);
|
|
264
|
-
const binary = (path) => Object.hasOwn(next.binaries, path);
|
|
265
|
-
const within = (file) => (path) => selected(composition, path) === selected(composition, file);
|
|
266
|
-
const reaching = (file, check) => {
|
|
267
|
-
if (!check.ok)
|
|
268
|
-
return false;
|
|
269
|
-
const part = within(file);
|
|
270
|
-
return check.references.every((reference) => resolves(reference, (path) => (part(path) ? declared(next.text[path]) : undefined), (path) => part(path) && binary(path)));
|
|
271
|
-
};
|
|
272
|
-
const changedTargets = new Map();
|
|
273
|
-
const shifted = [];
|
|
274
|
-
for (const path of paths) {
|
|
275
|
-
const now = next.text[path];
|
|
276
|
-
const was = previous.text[path];
|
|
277
|
-
const modeled = modelOf(composition, path) !== null;
|
|
278
|
-
if ((now === undefined) !== (was === undefined) ||
|
|
279
|
-
declared(now) !== declared(was) ||
|
|
280
|
-
binary(path) !== Object.hasOwn(previous.binaries, path)) {
|
|
281
|
-
shifted.push(path);
|
|
282
|
-
}
|
|
283
|
-
if (!modeled && typedIn(was) && !typedIn(now))
|
|
284
|
-
return false;
|
|
285
|
-
if (now === undefined) {
|
|
286
|
-
if (modeled)
|
|
287
|
-
changedTargets.set(path, []);
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
if (binary(path))
|
|
291
|
-
return false;
|
|
292
|
-
if (!modeled) {
|
|
293
|
-
if (declared(now) === undefined)
|
|
294
|
-
return false;
|
|
295
|
-
if (!typedIn(now) && !checked(path, now, composition).ok)
|
|
296
|
-
return false;
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
const check = checked(path, now, composition);
|
|
300
|
-
if (!reaching(path, check))
|
|
301
|
-
return false;
|
|
302
|
-
changedTargets.set(path, targetsOf(check));
|
|
303
|
-
}
|
|
304
|
-
const index = heldIndex(previous, composition);
|
|
305
|
-
if (index === null && shifted.length > 0)
|
|
306
|
-
return false;
|
|
307
|
-
for (const target of shifted) {
|
|
308
|
-
const files = index !== null && Object.hasOwn(index.referrers, target) ? index.referrers[target] : [];
|
|
309
|
-
for (const file of files) {
|
|
310
|
-
if (paths.has(file))
|
|
311
|
-
continue;
|
|
312
|
-
if (!reaching(file, checked(file, next.text[file], composition)))
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
if (index !== null) {
|
|
317
|
-
referrersOf.set(next.text, changedTargets.size === 0 ? index : reindexed(index, changedTargets));
|
|
318
|
-
}
|
|
319
|
-
return true;
|
|
77
|
+
return composition.model.status !== 'unavailable';
|
|
320
78
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { sql } from '@agentshouse/mdmodel';
|
|
2
|
+
import type { Plan, QueryRows } from './query.js';
|
|
3
|
+
import type { Connection } from './tables.js';
|
|
4
|
+
export type QueryRoom = {
|
|
5
|
+
readonly locator: string;
|
|
6
|
+
readonly key: number;
|
|
7
|
+
};
|
|
8
|
+
type Fragment = sql.Fragment;
|
|
9
|
+
export declare const VISIBLE: (alias: string) => string;
|
|
10
|
+
export declare function within(alias: string, path: string): Fragment;
|
|
11
|
+
export type QueryAnswer = QueryRows & {
|
|
12
|
+
readonly more?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,GAAG,EAOJ,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,EAAE,IAAI,EAAuC,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvF,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,KAAK,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAI7B,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MACkC,CAAC;AAa3E,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAM5D;AA2cD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA6ZjE,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,GAAE,MAAM,GAAG,IAAW,GAC3B,WAAW,CAUb"}
|