@agentshouse/mdruntime-adapter 0.1.0-c51fa73c21cdb → 0.1.0-c521df53d1a45
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 +3 -27
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +14 -108
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +134 -108
- package/dist/app-reference.d.ts +2 -0
- package/dist/app-reference.d.ts.map +1 -0
- package/dist/app-reference.js +2 -0
- package/dist/crockford.d.ts +4 -0
- package/dist/crockford.d.ts.map +1 -0
- package/dist/crockford.js +3 -0
- package/dist/digest.d.ts +1 -1
- package/dist/digest.d.ts.map +1 -1
- package/dist/digest.js +1 -1
- package/dist/discovery.d.ts +3 -8
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +11 -24
- package/dist/house-model.d.ts +2 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +484 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/model.d.ts +5 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +11 -13
- package/dist/part.d.ts +4 -2
- package/dist/part.d.ts.map +1 -1
- package/dist/part.js +15 -13
- package/dist/read.d.ts +22 -3
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +157 -92
- package/dist/room-types.d.ts +2 -1
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +93 -3
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +47 -56
- package/dist/stream.d.ts +1 -0
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +17 -2
- package/dist/transport.d.ts +11 -10
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +2 -1
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -0
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +2 -13
- package/package.json +8 -4
- package/AGENTS.md +0 -304
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -45
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -33
package/dist/adapter.js
CHANGED
|
@@ -1,62 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { stepped } from '@agentshouse/mdruntime';
|
|
2
2
|
import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
|
|
3
|
-
import { partModels, streamedModels, viewModels } from './model.js';
|
|
3
|
+
import { manifestedModels, partModels, streamedModels, viewModels } from './model.js';
|
|
4
4
|
import { gathered, gatheredEach, selections } from './gather.js';
|
|
5
5
|
import { createSiteAdapter } from './site.js';
|
|
6
|
-
import { authorityRoot, bootstrapping, emptyScope, housePart, parseEnumeration, parseFileAddress, parseGrant, parseParted, refreshFrom, viewOf, wholeView, } from './read.js';
|
|
7
|
-
import { PART_ATTEMPTS, unverifiedPart } from './part.js';
|
|
6
|
+
import { authorityRoot, bootstrapping, emptyScope, housePart, manifested, parseEnumeration, parseFileAddress, parseGrant, parseParted, partInventory, refreshFrom, viewOf, wholeView, } from './read.js';
|
|
7
|
+
import { PART_ATTEMPTS, partArrival, partFrame, unverifiedPart } from './part.js';
|
|
8
8
|
import { sha256Hex } from './digest.js';
|
|
9
|
-
import {
|
|
9
|
+
import { finishedUpload, houseUpload } from './upload.js';
|
|
10
10
|
import { houseAction } from './actions.js';
|
|
11
11
|
import { classifyDoor, classifyRead, discoveryFailure, doorRefusal } from './refusal.js';
|
|
12
12
|
import { houseNotifications } from './stream.js';
|
|
13
|
-
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
|
|
13
|
+
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_ATTACH, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
|
|
14
14
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
15
|
-
import {
|
|
16
|
-
import { HOUSE_ROOM_TYPES } from './room-types.js';
|
|
15
|
+
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
17
16
|
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
18
17
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
19
18
|
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
19
|
+
const OCTET_STREAM = 'application/octet-stream';
|
|
20
20
|
const EXPIRED_ADDRESS = 403;
|
|
21
21
|
function lapsedGrant(outcome) {
|
|
22
22
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
return known;
|
|
29
|
-
const sorted = await stepped(sortedKeys(held.documents));
|
|
30
|
-
heldPaths.set(held.documents, sorted);
|
|
31
|
-
return sorted;
|
|
32
|
-
}
|
|
33
|
-
function heldFiles(authority, held, paths, bound) {
|
|
34
|
-
const files = [];
|
|
35
|
-
let through = null;
|
|
36
|
-
for (let at = 0; at < paths.length && through === null; at += 1) {
|
|
37
|
-
const revision = held.revisions[paths[at]];
|
|
38
|
-
if (revision === undefined)
|
|
39
|
-
continue;
|
|
40
|
-
if (files.length === bound)
|
|
41
|
-
through = files.at(-1).path;
|
|
42
|
-
else
|
|
43
|
-
files.push({ path: paths[at], revision });
|
|
44
|
-
}
|
|
24
|
+
async function heldFiles(authority, held, bound) {
|
|
25
|
+
const listed = await held.files(null, bound + 1);
|
|
26
|
+
const files = listed.slice(0, bound);
|
|
27
|
+
const through = listed.length > bound ? (files.at(-1)?.path ?? null) : null;
|
|
45
28
|
return files.length === 0 ? null : { room: authority, through, files };
|
|
46
29
|
}
|
|
47
30
|
async function reused(scope, held) {
|
|
48
31
|
const sent = new Set(scope.contents.map((entry) => entry.path));
|
|
49
32
|
const contents = [...scope.contents];
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
33
|
+
const asked = scope.files.filter((file) => file.binary === undefined && !sent.has(file.path));
|
|
34
|
+
if (asked.length === 0)
|
|
35
|
+
return scope;
|
|
36
|
+
if (held === undefined)
|
|
37
|
+
return null;
|
|
38
|
+
const kept = await held.contents(asked.map(({ path }) => path));
|
|
39
|
+
for (const file of asked) {
|
|
40
|
+
const found = kept.get(file.path);
|
|
41
|
+
if (found === undefined ||
|
|
42
|
+
found.revision !== file.revision ||
|
|
43
|
+
(await sha256Hex(found.content)) !== file.sha256) {
|
|
57
44
|
return null;
|
|
58
45
|
}
|
|
59
|
-
contents.push({ path: file.path, content });
|
|
46
|
+
contents.push({ path: file.path, content: found.content });
|
|
60
47
|
}
|
|
61
48
|
return { ...scope, contents };
|
|
62
49
|
}
|
|
@@ -67,51 +54,56 @@ export function createAgentsHouseAdapter(options) {
|
|
|
67
54
|
const notifications = houseNotifications(transport, 'credential');
|
|
68
55
|
const tracked = new Map();
|
|
69
56
|
const handed = new Map();
|
|
57
|
+
let heldRevisions;
|
|
70
58
|
let bounds;
|
|
71
59
|
function declared() {
|
|
72
60
|
if (bounds === undefined)
|
|
73
61
|
throw new Error('no Discovery declared the bounds');
|
|
74
62
|
return bounds;
|
|
75
63
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
64
|
+
async function fetchedPart(entry, continued, listed, received, arriving) {
|
|
65
|
+
if (received !== undefined) {
|
|
66
|
+
const kept = new Uint8Array(received);
|
|
67
|
+
const held = await housePart(continued.room, kept, listed, 'credential');
|
|
68
|
+
if (held !== null)
|
|
69
|
+
return 'kind' in held ? held : { scope: held, frame: kept };
|
|
82
70
|
}
|
|
83
|
-
return next.then((room) => {
|
|
84
|
-
if (handed.get(locator) === held)
|
|
85
|
-
handed.set(locator, room);
|
|
86
|
-
else
|
|
87
|
-
handed.delete(locator);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
async function fetchedPart(entry, continued, listed) {
|
|
91
71
|
for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
|
|
92
72
|
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
93
73
|
prefixes: [authorityRoot(entry.handle)],
|
|
94
74
|
part: listed.part,
|
|
95
75
|
...(continued.held === undefined ? {} : { held: [continued.held] }),
|
|
96
|
-
});
|
|
76
|
+
}, partArrival(listed, arriving));
|
|
97
77
|
const failure = classifyRead(answered.status, answered.body, entry.locator);
|
|
98
78
|
if (failure !== null)
|
|
99
79
|
return failure;
|
|
100
|
-
const
|
|
80
|
+
const frame = partFrame(answered.body);
|
|
81
|
+
if (frame === null)
|
|
82
|
+
continue;
|
|
83
|
+
const scope = await housePart(continued.room, frame, listed, 'credential');
|
|
101
84
|
if (scope !== null)
|
|
102
|
-
return scope;
|
|
85
|
+
return 'kind' in scope ? scope : { scope, frame };
|
|
103
86
|
}
|
|
104
87
|
return unverifiedPart(entry.locator);
|
|
105
88
|
}
|
|
106
|
-
async function
|
|
89
|
+
async function manifestPage(asked, continued) {
|
|
90
|
+
const inventory = partInventory(continued.room);
|
|
91
|
+
if (inventory.parts === 0) {
|
|
92
|
+
const page = await partPage(asked, continued, undefined, undefined);
|
|
93
|
+
return page.kind === 'bootstrap' ? { ...page, inventory } : page;
|
|
94
|
+
}
|
|
95
|
+
const { models, seen } = await manifestedModels(continued.room, asked.entry);
|
|
96
|
+
return manifested(continued.room, inventory, JSON.stringify({ ...continued, seen }), models);
|
|
97
|
+
}
|
|
98
|
+
async function partPage(asked, continued, received, arriving) {
|
|
107
99
|
const { entry } = asked;
|
|
108
100
|
const listed = continued.room.parts[continued.next];
|
|
109
101
|
const sent = listed === undefined
|
|
110
|
-
? emptyScope(continued.room)
|
|
111
|
-
: await fetchedPart(entry, continued, listed);
|
|
102
|
+
? { scope: emptyScope(continued.room), frame: null }
|
|
103
|
+
: await fetchedPart(entry, continued, listed, received, arriving);
|
|
112
104
|
if ('kind' in sent)
|
|
113
105
|
return sent;
|
|
114
|
-
const scope = await reused(sent, asked.held);
|
|
106
|
+
const scope = await reused(sent.scope, asked.held);
|
|
115
107
|
if (scope === null) {
|
|
116
108
|
return asked.held === undefined
|
|
117
109
|
? UNCERTAIN_READ
|
|
@@ -120,19 +112,20 @@ export function createAgentsHouseAdapter(options) {
|
|
|
120
112
|
const next = continued.next + 1;
|
|
121
113
|
const more = next < continued.room.parts.length;
|
|
122
114
|
if (continued.next === 0 && !more)
|
|
123
|
-
|
|
115
|
+
handed.set(entry.locator, roomVersion(scope));
|
|
124
116
|
else
|
|
125
117
|
handed.delete(entry.locator);
|
|
126
118
|
notifications.reach(entry.authority, scope);
|
|
127
119
|
const seen = [
|
|
128
120
|
...continued.seen,
|
|
129
|
-
...
|
|
121
|
+
...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
|
|
130
122
|
];
|
|
131
123
|
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
132
124
|
return {
|
|
133
125
|
...(await stepped(bootstrapping(scope))),
|
|
134
126
|
...(models === undefined ? {} : { models }),
|
|
135
127
|
...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
|
|
128
|
+
...(sent.frame === null ? {} : { received: sent.frame }),
|
|
136
129
|
};
|
|
137
130
|
}
|
|
138
131
|
async function enumeratedPage(ask, page) {
|
|
@@ -164,18 +157,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
164
157
|
const answer = await refreshFrom(view, ask.fromRoomVersion);
|
|
165
158
|
if (answer.kind !== 'net-advancement')
|
|
166
159
|
return answer;
|
|
167
|
-
|
|
160
|
+
handed.set(ask.entry.locator, roomVersion(view));
|
|
168
161
|
const models = await viewModels(view, ask.entry);
|
|
169
162
|
return models === undefined ? answer : { ...answer, models };
|
|
170
163
|
}
|
|
171
164
|
async function streamed(entry, request, from) {
|
|
172
|
-
|
|
173
|
-
if (held?.roomVersion !== request.fromRoomVersion)
|
|
165
|
+
if (handed.get(entry.locator) !== request.fromRoomVersion)
|
|
174
166
|
return null;
|
|
175
|
-
const
|
|
167
|
+
const asked = notifications.edited(entry, from);
|
|
168
|
+
const kept = asked.length === 0 || heldRevisions === undefined
|
|
169
|
+
? new Map()
|
|
170
|
+
: await heldRevisions(entry.locator, asked);
|
|
171
|
+
const advanced = await stepped(notifications.advance(entry, from, (path, revision) => kept.get(path) === revision));
|
|
176
172
|
if (advanced === null)
|
|
177
173
|
return null;
|
|
178
|
-
|
|
174
|
+
handed.set(entry.locator, advanced.page.roomVersion);
|
|
179
175
|
const models = await streamedModels(advanced.schemas, entry, 'credential');
|
|
180
176
|
return models === undefined ? advanced.page : { ...advanced.page, models };
|
|
181
177
|
}
|
|
@@ -185,7 +181,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
185
181
|
const at = logPosition(room.roomVersion);
|
|
186
182
|
if (entry === undefined || at === null)
|
|
187
183
|
return [];
|
|
188
|
-
handed.set(room.locator,
|
|
184
|
+
handed.set(room.locator, room.roomVersion);
|
|
189
185
|
notifications.reach(entry.authority, at);
|
|
190
186
|
return [presented(entry.authority, at)];
|
|
191
187
|
});
|
|
@@ -203,8 +199,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
203
199
|
const held = handed.get(entry.locator);
|
|
204
200
|
if (held === undefined)
|
|
205
201
|
return outcome;
|
|
206
|
-
const follows = followsVersion(held
|
|
207
|
-
|
|
202
|
+
const follows = followsVersion(held, outcome.roomVersion);
|
|
203
|
+
if (follows)
|
|
204
|
+
handed.set(entry.locator, outcome.roomVersion);
|
|
208
205
|
const at = logPosition(outcome.roomVersion);
|
|
209
206
|
if (follows && at !== null)
|
|
210
207
|
notifications.reach(entry.authority, at);
|
|
@@ -233,8 +230,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
233
230
|
for (const ask of asks) {
|
|
234
231
|
if (ask.held === undefined || bound === 0)
|
|
235
232
|
continue;
|
|
236
|
-
const
|
|
237
|
-
const files = heldFiles(ask.entry.authority, ask.held, paths, bound);
|
|
233
|
+
const files = await heldFiles(ask.entry.authority, ask.held, bound);
|
|
238
234
|
if (files !== null)
|
|
239
235
|
held.push(files);
|
|
240
236
|
}
|
|
@@ -272,7 +268,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
272
268
|
continue;
|
|
273
269
|
}
|
|
274
270
|
const kept = held.find((files) => files.room === asked.entry.authority);
|
|
275
|
-
answer(asked.ask, await
|
|
271
|
+
answer(asked.ask, await manifestPage(asked.asked, {
|
|
276
272
|
room,
|
|
277
273
|
next: 0,
|
|
278
274
|
seen: [],
|
|
@@ -364,21 +360,16 @@ export function createAgentsHouseAdapter(options) {
|
|
|
364
360
|
const refusal = doorRefusal(answer.body);
|
|
365
361
|
if (refusal?.code !== 'files_unstaged')
|
|
366
362
|
return null;
|
|
367
|
-
const
|
|
368
|
-
if (!Array.isArray(
|
|
363
|
+
const uploads = refusal.fields.upload;
|
|
364
|
+
if (!Array.isArray(uploads))
|
|
369
365
|
return false;
|
|
370
|
-
for (const
|
|
371
|
-
const
|
|
372
|
-
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === sha256);
|
|
373
|
-
if (
|
|
366
|
+
for (const named of uploads) {
|
|
367
|
+
const upload = houseUpload(named);
|
|
368
|
+
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
|
|
369
|
+
if (upload === null || change === undefined)
|
|
374
370
|
return false;
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
url,
|
|
378
|
-
body: await file(change.localId),
|
|
379
|
-
operation,
|
|
380
|
-
});
|
|
381
|
-
if (delivered.status !== 200)
|
|
371
|
+
const finished = await finishedUpload(transport, upload, await file(change.localId));
|
|
372
|
+
if (finished?.body?.staged !== true)
|
|
382
373
|
return false;
|
|
383
374
|
}
|
|
384
375
|
return true;
|
|
@@ -422,9 +413,22 @@ export function createAgentsHouseAdapter(options) {
|
|
|
422
413
|
function linked(answer, locator) {
|
|
423
414
|
const address = addressed(answer, locator);
|
|
424
415
|
return address.kind === 'address'
|
|
425
|
-
? { kind: 'link', url: address.url, name: address.name }
|
|
416
|
+
? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
|
|
426
417
|
: address;
|
|
427
418
|
}
|
|
419
|
+
function refusedAttach(answer, locator) {
|
|
420
|
+
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
421
|
+
if (failure === null)
|
|
422
|
+
return null;
|
|
423
|
+
return failure.kind === 'scoped-refusal'
|
|
424
|
+
? {
|
|
425
|
+
kind: 'rejected',
|
|
426
|
+
code: failure.code,
|
|
427
|
+
fields: failure.fields,
|
|
428
|
+
retryable: failure.retryable,
|
|
429
|
+
}
|
|
430
|
+
: failure;
|
|
431
|
+
}
|
|
428
432
|
async function downloaded(ask, locator) {
|
|
429
433
|
let address = addressed(await ask(), locator);
|
|
430
434
|
if (address.kind !== 'address')
|
|
@@ -436,11 +440,14 @@ export function createAgentsHouseAdapter(options) {
|
|
|
436
440
|
return address;
|
|
437
441
|
read = await transport.download(address.url);
|
|
438
442
|
}
|
|
439
|
-
if (read.status !== 200 || read.
|
|
440
|
-
return UNCERTAIN_READ;
|
|
441
|
-
if ((await sha256Hex(await read.blob.arrayBuffer())) !== address.sha256)
|
|
443
|
+
if (read.status !== 200 || read.body === null)
|
|
442
444
|
return UNCERTAIN_READ;
|
|
443
|
-
return {
|
|
445
|
+
return {
|
|
446
|
+
kind: 'binary',
|
|
447
|
+
body: read.body,
|
|
448
|
+
mediaType: address.mediaType,
|
|
449
|
+
sha256: address.sha256,
|
|
450
|
+
};
|
|
444
451
|
}
|
|
445
452
|
function pathAddress(request) {
|
|
446
453
|
const entry = authorityFor(request.locator);
|
|
@@ -454,6 +461,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
454
461
|
}
|
|
455
462
|
return {
|
|
456
463
|
roomTypes: HOUSE_ROOM_TYPES,
|
|
464
|
+
nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
|
|
457
465
|
async authorize() {
|
|
458
466
|
return options.authorize();
|
|
459
467
|
},
|
|
@@ -503,7 +511,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
503
511
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
504
512
|
const asked = { entry, held: request.held };
|
|
505
513
|
if (request.pageToken !== undefined) {
|
|
506
|
-
return partPage(asked, JSON.parse(request.pageToken));
|
|
514
|
+
return partPage(asked, JSON.parse(request.pageToken), request.received, request.arriving);
|
|
507
515
|
}
|
|
508
516
|
return bootstrapTogether(asked);
|
|
509
517
|
},
|
|
@@ -563,17 +571,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
563
571
|
});
|
|
564
572
|
},
|
|
565
573
|
async binary(_authorization, request) {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
return downloaded(ask, request.locator);
|
|
571
|
-
}
|
|
572
|
-
const referrer = houseReferrer(request.referrer, tracked);
|
|
573
|
-
if (referrer === null) {
|
|
574
|
-
return { kind: 'rejected', code: 'referrer_unknown', fields: {}, retryable: false };
|
|
575
|
-
}
|
|
576
|
-
return downloaded(() => transport.door(DOOR_FILES_GET, { file: request.fileRef, referrer: referrer.referrer }), referrer.locator);
|
|
574
|
+
const ask = pathAddress(request);
|
|
575
|
+
if (ask === null)
|
|
576
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
577
|
+
return downloaded(ask, request.locator);
|
|
577
578
|
},
|
|
578
579
|
async link(_authorization, request) {
|
|
579
580
|
const ask = pathAddress(request);
|
|
@@ -581,12 +582,34 @@ export function createAgentsHouseAdapter(options) {
|
|
|
581
582
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
582
583
|
return linked(await ask(), request.locator);
|
|
583
584
|
},
|
|
584
|
-
|
|
585
|
-
const
|
|
586
|
-
if (
|
|
587
|
-
return
|
|
588
|
-
const
|
|
589
|
-
|
|
585
|
+
async attach(_authorization, request) {
|
|
586
|
+
const entry = authorityFor(request.locator);
|
|
587
|
+
if (entry === undefined)
|
|
588
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
589
|
+
const declared = await transport.door(DOOR_FILES_ATTACH, {
|
|
590
|
+
room_ref: entry.authority,
|
|
591
|
+
name: request.name,
|
|
592
|
+
bytes: request.byteLength,
|
|
593
|
+
sha256: request.sha256,
|
|
594
|
+
media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
|
|
595
|
+
});
|
|
596
|
+
const refused = refusedAttach(declared, request.locator);
|
|
597
|
+
if (refused !== null)
|
|
598
|
+
return refused;
|
|
599
|
+
const upload = houseUpload(declared.body?.upload);
|
|
600
|
+
if (upload === null)
|
|
601
|
+
return UNCERTAIN_READ;
|
|
602
|
+
const finished = await finishedUpload(transport, upload, request.blob);
|
|
603
|
+
if (finished === null)
|
|
604
|
+
return UNCERTAIN_READ;
|
|
605
|
+
const unfinished = refusedAttach(finished, request.locator);
|
|
606
|
+
if (unfinished !== null)
|
|
607
|
+
return unfinished;
|
|
608
|
+
const path = finished.body?.path;
|
|
609
|
+
const root = `/rooms/${entry.handle}/`;
|
|
610
|
+
return typeof path === 'string' && path.startsWith(root)
|
|
611
|
+
? { kind: 'attached', path: path.slice(root.length) }
|
|
612
|
+
: UNCERTAIN_READ;
|
|
590
613
|
},
|
|
591
614
|
reached(locator, version, target) {
|
|
592
615
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
@@ -600,7 +623,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
600
623
|
roomStream: {
|
|
601
624
|
hold: held,
|
|
602
625
|
reopen: notifications.reopen,
|
|
603
|
-
observe
|
|
626
|
+
observe(notify, receipts, revisions) {
|
|
627
|
+
heldRevisions = revisions;
|
|
628
|
+
return notifications.observe(notify, receipts);
|
|
629
|
+
},
|
|
604
630
|
published(locator, roomVersion) {
|
|
605
631
|
const at = logPosition(roomVersion);
|
|
606
632
|
if (at !== null)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-reference.d.ts","sourceRoot":"","sources":["../src/app-reference.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,QAEjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crockford.d.ts","sourceRoot":"","sources":["../src/crockford.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAErE,eAAO,MAAM,mBAAmB,uCAA4B,CAAC;AAE7D,eAAO,MAAM,2BAA2B,QAAqC,CAAC"}
|
package/dist/digest.d.ts
CHANGED
package/dist/digest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../src/digest.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../src/digest.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG9D"}
|
package/dist/digest.js
CHANGED
|
@@ -2,6 +2,6 @@ export function textBytes(value) {
|
|
|
2
2
|
return new TextEncoder().encode(value).length;
|
|
3
3
|
}
|
|
4
4
|
export async function sha256Hex(value) {
|
|
5
|
-
const digest = await crypto.subtle.digest('SHA-256',
|
|
5
|
+
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
|
|
6
6
|
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
7
7
|
}
|
package/dist/discovery.d.ts
CHANGED
|
@@ -23,16 +23,12 @@ export type HouseOperations = {
|
|
|
23
23
|
delete: readonly string[];
|
|
24
24
|
};
|
|
25
25
|
export type HouseReadLevel = 'mcp' | 'online' | 'local';
|
|
26
|
-
export type HouseModel = {
|
|
27
|
-
root: string;
|
|
28
|
-
paths: readonly string[];
|
|
29
|
-
};
|
|
30
26
|
export type HouseAuthority = LogPosition & {
|
|
31
27
|
roomRef: string;
|
|
32
28
|
roomHandle: string;
|
|
33
29
|
name: string;
|
|
34
30
|
schema: string;
|
|
35
|
-
|
|
31
|
+
typedSelection: readonly string[] | null;
|
|
36
32
|
managedReplication: 'admitted' | 'unavailable';
|
|
37
33
|
protectedPaths: readonly string[];
|
|
38
34
|
read: HouseReadLevel;
|
|
@@ -49,8 +45,7 @@ export type TrackedAuthority = LogPosition & {
|
|
|
49
45
|
authority: string;
|
|
50
46
|
handle: string;
|
|
51
47
|
schema: string;
|
|
52
|
-
|
|
53
|
-
schemas: readonly string[];
|
|
48
|
+
typedSelection: readonly string[] | null;
|
|
54
49
|
};
|
|
55
50
|
export type HouseSiteAuthority = LogPosition & {
|
|
56
51
|
roomRef: string;
|
|
@@ -67,7 +62,7 @@ export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthor
|
|
|
67
62
|
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
68
63
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
69
64
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
70
|
-
export declare function capabilities(actions: HouseDiscoveryDocument['actions'], rooms: readonly Pick<TrackedAuthority, 'authority' | '
|
|
65
|
+
export declare function capabilities(actions: HouseDiscoveryDocument['actions'], rooms: readonly Pick<TrackedAuthority, 'authority' | 'typedSelection'>[]): readonly Capability[];
|
|
71
66
|
export declare function siteCapabilities(): readonly Capability[];
|
|
72
67
|
export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
|
|
73
68
|
export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
|
package/dist/discovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,MAAM,EACN,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAAU,CAAC;AAE1D,MAAM,MAAM,WAAW,GAAG;IACxB,uBAAuB,EAAE,MAAM,CAAC;IAChC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,wBAAwB,EAAE,MAAM,CAAC;IACjC,2BAA2B,EAAE,MAAM,CAAC;IACpC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CA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EAAE,sBAAsB,GAAG,gBAAgB,EAAE,CAUhF;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,aAAa,EAAE,CAa5E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAMhE;AAED,wBAAgB,YAAY,CAC1B,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,EAC1C,KAAK,EAAE,SAAS,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,gBAAgB,CAAC,EAAE,GACvE,SAAS,UAAU,EAAE,CAWvB;AAED,wBAAgB,gBAAgB,IAAI,SAAS,UAAU,EAAE,CAOxD;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,cAAc,GAAG,cAAc,CAqBxE;AAED,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,EAChD,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,QAAQ,EAAE,SAAS,UAAU,EAAE,GAC9B,SAAS,CAQX"}
|
package/dist/discovery.js
CHANGED
|
@@ -43,16 +43,10 @@ function parseBounds(value) {
|
|
|
43
43
|
}
|
|
44
44
|
return bounds;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function parseTypedSelection(value) {
|
|
47
47
|
if (value === undefined)
|
|
48
48
|
return null;
|
|
49
|
-
|
|
50
|
-
return undefined;
|
|
51
|
-
const held = value;
|
|
52
|
-
const paths = stringList(held.paths);
|
|
53
|
-
if (typeof held.root !== 'string' || held.root.length === 0 || paths === null)
|
|
54
|
-
return undefined;
|
|
55
|
-
return { root: held.root, paths };
|
|
49
|
+
return stringList(value) ?? undefined;
|
|
56
50
|
}
|
|
57
51
|
function parseMember(value) {
|
|
58
52
|
if (typeof value !== 'object' || value === null)
|
|
@@ -89,12 +83,12 @@ function parseAuthority(value) {
|
|
|
89
83
|
return null;
|
|
90
84
|
}
|
|
91
85
|
const at = readPosition(held);
|
|
92
|
-
const
|
|
86
|
+
const typedSelection = parseTypedSelection(held.typed_selection);
|
|
93
87
|
const protectedPaths = stringList(held.protected_paths);
|
|
94
88
|
const operations = parseOperations(held.operations);
|
|
95
89
|
const read = READ_LEVELS.find((level) => level === held.read);
|
|
96
90
|
if (at === null ||
|
|
97
|
-
|
|
91
|
+
typedSelection === undefined ||
|
|
98
92
|
protectedPaths === null ||
|
|
99
93
|
read === undefined ||
|
|
100
94
|
operations === null)
|
|
@@ -108,7 +102,7 @@ function parseAuthority(value) {
|
|
|
108
102
|
roomHandle: held.room_handle,
|
|
109
103
|
name: held.name,
|
|
110
104
|
schema: held.model_root,
|
|
111
|
-
|
|
105
|
+
typedSelection,
|
|
112
106
|
managedReplication: held.managed_replication,
|
|
113
107
|
protectedPaths,
|
|
114
108
|
read,
|
|
@@ -188,25 +182,18 @@ export function siteTracked(document) {
|
|
|
188
182
|
authority: authority.roomRef,
|
|
189
183
|
handle: authority.roomHandle,
|
|
190
184
|
schema: authority.schema,
|
|
191
|
-
|
|
192
|
-
schemas: [authority.schema],
|
|
185
|
+
typedSelection: null,
|
|
193
186
|
position: authority.position,
|
|
194
187
|
logEpoch: authority.logEpoch,
|
|
195
188
|
}));
|
|
196
189
|
}
|
|
197
|
-
function schemasOf(authority) {
|
|
198
|
-
return authority.houseModel === null
|
|
199
|
-
? [authority.schema]
|
|
200
|
-
: [authority.schema, authority.houseModel.root];
|
|
201
|
-
}
|
|
202
190
|
export function trackedFrom(document) {
|
|
203
191
|
return document.authorities.map((authority) => ({
|
|
204
192
|
locator: authority.roomRef,
|
|
205
193
|
authority: authority.roomRef,
|
|
206
194
|
handle: authority.roomHandle,
|
|
207
195
|
schema: authority.schema,
|
|
208
|
-
|
|
209
|
-
schemas: schemasOf(authority),
|
|
196
|
+
typedSelection: authority.typedSelection,
|
|
210
197
|
position: authority.position,
|
|
211
198
|
logEpoch: authority.logEpoch,
|
|
212
199
|
}));
|
|
@@ -233,7 +220,7 @@ export function declaredRetention(bounds) {
|
|
|
233
220
|
};
|
|
234
221
|
}
|
|
235
222
|
export function capabilities(actions, rooms) {
|
|
236
|
-
const house = rooms.find((room) => room.
|
|
223
|
+
const house = rooms.find((room) => room.typedSelection !== null);
|
|
237
224
|
return [
|
|
238
225
|
{
|
|
239
226
|
name: PROVIDER_ACTIONS,
|
|
@@ -268,10 +255,10 @@ export function discoveredRoom(authority) {
|
|
|
268
255
|
admission: authority.managedReplication,
|
|
269
256
|
offline: authority.read === 'online' ? 'locked' : 'open',
|
|
270
257
|
},
|
|
271
|
-
...(authority.
|
|
258
|
+
...(authority.typedSelection === null
|
|
272
259
|
? {}
|
|
273
|
-
: { typedSelection: { roots: [...authority.
|
|
274
|
-
providerOwnedPaths: [...authority.protectedPaths,
|
|
260
|
+
: { typedSelection: { roots: [...authority.typedSelection] } }),
|
|
261
|
+
providerOwnedPaths: [...authority.protectedPaths, authority.schema],
|
|
275
262
|
};
|
|
276
263
|
}
|
|
277
264
|
export function mapDiscovery(document, rooms, declared) {
|