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