@agentshouse/mdruntime 0.1.0-c3903a68dcbbf → 0.1.0-c3a5b012b4a8c
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 +26 -13
- package/dist/adapter.d.ts +244 -88
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +8 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +46 -0
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +18 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +40 -6
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +336 -52
- 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 +9 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -60
- package/dist/change.d.ts +46 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +34 -0
- package/dist/client.d.ts +44 -24
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +161 -36
- package/dist/collection.d.ts +13 -16
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +52 -66
- package/dist/compile.d.ts +11 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +717 -0
- package/dist/connection.d.ts +69 -44
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +4581 -1472
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +47 -0
- package/dist/conversation.d.ts +76 -27
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1052 -273
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +10 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +20 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +161 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/host.d.ts +17 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +163 -75
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -1
- package/dist/index.d.ts +26 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/live.d.ts +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +165 -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 +30 -9
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +337 -87
- package/dist/messages.d.ts +52 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +168 -0
- package/dist/model.d.ts +17 -16
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +9 -9
- 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 +22 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +133 -17
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +72 -21
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +81 -1
- package/dist/overlay.d.ts +16 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +147 -180
- package/dist/parts.d.ts +59 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +118 -0
- package/dist/paths.d.ts +1 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -16
- package/dist/query.d.ts +56 -180
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -422
- package/dist/questions.d.ts +32 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +118 -0
- package/dist/reach.d.ts +54 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +483 -0
- package/dist/react.d.ts +45 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +54 -0
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +50 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +27 -0
- package/dist/recovery.d.ts +26 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +232 -0
- package/dist/refresh.d.ts +21 -7
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +155 -55
- package/dist/replica.d.ts +61 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +355 -162
- package/dist/room-draft.d.ts +62 -11
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +281 -83
- package/dist/rows.d.ts +32 -34
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +65 -87
- package/dist/save.d.ts +74 -6
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +902 -183
- package/dist/search.d.ts +15 -54
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -121
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +15 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +421 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +81 -0
- package/dist/status.d.ts +7 -4
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -15
- package/dist/store.d.ts +178 -80
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +372 -381
- package/dist/stored.d.ts +156 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +637 -0
- package/dist/tables.d.ts +388 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +706 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- 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 +199 -19
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +92 -67
- package/package.json +33 -10
- package/AGENTS.md +0 -210
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
- package/dist/read-side.d.ts +0 -14
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -371
package/dist/client.js
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
|
+
import { shownBy } from './media.js';
|
|
1
2
|
import { observed } from './observation.js';
|
|
2
|
-
import {
|
|
3
|
+
import { runtimeError } from './failure.js';
|
|
4
|
+
import { answer, AUTHORIZATION_ENDED, PORT_CLOSED, } 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
|
+
}
|
|
23
|
+
function refused(refusal) {
|
|
24
|
+
return runtimeError(refusal.code, refusal.code, refusal.retryable);
|
|
25
|
+
}
|
|
3
26
|
export function connectMdRuntime(port) {
|
|
4
27
|
let sequence = 0;
|
|
5
28
|
let refusal = null;
|
|
@@ -7,8 +30,10 @@ export function connectMdRuntime(port) {
|
|
|
7
30
|
const calls = new Map();
|
|
8
31
|
const opening = new Map();
|
|
9
32
|
const observations = new Map();
|
|
33
|
+
let drawing = null;
|
|
34
|
+
let settling = null;
|
|
10
35
|
const send = (message) => {
|
|
11
|
-
port.postMessage(
|
|
36
|
+
port.postMessage(message);
|
|
12
37
|
};
|
|
13
38
|
function begin(id, topic, first) {
|
|
14
39
|
const handle = observed(first, () => {
|
|
@@ -25,7 +50,7 @@ export function connectMdRuntime(port) {
|
|
|
25
50
|
if (topic === 'connection-refusal')
|
|
26
51
|
handle.receive(reported);
|
|
27
52
|
}
|
|
28
|
-
const failure =
|
|
53
|
+
const failure = refused(reported);
|
|
29
54
|
for (const [id, waiting] of opening) {
|
|
30
55
|
if (waiting.topic === 'connection-refusal')
|
|
31
56
|
waiting.settle(begin(id, waiting.topic, reported));
|
|
@@ -36,12 +61,12 @@ export function connectMdRuntime(port) {
|
|
|
36
61
|
for (const waiting of calls.values())
|
|
37
62
|
waiting.fail(failure);
|
|
38
63
|
calls.clear();
|
|
64
|
+
drawing?.();
|
|
39
65
|
}
|
|
40
|
-
function end(
|
|
66
|
+
function end(failure) {
|
|
41
67
|
if (ended !== null)
|
|
42
68
|
return;
|
|
43
|
-
ended =
|
|
44
|
-
const failure = new Error(reason);
|
|
69
|
+
ended = failure;
|
|
45
70
|
for (const waiting of opening.values())
|
|
46
71
|
waiting.fail(failure);
|
|
47
72
|
opening.clear();
|
|
@@ -51,16 +76,10 @@ export function connectMdRuntime(port) {
|
|
|
51
76
|
for (const { handle } of observations.values())
|
|
52
77
|
handle.end();
|
|
53
78
|
observations.clear();
|
|
79
|
+
drawing?.();
|
|
54
80
|
}
|
|
55
81
|
port.addEventListener('message', (event) => {
|
|
56
|
-
const
|
|
57
|
-
if (wire === null)
|
|
58
|
-
return;
|
|
59
|
-
if (!wire.matching) {
|
|
60
|
-
refuse(PROTOCOL_MISMATCH);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const message = answer(wire.message);
|
|
82
|
+
const message = answer(event.data);
|
|
64
83
|
if (message === null)
|
|
65
84
|
return;
|
|
66
85
|
if (message.kind === 'refusal') {
|
|
@@ -68,7 +87,11 @@ export function connectMdRuntime(port) {
|
|
|
68
87
|
return;
|
|
69
88
|
}
|
|
70
89
|
if (message.kind === 'ended') {
|
|
71
|
-
|
|
90
|
+
for (const { topic, handle } of observations.values()) {
|
|
91
|
+
if (topic === 'member')
|
|
92
|
+
handle.receive(null);
|
|
93
|
+
}
|
|
94
|
+
end(runtimeError('authorization-ended', AUTHORIZATION_ENDED));
|
|
72
95
|
return;
|
|
73
96
|
}
|
|
74
97
|
if (message.kind === 'event') {
|
|
@@ -78,31 +101,34 @@ export function connectMdRuntime(port) {
|
|
|
78
101
|
const waiting = opening.get(message.id);
|
|
79
102
|
if (waiting !== undefined) {
|
|
80
103
|
opening.delete(message.id);
|
|
81
|
-
if (message.kind === 'failure')
|
|
82
|
-
waiting.fail(
|
|
104
|
+
if (message.kind === 'failure') {
|
|
105
|
+
waiting.fail(runtimeError(message.code, message.message, message.retryable));
|
|
106
|
+
}
|
|
83
107
|
else
|
|
84
108
|
waiting.settle(begin(message.id, waiting.topic, message.value));
|
|
109
|
+
drawing?.();
|
|
85
110
|
return;
|
|
86
111
|
}
|
|
87
112
|
const called = calls.get(message.id);
|
|
88
113
|
if (called === undefined)
|
|
89
114
|
return;
|
|
90
115
|
calls.delete(message.id);
|
|
91
|
-
if (message.kind === 'failure')
|
|
92
|
-
called.fail(
|
|
116
|
+
if (message.kind === 'failure') {
|
|
117
|
+
called.fail(runtimeError(message.code, message.message, message.retryable));
|
|
118
|
+
}
|
|
93
119
|
else
|
|
94
120
|
called.settle(message.value);
|
|
95
121
|
});
|
|
96
122
|
port.addEventListener('close', () => {
|
|
97
|
-
end(PORT_CLOSED);
|
|
123
|
+
end(runtimeError('port-closed', PORT_CLOSED));
|
|
98
124
|
});
|
|
99
125
|
port.start();
|
|
100
126
|
send({ kind: 'hello' });
|
|
101
127
|
function ask(member, input) {
|
|
102
128
|
if (ended !== null)
|
|
103
|
-
return Promise.reject(
|
|
129
|
+
return Promise.reject(ended);
|
|
104
130
|
if (refusal !== null)
|
|
105
|
-
return Promise.reject(
|
|
131
|
+
return Promise.reject(refused(refusal));
|
|
106
132
|
const id = (sequence += 1);
|
|
107
133
|
return new Promise((settle, fail) => {
|
|
108
134
|
calls.set(id, { settle: settle, fail });
|
|
@@ -111,61 +137,160 @@ export function connectMdRuntime(port) {
|
|
|
111
137
|
}
|
|
112
138
|
function watch(topic, input) {
|
|
113
139
|
if (ended !== null)
|
|
114
|
-
return Promise.reject(
|
|
140
|
+
return Promise.reject(ended);
|
|
115
141
|
const id = (sequence += 1);
|
|
116
142
|
if (refusal !== null) {
|
|
117
143
|
return topic === 'connection-refusal'
|
|
118
144
|
? Promise.resolve(begin(id, topic, refusal))
|
|
119
|
-
: Promise.reject(
|
|
145
|
+
: Promise.reject(refused(refusal));
|
|
120
146
|
}
|
|
121
147
|
return new Promise((settle, fail) => {
|
|
122
148
|
opening.set(id, { topic, settle, fail });
|
|
123
149
|
send({ kind: 'observe', id, topic, input });
|
|
150
|
+
drawing?.();
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function streamed(answer) {
|
|
154
|
+
if (answer.kind !== 'binary')
|
|
155
|
+
return answer;
|
|
156
|
+
const { file, byteLength, mediaType } = answer;
|
|
157
|
+
let part = 0;
|
|
158
|
+
let received = 0;
|
|
159
|
+
const stream = new ReadableStream({
|
|
160
|
+
async pull(controller) {
|
|
161
|
+
const bytes = await ask('binaryFile.part', [file, part]);
|
|
162
|
+
if (bytes === null) {
|
|
163
|
+
if (received === byteLength)
|
|
164
|
+
controller.close();
|
|
165
|
+
else
|
|
166
|
+
controller.error(runtimeError('binary-file-absent', 'The file ended early'));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
part += 1;
|
|
170
|
+
received += bytes.byteLength;
|
|
171
|
+
controller.enqueue(bytes);
|
|
172
|
+
},
|
|
173
|
+
}, { highWaterMark: 0 });
|
|
174
|
+
return { kind: 'binary', stream, byteLength, mediaType };
|
|
175
|
+
}
|
|
176
|
+
async function download(room, path, revision) {
|
|
177
|
+
const tab = PAGE.test(path) ? globalThis.open('', '_blank') : null;
|
|
178
|
+
const linked = await ask('binaryFile.link', [room, path, revision]);
|
|
179
|
+
if (linked.kind === 'link' && PAGE.test(linked.name)) {
|
|
180
|
+
const away = tab ?? globalThis.open('', '_blank');
|
|
181
|
+
if (away === null)
|
|
182
|
+
return BLOCKED;
|
|
183
|
+
away.location.replace(linked.url);
|
|
184
|
+
return STARTED;
|
|
185
|
+
}
|
|
186
|
+
tab?.close();
|
|
187
|
+
if (linked.kind === 'link') {
|
|
188
|
+
handed(linked.url, linked.name);
|
|
189
|
+
return STARTED;
|
|
190
|
+
}
|
|
191
|
+
if (linked.kind !== 'absent')
|
|
192
|
+
return linked;
|
|
193
|
+
const read = streamed(await ask('binaryFile.read', [room, path, revision]));
|
|
194
|
+
if (read.kind !== 'binary')
|
|
195
|
+
return read;
|
|
196
|
+
const copy = await new Response(read.stream, {
|
|
197
|
+
headers: { 'content-type': read.mediaType },
|
|
198
|
+
}).blob();
|
|
199
|
+
const url = URL.createObjectURL(copy);
|
|
200
|
+
handed(url, path.slice(path.lastIndexOf('/') + 1));
|
|
201
|
+
setTimeout(() => URL.revokeObjectURL(url), HANDED_COPY_MS);
|
|
202
|
+
return STARTED;
|
|
203
|
+
}
|
|
204
|
+
function settled() {
|
|
205
|
+
if (settling !== null)
|
|
206
|
+
return settling;
|
|
207
|
+
settling = new Promise((resolve) => {
|
|
208
|
+
let moved = 0;
|
|
209
|
+
const check = () => {
|
|
210
|
+
moved += 1;
|
|
211
|
+
if (opening.size > 0)
|
|
212
|
+
return;
|
|
213
|
+
const at = moved;
|
|
214
|
+
const waited = (frames) => {
|
|
215
|
+
requestAnimationFrame(() => {
|
|
216
|
+
if (frames < SETTLED_FRAMES) {
|
|
217
|
+
waited(frames + 1);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (moved !== at || opening.size > 0)
|
|
221
|
+
return;
|
|
222
|
+
drawing = null;
|
|
223
|
+
resolve();
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
waited(1);
|
|
227
|
+
};
|
|
228
|
+
drawing = check;
|
|
229
|
+
check();
|
|
124
230
|
});
|
|
231
|
+
return settling;
|
|
125
232
|
}
|
|
126
|
-
|
|
233
|
+
const show = (room, path, revision) => ask('binaryFile.show', [room, path, revision]).then((shown) => streamed(shown));
|
|
234
|
+
return shownBy(show, {
|
|
127
235
|
rooms: () => ask('rooms', []),
|
|
128
|
-
slots: () => ask('slots', []),
|
|
129
236
|
query: ((query) => ask('query', [query])),
|
|
130
237
|
search: (request) => ask('search', [request]),
|
|
131
238
|
types: (locator) => ask('types', [locator]),
|
|
132
|
-
syncStatus: () => ask('syncStatus', []),
|
|
133
|
-
serviceMode: () => ask('serviceMode', []),
|
|
134
239
|
roomDraft: {
|
|
135
240
|
list: () => ask('roomDraft.list', []),
|
|
136
241
|
read: (room, path) => ask('roomDraft.read', [room, path]),
|
|
137
|
-
write: (room, path, revision, parts) => ask('roomDraft.write', [room, path, revision, parts]),
|
|
242
|
+
write: (room, path, revision, parts, next) => ask('roomDraft.write', next === undefined ? [room, path, revision, parts] : [room, path, revision, parts, next]),
|
|
138
243
|
discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
|
|
139
244
|
},
|
|
140
245
|
save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
|
|
141
|
-
|
|
246
|
+
saveParts: (room, parts) => ask('saveParts', [room, parts]),
|
|
142
247
|
presentation: {
|
|
143
248
|
read: () => ask('presentation.read', []),
|
|
144
249
|
write: (value) => ask('presentation.write', [value]),
|
|
250
|
+
edit: (members) => ask('presentation.edit', [members]),
|
|
145
251
|
},
|
|
146
252
|
conversation: {
|
|
147
253
|
list: () => ask('conversation.list', []),
|
|
148
254
|
read: (conversation, options) => ask('conversation.read', [conversation, options]),
|
|
149
255
|
create: (input) => ask('conversation.create', [input]),
|
|
150
|
-
send: (conversation) => ask('conversation.send', [conversation]),
|
|
256
|
+
send: (conversation, operation, draft) => ask('conversation.send', [conversation, operation, draft]),
|
|
151
257
|
answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
|
|
152
258
|
interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
|
|
153
259
|
kill: (conversation) => ask('conversation.kill', [conversation]),
|
|
154
|
-
cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
|
|
155
260
|
delete: (conversation) => ask('conversation.delete', [conversation]),
|
|
156
261
|
},
|
|
157
262
|
chatDraft: {
|
|
158
|
-
write: (conversation, draft) => ask('chatDraft.write', [conversation, draft]),
|
|
263
|
+
write: (conversation, draft, revision) => ask('chatDraft.write', [conversation, draft, revision]),
|
|
264
|
+
prepend: (conversation, draft) => ask('chatDraft.prepend', [conversation, draft]),
|
|
159
265
|
discard: (conversation) => ask('chatDraft.discard', [conversation]),
|
|
160
266
|
},
|
|
161
267
|
history: (locator, path, query) => ask('history', [locator, path, query]),
|
|
268
|
+
resolve: (room, path, destination) => ask('resolve', [room, path, destination]),
|
|
269
|
+
binaryFile: {
|
|
270
|
+
read: (room, path, revision) => ask('binaryFile.read', [room, path, revision]).then((read) => streamed(read)),
|
|
271
|
+
attach: (room, file) => ask('binaryFile.attach', [room, file]),
|
|
272
|
+
download,
|
|
273
|
+
},
|
|
162
274
|
call: (name, input) => ask('call', [name, input]),
|
|
163
275
|
reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
|
|
164
276
|
log: () => ask('log', []),
|
|
165
|
-
storageLoss: () => ask('storageLoss', []),
|
|
166
277
|
persistence: () => ask('persistence', []),
|
|
167
|
-
|
|
278
|
+
retry: () => ask('retry', []),
|
|
279
|
+
cleanUp: () => ask('cleanUp', []),
|
|
280
|
+
unsent: () => ask('unsent', []),
|
|
281
|
+
reset: () => ask('reset', []),
|
|
168
282
|
observe: ((topic, ...input) => watch(topic, input)),
|
|
169
283
|
reauthorize: () => ask('reauthorize', []),
|
|
170
|
-
|
|
284
|
+
settled,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
const turns = new WeakMap();
|
|
288
|
+
export function inTurn(client, work) {
|
|
289
|
+
const turn = (turns.get(client) ?? Promise.resolve()).then(work);
|
|
290
|
+
turns.set(client, turn.then(() => undefined, () => undefined));
|
|
291
|
+
return turn;
|
|
171
292
|
}
|
|
293
|
+
export { chainedWindows } from './chain.js';
|
|
294
|
+
export { roomDraftRevision } from './identity.js';
|
|
295
|
+
export { defineRoomMedia, ROOM_MEDIA } from './media.js';
|
|
296
|
+
export { unanswered } from './wire.js';
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type Document, type
|
|
1
|
+
import { type Document, type TypedPath } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { ModelState } from './model.js';
|
|
3
3
|
import type { MdModelIdentity } from './adapter.js';
|
|
4
|
-
import type { Refused } from './transfer.js';
|
|
5
4
|
export declare const MD_MODEL: MdModelIdentity;
|
|
6
5
|
export type Collection = {
|
|
7
|
-
|
|
6
|
+
text: Readonly<Record<string, string>>;
|
|
8
7
|
composition: Composition;
|
|
8
|
+
document(path: string): Document | undefined;
|
|
9
9
|
};
|
|
10
10
|
export type Composition = {
|
|
11
11
|
model: ModelState;
|
|
@@ -13,20 +13,17 @@ export type Composition = {
|
|
|
13
13
|
roots: readonly string[];
|
|
14
14
|
model: ModelState;
|
|
15
15
|
} | null;
|
|
16
|
-
|
|
16
|
+
typedPaths: readonly TypedPath[];
|
|
17
17
|
};
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
text: Readonly<Record<string, string>>;
|
|
22
|
-
collection: Collection;
|
|
18
|
+
export type Composed = {
|
|
19
|
+
readonly composition: Composition;
|
|
20
|
+
readonly fingerprint: string;
|
|
23
21
|
};
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
export declare function composedOf(composition: Composition): Composed;
|
|
23
|
+
export declare function selected(composition: Composition, path: string): boolean;
|
|
24
|
+
export declare function governing(composition: Composition, path: string): ModelState;
|
|
25
|
+
export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition): Collection;
|
|
26
|
+
export declare function documentsOf(collection: Collection): Generator<number, Iterable<readonly [string, Document]>, void>;
|
|
29
27
|
export declare function validRoot(root: unknown): root is string;
|
|
30
|
-
export declare function
|
|
31
|
-
export {};
|
|
28
|
+
export declare function available(composition: Composition): boolean;
|
|
32
29
|
//# 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,EAAkB,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAErF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,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,wBAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAKxE;AAED,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAI5E;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,82 +1,68 @@
|
|
|
1
|
-
import { parse,
|
|
1
|
+
import { parse, VERSION } from '@agentshouse/mdmodel';
|
|
2
2
|
import { beneath, normalize } from './paths.js';
|
|
3
|
+
import { hashed } from './observation.js';
|
|
4
|
+
import { sortedKeys } from './shared.js';
|
|
3
5
|
export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
|
|
4
|
-
const
|
|
5
|
-
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) {
|
|
6
28
|
return (composition.selection !== null &&
|
|
7
29
|
composition.selection.roots.some((root) => beneath(root, path)));
|
|
8
30
|
}
|
|
9
|
-
export function untyped(roots, path) {
|
|
10
|
-
return roots.some((root) => beneath(root, path));
|
|
11
|
-
}
|
|
12
31
|
export function governing(composition, path) {
|
|
13
32
|
return composition.selection !== null && selected(composition, path)
|
|
14
33
|
? composition.selection.model
|
|
15
34
|
: composition.model;
|
|
16
35
|
}
|
|
17
|
-
function
|
|
18
|
-
const
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
36
|
+
export function collectionOf(text, composition) {
|
|
37
|
+
const parsed = new Map();
|
|
38
|
+
return {
|
|
39
|
+
text,
|
|
40
|
+
composition,
|
|
41
|
+
document(path) {
|
|
42
|
+
if (parsed.has(path))
|
|
43
|
+
return parsed.get(path) ?? undefined;
|
|
44
|
+
const content = text[path];
|
|
45
|
+
if (content === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
const read = parse(content, path);
|
|
48
|
+
parsed.set(path, read.ok ? read.document : null);
|
|
49
|
+
return read.ok ? read.document : undefined;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
22
52
|
}
|
|
23
|
-
export function
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
return { documents, composition };
|
|
33
|
-
}
|
|
34
|
-
export function readCollection(text, composition, previous) {
|
|
35
|
-
const documents = {};
|
|
36
|
-
for (const path of Object.keys(text).sort()) {
|
|
37
|
-
if (untyped(composition.untypedFolders, path))
|
|
38
|
-
continue;
|
|
39
|
-
const parsed = parsedAt(text, path, previous);
|
|
40
|
-
if (!parsed.ok)
|
|
41
|
-
return { kind: 'refused', refusal: parsed.refusal };
|
|
42
|
-
documents[path] = parsed.document;
|
|
43
|
-
}
|
|
44
|
-
return { kind: 'read', collection: { documents, composition } };
|
|
53
|
+
export function* documentsOf(collection) {
|
|
54
|
+
const paths = yield* sortedKeys(collection.text);
|
|
55
|
+
return (function* () {
|
|
56
|
+
for (const path of paths) {
|
|
57
|
+
const document = collection.document(path);
|
|
58
|
+
if (document !== undefined)
|
|
59
|
+
yield [path, document];
|
|
60
|
+
}
|
|
61
|
+
})();
|
|
45
62
|
}
|
|
46
63
|
export function validRoot(root) {
|
|
47
64
|
return typeof root === 'string' && normalize(root) === root;
|
|
48
65
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
const typed = Object.entries(documents).find(([, content]) => {
|
|
52
|
-
const parsed = parse(content);
|
|
53
|
-
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
54
|
-
});
|
|
55
|
-
if (typed !== undefined)
|
|
56
|
-
return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
|
|
57
|
-
}
|
|
58
|
-
return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
|
|
59
|
-
}
|
|
60
|
-
export function validateCollection(text, binaryTargets, composition) {
|
|
61
|
-
const collection = {};
|
|
62
|
-
const selection = {};
|
|
63
|
-
for (const [path, content] of Object.entries(text)) {
|
|
64
|
-
if (untyped(composition.untypedFolders, path))
|
|
65
|
-
continue;
|
|
66
|
-
if (selected(composition, path))
|
|
67
|
-
selection[path] = content;
|
|
68
|
-
else
|
|
69
|
-
collection[path] = content;
|
|
70
|
-
}
|
|
71
|
-
const linked = binaryTargets.filter((path) => !untyped(composition.untypedFolders, path));
|
|
72
|
-
const verdicts = [
|
|
73
|
-
validateAgainst(collection, linked.filter((path) => !selected(composition, path)), composition.model),
|
|
74
|
-
];
|
|
75
|
-
if (composition.selection !== null) {
|
|
76
|
-
verdicts.push(validateAgainst(selection, linked.filter((path) => selected(composition, path)), composition.selection.model));
|
|
77
|
-
}
|
|
78
|
-
const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
|
|
79
|
-
if (refusals.length === 0)
|
|
80
|
-
return verdicts[0];
|
|
81
|
-
return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
|
|
66
|
+
export function available(composition) {
|
|
67
|
+
return composition.model.status !== 'unavailable';
|
|
82
68
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plan, QueryRows } from './query.js';
|
|
2
|
+
import type { Connection } from './tables.js';
|
|
3
|
+
export type QueryRoom = {
|
|
4
|
+
readonly locator: string;
|
|
5
|
+
readonly key: number;
|
|
6
|
+
};
|
|
7
|
+
export type QueryAnswer = QueryRows & {
|
|
8
|
+
readonly more?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
|
|
11
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAoBA,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;AAoe3E,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAmajE,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"}
|