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