@agentshouse/mdruntime-adapter 0.1.0-c83554fdd7451 → 0.1.0-c83eacba28825
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 +2 -2
- package/dist/actions.d.ts +4 -53
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -231
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +159 -303
- package/dist/authored-path.d.ts +9 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +34 -0
- package/dist/chunks.d.ts +37 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +269 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +19 -9
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +65 -32
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +5 -9
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +29 -34
- package/dist/read.d.ts +19 -53
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +46 -314
- package/dist/refusal.d.ts +3 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +17 -12
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/bounds.d.ts +7 -0
- package/dist/session-content/check.d.ts +18 -0
- package/dist/session-content/index.d.ts +7 -0
- package/dist/session-content/parts.d.ts +103 -0
- package/dist/session-content/state.d.ts +61 -0
- package/dist/session-content/turn.d.ts +328 -0
- package/dist/site.d.ts +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +80 -130
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +18 -0
- package/dist/stream.d.ts +16 -16
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +258 -430
- package/dist/transport.d.ts +53 -50
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +54 -12
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +3 -2
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +10 -8
- package/dist/version.d.ts +0 -1
- package/dist/write.d.ts +2 -3
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +27 -42
- package/package.json +3 -2
- package/dist/app-reference.d.ts +0 -2
- package/dist/app-reference.d.ts.map +0 -1
- package/dist/app-reference.js +0 -2
- package/dist/crockford.d.ts +0 -4
- package/dist/crockford.d.ts.map +0 -1
- package/dist/crockford.js +0 -3
- package/dist/gather.d.ts +0 -3
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -35
- package/dist/house-model.d.ts +0 -2
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -489
- package/dist/part.d.ts +0 -14
- package/dist/part.d.ts.map +0 -1
- package/dist/part.js +0 -90
- package/dist/room-stream.d.ts +0 -19
- package/dist/room-stream.d.ts.map +0 -1
- package/dist/room-stream.js +0 -57
- package/dist/room-types.d.ts +0 -7
- package/dist/room-types.d.ts.map +0 -1
- package/dist/room-types.js +0 -125
package/dist/read.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { DECIMAL, readPosition, roomVersion } from './version.js';
|
|
1
|
+
import { patching, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { roomVersion } from './version.js';
|
|
4
3
|
const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
|
|
5
4
|
function fileOf(revision) {
|
|
6
5
|
return REVISION_FILE.exec(revision)?.[1];
|
|
@@ -8,8 +7,10 @@ function fileOf(revision) {
|
|
|
8
7
|
export function answering() {
|
|
9
8
|
return {
|
|
10
9
|
documents: new Map(),
|
|
10
|
+
facts: new Map(),
|
|
11
11
|
revisions: new Map(),
|
|
12
12
|
fileIds: new Map(),
|
|
13
|
+
created: new Map(),
|
|
13
14
|
changes: new Map(),
|
|
14
15
|
binaryFiles: new Map(),
|
|
15
16
|
removals: new Set(),
|
|
@@ -25,8 +26,10 @@ export function revised(answer, path, revision) {
|
|
|
25
26
|
}
|
|
26
27
|
export function forgotten(answer, path) {
|
|
27
28
|
answer.documents.delete(path);
|
|
29
|
+
answer.facts.delete(path);
|
|
28
30
|
answer.revisions.delete(path);
|
|
29
31
|
answer.fileIds.delete(path);
|
|
32
|
+
answer.created.delete(path);
|
|
30
33
|
answer.changes.delete(path);
|
|
31
34
|
answer.binaryFiles.delete(path);
|
|
32
35
|
answer.removals.delete(path);
|
|
@@ -53,8 +56,10 @@ export function* answered(answer) {
|
|
|
53
56
|
const removals = yield* pathsOf(answer.removals);
|
|
54
57
|
return {
|
|
55
58
|
documents: yield* patching({}, answer.documents),
|
|
59
|
+
facts: yield* patching({}, answer.facts),
|
|
56
60
|
revisions: yield* patching({}, answer.revisions),
|
|
57
61
|
...(answer.fileIds.size === 0 ? {} : { fileIds: yield* patching({}, answer.fileIds) }),
|
|
62
|
+
...(answer.created.size === 0 ? {} : { created: yield* patching({}, answer.created) }),
|
|
58
63
|
changes: yield* patching({}, answer.changes),
|
|
59
64
|
binaryFiles: yield* patching({}, answer.binaryFiles),
|
|
60
65
|
removals,
|
|
@@ -118,11 +123,19 @@ export function headChange(held) {
|
|
|
118
123
|
const author = held.author === undefined ? null : changeAuthor(held.author);
|
|
119
124
|
if (held.author !== undefined && author === null)
|
|
120
125
|
return null;
|
|
121
|
-
if (held.
|
|
126
|
+
if (held.changed_at === undefined)
|
|
122
127
|
return undefined;
|
|
123
|
-
if (typeof held.
|
|
128
|
+
if (typeof held.changed_at !== 'string')
|
|
124
129
|
return null;
|
|
125
|
-
return { author, time: held.
|
|
130
|
+
return { author, time: held.changed_at };
|
|
131
|
+
}
|
|
132
|
+
export function createdOf(held) {
|
|
133
|
+
if (held.created_at === undefined)
|
|
134
|
+
return undefined;
|
|
135
|
+
return typeof held.created_at === 'string' ? held.created_at : null;
|
|
136
|
+
}
|
|
137
|
+
function createdHeld(created) {
|
|
138
|
+
return created === undefined ? {} : { created };
|
|
126
139
|
}
|
|
127
140
|
function headed(head) {
|
|
128
141
|
return head === undefined ? {} : { head };
|
|
@@ -138,15 +151,22 @@ export function binaryFileOf(held) {
|
|
|
138
151
|
function binaried(binary) {
|
|
139
152
|
return binary === undefined ? {} : { binary };
|
|
140
153
|
}
|
|
141
|
-
function
|
|
154
|
+
export function carriedFacts(held) {
|
|
155
|
+
return held.facts === undefined ? {} : { facts: held.facts };
|
|
156
|
+
}
|
|
157
|
+
function carriedSpace(held) {
|
|
158
|
+
return typeof held.space === 'string' ? { space: held.space } : {};
|
|
159
|
+
}
|
|
160
|
+
export function parseFile(value, mode) {
|
|
142
161
|
if (typeof value !== 'object' || value === null)
|
|
143
162
|
return null;
|
|
144
163
|
const file = value;
|
|
145
164
|
if (typeof file.path !== 'string')
|
|
146
165
|
return null;
|
|
147
166
|
const head = headChange(file);
|
|
167
|
+
const created = createdOf(file);
|
|
148
168
|
const binary = binaryFileOf(file);
|
|
149
|
-
if (head === null || binary === null)
|
|
169
|
+
if (head === null || created === null || binary === null)
|
|
150
170
|
return null;
|
|
151
171
|
if (mode === 'site') {
|
|
152
172
|
if (typeof file.sha256 !== 'string')
|
|
@@ -157,6 +177,7 @@ function parseFile(value, mode) {
|
|
|
157
177
|
version: file.sha256,
|
|
158
178
|
...headed(head),
|
|
159
179
|
...binaried(binary),
|
|
180
|
+
...carriedFacts(file),
|
|
160
181
|
};
|
|
161
182
|
}
|
|
162
183
|
if (typeof file.revision !== 'string')
|
|
@@ -167,288 +188,19 @@ function parseFile(value, mode) {
|
|
|
167
188
|
version: file.revision,
|
|
168
189
|
...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
|
|
169
190
|
...headed(head),
|
|
191
|
+
...createdHeld(created),
|
|
170
192
|
...binaried(binary),
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
function parseModels(value, mode) {
|
|
174
|
-
if (!Array.isArray(value))
|
|
175
|
-
return null;
|
|
176
|
-
const files = [];
|
|
177
|
-
const contents = [];
|
|
178
|
-
for (const entry of value) {
|
|
179
|
-
const file = parseFile(entry, mode);
|
|
180
|
-
const { content } = entry;
|
|
181
|
-
if (file === null || typeof content !== 'string')
|
|
182
|
-
return null;
|
|
183
|
-
files.push(file);
|
|
184
|
-
contents.push({ path: file.path, content });
|
|
185
|
-
}
|
|
186
|
-
return { files, contents };
|
|
187
|
-
}
|
|
188
|
-
function parseRoomHead(value, mode) {
|
|
189
|
-
if (typeof value !== 'object' || value === null)
|
|
190
|
-
return null;
|
|
191
|
-
const held = value;
|
|
192
|
-
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
193
|
-
return null;
|
|
194
|
-
const models = parseModels(held.models, mode);
|
|
195
|
-
if (models === null)
|
|
196
|
-
return null;
|
|
197
|
-
const manifest = held.manifest;
|
|
198
|
-
if (manifest.scope !== 'room')
|
|
199
|
-
return null;
|
|
200
|
-
const at = readPosition(manifest);
|
|
201
|
-
if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
|
|
202
|
-
return null;
|
|
203
|
-
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
204
|
-
return null;
|
|
205
|
-
return { anchor: manifest.anchor, ...at, models };
|
|
206
|
-
}
|
|
207
|
-
export async function roomHead(payload, mode) {
|
|
208
|
-
let text = '';
|
|
209
|
-
try {
|
|
210
|
-
for await (const chunk of gunzipped(payload))
|
|
211
|
-
text += chunk;
|
|
212
|
-
return text.endsWith('\n') && text.indexOf('\n') === text.length - 1
|
|
213
|
-
? parseRoomHead(JSON.parse(text), mode)
|
|
214
|
-
: null;
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
217
|
-
return null;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
export function manifested(room, pageToken, models) {
|
|
221
|
-
return {
|
|
222
|
-
kind: 'bootstrap',
|
|
223
|
-
roomVersion: roomVersion(room),
|
|
224
|
-
documents: {},
|
|
225
|
-
revisions: {},
|
|
226
|
-
changes: {},
|
|
227
|
-
binaryFiles: {},
|
|
228
|
-
pageToken,
|
|
229
|
-
...(models === undefined ? {} : { models }),
|
|
193
|
+
...carriedFacts(file),
|
|
194
|
+
...carriedSpace(file),
|
|
230
195
|
};
|
|
231
196
|
}
|
|
232
197
|
export function modelScope(room) {
|
|
233
|
-
return { ...emptyScope(room), files: room.models.files, contents: room.models.contents };
|
|
234
|
-
}
|
|
235
|
-
export function emptyScope(room) {
|
|
236
198
|
return {
|
|
237
199
|
anchor: room.anchor,
|
|
238
200
|
position: room.position,
|
|
239
201
|
logEpoch: room.logEpoch,
|
|
240
|
-
files:
|
|
241
|
-
contents:
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
function partLine(line, mode, read) {
|
|
245
|
-
if (read.ended)
|
|
246
|
-
return false;
|
|
247
|
-
let entry;
|
|
248
|
-
try {
|
|
249
|
-
entry = JSON.parse(line);
|
|
250
|
-
}
|
|
251
|
-
catch {
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
if (endLine(entry)) {
|
|
255
|
-
read.ended = true;
|
|
256
|
-
return true;
|
|
257
|
-
}
|
|
258
|
-
if (folderLine(entry)) {
|
|
259
|
-
read.folders.push(entry.folder);
|
|
260
|
-
return true;
|
|
261
|
-
}
|
|
262
|
-
const file = parseFile(entry, mode);
|
|
263
|
-
if (file === null)
|
|
264
|
-
return false;
|
|
265
|
-
read.files.push(file);
|
|
266
|
-
const { content } = entry;
|
|
267
|
-
if (typeof content === 'string')
|
|
268
|
-
read.contents.push({ path: file.path, content });
|
|
269
|
-
else if (content !== undefined)
|
|
270
|
-
return false;
|
|
271
|
-
return true;
|
|
272
|
-
}
|
|
273
|
-
async function partRead(chunks, mode) {
|
|
274
|
-
const read = { files: [], contents: [], folders: [], ended: false };
|
|
275
|
-
const pace = paced();
|
|
276
|
-
const unfinished = [];
|
|
277
|
-
for (let chunk = await chunks.read(); chunk.done !== true; chunk = await chunks.read()) {
|
|
278
|
-
const text = chunk.value;
|
|
279
|
-
let start = 0;
|
|
280
|
-
for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
|
|
281
|
-
const piece = text.slice(start, end);
|
|
282
|
-
const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
|
|
283
|
-
if (!partLine(line, mode, read)) {
|
|
284
|
-
await chunks.cancel();
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
start = end + 1;
|
|
288
|
-
const due = pace(line.length + ROW_WEIGHT);
|
|
289
|
-
if (due instanceof Promise)
|
|
290
|
-
await due;
|
|
291
|
-
}
|
|
292
|
-
if (start < text.length)
|
|
293
|
-
unfinished.push(text.slice(start));
|
|
294
|
-
}
|
|
295
|
-
return unfinished.length === 0 ? read : null;
|
|
296
|
-
}
|
|
297
|
-
function endLine(entry) {
|
|
298
|
-
if (typeof entry !== 'object' || entry === null || !('end' in entry))
|
|
299
|
-
return false;
|
|
300
|
-
return entry.end === true && Object.keys(entry).length === 1;
|
|
301
|
-
}
|
|
302
|
-
function folderLine(entry) {
|
|
303
|
-
if (typeof entry !== 'object' || entry === null || !('folder' in entry))
|
|
304
|
-
return false;
|
|
305
|
-
return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
|
|
306
|
-
}
|
|
307
|
-
export async function housePart(room, payload, mode) {
|
|
308
|
-
const read = await partRead(gunzipped(payload).getReader(), mode).catch(() => null);
|
|
309
|
-
if (read === null)
|
|
310
|
-
return { kind: 'transport-uncertainty' };
|
|
311
|
-
const { ended, ...scope } = read;
|
|
312
|
-
return { scope: { ...emptyScope(room), ...scope }, ended };
|
|
313
|
-
}
|
|
314
|
-
function folderChange(value) {
|
|
315
|
-
if (typeof value !== 'object' || value === null)
|
|
316
|
-
return null;
|
|
317
|
-
const { path, folder, removed, ...rest } = value;
|
|
318
|
-
return typeof path === 'string' &&
|
|
319
|
-
folder === true &&
|
|
320
|
-
(removed === undefined || removed === true) &&
|
|
321
|
-
Object.keys(rest).length === 0
|
|
322
|
-
? { path, removed: removed === true }
|
|
323
|
-
: null;
|
|
324
|
-
}
|
|
325
|
-
function parseChange(value, mode) {
|
|
326
|
-
if (typeof value !== 'object' || value === null)
|
|
327
|
-
return null;
|
|
328
|
-
const held = value;
|
|
329
|
-
if (typeof held.path !== 'string')
|
|
330
|
-
return null;
|
|
331
|
-
if (held.removed === true)
|
|
332
|
-
return { path: held.path, removed: true };
|
|
333
|
-
const head = headChange(held);
|
|
334
|
-
const binary = binaryFileOf(held);
|
|
335
|
-
if (head === null || binary === null)
|
|
336
|
-
return null;
|
|
337
|
-
if (binary !== undefined) {
|
|
338
|
-
if (mode === 'credential' && typeof held.revision !== 'string')
|
|
339
|
-
return null;
|
|
340
|
-
const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
|
|
341
|
-
return { path: held.path, binary, revision, version: revision, ...headed(head) };
|
|
342
|
-
}
|
|
343
|
-
if (mode === 'site') {
|
|
344
|
-
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
345
|
-
return null;
|
|
346
|
-
return {
|
|
347
|
-
path: held.path,
|
|
348
|
-
content: held.content,
|
|
349
|
-
revision: undefined,
|
|
350
|
-
version: held.sha256,
|
|
351
|
-
...headed(head),
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
if (typeof held.content === 'string' && typeof held.revision === 'string') {
|
|
355
|
-
return {
|
|
356
|
-
path: held.path,
|
|
357
|
-
content: held.content,
|
|
358
|
-
revision: held.revision,
|
|
359
|
-
version: held.revision,
|
|
360
|
-
...headed(head),
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
365
|
-
export function parseEnumeration(body, mode) {
|
|
366
|
-
if (typeof body !== 'object' || body === null)
|
|
367
|
-
return null;
|
|
368
|
-
if (!('authorities' in body) || !Array.isArray(body.authorities))
|
|
369
|
-
return null;
|
|
370
|
-
const authorities = [];
|
|
371
|
-
for (const entry of body.authorities) {
|
|
372
|
-
if (typeof entry !== 'object' || entry === null)
|
|
373
|
-
return null;
|
|
374
|
-
const held = entry;
|
|
375
|
-
const at = readPosition(held);
|
|
376
|
-
if (typeof held.authority !== 'string' || at === null)
|
|
377
|
-
return null;
|
|
378
|
-
if (!Array.isArray(held.changes))
|
|
379
|
-
return null;
|
|
380
|
-
const changes = [];
|
|
381
|
-
const folders = [];
|
|
382
|
-
for (const change of held.changes) {
|
|
383
|
-
const folder = folderChange(change);
|
|
384
|
-
if (folder !== null) {
|
|
385
|
-
folders.push(folder);
|
|
386
|
-
continue;
|
|
387
|
-
}
|
|
388
|
-
const mapped = parseChange(change, mode);
|
|
389
|
-
if (mapped === null)
|
|
390
|
-
return null;
|
|
391
|
-
changes.push(mapped);
|
|
392
|
-
}
|
|
393
|
-
const next = held.next === undefined ? undefined : readPage(held.next);
|
|
394
|
-
if (next === null)
|
|
395
|
-
return null;
|
|
396
|
-
authorities.push({
|
|
397
|
-
authority: held.authority,
|
|
398
|
-
...at,
|
|
399
|
-
changes,
|
|
400
|
-
...(folders.length === 0 ? {} : { folders }),
|
|
401
|
-
...(next === undefined ? {} : { next }),
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
return { authorities };
|
|
405
|
-
}
|
|
406
|
-
function readPage(held) {
|
|
407
|
-
if (typeof held !== 'object' || held === null)
|
|
408
|
-
return null;
|
|
409
|
-
const { after, through, read } = held;
|
|
410
|
-
if (typeof after !== 'string' || !DECIMAL.test(after))
|
|
411
|
-
return null;
|
|
412
|
-
if (typeof through !== 'string' || !DECIMAL.test(through))
|
|
413
|
-
return null;
|
|
414
|
-
if (typeof read !== 'number' || !Number.isSafeInteger(read) || read < 0)
|
|
415
|
-
return null;
|
|
416
|
-
return { after, through, read };
|
|
417
|
-
}
|
|
418
|
-
function advances(asked, next) {
|
|
419
|
-
const moved = BigInt(next.through) - BigInt(asked.through);
|
|
420
|
-
return moved > 0n || (moved === 0n && next.after === asked.after && next.read > asked.read);
|
|
421
|
-
}
|
|
422
|
-
export async function wholeView(first, more) {
|
|
423
|
-
const changes = new Map(first.changes.map((change) => [change.path, change]));
|
|
424
|
-
const folders = new Map((first.folders ?? []).map((folder) => [folder.path, folder]));
|
|
425
|
-
let view = first;
|
|
426
|
-
while (view.next !== undefined) {
|
|
427
|
-
const asked = view.next;
|
|
428
|
-
const page = await more(asked);
|
|
429
|
-
if ('kind' in page)
|
|
430
|
-
return page;
|
|
431
|
-
if (page.position !== asked.through ||
|
|
432
|
-
page.logEpoch !== first.logEpoch ||
|
|
433
|
-
(page.next !== undefined && !advances(asked, page.next))) {
|
|
434
|
-
return { kind: 'transport-uncertainty' };
|
|
435
|
-
}
|
|
436
|
-
for (const change of page.changes) {
|
|
437
|
-
changes.delete(change.path);
|
|
438
|
-
changes.set(change.path, change);
|
|
439
|
-
}
|
|
440
|
-
for (const folder of page.folders ?? []) {
|
|
441
|
-
folders.delete(folder.path);
|
|
442
|
-
folders.set(folder.path, folder);
|
|
443
|
-
}
|
|
444
|
-
view = page;
|
|
445
|
-
}
|
|
446
|
-
return {
|
|
447
|
-
authority: first.authority,
|
|
448
|
-
position: view.position,
|
|
449
|
-
logEpoch: first.logEpoch,
|
|
450
|
-
changes: [...changes.values()],
|
|
451
|
-
...(folders.size === 0 ? {} : { folders: [...folders.values()] }),
|
|
202
|
+
files: room.models.files,
|
|
203
|
+
contents: room.models.contents,
|
|
452
204
|
};
|
|
453
205
|
}
|
|
454
206
|
export function* bootstrapping(scope) {
|
|
@@ -460,13 +212,19 @@ export function* bootstrapping(scope) {
|
|
|
460
212
|
const answer = answering();
|
|
461
213
|
for (const file of scope.files) {
|
|
462
214
|
yield ROW_WEIGHT;
|
|
215
|
+
if (file.space !== undefined)
|
|
216
|
+
continue;
|
|
463
217
|
if (file.head !== undefined)
|
|
464
218
|
answer.changes.set(file.path, file.head);
|
|
219
|
+
if (file.created !== undefined)
|
|
220
|
+
answer.created.set(file.path, file.created);
|
|
465
221
|
const content = contents.get(file.path);
|
|
466
222
|
if (file.binary !== undefined)
|
|
467
223
|
answer.binaryFiles.set(file.path, file.binary);
|
|
468
224
|
else if (content !== undefined)
|
|
469
225
|
answer.documents.set(file.path, content);
|
|
226
|
+
if (file.binary === undefined && file.facts !== undefined)
|
|
227
|
+
answer.facts.set(file.path, file.facts);
|
|
470
228
|
if (file.revision !== undefined)
|
|
471
229
|
revised(answer, file.path, file.revision);
|
|
472
230
|
}
|
|
@@ -482,36 +240,10 @@ export function schemaOf(scope, schema) {
|
|
|
482
240
|
const content = scope.contents.find((entry) => entry.path === schema);
|
|
483
241
|
return content === undefined
|
|
484
242
|
? null
|
|
485
|
-
: {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
if (roomVersion(view) === fromRoomVersion)
|
|
492
|
-
return { kind: 'still-current' };
|
|
493
|
-
const answer = answering();
|
|
494
|
-
for (const change of view.changes) {
|
|
495
|
-
yield ROW_WEIGHT;
|
|
496
|
-
if ('removed' in change) {
|
|
497
|
-
answer.removals.add(change.path);
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
if ('content' in change)
|
|
501
|
-
answer.documents.set(change.path, change.content);
|
|
502
|
-
else
|
|
503
|
-
answer.binaryFiles.set(change.path, change.binary);
|
|
504
|
-
if (change.head !== undefined)
|
|
505
|
-
answer.changes.set(change.path, change.head);
|
|
506
|
-
if (change.revision !== undefined)
|
|
507
|
-
revised(answer, change.path, change.revision);
|
|
508
|
-
}
|
|
509
|
-
for (const folder of view.folders ?? []) {
|
|
510
|
-
yield ROW_WEIGHT;
|
|
511
|
-
folded(answer, folder.path, folder.removed);
|
|
512
|
-
}
|
|
513
|
-
return { kind: 'net-advancement', roomVersion: roomVersion(view), ...(yield* answered(answer)) };
|
|
514
|
-
}
|
|
515
|
-
export async function refreshFrom(view, fromRoomVersion) {
|
|
516
|
-
return stepped(refreshing(view, fromRoomVersion));
|
|
243
|
+
: {
|
|
244
|
+
schema: content.content,
|
|
245
|
+
version: file.version,
|
|
246
|
+
revision: file.revision ?? null,
|
|
247
|
+
...(file.space === undefined ? {} : { space: file.space }),
|
|
248
|
+
};
|
|
517
249
|
}
|
package/dist/refusal.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
|
|
1
|
+
import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal, TransportUncertainty } from '@agentshouse/mdruntime';
|
|
2
2
|
export declare function doorRefusal(body: unknown): ProviderRefusal | null;
|
|
3
|
+
export declare function answeredFailure(status: number, body: unknown): TransportUncertainty;
|
|
4
|
+
export declare function resetOf(refusal: ProviderRefusal | null): string | undefined;
|
|
3
5
|
export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
|
|
4
6
|
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
|
|
5
|
-
export declare function classifyRead(status: number, body: unknown, locator: string): AdapterFailure | {
|
|
6
|
-
kind: 'beyond-horizon';
|
|
7
|
-
} | null;
|
|
8
7
|
export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
|
|
9
|
-
//# sourceMappingURL=refusal.d.ts.map
|
package/dist/refusal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,
|
|
1
|
+
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACb,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAGhC,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAOjE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,oBAAoB,CAInF;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,GAAG,SAAS,CAG3E;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,eAAe,GACvB,aAAa,CAEf;AAoBD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG,IAAI,CAMvB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAQrF"}
|
package/dist/refusal.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { refusedFor, UNANSWERED, unusable } from './uncertain.js';
|
|
1
2
|
export function doorRefusal(body) {
|
|
2
3
|
if (typeof body !== 'object' || body === null)
|
|
3
4
|
return null;
|
|
@@ -9,24 +10,33 @@ export function doorRefusal(body) {
|
|
|
9
10
|
const { code, retryable, ...fields } = error;
|
|
10
11
|
return { code, fields, retryable: retryable === true };
|
|
11
12
|
}
|
|
13
|
+
export function answeredFailure(status, body) {
|
|
14
|
+
const refusal = doorRefusal(body);
|
|
15
|
+
if (refusal !== null)
|
|
16
|
+
return refusedFor(refusal);
|
|
17
|
+
return status === 0 || (status >= 500 && body === null) ? UNANSWERED : unusable();
|
|
18
|
+
}
|
|
19
|
+
export function resetOf(refusal) {
|
|
20
|
+
const reset = refusal?.fields.retry_at;
|
|
21
|
+
return refusal?.retryable === true && typeof reset === 'string' ? reset : undefined;
|
|
22
|
+
}
|
|
12
23
|
export function scopedRefusal(locator, scope, refusal) {
|
|
13
24
|
return { kind: 'scoped-refusal', locator, scope, ...refusal };
|
|
14
25
|
}
|
|
15
26
|
function doorFailure(status, body) {
|
|
16
27
|
if (status === 0)
|
|
17
|
-
return
|
|
18
|
-
const refusal = doorRefusal(body);
|
|
28
|
+
return UNANSWERED;
|
|
19
29
|
if (status === 401)
|
|
20
30
|
return { kind: 'revoked-authorization' };
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
const refusal = doorRefusal(body);
|
|
32
|
+
if (refusal?.retryable === true || refusal?.code === 'update_required')
|
|
33
|
+
return refusedFor(refusal);
|
|
24
34
|
if (status === 404 || refusal?.code === 'room_not_found')
|
|
25
35
|
return { kind: 'room-not-readable' };
|
|
26
36
|
if (status < 400)
|
|
27
37
|
return null;
|
|
28
38
|
if (refusal === null)
|
|
29
|
-
return
|
|
39
|
+
return answeredFailure(status, body);
|
|
30
40
|
return { kind: 'refused', scope: status === 403 ? 'operation' : 'undisclosed', refusal };
|
|
31
41
|
}
|
|
32
42
|
export function classifyDoor(status, body, locator) {
|
|
@@ -39,11 +49,6 @@ export function classifyDoor(status, body, locator) {
|
|
|
39
49
|
return scopedRefusal(locator, failure.scope, failure.refusal);
|
|
40
50
|
return failure;
|
|
41
51
|
}
|
|
42
|
-
export function classifyRead(status, body, locator) {
|
|
43
|
-
if (doorRefusal(body)?.code === 'expired')
|
|
44
|
-
return { kind: 'beyond-horizon' };
|
|
45
|
-
return classifyDoor(status, body, locator);
|
|
46
|
-
}
|
|
47
52
|
export function discoveryFailure(status, body) {
|
|
48
53
|
const failure = doorFailure(status, body);
|
|
49
54
|
if (failure === null)
|
|
@@ -53,5 +58,5 @@ export function discoveryFailure(status, body) {
|
|
|
53
58
|
if (failure.kind === 'refused') {
|
|
54
59
|
return { kind: 'contract-unavailable', ...failure.refusal };
|
|
55
60
|
}
|
|
56
|
-
return
|
|
61
|
+
return failure.kind === 'transport-uncertainty' ? failure : answeredFailure(status, body);
|
|
57
62
|
}
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SearchAnswer, SearchAsk } from '@agentshouse/mdruntime';
|
|
2
|
+
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
+
import { type HouseTransport } from './transport.js';
|
|
4
|
+
export declare function houseSearch(transport: Pick<HouseTransport, 'door'>, tracked: readonly TrackedAuthority[], request: SearchAsk): Promise<SearchAnswer>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAa,MAAM,wBAAwB,CAAC;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAoBrE,wBAAsB,WAAW,CAC/B,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,EACvC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EACpC,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,YAAY,CAAC,CAsBvB"}
|
package/dist/search.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { answeredFailure, doorRefusal } from './refusal.js';
|
|
2
|
+
import { houseDoorRoute } from './transport.js';
|
|
3
|
+
const ROOMS = '/rooms/';
|
|
4
|
+
function hitOf(file, locators) {
|
|
5
|
+
if (typeof file !== 'object' || file === null)
|
|
6
|
+
return null;
|
|
7
|
+
const { path, line, snippet } = file;
|
|
8
|
+
if (typeof path !== 'string' || !path.startsWith(ROOMS))
|
|
9
|
+
return null;
|
|
10
|
+
const slash = path.indexOf('/', ROOMS.length);
|
|
11
|
+
if (slash < 0)
|
|
12
|
+
return null;
|
|
13
|
+
const room = locators.get(path.slice(ROOMS.length, slash));
|
|
14
|
+
if (room === undefined)
|
|
15
|
+
return null;
|
|
16
|
+
return {
|
|
17
|
+
room,
|
|
18
|
+
path: path.slice(slash + 1),
|
|
19
|
+
...(typeof line === 'number' ? { line } : {}),
|
|
20
|
+
...(typeof snippet === 'string' ? { snippet } : {}),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export async function houseSearch(transport, tracked, request) {
|
|
24
|
+
const named = request.rooms === null
|
|
25
|
+
? null
|
|
26
|
+
: tracked.filter((entry) => request.rooms.includes(entry.locator));
|
|
27
|
+
if (named !== null && named.length === 0)
|
|
28
|
+
return { kind: 'found', documents: [] };
|
|
29
|
+
const answer = await transport.door(houseDoorRoute('rooms/search'), {
|
|
30
|
+
query: request.text,
|
|
31
|
+
...(named === null ? {} : { paths: named.map((entry) => `${ROOMS}${entry.handle}`) }),
|
|
32
|
+
});
|
|
33
|
+
if (answer.status === 401)
|
|
34
|
+
return { kind: 'revoked-authorization' };
|
|
35
|
+
const refusal = doorRefusal(answer.body);
|
|
36
|
+
if (refusal !== null)
|
|
37
|
+
return { kind: 'rejected', ...refusal };
|
|
38
|
+
const files = answer.body?.files;
|
|
39
|
+
if (answer.status !== 200 || !Array.isArray(files)) {
|
|
40
|
+
return answeredFailure(answer.status, answer.body);
|
|
41
|
+
}
|
|
42
|
+
const locators = new Map(tracked.map((entry) => [entry.handle, entry.locator]));
|
|
43
|
+
return {
|
|
44
|
+
kind: 'found',
|
|
45
|
+
documents: files.flatMap((file) => hitOf(file, locators) ?? []),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const OUTPUT_LINES = 20;
|
|
2
|
+
export declare const OUTPUT_CHARACTERS = 4000;
|
|
3
|
+
export declare const DIFF_CHARACTERS = 10000;
|
|
4
|
+
export declare const FIRST_PART_CHARACTERS = 2000;
|
|
5
|
+
export declare function lastLines(output: string): string;
|
|
6
|
+
export declare function firstPart(result: string): string;
|
|
7
|
+
export declare function keptDiff(diff: string): string | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Check<T> = (value: unknown) => value is T;
|
|
2
|
+
export type Checked<C> = C extends Check<infer T> ? T : never;
|
|
3
|
+
type Shape = Readonly<Record<string, Check<unknown>>>;
|
|
4
|
+
export type Shaped<S extends Shape> = {
|
|
5
|
+
readonly [K in keyof S]: Checked<S[K]>;
|
|
6
|
+
};
|
|
7
|
+
export declare const text: Check<string>;
|
|
8
|
+
export declare const integer: Check<number>;
|
|
9
|
+
export declare const count: Check<number>;
|
|
10
|
+
export declare const figure: Check<number>;
|
|
11
|
+
export declare const instant: Check<string>;
|
|
12
|
+
export declare function oneOf<const V extends readonly string[]>(...values: V): Check<V[number]>;
|
|
13
|
+
export declare function where<T>(check: Check<T>, holds: (value: T) => boolean): Check<T>;
|
|
14
|
+
export declare function nullable<T>(check: Check<T>): Check<T | null>;
|
|
15
|
+
export declare function list<T>(check: Check<T>): Check<readonly T[]>;
|
|
16
|
+
export declare function exact<const S extends Shape>(shape: S): Check<Shaped<S>>;
|
|
17
|
+
export declare function anyOf<const C extends readonly Check<unknown>[]>(...checks: C): Check<Checked<C[number]>>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DIFF_CHARACTERS, FIRST_PART_CHARACTERS, firstPart, keptDiff, lastLines, OUTPUT_CHARACTERS, OUTPUT_LINES, } from './bounds.js';
|
|
2
|
+
export { isOwn, isPart } from './parts.js';
|
|
3
|
+
export type { Call, FileChange, Part, PartOf, Status } from './parts.js';
|
|
4
|
+
export { isState, standingState } from './state.js';
|
|
5
|
+
export type { SessionState, Tokens } from './state.js';
|
|
6
|
+
export { applied, isOperation, isTurn } from './turn.js';
|
|
7
|
+
export type { Operation, Turn } from './turn.js';
|