@agentshouse/mdruntime-adapter 0.1.0-cb8fc491b1a92 → 0.1.0-cba21ddb21067

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 (83) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +4 -164
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +25 -228
  5. package/dist/adapter.d.ts +0 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +156 -151
  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/discovery.d.ts +30 -9
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +184 -22
  18. package/dist/history.d.ts +6 -0
  19. package/dist/history.d.ts.map +1 -0
  20. package/dist/history.js +85 -0
  21. package/dist/index.d.ts +7 -7
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +6 -5
  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 +15 -20
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +66 -164
  31. package/dist/refusal.d.ts +3 -2
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +17 -7
  34. package/dist/search.d.ts +4 -0
  35. package/dist/search.d.ts.map +1 -0
  36. package/dist/search.js +47 -0
  37. package/dist/session-content/bounds.d.ts +7 -0
  38. package/dist/session-content/check.d.ts +18 -0
  39. package/dist/session-content/index.d.ts +7 -0
  40. package/dist/session-content/parts.d.ts +103 -0
  41. package/dist/session-content/state.d.ts +61 -0
  42. package/dist/session-content/turn.d.ts +328 -0
  43. package/dist/site.d.ts +0 -1
  44. package/dist/site.d.ts.map +1 -1
  45. package/dist/site.js +67 -68
  46. package/dist/space-schema.d.ts +6 -0
  47. package/dist/space-schema.d.ts.map +1 -0
  48. package/dist/space-schema.js +11 -0
  49. package/dist/stream.d.ts +15 -6
  50. package/dist/stream.d.ts.map +1 -1
  51. package/dist/stream.js +192 -62
  52. package/dist/transport.d.ts +62 -24
  53. package/dist/transport.d.ts.map +1 -1
  54. package/dist/transport.js +16 -9
  55. package/dist/uncertain.d.ts +5 -0
  56. package/dist/uncertain.d.ts.map +1 -0
  57. package/dist/uncertain.js +11 -0
  58. package/dist/upload.d.ts +3 -2
  59. package/dist/upload.d.ts.map +1 -1
  60. package/dist/upload.js +8 -6
  61. package/dist/version.d.ts +0 -1
  62. package/dist/write.d.ts +2 -3
  63. package/dist/write.d.ts.map +1 -1
  64. package/dist/write.js +27 -42
  65. package/package.json +3 -2
  66. package/dist/app-reference.d.ts +0 -2
  67. package/dist/app-reference.d.ts.map +0 -1
  68. package/dist/app-reference.js +0 -2
  69. package/dist/crockford.d.ts +0 -4
  70. package/dist/crockford.d.ts.map +0 -1
  71. package/dist/crockford.js +0 -3
  72. package/dist/house-model.d.ts +0 -2983
  73. package/dist/house-model.d.ts.map +0 -1
  74. package/dist/house-model.js +0 -1643
  75. package/dist/part.d.ts +0 -14
  76. package/dist/part.d.ts.map +0 -1
  77. package/dist/part.js +0 -90
  78. package/dist/room-stream.d.ts +0 -19
  79. package/dist/room-stream.d.ts.map +0 -1
  80. package/dist/room-stream.js +0 -57
  81. package/dist/room-types.d.ts +0 -7
  82. package/dist/room-types.d.ts.map +0 -1
  83. package/dist/room-types.js +0 -126
package/dist/adapter.js CHANGED
@@ -1,99 +1,131 @@
1
+ import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
1
2
  import { stepped } from '@agentshouse/mdruntime';
2
- import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
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';
5
+ import { parseFileAddress, parseGrant } from './read.js';
6
+ import { chunkedHead, chunkLister, chunkPart } from './chunks.js';
7
7
  import { finishedUpload, houseUpload } from './upload.js';
8
- import { houseAction } from './actions.js';
9
- import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
10
- import { houseNotifications } from './stream.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';
11
13
  import { houseDoorRoute, } from './transport.js';
12
14
  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';
15
+ import { admittedPath } from './authored-path.js';
16
+ import { followsVersion, reachedVersion, roomVersion } from './version.js';
18
17
  const EXPIRED_ADDRESS = 403;
19
18
  function lapsedGrant(outcome) {
20
19
  return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
21
20
  }
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 };
21
+ function unstagedRefusal(answer) {
22
+ const refusal = doorRefusal(answer.body);
23
+ return refusal?.code === 'files_unstaged' ? refusal : null;
47
24
  }
48
25
  export function createAgentsHouseAdapter(options) {
49
26
  if ('site' in options)
50
27
  return createSiteAdapter(options.site, options.snapshot === true);
51
28
  const transport = options.transport;
52
- 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
+ });
53
34
  const tracked = new Map();
54
- const rooms = roomStreams('credential');
55
- const unreused = new Set();
35
+ const lister = chunkLister(transport, () => declared().max_prefixes, (locator) => tracked.get(locator));
36
+ const chunked = new Map();
37
+ const renewals = new WeakMap();
56
38
  let bounds;
57
39
  function declared() {
58
40
  if (bounds === undefined)
59
41
  throw new Error('no Discovery declared the bounds');
60
42
  return bounds;
61
43
  }
62
- async function streamedPage(entry, token, held) {
63
- const part = await rooms.part(entry, token);
64
- if ('kind' in part)
65
- return part;
66
- const scope = await reused(part.scope, held);
67
- if (scope === null) {
68
- unreused.add(entry.locator);
69
- return UNCERTAIN_READ;
70
- }
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()]);
71
54
  return {
72
- ...(await stepped(bootstrapping(scope))),
73
- ...(part.models === undefined ? {} : { models: part.models }),
74
- ...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
75
- bytes: part.bytes,
55
+ ...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
56
+ member: document.member,
57
+ roomList: document.roomList,
76
58
  };
77
59
  }
78
- async function openedRoom(entry, request) {
79
- const reusing = unreused.delete(entry.locator) ? undefined : request.held;
80
- const files = reusing === undefined
81
- ? null
82
- : await heldFiles(entry.authority, reusing, declared().max_held_files);
83
- const answered = await transport.streamed(houseDoorRoute('bootstrap'), {
84
- prefixes: [authorityRoot(entry.handle)],
85
- ...(files === null ? {} : { held: [files] }),
86
- }, request.signal ?? new AbortController().signal);
87
- if (answered.room === null)
88
- return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN_READ;
89
- return rooms.head(entry, answered.room, request.arriving, request.signal);
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
+ };
77
+ }
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);
119
+ }
120
+ notifications.send(rooms);
90
121
  }
91
- function held(rooms) {
92
- notifications.send(rooms.flatMap((room) => {
93
- const entry = tracked.get(room.locator);
94
- const at = logPosition(room.roomVersion);
95
- return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
96
- }));
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);
97
129
  }
98
130
  function authorityFor(locator) {
99
131
  return tracked.get(locator);
@@ -118,7 +150,7 @@ export function createAgentsHouseAdapter(options) {
118
150
  if (handed !== undefined && handed.sha256 === sha256) {
119
151
  return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
120
152
  }
121
- const minted = await transport.door(houseDoorRoute('batch-upload'), {
153
+ const minted = await transport.door(houseDoorRoute('files/batch-upload'), {
122
154
  ...head,
123
155
  paths,
124
156
  bytes,
@@ -131,38 +163,38 @@ export function createAgentsHouseAdapter(options) {
131
163
  }
132
164
  const grant = parseGrant(minted.body);
133
165
  if (grant === null)
134
- return { outcome: UNCERTAIN };
166
+ return { outcome: unusable() };
135
167
  const delivered = await transport.transfer({
136
- act: 'authored_batch_upload',
137
168
  url: grant.url,
138
169
  body: `${grant.operation}\n${delta}`,
139
170
  });
140
- if (delivered.status !== 200)
141
- return { outcome: UNCERTAIN };
171
+ if (delivered.status !== 200) {
172
+ return { outcome: answeredFailure(delivered.status, delivered.body) };
173
+ }
142
174
  const holding = parseGrant(delivered.body);
143
175
  if (holding === null)
144
- return { outcome: UNCERTAIN };
176
+ return { outcome: unusable() };
145
177
  const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
146
178
  await keep(upload);
147
179
  return { body: { ...head, paths, upload, runtime: notifications.runtime } };
148
180
  }
149
- async function staged(answer, { changeBatch: batch, file }) {
150
- const refusal = doorRefusal(answer.body);
151
- if (refusal?.code !== 'files_unstaged')
152
- return null;
153
- const uploads = refusal.fields.upload;
181
+ async function staged(uploads, { changeBatch: batch, file }) {
154
182
  if (!Array.isArray(uploads))
155
- return false;
183
+ return unusable();
156
184
  for (const named of uploads) {
157
185
  const upload = houseUpload(named);
158
186
  const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
159
187
  if (upload === null || change === undefined)
160
- return false;
188
+ return unusable();
161
189
  const finished = await finishedUpload(transport, upload, await file(change.localId));
162
- if (finished?.body?.staged !== true)
163
- return false;
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();
164
196
  }
165
- return true;
197
+ return null;
166
198
  }
167
199
  async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
168
200
  const inline = { ...head, changes, runtime: notifications.runtime };
@@ -171,13 +203,19 @@ export function createAgentsHouseAdapter(options) {
171
203
  : { body: inline };
172
204
  if ('outcome' in prepared)
173
205
  return prepared.outcome;
174
- const answer = await transport.door(houseDoorRoute('batch'), prepared.body);
175
- const stagedFiles = await staged(answer, request);
176
- if (stagedFiles === false)
177
- return UNCERTAIN;
178
- const settled = stagedFiles === null ? answer : await transport.door(houseDoorRoute('batch'), prepared.body);
179
- if (stagedFiles === true && (await staged(settled, request)) !== null)
180
- return UNCERTAIN;
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
+ }
181
219
  return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
182
220
  ? undefined
183
221
  : {
@@ -198,7 +236,7 @@ export function createAgentsHouseAdapter(options) {
198
236
  : failure;
199
237
  }
200
238
  const address = parseFileAddress(answer.body);
201
- return address === null ? UNCERTAIN_READ : { kind: 'address', ...address };
239
+ return address === null ? unusable() : { kind: 'address', ...address };
202
240
  }
203
241
  function linked(answer, locator) {
204
242
  const address = addressed(answer, locator);
@@ -230,8 +268,10 @@ export function createAgentsHouseAdapter(options) {
230
268
  return address;
231
269
  read = await transport.download(address.url);
232
270
  }
233
- if (read.status !== 200 || read.body === null)
234
- return UNCERTAIN_READ;
271
+ if (read.status !== 200)
272
+ return answeredFailure(read.status, null);
273
+ if (read.body === null)
274
+ return unusable();
235
275
  return {
236
276
  kind: 'binary',
237
277
  body: read.body,
@@ -243,7 +283,7 @@ export function createAgentsHouseAdapter(options) {
243
283
  const entry = authorityFor(request.locator);
244
284
  if (entry === undefined)
245
285
  return null;
246
- return () => transport.door(houseDoorRoute('files/get'), {
286
+ return () => transport.door(houseDoorRoute('files/read'), {
247
287
  room_ref: entry.authority,
248
288
  path: request.path,
249
289
  revision: request.revision,
@@ -251,54 +291,20 @@ export function createAgentsHouseAdapter(options) {
251
291
  }
252
292
  return {
253
293
  roomTypes: HOUSE_ROOM_TYPES,
254
- nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
294
+ typedPaths: HOUSE_TYPED_PATHS,
295
+ pathRule: admittedPath,
296
+ unkeptReads: HOUSE_UNKEPT_READS,
297
+ leadingReads: HOUSE_LEADING_READS,
255
298
  async authorize() {
256
299
  return options.authorize();
257
300
  },
258
- async discover(_authorization, scope) {
259
- const answer = await transport.door(houseDoorRoute('discover'), {
260
- prefixes: [...DISCOVER_PREFIXES],
261
- ...(scope === undefined ? {} : { rooms: scope.authorities }),
262
- });
263
- const failed = discoveryFailure(answer.status, answer.body);
264
- if (failed !== null)
265
- return failed;
266
- const document = parseDiscovery(answer.body);
267
- if (document === null)
268
- return { kind: 'transport-uncertainty' };
269
- bounds = document.bounds;
270
- const entries = trackedFrom(document);
271
- const covered = scope === undefined
272
- ? null
273
- : [
274
- ...new Set([
275
- ...[...tracked.values()]
276
- .filter((entry) => scope.authorities.includes(entry.authority))
277
- .map((entry) => entry.locator),
278
- ...entries.map((entry) => entry.locator),
279
- ]),
280
- ];
281
- if (covered === null)
282
- tracked.clear();
283
- else
284
- for (const locator of covered)
285
- tracked.delete(locator);
286
- for (const entry of entries)
287
- tracked.set(entry.locator, entry);
288
- notifications.track([...tracked.values()]);
289
- return {
290
- ...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
291
- member: document.member,
292
- ...(covered === null ? {} : { covered }),
293
- };
294
- },
295
301
  async bootstrap(_authorization, request) {
296
302
  const entry = authorityFor(request.locator);
297
303
  if (entry === undefined)
298
304
  return { kind: 'room-not-readable', locator: request.locator };
299
305
  return request.pageToken === undefined
300
- ? openedRoom(entry, request)
301
- : streamedPage(entry, request.pageToken, request.held);
306
+ ? listedRoom(entry)
307
+ : chunkPage(entry, request.pageToken, request.arriving);
302
308
  },
303
309
  async mutate(_authorization, request, keep) {
304
310
  const entry = authorityFor(request.locator);
@@ -315,7 +321,7 @@ export function createAgentsHouseAdapter(options) {
315
321
  : houseMove(batch, entry.handle, into.handle);
316
322
  if (mapped.kind === 'unmapped')
317
323
  return rejectedMapping(mapped);
318
- const head = operationHead(batch);
324
+ const head = operationHead(batch, entry.authority);
319
325
  const delta = deltaBody(mapped.changes);
320
326
  const bytes = deltaBytes(delta);
321
327
  const handed = request.upload;
@@ -329,16 +335,13 @@ export function createAgentsHouseAdapter(options) {
329
335
  const entry = authorityFor(request.locator);
330
336
  if (entry === undefined)
331
337
  return { kind: 'room-not-readable', locator: request.locator };
332
- const answer = await transport.door(houseDoorRoute('revisions'), revisionBody({
338
+ const answer = await transport.door(houseDoorRoute('files/revisions/list'), revisionBody({
333
339
  path: request.path,
334
340
  handle: entry.handle,
335
341
  ...(request.revision === undefined ? {} : { revision: request.revision }),
336
342
  ...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
337
343
  }));
338
- return historyOutcome(answer.status, answer.body, entry.locator, {
339
- path: request.path,
340
- ...(request.revision === undefined ? {} : { revision: request.revision }),
341
- });
344
+ return historyOutcome(answer.status, answer.body, entry.locator, request);
342
345
  },
343
346
  async binary(_authorization, request) {
344
347
  const ask = pathAddress(request);
@@ -361,17 +364,17 @@ export function createAgentsHouseAdapter(options) {
361
364
  name: request.name,
362
365
  bytes: request.byteLength,
363
366
  sha256: request.sha256,
364
- media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
367
+ media_type: request.mediaType,
365
368
  });
366
369
  const refused = refusedAttach(declared, request.locator);
367
370
  if (refused !== null)
368
371
  return refused;
369
372
  const upload = houseUpload(declared.body?.upload);
370
373
  if (upload === null)
371
- return UNCERTAIN_READ;
374
+ return unusable();
372
375
  const finished = await finishedUpload(transport, upload, request.blob);
373
- if (finished === null)
374
- return UNCERTAIN_READ;
376
+ if ('unfinished' in finished)
377
+ return answeredFailure(finished.unfinished, null);
375
378
  const unfinished = refusedAttach(finished, request.locator);
376
379
  if (unfinished !== null)
377
380
  return unfinished;
@@ -379,7 +382,7 @@ export function createAgentsHouseAdapter(options) {
379
382
  const root = `/rooms/${entry.handle}/`;
380
383
  return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
381
384
  ? { kind: 'attached', path: path.slice(root.length), revision }
382
- : UNCERTAIN_READ;
385
+ : unusable();
383
386
  },
384
387
  reached(locator, version, target) {
385
388
  return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
@@ -390,9 +393,11 @@ export function createAgentsHouseAdapter(options) {
390
393
  async action(_authorization, request) {
391
394
  return withAt(await houseAction(transport, request));
392
395
  },
396
+ search(_authorization, request) {
397
+ return houseSearch(transport, [...tracked.values()], request);
398
+ },
393
399
  roomStream: {
394
- hold: held,
395
- reopen: notifications.reopen,
400
+ hold,
396
401
  observe: notifications.observe,
397
402
  },
398
403
  conversations: notifications.conversations,
@@ -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"}
@@ -0,0 +1,34 @@
1
+ import { APP_PREFERENCES_HOME, APP_REFERENCE_PATTERN } from '@agentshouse/mdmodel';
2
+ export const GENERATED_PROVENANCE = '_provenance';
3
+ export const GENERATED_REVISIONS = '_revisions';
4
+ export const RESERVED_DERIVED = '_derived';
5
+ export const WHOLE_ESCAPED_NAMES = [
6
+ '.',
7
+ '..',
8
+ GENERATED_PROVENANCE,
9
+ GENERATED_REVISIONS,
10
+ RESERVED_DERIVED,
11
+ ];
12
+ export const AUTHORED_SEGMENT_MAX_CHARS = 255;
13
+ const REFUSED_SEGMENTS = [
14
+ ...WHOLE_ESCAPED_NAMES.map((name) => name.split('.').join('[.]')),
15
+ '[.][Gg][Ii][Tt][.]*',
16
+ ].join('|');
17
+ export const AUTHORED_SEGMENT = new RegExp(`^(?!(?:${REFUSED_SEGMENTS})(?:/|$))[A-Za-z0-9._][A-Za-z0-9._-]{0,${AUTHORED_SEGMENT_MAX_CHARS - 1}}$`);
18
+ export const LOCAL_COPY_MANIFEST = '.house';
19
+ export const LOCAL_COPY_ROOT_NAMES = [
20
+ '.gitignore',
21
+ '.ignore',
22
+ LOCAL_COPY_MANIFEST,
23
+ ];
24
+ function appPreferences(path) {
25
+ return (path.endsWith('.md') &&
26
+ APP_REFERENCE_PATTERN.test(path.slice(APP_PREFERENCES_HOME.length + 1, -3)));
27
+ }
28
+ export function admittedPath(path) {
29
+ const names = path.split('/');
30
+ const [root] = names;
31
+ return (!LOCAL_COPY_ROOT_NAMES.includes(root.toLowerCase()) &&
32
+ names.every((name) => AUTHORED_SEGMENT.test(name)) &&
33
+ (!path.startsWith(`${APP_PREFERENCES_HOME}/`) || appPreferences(path)));
34
+ }
@@ -0,0 +1,36 @@
1
+ import { type AdapterFailure, type BootstrapPart, type BootstrapResult } from '@agentshouse/mdruntime';
2
+ import type { TrackedAuthority } from './discovery.js';
3
+ import { type HouseModels, type HouseScope } from './read.js';
4
+ import { type HouseDoor, type HouseMode } from './transport.js';
5
+ import { type LogPosition } from './version.js';
6
+ export type ChunkAddress = {
7
+ readonly url: string;
8
+ readonly bytes: number;
9
+ };
10
+ export type ChunkedRoom = LogPosition & {
11
+ readonly anchor: string;
12
+ readonly mode: HouseMode;
13
+ readonly chunks: ReadonlyMap<string, ChunkAddress>;
14
+ readonly parts: readonly BootstrapPart[];
15
+ readonly names: ReadonlyMap<string, string>;
16
+ readonly models: HouseModels;
17
+ };
18
+ export type Listed = ChunkedRoom | {
19
+ readonly kind: 'not-ready';
20
+ } | AdapterFailure;
21
+ type Answered = {
22
+ readonly status: number;
23
+ readonly body: unknown;
24
+ };
25
+ export declare function partId(logEpoch: string, hash: string): string;
26
+ export declare function siteChunkList(answer: Answered, locator: string): Listed;
27
+ export declare function chunkedHead(listed: ChunkedRoom, entry: TrackedAuthority): Promise<BootstrapResult>;
28
+ export declare function chunkPart(body: ReadableStream<Uint8Array> | null, room: ChunkedRoom, id: string, arriving: ((bytes: number) => void) | undefined): Promise<BootstrapResult>;
29
+ export declare function chunkLister(transport: HouseDoor, most: () => number, tracked: (locator: string) => TrackedAuthority | undefined): {
30
+ askAll: (entries: readonly TrackedAuthority[]) => void;
31
+ list: (entry: TrackedAuthority) => Promise<Listed>;
32
+ renew(entry: TrackedAuthority, installing: readonly TrackedAuthority[]): Promise<Listed>;
33
+ forget(): void;
34
+ };
35
+ export declare function chunkScope(body: ReadableStream<Uint8Array>, room: ChunkedRoom, arriving: ((bytes: number) => void) | undefined): Promise<HouseScope | null>;
36
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,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