@agentshouse/mdruntime-adapter 0.1.0-c7d05e09c73b7 → 0.1.0-c7d6f34caf6de
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/AGENTS.md +96 -31
- package/dist/actions.d.ts +40 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +136 -118
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +102 -29
- package/dist/handed.d.ts +15 -0
- package/dist/handed.d.ts.map +1 -0
- package/dist/handed.js +38 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/read.d.ts +7 -7
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +59 -77
- package/dist/referrer.d.ts +7 -0
- package/dist/referrer.d.ts.map +1 -0
- package/dist/referrer.js +35 -0
- package/dist/refusal.d.ts +2 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +4 -8
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +40 -3
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +13 -6
- package/dist/transport.d.ts +15 -6
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -0
- package/dist/write.d.ts +3 -9
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +77 -11
- package/package.json +4 -4
- package/dist/links.d.ts +0 -20
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -104
package/dist/adapter.js
CHANGED
|
@@ -3,12 +3,13 @@ import { partModels, streamedModels, viewModels } from './model.js';
|
|
|
3
3
|
import { gathered, gatheredEach, selections } from './gather.js';
|
|
4
4
|
import { createSiteAdapter } from './site.js';
|
|
5
5
|
import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, viewOf, } from './read.js';
|
|
6
|
-
import {
|
|
6
|
+
import { acceptedHanded, enumeratedHanded, heldHanded, scopeHanded, streamedHanded, } from './handed.js';
|
|
7
7
|
import { houseAction } from './actions.js';
|
|
8
8
|
import { classifyDoor, classifyRead, discoveryFailure, doorRefusal } from './refusal.js';
|
|
9
9
|
import { houseNotifications } from './stream.js';
|
|
10
|
-
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, } from './transport.js';
|
|
10
|
+
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
|
|
11
11
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
12
|
+
import { houseReferrer } from './referrer.js';
|
|
12
13
|
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
13
14
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
14
15
|
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
@@ -33,7 +34,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
33
34
|
return { kind: 'room-not-readable', locator: entry.locator };
|
|
34
35
|
const next = envelope.next?.room === entry.authority ? envelope.next.path : null;
|
|
35
36
|
if (continued === null && next === null)
|
|
36
|
-
handed.set(entry.locator,
|
|
37
|
+
handed.set(entry.locator, scopeHanded(scope));
|
|
37
38
|
else
|
|
38
39
|
handed.delete(entry.locator);
|
|
39
40
|
notifications.reach(entry.authority, scope);
|
|
@@ -57,21 +58,18 @@ export function createAgentsHouseAdapter(options) {
|
|
|
57
58
|
const answer = refreshFrom(view, ask.fromRoomVersion);
|
|
58
59
|
if (answer.kind !== 'net-advancement')
|
|
59
60
|
return answer;
|
|
60
|
-
handed.set(ask.entry.locator,
|
|
61
|
+
handed.set(ask.entry.locator, enumeratedHanded(view, handed.get(ask.entry.locator)));
|
|
61
62
|
const models = await viewModels(view, ask.entry);
|
|
62
63
|
return models === undefined ? answer : { ...answer, models };
|
|
63
64
|
}
|
|
64
65
|
async function streamed(entry, request, from) {
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
66
|
+
const held = handed.get(entry.locator);
|
|
67
|
+
if (held?.roomVersion !== request.fromRoomVersion)
|
|
67
68
|
return null;
|
|
68
|
-
const advanced = notifications.advance(entry, from, (path, revision) =>
|
|
69
|
+
const advanced = notifications.advance(entry, from, (path, revision) => held.revisions.get(path) === revision);
|
|
69
70
|
if (advanced === null)
|
|
70
71
|
return null;
|
|
71
|
-
|
|
72
|
-
if (relinked === null)
|
|
73
|
-
return null;
|
|
74
|
-
handed.set(entry.locator, relinked);
|
|
72
|
+
handed.set(entry.locator, streamedHanded(held, advanced));
|
|
75
73
|
const models = await streamedModels(advanced.schemas, entry, 'credential');
|
|
76
74
|
return models === undefined ? advanced.page : { ...advanced.page, models };
|
|
77
75
|
}
|
|
@@ -81,7 +79,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
81
79
|
const at = logPosition(room.roomVersion);
|
|
82
80
|
if (entry === undefined || at === null)
|
|
83
81
|
return [];
|
|
84
|
-
handed.set(room.locator,
|
|
82
|
+
handed.set(room.locator, heldHanded(room));
|
|
85
83
|
notifications.reach(entry.authority, at);
|
|
86
84
|
return [presented(entry.authority, at)];
|
|
87
85
|
});
|
|
@@ -90,19 +88,15 @@ export function createAgentsHouseAdapter(options) {
|
|
|
90
88
|
function adopted(entry, outcome) {
|
|
91
89
|
if (outcome.kind !== 'accepted')
|
|
92
90
|
return outcome;
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
handed.set(entry.locator, relinked.links);
|
|
100
|
-
const at = logPosition(accepted.roomVersion);
|
|
91
|
+
const held = handed.get(entry.locator);
|
|
92
|
+
if (held === undefined)
|
|
93
|
+
return outcome;
|
|
94
|
+
const follows = followsVersion(held.roomVersion, outcome.roomVersion);
|
|
95
|
+
handed.set(entry.locator, acceptedHanded(held, outcome, follows ? outcome.roomVersion : held.roomVersion));
|
|
96
|
+
const at = logPosition(outcome.roomVersion);
|
|
101
97
|
if (follows && at !== null)
|
|
102
98
|
notifications.reach(entry.authority, at);
|
|
103
|
-
return
|
|
104
|
-
? accepted
|
|
105
|
-
: { ...accepted, attachments: relinked.attachments };
|
|
99
|
+
return outcome;
|
|
106
100
|
}
|
|
107
101
|
function authorityFor(locator) {
|
|
108
102
|
return tracked.get(locator);
|
|
@@ -232,9 +226,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
232
226
|
return { outcome: UNCERTAIN };
|
|
233
227
|
const delivered = await transport.transfer({
|
|
234
228
|
act: 'authored_batch_upload',
|
|
235
|
-
method: 'POST',
|
|
236
229
|
url: grant.url,
|
|
237
|
-
answer: 'json',
|
|
238
230
|
body: `${grant.operation}\n${delta}`,
|
|
239
231
|
});
|
|
240
232
|
if (delivered.status !== 200)
|
|
@@ -246,7 +238,30 @@ export function createAgentsHouseAdapter(options) {
|
|
|
246
238
|
await keep(upload);
|
|
247
239
|
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
248
240
|
}
|
|
249
|
-
async function
|
|
241
|
+
async function staged(answer, batch) {
|
|
242
|
+
const refusal = doorRefusal(answer.body);
|
|
243
|
+
if (refusal?.code !== 'files_unstaged')
|
|
244
|
+
return null;
|
|
245
|
+
const grants = refusal.fields.upload;
|
|
246
|
+
if (!Array.isArray(grants))
|
|
247
|
+
return false;
|
|
248
|
+
for (const grant of grants) {
|
|
249
|
+
const { url, operation, sha256 } = grant;
|
|
250
|
+
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === sha256);
|
|
251
|
+
if (typeof url !== 'string' || typeof operation !== 'string' || change === undefined)
|
|
252
|
+
return false;
|
|
253
|
+
const delivered = await transport.transfer({
|
|
254
|
+
act: 'binary_stage',
|
|
255
|
+
url,
|
|
256
|
+
body: change.blob,
|
|
257
|
+
operation,
|
|
258
|
+
});
|
|
259
|
+
if (delivered.status !== 200)
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
async function submit(batch, head, changes, delta, bytes, entry, handed, keep) {
|
|
250
265
|
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
251
266
|
const prepared = uploadable(inline, bytes, declared())
|
|
252
267
|
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
@@ -254,7 +269,33 @@ export function createAgentsHouseAdapter(options) {
|
|
|
254
269
|
if ('outcome' in prepared)
|
|
255
270
|
return prepared.outcome;
|
|
256
271
|
const answer = await transport.door(DOOR_BATCH, prepared.body);
|
|
257
|
-
|
|
272
|
+
const stagedFiles = await staged(answer, batch);
|
|
273
|
+
if (stagedFiles === false)
|
|
274
|
+
return UNCERTAIN;
|
|
275
|
+
const settled = stagedFiles === null ? answer : await transport.door(DOOR_BATCH, prepared.body);
|
|
276
|
+
if (stagedFiles === true && (await staged(settled, batch)) !== null)
|
|
277
|
+
return UNCERTAIN;
|
|
278
|
+
return mutationOutcome(settled.status, settled.body, entry.locator, entry.handle);
|
|
279
|
+
}
|
|
280
|
+
async function downloaded(answer, locator) {
|
|
281
|
+
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
282
|
+
if (failure !== null) {
|
|
283
|
+
return failure.kind === 'scoped-refusal'
|
|
284
|
+
? {
|
|
285
|
+
kind: 'rejected',
|
|
286
|
+
code: failure.code,
|
|
287
|
+
fields: failure.fields,
|
|
288
|
+
retryable: failure.retryable,
|
|
289
|
+
}
|
|
290
|
+
: failure;
|
|
291
|
+
}
|
|
292
|
+
const grant = parseGrant(answer.body);
|
|
293
|
+
if (grant === null || grant.method !== 'GET')
|
|
294
|
+
return UNCERTAIN_READ;
|
|
295
|
+
const read = await transport.download(grant.url);
|
|
296
|
+
if (read.status !== 200 || read.blob === null)
|
|
297
|
+
return UNCERTAIN_READ;
|
|
298
|
+
return { kind: 'binary', blob: read.blob };
|
|
258
299
|
}
|
|
259
300
|
return {
|
|
260
301
|
async authorize() {
|
|
@@ -316,10 +357,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
316
357
|
const delta = deltaBody(mapped.changes);
|
|
317
358
|
const bytes = deltaBytes(delta);
|
|
318
359
|
const handed = request.upload;
|
|
319
|
-
const
|
|
360
|
+
const batch = request.changeBatch;
|
|
361
|
+
const outcome = await submit(batch, head, mapped.changes, delta, bytes, entry, handed, keep);
|
|
320
362
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
321
363
|
return adopted(entry, outcome);
|
|
322
|
-
return adopted(entry, await submit(head, mapped.changes, delta, bytes, entry, undefined, keep));
|
|
364
|
+
return adopted(entry, await submit(batch, head, mapped.changes, delta, bytes, entry, undefined, keep));
|
|
323
365
|
},
|
|
324
366
|
async history(_authorization, request) {
|
|
325
367
|
const entry = authorityFor(request.locator);
|
|
@@ -336,6 +378,37 @@ export function createAgentsHouseAdapter(options) {
|
|
|
336
378
|
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
337
379
|
});
|
|
338
380
|
},
|
|
381
|
+
async binary(_authorization, request) {
|
|
382
|
+
if (request.kind === 'path') {
|
|
383
|
+
const entry = authorityFor(request.locator);
|
|
384
|
+
if (entry === undefined)
|
|
385
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
386
|
+
const answer = await transport.door(DOOR_FILES_GET, {
|
|
387
|
+
room_ref: entry.authority,
|
|
388
|
+
path: request.path,
|
|
389
|
+
revision: request.revision,
|
|
390
|
+
});
|
|
391
|
+
return downloaded(answer, request.locator);
|
|
392
|
+
}
|
|
393
|
+
const referrer = houseReferrer(request.referrer, tracked);
|
|
394
|
+
if (referrer === null) {
|
|
395
|
+
return { kind: 'rejected', code: 'referrer_unknown', fields: {}, retryable: false };
|
|
396
|
+
}
|
|
397
|
+
const answer = await transport.door(DOOR_FILES_GET, {
|
|
398
|
+
file: request.fileRef,
|
|
399
|
+
referrer: referrer.referrer,
|
|
400
|
+
});
|
|
401
|
+
return downloaded(answer, referrer.locator);
|
|
402
|
+
},
|
|
403
|
+
referrerScope(referrer) {
|
|
404
|
+
const held = houseReferrer(referrer, tracked);
|
|
405
|
+
if (held === null)
|
|
406
|
+
return null;
|
|
407
|
+
if (held.locator === '')
|
|
408
|
+
return { kind: 'conversations' };
|
|
409
|
+
const { path } = held.referrer;
|
|
410
|
+
return { kind: 'room', locator: held.locator, ...(path === undefined ? {} : { path }) };
|
|
411
|
+
},
|
|
339
412
|
reached(locator, version, target) {
|
|
340
413
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
341
414
|
},
|
package/dist/handed.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HeldRoom, MutationResult } from '@agentshouse/mdruntime';
|
|
2
|
+
import type { HouseScope, HouseView } from './read.js';
|
|
3
|
+
import type { StreamedAdvancement } from './stream.js';
|
|
4
|
+
export type HandedRoom = {
|
|
5
|
+
roomVersion: string;
|
|
6
|
+
revisions: ReadonlyMap<string, string>;
|
|
7
|
+
};
|
|
8
|
+
export declare function scopeHanded(scope: HouseScope): HandedRoom;
|
|
9
|
+
export declare function heldHanded(held: HeldRoom): HandedRoom;
|
|
10
|
+
export declare function acceptedHanded(held: HandedRoom, accepted: Extract<MutationResult, {
|
|
11
|
+
kind: 'accepted';
|
|
12
|
+
}>, roomVersion: string): HandedRoom;
|
|
13
|
+
export declare function enumeratedHanded(view: HouseView, earlier: HandedRoom | undefined): HandedRoom;
|
|
14
|
+
export declare function streamedHanded(held: HandedRoom, advanced: StreamedAdvancement): HandedRoom;
|
|
15
|
+
//# sourceMappingURL=handed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handed.d.ts","sourceRoot":"","sources":["../src/handed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CASzD;AAOD,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAErD;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,EACvD,WAAW,EAAE,MAAM,GAClB,UAAU,CAKZ;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS,GAAG,UAAU,CAM7F;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,GAAG,UAAU,CAM1F"}
|
package/dist/handed.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { roomVersion } from './version.js';
|
|
2
|
+
export function scopeHanded(scope) {
|
|
3
|
+
return {
|
|
4
|
+
roomVersion: roomVersion(scope),
|
|
5
|
+
revisions: new Map(scope.files.flatMap(({ path, revision }) => revision === undefined ? [] : [[path, revision]])),
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function revised(revisions, path, revision) {
|
|
9
|
+
if (revision === undefined)
|
|
10
|
+
revisions.delete(path);
|
|
11
|
+
else
|
|
12
|
+
revisions.set(path, revision);
|
|
13
|
+
}
|
|
14
|
+
export function heldHanded(held) {
|
|
15
|
+
return { roomVersion: held.roomVersion, revisions: new Map(Object.entries(held.revisions)) };
|
|
16
|
+
}
|
|
17
|
+
export function acceptedHanded(held, accepted, roomVersion) {
|
|
18
|
+
const revisions = new Map(held.revisions);
|
|
19
|
+
for (const [path, revision] of Object.entries(accepted.revisions))
|
|
20
|
+
revisions.set(path, revision);
|
|
21
|
+
for (const path of accepted.removals)
|
|
22
|
+
revisions.delete(path);
|
|
23
|
+
return { roomVersion, revisions };
|
|
24
|
+
}
|
|
25
|
+
export function enumeratedHanded(view, earlier) {
|
|
26
|
+
const revisions = new Map(earlier?.revisions);
|
|
27
|
+
for (const change of view.changes) {
|
|
28
|
+
revised(revisions, change.path, 'removed' in change ? undefined : change.revision);
|
|
29
|
+
}
|
|
30
|
+
return { roomVersion: roomVersion(view), revisions };
|
|
31
|
+
}
|
|
32
|
+
export function streamedHanded(held, advanced) {
|
|
33
|
+
const revisions = new Map(held.revisions);
|
|
34
|
+
for (const entry of advanced.entries) {
|
|
35
|
+
revised(revisions, entry.path, entry.kind === 'removed' ? undefined : entry.revision);
|
|
36
|
+
}
|
|
37
|
+
return { roomVersion: advanced.page.roomVersion, revisions };
|
|
38
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { createAgentsHouseAdapter, type AgentsHouseAdapterOptions } from './adapter.js';
|
|
2
|
-
export
|
|
2
|
+
export { HOUSE_APP_ACTS, HOUSE_APP_BATCHES } from './actions.js';
|
|
3
|
+
export type { HouseByteAct, HouseByteTransfer, HouseBytesAnswer, HouseDoorAnswer, HouseHeldRoom, HouseOpening, HouseStream, HouseStreamEntry, HouseStreamFrame, HouseSiteTransport, HouseTransport, } from './transport.js';
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACxF,YAAY,EACV,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjE,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/read.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BootstrapPage, RefreshResult
|
|
1
|
+
import type { BinaryFile, BootstrapPage, RefreshResult } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
3
|
import type { HouseMode } from './transport.js';
|
|
4
4
|
import { type LogPosition } from './version.js';
|
|
@@ -8,6 +8,7 @@ export type HouseManifestFile = {
|
|
|
8
8
|
revision: string | undefined;
|
|
9
9
|
version: string;
|
|
10
10
|
head?: HeadChange;
|
|
11
|
+
binary?: BinaryFile;
|
|
11
12
|
};
|
|
12
13
|
export type HouseContent = {
|
|
13
14
|
path: string;
|
|
@@ -17,7 +18,6 @@ export type HouseScope = LogPosition & {
|
|
|
17
18
|
anchor: string;
|
|
18
19
|
files: readonly HouseManifestFile[];
|
|
19
20
|
contents: readonly HouseContent[];
|
|
20
|
-
attachments?: readonly RoomAttachment[];
|
|
21
21
|
};
|
|
22
22
|
export type HouseCursor = {
|
|
23
23
|
room: string;
|
|
@@ -46,14 +46,14 @@ export type HouseChange = {
|
|
|
46
46
|
head?: HeadChange;
|
|
47
47
|
} | {
|
|
48
48
|
path: string;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
binary: BinaryFile;
|
|
50
|
+
revision: string | undefined;
|
|
51
|
+
version: string;
|
|
52
|
+
head?: HeadChange;
|
|
52
53
|
};
|
|
53
54
|
export type HouseView = LogPosition & {
|
|
54
55
|
authority: string;
|
|
55
56
|
changes: readonly HouseChange[];
|
|
56
|
-
attachments?: readonly RoomAttachment[];
|
|
57
57
|
};
|
|
58
58
|
export type HouseEnumeration = {
|
|
59
59
|
authorities: readonly HouseView[];
|
|
@@ -66,7 +66,7 @@ export declare function headChange(held: {
|
|
|
66
66
|
readonly author?: unknown;
|
|
67
67
|
readonly created_at?: unknown;
|
|
68
68
|
}): HeadChange | undefined | null;
|
|
69
|
-
export declare function
|
|
69
|
+
export declare function binaryFileOf(held: Readonly<Record<string, unknown>>): BinaryFile | undefined | null;
|
|
70
70
|
export declare function parseEnvelope(body: unknown): HouseEnvelope | null;
|
|
71
71
|
export declare function parseSiteBootstrap(body: unknown): HouseScope | null;
|
|
72
72
|
export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
|
package/dist/read.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EAEb,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,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AU,EAAE,IAAI,EAAE,SAAS,GAAG,UAAU,CAuB5E;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAElF;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,aAAa,CAqB5D;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAO9E;AAED,wBAAgB,MAAM,CACpB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,gBAAgB,GACxB,SAAS,GAAG,SAAS,CAEvB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,GAAG,aAAa,CA0BnF"}
|
package/dist/read.js
CHANGED
|
@@ -51,32 +51,19 @@ export function headChange(held) {
|
|
|
51
51
|
function headed(head) {
|
|
52
52
|
return head === undefined ? {} : { head };
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
if (
|
|
56
|
-
return
|
|
57
|
-
const {
|
|
58
|
-
if (typeof
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (mediaType !== null && typeof mediaType !== 'string')
|
|
63
|
-
return null;
|
|
64
|
-
return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
|
|
65
|
-
}
|
|
66
|
-
export function parseOriginals(value) {
|
|
67
|
-
if (!Array.isArray(value))
|
|
54
|
+
export function binaryFileOf(held) {
|
|
55
|
+
if (held.file === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
const { file, bytes, media_type: mediaType, sha256 } = held;
|
|
58
|
+
if (typeof file !== 'string' ||
|
|
59
|
+
typeof bytes !== 'number' ||
|
|
60
|
+
typeof mediaType !== 'string' ||
|
|
61
|
+
typeof sha256 !== 'string')
|
|
68
62
|
return null;
|
|
69
|
-
|
|
70
|
-
for (const entry of value) {
|
|
71
|
-
const attachment = parseOriginal(entry);
|
|
72
|
-
if (attachment === null)
|
|
73
|
-
return null;
|
|
74
|
-
attachments.push(attachment);
|
|
75
|
-
}
|
|
76
|
-
return attachments;
|
|
63
|
+
return { fileRef: file, byteLength: bytes, mediaType, sha256 };
|
|
77
64
|
}
|
|
78
|
-
function
|
|
79
|
-
return
|
|
65
|
+
function binaried(binary) {
|
|
66
|
+
return binary === undefined ? {} : { binary };
|
|
80
67
|
}
|
|
81
68
|
function parseFile(value, mode) {
|
|
82
69
|
if (typeof value !== 'object' || value === null)
|
|
@@ -85,16 +72,29 @@ function parseFile(value, mode) {
|
|
|
85
72
|
if (typeof file.path !== 'string')
|
|
86
73
|
return null;
|
|
87
74
|
const head = headChange(file);
|
|
88
|
-
|
|
75
|
+
const binary = binaryFileOf(file);
|
|
76
|
+
if (head === null || binary === null)
|
|
89
77
|
return null;
|
|
90
78
|
if (mode === 'site') {
|
|
91
79
|
if (typeof file.sha256 !== 'string')
|
|
92
80
|
return null;
|
|
93
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
path: file.path,
|
|
83
|
+
revision: binary?.sha256,
|
|
84
|
+
version: file.sha256,
|
|
85
|
+
...headed(head),
|
|
86
|
+
...binaried(binary),
|
|
87
|
+
};
|
|
94
88
|
}
|
|
95
89
|
if (typeof file.revision !== 'string')
|
|
96
90
|
return null;
|
|
97
|
-
return {
|
|
91
|
+
return {
|
|
92
|
+
path: file.path,
|
|
93
|
+
revision: file.revision,
|
|
94
|
+
version: file.revision,
|
|
95
|
+
...headed(head),
|
|
96
|
+
...binaried(binary),
|
|
97
|
+
};
|
|
98
98
|
}
|
|
99
99
|
function parseScope(value, mode) {
|
|
100
100
|
if (typeof value !== 'object' || value === null)
|
|
@@ -130,12 +130,7 @@ function parseScope(value, mode) {
|
|
|
130
130
|
return null;
|
|
131
131
|
contents.push({ path: content.path, content: content.content });
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
return { anchor: manifest.anchor, ...at, files, contents };
|
|
135
|
-
const attachments = parseOriginals(held.originals);
|
|
136
|
-
if (attachments === null)
|
|
137
|
-
return null;
|
|
138
|
-
return { anchor: manifest.anchor, ...at, files, contents, attachments };
|
|
133
|
+
return { anchor: manifest.anchor, ...at, files, contents };
|
|
139
134
|
}
|
|
140
135
|
function parseCursor(value) {
|
|
141
136
|
if (typeof value !== 'object' || value === null)
|
|
@@ -174,8 +169,15 @@ function parseChange(value, mode) {
|
|
|
174
169
|
if (held.removed === true)
|
|
175
170
|
return { path: held.path, removed: true };
|
|
176
171
|
const head = headChange(held);
|
|
177
|
-
|
|
172
|
+
const binary = binaryFileOf(held);
|
|
173
|
+
if (head === null || binary === null)
|
|
178
174
|
return null;
|
|
175
|
+
if (binary !== undefined) {
|
|
176
|
+
if (mode === 'credential' && typeof held.revision !== 'string')
|
|
177
|
+
return null;
|
|
178
|
+
const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
|
|
179
|
+
return { path: held.path, binary, revision, version: revision, ...headed(head) };
|
|
180
|
+
}
|
|
179
181
|
if (mode === 'site') {
|
|
180
182
|
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
181
183
|
return null;
|
|
@@ -196,12 +198,6 @@ function parseChange(value, mode) {
|
|
|
196
198
|
...headed(head),
|
|
197
199
|
};
|
|
198
200
|
}
|
|
199
|
-
if (typeof held.reference === 'object' && held.reference !== null) {
|
|
200
|
-
const reference = held.reference;
|
|
201
|
-
if (typeof reference.revision !== 'string')
|
|
202
|
-
return null;
|
|
203
|
-
return { path: held.path, reference: { revision: reference.revision } };
|
|
204
|
-
}
|
|
205
201
|
return null;
|
|
206
202
|
}
|
|
207
203
|
export function parseEnumeration(body, mode) {
|
|
@@ -226,14 +222,7 @@ export function parseEnumeration(body, mode) {
|
|
|
226
222
|
return null;
|
|
227
223
|
changes.push(mapped);
|
|
228
224
|
}
|
|
229
|
-
|
|
230
|
-
authorities.push({ authority: held.authority, ...at, changes });
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
const attachments = parseOriginals(held.originals);
|
|
234
|
-
if (attachments === null)
|
|
235
|
-
return null;
|
|
236
|
-
authorities.push({ authority: held.authority, ...at, changes, attachments });
|
|
225
|
+
authorities.push({ authority: held.authority, ...at, changes });
|
|
237
226
|
}
|
|
238
227
|
return { authorities };
|
|
239
228
|
}
|
|
@@ -245,18 +234,15 @@ export function advancedScope(scope, view) {
|
|
|
245
234
|
contents.delete(change.path);
|
|
246
235
|
if ('removed' in change)
|
|
247
236
|
continue;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
237
|
+
files.set(change.path, {
|
|
238
|
+
path: change.path,
|
|
239
|
+
revision: change.revision,
|
|
240
|
+
version: change.version,
|
|
241
|
+
...headed(change.head),
|
|
242
|
+
...('binary' in change ? { binary: change.binary } : {}),
|
|
243
|
+
});
|
|
244
|
+
if ('content' in change)
|
|
255
245
|
contents.set(change.path, change.content);
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
const { revision } = change.reference;
|
|
259
|
-
files.set(change.path, { path: change.path, revision, version: revision });
|
|
260
246
|
}
|
|
261
247
|
return {
|
|
262
248
|
...scope,
|
|
@@ -274,16 +260,16 @@ export function bootstrapOf(scope) {
|
|
|
274
260
|
const documents = {};
|
|
275
261
|
const revisions = {};
|
|
276
262
|
const changes = {};
|
|
277
|
-
const
|
|
263
|
+
const binaryFiles = {};
|
|
278
264
|
for (const file of scope.files) {
|
|
279
265
|
if (file.revision !== undefined)
|
|
280
266
|
revisions[file.path] = file.revision;
|
|
281
267
|
if (file.head !== undefined)
|
|
282
268
|
changes[file.path] = file.head;
|
|
283
269
|
const content = contents.get(file.path);
|
|
284
|
-
if (
|
|
285
|
-
|
|
286
|
-
else
|
|
270
|
+
if (file.binary !== undefined)
|
|
271
|
+
binaryFiles[file.path] = file.binary;
|
|
272
|
+
else if (content !== undefined)
|
|
287
273
|
documents[file.path] = content;
|
|
288
274
|
}
|
|
289
275
|
return {
|
|
@@ -292,8 +278,7 @@ export function bootstrapOf(scope) {
|
|
|
292
278
|
documents,
|
|
293
279
|
revisions,
|
|
294
280
|
changes,
|
|
295
|
-
|
|
296
|
-
...declared(scope.attachments),
|
|
281
|
+
binaryFiles,
|
|
297
282
|
};
|
|
298
283
|
}
|
|
299
284
|
export function schemaOf(scope, schema) {
|
|
@@ -314,23 +299,21 @@ export function refreshFrom(view, fromRoomVersion) {
|
|
|
314
299
|
const documents = {};
|
|
315
300
|
const revisions = {};
|
|
316
301
|
const changes = {};
|
|
317
|
-
const
|
|
302
|
+
const binaryFiles = {};
|
|
318
303
|
const removals = [];
|
|
319
304
|
for (const change of view.changes) {
|
|
320
305
|
if ('removed' in change) {
|
|
321
306
|
removals.push(change.path);
|
|
322
307
|
continue;
|
|
323
308
|
}
|
|
324
|
-
if ('content' in change)
|
|
309
|
+
if ('content' in change)
|
|
325
310
|
documents[change.path] = change.content;
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
binaryTargets.push(change.path);
|
|
333
|
-
revisions[change.path] = change.reference.revision;
|
|
311
|
+
else
|
|
312
|
+
binaryFiles[change.path] = change.binary;
|
|
313
|
+
if (change.revision !== undefined)
|
|
314
|
+
revisions[change.path] = change.revision;
|
|
315
|
+
if (change.head !== undefined)
|
|
316
|
+
changes[change.path] = change.head;
|
|
334
317
|
}
|
|
335
318
|
return {
|
|
336
319
|
kind: 'net-advancement',
|
|
@@ -338,8 +321,7 @@ export function refreshFrom(view, fromRoomVersion) {
|
|
|
338
321
|
documents,
|
|
339
322
|
revisions,
|
|
340
323
|
changes,
|
|
341
|
-
|
|
324
|
+
binaryFiles,
|
|
342
325
|
removals: removals.sort(),
|
|
343
|
-
...declared(view.attachments),
|
|
344
326
|
};
|
|
345
327
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TrackedAuthority } from './discovery.js';
|
|
2
|
+
export type HouseReferrer = {
|
|
3
|
+
locator: string;
|
|
4
|
+
referrer: Readonly<Record<string, string>>;
|
|
5
|
+
};
|
|
6
|
+
export declare function houseReferrer(referrer: unknown, tracked: ReadonlyMap<string, TrackedAuthority>): HouseReferrer | null;
|
|
7
|
+
//# sourceMappingURL=referrer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"referrer.d.ts","sourceRoot":"","sources":["../src/referrer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAgB5F,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC7C,aAAa,GAAG,IAAI,CAqBtB"}
|
package/dist/referrer.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function fields(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
3
|
+
? value
|
|
4
|
+
: null;
|
|
5
|
+
}
|
|
6
|
+
function named(held, ...keys) {
|
|
7
|
+
const present = Object.keys(held);
|
|
8
|
+
return (present.length === keys.length &&
|
|
9
|
+
keys.every((key) => typeof held[key] === 'string' && held[key] !== ''));
|
|
10
|
+
}
|
|
11
|
+
export function houseReferrer(referrer, tracked) {
|
|
12
|
+
const held = fields(referrer);
|
|
13
|
+
if (held === null)
|
|
14
|
+
return null;
|
|
15
|
+
if (named(held, 'room', 'path')) {
|
|
16
|
+
const entry = tracked.get(held.room);
|
|
17
|
+
if (entry === undefined)
|
|
18
|
+
return null;
|
|
19
|
+
return {
|
|
20
|
+
locator: entry.locator,
|
|
21
|
+
referrer: { room_ref: entry.authority, path: held.path },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (named(held, 'room_ref', 'record')) {
|
|
25
|
+
const roomRef = held.room_ref;
|
|
26
|
+
const entry = [...tracked.values()].find((candidate) => candidate.authority === roomRef);
|
|
27
|
+
return {
|
|
28
|
+
locator: entry?.locator ?? roomRef,
|
|
29
|
+
referrer: { room_ref: roomRef, record: held.record },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (named(held, 'message'))
|
|
33
|
+
return { locator: '', referrer: { message: held.message } };
|
|
34
|
+
return null;
|
|
35
|
+
}
|
package/dist/refusal.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export declare function doorRefusal(body: unknown): DoorRefusal | null;
|
|
6
|
-
export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: DoorRefusal): ScopedRefusal;
|
|
2
|
+
export declare function doorRefusal(body: unknown): ProviderRefusal | null;
|
|
3
|
+
export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
|
|
7
4
|
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
|
|
8
5
|
export declare function classifyRead(status: number, body: unknown, locator: string): AdapterFailure | {
|
|
9
6
|
kind: 'beyond-horizon';
|