@agentshouse/mdruntime-adapter 0.1.0-cedab65f24a09 → 0.1.0-cedb8e57837a7

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 CHANGED
@@ -5,8 +5,8 @@ change it, build, and push. They are documentation, not enforcement.
5
5
 
6
6
  ## The MD Runtime API
7
7
 
8
- App code reaches the MD Runtime through the remote client. The surfaces are Rooms,
9
- Query, Search, Observe, Types, Room Draft, Save, History, the binary file reads, Call,
8
+ App code reaches the MD Runtime through the remote client. The surfaces are Rooms, Query,
9
+ Search, Observe, Types, Room Draft, Save, History, Resolve, the binary file reads, Call,
10
10
  Reached, Log, the reported persistence answer, reauthorization, conversation, the chat
11
11
  draft, and Presentation State. Sync Status, readiness, the Service Mode, the storage-loss
12
12
  statement, the deployment facts and the signed-in member are observations only.
@@ -77,7 +77,7 @@ author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`; History of a Pat
77
77
  document holds answers the removed document's revisions, newest first, with `deleted:
78
78
  true`, which a link to the Path opens. Every member is asynchronous and every result a
79
79
  detached snapshot; nothing returns the authorization, performs a request the App's code
80
- composes, or exposes the browser store.
80
+ composes, or exposes the browser store. A Room `rooms` names `locked` shows only online.
81
81
 
82
82
  Every refusal and failure carries `code` and `retryable`: each Call and History answer
83
83
  other than its result, a refused Save or Room Draft write, a returned Room Draft's reason,
@@ -101,8 +101,8 @@ named; signing out answers `null`, then ends the observation with the authorizat
101
101
  hears it again only when it changes, keeping every unchanged Document the same object, so
102
102
  a component can tell what changed by identity. `{ documents, coverage }` or `{ groups,
103
103
  coverage }` is complete for the Rooms its `coverage` names, and `{ pending }` names each
104
- Room not yet acquired or prepared, `[{ room, awaits }]`: never read it as empty, draw it
105
- as loading and observe the query to hear the complete answer. A query is data:
104
+ Room not yet acquired, prepared or unlocked, `[{ room, awaits }]`: never read it as empty,
105
+ draw it as loading and observe the query to hear the complete answer. A query is data:
106
106
 
107
107
  - **Filter.** `rooms` names Room locators and defaults to every Room. `types` names MD
108
108
  Types, and `any` names untyped Markdown Documents. `pathPrefix` is a directory: `notes`
@@ -119,10 +119,13 @@ as loading and observe the query to hear the complete answer. A query is data:
119
119
  compares in calendar order and never with a date-time. A reference compares by the
120
120
  Room Path it resolves to. Untyped frontmatter, and a value under `oneOf` or a
121
121
  conditional, is plain values. There is no text containment or regular expression.
122
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
123
- reference at pointer `field`, at any depth, points to a matching Document of the same
124
- Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a matching
125
- Document of the same Room references. Each keeps a Document once.
122
+ - **Relations.** Within one Room, `hop: { field, types, where, pathPrefix }` keeps Documents
123
+ whose reference at pointer `field`, at any depth, points to a matching Document, and
124
+ `backlinks` with the same keys those a matching Document references, each once. A body
125
+ link, or a reference declaring `cross_room`, may name another Room's
126
+ `/rooms/<handle>/<path>`: `resolve(room, path, destination)` answers its `document`, the
127
+ `deleted` one's last `revision`, or `unreadable` where the App does not bind it or it is
128
+ locked.
126
129
  - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
127
130
  `preamble`, `markdown`, `backlinks`, `change` and `fileId`, where `fields` is `'all'`
128
131
  or a list of pointers and `sections` `'all'` or a list of names. Selected pointers
@@ -185,22 +188,24 @@ once, by words, from local state, with MiniSearch's defaults. There is no observ
185
188
 
186
189
  The MD Runtime owns one durable Room Draft per Room and Path, shared by every App and tab
187
190
  across reloads; a Room the Provider reports lost takes its Room Drafts and queue with it.
188
- Write one with `roomDraft.write(room, path, revision, parts)`, naming the revision you
189
- read or `null`, and every part it now changes: fields, sections and the preamble, or the
190
- whole Markdown, a creation, a move or a removal. A new part names its base, the value you
191
- showed when it was opened, a field's as `{ value }` or `null` for no such field, and keeps
192
- its first base; a binary Path entry's move or removal takes `null`. A write or discard
193
- from an older revision is refused as `stale` with the current Room Draft.
191
+ Write one with `roomDraft.write(room, path, revision, parts)`, naming the revision you read
192
+ or `null`, and every part it now changes: fields, sections and the preamble, or the whole
193
+ Markdown, a creation, a move, into another Room when it names `room`, or a removal. A new
194
+ part names its base, the value you showed when it was opened, a field's as `{ value }` or
195
+ `null` for no such field, and keeps its first base; a binary Path entry's move or removal
196
+ takes `null`. A write or discard from an older revision is refused as `stale` with the
197
+ current Room Draft.
194
198
 
195
199
  Save takes one Room and the Room Drafts of it to save, each with its revision, validates
196
- locally, and on success appends one Change Batch to that Room's queue and removes those
197
- Room Drafts. Refused as `stale`, `changed-underneath` naming each part whose base no
198
- longer matches the visible state, or a local validation rule, it creates nothing and
199
- leaves every Room Draft. A directory move or removal is that part on each Document and
200
- binary Path entry beneath it, saved together. `saveParts(room, [{ path, parts }])` saves
201
- parts, each Path once and each new part with its base, the same way but writes no Room
202
- Draft: one held at a saved Path stays, one at a moved Path moves with it to a destination
203
- that holds none. Never save by writing back a Room Draft read before.
200
+ locally, and on success appends one Change Batch to that Room's queue and removes those Room
201
+ Drafts. Refused as `stale`, `changed-underneath` naming each part whose base no longer
202
+ matches the visible state, or a local validation rule, it creates nothing and leaves every
203
+ Room Draft. A directory move or removal is that part on each Document and binary Path entry
204
+ beneath it, saved together; moves into another Room, saved alone, are one Change Batch in
205
+ both Rooms' queues. `saveParts(room, [{ path, parts }])` saves parts, each Path once and
206
+ each new part with its base, the same way but writes no Room Draft: one held at a saved Path
207
+ stays, one at a moved Path moves with it to a destination that holds none. Never save by
208
+ writing back a Room Draft read before.
204
209
 
205
210
  Outcomes follow the Provider's answer. An Accepted Change Batch stays in the queue, drawn
206
211
  over the confirmed layer, until that layer reaches the Room Version it was accepted at.
package/dist/actions.d.ts CHANGED
@@ -28,6 +28,9 @@ export type AppInputs = {
28
28
  readonly text?: string;
29
29
  readonly files?: readonly SentFile[];
30
30
  };
31
+ readonly 'trigger.list': {
32
+ readonly room_refs: readonly string[];
33
+ };
31
34
  };
32
35
  export type AppAnswers = {
33
36
  readonly 'conversation.history': ConversationHistories;
@@ -1 +1 @@
1
- {"version":3,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AE,SAAS;YACzB,QAAQ,CAAC,WAAW,EAAE,SAAS;gBAC7B,QAAQ,CAAC,QAAQ,EAAE;oBAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;oBAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;iBAAE,CAAC;aAC3E,EAAE,CAAC;SACL,EAAE,CAAC;KACL,CAAC;CACH,CAAC;AA4EF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE3D,CAAC;AAEF,eAAO,MAAM,WAAW,WAAW,CAAC;AAEpC,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE5D,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAKhF,CAAC;AAYJ,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAE3E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAKvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AA6ED,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAQjF;AAuKD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAiBtE"}
package/dist/actions.js CHANGED
@@ -2,6 +2,7 @@ import { changeBatchIdentity, } from '@agentshouse/mdruntime';
2
2
  import { doorRefusal } from './refusal.js';
3
3
  const HISTORY_PAGE = 100;
4
4
  const HISTORY_CONVERSATIONS = 64;
5
+ const TRIGGER_ROOMS = 100;
5
6
  const OCTET_STREAM = 'application/octet-stream';
6
7
  function mapped(door, input = (given) => given) {
7
8
  return {
@@ -11,10 +12,11 @@ function mapped(door, input = (given) => given) {
11
12
  },
12
13
  };
13
14
  }
14
- function carried(door, carry, batched) {
15
+ function carried(door, carry, batched, room) {
15
16
  return {
16
17
  door,
17
18
  ...(batched === undefined ? {} : { batched }),
19
+ ...(room === undefined ? {} : { room }),
18
20
  carry: (transport, input, name) => carry(transport, `/door/${door}`, input, name),
19
21
  };
20
22
  }
@@ -28,6 +30,7 @@ const APP_ACTS = {
28
30
  'conversation.kill': mapped('conversations/kill', controlBody),
29
31
  'conversation.markDone': mapped('conversations/done'),
30
32
  'conversation.rename': mapped('conversations/rename'),
33
+ 'conversation.retry': mapped('conversations/retry'),
31
34
  'conversation.send': carried('conversations/send', sendAction),
32
35
  'conversation.setOption': mapped('conversations/option'),
33
36
  'feature.list': mapped('apps/features/read'),
@@ -43,7 +46,7 @@ const APP_ACTS = {
43
46
  'routineAllowance.list': mapped('routines/allowance'),
44
47
  'routineRequest.list': mapped('routines/requests'),
45
48
  'storage.read': mapped('storage/inventory'),
46
- 'trigger.list': mapped('triggers/read'),
49
+ 'trigger.list': carried('triggers/read', triggersAction, ['room_refs'], 'room_refs'),
47
50
  'triggerOccurrence.list': mapped('triggers/fired'),
48
51
  };
49
52
  export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
@@ -53,15 +56,15 @@ export const HOUSE_SITE_ACTS = {
53
56
  };
54
57
  export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
55
58
  const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
59
+ const APP_ROOMS = new Map(Object.entries(APP_ACTS).flatMap(([name, act]) => act.room === undefined ? [] : [[name, act.room]]));
56
60
  export function houseConversationAgents(locator) {
57
61
  return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
58
62
  }
59
63
  export function declaredActions(routes) {
60
- return routes.map((route) => ({
61
- name: APP_NAMES.get(route) ?? route,
62
- inputShape: {},
63
- resultKind: 'house',
64
- }));
64
+ return routes.map((route) => {
65
+ const name = APP_NAMES.get(route) ?? route;
66
+ return { name, inputShape: {}, resultKind: 'house', room: APP_ROOMS.get(name) ?? 'room_ref' };
67
+ });
65
68
  }
66
69
  export function houseAction(transport, request) {
67
70
  if (Object.hasOwn(APP_ACTS, request.name)) {
@@ -351,6 +354,22 @@ function historyAsks(input) {
351
354
  }
352
355
  return asks;
353
356
  }
357
+ async function triggersAction(transport, route, input, name) {
358
+ const asked = record(input).room_refs;
359
+ if (!Array.isArray(asked) || asked.length === 0)
360
+ return malformed();
361
+ const rooms = [];
362
+ for (let at = 0; at < asked.length; at += TRIGGER_ROOMS) {
363
+ const outcome = actionOutcome(await transport.door(route, { room_refs: asked.slice(at, at + TRIGGER_ROOMS) }), name);
364
+ if (outcome.kind !== 'action')
365
+ return outcome;
366
+ const answered = record(outcome.result).rooms;
367
+ if (!Array.isArray(answered))
368
+ return { kind: 'transport-uncertainty' };
369
+ rooms.push(...answered);
370
+ }
371
+ return { kind: 'action', result: { rooms } };
372
+ }
354
373
  async function historyAction(transport, route, input, name) {
355
374
  const asks = historyAsks(input);
356
375
  if (asks === null)
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EACP,aAAa,EAmBd,MAAM,wBAAwB,CAAC;AA4ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAyBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAsErD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAsjBpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EACP,aAAa,EAmBd,MAAM,wBAAwB,CAAC;AA6ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AA0BxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAyFrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA8mBpF"}
package/dist/adapter.js CHANGED
@@ -1,15 +1,16 @@
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, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, viewOf, wholeView, } from './read.js';
6
7
  import { sha256Hex } from './digest.js';
7
8
  import { acceptedHanded, enumeratedHanded, heldHanded, scopeHanded, streamedHanded, } from './handed.js';
8
9
  import { houseAction } from './actions.js';
9
10
  import { classifyDoor, classifyRead, discoveryFailure, doorRefusal } from './refusal.js';
10
11
  import { houseNotifications } from './stream.js';
11
12
  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 { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
13
14
  import { houseReferrer } from './referrer.js';
14
15
  import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
15
16
  const UNCERTAIN = { kind: 'transport-uncertainty' };
@@ -17,16 +18,36 @@ const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
17
18
  function lapsedGrant(outcome) {
18
19
  return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
19
20
  }
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 };
21
+ const heldPaths = new WeakMap();
22
+ async function sortedHeld(held) {
23
+ const known = heldPaths.get(held.documents);
24
+ if (known !== undefined)
25
+ return known;
26
+ const sorted = await stepped(sortedKeys(held.documents));
27
+ heldPaths.set(held.documents, sorted);
28
+ return sorted;
29
+ }
30
+ function heldFiles(authority, held, paths, after, bound) {
31
+ let low = 0;
32
+ for (let high = paths.length; low < high;) {
33
+ const middle = (low + high) >>> 1;
34
+ if (after !== null && paths[middle] <= after)
35
+ low = middle + 1;
36
+ else
37
+ high = middle;
38
+ }
39
+ const files = [];
40
+ let through = null;
41
+ for (let at = low; at < paths.length && through === null; at += 1) {
42
+ const revision = held.revisions[paths[at]];
43
+ if (revision === undefined)
44
+ continue;
45
+ if (files.length === bound)
46
+ through = files.at(-1).path;
47
+ else
48
+ files.push({ path: paths[at], revision });
49
+ }
50
+ return files.length === 0 ? null : { room: authority, through, files };
30
51
  }
31
52
  async function reused(scope, held) {
32
53
  const sent = new Set(scope.contents.map((entry) => entry.path));
@@ -57,6 +78,20 @@ export function createAgentsHouseAdapter(options) {
57
78
  throw new Error('no Discovery declared the bounds');
58
79
  return bounds;
59
80
  }
81
+ function hand(locator, steps) {
82
+ const held = handed.get(locator);
83
+ const next = stepped(steps);
84
+ if (!(next instanceof Promise)) {
85
+ handed.set(locator, next);
86
+ return;
87
+ }
88
+ return next.then((room) => {
89
+ if (handed.get(locator) === held)
90
+ handed.set(locator, room);
91
+ else
92
+ handed.delete(locator);
93
+ });
94
+ }
60
95
  async function bootstrappedRoom(envelope, sent, asked, continued) {
61
96
  const { entry } = asked;
62
97
  if (sent === undefined)
@@ -72,7 +107,7 @@ export function createAgentsHouseAdapter(options) {
72
107
  const cursor = envelope.next?.room === entry.authority ? envelope.next : undefined;
73
108
  const next = cursor?.path ?? null;
74
109
  if (continued === null && next === null)
75
- handed.set(entry.locator, scopeHanded(scope));
110
+ await hand(entry.locator, scopeHanded(scope));
76
111
  else
77
112
  handed.delete(entry.locator);
78
113
  notifications.reach(entry.authority, scope);
@@ -85,14 +120,14 @@ export function createAgentsHouseAdapter(options) {
85
120
  ? null
86
121
  : { after: next, seen, ...(cursor?.cut === undefined ? {} : { cut: cursor.cut }) };
87
122
  return {
88
- ...bootstrapOf(scope),
123
+ ...(await stepped(bootstrapping(scope))),
89
124
  ...(models === undefined ? {} : { models }),
90
125
  ...(continuation === null ? {} : { pageToken: JSON.stringify(continuation) }),
91
126
  };
92
127
  }
93
128
  async function enumeratedPage(ask, page) {
94
129
  const answer = await transport.door(DOOR_ENUMERATE, {
95
- prefixes: contentPrefixes(ask.entry),
130
+ prefixes: [authorityRoot(ask.entry.handle)],
96
131
  positions: [
97
132
  {
98
133
  ...presented(ask.entry.authority, { position: page.after, logEpoch: ask.from.logEpoch }),
@@ -116,10 +151,10 @@ export function createAgentsHouseAdapter(options) {
116
151
  if ('kind' in view)
117
152
  return view;
118
153
  notifications.reach(ask.entry.authority, view);
119
- const answer = refreshFrom(view, ask.fromRoomVersion);
154
+ const answer = await refreshFrom(view, ask.fromRoomVersion);
120
155
  if (answer.kind !== 'net-advancement')
121
156
  return answer;
122
- handed.set(ask.entry.locator, enumeratedHanded(view, handed.get(ask.entry.locator)));
157
+ await hand(ask.entry.locator, enumeratedHanded(view, handed.get(ask.entry.locator)));
123
158
  const models = await viewModels(view, ask.entry);
124
159
  return models === undefined ? answer : { ...answer, models };
125
160
  }
@@ -127,10 +162,10 @@ export function createAgentsHouseAdapter(options) {
127
162
  const held = handed.get(entry.locator);
128
163
  if (held?.roomVersion !== request.fromRoomVersion)
129
164
  return null;
130
- const advanced = notifications.advance(entry, from, (path, revision) => held.revisions.get(path) === revision);
165
+ const advanced = await stepped(notifications.advance(entry, from, (path, revision) => held.revisions[path] === revision));
131
166
  if (advanced === null)
132
167
  return null;
133
- handed.set(entry.locator, streamedHanded(held, advanced));
168
+ await hand(entry.locator, streamedHanded(held, advanced));
134
169
  const models = await streamedModels(advanced.schemas, entry, 'credential');
135
170
  return models === undefined ? advanced.page : { ...advanced.page, models };
136
171
  }
@@ -146,14 +181,20 @@ export function createAgentsHouseAdapter(options) {
146
181
  });
147
182
  notifications.send(kept);
148
183
  }
149
- function adopted(entry, outcome) {
184
+ async function adoptedMove(entry, into, outcome) {
185
+ if (outcome.kind === 'accepted' && outcome.destination !== undefined) {
186
+ await adopted(into, { kind: 'accepted', ...outcome.destination });
187
+ }
188
+ return adopted(entry, outcome);
189
+ }
190
+ async function adopted(entry, outcome) {
150
191
  if (outcome.kind !== 'accepted')
151
192
  return outcome;
152
193
  const held = handed.get(entry.locator);
153
194
  if (held === undefined)
154
195
  return outcome;
155
196
  const follows = followsVersion(held.roomVersion, outcome.roomVersion);
156
- handed.set(entry.locator, acceptedHanded(held, outcome, follows ? outcome.roomVersion : held.roomVersion));
197
+ await hand(entry.locator, acceptedHanded(held, outcome, follows ? outcome.roomVersion : held.roomVersion));
157
198
  const at = logPosition(outcome.roomVersion);
158
199
  if (follows && at !== null)
159
200
  notifications.reach(entry.authority, at);
@@ -176,25 +217,31 @@ export function createAgentsHouseAdapter(options) {
176
217
  return result;
177
218
  return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
178
219
  }
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) ?? []);
220
+ async function holding(asks, after) {
221
+ const bound = Math.floor(declared().max_held_files / Math.max(1, asks.filter((ask) => ask.held !== undefined).length));
222
+ const held = [];
223
+ for (const ask of asks) {
224
+ if (ask.held === undefined || bound === 0)
225
+ continue;
226
+ const paths = await sortedHeld(ask.held);
227
+ const files = heldFiles(ask.entry.authority, ask.held, paths, after, bound);
228
+ if (files !== null)
229
+ held.push(files);
230
+ }
231
+ return held;
185
232
  }
186
233
  async function bootstrapped(asks, answer) {
187
234
  let open = asks.map((asked, ask) => ({ entry: asked.entry, asked, ask }));
188
235
  while (open.length > 0) {
189
236
  const unreached = [];
190
- for (const part of selections(open, ({ entry }) => weight(entry), declared().max_prefixes)) {
191
- const held = holding(part.map(({ asked }) => asked), null);
237
+ for (const part of selections(open, declared().max_prefixes)) {
238
+ const held = await holding(part.map(({ asked }) => asked), null);
192
239
  const answered = await transport.door(DOOR_BOOTSTRAP, {
193
- prefixes: part.flatMap(({ entry }) => contentPrefixes(entry)),
240
+ prefixes: part.map(({ entry }) => authorityRoot(entry.handle)),
194
241
  ...(held.length === 0 ? {} : { held }),
195
242
  });
196
243
  const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
197
- const envelope = classified[0] === null ? parseEnvelope(answered.body) : null;
244
+ const envelope = classified[0] === null ? await stepped(parseEnvelope(answered.body)) : null;
198
245
  for (const [index, asked] of part.entries()) {
199
246
  const failure = classified[index];
200
247
  if (failure !== null && failure !== undefined) {
@@ -223,16 +270,16 @@ export function createAgentsHouseAdapter(options) {
223
270
  path: continued.after,
224
271
  ...(continued.cut === undefined ? {} : { cut: continued.cut }),
225
272
  };
226
- const held = holding([asked], continued.after);
273
+ const held = await holding([asked], continued.after);
227
274
  const answered = await transport.door(DOOR_BOOTSTRAP, {
228
- prefixes: contentPrefixes(entry),
275
+ prefixes: [authorityRoot(entry.handle)],
229
276
  after,
230
277
  ...(held.length === 0 ? {} : { held }),
231
278
  });
232
279
  const failure = classifyRead(answered.status, answered.body, entry.locator);
233
280
  if (failure !== null)
234
281
  return failure;
235
- const envelope = parseEnvelope(answered.body);
282
+ const envelope = await stepped(parseEnvelope(answered.body));
236
283
  if (envelope === null)
237
284
  return UNCERTAIN_READ;
238
285
  const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
@@ -250,12 +297,12 @@ export function createAgentsHouseAdapter(options) {
250
297
  }
251
298
  async function enumerated(asks) {
252
299
  const answers = [];
253
- const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer, ({ ask }) => weight(ask.entry), declared().max_prefixes));
300
+ const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer, declared().max_prefixes));
254
301
  for (const part of parts) {
255
302
  let open = [...part];
256
303
  while (open.length > 0) {
257
304
  const answer = await transport.door(DOOR_ENUMERATE, {
258
- prefixes: open.flatMap(({ ask }) => contentPrefixes(ask.entry)),
305
+ prefixes: open.map(({ ask }) => authorityRoot(ask.entry.handle)),
259
306
  positions: open.map(({ ask }) => presented(ask.entry.authority, ask.from)),
260
307
  });
261
308
  const classified = open.map(({ ask }) => classifyRead(answer.status, answer.body, ask.entry.locator));
@@ -294,7 +341,9 @@ export function createAgentsHouseAdapter(options) {
294
341
  }
295
342
  const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
296
343
  if (minted.status !== 200) {
297
- return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };
344
+ return {
345
+ outcome: await stepped(mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)),
346
+ };
298
347
  }
299
348
  const grant = parseGrant(minted.body);
300
349
  if (grant === null || grant.method !== 'POST')
@@ -336,7 +385,7 @@ export function createAgentsHouseAdapter(options) {
336
385
  }
337
386
  return true;
338
387
  }
339
- async function submit(batch, head, changes, delta, bytes, entry, handed, keep) {
388
+ async function submit(batch, head, changes, delta, bytes, entry, handed, keep, into) {
340
389
  const inline = { ...head, changes, runtime: notifications.runtime };
341
390
  const prepared = uploadable(inline, bytes, declared())
342
391
  ? await uploaded(head, changes, delta, bytes, entry, handed, keep)
@@ -350,7 +399,12 @@ export function createAgentsHouseAdapter(options) {
350
399
  const settled = stagedFiles === null ? answer : await transport.door(DOOR_BATCH, prepared.body);
351
400
  if (stagedFiles === true && (await staged(settled, batch)) !== null)
352
401
  return UNCERTAIN;
353
- return mutationOutcome(settled.status, settled.body, entry.locator, entry.handle);
402
+ return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
403
+ ? undefined
404
+ : {
405
+ source: { authority: entry.authority, handle: entry.handle },
406
+ destination: { authority: into.authority, handle: into.handle },
407
+ }));
354
408
  }
355
409
  function granted(answer, locator) {
356
410
  const failure = classifyDoor(answer.status, answer.body, locator);
@@ -462,18 +516,27 @@ export function createAgentsHouseAdapter(options) {
462
516
  const entry = authorityFor(request.locator);
463
517
  if (entry === undefined)
464
518
  return { kind: 'room-not-readable', locator: request.locator };
465
- const mapped = houseChanges(request.changeBatch, entry.handle);
519
+ const batch = request.changeBatch;
520
+ const destination = batch.between?.destination.room;
521
+ const into = destination === undefined ? undefined : authorityFor(destination);
522
+ if (destination !== undefined && into === undefined) {
523
+ return { kind: 'room-not-readable', locator: destination };
524
+ }
525
+ const mapped = into === undefined
526
+ ? houseChanges(batch, entry.handle)
527
+ : houseMove(batch, entry.handle, into.handle);
466
528
  if (mapped.kind === 'unmapped')
467
529
  return rejectedMapping(mapped);
468
- const head = operationHead(request.changeBatch);
530
+ const head = operationHead(batch);
469
531
  const delta = deltaBody(mapped.changes);
470
532
  const bytes = deltaBytes(delta);
471
533
  const handed = request.upload;
472
- const batch = request.changeBatch;
473
- const outcome = await submit(batch, head, mapped.changes, delta, bytes, entry, handed, keep);
534
+ const answer = (upload) => submit(batch, head, mapped.changes, delta, bytes, entry, upload, keep, into);
535
+ const settle = (outcome) => into === undefined ? adopted(entry, outcome) : adoptedMove(entry, into, outcome);
536
+ const outcome = await answer(handed);
474
537
  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));
538
+ return settle(outcome);
539
+ return settle(await answer(undefined));
477
540
  },
478
541
  async history(_authorization, request) {
479
542
  const entry = authorityFor(request.locator);
@@ -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":[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9B,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] } }),
package/dist/gather.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export declare function gatheredEach<A, R>(send: (asks: readonly A[], answer: (ask: number, result: R) => void) => Promise<void>): (ask: A) => Promise<R>;
2
2
  export declare function gathered<A, R>(send: (asks: readonly A[]) => Promise<readonly R[]>): (ask: A) => Promise<R>;
3
- export declare function selections<T>(items: readonly T[], weight: (item: T) => number, limit: number): readonly (readonly T[])[];
3
+ export declare function selections<T>(items: readonly T[], limit: number): readonly (readonly T[])[];
4
4
  //# sourceMappingURL=gather.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gather.d.ts","sourceRoot":"","sources":["../src/gather.ts"],"names":[],"mappings":"AAMA,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,GACpF,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAwBxB;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,C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