@agentshouse/mdruntime-adapter 0.1.0-cd59fd8945dcb → 0.1.0-cd5da4f128434

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 (74) hide show
  1. package/README.md +3 -3
  2. package/dist/actions.d.ts +6 -44
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +26 -308
  5. package/dist/adapter.d.ts +1 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +296 -243
  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 +289 -0
  14. package/dist/digest.d.ts +0 -1
  15. package/dist/discovery.d.ts +24 -17
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +97 -56
  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 +9 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +8 -1
  24. package/dist/map.d.ts +0 -1
  25. package/dist/model.d.ts +5 -6
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +32 -43
  28. package/dist/read.d.ts +61 -46
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +179 -245
  31. package/dist/refusal.d.ts +3 -5
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +17 -11
  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 +1 -2
  44. package/dist/site.d.ts.map +1 -1
  45. package/dist/site.js +116 -106
  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 +14 -14
  50. package/dist/stream.d.ts.map +1 -1
  51. package/dist/stream.js +288 -153
  52. package/dist/transport.d.ts +99 -26
  53. package/dist/transport.d.ts.map +1 -1
  54. package/dist/transport.js +55 -9
  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 +1 -1
  62. package/dist/version.d.ts.map +1 -1
  63. package/dist/version.js +1 -1
  64. package/dist/write.d.ts +19 -12
  65. package/dist/write.d.ts.map +1 -1
  66. package/dist/write.js +153 -70
  67. package/package.json +9 -5
  68. package/AGENTS.md +0 -290
  69. package/dist/gather.d.ts +0 -4
  70. package/dist/gather.d.ts.map +0 -1
  71. package/dist/gather.js +0 -45
  72. package/dist/links.d.ts +0 -20
  73. package/dist/links.d.ts.map +0 -1
  74. package/dist/links.js +0 -104
package/dist/stream.js CHANGED
@@ -1,10 +1,30 @@
1
- import { acceptedMessage } from './actions.js';
2
- import { headChange } from './read.js';
3
- import { roomVersion } from './version.js';
4
- const HELD_FRAMES_MAX = 256;
1
+ import { ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
2
+ import { acceptedMessage, changeCursor, houseHistory } from './history.js';
3
+ import { spaceSchemaTexts, streamedModels } from './model.js';
4
+ import { spaceSchemas } from './space-schema.js';
5
+ import { answered, answering, binaryFileOf, createdOf, folded, forgotten, headChange, revised, } from './read.js';
6
+ import { DECIMAL, logPosition, presented, roomVersion } from './version.js';
5
7
  function turnOperation(frame) {
6
- const { type: _type, conversation_id: _conversation, turn_id: _turn, ...operation } = frame;
7
- return structuredClone(operation);
8
+ return 'at' in frame ? { op: 'begin', at: frame.at } : structuredClone(frame.operation);
9
+ }
10
+ function listedAgent(agent) {
11
+ return {
12
+ id: agent.id,
13
+ name: agent.name,
14
+ revision: agent.revision,
15
+ environment: agent.environment,
16
+ environment_name: agent.environment_name,
17
+ environment_connected: agent.environment_connected,
18
+ launch_directory: agent.launch_directory,
19
+ cli: agent.cli,
20
+ model: agent.model,
21
+ effort: agent.effort,
22
+ mode: agent.mode,
23
+ base_instructions: agent.base_instructions,
24
+ in_telegram: agent.in_telegram,
25
+ created: agent.created,
26
+ retired_at: agent.retired_at,
27
+ };
8
28
  }
9
29
  function listedConversation(listed) {
10
30
  return {
@@ -14,34 +34,99 @@ function listedConversation(listed) {
14
34
  created: listed.created_at,
15
35
  finished: listed.finished_at,
16
36
  outcome: listed.outcome,
37
+ waiting: listed.waiting,
38
+ newest: listed.newest === null ? null : changeCursor(listed.newest),
39
+ processEnded: listed.process_ended_at,
40
+ subject: listed.subject,
17
41
  };
18
42
  }
19
43
  function position(value) {
20
- if (!/^(?:0|[1-9][0-9]*)$/.test(value))
44
+ if (!DECIMAL.test(value))
21
45
  return null;
22
46
  return BigInt(value);
23
47
  }
24
- export function houseNotifications(transport, mode) {
48
+ function* changed(tracked, entries, version, schemas) {
49
+ const answer = answering();
50
+ for (const entry of entries) {
51
+ yield ROW_WEIGHT + (entry.text?.length ?? 0);
52
+ if (entry.kind === 'folder') {
53
+ folded(answer, entry.path, entry.removed === true);
54
+ continue;
55
+ }
56
+ if (entry.path === tracked.schema)
57
+ schemas.set(entry.path, entry);
58
+ forgotten(answer, entry.path);
59
+ if (entry.space !== undefined) {
60
+ answer.removals.add(entry.path);
61
+ continue;
62
+ }
63
+ if (entry.kind === 'removed') {
64
+ answer.removals.add(entry.path);
65
+ continue;
66
+ }
67
+ const binary = binaryFileOf(entry);
68
+ if (binary === undefined)
69
+ answer.documents.set(entry.path, entry.text ?? '');
70
+ else if (binary !== null)
71
+ answer.binaryFiles.set(entry.path, binary);
72
+ if (binary === undefined && entry.facts !== undefined)
73
+ answer.facts.set(entry.path, entry.facts);
74
+ const revision = entry.revision ?? binary?.sha256;
75
+ if (revision !== undefined)
76
+ revised(answer, entry.path, revision);
77
+ const head = headChange(entry);
78
+ if (head)
79
+ answer.changes.set(entry.path, head);
80
+ const created = createdOf(entry);
81
+ if (created)
82
+ answer.created.set(entry.path, created);
83
+ }
84
+ return { kind: 'net-advancement', roomVersion: version, ...(yield* answered(answer)) };
85
+ }
86
+ async function changePage(tracked, entries, version, mode, whole) {
87
+ const schemas = new Map();
88
+ const page = await stepped(changed(tracked, entries, version, schemas));
89
+ const models = await streamedModels(schemas, tracked, mode, whole);
90
+ return models === undefined ? page : { ...page, models };
91
+ }
92
+ export function houseNotifications(transport, mode, discovering) {
25
93
  const stream = transport.stream;
26
- const lines = new Map();
27
- const locators = new Map();
94
+ const staged = new Map();
95
+ let spaces = spaceSchemas();
96
+ let socket = null;
97
+ const tracking = new Map();
98
+ const located = new Map();
28
99
  const observers = new Set();
100
+ const replaying = new Map();
29
101
  const conversationObservers = new Set();
30
102
  const modeObservers = new Set();
31
103
  let replicated = [];
104
+ let listedCursor = null;
105
+ const unanswered = [];
106
+ const heldAtZero = new Set();
32
107
  const live = new Set();
33
108
  let opening = null;
109
+ let announced = null;
34
110
  const runtime = crypto.randomUUID();
35
111
  function emit(event) {
36
- for (const observer of observers)
37
- observer(event);
112
+ for (const observer of observers) {
113
+ const held = replaying.get(observer);
114
+ if (held === undefined)
115
+ observer(event);
116
+ else
117
+ held.push(event);
118
+ }
38
119
  }
39
120
  function emitConversation(event) {
40
121
  if (event.kind === 'turn' ||
41
122
  event.kind === 'questions' ||
42
123
  event.kind === 'process' ||
43
124
  event.kind === 'commands' ||
44
- event.kind === 'options') {
125
+ event.kind === 'options' ||
126
+ event.kind === 'starting' ||
127
+ event.kind === 'state' ||
128
+ event.kind === 'link' ||
129
+ event.kind === 'deliveries') {
45
130
  live.add(event.conversation);
46
131
  }
47
132
  for (const observer of conversationObservers)
@@ -49,11 +134,34 @@ export function houseNotifications(transport, mode) {
49
134
  }
50
135
  function reopened(next) {
51
136
  opening = next;
137
+ announced = null;
138
+ socket = next;
139
+ staged.clear();
140
+ spaces = spaceSchemas();
141
+ unanswered.length = 0;
142
+ heldAtZero.clear();
52
143
  const gapped = new Set([...replicated, ...live]);
53
144
  live.clear();
54
145
  for (const conversation of gapped)
55
146
  emitConversation({ kind: 'gap', conversation });
56
147
  emit({ kind: 'opened' });
148
+ if (mode === 'site')
149
+ announce(next, null);
150
+ }
151
+ function announce(via, frame) {
152
+ void discovering.opened(frame).then((discovery) => {
153
+ if (socket !== via)
154
+ return;
155
+ if (discovery === null) {
156
+ via.close();
157
+ return;
158
+ }
159
+ announced = { kind: 'discovered', discovery };
160
+ emit(announced);
161
+ }, (failure) => {
162
+ if (socket === via)
163
+ via.close(failure);
164
+ });
57
165
  }
58
166
  function converse(frame) {
59
167
  const conversation = frame.conversation_id;
@@ -72,6 +180,7 @@ export function houseNotifications(transport, mode) {
72
180
  return;
73
181
  emitConversation({ kind: 'commands', conversation, commands: [] });
74
182
  emitConversation({ kind: 'options', conversation, options: [] });
183
+ emitConversation({ kind: 'state', conversation, state: null });
75
184
  return;
76
185
  }
77
186
  if (frame.type === 'commands') {
@@ -86,6 +195,27 @@ export function houseNotifications(transport, mode) {
86
195
  emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });
87
196
  return;
88
197
  }
198
+ if (frame.type === 'starting') {
199
+ emitConversation({ kind: 'starting', conversation, step: frame.step });
200
+ return;
201
+ }
202
+ if (frame.type === 'state') {
203
+ emitConversation({ kind: 'state', conversation, state: structuredClone(frame.state) });
204
+ return;
205
+ }
206
+ if (frame.type === 'link') {
207
+ emitConversation({ kind: 'link', conversation, connected: frame.connected });
208
+ return;
209
+ }
210
+ if (frame.type === 'deliveries') {
211
+ emitConversation({
212
+ kind: 'deliveries',
213
+ conversation,
214
+ waiting: [...frame.waiting],
215
+ unknown: [...frame.unknown],
216
+ });
217
+ return;
218
+ }
89
219
  if (frame.type === 'interactions') {
90
220
  emitConversation({
91
221
  kind: 'questions',
@@ -99,18 +229,33 @@ export function houseNotifications(transport, mode) {
99
229
  return;
100
230
  emitConversation({ kind: 'accepted-message', conversation, message });
101
231
  }
102
- function announce(authority, at) {
103
- const version = roomVersion(at);
104
- for (const locator of locators.get(authority) ?? []) {
105
- emit({ kind: 'room-version', locator, roomVersion: version });
232
+ function stage(frame, via) {
233
+ const entries = spaceSchemaTexts(frame.entries, spaces);
234
+ const held = staged.get(frame.carry);
235
+ if (frame.index !== (held?.parts ?? 0)) {
236
+ staged.delete(frame.carry);
237
+ return;
238
+ }
239
+ if (held === undefined) {
240
+ for (const [carry, other] of staged) {
241
+ if (other.authority === frame.authority)
242
+ staged.delete(carry);
243
+ }
106
244
  }
245
+ const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
246
+ next.entries.push(...entries);
247
+ next.parts += 1;
248
+ staged.set(frame.carry, next);
249
+ via?.received(frame.authority, frame.carry, frame.index);
107
250
  }
108
- function interrupt(authority) {
109
- const line = lines.get(authority);
110
- if (line !== undefined)
111
- lines.set(authority, { ...line, frames: [] });
251
+ function carried(frame) {
252
+ const held = staged.get(frame.carry);
253
+ staged.delete(frame.carry);
254
+ if ((held?.parts ?? 0) !== frame.parts)
255
+ return;
256
+ publish(frame, held?.entries ?? []);
112
257
  }
113
- function receive(frame) {
258
+ function handle(frame, via) {
114
259
  if (frame.type === 'signal') {
115
260
  const mode = frame.service_mode;
116
261
  if (mode !== 'open' && mode !== 'write-halted')
@@ -120,20 +265,44 @@ export function houseNotifications(transport, mode) {
120
265
  return;
121
266
  }
122
267
  if (frame.type === 'opening') {
268
+ if (via !== null && mode === 'credential')
269
+ announce(via, frame);
270
+ return;
271
+ }
272
+ if (frame.type === 'caught_up') {
273
+ const expired = frame.expired.flatMap((authority) => tracking.get(authority) ?? []);
274
+ discovering.expired?.(expired);
123
275
  emit({
124
- kind: 'opening',
125
- expired: frame.expired.flatMap((authority) => locators.get(authority) ?? []),
276
+ kind: 'caught-up',
277
+ expired: [...expired.map(({ locator }) => locator), ...(unanswered.shift() ?? [])],
126
278
  });
127
279
  return;
128
280
  }
281
+ if (frame.type === 'authority_changed') {
282
+ const change = discovering.changed(frame);
283
+ if (change !== null)
284
+ emit(change);
285
+ return;
286
+ }
129
287
  if (frame.type === 'conversations') {
130
- emitConversation({ kind: 'list', entries: frame.conversations.map(listedConversation) });
288
+ emitConversation({
289
+ kind: 'list',
290
+ agents: frame.agents.map(listedAgent),
291
+ entries: frame.conversations.map(listedConversation),
292
+ whole: frame.whole,
293
+ more: frame.more,
294
+ cursor: frame.cursor,
295
+ });
131
296
  return;
132
297
  }
133
298
  if (frame.type === 'conversation') {
134
299
  emitConversation({ kind: 'listed', entry: listedConversation(frame.conversation) });
135
300
  return;
136
301
  }
302
+ if (frame.type === 'agent') {
303
+ emitConversation({ kind: 'agent', agent: listedAgent(frame.agent) });
304
+ return;
305
+ }
137
306
  if (frame.type === 'conversation_deleted') {
138
307
  emitConversation({ kind: 'unlisted', conversation: frame.conversation_id });
139
308
  return;
@@ -142,40 +311,50 @@ export function houseNotifications(transport, mode) {
142
311
  frame.type === 'process' ||
143
312
  frame.type === 'commands' ||
144
313
  frame.type === 'options' ||
314
+ frame.type === 'starting' ||
315
+ frame.type === 'state' ||
316
+ frame.type === 'link' ||
317
+ frame.type === 'deliveries' ||
145
318
  frame.type === 'interactions' ||
146
319
  frame.type === 'message') {
147
320
  converse(frame);
148
321
  return;
149
322
  }
150
- if (frame.type !== 'entries')
151
- return;
323
+ if (frame.type === 'part')
324
+ stage(frame, via);
325
+ else if (frame.type === 'carried')
326
+ carried(frame);
327
+ }
328
+ function publish(frame, entries) {
152
329
  const at = position(frame.position);
153
330
  const after = position(frame.after);
154
- if (at === null || after === null || after >= at) {
155
- interrupt(frame.authority);
331
+ if (at === null || after === null || after >= at)
156
332
  return;
333
+ const from = after === 0n && !heldAtZero.has(frame.authority)
334
+ ? null
335
+ : roomVersion({ position: frame.after, logEpoch: frame.log_epoch });
336
+ const version = roomVersion({ position: frame.position, logEpoch: frame.log_epoch });
337
+ for (const tracked of tracking.get(frame.authority) ?? []) {
338
+ emit({
339
+ kind: 'room-change',
340
+ locator: tracked.locator,
341
+ from,
342
+ roomVersion: version,
343
+ read: () => changePage(tracked, entries, version, mode, from === null),
344
+ });
157
345
  }
158
- const line = lines.get(frame.authority);
159
- if (line?.logEpoch === frame.log_epoch) {
160
- if (line.held !== null && at <= line.held)
161
- return;
162
- const last = line.frames.at(-1);
163
- if (last !== undefined && at <= last.position)
164
- return;
165
- const held = { after, position: at, entries: frame.entries };
166
- const next = last !== undefined && after <= last.position ? [...line.frames, held] : [held];
167
- lines.set(frame.authority, { ...line, frames: next.length > HELD_FRAMES_MAX ? [] : next });
168
- }
169
- else {
170
- interrupt(frame.authority);
171
- }
172
- announce(frame.authority, { position: frame.position, logEpoch: frame.log_epoch });
173
346
  }
174
- stream.observe(receive);
347
+ stream.observe((frame) => handle(frame, socket));
175
348
  stream.opened(reopened);
176
- stream.closed((revoked) => {
349
+ stream.closed(({ revoked, lost, authorityChanged }) => {
177
350
  opening = null;
178
- emit({ kind: 'closed', revoked });
351
+ announced = null;
352
+ socket = null;
353
+ staged.clear();
354
+ spaces = spaceSchemas();
355
+ unanswered.length = 0;
356
+ heldAtZero.clear();
357
+ emit({ kind: 'closed', revoked, lost, authorityChanged });
179
358
  });
180
359
  return {
181
360
  runtime,
@@ -191,19 +370,29 @@ export function houseNotifications(transport, mode) {
191
370
  replicate(next) {
192
371
  replicated = [...next];
193
372
  },
373
+ hold(cursor) {
374
+ listedCursor = cursor;
375
+ },
194
376
  observe(notify) {
195
377
  conversationObservers.add(notify);
196
378
  return () => {
197
379
  conversationObservers.delete(notify);
198
380
  };
199
381
  },
382
+ ...(mode === 'credential' ? { history: (request) => houseHistory(transport, request) } : {}),
200
383
  },
201
384
  observe(notify) {
202
385
  observers.add(notify);
203
386
  if (opening !== null) {
387
+ const replayed = [{ kind: 'opened' }];
388
+ if (announced !== null)
389
+ replayed.push(announced);
390
+ replaying.set(notify, replayed);
204
391
  queueMicrotask(() => {
205
- if (observers.has(notify))
206
- notify({ kind: 'opened' });
392
+ replaying.delete(notify);
393
+ for (const event of replayed)
394
+ if (observers.has(notify))
395
+ notify(event);
207
396
  });
208
397
  }
209
398
  return () => {
@@ -211,117 +400,63 @@ export function houseNotifications(transport, mode) {
211
400
  };
212
401
  },
213
402
  send(rooms) {
214
- for (const room of rooms) {
215
- const line = lines.get(room.authority);
216
- const held = position(room.position);
217
- if (line === undefined || held === null || line.logEpoch !== room.log_epoch)
218
- continue;
219
- lines.set(room.authority, { ...line, frames: [], held });
220
- }
221
- const current = opening;
222
- opening = null;
223
- current?.hold(rooms, runtime);
224
- },
225
- reopen() {
226
- const current = opening;
227
403
  opening = null;
228
- current?.close();
404
+ announced = null;
405
+ if (socket === null)
406
+ return;
407
+ const named = rooms.flatMap((room) => {
408
+ const entry = located.get(room.locator);
409
+ const at = room.roomVersion === null ? null : logPosition(room.roomVersion);
410
+ return entry === undefined || at === null ? [] : [{ entry, at }];
411
+ });
412
+ const unheld = rooms.flatMap((room) => {
413
+ const entry = located.get(room.locator);
414
+ return entry === undefined || room.roomVersion !== null ? [] : [entry];
415
+ });
416
+ for (const { entry, at } of named) {
417
+ if (at.position === '0')
418
+ heldAtZero.add(entry.authority);
419
+ else
420
+ heldAtZero.delete(entry.authority);
421
+ }
422
+ for (const entry of unheld)
423
+ heldAtZero.delete(entry.authority);
424
+ const site = mode === 'site';
425
+ unanswered.push(site ? unheld.map((entry) => entry.locator) : []);
426
+ socket.hold([
427
+ ...named.map(({ entry, at }) => presented(entry.authority, at)),
428
+ ...(site ? [] : unheld).map((entry) => presented(entry.authority, { position: '0', logEpoch: entry.logEpoch })),
429
+ ], runtime, listedCursor);
430
+ if (site)
431
+ return;
432
+ const made = unheld.filter((entry) => entry.position === '0');
433
+ queueMicrotask(() => {
434
+ for (const entry of made) {
435
+ const version = roomVersion(entry);
436
+ emit({
437
+ kind: 'room-change',
438
+ locator: entry.locator,
439
+ from: null,
440
+ roomVersion: version,
441
+ read: () => changePage(entry, [], version, mode, true),
442
+ });
443
+ }
444
+ });
229
445
  },
230
446
  track(entries) {
231
- locators.clear();
447
+ tracking.clear();
448
+ located.clear();
232
449
  for (const entry of entries) {
233
- locators.set(entry.authority, [...(locators.get(entry.authority) ?? []), entry.locator]);
234
- if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {
235
- lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [], held: null });
236
- }
450
+ tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
237
451
  }
238
- for (const authority of lines.keys()) {
239
- if (!locators.has(authority))
240
- lines.delete(authority);
452
+ for (const held of tracking.values()) {
453
+ for (const entry of held)
454
+ located.set(entry.locator, entry);
241
455
  }
242
- },
243
- reach(authority, at) {
244
- const line = lines.get(authority);
245
- const held = position(at.position);
246
- if (line === undefined || held === null || line.logEpoch !== at.logEpoch)
247
- return;
248
- if (line.held !== null && held <= line.held)
249
- return;
250
- lines.set(authority, {
251
- ...line,
252
- frames: line.frames.filter((frame) => frame.position > held),
253
- held,
254
- });
255
- },
256
- advance(tracked, from, holds) {
257
- const line = lines.get(tracked.authority);
258
- const start = position(from.position);
259
- if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
260
- return null;
261
- const pending = line.frames.filter((frame) => frame.position > start);
262
- const first = pending[0];
263
- if (first === undefined || first.after > start)
264
- return null;
265
- const documents = {};
266
- const revisions = {};
267
- const changes = {};
268
- const removals = [];
269
- const applied = [];
270
- const schemas = new Map();
271
- const forget = (path) => {
272
- delete documents[path];
273
- delete revisions[path];
274
- delete changes[path];
275
- const removed = removals.indexOf(path);
276
- if (removed !== -1)
277
- removals.splice(removed, 1);
278
- };
279
- for (const frame of pending) {
280
- for (const entry of frame.entries) {
281
- if (entry.kind === 'edited' &&
282
- entry.revision !== undefined &&
283
- holds?.(entry.path, entry.revision) === true) {
284
- forget(entry.path);
285
- continue;
286
- }
287
- applied.push(entry);
288
- if (tracked.schemas.includes(entry.path))
289
- schemas.set(entry.path, entry);
290
- if (entry.kind === 'removed') {
291
- forget(entry.path);
292
- removals.push(entry.path);
293
- continue;
294
- }
295
- if (entry.text === undefined)
296
- return null;
297
- if (mode === 'credential' && entry.revision === undefined)
298
- return null;
299
- const head = headChange(entry);
300
- if (head === null)
301
- return null;
302
- forget(entry.path);
303
- documents[entry.path] = entry.text;
304
- if (entry.revision !== undefined)
305
- revisions[entry.path] = entry.revision;
306
- if (head !== undefined)
307
- changes[entry.path] = head;
308
- }
456
+ for (const [carry, held] of staged) {
457
+ if (!tracking.has(held.authority))
458
+ staged.delete(carry);
309
459
  }
310
- const last = pending.at(-1);
311
- lines.set(tracked.authority, { ...line, frames: pending, held: last.position });
312
- return {
313
- page: {
314
- kind: 'net-advancement',
315
- roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),
316
- documents,
317
- revisions,
318
- changes,
319
- binaryTargets: [],
320
- removals: removals.sort(),
321
- },
322
- entries: applied,
323
- schemas,
324
- };
325
460
  },
326
461
  };
327
462
  }