@agentshouse/mdruntime-adapter 0.1.0-cea44707d3919 → 0.1.0-ceb5de2c525b2
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 +8 -6
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +48 -320
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +304 -228
- package/dist/authored-path.d.ts +66 -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 +45 -18
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +254 -65
- 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 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- 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 +31 -44
- package/dist/read.d.ts +54 -48
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +209 -267
- package/dist/refusal.d.ts +8 -10
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +31 -18
- package/dist/renamed.d.ts +10 -0
- package/dist/renamed.d.ts.map +1 -0
- package/dist/renamed.js +29 -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 +152 -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 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +279 -154
- package/dist/transport.d.ts +127 -31
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +91 -9
- 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 +177 -71
- package/package.json +11 -7
- package/AGENTS.md +0 -253
- 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,30 @@
|
|
|
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
|
+
created: agent.created,
|
|
26
|
+
retired_at: agent.retired_at,
|
|
27
|
+
};
|
|
8
28
|
}
|
|
9
29
|
function listedConversation(listed) {
|
|
10
30
|
return {
|
|
@@ -12,36 +32,92 @@ 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,
|
|
41
|
+
model: listed.model,
|
|
42
|
+
effort: listed.effort,
|
|
17
43
|
};
|
|
18
44
|
}
|
|
19
45
|
function position(value) {
|
|
20
|
-
if (
|
|
46
|
+
if (!DECIMAL.test(value))
|
|
21
47
|
return null;
|
|
22
48
|
return BigInt(value);
|
|
23
49
|
}
|
|
24
|
-
|
|
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) {
|
|
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) {
|
|
25
85
|
const stream = transport.stream;
|
|
26
|
-
const
|
|
27
|
-
|
|
86
|
+
const staged = new Map();
|
|
87
|
+
let spaces = spaceSchemas();
|
|
88
|
+
let socket = null;
|
|
89
|
+
const tracking = new Map();
|
|
90
|
+
const located = new Map();
|
|
28
91
|
const observers = new Set();
|
|
92
|
+
const replaying = new Map();
|
|
29
93
|
const conversationObservers = new Set();
|
|
30
94
|
const modeObservers = new Set();
|
|
31
95
|
let replicated = [];
|
|
96
|
+
let listedCursor = null;
|
|
97
|
+
const unanswered = [];
|
|
98
|
+
const heldAtZero = new Set();
|
|
32
99
|
const live = new Set();
|
|
33
100
|
let opening = null;
|
|
101
|
+
let announced = null;
|
|
34
102
|
const runtime = crypto.randomUUID();
|
|
35
103
|
function emit(event) {
|
|
36
|
-
for (const observer of observers)
|
|
37
|
-
observer
|
|
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
|
+
}
|
|
38
111
|
}
|
|
39
112
|
function emitConversation(event) {
|
|
40
113
|
if (event.kind === 'turn' ||
|
|
41
114
|
event.kind === 'questions' ||
|
|
42
115
|
event.kind === 'process' ||
|
|
43
116
|
event.kind === 'commands' ||
|
|
44
|
-
event.kind === 'options'
|
|
117
|
+
event.kind === 'options' ||
|
|
118
|
+
event.kind === 'starting' ||
|
|
119
|
+
event.kind === 'state' ||
|
|
120
|
+
event.kind === 'deliveries') {
|
|
45
121
|
live.add(event.conversation);
|
|
46
122
|
}
|
|
47
123
|
for (const observer of conversationObservers)
|
|
@@ -49,11 +125,34 @@ export function houseNotifications(transport, mode) {
|
|
|
49
125
|
}
|
|
50
126
|
function reopened(next) {
|
|
51
127
|
opening = next;
|
|
128
|
+
announced = null;
|
|
129
|
+
socket = next;
|
|
130
|
+
staged.clear();
|
|
131
|
+
spaces = spaceSchemas();
|
|
132
|
+
unanswered.length = 0;
|
|
133
|
+
heldAtZero.clear();
|
|
52
134
|
const gapped = new Set([...replicated, ...live]);
|
|
53
135
|
live.clear();
|
|
54
136
|
for (const conversation of gapped)
|
|
55
137
|
emitConversation({ kind: 'gap', conversation });
|
|
56
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
|
+
});
|
|
57
156
|
}
|
|
58
157
|
function converse(frame) {
|
|
59
158
|
const conversation = frame.conversation_id;
|
|
@@ -72,6 +171,7 @@ export function houseNotifications(transport, mode) {
|
|
|
72
171
|
return;
|
|
73
172
|
emitConversation({ kind: 'commands', conversation, commands: [] });
|
|
74
173
|
emitConversation({ kind: 'options', conversation, options: [] });
|
|
174
|
+
emitConversation({ kind: 'state', conversation, state: null });
|
|
75
175
|
return;
|
|
76
176
|
}
|
|
77
177
|
if (frame.type === 'commands') {
|
|
@@ -86,6 +186,23 @@ export function houseNotifications(transport, mode) {
|
|
|
86
186
|
emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });
|
|
87
187
|
return;
|
|
88
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
|
+
}
|
|
89
206
|
if (frame.type === 'interactions') {
|
|
90
207
|
emitConversation({
|
|
91
208
|
kind: 'questions',
|
|
@@ -99,18 +216,33 @@ export function houseNotifications(transport, mode) {
|
|
|
99
216
|
return;
|
|
100
217
|
emitConversation({ kind: 'accepted-message', conversation, message });
|
|
101
218
|
}
|
|
102
|
-
function
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
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);
|
|
230
|
+
}
|
|
106
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);
|
|
107
237
|
}
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
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 ?? []);
|
|
112
244
|
}
|
|
113
|
-
function
|
|
245
|
+
function handle(frame, via) {
|
|
114
246
|
if (frame.type === 'signal') {
|
|
115
247
|
const mode = frame.service_mode;
|
|
116
248
|
if (mode !== 'open' && mode !== 'write-halted')
|
|
@@ -120,20 +252,48 @@ export function houseNotifications(transport, mode) {
|
|
|
120
252
|
return;
|
|
121
253
|
}
|
|
122
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);
|
|
123
262
|
emit({
|
|
124
|
-
kind: '
|
|
125
|
-
expired:
|
|
263
|
+
kind: 'caught-up',
|
|
264
|
+
expired: [...expired.map(({ locator }) => locator), ...(unanswered.shift() ?? [])],
|
|
126
265
|
});
|
|
127
266
|
return;
|
|
128
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
|
+
}
|
|
129
278
|
if (frame.type === 'conversations') {
|
|
130
|
-
emitConversation({
|
|
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
|
+
});
|
|
131
287
|
return;
|
|
132
288
|
}
|
|
133
289
|
if (frame.type === 'conversation') {
|
|
134
290
|
emitConversation({ kind: 'listed', entry: listedConversation(frame.conversation) });
|
|
135
291
|
return;
|
|
136
292
|
}
|
|
293
|
+
if (frame.type === 'agent') {
|
|
294
|
+
emitConversation({ kind: 'agent', agent: listedAgent(frame.agent) });
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
137
297
|
if (frame.type === 'conversation_deleted') {
|
|
138
298
|
emitConversation({ kind: 'unlisted', conversation: frame.conversation_id });
|
|
139
299
|
return;
|
|
@@ -142,40 +302,49 @@ export function houseNotifications(transport, mode) {
|
|
|
142
302
|
frame.type === 'process' ||
|
|
143
303
|
frame.type === 'commands' ||
|
|
144
304
|
frame.type === 'options' ||
|
|
305
|
+
frame.type === 'starting' ||
|
|
306
|
+
frame.type === 'state' ||
|
|
307
|
+
frame.type === 'deliveries' ||
|
|
145
308
|
frame.type === 'interactions' ||
|
|
146
309
|
frame.type === 'message') {
|
|
147
310
|
converse(frame);
|
|
148
311
|
return;
|
|
149
312
|
}
|
|
150
|
-
if (frame.type
|
|
151
|
-
|
|
313
|
+
if (frame.type === 'part')
|
|
314
|
+
stage(frame, via);
|
|
315
|
+
else if (frame.type === 'carried')
|
|
316
|
+
carried(frame);
|
|
317
|
+
}
|
|
318
|
+
function publish(frame, entries) {
|
|
152
319
|
const at = position(frame.position);
|
|
153
320
|
const after = position(frame.after);
|
|
154
|
-
if (at === null || after === null || after >= at)
|
|
155
|
-
interrupt(frame.authority);
|
|
321
|
+
if (at === null || after === null || after >= at)
|
|
156
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
|
+
});
|
|
157
335
|
}
|
|
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
336
|
}
|
|
174
|
-
stream.observe(
|
|
337
|
+
stream.observe((frame) => handle(frame, socket));
|
|
175
338
|
stream.opened(reopened);
|
|
176
|
-
stream.closed((revoked) => {
|
|
339
|
+
stream.closed(({ revoked, lost, authorityChanged }) => {
|
|
177
340
|
opening = null;
|
|
178
|
-
|
|
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 });
|
|
179
348
|
});
|
|
180
349
|
return {
|
|
181
350
|
runtime,
|
|
@@ -191,19 +360,29 @@ export function houseNotifications(transport, mode) {
|
|
|
191
360
|
replicate(next) {
|
|
192
361
|
replicated = [...next];
|
|
193
362
|
},
|
|
363
|
+
hold(cursor) {
|
|
364
|
+
listedCursor = cursor;
|
|
365
|
+
},
|
|
194
366
|
observe(notify) {
|
|
195
367
|
conversationObservers.add(notify);
|
|
196
368
|
return () => {
|
|
197
369
|
conversationObservers.delete(notify);
|
|
198
370
|
};
|
|
199
371
|
},
|
|
372
|
+
...(mode === 'credential' ? { history: (request) => houseHistory(transport, request) } : {}),
|
|
200
373
|
},
|
|
201
374
|
observe(notify) {
|
|
202
375
|
observers.add(notify);
|
|
203
376
|
if (opening !== null) {
|
|
377
|
+
const replayed = [{ kind: 'opened' }];
|
|
378
|
+
if (announced !== null)
|
|
379
|
+
replayed.push(announced);
|
|
380
|
+
replaying.set(notify, replayed);
|
|
204
381
|
queueMicrotask(() => {
|
|
205
|
-
|
|
206
|
-
|
|
382
|
+
replaying.delete(notify);
|
|
383
|
+
for (const event of replayed)
|
|
384
|
+
if (observers.has(notify))
|
|
385
|
+
notify(event);
|
|
207
386
|
});
|
|
208
387
|
}
|
|
209
388
|
return () => {
|
|
@@ -211,117 +390,63 @@ export function houseNotifications(transport, mode) {
|
|
|
211
390
|
};
|
|
212
391
|
},
|
|
213
392
|
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
393
|
opening = null;
|
|
228
|
-
|
|
394
|
+
announced = null;
|
|
395
|
+
if (socket === null)
|
|
396
|
+
return;
|
|
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
|
+
});
|
|
433
|
+
}
|
|
434
|
+
});
|
|
229
435
|
},
|
|
230
436
|
track(entries) {
|
|
231
|
-
|
|
437
|
+
tracking.clear();
|
|
438
|
+
located.clear();
|
|
232
439
|
for (const entry of entries) {
|
|
233
|
-
|
|
234
|
-
if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {
|
|
235
|
-
lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [], held: null });
|
|
236
|
-
}
|
|
440
|
+
tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
|
|
237
441
|
}
|
|
238
|
-
for (const
|
|
239
|
-
|
|
240
|
-
|
|
442
|
+
for (const held of tracking.values()) {
|
|
443
|
+
for (const entry of held)
|
|
444
|
+
located.set(entry.locator, entry);
|
|
241
445
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const held = position(at.position);
|
|
246
|
-
if (line === undefined || held === null || line.logEpoch !== at.logEpoch)
|
|
247
|
-
return;
|
|
248
|
-
if (line.held !== null && held <= line.held)
|
|
249
|
-
return;
|
|
250
|
-
lines.set(authority, {
|
|
251
|
-
...line,
|
|
252
|
-
frames: line.frames.filter((frame) => frame.position > held),
|
|
253
|
-
held,
|
|
254
|
-
});
|
|
255
|
-
},
|
|
256
|
-
advance(tracked, from, holds) {
|
|
257
|
-
const line = lines.get(tracked.authority);
|
|
258
|
-
const start = position(from.position);
|
|
259
|
-
if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
|
|
260
|
-
return null;
|
|
261
|
-
const pending = line.frames.filter((frame) => frame.position > start);
|
|
262
|
-
const first = pending[0];
|
|
263
|
-
if (first === undefined || first.after > start)
|
|
264
|
-
return null;
|
|
265
|
-
const documents = {};
|
|
266
|
-
const revisions = {};
|
|
267
|
-
const changes = {};
|
|
268
|
-
const removals = [];
|
|
269
|
-
const applied = [];
|
|
270
|
-
const schemas = new Map();
|
|
271
|
-
const forget = (path) => {
|
|
272
|
-
delete documents[path];
|
|
273
|
-
delete revisions[path];
|
|
274
|
-
delete changes[path];
|
|
275
|
-
const removed = removals.indexOf(path);
|
|
276
|
-
if (removed !== -1)
|
|
277
|
-
removals.splice(removed, 1);
|
|
278
|
-
};
|
|
279
|
-
for (const frame of pending) {
|
|
280
|
-
for (const entry of frame.entries) {
|
|
281
|
-
if (entry.kind === 'edited' &&
|
|
282
|
-
entry.revision !== undefined &&
|
|
283
|
-
holds?.(entry.path, entry.revision) === true) {
|
|
284
|
-
forget(entry.path);
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
applied.push(entry);
|
|
288
|
-
if (tracked.schemas.includes(entry.path))
|
|
289
|
-
schemas.set(entry.path, entry);
|
|
290
|
-
if (entry.kind === 'removed') {
|
|
291
|
-
forget(entry.path);
|
|
292
|
-
removals.push(entry.path);
|
|
293
|
-
continue;
|
|
294
|
-
}
|
|
295
|
-
if (entry.text === undefined)
|
|
296
|
-
return null;
|
|
297
|
-
if (mode === 'credential' && entry.revision === undefined)
|
|
298
|
-
return null;
|
|
299
|
-
const head = headChange(entry);
|
|
300
|
-
if (head === null)
|
|
301
|
-
return null;
|
|
302
|
-
forget(entry.path);
|
|
303
|
-
documents[entry.path] = entry.text;
|
|
304
|
-
if (entry.revision !== undefined)
|
|
305
|
-
revisions[entry.path] = entry.revision;
|
|
306
|
-
if (head !== undefined)
|
|
307
|
-
changes[entry.path] = head;
|
|
308
|
-
}
|
|
446
|
+
for (const [carry, held] of staged) {
|
|
447
|
+
if (!tracking.has(held.authority))
|
|
448
|
+
staged.delete(carry);
|
|
309
449
|
}
|
|
310
|
-
const last = pending.at(-1);
|
|
311
|
-
lines.set(tracked.authority, { ...line, frames: pending, held: last.position });
|
|
312
|
-
return {
|
|
313
|
-
page: {
|
|
314
|
-
kind: 'net-advancement',
|
|
315
|
-
roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),
|
|
316
|
-
documents,
|
|
317
|
-
revisions,
|
|
318
|
-
changes,
|
|
319
|
-
binaryTargets: [],
|
|
320
|
-
removals: removals.sort(),
|
|
321
|
-
},
|
|
322
|
-
entries: applied,
|
|
323
|
-
schemas,
|
|
324
|
-
};
|
|
325
450
|
},
|
|
326
451
|
};
|
|
327
452
|
}
|