@agentshouse/mdruntime-adapter 0.1.0-cf059d0c8e9c0 → 0.1.0-cf151c882c69c

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 (88) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +7 -2
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +72 -10
  5. package/dist/adapter.d.ts +0 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +186 -177
  8. package/dist/authored-path.d.ts +61 -0
  9. package/dist/authored-path.d.ts.map +1 -0
  10. package/dist/authored-path.js +166 -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/discovery.d.ts +32 -7
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +203 -29
  18. package/dist/history.d.ts +1 -7
  19. package/dist/history.d.ts.map +1 -1
  20. package/dist/history.js +24 -30
  21. package/dist/index.d.ts +7 -8
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +6 -6
  24. package/dist/map.d.ts +0 -1
  25. package/dist/model.d.ts +6 -9
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +28 -26
  28. package/dist/read.d.ts +20 -24
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +103 -173
  31. package/dist/refusal.d.ts +6 -2
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +28 -7
  34. package/dist/renamed.d.ts +10 -0
  35. package/dist/renamed.d.ts.map +1 -0
  36. package/dist/renamed.js +29 -0
  37. package/dist/room-query.d.ts +4 -0
  38. package/dist/room-query.d.ts.map +1 -0
  39. package/dist/room-query.js +63 -0
  40. package/dist/search.d.ts +4 -0
  41. package/dist/search.d.ts.map +1 -0
  42. package/dist/search.js +47 -0
  43. package/dist/session-content/check.d.ts +17 -0
  44. package/dist/session-content/index.d.ts +6 -0
  45. package/dist/session-content/parts.d.ts +30 -0
  46. package/dist/session-content/state.d.ts +59 -0
  47. package/dist/session-content/turn.d.ts +137 -0
  48. package/dist/site.d.ts +0 -1
  49. package/dist/site.d.ts.map +1 -1
  50. package/dist/site.js +82 -52
  51. package/dist/space-schema.d.ts +6 -0
  52. package/dist/space-schema.d.ts.map +1 -0
  53. package/dist/space-schema.js +11 -0
  54. package/dist/stream.d.ts +4 -4
  55. package/dist/stream.d.ts.map +1 -1
  56. package/dist/stream.js +152 -77
  57. package/dist/transport.d.ts +65 -31
  58. package/dist/transport.d.ts.map +1 -1
  59. package/dist/transport.js +56 -15
  60. package/dist/uncertain.d.ts +5 -0
  61. package/dist/uncertain.d.ts.map +1 -0
  62. package/dist/uncertain.js +11 -0
  63. package/dist/upload.d.ts +7 -2
  64. package/dist/upload.d.ts.map +1 -1
  65. package/dist/upload.js +49 -6
  66. package/dist/version.d.ts +0 -1
  67. package/dist/write.d.ts +0 -2
  68. package/dist/write.d.ts.map +1 -1
  69. package/dist/write.js +36 -53
  70. package/package.json +4 -3
  71. package/dist/app-reference.d.ts +0 -2
  72. package/dist/app-reference.d.ts.map +0 -1
  73. package/dist/app-reference.js +0 -2
  74. package/dist/crockford.d.ts +0 -4
  75. package/dist/crockford.d.ts.map +0 -1
  76. package/dist/crockford.js +0 -3
  77. package/dist/house-model.d.ts +0 -2249
  78. package/dist/house-model.d.ts.map +0 -1
  79. package/dist/house-model.js +0 -1237
  80. package/dist/part.d.ts +0 -14
  81. package/dist/part.d.ts.map +0 -1
  82. package/dist/part.js +0 -90
  83. package/dist/room-stream.d.ts +0 -19
  84. package/dist/room-stream.d.ts.map +0 -1
  85. package/dist/room-stream.js +0 -57
  86. package/dist/room-types.d.ts +0 -7
  87. package/dist/room-types.d.ts.map +0 -1
  88. package/dist/room-types.js +0 -126
package/dist/adapter.js CHANGED
@@ -1,50 +1,25 @@
1
+ import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
1
2
  import { stepped } from '@agentshouse/mdruntime';
2
3
  import { capabilities, discoveredRoom, mapDiscovery, parseAuthorityChange, parseDiscovery, trackedFrom, } from './discovery.js';
3
4
  import { createSiteAdapter } from './site.js';
4
- import { authorityRoot, bootstrapping, parseFileAddress, parseGrant, } from './read.js';
5
- import { roomStreams } from './room-stream.js';
6
- import { sha256Hex } from './digest.js';
7
- import { finishedUpload, houseUpload } from './upload.js';
8
- import { houseAction } from './actions.js';
9
- import { classifyDoor, doorRefusal } from './refusal.js';
5
+ import { parseFileAddress, parseGrant } from './read.js';
6
+ import { chunkedHead, chunkLister, chunkPart } from './chunks.js';
7
+ import { finishedUpload, houseUpload, stagedBatch } from './upload.js';
8
+ import { houseAction, HOUSE_LEADING_READS, HOUSE_RENAMED_UNTIL_2026_12_18, HOUSE_RENAMED_UNTIL_2026_12_21, HOUSE_REWRITTEN_UNTIL_2026_12_19, HOUSE_REWRITTEN_UNTIL_2026_12_21, HOUSE_UNKEPT_READS, } from './actions.js';
9
+ import { houseQuery } from './room-query.js';
10
+ import { houseSearch } from './search.js';
11
+ import { answeredFailure, classifyDoor, keyedFailure } from './refusal.js';
12
+ import { UNANSWERED, unusable } from './uncertain.js';
10
13
  import { houseNotifications, } from './stream.js';
11
14
  import { houseDoorRoute, } from './transport.js';
15
+ import { renamedHandle } from './renamed.js';
12
16
  import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
13
- import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
14
- import { followsVersion, logPosition, presented, reachedVersion, roomVersion } from './version.js';
15
- const UNCERTAIN = { kind: 'transport-uncertainty' };
16
- const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
17
- const OCTET_STREAM = 'application/octet-stream';
17
+ import { admittedPath } from './authored-path.js';
18
+ import { followsVersion, reachedVersion, roomVersion } from './version.js';
18
19
  const EXPIRED_ADDRESS = 403;
19
20
  function lapsedGrant(outcome) {
20
21
  return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
21
22
  }
22
- async function heldFiles(authority, held, bound) {
23
- const listed = await held.files(null, bound + 1);
24
- const files = listed.slice(0, bound);
25
- const through = listed.length > bound ? (files.at(-1)?.path ?? null) : null;
26
- return files.length === 0 ? null : { room: authority, through, files };
27
- }
28
- async function reused(scope, held) {
29
- const sent = new Set(scope.contents.map((entry) => entry.path));
30
- const contents = [...scope.contents];
31
- const asked = scope.files.filter((file) => file.binary === undefined && !sent.has(file.path));
32
- if (asked.length === 0)
33
- return scope;
34
- if (held === undefined)
35
- return null;
36
- const kept = await held.contents(asked.map(({ path }) => path));
37
- for (const file of asked) {
38
- const found = kept.get(file.path);
39
- if (found === undefined ||
40
- found.revision !== file.revision ||
41
- (await sha256Hex(found.content)) !== file.sha256) {
42
- return null;
43
- }
44
- contents.push({ path: file.path, content: found.content });
45
- }
46
- return { ...scope, contents };
47
- }
48
23
  export function createAgentsHouseAdapter(options) {
49
24
  if ('site' in options)
50
25
  return createSiteAdapter(options.site, options.snapshot === true);
@@ -52,10 +27,12 @@ export function createAgentsHouseAdapter(options) {
52
27
  const notifications = houseNotifications(transport, 'credential', {
53
28
  opened: async (frame) => (frame === null ? null : opened(frame)),
54
29
  changed,
30
+ expired: (entries) => lister.askAll(entries),
55
31
  });
56
32
  const tracked = new Map();
57
- const rooms = roomStreams('credential');
58
- const unreused = new Set();
33
+ const lister = chunkLister(transport, () => declared().max_prefixes, (locator) => tracked.get(locator));
34
+ const chunked = new Map();
35
+ const renewals = new WeakMap();
59
36
  let bounds;
60
37
  function declared() {
61
38
  if (bounds === undefined)
@@ -68,19 +45,23 @@ export function createAgentsHouseAdapter(options) {
68
45
  return null;
69
46
  bounds = document.bounds;
70
47
  tracked.clear();
48
+ lister.forget();
71
49
  for (const entry of trackedFrom(document))
72
50
  tracked.set(entry.locator, entry);
73
51
  notifications.track([...tracked.values()]);
74
52
  return {
75
53
  ...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
76
54
  member: document.member,
55
+ timeZone: document.timeZone,
56
+ roomList: document.roomList,
77
57
  };
78
58
  }
79
59
  function changed(frame) {
80
60
  const change = parseAuthorityChange(frame);
81
61
  if (change === null)
82
62
  return null;
83
- for (const locator of change.left)
63
+ const unheld = [...change.left, ...change.listed];
64
+ for (const locator of unheld)
84
65
  tracked.delete(locator);
85
66
  for (const entry of trackedFrom(change))
86
67
  tracked.set(entry.locator, entry);
@@ -88,45 +69,63 @@ export function createAgentsHouseAdapter(options) {
88
69
  return {
89
70
  kind: 'authority-changed',
90
71
  rooms: change.authorities.map((authority) => discoveredRoom(authority)),
91
- left: change.left,
72
+ left: unheld,
92
73
  member: change.member,
74
+ timeZone: change.timeZone,
75
+ roomList: { ...change.roomList, left: change.left },
93
76
  };
94
77
  }
95
- async function streamedPage(entry, token, held) {
96
- const part = await rooms.part(entry, token);
97
- if ('kind' in part)
98
- return part;
99
- const scope = await reused(part.scope, held);
100
- if (scope === null) {
101
- unreused.add(entry.locator);
102
- return UNCERTAIN_READ;
103
- }
104
- return {
105
- ...(await stepped(bootstrapping(scope))),
106
- ...(part.models === undefined ? {} : { models: part.models }),
107
- ...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
108
- bytes: part.bytes,
109
- };
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) };
110
103
  }
111
- async function openedRoom(entry, request) {
112
- const reusing = unreused.delete(entry.locator) ? undefined : request.held;
113
- const files = reusing === undefined
114
- ? null
115
- : await heldFiles(entry.authority, reusing, declared().max_held_files);
116
- const answered = await transport.streamed(houseDoorRoute('bootstrap'), {
117
- prefixes: [authorityRoot(entry.handle)],
118
- ...(files === null ? {} : { held: [files] }),
119
- }, request.signal ?? new AbortController().signal);
120
- if (answered.room === null)
121
- return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN_READ;
122
- return rooms.head(entry, answered.room, request.arriving, request.signal);
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);
119
+ }
120
+ notifications.send(rooms);
123
121
  }
124
- function held(rooms) {
125
- notifications.send(rooms.flatMap((room) => {
126
- const entry = tracked.get(room.locator);
127
- const at = logPosition(room.roomVersion);
128
- return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
129
- }));
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);
130
129
  }
131
130
  function authorityFor(locator) {
132
131
  return tracked.get(locator);
@@ -151,8 +150,9 @@ export function createAgentsHouseAdapter(options) {
151
150
  if (handed !== undefined && handed.sha256 === sha256) {
152
151
  return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
153
152
  }
154
- const minted = await transport.door(houseDoorRoute('batch-upload'), {
153
+ const minted = await transport.door(houseDoorRoute('update'), {
155
154
  ...head,
155
+ op: 'stage',
156
156
  paths,
157
157
  bytes,
158
158
  sha256,
@@ -164,39 +164,21 @@ export function createAgentsHouseAdapter(options) {
164
164
  }
165
165
  const grant = parseGrant(minted.body);
166
166
  if (grant === null)
167
- return { outcome: UNCERTAIN };
167
+ return { outcome: unusable() };
168
168
  const delivered = await transport.transfer({
169
- act: 'authored_batch_upload',
170
169
  url: grant.url,
171
170
  body: `${grant.operation}\n${delta}`,
172
171
  });
173
- if (delivered.status !== 200)
174
- return { outcome: UNCERTAIN };
172
+ if (delivered.status !== 200) {
173
+ return { outcome: answeredFailure(delivered.status, delivered.body) };
174
+ }
175
175
  const holding = parseGrant(delivered.body);
176
176
  if (holding === null)
177
- return { outcome: UNCERTAIN };
177
+ return { outcome: unusable() };
178
178
  const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
179
179
  await keep(upload);
180
180
  return { body: { ...head, paths, upload, runtime: notifications.runtime } };
181
181
  }
182
- async function staged(answer, { changeBatch: batch, file }) {
183
- const refusal = doorRefusal(answer.body);
184
- if (refusal?.code !== 'files_unstaged')
185
- return null;
186
- const uploads = refusal.fields.upload;
187
- if (!Array.isArray(uploads))
188
- return false;
189
- for (const named of uploads) {
190
- const upload = houseUpload(named);
191
- const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
192
- if (upload === null || change === undefined)
193
- return false;
194
- const finished = await finishedUpload(transport, upload, await file(change.localId));
195
- if (finished?.body?.staged !== true)
196
- return false;
197
- }
198
- return true;
199
- }
200
182
  async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
201
183
  const inline = { ...head, changes, runtime: notifications.runtime };
202
184
  const prepared = uploadable(inline, bytes, declared())
@@ -204,13 +186,12 @@ export function createAgentsHouseAdapter(options) {
204
186
  : { body: inline };
205
187
  if ('outcome' in prepared)
206
188
  return prepared.outcome;
207
- const answer = await transport.door(houseDoorRoute('batch'), prepared.body);
208
- const stagedFiles = await staged(answer, request);
209
- if (stagedFiles === false)
210
- return UNCERTAIN;
211
- const settled = stagedFiles === null ? answer : await transport.door(houseDoorRoute('batch'), prepared.body);
212
- if (stagedFiles === true && (await staged(settled, request)) !== null)
213
- return UNCERTAIN;
189
+ const settled = await stagedBatch(transport, prepared.body, (sha256) => {
190
+ const change = request.changeBatch.changes.find((held) => held.kind === 'binary' && held.sha256 === sha256);
191
+ return change === undefined ? null : request.file(change.localId);
192
+ });
193
+ if ('kind' in settled)
194
+ return settled;
214
195
  return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
215
196
  ? undefined
216
197
  : {
@@ -218,28 +199,26 @@ export function createAgentsHouseAdapter(options) {
218
199
  destination: { authority: into.authority, handle: into.handle },
219
200
  }));
220
201
  }
221
- function addressed(answer, locator) {
222
- const failure = classifyDoor(answer.status, answer.body, locator);
223
- if (failure !== null) {
224
- return failure.kind === 'scoped-refusal'
225
- ? {
226
- kind: 'rejected',
227
- code: failure.code,
228
- fields: failure.fields,
229
- retryable: failure.retryable,
230
- }
231
- : failure;
232
- }
233
- const address = parseFileAddress(answer.body);
234
- return address === null ? UNCERTAIN_READ : { kind: 'address', ...address };
235
- }
236
- function linked(answer, locator) {
237
- const address = addressed(answer, locator);
238
- return address.kind === 'address'
239
- ? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
240
- : address;
202
+ async function mutated(request, keep, entry, into) {
203
+ const batch = request.changeBatch;
204
+ const mapped = into === undefined
205
+ ? houseChanges(batch, entry.handle)
206
+ : houseMove(batch, entry.handle, into.handle);
207
+ if (mapped.kind === 'unmapped')
208
+ return rejectedMapping(mapped);
209
+ const head = operationHead(batch);
210
+ const delta = deltaBody(mapped.changes);
211
+ const bytes = deltaBytes(delta);
212
+ const handed = request.upload;
213
+ const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
214
+ const outcome = await answer(handed);
215
+ if (handed === undefined || !lapsedGrant(outcome))
216
+ return outcome;
217
+ return answer(undefined);
241
218
  }
242
- function refusedAttach(answer, locator) {
219
+ function refusedOn(answer, locator) {
220
+ if (locator === null)
221
+ return keyedFailure(answer.status, answer.body);
243
222
  const failure = classifyDoor(answer.status, answer.body, locator);
244
223
  if (failure === null)
245
224
  return null;
@@ -252,6 +231,48 @@ export function createAgentsHouseAdapter(options) {
252
231
  }
253
232
  : failure;
254
233
  }
234
+ function addressed(answer, locator) {
235
+ const failure = refusedOn(answer, locator);
236
+ if (failure !== null)
237
+ return failure;
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
+ async function attached(request, into) {
248
+ const locator = into?.locator ?? null;
249
+ const declared = await transport.door(houseDoorRoute('files/attach'), {
250
+ ...(into === null ? {} : { room_ref: into.authority }),
251
+ name: request.name,
252
+ bytes: request.byteLength,
253
+ sha256: request.sha256,
254
+ media_type: request.mediaType,
255
+ });
256
+ const refused = refusedOn(declared, locator);
257
+ if (refused !== null)
258
+ return refused;
259
+ const upload = houseUpload(declared.body?.upload);
260
+ if (upload === null)
261
+ return unusable();
262
+ const finished = await finishedUpload(transport, upload, request.blob);
263
+ if ('unfinished' in finished)
264
+ return answeredFailure(finished.unfinished, null);
265
+ const unfinished = refusedOn(finished, locator);
266
+ if (unfinished !== null)
267
+ return unfinished;
268
+ const { path, revision, link } = (finished.body ?? {});
269
+ if (into === null)
270
+ return typeof link === 'string' ? { kind: 'linked', link } : unusable();
271
+ const root = `/rooms/${into.handle}/`;
272
+ return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
273
+ ? { kind: 'attached', path: path.slice(root.length), revision }
274
+ : unusable();
275
+ }
255
276
  async function downloaded(ask, locator) {
256
277
  let address = addressed(await ask(), locator);
257
278
  if (address.kind !== 'address')
@@ -263,20 +284,24 @@ export function createAgentsHouseAdapter(options) {
263
284
  return address;
264
285
  read = await transport.download(address.url);
265
286
  }
266
- if (read.status !== 200 || read.body === null)
267
- return UNCERTAIN_READ;
287
+ if (read.status !== 200)
288
+ return answeredFailure(read.status, null);
289
+ if (read.body === null)
290
+ return unusable();
268
291
  return {
269
292
  kind: 'binary',
270
293
  body: read.body,
271
294
  mediaType: address.mediaType,
272
295
  sha256: address.sha256,
296
+ url: address.url,
297
+ copies: address.copies,
273
298
  };
274
299
  }
275
300
  function pathAddress(request) {
276
301
  const entry = authorityFor(request.locator);
277
302
  if (entry === undefined)
278
303
  return null;
279
- return () => transport.door(houseDoorRoute('files/get'), {
304
+ return () => transport.door(houseDoorRoute('files/read'), {
280
305
  room_ref: entry.authority,
281
306
  path: request.path,
282
307
  revision: request.revision,
@@ -284,7 +309,15 @@ export function createAgentsHouseAdapter(options) {
284
309
  }
285
310
  return {
286
311
  roomTypes: HOUSE_ROOM_TYPES,
287
- nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
312
+ typedPaths: HOUSE_TYPED_PATHS,
313
+ pathRule: admittedPath,
314
+ unkeptReads: HOUSE_UNKEPT_READS,
315
+ leadingReads: HOUSE_LEADING_READS,
316
+ renamedActions: new Map([...HOUSE_RENAMED_UNTIL_2026_12_18, ...HOUSE_RENAMED_UNTIL_2026_12_21]),
317
+ rewrittenInputs: new Map([
318
+ ...HOUSE_REWRITTEN_UNTIL_2026_12_19,
319
+ ...HOUSE_REWRITTEN_UNTIL_2026_12_21,
320
+ ]),
288
321
  async authorize() {
289
322
  return options.authorize();
290
323
  },
@@ -293,48 +326,36 @@ export function createAgentsHouseAdapter(options) {
293
326
  if (entry === undefined)
294
327
  return { kind: 'room-not-readable', locator: request.locator };
295
328
  return request.pageToken === undefined
296
- ? openedRoom(entry, request)
297
- : streamedPage(entry, request.pageToken, request.held);
329
+ ? listedRoom(entry)
330
+ : chunkPage(entry, request.pageToken, request.arriving);
298
331
  },
299
332
  async mutate(_authorization, request, keep) {
300
333
  const entry = authorityFor(request.locator);
301
334
  if (entry === undefined)
302
335
  return { kind: 'room-not-readable', locator: request.locator };
303
- const batch = request.changeBatch;
304
- const destination = batch.between?.destination.room;
336
+ const destination = request.changeBatch.between?.destination.room;
305
337
  const into = destination === undefined ? undefined : authorityFor(destination);
306
338
  if (destination !== undefined && into === undefined) {
307
339
  return { kind: 'room-not-readable', locator: destination };
308
340
  }
309
- const mapped = into === undefined
310
- ? houseChanges(batch, entry.handle)
311
- : houseMove(batch, entry.handle, into.handle);
312
- if (mapped.kind === 'unmapped')
313
- return rejectedMapping(mapped);
314
- const head = operationHead(batch);
315
- const delta = deltaBody(mapped.changes);
316
- const bytes = deltaBytes(delta);
317
- const handed = request.upload;
318
- const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
319
- const outcome = await answer(handed);
320
- if (handed === undefined || !lapsedGrant(outcome))
341
+ const outcome = await mutated(request, keep, entry, into);
342
+ const renamed = renamedHandle(outcome);
343
+ if (renamed === null)
321
344
  return outcome;
322
- return answer(undefined);
345
+ const moved = (held) => held.handle === renamed.from ? { ...held, handle: renamed.to } : held;
346
+ return mutated(request, keep, moved(entry), into === undefined ? undefined : moved(into));
323
347
  },
324
348
  async history(_authorization, request) {
325
349
  const entry = authorityFor(request.locator);
326
350
  if (entry === undefined)
327
351
  return { kind: 'room-not-readable', locator: request.locator };
328
- const answer = await transport.door(houseDoorRoute('revisions'), revisionBody({
352
+ const answer = await transport.door(houseDoorRoute('files/revisions/list'), revisionBody({
329
353
  path: request.path,
330
354
  handle: entry.handle,
331
355
  ...(request.revision === undefined ? {} : { revision: request.revision }),
332
356
  ...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
333
357
  }));
334
- return historyOutcome(answer.status, answer.body, entry.locator, {
335
- path: request.path,
336
- ...(request.revision === undefined ? {} : { revision: request.revision }),
337
- });
358
+ return historyOutcome(answer.status, answer.body, entry.locator, request);
338
359
  },
339
360
  async binary(_authorization, request) {
340
361
  const ask = pathAddress(request);
@@ -343,39 +364,21 @@ export function createAgentsHouseAdapter(options) {
343
364
  return downloaded(ask, request.locator);
344
365
  },
345
366
  async link(_authorization, request) {
367
+ if (request.kind === 'key') {
368
+ return linked(await transport.door(houseDoorRoute('files/read'), { link: request.link }), null);
369
+ }
346
370
  const ask = pathAddress(request);
347
371
  if (ask === null)
348
372
  return { kind: 'room-not-readable', locator: request.locator };
349
373
  return linked(await ask(), request.locator);
350
374
  },
351
375
  async attach(_authorization, request) {
376
+ if (request.locator === undefined)
377
+ return attached(request, null);
352
378
  const entry = authorityFor(request.locator);
353
379
  if (entry === undefined)
354
380
  return { kind: 'room-not-readable', locator: request.locator };
355
- const declared = await transport.door(houseDoorRoute('files/attach'), {
356
- room_ref: entry.authority,
357
- name: request.name,
358
- bytes: request.byteLength,
359
- sha256: request.sha256,
360
- media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
361
- });
362
- const refused = refusedAttach(declared, request.locator);
363
- if (refused !== null)
364
- return refused;
365
- const upload = houseUpload(declared.body?.upload);
366
- if (upload === null)
367
- return UNCERTAIN_READ;
368
- const finished = await finishedUpload(transport, upload, request.blob);
369
- if (finished === null)
370
- return UNCERTAIN_READ;
371
- const unfinished = refusedAttach(finished, request.locator);
372
- if (unfinished !== null)
373
- return unfinished;
374
- const { path, revision } = (finished.body ?? {});
375
- const root = `/rooms/${entry.handle}/`;
376
- return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
377
- ? { kind: 'attached', path: path.slice(root.length), revision }
378
- : UNCERTAIN_READ;
381
+ return attached(request, entry);
379
382
  },
380
383
  reached(locator, version, target) {
381
384
  return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
@@ -386,8 +389,14 @@ export function createAgentsHouseAdapter(options) {
386
389
  async action(_authorization, request) {
387
390
  return withAt(await houseAction(transport, request));
388
391
  },
392
+ search(_authorization, request) {
393
+ return houseSearch(transport, [...tracked.values()], request);
394
+ },
395
+ queryHouse(_authorization, request) {
396
+ return houseQuery(transport, request);
397
+ },
389
398
  roomStream: {
390
- hold: held,
399
+ hold,
391
400
  observe: notifications.observe,
392
401
  },
393
402
  conversations: notifications.conversations,
@@ -0,0 +1,61 @@
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 LOCAL_COPY_MANIFEST = ".house";
6
+ export declare const LOCAL_COPY_ROOT_NAMES: readonly string[];
7
+ export declare const AUTHORED_NAME_MAX_BYTES = 255;
8
+ export declare const AUTHORED_PATH_MAX_BYTES = 768;
9
+ export declare const AUTHORED_NAME_RULE: {
10
+ readonly refusedCharacters: '/\\:*?"<>|';
11
+ readonly controlCharacters: 'Cc';
12
+ readonly refusedEnds: ' .';
13
+ readonly refusedStart: '-';
14
+ readonly gitNames: readonly ['.git', 'git~1'];
15
+ readonly windowsNames: readonly ["CON", "PRN", "AUX", "NUL", ...string[]];
16
+ readonly generatedNames: readonly ["_provenance", "_revisions", "_derived"];
17
+ readonly nameMaxBytes: 255;
18
+ readonly pathMaxBytes: 768;
19
+ };
20
+ export type NameRefusal = {
21
+ readonly rule: 'unicode';
22
+ } | {
23
+ readonly rule: 'character';
24
+ readonly character: string;
25
+ } | {
26
+ readonly rule: 'empty';
27
+ } | {
28
+ readonly rule: 'dots';
29
+ } | {
30
+ readonly rule: 'end';
31
+ readonly character: string;
32
+ } | {
33
+ readonly rule: 'git';
34
+ } | {
35
+ readonly rule: 'windows';
36
+ readonly reserved: string;
37
+ } | {
38
+ readonly rule: 'name_bytes';
39
+ readonly bytes: number;
40
+ } | {
41
+ readonly rule: 'start';
42
+ } | {
43
+ readonly rule: 'generated';
44
+ } | {
45
+ readonly rule: 'nfc';
46
+ };
47
+ export type PathRefusal = (NameRefusal & {
48
+ readonly name: string;
49
+ }) | {
50
+ readonly rule: 'root';
51
+ readonly name: string;
52
+ } | {
53
+ readonly rule: 'path_bytes';
54
+ readonly bytes: number;
55
+ };
56
+ export declare function utf8Bytes(text: string): number;
57
+ export declare function nameRefusal(name: string): NameRefusal | null;
58
+ export declare function pathRefusal(path: string): PathRefusal | null;
59
+ export declare function admittedPath(path: string): boolean;
60
+ export declare function sameName(left: string, right: string): boolean;
61
+ export declare function fittedName(name: string, count?: number, tail?: string): string;
@@ -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,mBAAmB,WAAW,CAAC;AAI5C,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAKlD,CAAC;AAEF,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAI3C,eAAO,MAAM,kBAAkB;aAC7B,iBAAiB,EAAE,YAAY;aAC/B,iBAAiB,EAAE,IAAI;aACvB,WAAW,EAAE,IAAI;aACjB,YAAY,EAAE,GAAG;aACjB,QAAQ,YAAG,MAAM,EAAE,OAAO;aAC1B,YAAY;aAUZ,cAAc;aACd,YAAY;aACZ,YAAY;CACJ,CAAC;AAEX,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC;AAE7B,MAAM,MAAM,WAAW,GACnB,CAAC,WAAW,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GACzC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAsB5D,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO9C;AAYD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAiB5D;AASD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAU5D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKlD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7D;AAyCD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAI,EAAE,IAAI,SAAK,GAAG,MAAM,CAUrE"}