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