@agentshouse/mdruntime-adapter 0.1.0-c8f4fd4801441 → 0.1.0-c910a6a99a150

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