@agentshouse/mdruntime-adapter 0.1.0-c4e5de8f794bd → 0.1.0-c4f8432079022

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
@@ -1,32 +1,48 @@
1
+ import { sortedKeys, stepped } from '@agentshouse/mdruntime';
1
2
  import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
2
3
  import { partModels, streamedModels, viewModels } from './model.js';
3
4
  import { gathered, gatheredEach, selections } from './gather.js';
4
5
  import { createSiteAdapter } from './site.js';
5
- import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, viewOf, wholeView, } from './read.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
8
  import { sha256Hex } from './digest.js';
7
9
  import { acceptedHanded, enumeratedHanded, heldHanded, scopeHanded, streamedHanded, } from './handed.js';
8
10
  import { houseAction } from './actions.js';
9
11
  import { classifyDoor, classifyRead, discoveryFailure, doorRefusal } from './refusal.js';
10
12
  import { houseNotifications } from './stream.js';
11
13
  import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
12
- import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
13
- import { houseReferrer } from './referrer.js';
14
+ import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
15
+ import { houseReferrer, houseReferrerScope } from './referrer.js';
16
+ import { HOUSE_ROOM_TYPES } from './room-types.js';
14
17
  import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
15
18
  const UNCERTAIN = { kind: 'transport-uncertainty' };
16
19
  const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
20
+ const EXPIRED_ADDRESS = 403;
17
21
  function lapsedGrant(outcome) {
18
22
  return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
19
23
  }
20
- function heldFiles(authority, held, after, budget) {
21
- if (held === undefined || budget === 0)
22
- return null;
23
- const paths = Object.keys(held.revisions)
24
- .filter((path) => held.documents[path] !== undefined && (after === null || path > after))
25
- .sort();
26
- if (paths.length === 0)
27
- return null;
28
- const files = paths.slice(0, budget).map((path) => ({ path, revision: held.revisions[path] }));
29
- return { room: authority, through: paths.length > budget ? files.at(-1).path : null, files };
24
+ const heldPaths = new WeakMap();
25
+ async function sortedHeld(held) {
26
+ const known = heldPaths.get(held.documents);
27
+ if (known !== undefined)
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
+ }
45
+ return files.length === 0 ? null : { room: authority, through, files };
30
46
  }
31
47
  async function reused(scope, held) {
32
48
  const sent = new Set(scope.contents.map((entry) => entry.path));
@@ -57,42 +73,71 @@ export function createAgentsHouseAdapter(options) {
57
73
  throw new Error('no Discovery declared the bounds');
58
74
  return bounds;
59
75
  }
60
- async function bootstrappedRoom(envelope, sent, asked, continued) {
76
+ function hand(locator, steps) {
77
+ const held = handed.get(locator);
78
+ const next = stepped(steps);
79
+ if (!(next instanceof Promise)) {
80
+ handed.set(locator, next);
81
+ return;
82
+ }
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
+ for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
92
+ const answered = await transport.door(DOOR_BOOTSTRAP, {
93
+ prefixes: [authorityRoot(entry.handle)],
94
+ part: listed.part,
95
+ ...(continued.held === undefined ? {} : { held: [continued.held] }),
96
+ });
97
+ const failure = classifyRead(answered.status, answered.body, entry.locator);
98
+ if (failure !== null)
99
+ return failure;
100
+ const scope = await housePart(continued.room, answered.body, listed, 'credential');
101
+ if (scope !== null)
102
+ return scope;
103
+ }
104
+ return unverifiedPart(entry.locator);
105
+ }
106
+ async function partPage(asked, continued) {
61
107
  const { entry } = asked;
62
- if (sent === undefined)
63
- return { kind: 'room-not-readable', locator: entry.locator };
108
+ const listed = continued.room.parts[continued.next];
109
+ const sent = listed === undefined
110
+ ? emptyScope(continued.room)
111
+ : await fetchedPart(entry, continued, listed);
112
+ if ('kind' in sent)
113
+ return sent;
64
114
  const scope = await reused(sent, asked.held);
65
115
  if (scope === null) {
66
116
  return asked.held === undefined
67
117
  ? UNCERTAIN_READ
68
- : continued === null
69
- ? bootstrapTogether({ entry, held: undefined })
70
- : continuedBootstrap({ entry, held: undefined }, continued);
118
+ : bootstrapTogether({ entry, held: undefined });
71
119
  }
72
- const cursor = envelope.next?.room === entry.authority ? envelope.next : undefined;
73
- const next = cursor?.path ?? null;
74
- if (continued === null && next === null)
75
- handed.set(entry.locator, scopeHanded(scope));
120
+ const next = continued.next + 1;
121
+ const more = next < continued.room.parts.length;
122
+ if (continued.next === 0 && !more)
123
+ await hand(entry.locator, scopeHanded(scope));
76
124
  else
77
125
  handed.delete(entry.locator);
78
126
  notifications.reach(entry.authority, scope);
79
127
  const seen = [
80
- ...(continued?.seen ?? []),
128
+ ...continued.seen,
81
129
  ...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
82
130
  ];
83
- const models = await partModels(scope, entry, new Set(seen), next === null);
84
- const continuation = next === null
85
- ? null
86
- : { after: next, seen, ...(cursor?.cut === undefined ? {} : { cut: cursor.cut }) };
131
+ const models = await partModels(scope, entry, new Set(seen), !more);
87
132
  return {
88
- ...bootstrapOf(scope),
133
+ ...(await stepped(bootstrapping(scope))),
89
134
  ...(models === undefined ? {} : { models }),
90
- ...(continuation === null ? {} : { pageToken: JSON.stringify(continuation) }),
135
+ ...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
91
136
  };
92
137
  }
93
138
  async function enumeratedPage(ask, page) {
94
139
  const answer = await transport.door(DOOR_ENUMERATE, {
95
- prefixes: contentPrefixes(ask.entry),
140
+ prefixes: [authorityRoot(ask.entry.handle)],
96
141
  positions: [
97
142
  {
98
143
  ...presented(ask.entry.authority, { position: page.after, logEpoch: ask.from.logEpoch }),
@@ -116,10 +161,10 @@ export function createAgentsHouseAdapter(options) {
116
161
  if ('kind' in view)
117
162
  return view;
118
163
  notifications.reach(ask.entry.authority, view);
119
- const answer = refreshFrom(view, ask.fromRoomVersion);
164
+ const answer = await refreshFrom(view, ask.fromRoomVersion);
120
165
  if (answer.kind !== 'net-advancement')
121
166
  return answer;
122
- handed.set(ask.entry.locator, enumeratedHanded(view, handed.get(ask.entry.locator)));
167
+ await hand(ask.entry.locator, enumeratedHanded(view, handed.get(ask.entry.locator)));
123
168
  const models = await viewModels(view, ask.entry);
124
169
  return models === undefined ? answer : { ...answer, models };
125
170
  }
@@ -127,10 +172,10 @@ export function createAgentsHouseAdapter(options) {
127
172
  const held = handed.get(entry.locator);
128
173
  if (held?.roomVersion !== request.fromRoomVersion)
129
174
  return null;
130
- const advanced = notifications.advance(entry, from, (path, revision) => held.revisions.get(path) === revision);
175
+ const advanced = await stepped(notifications.advance(entry, from, (path, revision) => held.revisions[path] === revision));
131
176
  if (advanced === null)
132
177
  return null;
133
- handed.set(entry.locator, streamedHanded(held, advanced));
178
+ await hand(entry.locator, streamedHanded(held, advanced));
134
179
  const models = await streamedModels(advanced.schemas, entry, 'credential');
135
180
  return models === undefined ? advanced.page : { ...advanced.page, models };
136
181
  }
@@ -146,14 +191,20 @@ export function createAgentsHouseAdapter(options) {
146
191
  });
147
192
  notifications.send(kept);
148
193
  }
149
- function adopted(entry, outcome) {
194
+ async function adoptedMove(entry, into, outcome) {
195
+ if (outcome.kind === 'accepted' && outcome.destination !== undefined) {
196
+ await adopted(into, { kind: 'accepted', ...outcome.destination });
197
+ }
198
+ return adopted(entry, outcome);
199
+ }
200
+ async function adopted(entry, outcome) {
150
201
  if (outcome.kind !== 'accepted')
151
202
  return outcome;
152
203
  const held = handed.get(entry.locator);
153
204
  if (held === undefined)
154
205
  return outcome;
155
206
  const follows = followsVersion(held.roomVersion, outcome.roomVersion);
156
- handed.set(entry.locator, acceptedHanded(held, outcome, follows ? outcome.roomVersion : held.roomVersion));
207
+ await hand(entry.locator, acceptedHanded(held, outcome, follows ? outcome.roomVersion : held.roomVersion));
157
208
  const at = logPosition(outcome.roomVersion);
158
209
  if (follows && at !== null)
159
210
  notifications.reach(entry.authority, at);
@@ -176,68 +227,62 @@ export function createAgentsHouseAdapter(options) {
176
227
  return result;
177
228
  return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
178
229
  }
179
- function weight(entry) {
180
- return contentPrefixes(entry).length;
181
- }
182
- function holding(asks, after) {
183
- const budget = Math.floor(declared().max_held_files / Math.max(1, asks.filter((ask) => ask.held !== undefined).length));
184
- return asks.flatMap((ask) => heldFiles(ask.entry.authority, ask.held, after, budget) ?? []);
230
+ async function holding(asks) {
231
+ const bound = Math.floor(declared().max_held_files / Math.max(1, asks.filter((ask) => ask.held !== undefined).length));
232
+ const held = [];
233
+ for (const ask of asks) {
234
+ if (ask.held === undefined || bound === 0)
235
+ continue;
236
+ const paths = await sortedHeld(ask.held);
237
+ const files = heldFiles(ask.entry.authority, ask.held, paths, bound);
238
+ if (files !== null)
239
+ held.push(files);
240
+ }
241
+ return held;
185
242
  }
186
243
  async function bootstrapped(asks, answer) {
187
244
  let open = asks.map((asked, ask) => ({ entry: asked.entry, asked, ask }));
188
245
  while (open.length > 0) {
189
246
  const unreached = [];
190
- for (const part of selections(open, ({ entry }) => weight(entry), declared().max_prefixes)) {
191
- const held = holding(part.map(({ asked }) => asked), null);
247
+ for (const part of selections(open, declared().max_prefixes)) {
248
+ const held = await holding(part.map(({ asked }) => asked));
192
249
  const answered = await transport.door(DOOR_BOOTSTRAP, {
193
- prefixes: part.flatMap(({ entry }) => contentPrefixes(entry)),
250
+ prefixes: part.map(({ entry }) => authorityRoot(entry.handle)),
194
251
  ...(held.length === 0 ? {} : { held }),
195
252
  });
196
253
  const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
197
- const envelope = classified[0] === null ? parseEnvelope(answered.body) : null;
254
+ const parted = classified[0] === null ? parseParted(answered.body) : null;
198
255
  for (const [index, asked] of part.entries()) {
199
256
  const failure = classified[index];
200
257
  if (failure !== null && failure !== undefined) {
201
258
  answer(asked.ask, failure);
202
259
  continue;
203
260
  }
204
- if (envelope === null) {
261
+ if (parted === null) {
205
262
  answer(asked.ask, UNCERTAIN_READ);
206
263
  continue;
207
264
  }
208
- const scope = envelope.scopes.find((candidate) => matchesScope(candidate, asked.entry));
209
- if (scope === undefined && envelope.next !== undefined) {
265
+ const room = parted.rooms.find((candidate) => candidate.anchor === asked.entry.authority);
266
+ if (room === undefined && parted.next !== undefined) {
210
267
  unreached.push(asked);
211
268
  continue;
212
269
  }
213
- answer(asked.ask, await bootstrappedRoom(envelope, scope, asked.asked, null));
270
+ if (room === undefined) {
271
+ answer(asked.ask, { kind: 'room-not-readable', locator: asked.entry.locator });
272
+ continue;
273
+ }
274
+ const kept = held.find((files) => files.room === asked.entry.authority);
275
+ answer(asked.ask, await partPage(asked.asked, {
276
+ room,
277
+ next: 0,
278
+ seen: [],
279
+ ...(kept === undefined ? {} : { held: kept }),
280
+ }));
214
281
  }
215
282
  }
216
283
  open = unreached;
217
284
  }
218
285
  }
219
- async function continuedBootstrap(asked, continued) {
220
- const { entry } = asked;
221
- const after = {
222
- room: entry.authority,
223
- path: continued.after,
224
- ...(continued.cut === undefined ? {} : { cut: continued.cut }),
225
- };
226
- const held = holding([asked], continued.after);
227
- const answered = await transport.door(DOOR_BOOTSTRAP, {
228
- prefixes: contentPrefixes(entry),
229
- after,
230
- ...(held.length === 0 ? {} : { held }),
231
- });
232
- const failure = classifyRead(answered.status, answered.body, entry.locator);
233
- if (failure !== null)
234
- return failure;
235
- const envelope = parseEnvelope(answered.body);
236
- if (envelope === null)
237
- return UNCERTAIN_READ;
238
- const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
239
- return bootstrappedRoom(envelope, scope, asked, continued);
240
- }
241
286
  function layered(asks) {
242
287
  const depths = new Map();
243
288
  const layers = [];
@@ -250,12 +295,12 @@ export function createAgentsHouseAdapter(options) {
250
295
  }
251
296
  async function enumerated(asks) {
252
297
  const answers = [];
253
- const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer, ({ ask }) => weight(ask.entry), declared().max_prefixes));
298
+ const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer, declared().max_prefixes));
254
299
  for (const part of parts) {
255
300
  let open = [...part];
256
301
  while (open.length > 0) {
257
302
  const answer = await transport.door(DOOR_ENUMERATE, {
258
- prefixes: open.flatMap(({ ask }) => contentPrefixes(ask.entry)),
303
+ prefixes: open.map(({ ask }) => authorityRoot(ask.entry.handle)),
259
304
  positions: open.map(({ ask }) => presented(ask.entry.authority, ask.from)),
260
305
  });
261
306
  const classified = open.map(({ ask }) => classifyRead(answer.status, answer.body, ask.entry.locator));
@@ -294,10 +339,12 @@ export function createAgentsHouseAdapter(options) {
294
339
  }
295
340
  const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
296
341
  if (minted.status !== 200) {
297
- return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };
342
+ return {
343
+ outcome: await stepped(mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)),
344
+ };
298
345
  }
299
346
  const grant = parseGrant(minted.body);
300
- if (grant === null || grant.method !== 'POST')
347
+ if (grant === null)
301
348
  return { outcome: UNCERTAIN };
302
349
  const delivered = await transport.transfer({
303
350
  act: 'authored_batch_upload',
@@ -307,13 +354,13 @@ export function createAgentsHouseAdapter(options) {
307
354
  if (delivered.status !== 200)
308
355
  return { outcome: UNCERTAIN };
309
356
  const holding = parseGrant(delivered.body);
310
- if (holding === null || holding.method !== 'POST')
357
+ if (holding === null)
311
358
  return { outcome: UNCERTAIN };
312
359
  const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
313
360
  await keep(upload);
314
361
  return { body: { ...head, paths, upload, runtime: notifications.runtime } };
315
362
  }
316
- async function staged(answer, batch) {
363
+ async function staged(answer, { changeBatch: batch, file }) {
317
364
  const refusal = doorRefusal(answer.body);
318
365
  if (refusal?.code !== 'files_unstaged')
319
366
  return null;
@@ -328,7 +375,7 @@ export function createAgentsHouseAdapter(options) {
328
375
  const delivered = await transport.transfer({
329
376
  act: 'binary_stage',
330
377
  url,
331
- body: change.blob,
378
+ body: await file(change.localId),
332
379
  operation,
333
380
  });
334
381
  if (delivered.status !== 200)
@@ -336,7 +383,7 @@ export function createAgentsHouseAdapter(options) {
336
383
  }
337
384
  return true;
338
385
  }
339
- async function submit(batch, head, changes, delta, bytes, entry, handed, keep) {
386
+ async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
340
387
  const inline = { ...head, changes, runtime: notifications.runtime };
341
388
  const prepared = uploadable(inline, bytes, declared())
342
389
  ? await uploaded(head, changes, delta, bytes, entry, handed, keep)
@@ -344,15 +391,20 @@ export function createAgentsHouseAdapter(options) {
344
391
  if ('outcome' in prepared)
345
392
  return prepared.outcome;
346
393
  const answer = await transport.door(DOOR_BATCH, prepared.body);
347
- const stagedFiles = await staged(answer, batch);
394
+ const stagedFiles = await staged(answer, request);
348
395
  if (stagedFiles === false)
349
396
  return UNCERTAIN;
350
397
  const settled = stagedFiles === null ? answer : await transport.door(DOOR_BATCH, prepared.body);
351
- if (stagedFiles === true && (await staged(settled, batch)) !== null)
398
+ if (stagedFiles === true && (await staged(settled, request)) !== null)
352
399
  return UNCERTAIN;
353
- return mutationOutcome(settled.status, settled.body, entry.locator, entry.handle);
400
+ return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
401
+ ? undefined
402
+ : {
403
+ source: { authority: entry.authority, handle: entry.handle },
404
+ destination: { authority: into.authority, handle: into.handle },
405
+ }));
354
406
  }
355
- function granted(answer, locator) {
407
+ function addressed(answer, locator) {
356
408
  const failure = classifyDoor(answer.status, answer.body, locator);
357
409
  if (failure !== null) {
358
410
  return failure.kind === 'scoped-refusal'
@@ -364,33 +416,47 @@ export function createAgentsHouseAdapter(options) {
364
416
  }
365
417
  : failure;
366
418
  }
367
- const grant = parseGrant(answer.body);
368
- const name = answer.body.name;
369
- if (grant === null || grant.method !== 'GET' || typeof name !== 'string') {
370
- return UNCERTAIN_READ;
371
- }
372
- return { kind: 'link', url: grant.url, name };
419
+ const address = parseFileAddress(answer.body);
420
+ return address === null ? UNCERTAIN_READ : { kind: 'address', ...address };
421
+ }
422
+ function linked(answer, locator) {
423
+ const address = addressed(answer, locator);
424
+ return address.kind === 'address'
425
+ ? { kind: 'link', url: address.url, name: address.name }
426
+ : address;
373
427
  }
374
- async function downloaded(answer, locator) {
375
- const link = granted(answer, locator);
376
- if (link.kind !== 'link')
377
- return link;
378
- const read = await transport.download(link.url);
379
- if (read.status !== 200 || read.blob === null)
428
+ async function downloaded(ask, locator) {
429
+ let address = addressed(await ask(), locator);
430
+ if (address.kind !== 'address')
431
+ return address;
432
+ let read = await transport.download(address.url);
433
+ if (read.status === EXPIRED_ADDRESS) {
434
+ address = addressed(await ask(), locator);
435
+ if (address.kind !== 'address')
436
+ return address;
437
+ read = await transport.download(address.url);
438
+ }
439
+ if (read.status !== 200 || read.body === null)
380
440
  return UNCERTAIN_READ;
381
- return { kind: 'binary', blob: read.blob };
441
+ return {
442
+ kind: 'binary',
443
+ body: read.body,
444
+ mediaType: address.mediaType,
445
+ sha256: address.sha256,
446
+ };
382
447
  }
383
- function pathGrant(request) {
448
+ function pathAddress(request) {
384
449
  const entry = authorityFor(request.locator);
385
450
  if (entry === undefined)
386
451
  return null;
387
- return transport.door(DOOR_FILES_GET, {
452
+ return () => transport.door(DOOR_FILES_GET, {
388
453
  room_ref: entry.authority,
389
454
  path: request.path,
390
455
  revision: request.revision,
391
456
  });
392
457
  }
393
458
  return {
459
+ roomTypes: HOUSE_ROOM_TYPES,
394
460
  async authorize() {
395
461
  return options.authorize();
396
462
  },
@@ -440,7 +506,7 @@ export function createAgentsHouseAdapter(options) {
440
506
  return { kind: 'room-not-readable', locator: request.locator };
441
507
  const asked = { entry, held: request.held };
442
508
  if (request.pageToken !== undefined) {
443
- return continuedBootstrap(asked, JSON.parse(request.pageToken));
509
+ return partPage(asked, JSON.parse(request.pageToken));
444
510
  }
445
511
  return bootstrapTogether(asked);
446
512
  },
@@ -462,18 +528,27 @@ export function createAgentsHouseAdapter(options) {
462
528
  const entry = authorityFor(request.locator);
463
529
  if (entry === undefined)
464
530
  return { kind: 'room-not-readable', locator: request.locator };
465
- const mapped = houseChanges(request.changeBatch, entry.handle);
531
+ const batch = request.changeBatch;
532
+ const destination = batch.between?.destination.room;
533
+ const into = destination === undefined ? undefined : authorityFor(destination);
534
+ if (destination !== undefined && into === undefined) {
535
+ return { kind: 'room-not-readable', locator: destination };
536
+ }
537
+ const mapped = into === undefined
538
+ ? houseChanges(batch, entry.handle)
539
+ : houseMove(batch, entry.handle, into.handle);
466
540
  if (mapped.kind === 'unmapped')
467
541
  return rejectedMapping(mapped);
468
- const head = operationHead(request.changeBatch);
542
+ const head = operationHead(batch);
469
543
  const delta = deltaBody(mapped.changes);
470
544
  const bytes = deltaBytes(delta);
471
545
  const handed = request.upload;
472
- const batch = request.changeBatch;
473
- const outcome = await submit(batch, head, mapped.changes, delta, bytes, entry, handed, keep);
546
+ const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
547
+ const settle = (outcome) => into === undefined ? adopted(entry, outcome) : adoptedMove(entry, into, outcome);
548
+ const outcome = await answer(handed);
474
549
  if (handed === undefined || !lapsedGrant(outcome))
475
- return adopted(entry, outcome);
476
- return adopted(entry, await submit(batch, head, mapped.changes, delta, bytes, entry, undefined, keep));
550
+ return settle(outcome);
551
+ return settle(await answer(undefined));
477
552
  },
478
553
  async history(_authorization, request) {
479
554
  const entry = authorityFor(request.locator);
@@ -492,35 +567,25 @@ export function createAgentsHouseAdapter(options) {
492
567
  },
493
568
  async binary(_authorization, request) {
494
569
  if (request.kind === 'path') {
495
- const asked = pathGrant(request);
496
- if (asked === null)
570
+ const ask = pathAddress(request);
571
+ if (ask === null)
497
572
  return { kind: 'room-not-readable', locator: request.locator };
498
- return downloaded(await asked, request.locator);
573
+ return downloaded(ask, request.locator);
499
574
  }
500
575
  const referrer = houseReferrer(request.referrer, tracked);
501
576
  if (referrer === null) {
502
577
  return { kind: 'rejected', code: 'referrer_unknown', fields: {}, retryable: false };
503
578
  }
504
- const answer = await transport.door(DOOR_FILES_GET, {
505
- file: request.fileRef,
506
- referrer: referrer.referrer,
507
- });
508
- return downloaded(answer, referrer.locator);
579
+ return downloaded(() => transport.door(DOOR_FILES_GET, { file: request.fileRef, referrer: referrer.referrer }), referrer.locator);
509
580
  },
510
581
  async link(_authorization, request) {
511
- const asked = pathGrant(request);
512
- if (asked === null)
582
+ const ask = pathAddress(request);
583
+ if (ask === null)
513
584
  return { kind: 'room-not-readable', locator: request.locator };
514
- return granted(await asked, request.locator);
585
+ return linked(await ask(), request.locator);
515
586
  },
516
587
  referrerScope(referrer) {
517
- const held = houseReferrer(referrer, tracked);
518
- if (held === null)
519
- return null;
520
- if (held.locator === '')
521
- return { kind: 'conversations' };
522
- const { path } = held.referrer;
523
- return { kind: 'room', locator: held.locator, ...(path === undefined ? {} : { path }) };
588
+ return houseReferrerScope(referrer, tracked);
524
589
  },
525
590
  reached(locator, version, target) {
526
591
  return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
@@ -16,13 +16,13 @@ export type HouseBounds = {
16
16
  max_held_files: number;
17
17
  change_retention_seconds: number;
18
18
  operation_retention_seconds: number;
19
+ max_move_documents?: number;
19
20
  };
20
21
  export type HouseOperations = {
21
- read: readonly string[];
22
- sync: readonly string[];
23
22
  write: readonly string[];
24
23
  delete: readonly string[];
25
24
  };
25
+ export type HouseReadLevel = 'mcp' | 'online' | 'local';
26
26
  export type HouseModel = {
27
27
  root: string;
28
28
  paths: readonly string[];
@@ -35,6 +35,7 @@ export type HouseAuthority = LogPosition & {
35
35
  houseModel: HouseModel | null;
36
36
  managedReplication: 'admitted' | 'unavailable';
37
37
  protectedPaths: readonly string[];
38
+ read: HouseReadLevel;
38
39
  operations: HouseOperations;
39
40
  };
40
41
  export type HouseDiscoveryDocument = {
@@ -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,EAA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CAAC,QAAQ,EAAE,kBAAkB,GAAG,gBAAgB,EAAE,CAW5E;AAQD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,sBAAsB,GAAG,gBAAgB,EAAE,CAWhF;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,YAAY,CAAC,EAAE,GACnE,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
@@ -17,7 +17,8 @@ const BOUND_KEYS = [
17
17
  'change_retention_seconds',
18
18
  'operation_retention_seconds',
19
19
  ];
20
- const OPERATION_KEYS = ['read', 'sync', 'write', 'delete'];
20
+ const OPERATION_KEYS = ['write', 'delete'];
21
+ const READ_LEVELS = ['mcp', 'online', 'local'];
21
22
  function stringList(value) {
22
23
  if (!Array.isArray(value))
23
24
  return null;
@@ -34,6 +35,12 @@ function parseBounds(value) {
34
35
  return null;
35
36
  bounds[key] = amount;
36
37
  }
38
+ const moves = held.max_move_documents;
39
+ if (moves !== undefined) {
40
+ if (typeof moves !== 'number' || !Number.isFinite(moves))
41
+ return null;
42
+ bounds.max_move_documents = moves;
43
+ }
37
44
  return bounds;
38
45
  }
39
46
  function parseHouseModel(value) {
@@ -85,7 +92,12 @@ function parseAuthority(value) {
85
92
  const houseModel = parseHouseModel(held.house_model);
86
93
  const protectedPaths = stringList(held.protected_paths);
87
94
  const operations = parseOperations(held.operations);
88
- if (at === null || houseModel === undefined || protectedPaths === null || operations === null)
95
+ const read = READ_LEVELS.find((level) => level === held.read);
96
+ if (at === null ||
97
+ houseModel === undefined ||
98
+ protectedPaths === null ||
99
+ read === undefined ||
100
+ operations === null)
89
101
  return null;
90
102
  if (typeof held.room_ref !== 'string' || held.room_ref.length === 0)
91
103
  return null;
@@ -99,6 +111,7 @@ function parseAuthority(value) {
99
111
  houseModel,
100
112
  managedReplication: held.managed_replication,
101
113
  protectedPaths,
114
+ read,
102
115
  operations,
103
116
  ...at,
104
117
  };
@@ -205,8 +218,11 @@ export function providerLimits(bounds) {
205
218
  { name: 'change-documents', value: bounds.max_batch_documents },
206
219
  { name: 'path-length', value: bounds.max_path_length },
207
220
  { name: 'path-depth', value: bounds.max_path_depth },
221
+ ...(bounds.max_move_documents === undefined
222
+ ? []
223
+ : [{ name: 'move-documents', value: bounds.max_move_documents }]),
208
224
  { name: 'write-rate' },
209
- { name: 'content-ceiling' },
225
+ { name: 'storage-limit' },
210
226
  ];
211
227
  }
212
228
  export function declaredRetention(bounds) {
@@ -244,12 +260,14 @@ export function discoveredRoom(authority) {
244
260
  handle: authority.roomHandle,
245
261
  roomVersion: roomVersion(authority),
246
262
  operations: {
247
- read: [...authority.operations.read],
248
- sync: [...authority.operations.sync],
249
263
  write: [...authority.operations.write],
250
264
  delete: [...authority.operations.delete],
251
265
  },
252
- replica: { selection: locator, admission: authority.managedReplication },
266
+ replica: {
267
+ selection: locator,
268
+ admission: authority.managedReplication,
269
+ offline: authority.read === 'online' ? 'locked' : 'open',
270
+ },
253
271
  ...(authority.houseModel === null
254
272
  ? {}
255
273
  : { typedSelection: { roots: [...authority.houseModel.paths] } }),