@agentshouse/mdruntime-adapter 0.1.0-c51fa73c21cdb → 0.1.0-c52e136e8d6ca

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/read.js CHANGED
@@ -1,4 +1,4 @@
1
- import { patching, ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
1
+ import { paced, patching, ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
2
2
  import { checkedPayload, gunzipped, parsePart } from './part.js';
3
3
  import { DECIMAL, readPosition, roomVersion } from './version.js';
4
4
  const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
@@ -13,6 +13,8 @@ export function answering() {
13
13
  changes: new Map(),
14
14
  binaryFiles: new Map(),
15
15
  removals: new Set(),
16
+ folders: new Set(),
17
+ folderRemovals: new Set(),
16
18
  };
17
19
  }
18
20
  export function revised(answer, path, revision) {
@@ -29,12 +31,26 @@ export function forgotten(answer, path) {
29
31
  answer.binaryFiles.delete(path);
30
32
  answer.removals.delete(path);
31
33
  }
32
- export function* answered(answer) {
33
- const removals = [];
34
- for (const path of answer.removals) {
35
- removals.push(path);
34
+ export function folded(answer, path, removed) {
35
+ if (removed) {
36
+ answer.folders.delete(path);
37
+ answer.folderRemovals.add(path);
38
+ }
39
+ else {
40
+ answer.folderRemovals.delete(path);
41
+ answer.folders.add(path);
42
+ }
43
+ }
44
+ function* pathsOf(paths) {
45
+ const list = [];
46
+ for (const path of paths) {
47
+ list.push(path);
36
48
  yield ROW_WEIGHT;
37
49
  }
50
+ return list;
51
+ }
52
+ export function* answered(answer) {
53
+ const removals = yield* pathsOf(answer.removals);
38
54
  return {
39
55
  documents: yield* patching({}, answer.documents),
40
56
  revisions: yield* patching({}, answer.revisions),
@@ -42,6 +58,10 @@ export function* answered(answer) {
42
58
  changes: yield* patching({}, answer.changes),
43
59
  binaryFiles: yield* patching({}, answer.binaryFiles),
44
60
  removals,
61
+ ...(answer.folders.size === 0 ? {} : { folders: yield* pathsOf(answer.folders) }),
62
+ ...(answer.folderRemovals.size === 0
63
+ ? {}
64
+ : { folderRemovals: yield* pathsOf(answer.folderRemovals) }),
45
65
  };
46
66
  }
47
67
  export function authorityRoot(handle) {
@@ -66,11 +86,14 @@ export function parseGrant(body) {
66
86
  export function parseFileAddress(body) {
67
87
  if (typeof body !== 'object' || body === null)
68
88
  return null;
69
- const { download, name, sha256 } = body;
70
- if (typeof download !== 'string' || typeof name !== 'string' || typeof sha256 !== 'string') {
89
+ const { download, name, sha256, media_type: mediaType } = body;
90
+ if (typeof download !== 'string' ||
91
+ typeof name !== 'string' ||
92
+ typeof sha256 !== 'string' ||
93
+ typeof mediaType !== 'string') {
71
94
  return null;
72
95
  }
73
- return { url: download, name, sha256 };
96
+ return { url: download, name, sha256, mediaType };
74
97
  }
75
98
  function changeAuthor(value) {
76
99
  if (typeof value !== 'object' || value === null)
@@ -103,15 +126,12 @@ function headed(head) {
103
126
  return head === undefined ? {} : { head };
104
127
  }
105
128
  export function binaryFileOf(held) {
106
- if (held.file === undefined)
129
+ if (held.media_type === undefined)
107
130
  return undefined;
108
- const { file, bytes, media_type: mediaType, sha256 } = held;
109
- if (typeof file !== 'string' ||
110
- typeof bytes !== 'number' ||
111
- typeof mediaType !== 'string' ||
112
- typeof sha256 !== 'string')
131
+ const { bytes, media_type: mediaType, sha256 } = held;
132
+ if (typeof bytes !== 'number' || typeof mediaType !== 'string' || typeof sha256 !== 'string')
113
133
  return null;
114
- return { fileRef: file, byteLength: bytes, mediaType, sha256 };
134
+ return { byteLength: bytes, mediaType, sha256 };
115
135
  }
116
136
  function binaried(binary) {
117
137
  return binary === undefined ? {} : { binary };
@@ -195,6 +215,24 @@ export function parseParted(body) {
195
215
  export function parseSiteParted(body) {
196
216
  return parseRoomParts(body);
197
217
  }
218
+ export function partInventory(room) {
219
+ return {
220
+ parts: room.parts.length,
221
+ bytes: room.parts.reduce((sum, part) => sum + part.bytes, 0),
222
+ };
223
+ }
224
+ export function manifested(room, inventory, pageToken) {
225
+ return {
226
+ kind: 'bootstrap',
227
+ roomVersion: roomVersion(room),
228
+ documents: {},
229
+ revisions: {},
230
+ changes: {},
231
+ binaryFiles: {},
232
+ inventory,
233
+ pageToken,
234
+ };
235
+ }
198
236
  export function emptyScope(room) {
199
237
  return {
200
238
  anchor: room.anchor,
@@ -204,50 +242,76 @@ export function emptyScope(room) {
204
242
  contents: [],
205
243
  };
206
244
  }
207
- function* partLines(text, mode) {
208
- const files = [];
209
- const contents = [];
210
- let start = 0;
211
- while (start < text.length) {
212
- const end = text.indexOf('\n', start);
213
- if (end === -1)
214
- return null;
215
- let entry;
216
- try {
217
- entry = JSON.parse(text.slice(start, end));
218
- }
219
- catch {
220
- return null;
245
+ function partLine(line, mode, read) {
246
+ let entry;
247
+ try {
248
+ entry = JSON.parse(line);
249
+ }
250
+ catch {
251
+ return false;
252
+ }
253
+ if (folderLine(entry)) {
254
+ read.folders.push(entry.folder);
255
+ return true;
256
+ }
257
+ const file = parseFile(entry, mode);
258
+ if (file === null)
259
+ return false;
260
+ read.files.push(file);
261
+ const { content } = entry;
262
+ if (typeof content === 'string')
263
+ read.contents.push({ path: file.path, content });
264
+ else if (content !== undefined)
265
+ return false;
266
+ return true;
267
+ }
268
+ async function partRead(chunks, mode) {
269
+ const read = { files: [], contents: [], folders: [] };
270
+ const pace = paced();
271
+ const unfinished = [];
272
+ for (let chunk = await chunks.read(); chunk.done !== true; chunk = await chunks.read()) {
273
+ const text = chunk.value;
274
+ let start = 0;
275
+ for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
276
+ const piece = text.slice(start, end);
277
+ const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
278
+ if (!partLine(line, mode, read)) {
279
+ await chunks.cancel();
280
+ return null;
281
+ }
282
+ start = end + 1;
283
+ const due = pace(line.length + ROW_WEIGHT);
284
+ if (due instanceof Promise)
285
+ await due;
221
286
  }
222
- start = end + 1;
223
- if (folderLine(entry))
224
- continue;
225
- const file = parseFile(entry, mode);
226
- if (file === null)
227
- return null;
228
- files.push(file);
229
- const { content } = entry;
230
- if (typeof content === 'string')
231
- contents.push({ path: file.path, content });
232
- else if (content !== undefined)
233
- return null;
234
- yield ROW_WEIGHT;
287
+ if (start < text.length)
288
+ unfinished.push(text.slice(start));
235
289
  }
236
- return { files, contents };
290
+ return unfinished.length === 0 ? read : null;
237
291
  }
238
292
  function folderLine(entry) {
239
293
  if (typeof entry !== 'object' || entry === null || !('folder' in entry))
240
294
  return false;
241
295
  return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
242
296
  }
243
- export async function housePart(room, body, listed, mode) {
244
- const payload = await checkedPayload(body, listed);
297
+ export async function housePart(room, frame, listed, mode) {
298
+ const payload = await checkedPayload(frame, listed);
245
299
  if (payload === null)
246
300
  return null;
247
- const text = await gunzipped(payload);
248
- const read = text === null ? null : await stepped(partLines(text, mode));
301
+ const read = await partRead(gunzipped(payload).getReader(), mode).catch(() => null);
249
302
  return read === null ? { kind: 'transport-uncertainty' } : { ...emptyScope(room), ...read };
250
303
  }
304
+ function folderChange(value) {
305
+ if (typeof value !== 'object' || value === null)
306
+ return null;
307
+ const { path, folder, removed, ...rest } = value;
308
+ return typeof path === 'string' &&
309
+ folder === true &&
310
+ (removed === undefined || removed === true) &&
311
+ Object.keys(rest).length === 0
312
+ ? { path, removed: removed === true }
313
+ : null;
314
+ }
251
315
  function parseChange(value, mode) {
252
316
  if (typeof value !== 'object' || value === null)
253
317
  return null;
@@ -304,7 +368,13 @@ export function parseEnumeration(body, mode) {
304
368
  if (!Array.isArray(held.changes))
305
369
  return null;
306
370
  const changes = [];
371
+ const folders = [];
307
372
  for (const change of held.changes) {
373
+ const folder = folderChange(change);
374
+ if (folder !== null) {
375
+ folders.push(folder);
376
+ continue;
377
+ }
308
378
  const mapped = parseChange(change, mode);
309
379
  if (mapped === null)
310
380
  return null;
@@ -317,6 +387,7 @@ export function parseEnumeration(body, mode) {
317
387
  authority: held.authority,
318
388
  ...at,
319
389
  changes,
390
+ ...(folders.length === 0 ? {} : { folders }),
320
391
  ...(next === undefined ? {} : { next }),
321
392
  });
322
393
  }
@@ -340,6 +411,7 @@ function advances(asked, next) {
340
411
  }
341
412
  export async function wholeView(first, more) {
342
413
  const changes = new Map(first.changes.map((change) => [change.path, change]));
414
+ const folders = new Map((first.folders ?? []).map((folder) => [folder.path, folder]));
343
415
  let view = first;
344
416
  while (view.next !== undefined) {
345
417
  const asked = view.next;
@@ -355,6 +427,10 @@ export async function wholeView(first, more) {
355
427
  changes.delete(change.path);
356
428
  changes.set(change.path, change);
357
429
  }
430
+ for (const folder of page.folders ?? []) {
431
+ folders.delete(folder.path);
432
+ folders.set(folder.path, folder);
433
+ }
358
434
  view = page;
359
435
  }
360
436
  return {
@@ -362,46 +438,7 @@ export async function wholeView(first, more) {
362
438
  position: view.position,
363
439
  logEpoch: first.logEpoch,
364
440
  changes: [...changes.values()],
365
- };
366
- }
367
- export function* advancedScope(scope, view) {
368
- const files = new Map();
369
- for (const file of scope.files) {
370
- files.set(file.path, file);
371
- yield ROW_WEIGHT;
372
- }
373
- const contents = new Map();
374
- for (const entry of scope.contents) {
375
- contents.set(entry.path, entry.content);
376
- yield ROW_WEIGHT;
377
- }
378
- for (const change of view.changes) {
379
- files.delete(change.path);
380
- contents.delete(change.path);
381
- yield ROW_WEIGHT;
382
- if ('removed' in change)
383
- continue;
384
- files.set(change.path, {
385
- path: change.path,
386
- revision: change.revision,
387
- version: change.version,
388
- ...headed(change.head),
389
- ...('binary' in change ? { binary: change.binary } : {}),
390
- });
391
- if ('content' in change)
392
- contents.set(change.path, change.content);
393
- }
394
- const listed = [];
395
- for (const [path, content] of contents) {
396
- listed.push({ path, content });
397
- yield ROW_WEIGHT;
398
- }
399
- return {
400
- ...scope,
401
- position: view.position,
402
- logEpoch: view.logEpoch,
403
- files: [...files.values()],
404
- contents: listed,
441
+ ...(folders.size === 0 ? {} : { folders: [...folders.values()] }),
405
442
  };
406
443
  }
407
444
  export function* bootstrapping(scope) {
@@ -423,7 +460,9 @@ export function* bootstrapping(scope) {
423
460
  if (file.revision !== undefined)
424
461
  revised(answer, file.path, file.revision);
425
462
  }
426
- const { removals: _removals, ...page } = yield* answered(answer);
463
+ for (const folder of scope.folders ?? [])
464
+ folded(answer, folder, false);
465
+ const { removals: _removals, folderRemovals: _folderRemovals, ...page } = yield* answered(answer);
427
466
  return { kind: 'bootstrap', roomVersion: roomVersion(scope), ...page };
428
467
  }
429
468
  export function schemaOf(scope, schema) {
@@ -457,6 +496,10 @@ function* refreshing(view, fromRoomVersion) {
457
496
  if (change.revision !== undefined)
458
497
  revised(answer, change.path, change.revision);
459
498
  }
499
+ for (const folder of view.folders ?? []) {
500
+ yield ROW_WEIGHT;
501
+ folded(answer, folder.path, folder.removed);
502
+ }
460
503
  return { kind: 'net-advancement', roomVersion: roomVersion(view), ...(yield* answered(answer)) };
461
504
  }
462
505
  export async function refreshFrom(view, fromRoomVersion) {
@@ -1,4 +1,4 @@
1
- export declare const INBOX_CHANNEL_KINDS: readonly ['telegram-bot'];
1
+ export declare const INBOX_CHANNEL_KINDS: readonly ['telegram-bot', 'whatsapp', 'messenger', 'instagram', 'viber', 'tiktok'];
2
2
  export type InboxChannelKind = (typeof INBOX_CHANNEL_KINDS)[number];
3
3
  export declare const INBOX_CHAT_TYPE = "inbox-chat";
4
4
  export declare const INBOX_MESSAGE_TYPE = "inbox-message";
@@ -1 +1 @@
1
- {"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,YAAI,cAAc,CAAU,CAAC;AAE7D,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAIlD,eAAO,MAAM,gBAAgB,QA6BjB,CAAC"}
1
+ {"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,YAC9B,cAAc,EACd,UAAU,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,QAAQ,CACA,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAalD,eAAO,MAAM,gBAAgB,QAuDjB,CAAC"}
@@ -1,7 +1,21 @@
1
- export const INBOX_CHANNEL_KINDS = ['telegram-bot'];
1
+ export const INBOX_CHANNEL_KINDS = [
2
+ 'telegram-bot',
3
+ 'whatsapp',
4
+ 'messenger',
5
+ 'instagram',
6
+ 'viber',
7
+ 'tiktok',
8
+ ];
2
9
  export const INBOX_CHAT_TYPE = 'inbox-chat';
3
10
  export const INBOX_MESSAGE_TYPE = 'inbox-message';
4
11
  const IDENTITY = "{ type: string, pattern: '^\\S+$' }";
12
+ const AGENT = [' agent: { type: string, format: uuid }', ' name: { type: string }'];
13
+ const ASSIGNEE = [
14
+ ' type: object',
15
+ ' properties:',
16
+ ' user: { type: string, format: uuid }',
17
+ ...AGENT,
18
+ ];
5
19
  export const HOUSE_ROOM_TYPES = [
6
20
  `${INBOX_CHAT_TYPE}:`,
7
21
  ' properties:',
@@ -14,6 +28,13 @@ export const HOUSE_ROOM_TYPES = [
14
28
  ' name: { type: string }',
15
29
  ` username: ${IDENTITY}`,
16
30
  ` phone: ${IDENTITY}`,
31
+ ' assignee:',
32
+ ...ASSIGNEE,
33
+ ' return_to:',
34
+ ' type: object',
35
+ ' properties:',
36
+ ...AGENT,
37
+ ' conversation: { type: string, format: uuid }',
17
38
  ' required: [inbox, channel, chat, customer]',
18
39
  `${INBOX_MESSAGE_TYPE}:`,
19
40
  ' properties:',
@@ -27,8 +48,27 @@ export const HOUSE_ROOM_TYPES = [
27
48
  ` channel_message: ${IDENTITY}`,
28
49
  ' state: { enum: [sending, sent, failed] }',
29
50
  ' reason: { type: string }',
51
+ ' reactions:',
52
+ ' type: array',
53
+ ' items:',
54
+ ' type: object',
55
+ ' properties:',
56
+ ' reaction: { type: string, minLength: 1 }',
57
+ ' sender:',
58
+ ' type: object',
59
+ ' properties:',
60
+ ` id: ${IDENTITY}`,
61
+ ' name: { type: string }',
62
+ ` username: ${IDENTITY}`,
63
+ ' count: { type: integer, minimum: 1 }',
64
+ ' required: [reaction]',
65
+ ` post: ${IDENTITY}`,
66
+ ' assignee:',
67
+ ...ASSIGNEE,
68
+ ' sent_outside: { const: true }',
69
+ ' withheld: { const: true }',
30
70
  ' required: [direction]',
31
71
  ' if: { properties: { direction: { const: in } } }',
32
- ' then: { required: [sent_at, channel_message] }',
72
+ ' then: { required: [sent_at] }',
33
73
  '',
34
74
  ].join('\n');
@@ -1 +1 @@
1
- {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAUR,MAAM,wBAAwB,CAAC;AA8BhC,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAuCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAmQ1F"}
1
+ {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAWR,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAoCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAoP1F"}
package/dist/site.js CHANGED
@@ -2,13 +2,12 @@ import { stepped } from '@agentshouse/mdruntime';
2
2
  import { actionOutcome, SITE_SUBMIT } from './actions.js';
3
3
  import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
4
4
  import { partModels, streamedModels, viewModels } from './model.js';
5
- import { advancedScope, bootstrapping, emptyScope, housePart, parseEnumeration, parseSiteParted, refreshFrom, viewOf, wholeView, } from './read.js';
6
- import { PART_ATTEMPTS, unverifiedPart } from './part.js';
5
+ import { bootstrapping, emptyScope, housePart, manifested, parseEnumeration, parseSiteParted, partInventory, refreshFrom, viewOf, wholeView, } from './read.js';
6
+ import { PART_ATTEMPTS, partArrival, partFrame, unverifiedPart } from './part.js';
7
7
  import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
8
8
  import { HOUSE_ROOM_TYPES } from './room-types.js';
9
9
  import { houseNotifications } from './stream.js';
10
- import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, SITE_FILE_RECORD, SITE_FILES, } from './transport.js';
11
- import { houseReferrer } from './referrer.js';
10
+ import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, SITE_FILES, } from './transport.js';
12
11
  import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
13
12
  const UNCERTAIN = { kind: 'transport-uncertainty' };
14
13
  function unfound() {
@@ -25,28 +24,15 @@ function siteRoom(tracked) {
25
24
  providerOwnedPaths: [],
26
25
  };
27
26
  }
28
- function settled(refused) {
29
- return refused.kind === 'beyond-horizon' ? UNCERTAIN : refused;
30
- }
31
27
  export function createSiteAdapter(transport, snapshot = false) {
32
28
  const notifications = houseNotifications(transport, 'site');
33
29
  const tracked = new Map();
34
30
  const expired = new Map();
35
- function published(referrer) {
36
- const named = houseReferrer(referrer, tracked);
37
- return named === null || !tracked.has(named.locator) ? null : named;
38
- }
39
31
  function fileRoute(request) {
40
- const named = published(request.kind === 'path' ? { room: request.locator, path: request.path } : request.referrer);
41
- if (named === null) {
42
- return { kind: 'rejected', code: 'referrer_unknown', fields: {}, retryable: false };
43
- }
44
- if (request.fileRef === undefined)
45
- return unfound();
46
- const { room_ref, path, record } = named.referrer;
47
- return `${SITE_FILES}${room_ref}/${encodeURIComponent(request.fileRef)}/${path === undefined
48
- ? `${SITE_FILE_RECORD}/${encodeURIComponent(record)}`
49
- : encodeURIComponent(path)}`;
32
+ const entry = tracked.get(request.locator);
33
+ if (entry === undefined)
34
+ return { kind: 'room-not-readable', locator: request.locator };
35
+ return `${SITE_FILES}${entry.authority}/${encodeURIComponent(request.revision)}/${encodeURIComponent(request.path)}`;
50
36
  }
51
37
  async function enumerated(entry, from, page) {
52
38
  const answer = await transport.door(SITE_DOOR_ENUMERATE, {
@@ -80,34 +66,29 @@ export function createSiteAdapter(transport, snapshot = false) {
80
66
  const room = parseSiteParted(answer.body);
81
67
  return room === null || room.anchor !== entry.authority ? UNCERTAIN : room;
82
68
  }
83
- async function fetchedPart(entry, room, listed) {
69
+ async function fetchedPart(entry, room, listed, received, arriving) {
70
+ if (received !== undefined) {
71
+ const kept = new Uint8Array(received);
72
+ const held = await housePart(room, kept, listed, 'site');
73
+ if (held !== null)
74
+ return 'kind' in held ? held : { scope: held, frame: kept };
75
+ }
84
76
  for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
85
- const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}?part=${encodeURIComponent(listed.part)}`);
77
+ const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}?part=${encodeURIComponent(listed.part)}`, partArrival(listed, arriving));
86
78
  const failure = classifyRead(answer.status, answer.body, entry.locator);
87
79
  if (failure?.kind === 'beyond-horizon')
88
80
  expired.set(entry.locator, room.position);
89
81
  if (failure !== null)
90
82
  return failure;
91
- const scope = await housePart(room, answer.body, listed, 'site');
83
+ const frame = partFrame(answer.body);
84
+ if (frame === null)
85
+ continue;
86
+ const scope = await housePart(room, frame, listed, 'site');
92
87
  if (scope !== null)
93
- return scope;
88
+ return 'kind' in scope ? scope : { scope, frame };
94
89
  }
95
90
  return unverifiedPart(entry.locator);
96
91
  }
97
- async function caughtUp(entry, continued) {
98
- const listed = continued.room.parts[continued.next];
99
- const scope = listed === undefined
100
- ? emptyScope(continued.room)
101
- : await fetchedPart(entry, continued.room, listed);
102
- if ('kind' in scope)
103
- return scope;
104
- if (continued.room.parts.length > 1 || roomVersion(scope) === roomVersion(entry))
105
- return scope;
106
- const view = await enumeration(entry, scope);
107
- if ('kind' in view)
108
- return settled(view);
109
- return stepped(advancedScope(scope, view));
110
- }
111
92
  async function refreshed(entry, fromRoomVersion) {
112
93
  const from = logPosition(fromRoomVersion);
113
94
  if (from === null)
@@ -154,17 +135,25 @@ export function createSiteAdapter(transport, snapshot = false) {
154
135
  if (entry === undefined)
155
136
  return { kind: 'room-not-readable', locator: request.locator };
156
137
  let continued;
138
+ let inventory;
157
139
  if (request.pageToken === undefined) {
158
140
  const room = await partedRoom(entry);
159
141
  if ('kind' in room)
160
142
  return room;
161
143
  continued = { room, next: 0, seen: [] };
144
+ inventory = partInventory(room);
145
+ if (inventory.parts > 0)
146
+ return manifested(room, inventory, JSON.stringify(continued));
162
147
  }
163
148
  else
164
149
  continued = JSON.parse(request.pageToken);
165
- const scope = await caughtUp(entry, continued);
166
- if ('kind' in scope)
167
- return scope;
150
+ const listed = continued.room.parts[continued.next];
151
+ const sent = listed === undefined
152
+ ? { scope: emptyScope(continued.room), frame: null }
153
+ : await fetchedPart(entry, continued.room, listed, request.received, request.arriving);
154
+ if ('kind' in sent)
155
+ return sent;
156
+ const { scope } = sent;
168
157
  notifications.reach(entry.authority, scope);
169
158
  const next = continued.next + 1;
170
159
  const more = next < continued.room.parts.length;
@@ -173,10 +162,13 @@ export function createSiteAdapter(transport, snapshot = false) {
173
162
  ...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
174
163
  ];
175
164
  const models = await partModels(scope, entry, new Set(seen), !more);
165
+ const { folders: _folders, ...page } = await stepped(bootstrapping(scope));
176
166
  return {
177
- ...(await stepped(bootstrapping(scope))),
167
+ ...page,
178
168
  ...(models === undefined ? {} : { models }),
179
169
  ...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
170
+ ...(inventory === undefined ? {} : { inventory }),
171
+ ...(sent.frame === null ? {} : { received: sent.frame }),
180
172
  };
181
173
  },
182
174
  async refresh(_authorization, request) {
@@ -205,8 +197,8 @@ export function createSiteAdapter(transport, snapshot = false) {
205
197
  const read = await transport.download(route);
206
198
  if (read.status === 404)
207
199
  return unfound();
208
- return read.status === 200 && read.blob !== null
209
- ? { kind: 'binary', blob: read.blob }
200
+ return read.status === 200 && read.body !== null
201
+ ? { kind: 'binary', body: read.body, mediaType: read.mediaType }
210
202
  : UNCERTAIN;
211
203
  },
212
204
  async link(_authorization, request) {
@@ -219,13 +211,6 @@ export function createSiteAdapter(transport, snapshot = false) {
219
211
  name: request.path.slice(request.path.lastIndexOf('/') + 1),
220
212
  };
221
213
  },
222
- referrerScope(referrer) {
223
- const named = published(referrer);
224
- if (named === null)
225
- return null;
226
- const { path } = named.referrer;
227
- return { locator: named.locator, ...(path === undefined ? {} : { path }) };
228
- },
229
214
  reached(locator, version, target) {
230
215
  return reachedVersion(version, target, tracked.get(locator)?.logEpoch);
231
216
  },
package/dist/stream.d.ts CHANGED
@@ -15,6 +15,7 @@ export type HouseNotifications = {
15
15
  reopen(): void;
16
16
  track(authorities: readonly TrackedAuthority[]): void;
17
17
  reach(authority: string, at: LogPosition): void;
18
+ edited(tracked: TrackedAuthority, from: LogPosition): readonly string[];
18
19
  advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): Generator<number, StreamedAdvancement | null, void>;
19
20
  conversations: ConversationStream;
20
21
  serviceMode: ServiceModeSignal;
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kB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I,CAAC;IACtD,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD,MAAM,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,SAAS,MAAM,EAAE,CAAC;IACxE,OAAO,CACL,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,WAAW,EACjB,KAAK,CAAC,EAAE,YAAY,GACnB,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;IACvD,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAmFF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CA8jB5F"}
package/dist/stream.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
2
  import { acceptedMessage } from './actions.js';
3
3
  import { sha256Hex } from './digest.js';
4
- import { answered, answering, binaryFileOf, forgotten, headChange, revised } from './read.js';
4
+ import { answered, answering, binaryFileOf, folded, forgotten, headChange, revised, } from './read.js';
5
5
  import { roomVersion } from './version.js';
6
6
  const HELD_FRAMES_MAX = 256;
7
7
  function turnOperation(frame) {
@@ -556,6 +556,17 @@ export function houseNotifications(transport, mode) {
556
556
  held,
557
557
  });
558
558
  },
559
+ edited(tracked, from) {
560
+ const line = lines.get(tracked.authority);
561
+ const start = position(from.position);
562
+ if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
563
+ return [];
564
+ return [
565
+ ...new Set(line.frames
566
+ .filter((frame) => frame.position > start)
567
+ .flatMap((frame) => frame.entries.flatMap((entry) => entry.kind === 'edited' && entry.revision !== undefined ? [entry.path] : []))),
568
+ ];
569
+ },
559
570
  *advance(tracked, from, holds) {
560
571
  const line = lines.get(tracked.authority);
561
572
  const start = position(from.position);
@@ -570,6 +581,10 @@ export function houseNotifications(transport, mode) {
570
581
  for (const frame of pending) {
571
582
  for (const entry of frame.entries) {
572
583
  yield ROW_WEIGHT + (entry.text?.length ?? 0);
584
+ if (entry.kind === 'folder') {
585
+ folded(answer, entry.path, entry.removed === true);
586
+ continue;
587
+ }
573
588
  if (entry.kind === 'edited' &&
574
589
  entry.revision !== undefined &&
575
590
  holds?.(entry.path, entry.revision) === true) {