@agentshouse/mdruntime-adapter 0.1.0-c0a168d2cd8cc → 0.1.0-c0a3a92c6ef52

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,6 +1,5 @@
1
- import { paced, patching, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
- import { gunzipped } from './part.js';
3
- import { readPosition, roomVersion } from './version.js';
1
+ import { patching, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { roomVersion } from './version.js';
4
3
  const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
5
4
  function fileOf(revision) {
6
5
  return REVISION_FILE.exec(revision)?.[1];
@@ -8,9 +7,10 @@ function fileOf(revision) {
8
7
  export function answering() {
9
8
  return {
10
9
  documents: new Map(),
11
- outlines: new Map(),
10
+ facts: new Map(),
12
11
  revisions: new Map(),
13
12
  fileIds: new Map(),
13
+ created: new Map(),
14
14
  changes: new Map(),
15
15
  binaryFiles: new Map(),
16
16
  removals: new Set(),
@@ -26,9 +26,10 @@ export function revised(answer, path, revision) {
26
26
  }
27
27
  export function forgotten(answer, path) {
28
28
  answer.documents.delete(path);
29
- answer.outlines.delete(path);
29
+ answer.facts.delete(path);
30
30
  answer.revisions.delete(path);
31
31
  answer.fileIds.delete(path);
32
+ answer.created.delete(path);
32
33
  answer.changes.delete(path);
33
34
  answer.binaryFiles.delete(path);
34
35
  answer.removals.delete(path);
@@ -55,9 +56,10 @@ export function* answered(answer) {
55
56
  const removals = yield* pathsOf(answer.removals);
56
57
  return {
57
58
  documents: yield* patching({}, answer.documents),
58
- ...(answer.outlines.size === 0 ? {} : { outlines: yield* patching({}, answer.outlines) }),
59
+ facts: yield* patching({}, answer.facts),
59
60
  revisions: yield* patching({}, answer.revisions),
60
61
  ...(answer.fileIds.size === 0 ? {} : { fileIds: yield* patching({}, answer.fileIds) }),
62
+ ...(answer.created.size === 0 ? {} : { created: yield* patching({}, answer.created) }),
61
63
  changes: yield* patching({}, answer.changes),
62
64
  binaryFiles: yield* patching({}, answer.binaryFiles),
63
65
  removals,
@@ -121,11 +123,19 @@ export function headChange(held) {
121
123
  const author = held.author === undefined ? null : changeAuthor(held.author);
122
124
  if (held.author !== undefined && author === null)
123
125
  return null;
124
- if (held.created_at === undefined)
126
+ if (held.changed_at === undefined)
125
127
  return undefined;
126
- if (typeof held.created_at !== 'string')
128
+ if (typeof held.changed_at !== 'string')
127
129
  return null;
128
- return { author, time: held.created_at };
130
+ return { author, time: held.changed_at };
131
+ }
132
+ export function createdOf(held) {
133
+ if (held.created_at === undefined)
134
+ return undefined;
135
+ return typeof held.created_at === 'string' ? held.created_at : null;
136
+ }
137
+ function createdHeld(created) {
138
+ return created === undefined ? {} : { created };
129
139
  }
130
140
  function headed(head) {
131
141
  return head === undefined ? {} : { head };
@@ -141,45 +151,33 @@ export function binaryFileOf(held) {
141
151
  function binaried(binary) {
142
152
  return binary === undefined ? {} : { binary };
143
153
  }
144
- export function outlineOf(value) {
145
- if (value === undefined)
146
- return undefined;
147
- if (typeof value !== 'object' || value === null)
148
- return null;
149
- const { type, fields, links } = value;
150
- if (type !== null && typeof type !== 'string')
151
- return null;
152
- if (fields !== null && (typeof fields !== 'object' || Array.isArray(fields)))
153
- return null;
154
- if (!Array.isArray(links) || links.some((link) => typeof link !== 'string'))
155
- return null;
156
- return {
157
- type: type,
158
- fields: fields,
159
- links: links,
160
- };
154
+ export function carriedFacts(held) {
155
+ return held.facts === undefined ? {} : { facts: held.facts };
156
+ }
157
+ function carriedSpace(held) {
158
+ return typeof held.space === 'string' ? { space: held.space } : {};
161
159
  }
162
- function parseFile(value, mode) {
160
+ export function parseFile(value, mode) {
163
161
  if (typeof value !== 'object' || value === null)
164
162
  return null;
165
163
  const file = value;
166
164
  if (typeof file.path !== 'string')
167
165
  return null;
168
166
  const head = headChange(file);
167
+ const created = createdOf(file);
169
168
  const binary = binaryFileOf(file);
170
- const outline = outlineOf(file.outline);
171
- if (head === null || binary === null || outline === null)
169
+ if (head === null || created === null || binary === null)
172
170
  return null;
173
171
  if (mode === 'site') {
174
172
  if (typeof file.sha256 !== 'string')
175
173
  return null;
176
174
  return {
177
175
  path: file.path,
178
- revision: binary?.sha256 ?? file.sha256,
176
+ revision: binary?.sha256,
179
177
  version: file.sha256,
180
178
  ...headed(head),
181
179
  ...binaried(binary),
182
- ...(outline === undefined ? {} : { outline }),
180
+ ...carriedFacts(file),
183
181
  };
184
182
  }
185
183
  if (typeof file.revision !== 'string')
@@ -190,151 +188,21 @@ function parseFile(value, mode) {
190
188
  version: file.revision,
191
189
  ...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
192
190
  ...headed(head),
191
+ ...createdHeld(created),
193
192
  ...binaried(binary),
194
- ...(outline === undefined ? {} : { outline }),
195
- };
196
- }
197
- function parseModels(value, mode) {
198
- if (!Array.isArray(value))
199
- return null;
200
- const files = [];
201
- const contents = [];
202
- for (const entry of value) {
203
- const file = parseFile(entry, mode);
204
- const { content } = entry;
205
- if (file === null || typeof content !== 'string')
206
- return null;
207
- files.push(file);
208
- contents.push({ path: file.path, content });
209
- }
210
- return { files, contents };
211
- }
212
- function parseRoomHead(value, mode) {
213
- if (typeof value !== 'object' || value === null)
214
- return null;
215
- const held = value;
216
- if (typeof held.manifest !== 'object' || held.manifest === null)
217
- return null;
218
- const models = parseModels(held.models, mode);
219
- if (models === null)
220
- return null;
221
- const manifest = held.manifest;
222
- if (manifest.scope !== 'room')
223
- return null;
224
- const at = readPosition(manifest);
225
- if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
226
- return null;
227
- if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
228
- return null;
229
- return { anchor: manifest.anchor, ...at, models };
230
- }
231
- export async function roomHead(payload, mode) {
232
- let text = '';
233
- try {
234
- for await (const chunk of gunzipped(payload))
235
- text += chunk;
236
- return text.endsWith('\n') && text.indexOf('\n') === text.length - 1
237
- ? parseRoomHead(JSON.parse(text), mode)
238
- : null;
239
- }
240
- catch {
241
- return null;
242
- }
243
- }
244
- export function manifested(room, pageToken, models) {
245
- return {
246
- kind: 'bootstrap',
247
- roomVersion: roomVersion(room),
248
- documents: {},
249
- revisions: {},
250
- changes: {},
251
- binaryFiles: {},
252
- pageToken,
253
- ...(models === undefined ? {} : { models }),
193
+ ...carriedFacts(file),
194
+ ...carriedSpace(file),
254
195
  };
255
196
  }
256
197
  export function modelScope(room) {
257
- return { ...emptyScope(room), files: room.models.files, contents: room.models.contents };
258
- }
259
- export function emptyScope(room) {
260
198
  return {
261
199
  anchor: room.anchor,
262
200
  position: room.position,
263
201
  logEpoch: room.logEpoch,
264
- files: [],
265
- contents: [],
202
+ files: room.models.files,
203
+ contents: room.models.contents,
266
204
  };
267
205
  }
268
- function partLine(line, mode, read) {
269
- if (read.ended)
270
- return false;
271
- let entry;
272
- try {
273
- entry = JSON.parse(line);
274
- }
275
- catch {
276
- return false;
277
- }
278
- if (endLine(entry)) {
279
- read.ended = true;
280
- return true;
281
- }
282
- if (folderLine(entry)) {
283
- read.folders.push(entry.folder);
284
- return true;
285
- }
286
- const file = parseFile(entry, mode);
287
- if (file === null)
288
- return false;
289
- read.files.push(file);
290
- const { content } = entry;
291
- if (typeof content === 'string')
292
- read.contents.push({ path: file.path, content });
293
- else if (content !== undefined)
294
- return false;
295
- return true;
296
- }
297
- async function partRead(chunks, mode) {
298
- const read = { files: [], contents: [], folders: [], ended: false };
299
- const pace = paced();
300
- const unfinished = [];
301
- for (let chunk = await chunks.read(); chunk.done !== true; chunk = await chunks.read()) {
302
- const text = chunk.value;
303
- let start = 0;
304
- for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
305
- const piece = text.slice(start, end);
306
- const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
307
- if (!partLine(line, mode, read)) {
308
- await chunks.cancel();
309
- return null;
310
- }
311
- start = end + 1;
312
- const due = pace(line.length + ROW_WEIGHT);
313
- if (due instanceof Promise)
314
- await due;
315
- }
316
- if (start < text.length)
317
- unfinished.push(text.slice(start));
318
- }
319
- return unfinished.length === 0 ? read : null;
320
- }
321
- function endLine(entry) {
322
- if (typeof entry !== 'object' || entry === null || !('end' in entry))
323
- return false;
324
- return entry.end === true && Object.keys(entry).length === 1;
325
- }
326
- function folderLine(entry) {
327
- if (typeof entry !== 'object' || entry === null || !('folder' in entry))
328
- return false;
329
- return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
330
- }
331
- export async function housePart(room, payload, mode) {
332
- const read = await partRead(gunzipped(payload).getReader(), mode).catch(() => null);
333
- if (read === null)
334
- return { kind: 'transport-uncertainty' };
335
- const { ended, ...scope } = read;
336
- return { scope: { ...emptyScope(room), ...scope }, ended };
337
- }
338
206
  export function* bootstrapping(scope) {
339
207
  const contents = new Map();
340
208
  for (const entry of scope.contents) {
@@ -344,15 +212,19 @@ export function* bootstrapping(scope) {
344
212
  const answer = answering();
345
213
  for (const file of scope.files) {
346
214
  yield ROW_WEIGHT;
215
+ if (file.space !== undefined)
216
+ continue;
347
217
  if (file.head !== undefined)
348
218
  answer.changes.set(file.path, file.head);
219
+ if (file.created !== undefined)
220
+ answer.created.set(file.path, file.created);
349
221
  const content = contents.get(file.path);
350
222
  if (file.binary !== undefined)
351
223
  answer.binaryFiles.set(file.path, file.binary);
352
224
  else if (content !== undefined)
353
225
  answer.documents.set(file.path, content);
354
- else if (file.outline !== undefined)
355
- answer.outlines.set(file.path, file.outline);
226
+ if (file.binary === undefined && file.facts !== undefined)
227
+ answer.facts.set(file.path, file.facts);
356
228
  if (file.revision !== undefined)
357
229
  revised(answer, file.path, file.revision);
358
230
  }
@@ -368,5 +240,10 @@ export function schemaOf(scope, schema) {
368
240
  const content = scope.contents.find((entry) => entry.path === schema);
369
241
  return content === undefined
370
242
  ? null
371
- : { schema: content.content, version: file.version, revision: file.revision ?? null };
243
+ : {
244
+ schema: content.content,
245
+ version: file.version,
246
+ revision: file.revision ?? null,
247
+ ...(file.space === undefined ? {} : { space: file.space }),
248
+ };
372
249
  }
@@ -1 +1 @@
1
- {"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,YAC9B,cAAc,EACd,mBAAmB,EACnB,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,SAAS,SAAS,CAAC;AAEhC,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD,eAAO,MAAM,yBAAyB,UAAiC,CAAC;AAyBxE,eAAO,MAAM,gBAAgB,QA6FjB,CAAC"}
1
+ {"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,YAC9B,cAAc,EACd,mBAAmB,EACnB,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,SAAS,SAAS,CAAC;AAEhC,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD,eAAO,MAAM,yBAAyB,UAAiC,CAAC;AAyBxE,eAAO,MAAM,gBAAgB,QA2FjB,CAAC"}
@@ -58,8 +58,6 @@ export const HOUSE_ROOM_TYPES = [
58
58
  ` username: ${IDENTITY}`,
59
59
  ' sent_at: { type: string, format: date-time }',
60
60
  ` channel_message: ${IDENTITY}`,
61
- ' state: { enum: [sending, sent, failed] }',
62
- ' reason: { type: string }',
63
61
  ' labelled: { const: true }',
64
62
  ' reactions:',
65
63
  ' type: array',
package/dist/search.js CHANGED
@@ -27,7 +27,7 @@ export async function houseSearch(transport, tracked, request) {
27
27
  : tracked.filter((entry) => request.rooms.includes(entry.locator));
28
28
  if (named !== null && named.length === 0)
29
29
  return { kind: 'found', documents: [] };
30
- const answer = await transport.door(houseDoorRoute('search'), {
30
+ const answer = await transport.door(houseDoorRoute('rooms/search'), {
31
31
  query: request.text,
32
32
  ...(named === null ? {} : { paths: named.map((entry) => `${ROOMS}${entry.handle}`) }),
33
33
  });
@@ -1 +1 @@
1
- {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAQR,MAAM,wBAAwB,CAAC;AAgBhC,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAuBxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAsL1F"}
1
+ {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAQR,MAAM,wBAAwB,CAAC;AAehC,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAuBxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAiK1F"}
package/dist/site.js CHANGED
@@ -1,14 +1,13 @@
1
- import { stepped } from '@agentshouse/mdruntime';
2
1
  import { actionOutcome } from './actions.js';
2
+ import { chunkedHead, chunkPart, siteChunkList } from './chunks.js';
3
3
  import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
4
- import { bootstrapping } from './read.js';
5
- import { roomStreams } from './room-stream.js';
6
- import { classifyDoor, discoveryFailure } from './refusal.js';
4
+ import { spaceSchemas } from './space-schema.js';
5
+ import { discoveryFailure } from './refusal.js';
7
6
  import { HOUSE_TYPED_PATHS } from './house-model.js';
8
7
  import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
9
8
  import { houseNotifications } from './stream.js';
10
- import { houseSiteRoute, SITE_DOOR_SUBMIT, SITE_FILES, SITE_SUBMISSION, } from './transport.js';
11
- import { followsVersion, logPosition, presented, reachedVersion, roomVersion } from './version.js';
9
+ import { houseSiteRoute, SITE_DOOR_SUBMIT, SITE_FILES, SITES_SUBMISSIONS_CREATE, } from './transport.js';
10
+ import { followsVersion, reachedVersion, roomVersion } from './version.js';
12
11
  const UNCERTAIN = { kind: 'transport-uncertainty' };
13
12
  function unfound() {
14
13
  return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
@@ -19,56 +18,47 @@ function siteRoom(tracked) {
19
18
  locator: tracked.locator,
20
19
  handle: tracked.handle,
21
20
  roomVersion: roomVersion(tracked),
22
- operations: { write: [], delete: [] },
21
+ operations: { write: [], erase: [] },
23
22
  replica: { selection: tracked.locator, admission: 'admitted', offline: 'open' },
24
23
  providerOwnedPaths: [],
25
24
  };
26
25
  }
27
26
  export function createSiteAdapter(transport, snapshot = false) {
27
+ const spaces = spaceSchemas();
28
28
  const notifications = houseNotifications(transport, 'site', {
29
29
  opened: async () => {
30
30
  const found = await discovered();
31
31
  return found.kind === 'discovery' ? found : null;
32
32
  },
33
33
  changed: () => null,
34
- });
34
+ }, spaces);
35
35
  const tracked = new Map();
36
- const read = new Map();
37
- const rooms = roomStreams('site');
36
+ const chunked = new Map();
38
37
  function fileRoute(request) {
39
38
  const entry = tracked.get(request.locator);
40
39
  if (entry === undefined)
41
40
  return { kind: 'room-not-readable', locator: request.locator };
42
41
  return `${SITE_FILES}${entry.authority}/${encodeURIComponent(request.revision)}/${encodeURIComponent(request.path)}`;
43
42
  }
44
- async function openedRoom(entry, arriving, signal) {
45
- const cut = read.get(entry.locator);
46
- const answered = await transport.streamed(`${houseSiteRoute('bootstrap')}/${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`, signal ?? new AbortController().signal);
47
- if (answered.room === null)
48
- return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN;
49
- const head = await rooms.head(entry, answered.room, arriving, signal);
50
- const at = head.kind === 'bootstrap' ? logPosition(head.roomVersion) : null;
51
- if (at !== null)
52
- read.set(entry.locator, at.position);
43
+ async function listedRoom(entry) {
44
+ const past = chunked.get(entry.locator)?.position;
45
+ const listed = siteChunkList(await transport.read(`${houseSiteRoute('chunks')}/${entry.authority}${past === undefined ? '' : `?expired=${past}`}`), entry.locator);
46
+ if ('kind' in listed)
47
+ return listed;
48
+ const head = await chunkedHead(listed, entry, spaces);
49
+ if (head.kind === 'bootstrap')
50
+ chunked.set(entry.locator, listed);
53
51
  return head;
54
52
  }
55
- async function namedDocument(entry, path, signal) {
56
- const answered = await transport.streamed(`${houseSiteRoute('bootstrap')}/${entry.authority}?path=${encodeURIComponent(path)}`, signal ?? new AbortController().signal);
57
- if (answered.room === null)
58
- return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN;
59
- return rooms.named(entry, answered.room, signal);
60
- }
61
- async function streamedPage(entry, token) {
62
- const part = await rooms.part(entry, token);
63
- if ('kind' in part)
64
- return part;
65
- const { folders: _folders, ...page } = await stepped(bootstrapping(part.scope));
66
- return {
67
- ...page,
68
- ...(part.models === undefined ? {} : { models: part.models }),
69
- ...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
70
- bytes: part.bytes,
71
- };
53
+ async function chunkPage(entry, id, arriving) {
54
+ const room = chunked.get(entry.locator);
55
+ const address = room?.chunks.get(id);
56
+ if (room === undefined || address === undefined)
57
+ return UNCERTAIN;
58
+ const read = await transport.download(address.url);
59
+ if (read.status !== 200)
60
+ return UNCERTAIN;
61
+ return chunkPart(read.body, room, id, arriving);
72
62
  }
73
63
  async function discovered() {
74
64
  const answer = await transport.read(houseSiteRoute('discover'));
@@ -97,11 +87,9 @@ export function createSiteAdapter(transport, snapshot = false) {
97
87
  const entry = tracked.get(request.locator);
98
88
  if (entry === undefined)
99
89
  return { kind: 'room-not-readable', locator: request.locator };
100
- if (request.path !== undefined)
101
- return namedDocument(entry, request.path, request.signal);
102
90
  return request.pageToken === undefined
103
- ? openedRoom(entry, request.arriving, request.signal)
104
- : streamedPage(entry, request.pageToken);
91
+ ? listedRoom(entry)
92
+ : chunkPage(entry, request.pageToken, request.arriving);
105
93
  },
106
94
  ...(snapshot
107
95
  ? {
@@ -155,7 +143,7 @@ export function createSiteAdapter(transport, snapshot = false) {
155
143
  return followsVersion(version, next);
156
144
  },
157
145
  async action(_authorization, request) {
158
- if (request.name !== SITE_SUBMISSION) {
146
+ if (request.name !== SITES_SUBMISSIONS_CREATE) {
159
147
  return {
160
148
  kind: 'rejected',
161
149
  code: 'action-unimplemented',
@@ -165,18 +153,12 @@ export function createSiteAdapter(transport, snapshot = false) {
165
153
  }
166
154
  if (!transport.online())
167
155
  return UNCERTAIN;
168
- return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), SITE_SUBMISSION, request.input);
156
+ return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), SITES_SUBMISSIONS_CREATE, request.input);
169
157
  },
170
158
  roomStream: snapshot
171
159
  ? undefined
172
160
  : {
173
- hold(rooms) {
174
- notifications.send(rooms.flatMap((room) => {
175
- const entry = tracked.get(room.locator);
176
- const at = logPosition(room.roomVersion);
177
- return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
178
- }));
179
- },
161
+ hold: notifications.send,
180
162
  observe: notifications.observe,
181
163
  },
182
164
  serviceMode: notifications.serviceMode,
@@ -0,0 +1,7 @@
1
+ export type SpaceSchemas = {
2
+ held(space: string, revision: string): string | undefined;
3
+ keep(space: string, revision: string, text: string): void;
4
+ };
5
+ export declare function spaceSchemas(): SpaceSchemas;
6
+ export declare function spaceIdentity(space: string): string;
7
+ //# sourceMappingURL=space-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space-schema.d.ts","sourceRoot":"","sources":["../src/space-schema.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC1D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3D,CAAC;AAEF,wBAAgB,YAAY,IAAI,YAAY,CAY3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}
@@ -0,0 +1,18 @@
1
+ const HELD_TEXTS = 16;
2
+ export function spaceSchemas() {
3
+ const texts = new Map();
4
+ const key = (space, revision) => `${space} ${revision}`;
5
+ return {
6
+ held: (space, revision) => texts.get(key(space, revision)),
7
+ keep(space, revision, text) {
8
+ const named = key(space, revision);
9
+ texts.delete(named);
10
+ texts.set(named, text);
11
+ if (texts.size > HELD_TEXTS)
12
+ texts.delete(texts.keys().next().value);
13
+ },
14
+ };
15
+ }
16
+ export function spaceIdentity(space) {
17
+ return `space:${space}`;
18
+ }
package/dist/stream.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { type AuthorityChange, type Discovery, type ConversationStream, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
1
+ import { type AuthorityChange, type Discovery, type ConversationStream, type HeldRoom, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
2
2
  import type { TrackedAuthority } from './discovery.js';
3
- import { type HouseDoor, type HouseHeldRoom, type HouseMode, type HouseStreamFrame } from './transport.js';
3
+ import type { SpaceSchemas } from './space-schema.js';
4
+ import { type HouseDoor, type HouseMode, type HouseStreamFrame } from './transport.js';
4
5
  export type HouseOpeningFrame = Extract<HouseStreamFrame, {
5
6
  type: 'opening';
6
7
  }>;
@@ -10,14 +11,15 @@ export type HouseAuthorityChangedFrame = Extract<HouseStreamFrame, {
10
11
  export type HouseDiscovering = {
11
12
  opened(frame: HouseOpeningFrame | null): Promise<Discovery | null>;
12
13
  changed(frame: HouseAuthorityChangedFrame): AuthorityChange | null;
14
+ expired?(authorities: readonly string[]): void;
13
15
  };
14
16
  export type HouseNotifications = {
15
17
  runtime: string;
16
18
  observe(notify: (event: RoomStreamEvent) => void): () => void;
17
- send(rooms: readonly HouseHeldRoom[]): void;
19
+ send(rooms: readonly HeldRoom[]): void;
18
20
  track(authorities: readonly TrackedAuthority[]): void;
19
21
  conversations: ConversationStream;
20
22
  serviceMode: ServiceModeSignal;
21
23
  };
22
- export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering): HouseNotifications;
24
+ export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering, spaces: SpaceSchemas): HouseNotifications;
23
25
  //# sourceMappingURL=stream.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EAEpB,KAAK,SAAS,EACd,KAAK,kBAAkB,EAIvB,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAYvD,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,aAAa,EAElB,KAAK,SAAS,EAGd,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AAaxB,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAE/E,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC,CAAC;AAElG,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IACnE,OAAO,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