@agentshouse/mdruntime-adapter 0.1.0-cf6a7cf003c4b → 0.1.0-cfd03209dcd82

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/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 { acceptedLinks, enumeratedLinks, heldLinks, scopeLinks, streamedLinks, } from './links.js';
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, scopeLinks(scope));
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, enumeratedLinks(view, handed.get(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 links = handed.get(entry.locator);
66
- if (links?.roomVersion !== request.fromRoomVersion)
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) => links.revisions.get(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
- const relinked = streamedLinks(links, advanced);
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, heldLinks(room));
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 { originals, ...accepted } = outcome;
94
- const links = handed.get(entry.locator);
95
- if (links === undefined)
96
- return accepted;
97
- const follows = followsVersion(links.roomVersion, accepted.roomVersion);
98
- const relinked = acceptedLinks(links, accepted, follows ? accepted.roomVersion : links.roomVersion, originals);
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 relinked.attachments === undefined
104
- ? accepted
105
- : { ...accepted, attachments: relinked.attachments };
99
+ return outcome;
106
100
  }
107
101
  function authorityFor(locator) {
108
102
  return tracked.get(locator);
@@ -244,7 +238,30 @@ export function createAgentsHouseAdapter(options) {
244
238
  await keep(upload);
245
239
  return { body: { ...head, paths, upload, runtime: notifications.runtime } };
246
240
  }
247
- async function submit(head, changes, delta, bytes, entry, handed, keep) {
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) {
248
265
  const inline = { ...head, changes, runtime: notifications.runtime };
249
266
  const prepared = uploadable(inline, bytes, declared())
250
267
  ? await uploaded(head, changes, delta, bytes, entry, handed, keep)
@@ -252,7 +269,33 @@ export function createAgentsHouseAdapter(options) {
252
269
  if ('outcome' in prepared)
253
270
  return prepared.outcome;
254
271
  const answer = await transport.door(DOOR_BATCH, prepared.body);
255
- return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);
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 };
256
299
  }
257
300
  return {
258
301
  async authorize() {
@@ -314,10 +357,11 @@ export function createAgentsHouseAdapter(options) {
314
357
  const delta = deltaBody(mapped.changes);
315
358
  const bytes = deltaBytes(delta);
316
359
  const handed = request.upload;
317
- const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);
360
+ const batch = request.changeBatch;
361
+ const outcome = await submit(batch, head, mapped.changes, delta, bytes, entry, handed, keep);
318
362
  if (handed === undefined || !lapsedGrant(outcome))
319
363
  return adopted(entry, outcome);
320
- 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));
321
365
  },
322
366
  async history(_authorization, request) {
323
367
  const entry = authorityFor(request.locator);
@@ -334,6 +378,37 @@ export function createAgentsHouseAdapter(options) {
334
378
  ...(request.revision === undefined ? {} : { revision: request.revision }),
335
379
  });
336
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
+ },
337
412
  reached(locator, version, target) {
338
413
  return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
339
414
  },
@@ -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,o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,CAW5E;AAQD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,sBAAsB,GAAG,gBAAgB,EAAE,CAWhF;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,aAAa,EAAE,CAU5E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAMhE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,sBAAsB,GAAG,SAAS,UAAU,EAAE,CAWpF;AAED,wBAAgB,gBAAgB,IAAI,SAAS,UAAU,EAAE,CAOxD;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,cAAc,GAAG,cAAc,CAmBxE;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
@@ -1,4 +1,4 @@
1
- import { declaredActions, houseConversationAgents } from './actions.js';
1
+ import { declaredActions, houseConversationAgents, SITE_SUBMIT } from './actions.js';
2
2
  import { readPosition, roomVersion } from './version.js';
3
3
  export const PROVIDER_ACTIONS = 'provider-actions';
4
4
  export const DISCOVER_PREFIXES = ['/'];
@@ -229,7 +229,10 @@ export function capabilities(document) {
229
229
  }
230
230
  export function siteCapabilities() {
231
231
  return [
232
- { name: PROVIDER_ACTIONS, actions: [{ name: 'submit', inputShape: {}, resultKind: 'house' }] },
232
+ {
233
+ name: PROVIDER_ACTIONS,
234
+ actions: [{ name: SITE_SUBMIT, inputShape: {}, resultKind: 'house' }],
235
+ },
233
236
  ];
234
237
  }
235
238
  export function discoveredRoom(authority) {
@@ -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,4 +1,4 @@
1
1
  export { createAgentsHouseAdapter, type AgentsHouseAdapterOptions } from './adapter.js';
2
- export { HOUSE_APP_ACTS } from './actions.js';
3
- export type { HouseByteAct, HouseByteTransfer, HouseDoorAnswer, HouseHeldRoom, HouseOpening, HouseStream, HouseStreamEntry, HouseStreamFrame, HouseSiteTransport, HouseTransport, } from './transport.js';
2
+ export { HOUSE_APP_ACTS, HOUSE_APP_BATCHES, HOUSE_SITE_ACTS } from './actions.js';
3
+ export type { HouseByteAct, HouseByteTransfer, HouseBytesAnswer, HouseDoorAnswer, HouseHeldRoom, HouseOpening, HouseStream, HouseStreamEntry, HouseStreamFrame, HouseSiteTransport, HouseTransport, } from './transport.js';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -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,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC"}
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,eAAe,EAAE,MAAM,cAAc,CAAC;AAClF,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
@@ -1,2 +1,2 @@
1
1
  export { createAgentsHouseAdapter } from './adapter.js';
2
- export { HOUSE_APP_ACTS } from './actions.js';
2
+ export { HOUSE_APP_ACTS, HOUSE_APP_BATCHES, HOUSE_SITE_ACTS } from './actions.js';
package/dist/read.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BootstrapPage, RefreshResult, RoomAttachment } from '@agentshouse/mdruntime';
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
- reference: {
50
- revision: string;
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,6 +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 binaryFileOf(held: Readonly<Record<string, unknown>>): BinaryFile | undefined | null;
69
70
  export declare function parseEnvelope(body: unknown): HouseEnvelope | null;
70
71
  export declare function parseSiteBootstrap(body: unknown): HouseScope | null;
71
72
  export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
@@ -1 +1 @@
1
- {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,EACb,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,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E,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,8 +51,19 @@ export function headChange(held) {
51
51
  function headed(head) {
52
52
  return head === undefined ? {} : { head };
53
53
  }
54
- function declared(attachments) {
55
- return attachments === undefined ? {} : { attachments };
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')
62
+ return null;
63
+ return { fileRef: file, byteLength: bytes, mediaType, sha256 };
64
+ }
65
+ function binaried(binary) {
66
+ return binary === undefined ? {} : { binary };
56
67
  }
57
68
  function parseFile(value, mode) {
58
69
  if (typeof value !== 'object' || value === null)
@@ -61,16 +72,29 @@ function parseFile(value, mode) {
61
72
  if (typeof file.path !== 'string')
62
73
  return null;
63
74
  const head = headChange(file);
64
- if (head === null)
75
+ const binary = binaryFileOf(file);
76
+ if (head === null || binary === null)
65
77
  return null;
66
78
  if (mode === 'site') {
67
79
  if (typeof file.sha256 !== 'string')
68
80
  return null;
69
- return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };
81
+ return {
82
+ path: file.path,
83
+ revision: binary?.sha256,
84
+ version: file.sha256,
85
+ ...headed(head),
86
+ ...binaried(binary),
87
+ };
70
88
  }
71
89
  if (typeof file.revision !== 'string')
72
90
  return null;
73
- return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };
91
+ return {
92
+ path: file.path,
93
+ revision: file.revision,
94
+ version: file.revision,
95
+ ...headed(head),
96
+ ...binaried(binary),
97
+ };
74
98
  }
75
99
  function parseScope(value, mode) {
76
100
  if (typeof value !== 'object' || value === null)
@@ -106,9 +130,7 @@ function parseScope(value, mode) {
106
130
  return null;
107
131
  contents.push({ path: content.path, content: content.content });
108
132
  }
109
- if (mode === 'site')
110
- return { anchor: manifest.anchor, ...at, files, contents };
111
- return { anchor: manifest.anchor, ...at, files, contents, attachments: [] };
133
+ return { anchor: manifest.anchor, ...at, files, contents };
112
134
  }
113
135
  function parseCursor(value) {
114
136
  if (typeof value !== 'object' || value === null)
@@ -147,8 +169,15 @@ function parseChange(value, mode) {
147
169
  if (held.removed === true)
148
170
  return { path: held.path, removed: true };
149
171
  const head = headChange(held);
150
- if (head === null)
172
+ const binary = binaryFileOf(held);
173
+ if (head === null || binary === null)
151
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
+ }
152
181
  if (mode === 'site') {
153
182
  if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
154
183
  return null;
@@ -169,12 +198,6 @@ function parseChange(value, mode) {
169
198
  ...headed(head),
170
199
  };
171
200
  }
172
- if (typeof held.reference === 'object' && held.reference !== null) {
173
- const reference = held.reference;
174
- if (typeof reference.revision !== 'string')
175
- return null;
176
- return { path: held.path, reference: { revision: reference.revision } };
177
- }
178
201
  return null;
179
202
  }
180
203
  export function parseEnumeration(body, mode) {
@@ -199,11 +222,7 @@ export function parseEnumeration(body, mode) {
199
222
  return null;
200
223
  changes.push(mapped);
201
224
  }
202
- if (mode === 'site') {
203
- authorities.push({ authority: held.authority, ...at, changes });
204
- continue;
205
- }
206
- authorities.push({ authority: held.authority, ...at, changes, attachments: [] });
225
+ authorities.push({ authority: held.authority, ...at, changes });
207
226
  }
208
227
  return { authorities };
209
228
  }
@@ -215,18 +234,15 @@ export function advancedScope(scope, view) {
215
234
  contents.delete(change.path);
216
235
  if ('removed' in change)
217
236
  continue;
218
- if ('content' in change) {
219
- files.set(change.path, {
220
- path: change.path,
221
- revision: change.revision,
222
- version: change.version,
223
- ...headed(change.head),
224
- });
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)
225
245
  contents.set(change.path, change.content);
226
- continue;
227
- }
228
- const { revision } = change.reference;
229
- files.set(change.path, { path: change.path, revision, version: revision });
230
246
  }
231
247
  return {
232
248
  ...scope,
@@ -244,16 +260,16 @@ export function bootstrapOf(scope) {
244
260
  const documents = {};
245
261
  const revisions = {};
246
262
  const changes = {};
247
- const binaryTargets = [];
263
+ const binaryFiles = {};
248
264
  for (const file of scope.files) {
249
265
  if (file.revision !== undefined)
250
266
  revisions[file.path] = file.revision;
251
267
  if (file.head !== undefined)
252
268
  changes[file.path] = file.head;
253
269
  const content = contents.get(file.path);
254
- if (content === undefined)
255
- binaryTargets.push(file.path);
256
- else
270
+ if (file.binary !== undefined)
271
+ binaryFiles[file.path] = file.binary;
272
+ else if (content !== undefined)
257
273
  documents[file.path] = content;
258
274
  }
259
275
  return {
@@ -262,8 +278,7 @@ export function bootstrapOf(scope) {
262
278
  documents,
263
279
  revisions,
264
280
  changes,
265
- binaryTargets: binaryTargets.sort(),
266
- ...declared(scope.attachments),
281
+ binaryFiles,
267
282
  };
268
283
  }
269
284
  export function schemaOf(scope, schema) {
@@ -284,23 +299,21 @@ export function refreshFrom(view, fromRoomVersion) {
284
299
  const documents = {};
285
300
  const revisions = {};
286
301
  const changes = {};
287
- const binaryTargets = [];
302
+ const binaryFiles = {};
288
303
  const removals = [];
289
304
  for (const change of view.changes) {
290
305
  if ('removed' in change) {
291
306
  removals.push(change.path);
292
307
  continue;
293
308
  }
294
- if ('content' in change) {
309
+ if ('content' in change)
295
310
  documents[change.path] = change.content;
296
- if (change.revision !== undefined)
297
- revisions[change.path] = change.revision;
298
- if (change.head !== undefined)
299
- changes[change.path] = change.head;
300
- continue;
301
- }
302
- binaryTargets.push(change.path);
303
- 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;
304
317
  }
305
318
  return {
306
319
  kind: 'net-advancement',
@@ -308,8 +321,7 @@ export function refreshFrom(view, fromRoomVersion) {
308
321
  documents,
309
322
  revisions,
310
323
  changes,
311
- binaryTargets: binaryTargets.sort(),
324
+ binaryFiles,
312
325
  removals: removals.sort(),
313
- ...declared(view.attachments),
314
326
  };
315
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"}
@@ -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
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAMR,MAAM,wBAAwB,CAAC;AAsBhC,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAgCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAwIxE"}
1
+ {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAOR,MAAM,wBAAwB,CAAC;AAsBhC,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAiCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CA8KxE"}