@agentshouse/mdruntime-adapter 0.1.0-cf22c8563f9f4 → 0.1.0-cf3b6e1c58319
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 +6 -6
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +28 -324
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +303 -218
- package/dist/app-reference.d.ts +1 -0
- package/dist/app-reference.d.ts.map +1 -0
- package/dist/app-reference.js +2 -0
- package/dist/authored-path.d.ts +10 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +35 -0
- package/dist/chunks.d.ts +37 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +254 -0
- package/dist/crockford.d.ts +3 -0
- package/dist/crockford.d.ts.map +1 -0
- package/dist/crockford.js +3 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +26 -18
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +107 -55
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/house-model.d.ts +826 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +464 -0
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +5 -5
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +40 -33
- package/dist/read.d.ts +63 -43
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +179 -262
- package/dist/refusal.d.ts +5 -10
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +21 -19
- package/dist/room-types.d.ts +4 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +136 -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/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 +102 -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 +128 -107
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +18 -0
- package/dist/stream.d.ts +15 -13
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +299 -149
- package/dist/transport.d.ts +96 -28
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +55 -9
- 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 +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/write.d.ts +20 -12
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +178 -70
- package/package.json +9 -6
- package/AGENTS.md +0 -244
- package/dist/gather.d.ts +0 -3
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -40
- package/dist/links.d.ts +0 -20
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -104
package/dist/stream.d.ts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AuthorityChange, type Discovery, type ConversationStream, type HeldRoom, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import type {
|
|
4
|
-
import { type
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import type { SpaceSchemas } from './space-schema.js';
|
|
4
|
+
import { type HouseDoor, type HouseMode, type HouseStreamFrame } from './transport.js';
|
|
5
|
+
export type HouseOpeningFrame = Extract<HouseStreamFrame, {
|
|
6
|
+
type: 'opening';
|
|
7
|
+
}>;
|
|
8
|
+
export type HouseAuthorityChangedFrame = Extract<HouseStreamFrame, {
|
|
9
|
+
type: 'authority_changed';
|
|
10
|
+
}>;
|
|
11
|
+
export type HouseDiscovering = {
|
|
12
|
+
opened(frame: HouseOpeningFrame | null): Promise<Discovery | null>;
|
|
13
|
+
changed(frame: HouseAuthorityChangedFrame): AuthorityChange | null;
|
|
14
|
+
expired?(authorities: readonly string[]): void;
|
|
10
15
|
};
|
|
11
16
|
export type HouseNotifications = {
|
|
12
17
|
runtime: string;
|
|
13
18
|
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
14
|
-
send(rooms: readonly
|
|
19
|
+
send(rooms: readonly HeldRoom[]): void;
|
|
15
20
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
16
|
-
reach(authority: string, at: LogPosition): void;
|
|
17
|
-
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): StreamedAdvancement | null;
|
|
18
21
|
conversations: ConversationStream;
|
|
19
22
|
serviceMode: ServiceModeSignal;
|
|
20
23
|
};
|
|
21
|
-
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
|
|
22
|
-
//# sourceMappingURL=stream.d.ts.map
|
|
24
|
+
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering, spaces: SpaceSchemas): HouseNotifications;
|
package/dist/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EAEpB,KAAK,SAAS,EACd,KAAK,kBAAkB,EAEvB,KAAK,QAAQ,EAGb,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAYtD,OAAO,EAEL,KAAK,SAAS,EAEd,KAAK,SAAS,EAGd,KAAK,gBAAgB,EACtB,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,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;CAChD,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,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAyHF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,gBAAgB,EAC7B,MAAM,EAAE,YAAY,GACnB,kBAAkB,CA+XpB"}
|
package/dist/stream.js
CHANGED
|
@@ -1,47 +1,146 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { ROW_WEIGHT, stepped, uncertainError, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { acceptedMessage, changeCursor, houseHistory } from './history.js';
|
|
3
|
+
import { keptSpaceSchemas, streamedModels } from './model.js';
|
|
4
|
+
import { answered, answering, binaryFileOf, createdOf, folded, forgotten, headChange, revised, } from './read.js';
|
|
5
|
+
import { classifyDoor } from './refusal.js';
|
|
6
|
+
import { houseDoorRoute, } from './transport.js';
|
|
7
|
+
import { DECIMAL, logPosition, presented, roomVersion } from './version.js';
|
|
5
8
|
function turnOperation(frame) {
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
return 'at' in frame ? { op: 'begin', at: frame.at } : structuredClone(frame.operation);
|
|
10
|
+
}
|
|
11
|
+
async function houseAgents(transport) {
|
|
12
|
+
const answer = await transport.door(houseDoorRoute('agents/list'), {});
|
|
13
|
+
const failure = classifyDoor(answer.status, answer.body, 'agents/list');
|
|
14
|
+
if (failure?.kind === 'transport-uncertainty') {
|
|
15
|
+
throw uncertainError(failure);
|
|
16
|
+
}
|
|
17
|
+
const agents = answer.status === 200 ? answer.body?.agents : null;
|
|
18
|
+
if (!Array.isArray(agents))
|
|
19
|
+
return null;
|
|
20
|
+
return agents.flatMap((one) => {
|
|
21
|
+
const { id, name, cli, environment, environment_name: environmentName, environment_connected: connected, retired_at: retired, } = (one ?? {});
|
|
22
|
+
return typeof id === 'string' &&
|
|
23
|
+
typeof name === 'string' &&
|
|
24
|
+
typeof cli === 'string' &&
|
|
25
|
+
typeof environment === 'string' &&
|
|
26
|
+
typeof environmentName === 'string' &&
|
|
27
|
+
typeof connected === 'boolean'
|
|
28
|
+
? [
|
|
29
|
+
{
|
|
30
|
+
agent: id,
|
|
31
|
+
name,
|
|
32
|
+
retired: retired !== null && retired !== undefined,
|
|
33
|
+
cli,
|
|
34
|
+
environment: {
|
|
35
|
+
identity: environment,
|
|
36
|
+
name: environmentName,
|
|
37
|
+
state: connected ? 'online' : 'offline',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
]
|
|
41
|
+
: [];
|
|
42
|
+
});
|
|
8
43
|
}
|
|
9
44
|
function listedConversation(listed) {
|
|
10
45
|
return {
|
|
11
46
|
conversation: listed.conversation_id,
|
|
12
47
|
agent: listed.agent_id,
|
|
48
|
+
agentName: listed.agent_name,
|
|
49
|
+
agentRetired: listed.agent_retired,
|
|
13
50
|
name: listed.name,
|
|
14
51
|
created: listed.created_at,
|
|
15
52
|
finished: listed.finished_at,
|
|
16
53
|
outcome: listed.outcome,
|
|
54
|
+
waiting: listed.waiting,
|
|
55
|
+
newest: listed.newest === null ? null : changeCursor(listed.newest),
|
|
56
|
+
processEnded: listed.process_ended_at,
|
|
17
57
|
};
|
|
18
58
|
}
|
|
19
59
|
function position(value) {
|
|
20
|
-
if (
|
|
60
|
+
if (!DECIMAL.test(value))
|
|
21
61
|
return null;
|
|
22
62
|
return BigInt(value);
|
|
23
63
|
}
|
|
24
|
-
|
|
64
|
+
function* changed(tracked, entries, version, schemas) {
|
|
65
|
+
const answer = answering();
|
|
66
|
+
for (const entry of entries) {
|
|
67
|
+
yield ROW_WEIGHT + (entry.text?.length ?? 0);
|
|
68
|
+
if (entry.kind === 'folder') {
|
|
69
|
+
folded(answer, entry.path, entry.removed === true);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (entry.path === tracked.schema)
|
|
73
|
+
schemas.set(entry.path, entry);
|
|
74
|
+
forgotten(answer, entry.path);
|
|
75
|
+
if (entry.space !== undefined) {
|
|
76
|
+
answer.removals.add(entry.path);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (entry.kind === 'removed') {
|
|
80
|
+
answer.removals.add(entry.path);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const binary = binaryFileOf(entry);
|
|
84
|
+
if (binary === undefined)
|
|
85
|
+
answer.documents.set(entry.path, entry.text ?? '');
|
|
86
|
+
else if (binary !== null)
|
|
87
|
+
answer.binaryFiles.set(entry.path, binary);
|
|
88
|
+
if (binary === undefined && entry.facts !== undefined)
|
|
89
|
+
answer.facts.set(entry.path, entry.facts);
|
|
90
|
+
const revision = entry.revision ?? binary?.sha256;
|
|
91
|
+
if (revision !== undefined)
|
|
92
|
+
revised(answer, entry.path, revision);
|
|
93
|
+
const head = headChange(entry);
|
|
94
|
+
if (head)
|
|
95
|
+
answer.changes.set(entry.path, head);
|
|
96
|
+
const created = createdOf(entry);
|
|
97
|
+
if (created)
|
|
98
|
+
answer.created.set(entry.path, created);
|
|
99
|
+
}
|
|
100
|
+
return { kind: 'net-advancement', roomVersion: version, ...(yield* answered(answer)) };
|
|
101
|
+
}
|
|
102
|
+
async function changePage(tracked, entries, version, mode, spaces, whole) {
|
|
103
|
+
const schemas = new Map();
|
|
104
|
+
const page = await stepped(changed(tracked, entries, version, schemas));
|
|
105
|
+
const models = await streamedModels(schemas, tracked, mode, spaces, whole);
|
|
106
|
+
return models === undefined ? page : { ...page, models };
|
|
107
|
+
}
|
|
108
|
+
export function houseNotifications(transport, mode, discovering, spaces) {
|
|
25
109
|
const stream = transport.stream;
|
|
26
|
-
const
|
|
27
|
-
|
|
110
|
+
const staged = new Map();
|
|
111
|
+
let socket = null;
|
|
112
|
+
const tracking = new Map();
|
|
28
113
|
const observers = new Set();
|
|
114
|
+
const replaying = new Map();
|
|
29
115
|
const conversationObservers = new Set();
|
|
30
116
|
const modeObservers = new Set();
|
|
31
117
|
let replicated = [];
|
|
118
|
+
let listedCursor = null;
|
|
119
|
+
const unanswered = [];
|
|
120
|
+
const heldAtZero = new Set();
|
|
32
121
|
const live = new Set();
|
|
33
122
|
let opening = null;
|
|
123
|
+
let announced = null;
|
|
34
124
|
const runtime = crypto.randomUUID();
|
|
35
125
|
function emit(event) {
|
|
36
|
-
for (const observer of observers)
|
|
37
|
-
observer
|
|
126
|
+
for (const observer of observers) {
|
|
127
|
+
const held = replaying.get(observer);
|
|
128
|
+
if (held === undefined)
|
|
129
|
+
observer(event);
|
|
130
|
+
else
|
|
131
|
+
held.push(event);
|
|
132
|
+
}
|
|
38
133
|
}
|
|
39
134
|
function emitConversation(event) {
|
|
40
135
|
if (event.kind === 'turn' ||
|
|
41
136
|
event.kind === 'questions' ||
|
|
42
137
|
event.kind === 'process' ||
|
|
43
138
|
event.kind === 'commands' ||
|
|
44
|
-
event.kind === 'options'
|
|
139
|
+
event.kind === 'options' ||
|
|
140
|
+
event.kind === 'starting' ||
|
|
141
|
+
event.kind === 'state' ||
|
|
142
|
+
event.kind === 'link' ||
|
|
143
|
+
event.kind === 'deliveries') {
|
|
45
144
|
live.add(event.conversation);
|
|
46
145
|
}
|
|
47
146
|
for (const observer of conversationObservers)
|
|
@@ -49,11 +148,33 @@ export function houseNotifications(transport, mode) {
|
|
|
49
148
|
}
|
|
50
149
|
function reopened(next) {
|
|
51
150
|
opening = next;
|
|
151
|
+
announced = null;
|
|
152
|
+
socket = next;
|
|
153
|
+
staged.clear();
|
|
154
|
+
unanswered.length = 0;
|
|
155
|
+
heldAtZero.clear();
|
|
52
156
|
const gapped = new Set([...replicated, ...live]);
|
|
53
157
|
live.clear();
|
|
54
158
|
for (const conversation of gapped)
|
|
55
159
|
emitConversation({ kind: 'gap', conversation });
|
|
56
160
|
emit({ kind: 'opened' });
|
|
161
|
+
if (mode === 'site')
|
|
162
|
+
announce(next, null);
|
|
163
|
+
}
|
|
164
|
+
function announce(via, frame) {
|
|
165
|
+
void discovering.opened(frame).then((discovery) => {
|
|
166
|
+
if (socket !== via)
|
|
167
|
+
return;
|
|
168
|
+
if (discovery === null) {
|
|
169
|
+
via.close();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
announced = { kind: 'discovered', discovery };
|
|
173
|
+
emit(announced);
|
|
174
|
+
}, (failure) => {
|
|
175
|
+
if (socket === via)
|
|
176
|
+
via.close(failure);
|
|
177
|
+
});
|
|
57
178
|
}
|
|
58
179
|
function converse(frame) {
|
|
59
180
|
const conversation = frame.conversation_id;
|
|
@@ -72,6 +193,7 @@ export function houseNotifications(transport, mode) {
|
|
|
72
193
|
return;
|
|
73
194
|
emitConversation({ kind: 'commands', conversation, commands: [] });
|
|
74
195
|
emitConversation({ kind: 'options', conversation, options: [] });
|
|
196
|
+
emitConversation({ kind: 'state', conversation, state: null });
|
|
75
197
|
return;
|
|
76
198
|
}
|
|
77
199
|
if (frame.type === 'commands') {
|
|
@@ -86,6 +208,27 @@ export function houseNotifications(transport, mode) {
|
|
|
86
208
|
emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });
|
|
87
209
|
return;
|
|
88
210
|
}
|
|
211
|
+
if (frame.type === 'starting') {
|
|
212
|
+
emitConversation({ kind: 'starting', conversation, step: frame.step });
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (frame.type === 'state') {
|
|
216
|
+
emitConversation({ kind: 'state', conversation, state: structuredClone(frame.state) });
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (frame.type === 'link') {
|
|
220
|
+
emitConversation({ kind: 'link', conversation, connected: frame.connected });
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (frame.type === 'deliveries') {
|
|
224
|
+
emitConversation({
|
|
225
|
+
kind: 'deliveries',
|
|
226
|
+
conversation,
|
|
227
|
+
waiting: [...frame.waiting],
|
|
228
|
+
unknown: [...frame.unknown],
|
|
229
|
+
});
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
89
232
|
if (frame.type === 'interactions') {
|
|
90
233
|
emitConversation({
|
|
91
234
|
kind: 'questions',
|
|
@@ -99,18 +242,33 @@ export function houseNotifications(transport, mode) {
|
|
|
99
242
|
return;
|
|
100
243
|
emitConversation({ kind: 'accepted-message', conversation, message });
|
|
101
244
|
}
|
|
102
|
-
function
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
245
|
+
function stage(frame, via) {
|
|
246
|
+
const held = staged.get(frame.carry);
|
|
247
|
+
if (frame.index !== (held?.parts ?? 0)) {
|
|
248
|
+
staged.delete(frame.carry);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (held === undefined) {
|
|
252
|
+
for (const [carry, other] of staged) {
|
|
253
|
+
if (other.authority === frame.authority)
|
|
254
|
+
staged.delete(carry);
|
|
255
|
+
}
|
|
106
256
|
}
|
|
257
|
+
const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
|
|
258
|
+
keptSpaceSchemas(frame.entries, spaces);
|
|
259
|
+
next.entries.push(...frame.entries);
|
|
260
|
+
next.parts += 1;
|
|
261
|
+
staged.set(frame.carry, next);
|
|
262
|
+
via?.received(frame.authority, frame.carry, frame.index);
|
|
107
263
|
}
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
264
|
+
function carried(frame) {
|
|
265
|
+
const held = staged.get(frame.carry);
|
|
266
|
+
staged.delete(frame.carry);
|
|
267
|
+
if ((held?.parts ?? 0) !== frame.parts)
|
|
268
|
+
return;
|
|
269
|
+
publish(frame, held?.entries ?? []);
|
|
112
270
|
}
|
|
113
|
-
function
|
|
271
|
+
function handle(frame, via) {
|
|
114
272
|
if (frame.type === 'signal') {
|
|
115
273
|
const mode = frame.service_mode;
|
|
116
274
|
if (mode !== 'open' && mode !== 'write-halted')
|
|
@@ -120,14 +278,35 @@ export function houseNotifications(transport, mode) {
|
|
|
120
278
|
return;
|
|
121
279
|
}
|
|
122
280
|
if (frame.type === 'opening') {
|
|
281
|
+
if (via !== null && mode === 'credential')
|
|
282
|
+
announce(via, frame);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (frame.type === 'caught_up') {
|
|
286
|
+
discovering.expired?.(frame.expired);
|
|
123
287
|
emit({
|
|
124
|
-
kind: '
|
|
125
|
-
expired:
|
|
288
|
+
kind: 'caught-up',
|
|
289
|
+
expired: [
|
|
290
|
+
...frame.expired.flatMap((authority) => (tracking.get(authority) ?? []).map((tracked) => tracked.locator)),
|
|
291
|
+
...(unanswered.shift() ?? []),
|
|
292
|
+
],
|
|
126
293
|
});
|
|
127
294
|
return;
|
|
128
295
|
}
|
|
296
|
+
if (frame.type === 'authority_changed') {
|
|
297
|
+
const change = discovering.changed(frame);
|
|
298
|
+
if (change !== null)
|
|
299
|
+
emit(change);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
129
302
|
if (frame.type === 'conversations') {
|
|
130
|
-
emitConversation({
|
|
303
|
+
emitConversation({
|
|
304
|
+
kind: 'list',
|
|
305
|
+
entries: frame.conversations.map(listedConversation),
|
|
306
|
+
whole: frame.whole,
|
|
307
|
+
more: frame.more,
|
|
308
|
+
cursor: frame.cursor,
|
|
309
|
+
});
|
|
131
310
|
return;
|
|
132
311
|
}
|
|
133
312
|
if (frame.type === 'conversation') {
|
|
@@ -142,40 +321,49 @@ export function houseNotifications(transport, mode) {
|
|
|
142
321
|
frame.type === 'process' ||
|
|
143
322
|
frame.type === 'commands' ||
|
|
144
323
|
frame.type === 'options' ||
|
|
324
|
+
frame.type === 'starting' ||
|
|
325
|
+
frame.type === 'state' ||
|
|
326
|
+
frame.type === 'link' ||
|
|
327
|
+
frame.type === 'deliveries' ||
|
|
145
328
|
frame.type === 'interactions' ||
|
|
146
329
|
frame.type === 'message') {
|
|
147
330
|
converse(frame);
|
|
148
331
|
return;
|
|
149
332
|
}
|
|
150
|
-
if (frame.type
|
|
151
|
-
|
|
333
|
+
if (frame.type === 'part')
|
|
334
|
+
stage(frame, via);
|
|
335
|
+
else if (frame.type === 'carried')
|
|
336
|
+
carried(frame);
|
|
337
|
+
}
|
|
338
|
+
function publish(frame, entries) {
|
|
152
339
|
const at = position(frame.position);
|
|
153
340
|
const after = position(frame.after);
|
|
154
|
-
if (at === null || after === null || after >= at)
|
|
155
|
-
interrupt(frame.authority);
|
|
341
|
+
if (at === null || after === null || after >= at)
|
|
156
342
|
return;
|
|
343
|
+
const from = after === 0n && !heldAtZero.has(frame.authority)
|
|
344
|
+
? null
|
|
345
|
+
: roomVersion({ position: frame.after, logEpoch: frame.log_epoch });
|
|
346
|
+
const version = roomVersion({ position: frame.position, logEpoch: frame.log_epoch });
|
|
347
|
+
for (const tracked of tracking.get(frame.authority) ?? []) {
|
|
348
|
+
emit({
|
|
349
|
+
kind: 'room-change',
|
|
350
|
+
locator: tracked.locator,
|
|
351
|
+
from,
|
|
352
|
+
roomVersion: version,
|
|
353
|
+
read: () => changePage(tracked, entries, version, mode, spaces, from === null),
|
|
354
|
+
});
|
|
157
355
|
}
|
|
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
356
|
}
|
|
174
|
-
stream.observe(
|
|
357
|
+
stream.observe((frame) => handle(frame, socket));
|
|
175
358
|
stream.opened(reopened);
|
|
176
|
-
stream.closed((revoked) => {
|
|
359
|
+
stream.closed(({ revoked, lost, authorityChanged }) => {
|
|
177
360
|
opening = null;
|
|
178
|
-
|
|
361
|
+
announced = null;
|
|
362
|
+
socket = null;
|
|
363
|
+
staged.clear();
|
|
364
|
+
unanswered.length = 0;
|
|
365
|
+
heldAtZero.clear();
|
|
366
|
+
emit({ kind: 'closed', revoked, lost, authorityChanged });
|
|
179
367
|
});
|
|
180
368
|
return {
|
|
181
369
|
runtime,
|
|
@@ -191,19 +379,34 @@ export function houseNotifications(transport, mode) {
|
|
|
191
379
|
replicate(next) {
|
|
192
380
|
replicated = [...next];
|
|
193
381
|
},
|
|
382
|
+
hold(cursor) {
|
|
383
|
+
listedCursor = cursor;
|
|
384
|
+
},
|
|
194
385
|
observe(notify) {
|
|
195
386
|
conversationObservers.add(notify);
|
|
196
387
|
return () => {
|
|
197
388
|
conversationObservers.delete(notify);
|
|
198
389
|
};
|
|
199
390
|
},
|
|
391
|
+
...(mode === 'credential'
|
|
392
|
+
? {
|
|
393
|
+
agents: () => houseAgents(transport),
|
|
394
|
+
history: (request) => houseHistory(transport, request),
|
|
395
|
+
}
|
|
396
|
+
: {}),
|
|
200
397
|
},
|
|
201
398
|
observe(notify) {
|
|
202
399
|
observers.add(notify);
|
|
203
400
|
if (opening !== null) {
|
|
401
|
+
const replayed = [{ kind: 'opened' }];
|
|
402
|
+
if (announced !== null)
|
|
403
|
+
replayed.push(announced);
|
|
404
|
+
replaying.set(notify, replayed);
|
|
204
405
|
queueMicrotask(() => {
|
|
205
|
-
|
|
206
|
-
|
|
406
|
+
replaying.delete(notify);
|
|
407
|
+
for (const event of replayed)
|
|
408
|
+
if (observers.has(notify))
|
|
409
|
+
notify(event);
|
|
207
410
|
});
|
|
208
411
|
}
|
|
209
412
|
return () => {
|
|
@@ -211,112 +414,59 @@ export function houseNotifications(transport, mode) {
|
|
|
211
414
|
};
|
|
212
415
|
},
|
|
213
416
|
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
417
|
opening = null;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
track(entries) {
|
|
226
|
-
locators.clear();
|
|
227
|
-
for (const entry of entries) {
|
|
228
|
-
locators.set(entry.authority, [...(locators.get(entry.authority) ?? []), entry.locator]);
|
|
229
|
-
if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {
|
|
230
|
-
lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [], held: null });
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
for (const authority of lines.keys()) {
|
|
234
|
-
if (!locators.has(authority))
|
|
235
|
-
lines.delete(authority);
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
reach(authority, at) {
|
|
239
|
-
const line = lines.get(authority);
|
|
240
|
-
const held = position(at.position);
|
|
241
|
-
if (line === undefined || held === null || line.logEpoch !== at.logEpoch)
|
|
418
|
+
announced = null;
|
|
419
|
+
if (socket === null)
|
|
242
420
|
return;
|
|
243
|
-
|
|
421
|
+
const entries = new Map([...tracking.values()].flat().map((tracked) => [tracked.locator, tracked]));
|
|
422
|
+
const named = rooms.flatMap((room) => {
|
|
423
|
+
const entry = entries.get(room.locator);
|
|
424
|
+
const at = room.roomVersion === null ? null : logPosition(room.roomVersion);
|
|
425
|
+
return entry === undefined || at === null ? [] : [{ entry, at }];
|
|
426
|
+
});
|
|
427
|
+
const unheld = rooms.flatMap((room) => {
|
|
428
|
+
const entry = entries.get(room.locator);
|
|
429
|
+
return entry === undefined || room.roomVersion !== null ? [] : [entry];
|
|
430
|
+
});
|
|
431
|
+
for (const { entry, at } of named) {
|
|
432
|
+
if (at.position === '0')
|
|
433
|
+
heldAtZero.add(entry.authority);
|
|
434
|
+
else
|
|
435
|
+
heldAtZero.delete(entry.authority);
|
|
436
|
+
}
|
|
437
|
+
for (const entry of unheld)
|
|
438
|
+
heldAtZero.delete(entry.authority);
|
|
439
|
+
const site = mode === 'site';
|
|
440
|
+
unanswered.push(site ? unheld.map((entry) => entry.locator) : []);
|
|
441
|
+
socket.hold([
|
|
442
|
+
...named.map(({ entry, at }) => presented(entry.authority, at)),
|
|
443
|
+
...(site ? [] : unheld).map((entry) => presented(entry.authority, { position: '0', logEpoch: entry.logEpoch })),
|
|
444
|
+
], runtime, listedCursor);
|
|
445
|
+
if (site)
|
|
244
446
|
return;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
447
|
+
const made = unheld.filter((entry) => entry.position === '0');
|
|
448
|
+
queueMicrotask(() => {
|
|
449
|
+
for (const entry of made) {
|
|
450
|
+
const version = roomVersion(entry);
|
|
451
|
+
emit({
|
|
452
|
+
kind: 'room-change',
|
|
453
|
+
locator: entry.locator,
|
|
454
|
+
from: null,
|
|
455
|
+
roomVersion: version,
|
|
456
|
+
read: () => changePage(entry, [], version, mode, spaces, true),
|
|
457
|
+
});
|
|
458
|
+
}
|
|
249
459
|
});
|
|
250
460
|
},
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
return null;
|
|
260
|
-
const documents = {};
|
|
261
|
-
const revisions = {};
|
|
262
|
-
const changes = {};
|
|
263
|
-
const removals = [];
|
|
264
|
-
const applied = [];
|
|
265
|
-
const schemas = new Map();
|
|
266
|
-
const forget = (path) => {
|
|
267
|
-
delete documents[path];
|
|
268
|
-
delete revisions[path];
|
|
269
|
-
delete changes[path];
|
|
270
|
-
const removed = removals.indexOf(path);
|
|
271
|
-
if (removed !== -1)
|
|
272
|
-
removals.splice(removed, 1);
|
|
273
|
-
};
|
|
274
|
-
for (const frame of pending) {
|
|
275
|
-
for (const entry of frame.entries) {
|
|
276
|
-
if (entry.kind === 'edited' &&
|
|
277
|
-
entry.revision !== undefined &&
|
|
278
|
-
holds?.(entry.path, entry.revision) === true) {
|
|
279
|
-
forget(entry.path);
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
applied.push(entry);
|
|
283
|
-
if (tracked.schemas.includes(entry.path))
|
|
284
|
-
schemas.set(entry.path, entry);
|
|
285
|
-
if (entry.kind === 'removed') {
|
|
286
|
-
forget(entry.path);
|
|
287
|
-
removals.push(entry.path);
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
if (entry.text === undefined)
|
|
291
|
-
return null;
|
|
292
|
-
if (mode === 'credential' && entry.revision === undefined)
|
|
293
|
-
return null;
|
|
294
|
-
const head = headChange(entry);
|
|
295
|
-
if (head === null)
|
|
296
|
-
return null;
|
|
297
|
-
forget(entry.path);
|
|
298
|
-
documents[entry.path] = entry.text;
|
|
299
|
-
if (entry.revision !== undefined)
|
|
300
|
-
revisions[entry.path] = entry.revision;
|
|
301
|
-
if (head !== undefined)
|
|
302
|
-
changes[entry.path] = head;
|
|
303
|
-
}
|
|
461
|
+
track(entries) {
|
|
462
|
+
tracking.clear();
|
|
463
|
+
for (const entry of entries) {
|
|
464
|
+
tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
|
|
465
|
+
}
|
|
466
|
+
for (const [carry, held] of staged) {
|
|
467
|
+
if (!tracking.has(held.authority))
|
|
468
|
+
staged.delete(carry);
|
|
304
469
|
}
|
|
305
|
-
const last = pending.at(-1);
|
|
306
|
-
lines.set(tracked.authority, { ...line, frames: pending, held: last.position });
|
|
307
|
-
return {
|
|
308
|
-
page: {
|
|
309
|
-
kind: 'net-advancement',
|
|
310
|
-
roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),
|
|
311
|
-
documents,
|
|
312
|
-
revisions,
|
|
313
|
-
changes,
|
|
314
|
-
binaryTargets: [],
|
|
315
|
-
removals: removals.sort(),
|
|
316
|
-
},
|
|
317
|
-
entries: applied,
|
|
318
|
-
schemas,
|
|
319
|
-
};
|
|
320
470
|
},
|
|
321
471
|
};
|
|
322
472
|
}
|