@agentshouse/mdruntime-adapter 0.1.0-c8f4fd4801441 → 0.1.0-c9107451c8ea3
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 +2 -2
- package/dist/actions.d.ts +4 -43
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +8 -333
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +243 -277
- package/dist/app-reference.d.ts +2 -0
- package/dist/app-reference.d.ts.map +1 -0
- package/dist/app-reference.js +2 -0
- package/dist/chunks.d.ts +38 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +247 -0
- package/dist/crockford.d.ts +4 -0
- package/dist/crockford.d.ts.map +1 -0
- package/dist/crockford.js +3 -0
- package/dist/discovery.d.ts +23 -14
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +94 -53
- package/dist/history.d.ts +12 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +92 -0
- package/dist/house-model.d.ts +672 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +377 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/model.d.ts +5 -5
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +33 -43
- package/dist/read.d.ts +52 -43
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +139 -232
- package/dist/refusal.d.ts +0 -3
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +2 -6
- package/dist/room-types.d.ts +7 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +123 -0
- package/dist/search.d.ts +5 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +107 -130
- package/dist/space-schema.d.ts +7 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +18 -0
- package/dist/stream.d.ts +15 -13
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +272 -159
- package/dist/transport.d.ts +80 -25
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +54 -11
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/write.d.ts +18 -2
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +105 -71
- package/package.json +8 -5
- package/AGENTS.md +0 -318
- 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,47 +1,122 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { acceptedMessage, cursorPosition, houseHistory } from './history.js';
|
|
3
|
+
import { keptSpaceSchemas, streamedModels } from './model.js';
|
|
4
|
+
import { answered, answering, binaryFileOf, folded, forgotten, headChange, revised, } from './read.js';
|
|
5
|
+
import { houseDoorRoute, } from './transport.js';
|
|
6
|
+
import { DECIMAL, logPosition, presented, roomVersion } from './version.js';
|
|
5
7
|
function turnOperation(frame) {
|
|
6
8
|
const { type: _type, conversation_id: _conversation, turn_id: _turn, ...operation } = frame;
|
|
7
9
|
return structuredClone(operation);
|
|
8
10
|
}
|
|
11
|
+
async function houseAgents(transport) {
|
|
12
|
+
const answer = await transport.door(houseDoorRoute('agents/read'), {});
|
|
13
|
+
const agents = answer.status === 200 ? answer.body?.agents : null;
|
|
14
|
+
if (!Array.isArray(agents))
|
|
15
|
+
return null;
|
|
16
|
+
return agents.flatMap((one) => {
|
|
17
|
+
const { id, name, retired_at: retired } = (one ?? {});
|
|
18
|
+
return typeof id === 'string' && typeof name === 'string'
|
|
19
|
+
? [{ agent: id, name, retired: retired !== null && retired !== undefined }]
|
|
20
|
+
: [];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
9
23
|
function listedConversation(listed) {
|
|
10
24
|
return {
|
|
11
25
|
conversation: listed.conversation_id,
|
|
12
26
|
agent: listed.agent_id,
|
|
27
|
+
agentName: listed.agent_name,
|
|
28
|
+
agentRetired: listed.agent_retired,
|
|
13
29
|
name: listed.name,
|
|
14
30
|
created: listed.created_at,
|
|
15
31
|
finished: listed.finished_at,
|
|
16
32
|
outcome: listed.outcome,
|
|
33
|
+
waiting: listed.waiting,
|
|
34
|
+
newest: listed.newest === null ? null : cursorPosition(listed.newest),
|
|
35
|
+
processEnded: listed.process_ended_at,
|
|
17
36
|
};
|
|
18
37
|
}
|
|
19
38
|
function position(value) {
|
|
20
|
-
if (
|
|
39
|
+
if (!DECIMAL.test(value))
|
|
21
40
|
return null;
|
|
22
41
|
return BigInt(value);
|
|
23
42
|
}
|
|
24
|
-
|
|
43
|
+
function* changed(tracked, entries, version, schemas) {
|
|
44
|
+
const answer = answering();
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
yield ROW_WEIGHT + (entry.text?.length ?? 0);
|
|
47
|
+
if (entry.kind === 'folder') {
|
|
48
|
+
folded(answer, entry.path, entry.removed === true);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (entry.path === tracked.schema)
|
|
52
|
+
schemas.set(entry.path, entry);
|
|
53
|
+
forgotten(answer, entry.path);
|
|
54
|
+
if (entry.space !== undefined) {
|
|
55
|
+
answer.removals.add(entry.path);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (entry.kind === 'removed') {
|
|
59
|
+
answer.removals.add(entry.path);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const binary = binaryFileOf(entry);
|
|
63
|
+
if (binary === undefined)
|
|
64
|
+
answer.documents.set(entry.path, entry.text ?? '');
|
|
65
|
+
else if (binary !== null)
|
|
66
|
+
answer.binaryFiles.set(entry.path, binary);
|
|
67
|
+
if (binary === undefined && entry.facts !== undefined)
|
|
68
|
+
answer.facts.set(entry.path, entry.facts);
|
|
69
|
+
const revision = entry.revision ?? binary?.sha256;
|
|
70
|
+
if (revision !== undefined)
|
|
71
|
+
revised(answer, entry.path, revision);
|
|
72
|
+
const head = headChange(entry);
|
|
73
|
+
if (head)
|
|
74
|
+
answer.changes.set(entry.path, head);
|
|
75
|
+
}
|
|
76
|
+
return { kind: 'net-advancement', roomVersion: version, ...(yield* answered(answer)) };
|
|
77
|
+
}
|
|
78
|
+
async function changePage(tracked, entries, version, mode, spaces, whole) {
|
|
79
|
+
const schemas = new Map();
|
|
80
|
+
const page = await stepped(changed(tracked, entries, version, schemas));
|
|
81
|
+
const models = await streamedModels(schemas, tracked, mode, spaces, whole);
|
|
82
|
+
return models === undefined ? page : { ...page, models };
|
|
83
|
+
}
|
|
84
|
+
export function houseNotifications(transport, mode, discovering, spaces) {
|
|
25
85
|
const stream = transport.stream;
|
|
26
|
-
const
|
|
27
|
-
|
|
86
|
+
const staged = new Map();
|
|
87
|
+
let socket = null;
|
|
88
|
+
const tracking = 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
|
|
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 === 'subagents' ||
|
|
118
|
+
event.kind === 'link' ||
|
|
119
|
+
event.kind === 'deliveries') {
|
|
45
120
|
live.add(event.conversation);
|
|
46
121
|
}
|
|
47
122
|
for (const observer of conversationObservers)
|
|
@@ -49,11 +124,33 @@ export function houseNotifications(transport, mode) {
|
|
|
49
124
|
}
|
|
50
125
|
function reopened(next) {
|
|
51
126
|
opening = next;
|
|
127
|
+
announced = null;
|
|
128
|
+
socket = next;
|
|
129
|
+
staged.clear();
|
|
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
|
+
}, () => {
|
|
151
|
+
if (socket === via)
|
|
152
|
+
via.close();
|
|
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: 'subagents', conversation, subagents: [] });
|
|
75
173
|
return;
|
|
76
174
|
}
|
|
77
175
|
if (frame.type === 'commands') {
|
|
@@ -86,6 +184,26 @@ 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 === 'subagents') {
|
|
192
|
+
emitConversation({
|
|
193
|
+
kind: 'subagents',
|
|
194
|
+
conversation,
|
|
195
|
+
subagents: structuredClone(frame.subagents),
|
|
196
|
+
});
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (frame.type === 'link') {
|
|
200
|
+
emitConversation({ kind: 'link', conversation, connected: frame.connected });
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (frame.type === 'deliveries') {
|
|
204
|
+
emitConversation({ kind: 'deliveries', conversation, unknown: [...frame.unknown] });
|
|
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 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
|
+
keptSpaceSchemas(frame.entries, spaces);
|
|
234
|
+
next.entries.push(...frame.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,14 +253,35 @@ 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
|
+
discovering.expired?.(frame.expired);
|
|
123
262
|
emit({
|
|
124
|
-
kind: '
|
|
125
|
-
expired:
|
|
263
|
+
kind: 'caught-up',
|
|
264
|
+
expired: [
|
|
265
|
+
...frame.expired.flatMap((authority) => (tracking.get(authority) ?? []).map((tracked) => tracked.locator)),
|
|
266
|
+
...(unanswered.shift() ?? []),
|
|
267
|
+
],
|
|
126
268
|
});
|
|
127
269
|
return;
|
|
128
270
|
}
|
|
271
|
+
if (frame.type === 'authority_changed') {
|
|
272
|
+
const change = discovering.changed(frame);
|
|
273
|
+
if (change !== null)
|
|
274
|
+
emit(change);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
129
277
|
if (frame.type === 'conversations') {
|
|
130
|
-
emitConversation({
|
|
278
|
+
emitConversation({
|
|
279
|
+
kind: 'list',
|
|
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') {
|
|
@@ -142,40 +296,49 @@ export function houseNotifications(transport, mode) {
|
|
|
142
296
|
frame.type === 'process' ||
|
|
143
297
|
frame.type === 'commands' ||
|
|
144
298
|
frame.type === 'options' ||
|
|
299
|
+
frame.type === 'starting' ||
|
|
300
|
+
frame.type === 'subagents' ||
|
|
301
|
+
frame.type === 'link' ||
|
|
302
|
+
frame.type === 'deliveries' ||
|
|
145
303
|
frame.type === 'interactions' ||
|
|
146
304
|
frame.type === 'message') {
|
|
147
305
|
converse(frame);
|
|
148
306
|
return;
|
|
149
307
|
}
|
|
150
|
-
if (frame.type
|
|
151
|
-
|
|
308
|
+
if (frame.type === 'part')
|
|
309
|
+
stage(frame, via);
|
|
310
|
+
else if (frame.type === 'carried')
|
|
311
|
+
carried(frame);
|
|
312
|
+
}
|
|
313
|
+
function publish(frame, entries) {
|
|
152
314
|
const at = position(frame.position);
|
|
153
315
|
const after = position(frame.after);
|
|
154
|
-
if (at === null || after === null || after >= at)
|
|
155
|
-
interrupt(frame.authority);
|
|
316
|
+
if (at === null || after === null || after >= at)
|
|
156
317
|
return;
|
|
318
|
+
const from = after === 0n && !heldAtZero.has(frame.authority)
|
|
319
|
+
? null
|
|
320
|
+
: roomVersion({ position: frame.after, logEpoch: frame.log_epoch });
|
|
321
|
+
const version = roomVersion({ position: frame.position, logEpoch: frame.log_epoch });
|
|
322
|
+
for (const tracked of tracking.get(frame.authority) ?? []) {
|
|
323
|
+
emit({
|
|
324
|
+
kind: 'room-change',
|
|
325
|
+
locator: tracked.locator,
|
|
326
|
+
from,
|
|
327
|
+
roomVersion: version,
|
|
328
|
+
read: () => changePage(tracked, entries, version, mode, spaces, from === null),
|
|
329
|
+
});
|
|
157
330
|
}
|
|
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
331
|
}
|
|
174
|
-
stream.observe(
|
|
332
|
+
stream.observe((frame) => handle(frame, socket));
|
|
175
333
|
stream.opened(reopened);
|
|
176
|
-
stream.closed((revoked) => {
|
|
334
|
+
stream.closed(({ revoked, lost, authorityChanged }) => {
|
|
177
335
|
opening = null;
|
|
178
|
-
|
|
336
|
+
announced = null;
|
|
337
|
+
socket = null;
|
|
338
|
+
staged.clear();
|
|
339
|
+
unanswered.length = 0;
|
|
340
|
+
heldAtZero.clear();
|
|
341
|
+
emit({ kind: 'closed', revoked, lost, authorityChanged });
|
|
179
342
|
});
|
|
180
343
|
return {
|
|
181
344
|
runtime,
|
|
@@ -191,19 +354,34 @@ export function houseNotifications(transport, mode) {
|
|
|
191
354
|
replicate(next) {
|
|
192
355
|
replicated = [...next];
|
|
193
356
|
},
|
|
357
|
+
hold(cursor) {
|
|
358
|
+
listedCursor = cursor;
|
|
359
|
+
},
|
|
194
360
|
observe(notify) {
|
|
195
361
|
conversationObservers.add(notify);
|
|
196
362
|
return () => {
|
|
197
363
|
conversationObservers.delete(notify);
|
|
198
364
|
};
|
|
199
365
|
},
|
|
366
|
+
...(mode === 'credential'
|
|
367
|
+
? {
|
|
368
|
+
agents: () => houseAgents(transport),
|
|
369
|
+
history: (request) => houseHistory(transport, request),
|
|
370
|
+
}
|
|
371
|
+
: {}),
|
|
200
372
|
},
|
|
201
373
|
observe(notify) {
|
|
202
374
|
observers.add(notify);
|
|
203
375
|
if (opening !== null) {
|
|
376
|
+
const replayed = [{ kind: 'opened' }];
|
|
377
|
+
if (announced !== null)
|
|
378
|
+
replayed.push(announced);
|
|
379
|
+
replaying.set(notify, replayed);
|
|
204
380
|
queueMicrotask(() => {
|
|
205
|
-
|
|
206
|
-
|
|
381
|
+
replaying.delete(notify);
|
|
382
|
+
for (const event of replayed)
|
|
383
|
+
if (observers.has(notify))
|
|
384
|
+
notify(event);
|
|
207
385
|
});
|
|
208
386
|
}
|
|
209
387
|
return () => {
|
|
@@ -211,124 +389,59 @@ export function houseNotifications(transport, mode) {
|
|
|
211
389
|
};
|
|
212
390
|
},
|
|
213
391
|
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
392
|
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)
|
|
393
|
+
announced = null;
|
|
394
|
+
if (socket === null)
|
|
247
395
|
return;
|
|
248
|
-
|
|
396
|
+
const entries = new Map([...tracking.values()].flat().map((tracked) => [tracked.locator, tracked]));
|
|
397
|
+
const named = rooms.flatMap((room) => {
|
|
398
|
+
const entry = entries.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 = entries.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)
|
|
249
421
|
return;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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, spaces, true),
|
|
432
|
+
});
|
|
433
|
+
}
|
|
254
434
|
});
|
|
255
435
|
},
|
|
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
|
-
}
|
|
436
|
+
track(entries) {
|
|
437
|
+
tracking.clear();
|
|
438
|
+
for (const entry of entries) {
|
|
439
|
+
tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
|
|
440
|
+
}
|
|
441
|
+
for (const [carry, held] of staged) {
|
|
442
|
+
if (!tracking.has(held.authority))
|
|
443
|
+
staged.delete(carry);
|
|
316
444
|
}
|
|
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
445
|
},
|
|
333
446
|
};
|
|
334
447
|
}
|