@agentshouse/mdruntime-adapter 0.1.0-c068fdf374af0 → 0.1.0-c08ff97beadbc

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 (52) hide show
  1. package/dist/actions.d.ts +2 -164
  2. package/dist/actions.d.ts.map +1 -1
  3. package/dist/actions.js +7 -225
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +72 -200
  6. package/dist/discovery.d.ts +17 -3
  7. package/dist/discovery.d.ts.map +1 -1
  8. package/dist/discovery.js +58 -22
  9. package/dist/history.d.ts +12 -0
  10. package/dist/history.d.ts.map +1 -0
  11. package/dist/history.js +92 -0
  12. package/dist/house-model.d.ts +325 -2372
  13. package/dist/house-model.d.ts.map +1 -1
  14. package/dist/house-model.js +53 -1189
  15. package/dist/index.d.ts +5 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +5 -2
  18. package/dist/model.d.ts +1 -2
  19. package/dist/model.d.ts.map +1 -1
  20. package/dist/model.js +0 -17
  21. package/dist/read.d.ts +5 -44
  22. package/dist/read.d.ts.map +1 -1
  23. package/dist/read.js +30 -175
  24. package/dist/refusal.d.ts +0 -3
  25. package/dist/refusal.d.ts.map +1 -1
  26. package/dist/refusal.js +0 -5
  27. package/dist/room-stream.d.ts +1 -0
  28. package/dist/room-stream.d.ts.map +1 -1
  29. package/dist/room-stream.js +23 -2
  30. package/dist/room-types.d.ts +2 -2
  31. package/dist/room-types.d.ts.map +1 -1
  32. package/dist/room-types.js +5 -6
  33. package/dist/search.d.ts +5 -0
  34. package/dist/search.d.ts.map +1 -0
  35. package/dist/search.js +47 -0
  36. package/dist/site.d.ts.map +1 -1
  37. package/dist/site.js +52 -85
  38. package/dist/stream.d.ts +12 -10
  39. package/dist/stream.d.ts.map +1 -1
  40. package/dist/stream.js +151 -158
  41. package/dist/transport.d.ts +37 -16
  42. package/dist/transport.d.ts.map +1 -1
  43. package/dist/transport.js +54 -12
  44. package/dist/upload.d.ts.map +1 -1
  45. package/dist/upload.js +2 -2
  46. package/dist/write.d.ts +2 -1
  47. package/dist/write.d.ts.map +1 -1
  48. package/dist/write.js +7 -17
  49. package/package.json +2 -2
  50. package/dist/gather.d.ts +0 -3
  51. package/dist/gather.d.ts.map +0 -1
  52. package/dist/gather.js +0 -35
package/dist/adapter.js CHANGED
@@ -1,19 +1,18 @@
1
1
  import { stepped } from '@agentshouse/mdruntime';
2
- import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
3
- import { streamedModels, viewModels } from './model.js';
4
- import { gathered, selections } from './gather.js';
2
+ import { capabilities, discoveredRoom, mapDiscovery, parseAuthorityChange, parseDiscovery, trackedFrom, } from './discovery.js';
5
3
  import { createSiteAdapter } from './site.js';
6
- import { authorityRoot, bootstrapping, parseEnumeration, parseFileAddress, parseGrant, refreshFrom, viewOf, wholeView, } from './read.js';
4
+ import { authorityRoot, bootstrapping, parseFileAddress, parseGrant, } from './read.js';
7
5
  import { roomStreams } from './room-stream.js';
8
6
  import { sha256Hex } from './digest.js';
9
7
  import { finishedUpload, houseUpload } from './upload.js';
10
8
  import { houseAction } from './actions.js';
11
- import { classifyDoor, classifyRead, discoveryFailure, doorRefusal } from './refusal.js';
12
- import { houseNotifications } from './stream.js';
13
- import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_ATTACH, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
9
+ import { houseSearch } from './search.js';
10
+ import { classifyDoor, doorRefusal } from './refusal.js';
11
+ import { houseNotifications, } from './stream.js';
12
+ import { houseDoorRoute, } from './transport.js';
14
13
  import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
15
14
  import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
16
- import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
15
+ import { followsVersion, logPosition, presented, reachedVersion, roomVersion } from './version.js';
17
16
  const UNCERTAIN = { kind: 'transport-uncertainty' };
18
17
  const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
19
18
  const OCTET_STREAM = 'application/octet-stream';
@@ -30,7 +29,7 @@ async function heldFiles(authority, held, bound) {
30
29
  async function reused(scope, held) {
31
30
  const sent = new Set(scope.contents.map((entry) => entry.path));
32
31
  const contents = [...scope.contents];
33
- const asked = scope.files.filter((file) => file.binary === undefined && !sent.has(file.path));
32
+ const asked = scope.files.filter((file) => file.binary === undefined && file.outline === undefined && !sent.has(file.path));
34
33
  if (asked.length === 0)
35
34
  return scope;
36
35
  if (held === undefined)
@@ -51,9 +50,11 @@ export function createAgentsHouseAdapter(options) {
51
50
  if ('site' in options)
52
51
  return createSiteAdapter(options.site, options.snapshot === true);
53
52
  const transport = options.transport;
54
- const notifications = houseNotifications(transport, 'credential');
53
+ const notifications = houseNotifications(transport, 'credential', {
54
+ opened: async (frame) => (frame === null ? null : opened(frame)),
55
+ changed,
56
+ });
55
57
  const tracked = new Map();
56
- const handed = new Map();
57
58
  const rooms = roomStreams('credential');
58
59
  const unreused = new Set();
59
60
  let bounds;
@@ -62,6 +63,36 @@ export function createAgentsHouseAdapter(options) {
62
63
  throw new Error('no Discovery declared the bounds');
63
64
  return bounds;
64
65
  }
66
+ function opened(frame) {
67
+ const document = parseDiscovery(frame);
68
+ if (document === null)
69
+ return null;
70
+ bounds = document.bounds;
71
+ tracked.clear();
72
+ for (const entry of trackedFrom(document))
73
+ tracked.set(entry.locator, entry);
74
+ notifications.track([...tracked.values()]);
75
+ return {
76
+ ...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
77
+ member: document.member,
78
+ };
79
+ }
80
+ function changed(frame) {
81
+ const change = parseAuthorityChange(frame);
82
+ if (change === null)
83
+ return null;
84
+ for (const locator of change.left)
85
+ tracked.delete(locator);
86
+ for (const entry of trackedFrom(change))
87
+ tracked.set(entry.locator, entry);
88
+ notifications.track([...tracked.values()]);
89
+ return {
90
+ kind: 'authority-changed',
91
+ rooms: change.authorities.map((authority) => discoveredRoom(authority)),
92
+ left: change.left,
93
+ member: change.member,
94
+ };
95
+ }
65
96
  async function streamedPage(entry, token, held) {
66
97
  const part = await rooms.part(entry, token);
67
98
  if ('kind' in part)
@@ -71,11 +102,6 @@ export function createAgentsHouseAdapter(options) {
71
102
  unreused.add(entry.locator);
72
103
  return UNCERTAIN_READ;
73
104
  }
74
- if (part.first && part.ended)
75
- handed.set(entry.locator, roomVersion(scope));
76
- else
77
- handed.delete(entry.locator);
78
- notifications.reach(entry.authority, scope);
79
105
  return {
80
106
  ...(await stepped(bootstrapping(scope))),
81
107
  ...(part.models === undefined ? {} : { models: part.models }),
@@ -83,12 +109,19 @@ export function createAgentsHouseAdapter(options) {
83
109
  bytes: part.bytes,
84
110
  };
85
111
  }
112
+ async function namedDocument(entry, path, signal) {
113
+ const answered = await transport.streamed(houseDoorRoute('bootstrap'), { room_ref: entry.authority, prefixes: [`${authorityRoot(entry.handle)}/${path}`] }, signal ?? new AbortController().signal);
114
+ if (answered.room === null)
115
+ return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN_READ;
116
+ return rooms.named(entry, answered.room, signal);
117
+ }
86
118
  async function openedRoom(entry, request) {
87
119
  const reusing = unreused.delete(entry.locator) ? undefined : request.held;
88
120
  const files = reusing === undefined
89
121
  ? null
90
122
  : await heldFiles(entry.authority, reusing, declared().max_held_files);
91
- const answered = await transport.streamed(DOOR_BOOTSTRAP, {
123
+ const answered = await transport.streamed(houseDoorRoute('bootstrap'), {
124
+ room_ref: entry.authority,
92
125
  prefixes: [authorityRoot(entry.handle)],
93
126
  ...(files === null ? {} : { held: [files] }),
94
127
  }, request.signal ?? new AbortController().signal);
@@ -96,80 +129,12 @@ export function createAgentsHouseAdapter(options) {
96
129
  return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN_READ;
97
130
  return rooms.head(entry, answered.room, request.arriving, request.signal);
98
131
  }
99
- async function enumeratedPage(ask, page) {
100
- const answer = await transport.door(DOOR_ENUMERATE, {
101
- prefixes: [authorityRoot(ask.entry.handle)],
102
- positions: [
103
- {
104
- ...presented(ask.entry.authority, { position: page.after, logEpoch: ask.from.logEpoch }),
105
- page: { through: page.through, read: page.read },
106
- },
107
- ],
108
- });
109
- const failure = classifyRead(answer.status, answer.body, ask.entry.locator);
110
- if (failure !== null)
111
- return failure;
112
- const enumeration = parseEnumeration(answer.body, 'credential');
113
- if (enumeration === null)
114
- return UNCERTAIN_READ;
115
- return (viewOf(enumeration, ask.entry) ?? { kind: 'room-not-readable', locator: ask.entry.locator });
116
- }
117
- async function enumeratedRoom(enumeration, ask) {
118
- const first = viewOf(enumeration, ask.entry);
119
- if (first === undefined)
120
- return { kind: 'room-not-readable', locator: ask.entry.locator };
121
- const view = await wholeView(first, (page) => enumeratedPage(ask, page));
122
- if ('kind' in view)
123
- return view;
124
- notifications.reach(ask.entry.authority, view);
125
- const answer = await refreshFrom(view, ask.fromRoomVersion);
126
- if (answer.kind !== 'net-advancement')
127
- return answer;
128
- handed.set(ask.entry.locator, roomVersion(view));
129
- const models = await viewModels(view, ask.entry);
130
- return models === undefined ? answer : { ...answer, models };
131
- }
132
- async function streamed(entry, request, from) {
133
- if (handed.get(entry.locator) !== request.fromRoomVersion)
134
- return null;
135
- const advanced = await stepped(notifications.advance(entry, from));
136
- if (advanced === null)
137
- return null;
138
- handed.set(entry.locator, advanced.page.roomVersion);
139
- const models = await streamedModels(advanced.schemas, entry, 'credential');
140
- return models === undefined ? advanced.page : { ...advanced.page, models };
141
- }
142
132
  function held(rooms) {
143
- const kept = rooms.flatMap((room) => {
133
+ notifications.send(rooms.flatMap((room) => {
144
134
  const entry = tracked.get(room.locator);
145
135
  const at = logPosition(room.roomVersion);
146
- if (entry === undefined || at === null)
147
- return [];
148
- handed.set(room.locator, room.roomVersion);
149
- notifications.reach(entry.authority, at);
150
- return [presented(entry.authority, at)];
151
- });
152
- notifications.send(kept);
153
- }
154
- async function adoptedMove(entry, into, outcome) {
155
- if (outcome.kind === 'accepted' && outcome.destination !== undefined) {
156
- await adopted(into, { kind: 'accepted', ...outcome.destination });
157
- }
158
- return adopted(entry, outcome);
159
- }
160
- async function adopted(entry, outcome) {
161
- if (outcome.kind !== 'accepted')
162
- return outcome;
163
- const held = handed.get(entry.locator);
164
- if (held === undefined)
165
- return outcome;
166
- const follows = followsVersion(held, outcome.roomVersion);
167
- if (follows)
168
- handed.set(entry.locator, outcome.roomVersion);
169
- const at = logPosition(outcome.roomVersion);
170
- if (follows && at !== null)
171
- notifications.reach(entry.authority, at);
172
- return outcome;
136
+ return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
137
+ }));
173
138
  }
174
139
  function authorityFor(locator) {
175
140
  return tracked.get(locator);
@@ -188,60 +153,18 @@ export function createAgentsHouseAdapter(options) {
188
153
  return result;
189
154
  return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
190
155
  }
191
- function layered(asks) {
192
- const depths = new Map();
193
- const layers = [];
194
- for (const ask of asks) {
195
- const depth = depths.get(ask.ask.entry.authority) ?? 0;
196
- depths.set(ask.ask.entry.authority, depth + 1);
197
- (layers[depth] ??= []).push(ask);
198
- }
199
- return layers;
200
- }
201
- async function enumerated(asks) {
202
- const answers = [];
203
- const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer, declared().max_prefixes));
204
- for (const part of parts) {
205
- let open = [...part];
206
- while (open.length > 0) {
207
- const answer = await transport.door(DOOR_ENUMERATE, {
208
- prefixes: open.map(({ ask }) => authorityRoot(ask.entry.handle)),
209
- positions: open.map(({ ask }) => presented(ask.entry.authority, ask.from)),
210
- });
211
- const classified = open.map(({ ask }) => classifyRead(answer.status, answer.body, ask.entry.locator));
212
- if (classified[0]?.kind === 'beyond-horizon') {
213
- const named = doorRefusal(answer.body)?.fields.authority;
214
- const expired = open.filter(({ ask }) => ask.entry.authority === named);
215
- const answered = expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };
216
- const gone = expired.length === 0 ? open : expired;
217
- for (const ask of gone)
218
- answers[ask.index] = answered;
219
- open = open.filter((ask) => !gone.includes(ask));
220
- continue;
221
- }
222
- const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
223
- for (const [answerIndex, { ask, index }] of open.entries()) {
224
- const failure = classified[answerIndex];
225
- if (failure !== null && failure !== undefined) {
226
- answers[index] = failure;
227
- continue;
228
- }
229
- answers[index] =
230
- enumeration === null ? UNCERTAIN_READ : await enumeratedRoom(enumeration, ask);
231
- }
232
- open = [];
233
- }
234
- }
235
- return answers;
236
- }
237
- const enumerateTogether = gathered(enumerated);
238
156
  async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
239
157
  const paths = batchPaths(changes);
240
158
  const sha256 = await deltaDigest(delta);
241
159
  if (handed !== undefined && handed.sha256 === sha256) {
242
160
  return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
243
161
  }
244
- const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
162
+ const minted = await transport.door(houseDoorRoute('batch-upload'), {
163
+ ...head,
164
+ paths,
165
+ bytes,
166
+ sha256,
167
+ });
245
168
  if (minted.status !== 200) {
246
169
  return {
247
170
  outcome: await stepped(mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)),
@@ -289,11 +212,11 @@ export function createAgentsHouseAdapter(options) {
289
212
  : { body: inline };
290
213
  if ('outcome' in prepared)
291
214
  return prepared.outcome;
292
- const answer = await transport.door(DOOR_BATCH, prepared.body);
215
+ const answer = await transport.door(houseDoorRoute('batch'), prepared.body);
293
216
  const stagedFiles = await staged(answer, request);
294
217
  if (stagedFiles === false)
295
218
  return UNCERTAIN;
296
- const settled = stagedFiles === null ? answer : await transport.door(DOOR_BATCH, prepared.body);
219
+ const settled = stagedFiles === null ? answer : await transport.door(houseDoorRoute('batch'), prepared.body);
297
220
  if (stagedFiles === true && (await staged(settled, request)) !== null)
298
221
  return UNCERTAIN;
299
222
  return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
@@ -361,7 +284,7 @@ export function createAgentsHouseAdapter(options) {
361
284
  const entry = authorityFor(request.locator);
362
285
  if (entry === undefined)
363
286
  return null;
364
- return () => transport.door(DOOR_FILES_GET, {
287
+ return () => transport.door(houseDoorRoute('files/get'), {
365
288
  room_ref: entry.authority,
366
289
  path: request.path,
367
290
  revision: request.revision,
@@ -373,68 +296,16 @@ export function createAgentsHouseAdapter(options) {
373
296
  async authorize() {
374
297
  return options.authorize();
375
298
  },
376
- async discover(_authorization, scope) {
377
- const answer = await transport.door(DOOR_DISCOVER, {
378
- prefixes: [...DISCOVER_PREFIXES],
379
- ...(scope === undefined ? {} : { rooms: scope.authorities }),
380
- });
381
- const failed = discoveryFailure(answer.status, answer.body);
382
- if (failed !== null)
383
- return failed;
384
- const document = parseDiscovery(answer.body);
385
- if (document === null)
386
- return { kind: 'transport-uncertainty' };
387
- bounds = document.bounds;
388
- const entries = trackedFrom(document);
389
- const covered = scope === undefined
390
- ? null
391
- : [
392
- ...new Set([
393
- ...[...tracked.values()]
394
- .filter((entry) => scope.authorities.includes(entry.authority))
395
- .map((entry) => entry.locator),
396
- ...entries.map((entry) => entry.locator),
397
- ]),
398
- ];
399
- if (covered === null)
400
- tracked.clear();
401
- else
402
- for (const locator of covered)
403
- tracked.delete(locator);
404
- for (const entry of entries)
405
- tracked.set(entry.locator, entry);
406
- for (const locator of handed.keys())
407
- if (!tracked.has(locator))
408
- handed.delete(locator);
409
- notifications.track([...tracked.values()]);
410
- return {
411
- ...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions, [...tracked.values()])),
412
- member: document.member,
413
- ...(covered === null ? {} : { covered }),
414
- };
415
- },
416
299
  async bootstrap(_authorization, request) {
417
300
  const entry = authorityFor(request.locator);
418
301
  if (entry === undefined)
419
302
  return { kind: 'room-not-readable', locator: request.locator };
303
+ if (request.path !== undefined)
304
+ return namedDocument(entry, request.path, request.signal);
420
305
  return request.pageToken === undefined
421
306
  ? openedRoom(entry, request)
422
307
  : streamedPage(entry, request.pageToken, request.held);
423
308
  },
424
- async refresh(_authorization, request) {
425
- const entry = authorityFor(request.locator);
426
- if (entry === undefined)
427
- return { kind: 'room-not-readable', locator: request.locator };
428
- if (request.pageToken !== undefined)
429
- return { kind: 'transport-uncertainty' };
430
- const from = logPosition(request.fromRoomVersion);
431
- if (from === null)
432
- return { kind: 'beyond-horizon' };
433
- const answered = await streamed(entry, request, from);
434
- if (answered !== null)
435
- return answered;
436
- return enumerateTogether({ entry, from, fromRoomVersion: request.fromRoomVersion });
437
- },
438
309
  async mutate(_authorization, request, keep) {
439
310
  const entry = authorityFor(request.locator);
440
311
  if (entry === undefined)
@@ -450,22 +321,21 @@ export function createAgentsHouseAdapter(options) {
450
321
  : houseMove(batch, entry.handle, into.handle);
451
322
  if (mapped.kind === 'unmapped')
452
323
  return rejectedMapping(mapped);
453
- const head = operationHead(batch);
324
+ const head = operationHead(batch, entry.authority);
454
325
  const delta = deltaBody(mapped.changes);
455
326
  const bytes = deltaBytes(delta);
456
327
  const handed = request.upload;
457
328
  const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
458
- const settle = (outcome) => into === undefined ? adopted(entry, outcome) : adoptedMove(entry, into, outcome);
459
329
  const outcome = await answer(handed);
460
330
  if (handed === undefined || !lapsedGrant(outcome))
461
- return settle(outcome);
462
- return settle(await answer(undefined));
331
+ return outcome;
332
+ return answer(undefined);
463
333
  },
464
334
  async history(_authorization, request) {
465
335
  const entry = authorityFor(request.locator);
466
336
  if (entry === undefined)
467
337
  return { kind: 'room-not-readable', locator: request.locator };
468
- const answer = await transport.door(DOOR_REVISIONS, revisionBody({
338
+ const answer = await transport.door(houseDoorRoute('revisions'), revisionBody({
469
339
  path: request.path,
470
340
  handle: entry.handle,
471
341
  ...(request.revision === undefined ? {} : { revision: request.revision }),
@@ -492,7 +362,7 @@ export function createAgentsHouseAdapter(options) {
492
362
  const entry = authorityFor(request.locator);
493
363
  if (entry === undefined)
494
364
  return { kind: 'room-not-readable', locator: request.locator };
495
- const declared = await transport.door(DOOR_FILES_ATTACH, {
365
+ const declared = await transport.door(houseDoorRoute('files/attach'), {
496
366
  room_ref: entry.authority,
497
367
  name: request.name,
498
368
  bytes: request.byteLength,
@@ -526,9 +396,11 @@ export function createAgentsHouseAdapter(options) {
526
396
  async action(_authorization, request) {
527
397
  return withAt(await houseAction(transport, request));
528
398
  },
399
+ search(_authorization, request) {
400
+ return houseSearch(transport, [...tracked.values()], request);
401
+ },
529
402
  roomStream: {
530
403
  hold: held,
531
- reopen: notifications.reopen,
532
404
  observe: notifications.observe,
533
405
  },
534
406
  conversations: notifications.conversations,
@@ -1,7 +1,6 @@
1
1
  import type { Capability, DiscoveredRoom, Discovery, Member, ProviderLimit, Retention } from '@agentshouse/mdruntime';
2
2
  import { type LogPosition } from './version.js';
3
3
  export declare const PROVIDER_ACTIONS = "provider-actions";
4
- export declare const DISCOVER_PREFIXES: readonly string[];
5
4
  export type HouseBounds = {
6
5
  max_authored_file_bytes: number;
7
6
  max_batch_operations: number;
@@ -40,6 +39,11 @@ export type HouseDiscoveryDocument = {
40
39
  authorities: readonly HouseAuthority[];
41
40
  actions: readonly string[];
42
41
  };
42
+ export type HouseAuthorityChange = {
43
+ member: Member;
44
+ authorities: readonly HouseAuthority[];
45
+ left: readonly string[];
46
+ };
43
47
  export type TrackedAuthority = LogPosition & {
44
48
  locator: string;
45
49
  authority: string;
@@ -56,14 +60,24 @@ export type HouseSiteDiscovery = {
56
60
  bounds: HouseBounds;
57
61
  authorities: readonly HouseSiteAuthority[];
58
62
  };
63
+ type RoomOwn = 'room_ref' | 'room_handle' | 'name' | 'position';
64
+ type Folded<A extends Record<RoomOwn, unknown>> = {
65
+ readonly shapes: readonly Omit<A, RoomOwn>[];
66
+ readonly rooms: readonly (Pick<A, RoomOwn> & {
67
+ readonly shape: number;
68
+ })[];
69
+ };
70
+ export declare function foldedAuthorities<A extends Record<RoomOwn, unknown>>(authorities: readonly A[]): Folded<A>;
59
71
  export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
72
+ export declare function parseAuthorityChange(body: unknown): HouseAuthorityChange | null;
60
73
  export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
61
74
  export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
62
- export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
75
+ export declare function trackedFrom(document: Pick<HouseDiscoveryDocument, 'authorities'>): TrackedAuthority[];
63
76
  export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
64
77
  export declare function declaredRetention(bounds: HouseBounds): Retention;
65
- export declare function capabilities(actions: HouseDiscoveryDocument['actions'], rooms: readonly Pick<TrackedAuthority, 'authority' | 'handle'>[]): readonly Capability[];
78
+ export declare function capabilities(actions: HouseDiscoveryDocument['actions']): readonly Capability[];
66
79
  export declare function siteCapabilities(): readonly Capability[];
67
80
  export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
68
81
  export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
82
+ export {};
69
83
  //# sourceMappingURL=discovery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,MAAM,EACN,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAE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AgB,IAAI,SAAS,UAAU,EAAE,CAOxD;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,cAAc,GAAG,cAAc,CAqBxE;AAED,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,EAChD,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,QAAQ,EAAE,SAAS,UAAU,EAAE,GAC9B,SAAS,CAQX"}
package/dist/discovery.js CHANGED
@@ -1,8 +1,7 @@
1
- import { declaredActions, houseConversationAgents, SITE_SUBMIT } from './actions.js';
1
+ import { declaredActions } from './actions.js';
2
+ import { SITE_SUBMISSION } from './transport.js';
2
3
  import { readPosition, roomVersion } from './version.js';
3
4
  export const PROVIDER_ACTIONS = 'provider-actions';
4
- export const DISCOVER_PREFIXES = ['/'];
5
- const PRIVATE_HANDLE = 'private';
6
5
  const BOUND_KEYS = [
7
6
  'max_authored_file_bytes',
8
7
  'max_batch_operations',
@@ -111,6 +110,47 @@ function parseAuthority(value) {
111
110
  ...at,
112
111
  };
113
112
  }
113
+ function parseAuthorities(value) {
114
+ if (!Array.isArray(value))
115
+ return null;
116
+ const authorities = [];
117
+ for (const entry of value) {
118
+ const authority = parseAuthority(entry);
119
+ if (authority === null)
120
+ return null;
121
+ authorities.push(authority);
122
+ }
123
+ return authorities;
124
+ }
125
+ export function foldedAuthorities(authorities) {
126
+ const shapes = [];
127
+ const known = new Map();
128
+ const rooms = authorities.map(({ room_ref, room_handle, name, position, ...shape }) => {
129
+ const key = JSON.stringify(shape);
130
+ let held = known.get(key);
131
+ if (held === undefined) {
132
+ held = shapes.push(shape) - 1;
133
+ known.set(key, held);
134
+ }
135
+ return { room_ref, room_handle, name, position, shape: held };
136
+ });
137
+ return { shapes, rooms };
138
+ }
139
+ function unfolded(shapes, rooms) {
140
+ if (!Array.isArray(shapes) || !Array.isArray(rooms))
141
+ return null;
142
+ const authorities = [];
143
+ for (const room of rooms) {
144
+ if (typeof room !== 'object' || room === null)
145
+ return null;
146
+ const { shape, ...own } = room;
147
+ const held = typeof shape === 'number' ? shapes[shape] : undefined;
148
+ if (typeof held !== 'object' || held === null)
149
+ return null;
150
+ authorities.push({ ...held, ...own });
151
+ }
152
+ return authorities;
153
+ }
114
154
  export function parseDiscovery(body) {
115
155
  if (typeof body !== 'object' || body === null)
116
156
  return null;
@@ -126,16 +166,19 @@ export function parseDiscovery(body) {
126
166
  new Set(actions).size !== actions.length ||
127
167
  actions.some((name) => name.length === 0))
128
168
  return null;
129
- if (!Array.isArray(held.authorities))
169
+ const authorities = parseAuthorities(unfolded(held.shapes, held.rooms));
170
+ return authorities === null ? null : { member, bounds, authorities, actions };
171
+ }
172
+ export function parseAuthorityChange(body) {
173
+ if (typeof body !== 'object' || body === null)
130
174
  return null;
131
- const authorities = [];
132
- for (const entry of held.authorities) {
133
- const authority = parseAuthority(entry);
134
- if (authority === null)
135
- return null;
136
- authorities.push(authority);
137
- }
138
- return { member, bounds, authorities, actions };
175
+ const held = body;
176
+ const member = parseMember(held.member);
177
+ const authorities = parseAuthorities(held.authorities);
178
+ const left = stringList(held.left);
179
+ if (member === null || authorities === null || left === null)
180
+ return null;
181
+ return { member, authorities, left };
139
182
  }
140
183
  function parseSiteAuthority(value) {
141
184
  if (typeof value !== 'object' || value === null)
@@ -220,21 +263,14 @@ export function declaredRetention(bounds) {
220
263
  refreshHorizon: bounds.change_retention_seconds,
221
264
  };
222
265
  }
223
- export function capabilities(actions, rooms) {
224
- const own = rooms.find((room) => room.handle === PRIVATE_HANDLE);
225
- return [
226
- {
227
- name: PROVIDER_ACTIONS,
228
- actions: declaredActions(actions),
229
- ...(own === undefined ? {} : { conversationAgents: houseConversationAgents(own.authority) }),
230
- },
231
- ];
266
+ export function capabilities(actions) {
267
+ return [{ name: PROVIDER_ACTIONS, actions: declaredActions(actions) }];
232
268
  }
233
269
  export function siteCapabilities() {
234
270
  return [
235
271
  {
236
272
  name: PROVIDER_ACTIONS,
237
- actions: [{ name: SITE_SUBMIT, inputShape: {}, resultKind: 'house' }],
273
+ actions: [{ name: SITE_SUBMISSION, inputShape: {}, resultKind: 'house' }],
238
274
  },
239
275
  ];
240
276
  }
@@ -0,0 +1,12 @@
1
+ import type { AcceptedMessage, ActionResult, ConversationHistoryRequest } from '@agentshouse/mdruntime';
2
+ import { type HouseDoor } from './transport.js';
3
+ export declare const HISTORY_PAGE = 100;
4
+ type HistoryCursor = {
5
+ accepted_at: string;
6
+ message_id: string;
7
+ };
8
+ export declare function cursorPosition(cursor: HistoryCursor): string;
9
+ export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
10
+ export declare function houseHistory(transport: HouseDoor, request: ConversationHistoryRequest): Promise<ActionResult>;
11
+ export {};
12
+ //# sourceMappingURL=history.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EAGZ,0BAA0B,EAC3B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhE,eAAO,MAAM,YAAY,MAAM,CAAC;AAIhC,KAAK,aAAa,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAkBjE,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAE5D;AAUD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE;AA8BD,wBAAsB,YAAY,CAChC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,YAAY,CAAC,CAqBvB"}