@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c0074032f9909

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 (85) hide show
  1. package/README.md +32 -0
  2. package/dist/actions.d.ts +8 -16
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +43 -436
  5. package/dist/adapter.d.ts +1 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +352 -231
  8. package/dist/authored-path.d.ts +9 -0
  9. package/dist/authored-path.d.ts.map +1 -0
  10. package/dist/authored-path.js +34 -0
  11. package/dist/chunks.d.ts +36 -0
  12. package/dist/chunks.d.ts.map +1 -0
  13. package/dist/chunks.js +281 -0
  14. package/dist/digest.d.ts +0 -1
  15. package/dist/digest.js +1 -5
  16. package/dist/discovery.d.ts +49 -42
  17. package/dist/discovery.d.ts.map +1 -1
  18. package/dist/discovery.js +317 -232
  19. package/dist/history.d.ts +6 -0
  20. package/dist/history.d.ts.map +1 -0
  21. package/dist/history.js +85 -0
  22. package/dist/index.d.ts +10 -3
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +9 -3
  25. package/dist/map.d.ts +2 -3
  26. package/dist/map.d.ts.map +1 -1
  27. package/dist/map.js +6 -7
  28. package/dist/model.d.ts +8 -19
  29. package/dist/model.d.ts.map +1 -1
  30. package/dist/model.js +43 -57
  31. package/dist/read.d.ts +65 -54
  32. package/dist/read.d.ts.map +1 -1
  33. package/dist/read.js +217 -295
  34. package/dist/refusal.d.ts +7 -11
  35. package/dist/refusal.d.ts.map +1 -1
  36. package/dist/refusal.js +53 -69
  37. package/dist/search.d.ts +4 -0
  38. package/dist/search.d.ts.map +1 -0
  39. package/dist/search.js +47 -0
  40. package/dist/session-content/bounds.d.ts +7 -0
  41. package/dist/session-content/check.d.ts +18 -0
  42. package/dist/session-content/index.d.ts +7 -0
  43. package/dist/session-content/parts.d.ts +103 -0
  44. package/dist/session-content/state.d.ts +61 -0
  45. package/dist/session-content/turn.d.ts +328 -0
  46. package/dist/site.d.ts +1 -2
  47. package/dist/site.d.ts.map +1 -1
  48. package/dist/site.js +142 -172
  49. package/dist/space-schema.d.ts +6 -0
  50. package/dist/space-schema.d.ts.map +1 -0
  51. package/dist/space-schema.js +11 -0
  52. package/dist/stream.d.ts +20 -9
  53. package/dist/stream.d.ts.map +1 -1
  54. package/dist/stream.js +394 -236
  55. package/dist/transport.d.ts +172 -47
  56. package/dist/transport.d.ts.map +1 -1
  57. package/dist/transport.js +58 -12
  58. package/dist/uncertain.d.ts +5 -0
  59. package/dist/uncertain.d.ts.map +1 -0
  60. package/dist/uncertain.js +11 -0
  61. package/dist/upload.d.ts +13 -0
  62. package/dist/upload.d.ts.map +1 -0
  63. package/dist/upload.js +65 -0
  64. package/dist/version.d.ts +3 -1
  65. package/dist/version.d.ts.map +1 -1
  66. package/dist/version.js +32 -18
  67. package/dist/write.d.ts +24 -11
  68. package/dist/write.d.ts.map +1 -1
  69. package/dist/write.js +263 -241
  70. package/package.json +10 -14
  71. package/AGENTS.md +0 -79
  72. package/dist/actions.js.map +0 -1
  73. package/dist/adapter.js.map +0 -1
  74. package/dist/digest.js.map +0 -1
  75. package/dist/discovery.js.map +0 -1
  76. package/dist/index.js.map +0 -1
  77. package/dist/map.js.map +0 -1
  78. package/dist/model.js.map +0 -1
  79. package/dist/read.js.map +0 -1
  80. package/dist/refusal.js.map +0 -1
  81. package/dist/site.js.map +0 -1
  82. package/dist/stream.js.map +0 -1
  83. package/dist/transport.js.map +0 -1
  84. package/dist/version.js.map +0 -1
  85. package/dist/write.js.map +0 -1
package/dist/adapter.js CHANGED
@@ -1,285 +1,406 @@
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 { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
2
+ import { stepped } from '@agentshouse/mdruntime';
3
+ import { capabilities, discoveredRoom, mapDiscovery, parseAuthorityChange, parseDiscovery, trackedFrom, } from './discovery.js';
3
4
  import { createSiteAdapter } from './site.js';
4
- import { authorityRoot, bootstrapFrom, contentPrefixes, definitionsFrom, modelPrefix, parseEnumeration, parseEnvelope, parseGrant, refreshFrom } from './read.js';
5
- import { houseAction } from './actions.js';
6
- import { classifyDoor, discoveryFailure } from './refusal.js';
7
- 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, operationHead, 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
- ]);
5
+ import { parseFileAddress, parseGrant } from './read.js';
6
+ import { chunkedHead, chunkLister, chunkPart } from './chunks.js';
7
+ import { finishedUpload, houseUpload } from './upload.js';
8
+ import { houseAction, HOUSE_LEADING_READS, HOUSE_UNKEPT_READS } from './actions.js';
9
+ import { houseSearch } from './search.js';
10
+ import { answeredFailure, classifyDoor, doorRefusal } from './refusal.js';
11
+ import { UNANSWERED, unusable } from './uncertain.js';
12
+ import { houseNotifications, } from './stream.js';
13
+ import { houseDoorRoute, } from './transport.js';
14
+ import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
15
+ import { admittedPath } from './authored-path.js';
16
+ import { followsVersion, reachedVersion, roomVersion } from './version.js';
17
+ const EXPIRED_ADDRESS = 403;
20
18
  function lapsedGrant(outcome) {
21
19
  return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
22
20
  }
23
- function modelFailure(classified, envelope) {
24
- if (classified === null) {
25
- return envelope === null ? {
26
- kind: 'transport-uncertainty'
27
- } : MODEL_ABSENT;
28
- }
29
- return failedModel(classified);
21
+ function unstagedRefusal(answer) {
22
+ const refusal = doorRefusal(answer.body);
23
+ return refusal?.code === 'files_unstaged' ? refusal : null;
30
24
  }
31
25
  export function createAgentsHouseAdapter(options) {
32
- if ('site' in options) return createSiteAdapter(options.site);
26
+ if ('site' in options)
27
+ return createSiteAdapter(options.site, options.snapshot === true);
33
28
  const transport = options.transport;
34
- const notifications = houseNotifications(transport, 'credential');
29
+ const notifications = houseNotifications(transport, 'credential', {
30
+ opened: async (frame) => (frame === null ? null : opened(frame)),
31
+ changed,
32
+ expired: (entries) => lister.askAll(entries),
33
+ });
35
34
  const tracked = new Map();
36
- 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);
35
+ const lister = chunkLister(transport, () => declared().max_prefixes, (locator) => tracked.get(locator));
36
+ const chunked = new Map();
37
+ const renewals = new WeakMap();
38
+ let bounds;
39
+ function declared() {
40
+ if (bounds === undefined)
41
+ throw new Error('no Discovery declared the bounds');
42
+ return bounds;
40
43
  }
41
- async function acquireModels(entries) {
42
- 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));
59
- }
60
- return acquired;
44
+ function opened(frame) {
45
+ const document = parseDiscovery(frame);
46
+ if (document === null)
47
+ return null;
48
+ bounds = document.bounds;
49
+ tracked.clear();
50
+ lister.forget();
51
+ for (const entry of trackedFrom(document))
52
+ tracked.set(entry.locator, entry);
53
+ notifications.track([...tracked.values()]);
54
+ return {
55
+ ...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
56
+ member: document.member,
57
+ roomList: document.roomList,
58
+ };
59
+ }
60
+ function changed(frame) {
61
+ const change = parseAuthorityChange(frame);
62
+ if (change === null)
63
+ return null;
64
+ const unheld = [...change.left, ...change.listed];
65
+ for (const locator of unheld)
66
+ tracked.delete(locator);
67
+ for (const entry of trackedFrom(change))
68
+ tracked.set(entry.locator, entry);
69
+ notifications.track([...tracked.values()]);
70
+ return {
71
+ kind: 'authority-changed',
72
+ rooms: change.authorities.map((authority) => discoveredRoom(authority)),
73
+ left: unheld,
74
+ member: change.member,
75
+ roomList: { ...change.roomList, left: change.left },
76
+ };
61
77
  }
62
- function roomOf(authority, acquired) {
63
- const locator = locatorOf(authority);
64
- const key = modelKey(locator, 'collection');
65
- const collection = models.retain(key, acquired.get(key));
66
- if (authority.kind !== 'private') {
67
- return discoveredRoom(authority, collection?.identity ?? null, undefined);
78
+ async function listedRoom(entry) {
79
+ const listed = await lister.list(entry);
80
+ if ('kind' in listed)
81
+ return listed;
82
+ const head = await chunkedHead(listed, entry);
83
+ if (head.kind === 'bootstrap')
84
+ chunked.set(entry.locator, listed);
85
+ return head;
86
+ }
87
+ async function chunkRead(entry, id) {
88
+ const room = chunked.get(entry.locator);
89
+ const address = room?.chunks.get(id);
90
+ if (room === undefined || address === undefined)
91
+ return UNANSWERED;
92
+ const read = await transport.download(address.url);
93
+ if (read.status !== EXPIRED_ADDRESS)
94
+ return { room, read };
95
+ const renewed = await renewal(entry, room);
96
+ if ('kind' in renewed)
97
+ return renewed;
98
+ const renewedAddress = renewed.chunks.get(id);
99
+ if (renewedAddress === undefined)
100
+ return unusable();
101
+ chunked.set(entry.locator, renewed);
102
+ return { room: renewed, read: await transport.download(renewedAddress.url) };
103
+ }
104
+ function renewal(entry, stale) {
105
+ const held = renewals.get(stale);
106
+ if (held !== undefined)
107
+ return held;
108
+ const renewed = lister.renew(entry, [...chunked.keys()].flatMap((locator) => tracked.get(locator) ?? []));
109
+ renewals.set(stale, renewed);
110
+ return renewed;
111
+ }
112
+ function hold(rooms) {
113
+ for (const room of rooms) {
114
+ const listed = chunked.get(room.locator);
115
+ if (listed !== undefined &&
116
+ room.roomVersion !== null &&
117
+ reachedVersion(room.roomVersion, roomVersion(listed), listed.logEpoch))
118
+ chunked.delete(room.locator);
68
119
  }
69
- const selection = models.retain(modelKey(locator, 'typed-selection'), acquired.get(modelKey(locator, 'typed-selection')));
70
- return discoveredRoom(authority, collection?.identity ?? null, providerSelection(selection?.identity ?? null));
120
+ notifications.send(rooms);
121
+ }
122
+ async function chunkPage(entry, id, arriving) {
123
+ const fetched = await chunkRead(entry, id);
124
+ if ('kind' in fetched)
125
+ return fetched;
126
+ if (fetched.read.status !== 200)
127
+ return answeredFailure(fetched.read.status, null);
128
+ return chunkPart(fetched.read.body, fetched.room, id, arriving);
71
129
  }
72
130
  function authorityFor(locator) {
73
131
  return tracked.get(locator);
74
132
  }
75
- async function bundled(body) {
76
- const grant = parseGrant(body);
77
- if (grant === null) return body;
78
- if (grant.method !== 'GET') return null;
79
- const answer = await transport.transfer({
80
- act: 'working_copy_bundle',
81
- method: 'GET',
82
- url: grant.url
83
- });
84
- return answer.status === 200 ? answer.body : null;
133
+ function withAt(result) {
134
+ if (result.kind !== 'action')
135
+ return result;
136
+ const body = result.result;
137
+ if (typeof body !== 'object' || body === null)
138
+ return result;
139
+ const { authority, position, log_epoch: logEpoch } = body;
140
+ if (typeof position !== 'string' || typeof logEpoch !== 'string')
141
+ return result;
142
+ const locator = [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
143
+ if (locator === undefined)
144
+ return result;
145
+ return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
85
146
  }
86
- async function uploaded(head, changes, delta, bytes, entry) {
147
+ async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
87
148
  const paths = batchPaths(changes);
88
149
  const sha256 = await deltaDigest(delta);
89
- const retained = submissions.get(head.operation_id);
90
- if (retained !== undefined && retained.sha256 === sha256 && retained.body.app_ref === head.app_ref && retained.body.release === head.release) return {
91
- body: retained.body
92
- };
93
- const minted = await transport.door(DOOR_BATCH_UPLOAD, {
150
+ if (handed !== undefined && handed.sha256 === sha256) {
151
+ return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
152
+ }
153
+ const minted = await transport.door(houseDoorRoute('files/batch-upload'), {
94
154
  ...head,
95
155
  paths,
96
156
  bytes,
97
- sha256
157
+ sha256,
98
158
  });
99
159
  if (minted.status !== 200) {
100
160
  return {
101
- outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)
161
+ outcome: await stepped(mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)),
102
162
  };
103
163
  }
104
164
  const grant = parseGrant(minted.body);
105
- if (grant === null || grant.method !== 'POST') return {
106
- outcome: UNCERTAIN
107
- };
165
+ if (grant === null)
166
+ return { outcome: unusable() };
108
167
  const delivered = await transport.transfer({
109
- act: 'authored_batch_upload',
110
- method: 'POST',
111
168
  url: grant.url,
112
- body: `${grant.operation}\n${delta}`
169
+ body: `${grant.operation}\n${delta}`,
113
170
  });
114
- if (delivered.status !== 200) return {
115
- outcome: UNCERTAIN
116
- };
171
+ if (delivered.status !== 200) {
172
+ return { outcome: answeredFailure(delivered.status, delivered.body) };
173
+ }
117
174
  const holding = parseGrant(delivered.body);
118
- if (holding === null) return {
119
- outcome: UNCERTAIN
120
- };
121
- const body = {
122
- ...head,
123
- paths,
124
- upload: {
125
- url: holding.url,
126
- operation: holding.operation,
127
- bytes,
128
- sha256
175
+ if (holding === null)
176
+ return { outcome: unusable() };
177
+ const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
178
+ await keep(upload);
179
+ return { body: { ...head, paths, upload, runtime: notifications.runtime } };
180
+ }
181
+ async function staged(uploads, { changeBatch: batch, file }) {
182
+ if (!Array.isArray(uploads))
183
+ return unusable();
184
+ for (const named of uploads) {
185
+ const upload = houseUpload(named);
186
+ const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
187
+ if (upload === null || change === undefined)
188
+ return unusable();
189
+ const finished = await finishedUpload(transport, upload, await file(change.localId));
190
+ if ('unfinished' in finished)
191
+ return answeredFailure(finished.unfinished, null);
192
+ if (finished.status !== 200)
193
+ return answeredFailure(finished.status, finished.body);
194
+ if (finished.body?.staged !== true)
195
+ return unusable();
196
+ }
197
+ return null;
198
+ }
199
+ async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
200
+ const inline = { ...head, changes, runtime: notifications.runtime };
201
+ const prepared = uploadable(inline, bytes, declared())
202
+ ? await uploaded(head, changes, delta, bytes, entry, handed, keep)
203
+ : { body: inline };
204
+ if ('outcome' in prepared)
205
+ return prepared.outcome;
206
+ const answer = await transport.door(houseDoorRoute('files/batch'), prepared.body);
207
+ const unstaged = unstagedRefusal(answer);
208
+ if (unstaged !== null) {
209
+ const staging = await staged(unstaged.fields.upload, request);
210
+ if (staging !== null)
211
+ return staging;
212
+ }
213
+ const settled = unstaged === null
214
+ ? answer
215
+ : await transport.door(houseDoorRoute('files/batch'), prepared.body);
216
+ if (unstaged !== null && unstagedRefusal(settled) !== null) {
217
+ return answeredFailure(settled.status, settled.body);
218
+ }
219
+ return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
220
+ ? undefined
221
+ : {
222
+ source: { authority: entry.authority, handle: entry.handle },
223
+ destination: { authority: into.authority, handle: into.handle },
224
+ }));
225
+ }
226
+ function addressed(answer, locator) {
227
+ const failure = classifyDoor(answer.status, answer.body, locator);
228
+ if (failure !== null) {
229
+ return failure.kind === 'scoped-refusal'
230
+ ? {
231
+ kind: 'rejected',
232
+ code: failure.code,
233
+ fields: failure.fields,
234
+ retryable: failure.retryable,
235
+ }
236
+ : failure;
237
+ }
238
+ const address = parseFileAddress(answer.body);
239
+ return address === null ? unusable() : { kind: 'address', ...address };
240
+ }
241
+ function linked(answer, locator) {
242
+ const address = addressed(answer, locator);
243
+ return address.kind === 'address'
244
+ ? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
245
+ : address;
246
+ }
247
+ function refusedAttach(answer, locator) {
248
+ const failure = classifyDoor(answer.status, answer.body, locator);
249
+ if (failure === null)
250
+ return null;
251
+ return failure.kind === 'scoped-refusal'
252
+ ? {
253
+ kind: 'rejected',
254
+ code: failure.code,
255
+ fields: failure.fields,
256
+ retryable: failure.retryable,
129
257
  }
130
- };
131
- submissions.set(head.operation_id, {
132
- sha256,
133
- body
134
- });
258
+ : failure;
259
+ }
260
+ async function downloaded(ask, locator) {
261
+ let address = addressed(await ask(), locator);
262
+ if (address.kind !== 'address')
263
+ return address;
264
+ let read = await transport.download(address.url);
265
+ if (read.status === EXPIRED_ADDRESS) {
266
+ address = addressed(await ask(), locator);
267
+ if (address.kind !== 'address')
268
+ return address;
269
+ read = await transport.download(address.url);
270
+ }
271
+ if (read.status !== 200)
272
+ return answeredFailure(read.status, null);
273
+ if (read.body === null)
274
+ return unusable();
135
275
  return {
136
- body
276
+ kind: 'binary',
277
+ body: read.body,
278
+ mediaType: address.mediaType,
279
+ sha256: address.sha256,
137
280
  };
138
281
  }
139
- async function submit(head, changes, delta, bytes, entry) {
140
- const prepared = uploadable(bytes) ? await uploaded(head, changes, delta, bytes, entry) : {
141
- body: {
142
- ...head,
143
- changes
144
- }
145
- };
146
- if ('outcome' in prepared) return prepared.outcome;
147
- const answer = await transport.door(DOOR_BATCH, prepared.body);
148
- return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);
282
+ function pathAddress(request) {
283
+ const entry = authorityFor(request.locator);
284
+ if (entry === undefined)
285
+ return null;
286
+ return () => transport.door(houseDoorRoute('files/read'), {
287
+ room_ref: entry.authority,
288
+ path: request.path,
289
+ revision: request.revision,
290
+ });
149
291
  }
150
292
  return {
151
- async authorize () {
293
+ roomTypes: HOUSE_ROOM_TYPES,
294
+ typedPaths: HOUSE_TYPED_PATHS,
295
+ pathRule: admittedPath,
296
+ unkeptReads: HOUSE_UNKEPT_READS,
297
+ leadingReads: HOUSE_LEADING_READS,
298
+ async authorize() {
152
299
  return options.authorize();
153
300
  },
154
- async model (_authorization, request) {
155
- return models.answer(request);
156
- },
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);
165
- const document = parseDiscovery(answer.body);
166
- if (document === null) return {
167
- kind: 'transport-uncertainty'
168
- };
169
- const entries = trackedFrom(document);
170
- tracked.clear();
171
- for (const entry of entries)tracked.set(entry.locator, entry);
172
- notifications.track(entries);
173
- 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());
176
- },
177
- async bootstrap (_authorization, request) {
301
+ async bootstrap(_authorization, request) {
178
302
  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);
303
+ if (entry === undefined)
304
+ return { kind: 'room-not-readable', locator: request.locator };
305
+ return request.pageToken === undefined
306
+ ? listedRoom(entry)
307
+ : chunkPage(entry, request.pageToken, request.arriving);
202
308
  },
203
- async refresh (_authorization, request) {
309
+ async mutate(_authorization, request, keep) {
204
310
  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
- };
212
- 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
- ]
225
- });
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
- },
234
- async mutate (_authorization, request) {
235
- const entry = authorityFor(request.locator);
236
- if (entry === undefined) return {
237
- kind: 'room-not-readable',
238
- locator: request.locator
239
- };
240
- const mapped = houseChanges(request.changeBatch, entry.handle);
241
- if (mapped.kind === 'unmapped') return rejectedMapping(mapped);
242
- const head = operationHead(request.changeBatch);
311
+ if (entry === undefined)
312
+ return { kind: 'room-not-readable', locator: request.locator };
313
+ const batch = request.changeBatch;
314
+ const destination = batch.between?.destination.room;
315
+ const into = destination === undefined ? undefined : authorityFor(destination);
316
+ if (destination !== undefined && into === undefined) {
317
+ return { kind: 'room-not-readable', locator: destination };
318
+ }
319
+ const mapped = into === undefined
320
+ ? houseChanges(batch, entry.handle)
321
+ : houseMove(batch, entry.handle, into.handle);
322
+ if (mapped.kind === 'unmapped')
323
+ return rejectedMapping(mapped);
324
+ const head = operationHead(batch, entry.authority);
243
325
  const delta = deltaBody(mapped.changes);
244
326
  const bytes = deltaBytes(delta);
245
- const resent = submissions.has(head.operation_id);
246
- let outcome = await submit(head, mapped.changes, delta, bytes, entry);
247
- if (resent && lapsedGrant(outcome)) {
248
- submissions.delete(head.operation_id);
249
- outcome = await submit(head, mapped.changes, delta, bytes, entry);
250
- }
251
- if (RESOLVED_OUTCOMES.has(outcome.kind)) submissions.delete(head.operation_id);
252
- return outcome;
327
+ const handed = request.upload;
328
+ const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
329
+ const outcome = await answer(handed);
330
+ if (handed === undefined || !lapsedGrant(outcome))
331
+ return outcome;
332
+ return answer(undefined);
253
333
  },
254
- async history (_authorization, request) {
334
+ async history(_authorization, request) {
255
335
  const entry = authorityFor(request.locator);
256
- if (entry === undefined) return {
257
- kind: 'room-not-readable',
258
- locator: request.locator
259
- };
260
- const answer = await transport.door(DOOR_REVISIONS, revisionBody({
336
+ if (entry === undefined)
337
+ return { kind: 'room-not-readable', locator: request.locator };
338
+ const answer = await transport.door(houseDoorRoute('files/revisions/list'), revisionBody({
261
339
  path: request.path,
262
340
  handle: entry.handle,
263
- ...request.revision === undefined ? {} : {
264
- revision: request.revision
265
- },
266
- ...request.pageToken === undefined ? {} : {
267
- pageToken: request.pageToken
268
- }
341
+ ...(request.revision === undefined ? {} : { revision: request.revision }),
342
+ ...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
269
343
  }));
270
- return historyOutcome(answer.status, answer.body, entry.locator, {
271
- path: request.path,
272
- ...request.revision === undefined ? {} : {
273
- revision: request.revision
274
- }
344
+ return historyOutcome(answer.status, answer.body, entry.locator, request);
345
+ },
346
+ async binary(_authorization, request) {
347
+ const ask = pathAddress(request);
348
+ if (ask === null)
349
+ return { kind: 'room-not-readable', locator: request.locator };
350
+ return downloaded(ask, request.locator);
351
+ },
352
+ async link(_authorization, request) {
353
+ const ask = pathAddress(request);
354
+ if (ask === null)
355
+ return { kind: 'room-not-readable', locator: request.locator };
356
+ return linked(await ask(), request.locator);
357
+ },
358
+ async attach(_authorization, request) {
359
+ const entry = authorityFor(request.locator);
360
+ if (entry === undefined)
361
+ return { kind: 'room-not-readable', locator: request.locator };
362
+ const declared = await transport.door(houseDoorRoute('files/attach'), {
363
+ room_ref: entry.authority,
364
+ name: request.name,
365
+ bytes: request.byteLength,
366
+ sha256: request.sha256,
367
+ media_type: request.mediaType,
275
368
  });
369
+ const refused = refusedAttach(declared, request.locator);
370
+ if (refused !== null)
371
+ return refused;
372
+ const upload = houseUpload(declared.body?.upload);
373
+ if (upload === null)
374
+ return unusable();
375
+ const finished = await finishedUpload(transport, upload, request.blob);
376
+ if ('unfinished' in finished)
377
+ return answeredFailure(finished.unfinished, null);
378
+ const unfinished = refusedAttach(finished, request.locator);
379
+ if (unfinished !== null)
380
+ return unfinished;
381
+ const { path, revision } = (finished.body ?? {});
382
+ const root = `/rooms/${entry.handle}/`;
383
+ return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
384
+ ? { kind: 'attached', path: path.slice(root.length), revision }
385
+ : unusable();
386
+ },
387
+ reached(locator, version, target) {
388
+ return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
389
+ },
390
+ follows(_locator, version, next) {
391
+ return followsVersion(version, next);
392
+ },
393
+ async action(_authorization, request) {
394
+ return withAt(await houseAction(transport, request));
395
+ },
396
+ search(_authorization, request) {
397
+ return houseSearch(transport, [...tracked.values()], request);
276
398
  },
277
- async action (_authorization, request) {
278
- return houseAction(transport, request);
399
+ roomStream: {
400
+ hold,
401
+ observe: notifications.observe,
279
402
  },
280
- roomVersions: notifications,
281
- conversations: notifications.conversations
403
+ conversations: notifications.conversations,
404
+ serviceMode: notifications.serviceMode,
282
405
  };
283
406
  }
284
-
285
- //# sourceMappingURL=adapter.js.map
@@ -0,0 +1,9 @@
1
+ export declare const GENERATED_PROVENANCE = "_provenance";
2
+ export declare const GENERATED_REVISIONS = "_revisions";
3
+ export declare const RESERVED_DERIVED = "_derived";
4
+ export declare const WHOLE_ESCAPED_NAMES: readonly string[];
5
+ export declare const AUTHORED_SEGMENT_MAX_CHARS = 255;
6
+ export declare const AUTHORED_SEGMENT: RegExp;
7
+ export declare const LOCAL_COPY_MANIFEST = ".house";
8
+ export declare const LOCAL_COPY_ROOT_NAMES: readonly string[];
9
+ export declare function admittedPath(path: string): boolean;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authored-path.d.ts","sourceRoot":"","sources":["../src/authored-path.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAElD,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAMhD,CAAC;AAEF,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAO9C,eAAO,MAAM,gBAAgB,QAE5B,CAAC;AAEF,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAE5C,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAIlD,CAAC;AASF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQlD"}