@agentshouse/mdruntime-adapter 0.1.0-cd0511bd2d033 → 0.1.0-cd1a679949dfc
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 +11 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +196 -9
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +183 -179
- 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 +27 -10
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +176 -29
- package/dist/history.d.ts +1 -7
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +22 -29
- package/dist/index.d.ts +8 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -8
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -9
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +28 -26
- package/dist/read.d.ts +17 -29
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +99 -180
- package/dist/refusal.d.ts +6 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +28 -7
- 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 +0 -1
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +5 -5
- 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 +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +81 -53
- 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 +5 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +207 -76
- package/dist/transport.d.ts +79 -31
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +54 -17
- 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 +7 -2
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +49 -6
- package/dist/version.d.ts +0 -1
- package/dist/write.d.ts +3 -10
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +90 -110
- package/package.json +4 -3
- 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/house-model.d.ts +0 -719
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -393
- 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 -125
package/dist/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,eAAe,EAEpB,KAAK,SAAS,EACd,KAAK,kBAAkB,EAEvB,KAAK,QAAQ,EAIb,KAAK,eAAe,EAGpB,KAAK,SAAS,EAEd,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAYvD,OAAO,EACL,KAAK,SAAS,EAGd,KAAK,SAAS,EAGd,KAAK,gBAAgB,EAEtB,MAAM,gBAAgB,CAAC;AAaxB,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAE/E,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC,CAAC;AAElG,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IACnE,OAAO,CAAC,KAAK,EAAE,0BAA0B,GAAG,eAAe,GAAG,IAAI,CAAC;IACnE,OAAO,CAAC,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC9D,IAAI,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,IAAI,CAAC;IACvC,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtD,aAAa,EAAE,kBAAkB,CAAC;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AA8GF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,gBAAgB,GAC5B,kBAAkB,CAuapB"}
|
package/dist/stream.js
CHANGED
|
@@ -1,38 +1,63 @@
|
|
|
1
|
+
import { parse } from '@agentshouse/mdmodel';
|
|
1
2
|
import { ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
|
-
import { acceptedMessage,
|
|
3
|
-
import { streamedModels } from './model.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { DECIMAL, roomVersion } from './version.js';
|
|
3
|
+
import { acceptedMessage, changeCursor, houseHistory } from './history.js';
|
|
4
|
+
import { spaceSchemaTexts, streamedModels } from './model.js';
|
|
5
|
+
import { spaceSchemas } from './space-schema.js';
|
|
6
|
+
import { answered, answering, documentEntry, folded, forgotten, kept, } from './read.js';
|
|
7
|
+
import { DECIMAL, logPosition, presented, roomVersion } from './version.js';
|
|
8
|
+
const CURRENT_RUN_STATES = new Set(['awaiting_approval', 'started']);
|
|
9
|
+
const NO_RUN_MARKS = { rooms: {}, sent: null };
|
|
10
|
+
function heardRun(request) {
|
|
11
|
+
const read = parse(`---\n${request.document}---\n`);
|
|
12
|
+
if (!read.ok)
|
|
13
|
+
throw new Error(`the stream carried request ${request.name} as no document`);
|
|
14
|
+
const fields = read.document.fields;
|
|
15
|
+
return {
|
|
16
|
+
room: request.room_ref,
|
|
17
|
+
name: request.name,
|
|
18
|
+
document: request.document,
|
|
19
|
+
current: CURRENT_RUN_STATES.has(fields.state),
|
|
20
|
+
starter: typeof fields.requester === 'string' ? fields.requester : null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
7
23
|
function turnOperation(frame) {
|
|
8
|
-
|
|
9
|
-
return structuredClone(operation);
|
|
24
|
+
return 'at' in frame ? { op: 'begin', at: frame.at } : structuredClone(frame.operation);
|
|
10
25
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
function listedAgent(agent) {
|
|
27
|
+
return {
|
|
28
|
+
id: agent.id,
|
|
29
|
+
name: agent.name,
|
|
30
|
+
revision: agent.revision,
|
|
31
|
+
environment: agent.environment,
|
|
32
|
+
environment_name: agent.environment_name,
|
|
33
|
+
environment_connected: agent.environment_connected,
|
|
34
|
+
launch_directory: agent.launch_directory,
|
|
35
|
+
cli: agent.cli,
|
|
36
|
+
model: agent.model,
|
|
37
|
+
effort: agent.effort,
|
|
38
|
+
model_fixed: agent.model_fixed,
|
|
39
|
+
mode: agent.mode,
|
|
40
|
+
base_instructions: agent.base_instructions,
|
|
41
|
+
in_telegram: agent.in_telegram,
|
|
42
|
+
telegram_messages: agent.telegram_messages,
|
|
43
|
+
created: agent.created,
|
|
44
|
+
retired_at: agent.retired_at,
|
|
45
|
+
};
|
|
22
46
|
}
|
|
23
47
|
function listedConversation(listed) {
|
|
24
48
|
return {
|
|
25
49
|
conversation: listed.conversation_id,
|
|
26
50
|
agent: listed.agent_id,
|
|
27
|
-
agentName: listed.agent_name,
|
|
28
|
-
agentRetired: listed.agent_retired,
|
|
29
51
|
name: listed.name,
|
|
30
52
|
created: listed.created_at,
|
|
31
|
-
finished: listed.finished_at,
|
|
32
53
|
outcome: listed.outcome,
|
|
33
54
|
waiting: listed.waiting,
|
|
34
|
-
newest: listed.newest === null ? null :
|
|
55
|
+
newest: listed.newest === null ? null : changeCursor(listed.newest),
|
|
35
56
|
processEnded: listed.process_ended_at,
|
|
57
|
+
subject: listed.subject,
|
|
58
|
+
room: listed.room_ref,
|
|
59
|
+
model: listed.model,
|
|
60
|
+
effort: listed.effort,
|
|
36
61
|
};
|
|
37
62
|
}
|
|
38
63
|
function position(value) {
|
|
@@ -40,59 +65,72 @@ function position(value) {
|
|
|
40
65
|
return null;
|
|
41
66
|
return BigInt(value);
|
|
42
67
|
}
|
|
43
|
-
function* changed(tracked, entries, version, schemas) {
|
|
68
|
+
function* changed(tracked, entries, version, mode, schemas) {
|
|
44
69
|
const answer = answering();
|
|
45
70
|
for (const entry of entries) {
|
|
46
|
-
yield ROW_WEIGHT + (entry.
|
|
71
|
+
yield ROW_WEIGHT + (entry.content?.length ?? 0);
|
|
47
72
|
if (entry.kind === 'folder') {
|
|
48
73
|
folded(answer, entry.path, entry.removed === true);
|
|
49
74
|
continue;
|
|
50
75
|
}
|
|
51
|
-
if (entry.path === tracked.schema)
|
|
52
|
-
schemas.set(entry.path, entry);
|
|
53
|
-
forgotten(answer, entry.path);
|
|
54
76
|
if (entry.kind === 'removed') {
|
|
77
|
+
if (entry.path === tracked.schema)
|
|
78
|
+
schemas.set(entry.path, null);
|
|
79
|
+
forgotten(answer, entry.path);
|
|
55
80
|
answer.removals.add(entry.path);
|
|
56
81
|
continue;
|
|
57
82
|
}
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const head = headChange(entry);
|
|
69
|
-
if (head)
|
|
70
|
-
answer.changes.set(entry.path, head);
|
|
83
|
+
const file = documentEntry(entry, mode);
|
|
84
|
+
if (file === null)
|
|
85
|
+
throw new Error(`the stream carried ${entry.path} as no file`);
|
|
86
|
+
if (entry.path === tracked.schema)
|
|
87
|
+
schemas.set(entry.path, file);
|
|
88
|
+
forgotten(answer, file.path);
|
|
89
|
+
if (file.space === undefined)
|
|
90
|
+
kept(answer, file);
|
|
91
|
+
else
|
|
92
|
+
answer.removals.add(file.path);
|
|
71
93
|
}
|
|
72
94
|
return { kind: 'net-advancement', roomVersion: version, ...(yield* answered(answer)) };
|
|
73
95
|
}
|
|
74
|
-
async function changePage(tracked, entries, version, mode) {
|
|
96
|
+
async function changePage(tracked, entries, version, mode, whole) {
|
|
75
97
|
const schemas = new Map();
|
|
76
|
-
const page = await stepped(changed(tracked, entries, version, schemas));
|
|
77
|
-
const models = await streamedModels(schemas, tracked,
|
|
98
|
+
const page = await stepped(changed(tracked, entries, version, mode, schemas));
|
|
99
|
+
const models = await streamedModels(schemas, tracked, whole);
|
|
78
100
|
return models === undefined ? page : { ...page, models };
|
|
79
101
|
}
|
|
80
102
|
export function houseNotifications(transport, mode, discovering) {
|
|
81
103
|
const stream = transport.stream;
|
|
82
104
|
const staged = new Map();
|
|
105
|
+
let spaces = spaceSchemas();
|
|
83
106
|
let socket = null;
|
|
84
107
|
const tracking = new Map();
|
|
108
|
+
const located = new Map();
|
|
85
109
|
const observers = new Set();
|
|
110
|
+
const replaying = new Map();
|
|
86
111
|
const conversationObservers = new Set();
|
|
112
|
+
const runObservers = new Set();
|
|
87
113
|
const modeObservers = new Set();
|
|
88
114
|
let replicated = [];
|
|
89
115
|
let listedCursor = null;
|
|
116
|
+
let runMarks = NO_RUN_MARKS;
|
|
117
|
+
const unanswered = [];
|
|
118
|
+
const heldAtZero = new Set();
|
|
90
119
|
const live = new Set();
|
|
91
120
|
let opening = null;
|
|
92
121
|
let announced = null;
|
|
93
122
|
const runtime = crypto.randomUUID();
|
|
94
123
|
function emit(event) {
|
|
95
|
-
for (const observer of observers)
|
|
124
|
+
for (const observer of observers) {
|
|
125
|
+
const held = replaying.get(observer);
|
|
126
|
+
if (held === undefined)
|
|
127
|
+
observer(event);
|
|
128
|
+
else
|
|
129
|
+
held.push(event);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function emitRun(event) {
|
|
133
|
+
for (const observer of runObservers)
|
|
96
134
|
observer(event);
|
|
97
135
|
}
|
|
98
136
|
function emitConversation(event) {
|
|
@@ -102,8 +140,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
102
140
|
event.kind === 'commands' ||
|
|
103
141
|
event.kind === 'options' ||
|
|
104
142
|
event.kind === 'starting' ||
|
|
105
|
-
event.kind === '
|
|
106
|
-
event.kind === 'link' ||
|
|
143
|
+
event.kind === 'state' ||
|
|
107
144
|
event.kind === 'deliveries') {
|
|
108
145
|
live.add(event.conversation);
|
|
109
146
|
}
|
|
@@ -115,6 +152,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
115
152
|
announced = null;
|
|
116
153
|
socket = next;
|
|
117
154
|
staged.clear();
|
|
155
|
+
spaces = spaceSchemas();
|
|
156
|
+
unanswered.length = 0;
|
|
157
|
+
heldAtZero.clear();
|
|
118
158
|
const gapped = new Set([...replicated, ...live]);
|
|
119
159
|
live.clear();
|
|
120
160
|
for (const conversation of gapped)
|
|
@@ -133,9 +173,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
133
173
|
}
|
|
134
174
|
announced = { kind: 'discovered', discovery };
|
|
135
175
|
emit(announced);
|
|
136
|
-
}, () => {
|
|
176
|
+
}, (failure) => {
|
|
137
177
|
if (socket === via)
|
|
138
|
-
via.close();
|
|
178
|
+
via.close(failure);
|
|
139
179
|
});
|
|
140
180
|
}
|
|
141
181
|
function converse(frame) {
|
|
@@ -155,7 +195,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
155
195
|
return;
|
|
156
196
|
emitConversation({ kind: 'commands', conversation, commands: [] });
|
|
157
197
|
emitConversation({ kind: 'options', conversation, options: [] });
|
|
158
|
-
emitConversation({ kind: '
|
|
198
|
+
emitConversation({ kind: 'state', conversation, state: null });
|
|
159
199
|
return;
|
|
160
200
|
}
|
|
161
201
|
if (frame.type === 'commands') {
|
|
@@ -174,20 +214,17 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
174
214
|
emitConversation({ kind: 'starting', conversation, step: frame.step });
|
|
175
215
|
return;
|
|
176
216
|
}
|
|
177
|
-
if (frame.type === '
|
|
178
|
-
emitConversation({
|
|
179
|
-
kind: 'subagents',
|
|
180
|
-
conversation,
|
|
181
|
-
subagents: structuredClone(frame.subagents),
|
|
182
|
-
});
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (frame.type === 'link') {
|
|
186
|
-
emitConversation({ kind: 'link', conversation, connected: frame.connected });
|
|
217
|
+
if (frame.type === 'state') {
|
|
218
|
+
emitConversation({ kind: 'state', conversation, state: structuredClone(frame.state) });
|
|
187
219
|
return;
|
|
188
220
|
}
|
|
189
221
|
if (frame.type === 'deliveries') {
|
|
190
|
-
emitConversation({
|
|
222
|
+
emitConversation({
|
|
223
|
+
kind: 'deliveries',
|
|
224
|
+
conversation,
|
|
225
|
+
waiting: [...frame.waiting],
|
|
226
|
+
unknown: [...frame.unknown],
|
|
227
|
+
});
|
|
191
228
|
return;
|
|
192
229
|
}
|
|
193
230
|
if (frame.type === 'interactions') {
|
|
@@ -204,6 +241,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
204
241
|
emitConversation({ kind: 'accepted-message', conversation, message });
|
|
205
242
|
}
|
|
206
243
|
function stage(frame, via) {
|
|
244
|
+
const entries = spaceSchemaTexts(frame.entries, spaces);
|
|
207
245
|
const held = staged.get(frame.carry);
|
|
208
246
|
if (frame.index !== (held?.parts ?? 0)) {
|
|
209
247
|
staged.delete(frame.carry);
|
|
@@ -216,7 +254,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
216
254
|
}
|
|
217
255
|
}
|
|
218
256
|
const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
|
|
219
|
-
next.entries.push(...
|
|
257
|
+
next.entries.push(...entries);
|
|
220
258
|
next.parts += 1;
|
|
221
259
|
staged.set(frame.carry, next);
|
|
222
260
|
via?.received(frame.authority, frame.carry, frame.index);
|
|
@@ -243,9 +281,35 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
243
281
|
return;
|
|
244
282
|
}
|
|
245
283
|
if (frame.type === 'caught_up') {
|
|
284
|
+
const expired = frame.expired.flatMap((authority) => tracking.get(authority) ?? []);
|
|
285
|
+
discovering.expired?.(expired);
|
|
246
286
|
emit({
|
|
247
287
|
kind: 'caught-up',
|
|
248
|
-
expired:
|
|
288
|
+
expired: [...expired.map(({ locator }) => locator), ...(unanswered.shift() ?? [])],
|
|
289
|
+
});
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (frame.type === 'report') {
|
|
293
|
+
emit({ kind: 'reported' });
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (frame.type === 'request') {
|
|
297
|
+
const room = frame.request.room_ref;
|
|
298
|
+
emitRun({
|
|
299
|
+
kind: 'run',
|
|
300
|
+
run: heardRun(frame.request),
|
|
301
|
+
listing: tracking.has(room) ? room : null,
|
|
302
|
+
});
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (frame.type === 'requests') {
|
|
306
|
+
emitRun({
|
|
307
|
+
kind: 'runs',
|
|
308
|
+
listing: frame.room_ref,
|
|
309
|
+
runs: frame.requests.map(heardRun),
|
|
310
|
+
whole: frame.whole,
|
|
311
|
+
more: frame.more,
|
|
312
|
+
mark: frame.cursor,
|
|
249
313
|
});
|
|
250
314
|
return;
|
|
251
315
|
}
|
|
@@ -258,6 +322,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
258
322
|
if (frame.type === 'conversations') {
|
|
259
323
|
emitConversation({
|
|
260
324
|
kind: 'list',
|
|
325
|
+
agents: frame.agents.map(listedAgent),
|
|
261
326
|
entries: frame.conversations.map(listedConversation),
|
|
262
327
|
whole: frame.whole,
|
|
263
328
|
more: frame.more,
|
|
@@ -269,6 +334,10 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
269
334
|
emitConversation({ kind: 'listed', entry: listedConversation(frame.conversation) });
|
|
270
335
|
return;
|
|
271
336
|
}
|
|
337
|
+
if (frame.type === 'agent') {
|
|
338
|
+
emitConversation({ kind: 'agent', agent: listedAgent(frame.agent) });
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
272
341
|
if (frame.type === 'conversation_deleted') {
|
|
273
342
|
emitConversation({ kind: 'unlisted', conversation: frame.conversation_id });
|
|
274
343
|
return;
|
|
@@ -278,8 +347,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
278
347
|
frame.type === 'commands' ||
|
|
279
348
|
frame.type === 'options' ||
|
|
280
349
|
frame.type === 'starting' ||
|
|
281
|
-
frame.type === '
|
|
282
|
-
frame.type === 'link' ||
|
|
350
|
+
frame.type === 'state' ||
|
|
283
351
|
frame.type === 'deliveries' ||
|
|
284
352
|
frame.type === 'interactions' ||
|
|
285
353
|
frame.type === 'message') {
|
|
@@ -296,7 +364,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
296
364
|
const after = position(frame.after);
|
|
297
365
|
if (at === null || after === null || after >= at)
|
|
298
366
|
return;
|
|
299
|
-
const from =
|
|
367
|
+
const from = after === 0n && !heldAtZero.has(frame.authority)
|
|
368
|
+
? null
|
|
369
|
+
: roomVersion({ position: frame.after, logEpoch: frame.log_epoch });
|
|
300
370
|
const version = roomVersion({ position: frame.position, logEpoch: frame.log_epoch });
|
|
301
371
|
for (const tracked of tracking.get(frame.authority) ?? []) {
|
|
302
372
|
emit({
|
|
@@ -304,7 +374,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
304
374
|
locator: tracked.locator,
|
|
305
375
|
from,
|
|
306
376
|
roomVersion: version,
|
|
307
|
-
read: () => changePage(tracked, entries, version, mode),
|
|
377
|
+
read: () => changePage(tracked, entries, version, mode, from === null),
|
|
308
378
|
});
|
|
309
379
|
}
|
|
310
380
|
}
|
|
@@ -315,6 +385,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
315
385
|
announced = null;
|
|
316
386
|
socket = null;
|
|
317
387
|
staged.clear();
|
|
388
|
+
spaces = spaceSchemas();
|
|
389
|
+
unanswered.length = 0;
|
|
390
|
+
heldAtZero.clear();
|
|
318
391
|
emit({ kind: 'closed', revoked, lost, authorityChanged });
|
|
319
392
|
});
|
|
320
393
|
return {
|
|
@@ -340,20 +413,30 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
340
413
|
conversationObservers.delete(notify);
|
|
341
414
|
};
|
|
342
415
|
},
|
|
343
|
-
...(mode === 'credential'
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
416
|
+
...(mode === 'credential' ? { history: (request) => houseHistory(transport, request) } : {}),
|
|
417
|
+
},
|
|
418
|
+
runs: {
|
|
419
|
+
hold(marks) {
|
|
420
|
+
runMarks = marks;
|
|
421
|
+
},
|
|
422
|
+
observe(notify) {
|
|
423
|
+
runObservers.add(notify);
|
|
424
|
+
return () => {
|
|
425
|
+
runObservers.delete(notify);
|
|
426
|
+
};
|
|
427
|
+
},
|
|
349
428
|
},
|
|
350
429
|
observe(notify) {
|
|
351
430
|
observers.add(notify);
|
|
352
|
-
|
|
353
|
-
|
|
431
|
+
if (opening !== null) {
|
|
432
|
+
const replayed = [{ kind: 'opened' }];
|
|
433
|
+
if (announced !== null)
|
|
434
|
+
replayed.push(announced);
|
|
435
|
+
replaying.set(notify, replayed);
|
|
354
436
|
queueMicrotask(() => {
|
|
437
|
+
replaying.delete(notify);
|
|
355
438
|
for (const event of replayed)
|
|
356
|
-
if (
|
|
439
|
+
if (observers.has(notify))
|
|
357
440
|
notify(event);
|
|
358
441
|
});
|
|
359
442
|
}
|
|
@@ -364,13 +447,61 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
364
447
|
send(rooms) {
|
|
365
448
|
opening = null;
|
|
366
449
|
announced = null;
|
|
367
|
-
socket
|
|
450
|
+
if (socket === null)
|
|
451
|
+
return;
|
|
452
|
+
const named = rooms.flatMap((room) => {
|
|
453
|
+
const entry = located.get(room.locator);
|
|
454
|
+
const at = room.roomVersion === null ? null : logPosition(room.roomVersion);
|
|
455
|
+
return entry === undefined || at === null ? [] : [{ entry, at }];
|
|
456
|
+
});
|
|
457
|
+
const unheld = rooms.flatMap((room) => {
|
|
458
|
+
const entry = located.get(room.locator);
|
|
459
|
+
return entry === undefined || room.roomVersion !== null ? [] : [entry];
|
|
460
|
+
});
|
|
461
|
+
for (const { entry, at } of named) {
|
|
462
|
+
if (at.position === '0')
|
|
463
|
+
heldAtZero.add(entry.authority);
|
|
464
|
+
else
|
|
465
|
+
heldAtZero.delete(entry.authority);
|
|
466
|
+
}
|
|
467
|
+
for (const entry of unheld)
|
|
468
|
+
heldAtZero.delete(entry.authority);
|
|
469
|
+
const site = mode === 'site';
|
|
470
|
+
unanswered.push(site ? unheld.map((entry) => entry.locator) : []);
|
|
471
|
+
const marked = (held) => {
|
|
472
|
+
const mark = runMarks.rooms[held.authority];
|
|
473
|
+
return mark === undefined ? held : { ...held, requests: mark };
|
|
474
|
+
};
|
|
475
|
+
socket.hold([
|
|
476
|
+
...named.map(({ entry, at }) => marked(presented(entry.authority, at))),
|
|
477
|
+
...(site ? [] : unheld).map((entry) => marked(presented(entry.authority, { position: '0', logEpoch: entry.logEpoch }))),
|
|
478
|
+
], runtime, listedCursor, runMarks.sent ?? undefined);
|
|
479
|
+
if (site)
|
|
480
|
+
return;
|
|
481
|
+
const made = unheld.filter((entry) => entry.position === '0');
|
|
482
|
+
queueMicrotask(() => {
|
|
483
|
+
for (const entry of made) {
|
|
484
|
+
const version = roomVersion(entry);
|
|
485
|
+
emit({
|
|
486
|
+
kind: 'room-change',
|
|
487
|
+
locator: entry.locator,
|
|
488
|
+
from: null,
|
|
489
|
+
roomVersion: version,
|
|
490
|
+
read: () => changePage(entry, [], version, mode, true),
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
});
|
|
368
494
|
},
|
|
369
495
|
track(entries) {
|
|
370
496
|
tracking.clear();
|
|
497
|
+
located.clear();
|
|
371
498
|
for (const entry of entries) {
|
|
372
499
|
tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
|
|
373
500
|
}
|
|
501
|
+
for (const held of tracking.values()) {
|
|
502
|
+
for (const entry of held)
|
|
503
|
+
located.set(entry.locator, entry);
|
|
504
|
+
}
|
|
374
505
|
for (const [carry, held] of staged) {
|
|
375
506
|
if (!tracking.has(held.authority))
|
|
376
507
|
staged.delete(carry);
|