@agentshouse/mdruntime-adapter 0.1.0-c8cad855cc8e8 → 0.1.0-c8d6935639fda

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 (78) hide show
  1. package/README.md +3 -3
  2. package/dist/actions.d.ts +6 -74
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +25 -333
  5. package/dist/adapter.d.ts +0 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +209 -394
  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 +35 -19
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +199 -59
  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 +10 -4
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +9 -2
  24. package/dist/map.d.ts +0 -1
  25. package/dist/model.d.ts +6 -6
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +31 -48
  28. package/dist/read.d.ts +18 -64
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +76 -358
  31. package/dist/refusal.d.ts +3 -5
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +17 -12
  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 +87 -191
  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 -16
  50. package/dist/stream.d.ts.map +1 -1
  51. package/dist/stream.js +242 -426
  52. package/dist/transport.d.ts +75 -45
  53. package/dist/transport.d.ts.map +1 -1
  54. package/dist/transport.js +56 -11
  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 +13 -0
  59. package/dist/upload.d.ts.map +1 -0
  60. package/dist/upload.js +65 -0
  61. package/dist/version.d.ts +0 -1
  62. package/dist/write.d.ts +6 -3
  63. package/dist/write.d.ts.map +1 -1
  64. package/dist/write.js +39 -57
  65. package/package.json +9 -4
  66. package/AGENTS.md +0 -312
  67. package/dist/gather.d.ts +0 -4
  68. package/dist/gather.d.ts.map +0 -1
  69. package/dist/gather.js +0 -35
  70. package/dist/part.d.ts +0 -13
  71. package/dist/part.d.ts.map +0 -1
  72. package/dist/part.js +0 -80
  73. package/dist/referrer.d.ts +0 -9
  74. package/dist/referrer.d.ts.map +0 -1
  75. package/dist/referrer.js +0 -41
  76. package/dist/room-types.d.ts +0 -6
  77. package/dist/room-types.d.ts.map +0 -1
  78. package/dist/room-types.js +0 -66
@@ -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,"file":"chunks.d.ts","sourceRoot":"","sources":["../src/chunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAInB,OAAO,EAAkB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACnD,QAAQ,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAA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
@@ -0,0 +1,281 @@
1
+ import { paced, ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
2
+ import { manifestedModels } from './model.js';
3
+ import { authorityRoot, bootstrapping, documentEntry, } from './read.js';
4
+ import { classifyDoor } from './refusal.js';
5
+ import { failedOn, unusable } from './uncertain.js';
6
+ import { spaceSchemas } from './space-schema.js';
7
+ import { houseDoorRoute } from './transport.js';
8
+ import { readPosition, roomVersion } from './version.js';
9
+ function authorKey(author) {
10
+ for (const kind of ['user', 'site', 'inbox']) {
11
+ if (typeof author[kind] === 'string')
12
+ return `${kind}:${author[kind]}`;
13
+ }
14
+ const { app, release, function: named } = author;
15
+ return typeof app === 'string' && typeof release === 'string' && typeof named === 'string'
16
+ ? `app:${app}:${release}:${named}`
17
+ : null;
18
+ }
19
+ function namesOf(authors) {
20
+ if (!Array.isArray(authors))
21
+ return null;
22
+ const names = new Map();
23
+ for (const author of authors) {
24
+ const key = typeof author === 'object' && author !== null ? authorKey(author) : null;
25
+ if (key === null || typeof author.name !== 'string')
26
+ return null;
27
+ names.set(key, author.name);
28
+ }
29
+ return names;
30
+ }
31
+ function schemaText(file, texts) {
32
+ const { space, revision, content } = file;
33
+ if (content !== undefined) {
34
+ if (space !== undefined && revision !== undefined)
35
+ texts.keep(space, revision, content);
36
+ return content;
37
+ }
38
+ return space === undefined || revision === undefined ? undefined : texts.held(space, revision);
39
+ }
40
+ function modelsOf(models, mode, texts) {
41
+ if (!Array.isArray(models))
42
+ return null;
43
+ const files = [];
44
+ for (const entry of models) {
45
+ const file = documentEntry(entry, mode);
46
+ const content = file === null ? undefined : schemaText(file, texts);
47
+ if (file === null || content === undefined)
48
+ return null;
49
+ files.push({ ...file, content });
50
+ }
51
+ return files;
52
+ }
53
+ export function partId(logEpoch, hash) {
54
+ return `${logEpoch}:${hash}`;
55
+ }
56
+ function chunkedRoom(room, mode, texts) {
57
+ const at = readPosition(room);
58
+ const names = mode === 'site' ? new Map() : namesOf(room.authors);
59
+ const models = modelsOf(room.models, mode, texts);
60
+ if (at === null || names === null || models === null || !Array.isArray(room.chunks))
61
+ return null;
62
+ const chunks = new Map();
63
+ const parts = [];
64
+ for (const chunk of room.chunks) {
65
+ const { hash, bytes, download } = chunk;
66
+ if (typeof hash !== 'string' || typeof bytes !== 'number' || typeof download !== 'string')
67
+ return null;
68
+ const id = partId(at.logEpoch, hash);
69
+ chunks.set(id, { url: download, bytes });
70
+ parts.push({ id, bytes });
71
+ }
72
+ return { anchor: room.room_ref, ...at, mode, chunks, parts, names, models };
73
+ }
74
+ function listedRoom(room, mode, texts) {
75
+ if (typeof room !== 'object' || room === null)
76
+ return null;
77
+ const held = room;
78
+ if (typeof held.room_ref !== 'string')
79
+ return null;
80
+ if (held.ready === false)
81
+ return { kind: 'not-ready' };
82
+ return held.ready === true ? chunkedRoom(held, mode, texts) : null;
83
+ }
84
+ export function siteChunkList(answer, locator) {
85
+ const failure = classifyDoor(answer.status, answer.body, locator);
86
+ if (failure !== null)
87
+ return failure;
88
+ return listedRoom(answer.body, 'site', spaceSchemas()) ?? unusable();
89
+ }
90
+ export async function chunkedHead(listed, entry) {
91
+ if (listed.anchor !== entry.authority)
92
+ return unusable();
93
+ const models = await manifestedModels({
94
+ anchor: listed.anchor,
95
+ position: listed.position,
96
+ logEpoch: listed.logEpoch,
97
+ models: listed.models,
98
+ }, entry);
99
+ return {
100
+ kind: 'bootstrap',
101
+ roomVersion: roomVersion(listed),
102
+ documents: {},
103
+ facts: {},
104
+ revisions: {},
105
+ changes: {},
106
+ binaryFiles: {},
107
+ parts: listed.parts,
108
+ ...(models === undefined ? {} : { models }),
109
+ };
110
+ }
111
+ export async function chunkPart(body, room, id, arriving) {
112
+ const address = room.chunks.get(id);
113
+ if (body === null || address === undefined)
114
+ return unusable();
115
+ let scope;
116
+ try {
117
+ scope = await chunkScope(body, room, arriving);
118
+ }
119
+ catch (error) {
120
+ return failedOn(error);
121
+ }
122
+ if (scope === null)
123
+ return unusable();
124
+ return { ...(await stepped(bootstrapping(scope))), bytes: address.bytes };
125
+ }
126
+ function listedRooms(answer) {
127
+ const rooms = answer.body?.rooms;
128
+ if (!Array.isArray(rooms))
129
+ return null;
130
+ const listed = new Map();
131
+ const texts = spaceSchemas();
132
+ for (const room of rooms) {
133
+ const held = listedRoom(room, 'credential', texts);
134
+ if (held === null)
135
+ return null;
136
+ listed.set(room.room_ref, held);
137
+ }
138
+ return listed;
139
+ }
140
+ export function chunkLister(transport, most, tracked) {
141
+ const asked = new Map();
142
+ const unlisted = new Set();
143
+ function answered(entries, whole) {
144
+ const prefixes = whole ? ['/'] : entries.map((entry) => authorityRoot(entry.handle));
145
+ return transport.door(houseDoorRoute('room-chunks/list'), { prefixes }).then((answer) => {
146
+ const failure = classifyDoor(answer.status, answer.body, '');
147
+ if (failure !== null)
148
+ return failed(entries, failure);
149
+ const listed = listedRooms(answer);
150
+ return listed ?? failed(entries, unusable());
151
+ }, (error) => failed(entries, failedOn(error)));
152
+ }
153
+ function failed(entries, failure) {
154
+ return new Map(entries.map((entry) => [
155
+ entry.authority,
156
+ failure.kind === 'room-not-readable' || failure.kind === 'scoped-refusal'
157
+ ? { ...failure, locator: entry.locator }
158
+ : failure,
159
+ ]));
160
+ }
161
+ function settled(entry, lists) {
162
+ return lists.then((listed) => listed.get(entry.authority) ?? { kind: 'room-not-readable', locator: entry.locator });
163
+ }
164
+ function askAll(entries) {
165
+ if (entries.length === 0)
166
+ return;
167
+ const lists = answered(entries, entries.length > most());
168
+ for (const entry of entries) {
169
+ const listed = settled(entry, lists);
170
+ listed.catch(() => { });
171
+ asked.set(entry.authority, { entry, listed });
172
+ }
173
+ }
174
+ function current(entry) {
175
+ return asked.get(entry.authority)?.entry.handle === entry.handle;
176
+ }
177
+ function askTogether(entries) {
178
+ askAll([...new Map(entries.map((one) => [one.authority, one])).values()]);
179
+ }
180
+ function waiting() {
181
+ return [...unlisted].flatMap((locator) => {
182
+ const entry = tracked(locator);
183
+ if (entry === undefined)
184
+ unlisted.delete(locator);
185
+ return entry ?? [];
186
+ });
187
+ }
188
+ function list(entry) {
189
+ if (!current(entry))
190
+ askTogether([...waiting().filter((one) => !current(one)), entry]);
191
+ const { listed } = asked.get(entry.authority);
192
+ asked.delete(entry.authority);
193
+ return listed.then((answer) => {
194
+ if ('kind' in answer)
195
+ unlisted.add(entry.locator);
196
+ else
197
+ unlisted.delete(entry.locator);
198
+ return answer;
199
+ });
200
+ }
201
+ return {
202
+ askAll,
203
+ list,
204
+ renew(entry, installing) {
205
+ if (!current(entry)) {
206
+ const listed = [...asked.values()].flatMap((held) => tracked(held.entry.locator) ?? []);
207
+ askTogether([...listed, ...waiting(), ...installing, entry]);
208
+ }
209
+ return list(entry);
210
+ },
211
+ forget() {
212
+ asked.clear();
213
+ unlisted.clear();
214
+ },
215
+ };
216
+ }
217
+ function folderLine(entry) {
218
+ return typeof entry.folder === 'string' && Object.keys(entry).length === 1 ? entry.folder : null;
219
+ }
220
+ function chunkEntry(line, room, read) {
221
+ let entry;
222
+ try {
223
+ entry = JSON.parse(line);
224
+ }
225
+ catch {
226
+ return false;
227
+ }
228
+ if (typeof entry !== 'object' || entry === null)
229
+ return false;
230
+ const folder = folderLine(entry);
231
+ if (folder !== null) {
232
+ read.folders.push(folder);
233
+ return true;
234
+ }
235
+ const author = entry.author;
236
+ let named = entry;
237
+ if (author !== undefined) {
238
+ const key = typeof author === 'object' && author !== null ? authorKey(author) : null;
239
+ const name = key === null ? undefined : room.names.get(key);
240
+ if (name === undefined)
241
+ return false;
242
+ named = { ...entry, author: { ...author, name } };
243
+ }
244
+ const file = documentEntry(named, room.mode);
245
+ if (file === null)
246
+ return false;
247
+ read.files.push(file);
248
+ return true;
249
+ }
250
+ export async function chunkScope(body, room, arriving) {
251
+ const read = { files: [], folders: [] };
252
+ const reader = body.getReader();
253
+ const decoder = new TextDecoder();
254
+ const pace = paced();
255
+ const unfinished = [];
256
+ let bytes = 0;
257
+ for (let chunk = await reader.read(); chunk.done !== true; chunk = await reader.read()) {
258
+ bytes += chunk.value.length;
259
+ arriving?.(bytes);
260
+ const text = decoder.decode(chunk.value, { stream: true });
261
+ let start = 0;
262
+ for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
263
+ const piece = text.slice(start, end);
264
+ const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
265
+ start = end + 1;
266
+ if (line.length > 0 && !chunkEntry(line, room, read)) {
267
+ await reader.cancel();
268
+ return null;
269
+ }
270
+ const due = pace(line.length + ROW_WEIGHT);
271
+ if (due instanceof Promise)
272
+ await due;
273
+ }
274
+ if (start < text.length)
275
+ unfinished.push(text.slice(start));
276
+ }
277
+ const rest = unfinished.join('') + decoder.decode();
278
+ if (rest.length > 0 && !chunkEntry(rest, room, read))
279
+ return null;
280
+ return { anchor: room.anchor, position: room.position, logEpoch: room.logEpoch, ...read };
281
+ }
package/dist/digest.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export declare function textBytes(value: string): number;
2
2
  export declare function sha256Hex(value: string): Promise<string>;
3
- //# sourceMappingURL=digest.d.ts.map
@@ -1,41 +1,33 @@
1
- import type { Capability, DiscoveredRoom, Discovery, Member, ProviderLimit, Retention } from '@agentshouse/mdruntime';
1
+ import type { Capability, DiscoveredRoom, Discovery, Member, ProviderLimit, Retention, RoomList } 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;
8
7
  max_batch_documents: number;
9
8
  max_path_length: number;
10
9
  max_path_depth: number;
11
- max_mount_files: number;
12
- max_mount_bytes: number;
13
10
  max_inline_body_bytes: number;
14
11
  max_upload_bytes: number;
15
12
  max_prefixes: number;
16
- max_held_files: number;
17
13
  change_retention_seconds: number;
18
- operation_retention_seconds: number;
19
14
  max_move_documents?: number;
20
15
  };
21
16
  export type HouseOperations = {
22
17
  write: readonly string[];
23
- delete: readonly string[];
24
- };
25
- export type HouseReadLevel = 'mcp' | 'online' | 'local';
26
- export type HouseModel = {
27
- root: string;
28
- paths: readonly string[];
18
+ erase: readonly string[];
29
19
  };
20
+ export type HouseAccessLevel = 'search' | 'open' | 'keep';
30
21
  export type HouseAuthority = LogPosition & {
31
22
  roomRef: string;
32
23
  roomHandle: string;
33
24
  name: string;
34
25
  schema: string;
35
- houseModel: HouseModel | null;
26
+ typedSelection: readonly string[] | null;
36
27
  managedReplication: 'admitted' | 'unavailable';
37
28
  protectedPaths: readonly string[];
38
- read: HouseReadLevel;
29
+ writtenHomes: readonly string[];
30
+ level: HouseAccessLevel;
39
31
  operations: HouseOperations;
40
32
  };
41
33
  export type HouseDiscoveryDocument = {
@@ -43,14 +35,21 @@ export type HouseDiscoveryDocument = {
43
35
  bounds: HouseBounds;
44
36
  authorities: readonly HouseAuthority[];
45
37
  actions: readonly string[];
38
+ roomList: RoomList;
39
+ };
40
+ export type HouseAuthorityChange = {
41
+ member: Member;
42
+ authorities: readonly HouseAuthority[];
43
+ listed: readonly string[];
44
+ left: readonly string[];
45
+ roomList: RoomList;
46
46
  };
47
47
  export type TrackedAuthority = LogPosition & {
48
48
  locator: string;
49
49
  authority: string;
50
50
  handle: string;
51
51
  schema: string;
52
- houseModel: HouseModel | null;
53
- schemas: readonly string[];
52
+ typedSelection: readonly string[] | null;
54
53
  };
55
54
  export type HouseSiteAuthority = LogPosition & {
56
55
  roomRef: string;
@@ -61,14 +60,31 @@ export type HouseSiteDiscovery = {
61
60
  bounds: HouseBounds;
62
61
  authorities: readonly HouseSiteAuthority[];
63
62
  };
63
+ export declare const ROOM_OWN: {
64
+ readonly room_ref: true;
65
+ readonly room_handle: true;
66
+ readonly name: true;
67
+ readonly position: true;
68
+ readonly created: true;
69
+ readonly archived: true;
70
+ };
71
+ type RoomOwn = keyof typeof ROOM_OWN;
72
+ type Folded<A extends Record<'room_ref' | 'room_handle' | 'name' | 'position', unknown>> = {
73
+ readonly shapes: readonly Omit<A, RoomOwn>[];
74
+ readonly rooms: readonly (Pick<A, Extract<keyof A, RoomOwn>> & {
75
+ readonly shape: number;
76
+ })[];
77
+ };
78
+ export declare function foldedAuthorities<A extends Record<'room_ref' | 'room_handle' | 'name' | 'position', unknown>>(authorities: readonly A[]): Folded<A>;
64
79
  export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
80
+ export declare function parseAuthorityChange(body: unknown): HouseAuthorityChange | null;
65
81
  export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
66
82
  export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
67
- export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
83
+ export declare function trackedFrom(document: Pick<HouseDiscoveryDocument, 'authorities'>): TrackedAuthority[];
68
84
  export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
69
85
  export declare function declaredRetention(bounds: HouseBounds): Retention;
70
- export declare function capabilities(actions: HouseDiscoveryDocument['actions'], rooms: readonly Pick<TrackedAuthority, 'authority' | 'houseModel'>[]): readonly Capability[];
86
+ export declare function capabilities(actions: HouseDiscoveryDocument['actions']): readonly Capability[];
71
87
  export declare function siteCapabilities(): readonly Capability[];
72
88
  export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
73
89
  export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
74
- //# sourceMappingURL=discovery.d.ts.map
90
+ export {};
@@ -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,qBAA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