@agentshouse/mdruntime-adapter 0.1.0-c17fae3d012d0 → 0.1.0-c18e9b633b5bc

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