@agentshouse/mdruntime-adapter 0.1.0-cf22c8563f9f4 → 0.1.0-cf24515ef4112

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