@agentshouse/mdruntime 0.1.0-ca7c26c6bc27e → 0.1.0-ca92b54804c33
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 +25 -12
- package/dist/adapter.d.ts +199 -54
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +7 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +40 -28
- 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 +37 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +336 -51
- 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 -56
- 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 -18
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +161 -30
- package/dist/collection.d.ts +13 -14
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +52 -56
- package/dist/compile.d.ts +11 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +586 -0
- package/dist/connection.d.ts +67 -24
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +4414 -1205
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation.d.ts +65 -21
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +922 -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 +11 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +134 -34
- 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 +24 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/job.d.ts +14 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +28 -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 +22 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +299 -94
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +91 -0
- package/dist/model.d.ts +17 -12
- 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 -4
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +120 -14
- 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 -5
- 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/paths.d.ts +1 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -16
- package/dist/query.d.ts +42 -181
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -423
- package/dist/reach.d.ts +19 -5
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +298 -92
- package/dist/react.d.ts +45 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +54 -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 +20 -7
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +155 -59
- package/dist/replica.d.ts +61 -34
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +355 -162
- package/dist/room-draft.d.ts +59 -11
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +276 -80
- 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 -182
- 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/status.d.ts +7 -4
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -15
- package/dist/store.d.ts +174 -68
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +367 -360
- package/dist/stored.d.ts +156 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +635 -0
- package/dist/tables.d.ts +381 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +700 -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 +179 -45
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +72 -46
- package/package.json +33 -10
- package/AGENTS.md +0 -215
- 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 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -377
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,19 +137,101 @@ 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
236
|
query: ((query) => ask('query', [query])),
|
|
129
237
|
search: (request) => ask('search', [request]),
|
|
@@ -131,35 +239,58 @@ export function connectMdRuntime(port) {
|
|
|
131
239
|
roomDraft: {
|
|
132
240
|
list: () => ask('roomDraft.list', []),
|
|
133
241
|
read: (room, path) => ask('roomDraft.read', [room, path]),
|
|
134
|
-
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]),
|
|
135
243
|
discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
|
|
136
244
|
},
|
|
137
245
|
save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
|
|
246
|
+
saveParts: (room, parts) => ask('saveParts', [room, parts]),
|
|
138
247
|
presentation: {
|
|
139
248
|
read: () => ask('presentation.read', []),
|
|
140
249
|
write: (value) => ask('presentation.write', [value]),
|
|
250
|
+
edit: (members) => ask('presentation.edit', [members]),
|
|
141
251
|
},
|
|
142
252
|
conversation: {
|
|
143
253
|
list: () => ask('conversation.list', []),
|
|
144
254
|
read: (conversation, options) => ask('conversation.read', [conversation, options]),
|
|
145
255
|
create: (input) => ask('conversation.create', [input]),
|
|
146
|
-
send: (conversation) => ask('conversation.send', [conversation]),
|
|
256
|
+
send: (conversation, operation, draft) => ask('conversation.send', [conversation, operation, draft]),
|
|
147
257
|
answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
|
|
148
258
|
interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
|
|
149
259
|
kill: (conversation) => ask('conversation.kill', [conversation]),
|
|
150
|
-
cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
|
|
151
260
|
delete: (conversation) => ask('conversation.delete', [conversation]),
|
|
152
261
|
},
|
|
153
262
|
chatDraft: {
|
|
154
|
-
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]),
|
|
155
265
|
discard: (conversation) => ask('chatDraft.discard', [conversation]),
|
|
156
266
|
},
|
|
157
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
|
+
},
|
|
158
274
|
call: (name, input) => ask('call', [name, input]),
|
|
159
275
|
reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
|
|
160
276
|
log: () => ask('log', []),
|
|
161
277
|
persistence: () => ask('persistence', []),
|
|
278
|
+
retry: () => ask('retry', []),
|
|
279
|
+
cleanUp: () => ask('cleanUp', []),
|
|
280
|
+
unsent: () => ask('unsent', []),
|
|
281
|
+
reset: () => ask('reset', []),
|
|
162
282
|
observe: ((topic, ...input) => watch(topic, input)),
|
|
163
283
|
reauthorize: () => ask('reauthorize', []),
|
|
164
|
-
|
|
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;
|
|
165
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,18 +13,17 @@ export type Composition = {
|
|
|
13
13
|
roots: readonly string[];
|
|
14
14
|
model: ModelState;
|
|
15
15
|
} | null;
|
|
16
|
+
typedPaths: readonly TypedPath[];
|
|
16
17
|
};
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
collection: Collection;
|
|
18
|
+
export type Composed = {
|
|
19
|
+
readonly composition: Composition;
|
|
20
|
+
readonly fingerprint: string;
|
|
21
21
|
};
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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>;
|
|
27
27
|
export declare function validRoot(root: unknown): root is string;
|
|
28
|
-
export declare function
|
|
29
|
-
export {};
|
|
28
|
+
export declare function available(composition: Composition): boolean;
|
|
30
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,8 +1,30 @@
|
|
|
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
|
}
|
|
@@ -11,62 +33,36 @@ export function governing(composition, path) {
|
|
|
11
33
|
? composition.selection.model
|
|
12
34
|
: composition.model;
|
|
13
35
|
}
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
};
|
|
28
52
|
}
|
|
29
|
-
export function
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
})();
|
|
38
62
|
}
|
|
39
63
|
export function validRoot(root) {
|
|
40
64
|
return typeof root === 'string' && normalize(root) === root;
|
|
41
65
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
const typed = Object.entries(documents).find(([, content]) => {
|
|
45
|
-
const parsed = parse(content);
|
|
46
|
-
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
47
|
-
});
|
|
48
|
-
if (typed !== undefined)
|
|
49
|
-
return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
|
|
50
|
-
}
|
|
51
|
-
return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
|
|
52
|
-
}
|
|
53
|
-
export function validateCollection(text, binaryTargets, composition) {
|
|
54
|
-
const collection = {};
|
|
55
|
-
const selection = {};
|
|
56
|
-
for (const [path, content] of Object.entries(text)) {
|
|
57
|
-
if (selected(composition, path))
|
|
58
|
-
selection[path] = content;
|
|
59
|
-
else
|
|
60
|
-
collection[path] = content;
|
|
61
|
-
}
|
|
62
|
-
const verdicts = [
|
|
63
|
-
validateAgainst(collection, binaryTargets.filter((path) => !selected(composition, path)), composition.model),
|
|
64
|
-
];
|
|
65
|
-
if (composition.selection !== null) {
|
|
66
|
-
verdicts.push(validateAgainst(selection, binaryTargets.filter((path) => selected(composition, path)), composition.selection.model));
|
|
67
|
-
}
|
|
68
|
-
const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
|
|
69
|
-
if (refusals.length === 0)
|
|
70
|
-
return verdicts[0];
|
|
71
|
-
return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
|
|
66
|
+
export function available(composition) {
|
|
67
|
+
return composition.model.status !== 'unavailable';
|
|
72
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;AA+a3E,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAkUjE,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"}
|