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