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