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

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/site.js CHANGED
@@ -1,9 +1,9 @@
1
1
  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
- import { manifestedModels, partModels, streamedModels, viewModels } from './model.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';
4
+ import { streamedModels, viewModels } from './model.js';
5
+ import { bootstrapping, parseEnumeration, refreshFrom, viewOf, wholeView, } from './read.js';
6
+ import { roomStreams } from './room-stream.js';
7
7
  import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
8
8
  import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
9
9
  import { houseNotifications } from './stream.js';
@@ -27,7 +27,8 @@ function siteRoom(tracked) {
27
27
  export function createSiteAdapter(transport, snapshot = false) {
28
28
  const notifications = houseNotifications(transport, 'site');
29
29
  const tracked = new Map();
30
- const expired = new Map();
30
+ const read = new Map();
31
+ const rooms = roomStreams('site');
31
32
  function fileRoute(request) {
32
33
  const entry = tracked.get(request.locator);
33
34
  if (entry === undefined)
@@ -57,37 +58,29 @@ export function createSiteAdapter(transport, snapshot = false) {
57
58
  const first = await enumerated(entry, from);
58
59
  return 'kind' in first ? first : wholeView(first, (page) => enumerated(entry, from, page));
59
60
  }
60
- async function partedRoom(entry) {
61
- const cut = expired.get(entry.locator);
62
- const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`);
63
- const classified = classifyDoor(answer.status, answer.body, entry.locator);
64
- if (classified !== null)
65
- return classified;
66
- const room = parseSiteParted(answer.body);
67
- return room === null || room.anchor !== entry.authority ? UNCERTAIN : room;
61
+ async function openedRoom(entry, arriving, signal) {
62
+ const cut = read.get(entry.locator);
63
+ const answered = await transport.streamed(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`, signal ?? new AbortController().signal);
64
+ if (answered.room === null)
65
+ return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN;
66
+ const head = await rooms.head(entry, answered.room, arriving, signal);
67
+ const at = head.kind === 'bootstrap' ? logPosition(head.roomVersion) : null;
68
+ if (at !== null)
69
+ read.set(entry.locator, at.position);
70
+ return head;
68
71
  }
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
- }
76
- for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
77
- const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}?part=${encodeURIComponent(listed.part)}`, partArrival(listed, arriving));
78
- const failure = classifyRead(answer.status, answer.body, entry.locator);
79
- if (failure?.kind === 'beyond-horizon')
80
- expired.set(entry.locator, room.position);
81
- if (failure !== null)
82
- return failure;
83
- const frame = partFrame(answer.body);
84
- if (frame === null)
85
- continue;
86
- const scope = await housePart(room, frame, listed, 'site');
87
- if (scope !== null)
88
- return 'kind' in scope ? scope : { scope, frame };
89
- }
90
- return unverifiedPart(entry.locator);
72
+ async function streamedPage(entry, token) {
73
+ const part = await rooms.part(entry, token);
74
+ if ('kind' in part)
75
+ return part;
76
+ notifications.reach(entry.authority, part.scope);
77
+ const { folders: _folders, ...page } = await stepped(bootstrapping(part.scope));
78
+ return {
79
+ ...page,
80
+ ...(part.models === undefined ? {} : { models: part.models }),
81
+ ...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
82
+ bytes: part.bytes,
83
+ };
91
84
  }
92
85
  async function refreshed(entry, fromRoomVersion) {
93
86
  const from = logPosition(fromRoomVersion);
@@ -135,44 +128,9 @@ export function createSiteAdapter(transport, snapshot = false) {
135
128
  const entry = tracked.get(request.locator);
136
129
  if (entry === undefined)
137
130
  return { kind: 'room-not-readable', locator: request.locator };
138
- let continued;
139
- let inventory;
140
- if (request.pageToken === undefined) {
141
- const room = await partedRoom(entry);
142
- if ('kind' in room)
143
- return room;
144
- const { models, seen } = await manifestedModels(room, entry);
145
- continued = { room, next: 0, seen };
146
- inventory = partInventory(room);
147
- if (inventory.parts > 0) {
148
- return manifested(room, inventory, JSON.stringify(continued), models);
149
- }
150
- }
151
- else
152
- continued = JSON.parse(request.pageToken);
153
- const listed = continued.room.parts[continued.next];
154
- const sent = listed === undefined
155
- ? { scope: emptyScope(continued.room), frame: null }
156
- : await fetchedPart(entry, continued.room, listed, request.received, request.arriving);
157
- if ('kind' in sent)
158
- return sent;
159
- const { scope } = sent;
160
- notifications.reach(entry.authority, scope);
161
- const next = continued.next + 1;
162
- const more = next < continued.room.parts.length;
163
- const seen = [
164
- ...continued.seen,
165
- ...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
166
- ];
167
- const models = await partModels(scope, entry, new Set(seen), !more);
168
- const { folders: _folders, ...page } = await stepped(bootstrapping(scope));
169
- return {
170
- ...page,
171
- ...(models === undefined ? {} : { models }),
172
- ...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
173
- ...(inventory === undefined ? {} : { inventory }),
174
- ...(sent.frame === null ? {} : { received: sent.frame }),
175
- };
131
+ return request.pageToken === undefined
132
+ ? openedRoom(entry, request.arriving, request.signal)
133
+ : streamedPage(entry, request.pageToken);
176
134
  },
177
135
  async refresh(_authorization, request) {
178
136
  const entry = tracked.get(request.locator);
@@ -190,6 +148,9 @@ export function createSiteAdapter(transport, snapshot = false) {
190
148
  async mutate() {
191
149
  return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {}, retryable: false };
192
150
  },
151
+ async attach() {
152
+ return { kind: 'rejected', code: 'write-grant', fields: {}, retryable: false };
153
+ },
193
154
  async history() {
194
155
  return { kind: 'no-history' };
195
156
  },
@@ -248,11 +209,6 @@ export function createSiteAdapter(transport, snapshot = false) {
248
209
  },
249
210
  reopen: notifications.reopen,
250
211
  observe: notifications.observe,
251
- published(locator, roomVersion) {
252
- const at = logPosition(roomVersion);
253
- if (at !== null)
254
- notifications.published(locator, at);
255
- },
256
212
  },
257
213
  serviceMode: notifications.serviceMode,
258
214
  };
package/dist/stream.d.ts CHANGED
@@ -1,22 +1,19 @@
1
- import { type ConversationStream, type RefreshPage, type RoomStreamEvent, type ServiceModeSignal, type StreamReceipts } from '@agentshouse/mdruntime';
1
+ import { type ConversationStream, type RefreshPage, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
2
2
  import type { TrackedAuthority } from './discovery.js';
3
3
  import type { HouseDoor, HouseHeldRoom, HouseMode, HouseStreamEntry } from './transport.js';
4
4
  import { type LogPosition } from './version.js';
5
- export type HeldRevision = (path: string, revision: string) => boolean;
6
5
  export type StreamedAdvancement = {
7
6
  page: RefreshPage;
8
7
  schemas: ReadonlyMap<string, HouseStreamEntry>;
9
8
  };
10
9
  export type HouseNotifications = {
11
10
  runtime: string;
12
- observe(notify: (event: RoomStreamEvent) => void, receipts: StreamReceipts): () => void;
11
+ observe(notify: (event: RoomStreamEvent) => void): () => void;
13
12
  send(rooms: readonly HouseHeldRoom[]): void;
14
- published(locator: string, at: LogPosition): void;
15
13
  reopen(): void;
16
14
  track(authorities: readonly TrackedAuthority[]): void;
17
15
  reach(authority: string, at: LogPosition): void;
18
- edited(tracked: TrackedAuthority, from: LogPosition): readonly string[];
19
- advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): Generator<number, StreamedAdvancement | null, void>;
16
+ advance(tracked: TrackedAuthority, from: LogPosition): Generator<number, StreamedAdvancement | null, void>;
20
17
  conversations: ConversationStream;
21
18
  serviceMode: ServiceModeSignal;
22
19
  };
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EAEvB,KAAK,WAAW,EAChB,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAEpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAUvD,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAEb,SAAS,EAET,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AA0C7D,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;AAEvE,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,EAAE,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAAC;IACxF,IAAI,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,IAAI,CAAC;IAC5C,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,CAAC;IAClD,MAAM,IAAI,IAAI,CAAC;IACf,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,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"}
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EAEvB,KAAK,WAAW,EAChB,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAUvD,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAEb,SAAS,EAET,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AA0B7D,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC9D,IAAI,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,IAAI,CAAC;IAC5C,MAAM,IAAI,IAAI,CAAC;IACf,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtD,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD,OAAO,CACL,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,WAAW,GAChB,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;IACvD,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAyBF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CA+W5F"}
package/dist/stream.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
- import { acceptedMessage } from './actions.js';
3
- import { sha256Hex } from './digest.js';
2
+ import { acceptedMessage, cursorPosition } from './actions.js';
4
3
  import { answered, answering, binaryFileOf, folded, forgotten, headChange, revised, } from './read.js';
5
4
  import { roomVersion } from './version.js';
6
5
  const HELD_FRAMES_MAX = 256;
@@ -17,6 +16,7 @@ function listedConversation(listed) {
17
16
  finished: listed.finished_at,
18
17
  outcome: listed.outcome,
19
18
  waiting: listed.waiting,
19
+ newest: listed.newest === null ? null : cursorPosition(listed.newest),
20
20
  };
21
21
  }
22
22
  function position(value) {
@@ -24,78 +24,11 @@ function position(value) {
24
24
  return null;
25
25
  return BigInt(value);
26
26
  }
27
- function assembled(entries) {
28
- const whole = [];
29
- let open = null;
30
- for (const entry of entries) {
31
- if (entry.kind === 'piece') {
32
- if (open === null || open.entry.path !== entry.path || entry.text === undefined)
33
- return null;
34
- open.texts.push(entry.text);
35
- }
36
- else {
37
- if (open !== null)
38
- return null;
39
- if (entry.continued !== true) {
40
- whole.push(entry);
41
- continue;
42
- }
43
- if (entry.text === undefined)
44
- return null;
45
- open = { entry, texts: [entry.text] };
46
- }
47
- if (entry.continued === true)
48
- continue;
49
- const { continued: _continued, ...head } = open.entry;
50
- whole.push({ ...head, text: open.texts.join('') });
51
- open = null;
52
- }
53
- return open === null ? whole : null;
54
- }
55
- async function verified(entries) {
56
- try {
57
- for (const entry of entries) {
58
- if (entry.text === undefined || entry.sha256 === undefined)
59
- continue;
60
- if ((await sha256Hex(entry.text)) !== entry.sha256)
61
- return false;
62
- }
63
- return true;
64
- }
65
- catch {
66
- return false;
67
- }
68
- }
69
- function resumed(kept, frame) {
70
- const last = frame.entries.at(-1);
71
- const point = { parts: frame.index + 1, from: frame.from, target: frame.target };
72
- if (last?.continued !== true)
73
- return { ...point, handled: frame.handled, piece: null };
74
- const text = last.text?.length ?? 0;
75
- if (last.kind !== 'piece') {
76
- return last.sha256 === undefined
77
- ? kept.resume
78
- : { ...point, handled: frame.handled, piece: { sha256: last.sha256, offset: text } };
79
- }
80
- const piece = kept.resume?.piece ?? null;
81
- if (piece === null)
82
- return kept.resume;
83
- const pieces = frame.entries.reduce((sum, entry) => sum + (entry.kind === 'piece' ? (entry.text?.length ?? 0) : 0), 0);
84
- return {
85
- ...point,
86
- handled: frame.handled,
87
- piece: { sha256: piece.sha256, offset: piece.offset + pieces },
88
- };
89
- }
90
27
  export function houseNotifications(transport, mode) {
91
28
  const stream = transport.stream;
92
29
  const lines = new Map();
93
- const kept = new Map();
94
- let receipts = null;
95
- let loaded = Promise.resolve();
30
+ const staged = new Map();
96
31
  let acknowledging = null;
97
- let receiving = Promise.resolve();
98
- let verifying = 0;
99
32
  const locators = new Map();
100
33
  const observers = new Set();
101
34
  const conversationObservers = new Set();
@@ -125,6 +58,7 @@ export function houseNotifications(transport, mode) {
125
58
  function reopened(next) {
126
59
  opening = next;
127
60
  acknowledging = next;
61
+ staged.clear();
128
62
  const gapped = new Set([...replicated, ...live]);
129
63
  live.clear();
130
64
  for (const conversation of gapped)
@@ -198,160 +132,36 @@ export function houseNotifications(transport, mode) {
198
132
  if (line !== undefined)
199
133
  lines.set(authority, { ...line, frames: [] });
200
134
  }
201
- async function forget(carries) {
202
- const held = carries.filter((carry) => kept.delete(carry));
203
- if (held.length > 0)
204
- await receipts?.drop(held).catch(() => { });
205
- }
206
- async function lost(authority, carry) {
135
+ function lost(authority, carry) {
136
+ staged.delete(carry);
207
137
  interrupt(authority);
208
- await forget([carry]);
209
138
  }
210
- async function stage(frame, via) {
211
- await loaded;
212
- const port = receipts;
213
- if (port === null)
214
- return;
215
- const held = kept.get(frame.carry);
216
- if (held === undefined && frame.index !== 0) {
217
- interrupt(frame.authority);
218
- return;
219
- }
220
- if (held !== undefined &&
221
- (held.fenced !== null || frame.index > held.parts || frame.index < (held.resume?.parts ?? 0))) {
222
- await lost(frame.authority, frame.carry);
139
+ function stage(frame, via) {
140
+ const held = staged.get(frame.carry);
141
+ if (frame.index !== (held?.parts ?? 0)) {
142
+ lost(frame.authority, frame.carry);
223
143
  return;
224
144
  }
225
145
  if (held === undefined) {
226
- await forget([...kept.values()]
227
- .filter((other) => other.authority === frame.authority && other.fenced === null)
228
- .map((other) => other.carry));
229
- }
230
- const start = held ?? {
231
- authority: frame.authority,
232
- carry: frame.carry,
233
- logEpoch: lines.get(frame.authority)?.logEpoch ?? null,
234
- after: frame.after,
235
- parts: 0,
236
- resume: null,
237
- fenced: null,
238
- };
239
- const next = { ...start, parts: frame.index + 1, resume: resumed(start, frame) };
240
- const part = { entries: frame.entries };
241
- try {
242
- await port.keep(frame.carry, next, { index: frame.index, value: part });
243
- }
244
- catch {
245
- await lost(frame.authority, frame.carry);
246
- return;
146
+ for (const [carry, other] of staged) {
147
+ if (other.authority === frame.authority)
148
+ staged.delete(carry);
149
+ }
247
150
  }
248
- kept.set(frame.carry, next);
151
+ const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
152
+ next.entries.push(...frame.entries);
153
+ next.parts += 1;
154
+ staged.set(frame.carry, next);
249
155
  via?.received(frame.authority, frame.carry, frame.index);
250
156
  }
251
- async function keptEntries(carry, parts) {
252
- if (parts === 0)
253
- return [];
254
- if (receipts === null)
255
- return null;
256
- const read = (await receipts.parts(carry, parts));
257
- if (read.length !== parts)
258
- return null;
259
- const entries = assembled(read.flatMap((part) => part.entries));
260
- return entries !== null && (await verified(entries)) ? entries : null;
261
- }
262
- async function carried(frame) {
263
- await loaded;
264
- const held = kept.get(frame.carry);
265
- if (frame.parts > 0 && held?.parts !== frame.parts) {
266
- await lost(frame.authority, frame.carry);
267
- return;
268
- }
269
- const entries = await keptEntries(frame.carry, frame.parts).catch(() => null);
270
- if (entries === null) {
271
- await lost(frame.authority, frame.carry);
272
- return;
273
- }
274
- const fenced = {
275
- ...(held ?? {
276
- authority: frame.authority,
277
- carry: frame.carry,
278
- logEpoch: frame.log_epoch,
279
- after: frame.after,
280
- parts: 0,
281
- resume: null,
282
- }),
283
- after: frame.after,
284
- fenced: { position: frame.position, logEpoch: frame.log_epoch },
285
- };
286
- try {
287
- await receipts?.keep(frame.carry, fenced);
288
- }
289
- catch {
290
- await lost(frame.authority, frame.carry);
157
+ function carried(frame) {
158
+ const held = staged.get(frame.carry);
159
+ staged.delete(frame.carry);
160
+ if ((held?.parts ?? 0) !== frame.parts) {
161
+ interrupt(frame.authority);
291
162
  return;
292
163
  }
293
- kept.set(frame.carry, fenced);
294
- publish(frame, entries);
295
- }
296
- async function load(port) {
297
- try {
298
- for (const { key, head } of await port.heads())
299
- kept.set(key, head);
300
- }
301
- catch {
302
- kept.clear();
303
- }
304
- }
305
- async function restored(room) {
306
- const line = lines.get(room.authority);
307
- let at = room.position;
308
- const chain = [];
309
- for (;;) {
310
- const next = [...kept.values()].find((carry) => carry.authority === room.authority &&
311
- carry.after === at &&
312
- carry.fenced?.logEpoch === room.log_epoch);
313
- if (next?.fenced == null)
314
- break;
315
- const entries = await keptEntries(next.carry, next.parts).catch(() => null);
316
- if (entries === null)
317
- break;
318
- chain.push({ carry: next, entries });
319
- at = next.fenced.position;
320
- }
321
- const partial = [...kept.values()].find((carry) => carry.authority === room.authority &&
322
- carry.fenced === null &&
323
- carry.logEpoch === room.log_epoch &&
324
- carry.after === at &&
325
- carry.resume !== null &&
326
- carry.resume.parts > 0);
327
- const stale = [...kept.values()].filter((carry) => carry.authority === room.authority &&
328
- carry !== partial &&
329
- !chain.some((link) => link.carry === carry));
330
- await forget(stale.map((carry) => carry.carry));
331
- if (line !== undefined && line.logEpoch === room.log_epoch && chain.length > 0) {
332
- const frames = chain.map(({ carry, entries }) => ({
333
- after: BigInt(carry.after),
334
- position: BigInt(carry.fenced.position),
335
- entries,
336
- }));
337
- lines.set(room.authority, { ...line, frames: [...line.frames, ...frames] });
338
- }
339
- return {
340
- ...room,
341
- position: at,
342
- ...(partial?.resume == null
343
- ? {}
344
- : {
345
- carry: {
346
- id: partial.carry,
347
- parts: partial.resume.parts,
348
- from: partial.resume.from,
349
- target: partial.resume.target,
350
- handled: partial.resume.handled,
351
- ...(partial.resume.piece === null ? {} : { piece: partial.resume.piece }),
352
- },
353
- }),
354
- };
164
+ publish(frame, held?.entries ?? []);
355
165
  }
356
166
  function handle(frame, via) {
357
167
  if (frame.type === 'signal') {
@@ -398,9 +208,9 @@ export function houseNotifications(transport, mode) {
398
208
  return;
399
209
  }
400
210
  if (frame.type === 'part')
401
- return stage(frame, via);
402
- if (frame.type === 'carried')
403
- return carried(frame);
211
+ stage(frame, via);
212
+ else if (frame.type === 'carried')
213
+ carried(frame);
404
214
  }
405
215
  function publish(frame, entries) {
406
216
  const at = position(frame.position);
@@ -425,29 +235,12 @@ export function houseNotifications(transport, mode) {
425
235
  }
426
236
  announce(frame.authority, { position: frame.position, logEpoch: frame.log_epoch });
427
237
  }
428
- stream.observe((frame) => {
429
- const via = acknowledging;
430
- if (verifying === 0) {
431
- const handled = handle(frame, via);
432
- if (handled === undefined)
433
- return;
434
- verifying += 1;
435
- receiving = handled.finally(() => {
436
- verifying -= 1;
437
- });
438
- return;
439
- }
440
- verifying += 1;
441
- receiving = receiving
442
- .then(() => handle(frame, via))
443
- .finally(() => {
444
- verifying -= 1;
445
- });
446
- });
238
+ stream.observe((frame) => handle(frame, acknowledging));
447
239
  stream.opened(reopened);
448
240
  stream.closed(({ revoked, lost }) => {
449
241
  opening = null;
450
242
  acknowledging = null;
243
+ staged.clear();
451
244
  emit({ kind: 'closed', revoked, lost });
452
245
  });
453
246
  return {
@@ -471,12 +264,8 @@ export function houseNotifications(transport, mode) {
471
264
  };
472
265
  },
473
266
  },
474
- observe(notify, port) {
267
+ observe(notify) {
475
268
  observers.add(notify);
476
- if (receipts === null) {
477
- receipts = port;
478
- loaded = load(port);
479
- }
480
269
  if (opening !== null) {
481
270
  queueMicrotask(() => {
482
271
  if (observers.has(notify))
@@ -497,30 +286,7 @@ export function houseNotifications(transport, mode) {
497
286
  }
498
287
  const current = opening;
499
288
  opening = null;
500
- if (current === null)
501
- return;
502
- void loaded
503
- .then(() => Promise.all(rooms.map(restored)))
504
- .then((presented) => {
505
- current.hold(presented, runtime);
506
- for (const [index, room] of presented.entries()) {
507
- if (room.position === rooms[index].position)
508
- continue;
509
- announce(room.authority, { position: room.position, logEpoch: room.log_epoch });
510
- }
511
- });
512
- },
513
- published(locator, at) {
514
- const authority = [...locators].find(([, held]) => held.includes(locator))?.[0];
515
- const reached = position(at.position);
516
- if (authority === undefined || reached === null)
517
- return;
518
- void forget([...kept.values()]
519
- .filter((carry) => carry.authority === authority &&
520
- carry.fenced !== null &&
521
- carry.fenced.logEpoch === at.logEpoch &&
522
- BigInt(carry.fenced.position) <= reached)
523
- .map((carry) => carry.carry));
289
+ current?.hold(rooms, runtime);
524
290
  },
525
291
  reopen() {
526
292
  const current = opening;
@@ -539,9 +305,10 @@ export function houseNotifications(transport, mode) {
539
305
  if (!locators.has(authority))
540
306
  lines.delete(authority);
541
307
  }
542
- void loaded.then(() => forget([...kept.values()]
543
- .filter((carry) => !locators.has(carry.authority))
544
- .map((carry) => carry.carry)));
308
+ for (const [carry, held] of staged) {
309
+ if (!locators.has(held.authority))
310
+ staged.delete(carry);
311
+ }
545
312
  },
546
313
  reach(authority, at) {
547
314
  const line = lines.get(authority);
@@ -556,18 +323,7 @@ export function houseNotifications(transport, mode) {
556
323
  held,
557
324
  });
558
325
  },
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
- },
570
- *advance(tracked, from, holds) {
326
+ *advance(tracked, from) {
571
327
  const line = lines.get(tracked.authority);
572
328
  const start = position(from.position);
573
329
  if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
@@ -585,12 +341,6 @@ export function houseNotifications(transport, mode) {
585
341
  folded(answer, entry.path, entry.removed === true);
586
342
  continue;
587
343
  }
588
- if (entry.kind === 'edited' &&
589
- entry.revision !== undefined &&
590
- holds?.(entry.path, entry.revision) === true) {
591
- forgotten(answer, entry.path);
592
- continue;
593
- }
594
344
  if (entry.path === tracked.schema)
595
345
  schemas.set(entry.path, entry);
596
346
  if (entry.kind === 'removed') {
@@ -599,7 +349,7 @@ export function houseNotifications(transport, mode) {
599
349
  continue;
600
350
  }
601
351
  const binary = binaryFileOf(entry);
602
- if (binary === null || (binary === undefined && entry.text === undefined))
352
+ if (binary === null)
603
353
  return null;
604
354
  if (mode === 'credential' && entry.revision === undefined)
605
355
  return null;