@agentshouse/mdruntime-adapter 0.1.0-alpha.8 → 0.1.0-c6ddfd288ac81

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.
Files changed (60) hide show
  1. package/AGENTS.md +157 -26
  2. package/README.md +32 -0
  3. package/dist/actions.d.ts +4 -12
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +239 -332
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +257 -194
  8. package/dist/digest.js +1 -5
  9. package/dist/discovery.d.ts +20 -18
  10. package/dist/discovery.d.ts.map +1 -1
  11. package/dist/discovery.js +182 -210
  12. package/dist/gather.d.ts +3 -0
  13. package/dist/gather.d.ts.map +1 -0
  14. package/dist/gather.js +40 -0
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +0 -2
  18. package/dist/links.d.ts +11 -0
  19. package/dist/links.d.ts.map +1 -0
  20. package/dist/links.js +51 -0
  21. package/dist/map.d.ts +2 -2
  22. package/dist/map.d.ts.map +1 -1
  23. package/dist/map.js +6 -7
  24. package/dist/model.d.ts +2 -2
  25. package/dist/model.d.ts.map +1 -1
  26. package/dist/model.js +21 -39
  27. package/dist/read.d.ts +29 -23
  28. package/dist/read.d.ts.map +1 -1
  29. package/dist/read.js +222 -195
  30. package/dist/refusal.d.ts.map +1 -1
  31. package/dist/refusal.js +30 -51
  32. package/dist/site.d.ts.map +1 -1
  33. package/dist/site.js +108 -124
  34. package/dist/stream.d.ts +9 -5
  35. package/dist/stream.d.ts.map +1 -1
  36. package/dist/stream.js +186 -203
  37. package/dist/transport.d.ts +45 -28
  38. package/dist/transport.d.ts.map +1 -1
  39. package/dist/transport.js +3 -3
  40. package/dist/version.d.ts +1 -0
  41. package/dist/version.d.ts.map +1 -1
  42. package/dist/version.js +23 -18
  43. package/dist/write.d.ts +9 -3
  44. package/dist/write.d.ts.map +1 -1
  45. package/dist/write.js +123 -196
  46. package/package.json +4 -12
  47. package/dist/actions.js.map +0 -1
  48. package/dist/adapter.js.map +0 -1
  49. package/dist/digest.js.map +0 -1
  50. package/dist/discovery.js.map +0 -1
  51. package/dist/index.js.map +0 -1
  52. package/dist/map.js.map +0 -1
  53. package/dist/model.js.map +0 -1
  54. package/dist/read.js.map +0 -1
  55. package/dist/refusal.js.map +0 -1
  56. package/dist/site.js.map +0 -1
  57. package/dist/stream.js.map +0 -1
  58. package/dist/transport.js.map +0 -1
  59. package/dist/version.js.map +0 -1
  60. package/dist/write.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;AAqChC,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAexB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AA2BjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAsQpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;AA0ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAuBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAiCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA4YpF"}
package/dist/adapter.js CHANGED
@@ -1,61 +1,89 @@
1
- import { DISCOVER_PREFIXES, PROVIDER_SELECTION_MODEL_ROOT, capabilities, discoveredRoom, locatorOf, mapDiscovery, parseDiscovery, providerSelection, trackedFrom } from './discovery.js';
2
- import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf } from './model.js';
1
+ import { DISCOVER_PREFIXES, HOUSE_SCHEMA, capabilities, discoveredRoom, locatorOf, mapDiscovery, parseDiscovery, providerSelection, trackedFrom, } from './discovery.js';
2
+ import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf, } from './model.js';
3
+ import { gathered, selections } from './gather.js';
3
4
  import { createSiteAdapter } from './site.js';
4
- import { authorityRoot, bootstrapFrom, contentPrefixes, definitionsFrom, modelPrefix, parseEnumeration, parseEnvelope, parseGrant, refreshFrom } from './read.js';
5
+ import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, schemaFrom, schemaPath, viewOf, } from './read.js';
6
+ import { enumeratedLinks, scopeLinks, streamedLinks } from './links.js';
5
7
  import { houseAction } from './actions.js';
6
- import { classifyDoor, discoveryFailure } from './refusal.js';
8
+ import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
7
9
  import { houseNotifications } from './stream.js';
8
- import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, PRIVATE_AUTHORITY } from './transport.js';
9
- import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, rejectedMapping, revisionBody, uploadable } from './write.js';
10
- import { logPosition, presented } from './version.js';
11
- const UNCERTAIN = {
12
- kind: 'transport-uncertainty'
13
- };
14
- const RESOLVED_OUTCOMES = new Set([
15
- 'accepted',
16
- 'conflicted',
17
- 'rejected',
18
- 'expired'
19
- ]);
10
+ import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, DOOR_SELECTION_MAX, PRIVATE_LOCATOR, } from './transport.js';
11
+ import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
12
+ import { logPosition, presented, reachedVersion, roomVersion, } from './version.js';
13
+ const UNCERTAIN = { kind: 'transport-uncertainty' };
14
+ const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
20
15
  function lapsedGrant(outcome) {
21
16
  return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
22
17
  }
23
18
  function modelFailure(classified, envelope) {
24
19
  if (classified === null) {
25
- return envelope === null ? {
26
- kind: 'transport-uncertainty'
27
- } : MODEL_ABSENT;
20
+ return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;
28
21
  }
29
22
  return failedModel(classified);
30
23
  }
31
24
  export function createAgentsHouseAdapter(options) {
32
- if ('site' in options) return createSiteAdapter(options.site);
25
+ if ('site' in options)
26
+ return createSiteAdapter(options.site);
33
27
  const transport = options.transport;
34
28
  const notifications = houseNotifications(transport, 'credential');
35
29
  const tracked = new Map();
30
+ const handed = new Map();
36
31
  const models = modelShelf();
37
- const submissions = new Map();
38
- function held(envelope, entry, modelRoot, identity, failure) {
39
- return heldModel(envelope === null ? null : definitionsFrom(envelope, entry, modelRoot), identity, failure);
32
+ function bootstrappedRoom(envelope, entry) {
33
+ const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
34
+ if (scope === undefined)
35
+ return { kind: 'room-not-readable', locator: entry.locator };
36
+ handed.set(entry.locator, scopeLinks(scope));
37
+ return bootstrapOf(scope, entry);
38
+ }
39
+ function enumeratedRoom(enumeration, ask) {
40
+ const view = viewOf(enumeration, ask.entry);
41
+ if (view === undefined)
42
+ return { kind: 'room-not-readable', locator: ask.entry.locator };
43
+ const answer = refreshFrom(view, ask.entry, ask.fromRoomVersion);
44
+ if (answer.kind === 'net-advancement') {
45
+ handed.set(ask.entry.locator, enumeratedLinks(view, handed.get(ask.entry.locator)));
46
+ }
47
+ return answer;
48
+ }
49
+ function streamed(entry, request, from) {
50
+ const links = handed.get(entry.locator);
51
+ if (links?.roomVersion !== request.fromRoomVersion)
52
+ return null;
53
+ const advanced = notifications.advance(entry, from);
54
+ if (advanced === null)
55
+ return null;
56
+ if (request.minPosition !== undefined &&
57
+ !reachedVersion(advanced.page.roomVersion, request.minPosition, entry.logEpoch))
58
+ return null;
59
+ const relinked = streamedLinks(links, advanced);
60
+ if (relinked === null)
61
+ return null;
62
+ handed.set(entry.locator, relinked);
63
+ return advanced.page;
64
+ }
65
+ function held(envelope, entry, schema, failure) {
66
+ return heldModel(envelope === null ? null : schemaFrom(envelope, entry, schema), schemaPath(entry.handle, schema), failure);
67
+ }
68
+ function modelPrefixes(entry) {
69
+ return entry.schemas.map((schema) => schemaPath(entry.handle, schema));
40
70
  }
41
71
  async function acquireModels(entries) {
42
72
  const acquired = new Map();
43
- const privateEntry = entries.find((entry)=>entry.authority === PRIVATE_AUTHORITY);
44
- const prefixes = entries.map((entry)=>modelPrefix(entry, entry.modelRoot));
45
- if (privateEntry !== undefined) {
46
- prefixes.push(`${authorityRoot(undefined)}/${PROVIDER_SELECTION_MODEL_ROOT}`);
47
- }
48
- const answer = await transport.door(DOOR_BOOTSTRAP, {
49
- prefixes
50
- });
51
- const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);
52
- const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;
53
- const failure = modelFailure(classified, envelope);
54
- for (const entry of entries){
55
- acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.modelRoot, `${authorityRoot(entry.handle)}/${entry.modelRoot}`, failure));
56
- }
57
- if (privateEntry !== undefined) {
58
- acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, PROVIDER_SELECTION_MODEL_ROOT, `${authorityRoot(undefined)}/${PROVIDER_SELECTION_MODEL_ROOT}`, failure));
73
+ for (const part of selections(entries, (entry) => modelPrefixes(entry).length, DOOR_SELECTION_MAX)) {
74
+ const privateEntry = part.find((entry) => entry.locator === PRIVATE_LOCATOR);
75
+ const answer = await transport.door(DOOR_BOOTSTRAP, {
76
+ prefixes: part.flatMap((entry) => modelPrefixes(entry)),
77
+ });
78
+ const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
79
+ const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;
80
+ const failure = modelFailure(classified, envelope);
81
+ for (const entry of part) {
82
+ acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.schema, failure));
83
+ }
84
+ if (privateEntry !== undefined) {
85
+ acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, HOUSE_SCHEMA, failure));
86
+ }
59
87
  }
60
88
  return acquired;
61
89
  }
@@ -63,7 +91,7 @@ export function createAgentsHouseAdapter(options) {
63
91
  const locator = locatorOf(authority);
64
92
  const key = modelKey(locator, 'collection');
65
93
  const collection = models.retain(key, acquired.get(key));
66
- if (authority.kind !== 'private') {
94
+ if (locator !== PRIVATE_LOCATOR) {
67
95
  return discoveredRoom(authority, collection?.identity ?? null, undefined);
68
96
  }
69
97
  const selection = models.retain(modelKey(locator, 'typed-selection'), acquired.get(modelKey(locator, 'typed-selection')));
@@ -72,214 +100,249 @@ export function createAgentsHouseAdapter(options) {
72
100
  function authorityFor(locator) {
73
101
  return tracked.get(locator);
74
102
  }
103
+ function withAt(result) {
104
+ if (result.kind !== 'action')
105
+ return result;
106
+ const body = result.result;
107
+ if (typeof body !== 'object' || body === null)
108
+ return result;
109
+ const { authority, position, log_epoch: logEpoch } = body;
110
+ if (typeof position !== 'string' || typeof logEpoch !== 'string')
111
+ return result;
112
+ const locator = authority === undefined
113
+ ? PRIVATE_LOCATOR
114
+ : [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
115
+ if (locator === undefined)
116
+ return result;
117
+ return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
118
+ }
75
119
  async function bundled(body) {
76
120
  const grant = parseGrant(body);
77
- if (grant === null) return body;
78
- if (grant.method !== 'GET') return null;
121
+ if (grant === null)
122
+ return body;
123
+ if (grant.method !== 'GET')
124
+ return null;
79
125
  const answer = await transport.transfer({
80
- act: 'working_copy_bundle',
126
+ act: 'local_copy_bundle',
81
127
  method: 'GET',
82
- url: grant.url
128
+ url: grant.url,
129
+ answer: 'json',
83
130
  });
84
131
  return answer.status === 200 ? answer.body : null;
85
132
  }
86
- async function uploaded(identity, changes, delta, bytes, entry) {
133
+ function weight(entry) {
134
+ return contentPrefixes(entry).length;
135
+ }
136
+ async function bootstrapped(entries) {
137
+ const answers = [];
138
+ for (const part of selections(entries, weight, DOOR_SELECTION_MAX)) {
139
+ const answer = await transport.door(DOOR_BOOTSTRAP, {
140
+ prefixes: part.flatMap((entry) => contentPrefixes(entry)),
141
+ });
142
+ const classified = part.map((entry) => classifyDoor(answer.status, answer.body, entry.locator));
143
+ const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
144
+ part.forEach((entry, index) => {
145
+ const failure = classified[index];
146
+ if (failure === null || failure === undefined) {
147
+ answers.push(envelope === null ? UNCERTAIN_READ : bootstrappedRoom(envelope, entry));
148
+ return;
149
+ }
150
+ answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);
151
+ });
152
+ }
153
+ return answers;
154
+ }
155
+ function layered(asks) {
156
+ const depths = new Map();
157
+ const layers = [];
158
+ for (const ask of asks) {
159
+ const depth = depths.get(ask.entry.authority) ?? 0;
160
+ depths.set(ask.entry.authority, depth + 1);
161
+ (layers[depth] ??= []).push(ask);
162
+ }
163
+ return layers;
164
+ }
165
+ async function enumerated(asks) {
166
+ const answers = new Map();
167
+ const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry), DOOR_SELECTION_MAX));
168
+ for (const part of parts) {
169
+ let open = [...part];
170
+ while (open.length > 0) {
171
+ const answer = await transport.door(DOOR_ENUMERATE, {
172
+ prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),
173
+ positions: open.map((ask) => ({
174
+ ...presented(ask.entry.authority, ask.from),
175
+ ...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),
176
+ })),
177
+ });
178
+ const refusal = doorRefusal(answer.body);
179
+ if (refusal?.code === 'replica_behind') {
180
+ const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);
181
+ const behind = named.length === 0 ? open : named;
182
+ for (const ask of behind)
183
+ answers.set(ask, { kind: 'retryable-refusal', ...refusal });
184
+ open = open.filter((ask) => !behind.includes(ask));
185
+ continue;
186
+ }
187
+ const classified = open.map((ask) => classifyDoor(answer.status, answer.body, ask.entry.locator));
188
+ if (classified[0]?.kind === 'beyond-horizon') {
189
+ const named = doorRefusal(answer.body)?.fields.authority;
190
+ const expired = open.filter((ask) => ask.entry.authority === named);
191
+ const answered = expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };
192
+ const gone = expired.length === 0 ? open : expired;
193
+ for (const ask of gone)
194
+ answers.set(ask, answered);
195
+ open = open.filter((ask) => !gone.includes(ask));
196
+ continue;
197
+ }
198
+ const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
199
+ open.forEach((ask, index) => {
200
+ const failure = classified[index];
201
+ if (failure !== null && failure !== undefined) {
202
+ answers.set(ask, failure);
203
+ return;
204
+ }
205
+ answers.set(ask, enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask));
206
+ });
207
+ open = [];
208
+ }
209
+ }
210
+ return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);
211
+ }
212
+ const bootstrapTogether = gathered(bootstrapped);
213
+ const enumerateTogether = gathered(enumerated);
214
+ async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
87
215
  const paths = batchPaths(changes);
88
216
  const sha256 = await deltaDigest(delta);
89
- const retained = submissions.get(identity);
90
- if (retained !== undefined && retained.sha256 === sha256) return {
91
- body: retained.body
92
- };
93
- const minted = await transport.door(DOOR_BATCH_UPLOAD, {
94
- operation_id: identity,
95
- paths,
96
- bytes,
97
- sha256
98
- });
217
+ if (handed !== undefined && handed.sha256 === sha256) {
218
+ return { body: { ...head, paths, upload: handed } };
219
+ }
220
+ const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
99
221
  if (minted.status !== 200) {
100
- return {
101
- outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)
102
- };
222
+ return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };
103
223
  }
104
224
  const grant = parseGrant(minted.body);
105
- if (grant === null || grant.method !== 'POST') return {
106
- outcome: UNCERTAIN
107
- };
225
+ if (grant === null || grant.method !== 'POST')
226
+ return { outcome: UNCERTAIN };
108
227
  const delivered = await transport.transfer({
109
228
  act: 'authored_batch_upload',
110
229
  method: 'POST',
111
230
  url: grant.url,
112
- body: `${grant.operation}\n${delta}`
231
+ answer: 'json',
232
+ body: `${grant.operation}\n${delta}`,
113
233
  });
114
- if (delivered.status !== 200) return {
115
- outcome: UNCERTAIN
116
- };
234
+ if (delivered.status !== 200)
235
+ return { outcome: UNCERTAIN };
117
236
  const holding = parseGrant(delivered.body);
118
- if (holding === null) return {
119
- outcome: UNCERTAIN
120
- };
121
- const body = {
122
- operation_id: identity,
123
- paths,
124
- upload: {
125
- url: holding.url,
126
- operation: holding.operation,
127
- bytes,
128
- sha256
129
- }
130
- };
131
- submissions.set(identity, {
132
- sha256,
133
- body
134
- });
135
- return {
136
- body
137
- };
237
+ if (holding === null || holding.method !== 'POST')
238
+ return { outcome: UNCERTAIN };
239
+ const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
240
+ await keep(upload);
241
+ return { body: { ...head, paths, upload } };
138
242
  }
139
- async function submit(identity, changes, delta, bytes, entry) {
140
- const prepared = uploadable(bytes) ? await uploaded(identity, changes, delta, bytes, entry) : {
141
- body: {
142
- operation_id: identity,
143
- changes
144
- }
145
- };
146
- if ('outcome' in prepared) return prepared.outcome;
243
+ async function submit(head, changes, delta, bytes, entry, handed, keep) {
244
+ const prepared = uploadable(bytes)
245
+ ? await uploaded(head, changes, delta, bytes, entry, handed, keep)
246
+ : { body: { ...head, changes } };
247
+ if ('outcome' in prepared)
248
+ return prepared.outcome;
147
249
  const answer = await transport.door(DOOR_BATCH, prepared.body);
148
250
  return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);
149
251
  }
150
252
  return {
151
- async authorize () {
253
+ async authorize() {
152
254
  return options.authorize();
153
255
  },
154
- async model (_authorization, request) {
256
+ async model(_authorization, request) {
155
257
  return models.answer(request);
156
258
  },
157
- async discover (_authorization) {
158
- const answer = await transport.door(DOOR_DISCOVER, {
159
- prefixes: [
160
- ...DISCOVER_PREFIXES
161
- ]
162
- });
163
- const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);
164
- if (classified !== null) return discoveryFailure(classified);
259
+ async discover(_authorization) {
260
+ const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });
261
+ const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
262
+ if (classified !== null)
263
+ return discoveryFailure(classified);
165
264
  const document = parseDiscovery(answer.body);
166
- if (document === null) return {
167
- kind: 'transport-uncertainty'
168
- };
265
+ if (document === null)
266
+ return { kind: 'transport-uncertainty' };
169
267
  const entries = trackedFrom(document);
170
268
  tracked.clear();
171
- for (const entry of entries)tracked.set(entry.locator, entry);
269
+ for (const entry of entries)
270
+ tracked.set(entry.locator, entry);
271
+ for (const locator of handed.keys())
272
+ if (!tracked.has(locator))
273
+ handed.delete(locator);
172
274
  notifications.track(entries);
173
275
  const acquired = await acquireModels(entries);
174
- models.keep(entries.map((entry)=>entry.locator));
175
- return mapDiscovery(document, document.authorities.map((authority)=>roomOf(authority, acquired)), capabilities());
276
+ models.keep(entries.map((entry) => entry.locator));
277
+ return mapDiscovery(document, document.authorities.map((authority) => roomOf(authority, acquired)), capabilities(document.actions));
176
278
  },
177
- async bootstrap (_authorization, request) {
279
+ async bootstrap(_authorization, request) {
178
280
  const entry = authorityFor(request.locator);
179
- if (entry === undefined) return {
180
- kind: 'room-not-readable',
181
- locator: request.locator
182
- };
183
- if (request.pageToken !== undefined) return {
184
- kind: 'transport-uncertainty'
185
- };
186
- const answer = await transport.door(DOOR_BOOTSTRAP, {
187
- prefixes: [
188
- ...contentPrefixes(entry)
189
- ]
190
- });
191
- const classified = classifyDoor(answer.status, answer.body, entry.locator);
192
- if (classified !== null) {
193
- return classified.kind === 'beyond-horizon' ? {
194
- kind: 'transport-uncertainty'
195
- } : classified;
196
- }
197
- const envelope = parseEnvelope(await bundled(answer.body));
198
- if (envelope === null) return {
199
- kind: 'transport-uncertainty'
200
- };
201
- return bootstrapFrom(envelope, entry);
281
+ if (entry === undefined)
282
+ return { kind: 'room-not-readable', locator: request.locator };
283
+ if (request.pageToken !== undefined)
284
+ return { kind: 'transport-uncertainty' };
285
+ return bootstrapTogether(entry);
202
286
  },
203
- async refresh (_authorization, request) {
287
+ async refresh(_authorization, request) {
204
288
  const entry = authorityFor(request.locator);
205
- if (entry === undefined) return {
206
- kind: 'room-not-readable',
207
- locator: request.locator
208
- };
209
- if (request.pageToken !== undefined) return {
210
- kind: 'transport-uncertainty'
211
- };
289
+ if (entry === undefined)
290
+ return { kind: 'room-not-readable', locator: request.locator };
291
+ if (request.pageToken !== undefined)
292
+ return { kind: 'transport-uncertainty' };
212
293
  const from = logPosition(request.fromRoomVersion);
213
- if (from === null) return {
214
- kind: 'beyond-horizon'
215
- };
216
- const streamed = notifications.advance(entry, from);
217
- if (streamed !== null) return streamed;
218
- const answer = await transport.door(DOOR_ENUMERATE, {
219
- prefixes: [
220
- ...contentPrefixes(entry)
221
- ],
222
- positions: [
223
- presented(entry.authority, from)
224
- ]
294
+ if (from === null)
295
+ return { kind: 'beyond-horizon' };
296
+ const answered = streamed(entry, request, from);
297
+ if (answered !== null)
298
+ return answered;
299
+ const minPosition = request.minPosition === undefined ? null : logPosition(request.minPosition);
300
+ return enumerateTogether({
301
+ entry,
302
+ from,
303
+ fromRoomVersion: request.fromRoomVersion,
304
+ ...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),
225
305
  });
226
- const classified = classifyDoor(answer.status, answer.body, entry.locator);
227
- if (classified !== null) return classified;
228
- const enumeration = parseEnumeration(answer.body, 'credential');
229
- if (enumeration === null) return {
230
- kind: 'transport-uncertainty'
231
- };
232
- return refreshFrom(enumeration, entry, request.fromRoomVersion);
233
306
  },
234
- async mutate (_authorization, request) {
307
+ async mutate(_authorization, request, keep) {
235
308
  const entry = authorityFor(request.locator);
236
- if (entry === undefined) return {
237
- kind: 'room-not-readable',
238
- locator: request.locator
239
- };
309
+ if (entry === undefined)
310
+ return { kind: 'room-not-readable', locator: request.locator };
240
311
  const mapped = houseChanges(request.changeBatch, entry.handle);
241
- if (mapped.kind === 'unmapped') return rejectedMapping(mapped);
242
- const identity = request.changeBatch.id;
312
+ if (mapped.kind === 'unmapped')
313
+ return rejectedMapping(mapped);
314
+ const head = operationHead(request.changeBatch);
243
315
  const delta = deltaBody(mapped.changes);
244
316
  const bytes = deltaBytes(delta);
245
- const resent = submissions.has(identity);
246
- let outcome = await submit(identity, mapped.changes, delta, bytes, entry);
247
- if (resent && lapsedGrant(outcome)) {
248
- submissions.delete(identity);
249
- outcome = await submit(identity, mapped.changes, delta, bytes, entry);
250
- }
251
- if (RESOLVED_OUTCOMES.has(outcome.kind)) submissions.delete(identity);
252
- return outcome;
317
+ const handed = request.upload;
318
+ const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);
319
+ if (handed === undefined || !lapsedGrant(outcome))
320
+ return outcome;
321
+ return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);
253
322
  },
254
- async history (_authorization, request) {
323
+ async history(_authorization, request) {
255
324
  const entry = authorityFor(request.locator);
256
- if (entry === undefined) return {
257
- kind: 'room-not-readable',
258
- locator: request.locator
259
- };
325
+ if (entry === undefined)
326
+ return { kind: 'room-not-readable', locator: request.locator };
260
327
  const answer = await transport.door(DOOR_REVISIONS, revisionBody({
261
328
  path: request.path,
262
329
  handle: entry.handle,
263
- ...request.revision === undefined ? {} : {
264
- revision: request.revision
265
- },
266
- ...request.pageToken === undefined ? {} : {
267
- pageToken: request.pageToken
268
- }
330
+ ...(request.revision === undefined ? {} : { revision: request.revision }),
331
+ ...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
269
332
  }));
270
333
  return historyOutcome(answer.status, answer.body, entry.locator, {
271
334
  path: request.path,
272
- ...request.revision === undefined ? {} : {
273
- revision: request.revision
274
- }
335
+ ...(request.revision === undefined ? {} : { revision: request.revision }),
275
336
  });
276
337
  },
277
- async action (_authorization, request) {
278
- return houseAction(transport, request);
338
+ reached(locator, version, target) {
339
+ return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
340
+ },
341
+ async action(_authorization, request) {
342
+ return withAt(await houseAction(transport, request));
279
343
  },
280
344
  roomVersions: notifications,
281
- conversations: notifications.conversations
345
+ conversations: notifications.conversations,
346
+ serviceMode: notifications.serviceMode,
282
347
  };
283
348
  }
284
-
285
- //# sourceMappingURL=adapter.js.map
package/dist/digest.js CHANGED
@@ -3,9 +3,5 @@ export function textBytes(value) {
3
3
  }
4
4
  export async function sha256Hex(value) {
5
5
  const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
6
- return [
7
- ...new Uint8Array(digest)
8
- ].map((byte)=>byte.toString(16).padStart(2, '0')).join('');
6
+ return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
9
7
  }
10
-
11
- //# sourceMappingURL=digest.js.map
@@ -7,10 +7,14 @@ export declare const PROVIDER_ACTIONS = "provider-actions";
7
7
  export declare const MOVE_REFERENCE_REWRITES = "move-reference-rewrites";
8
8
  export declare const DISCOVER_PREFIXES: readonly string[];
9
9
  export declare const PROVIDER_SELECTION_ROOTS: readonly string[];
10
- export declare const PROVIDER_SELECTION_MODEL_ROOT = "house/settings/model";
10
+ export declare const UNTYPED_FOLDERS: readonly string[];
11
+ export declare const RESERVED_NAMES: readonly string[];
12
+ export declare const HOUSE_SCHEMA = "house/schema.yaml";
13
+ export declare const PRIVATE_HANDLE = "private";
11
14
  export type HouseBounds = {
12
15
  max_authored_file_bytes: number;
13
16
  max_batch_operations: number;
17
+ max_batch_documents: number;
14
18
  max_path_length: number;
15
19
  max_path_depth: number;
16
20
  max_mount_files: number;
@@ -25,12 +29,10 @@ export type HouseOperations = {
25
29
  delete: readonly string[];
26
30
  };
27
31
  export type HouseAuthority = LogPosition & {
28
- kind: 'room' | 'private';
29
32
  roomRef: string;
30
- roomHandle: string | null;
33
+ roomHandle: string;
31
34
  name: string;
32
- collectionRoot: string;
33
- modelRoot: string;
35
+ schema: string;
34
36
  managedReplication: 'admitted' | 'unavailable';
35
37
  protectedPaths: readonly string[];
36
38
  operations: HouseOperations;
@@ -39,24 +41,27 @@ export type HouseDiscoveryDocument = {
39
41
  bounds: HouseBounds;
40
42
  mdModelVersion: string;
41
43
  authorities: readonly HouseAuthority[];
44
+ actions: readonly string[];
42
45
  };
43
46
  export type TrackedAuthority = LogPosition & {
44
47
  locator: string;
45
48
  authority: string;
46
- handle: string | undefined;
47
- collectionRoot: string;
48
- modelRoot: string;
49
- modelRoots: readonly string[];
49
+ handle: string;
50
+ schema: string;
51
+ schemas: readonly string[];
52
+ };
53
+ export type HouseSiteEntry = {
54
+ roomRef: string;
55
+ segment: string;
50
56
  };
51
57
  export type HouseSiteSlot = {
52
58
  slot: string;
53
- roomRef: string | null;
59
+ entries: readonly HouseSiteEntry[];
54
60
  };
55
61
  export type HouseSiteAuthority = LogPosition & {
56
62
  roomRef: string;
57
63
  roomHandle: string;
58
- collectionRoot: string;
59
- modelRoot: string;
64
+ schema: string;
60
65
  };
61
66
  export type HouseSiteDiscovery = {
62
67
  bounds: HouseBounds;
@@ -64,18 +69,15 @@ export type HouseSiteDiscovery = {
64
69
  slots: readonly HouseSiteSlot[];
65
70
  authorities: readonly HouseSiteAuthority[];
66
71
  };
67
- export type SiteTracked = TrackedAuthority & {
68
- slot: string;
69
- };
70
72
  export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
71
73
  export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
72
- export declare function siteLocator(slot: string, roomRef: string): string;
73
- export declare function siteTracked(document: HouseSiteDiscovery): SiteTracked[];
74
+ export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
75
+ export declare function siteSlots(document: HouseSiteDiscovery): Discovery['slots'];
74
76
  export declare function locatorOf(authority: HouseAuthority): string;
75
77
  export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
76
78
  export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
77
79
  export declare function declaredRetention(bounds: HouseBounds): Retention;
78
- export declare function capabilities(): readonly Capability[];
80
+ export declare function capabilities(actions: readonly string[]): readonly Capability[];
79
81
  export declare function siteCapabilities(): readonly Capability[];
80
82
  export declare function providerSelection(attachedModel: TypedSelection['attachedModel']): TypedSelection;
81
83
  export declare function discoveredRoom(authority: HouseAuthority, attachedModel: DiscoveredRoom['attachedModel'], typedSelection: TypedSelection | undefined): DiscoveredRoom;