@agentshouse/mdruntime-adapter 0.1.0-cca5d676bc88e → 0.1.0-ccc7c7aecd1ac
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 -328
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +314 -222
- 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/discovery.d.ts +46 -20
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +266 -67
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -6
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +35 -38
- package/dist/read.d.ts +54 -48
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +182 -266
- package/dist/refusal.d.ts +10 -13
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +54 -24
- package/dist/room-query.d.ts +4 -0
- package/dist/room-query.d.ts.map +1 -0
- package/dist/room-query.js +36 -0
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/check.d.ts +17 -0
- package/dist/session-content/index.d.ts +6 -0
- package/dist/session-content/parts.d.ts +30 -0
- package/dist/session-content/state.d.ts +59 -0
- package/dist/session-content/turn.d.ts +137 -0
- package/dist/site.d.ts +1 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +139 -107
- 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 -13
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +282 -148
- package/dist/transport.d.ts +125 -30
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +90 -10
- 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 +183 -78
- package/package.json +10 -6
- package/AGENTS.md +0 -231
- 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
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type SpaceSchemas = {
|
|
2
|
+
held(space: string, revision: string): string | undefined;
|
|
3
|
+
keep(space: string, revision: string, text: string): void;
|
|
4
|
+
};
|
|
5
|
+
export declare function spaceSchemas(): SpaceSchemas;
|
|
6
|
+
export declare function spaceIdentity(space: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space-schema.d.ts","sourceRoot":"","sources":["../src/space-schema.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC1D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3D,CAAC;AAEF,wBAAgB,YAAY,IAAI,YAAY,CAO3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function spaceSchemas() {
|
|
2
|
+
const texts = new Map();
|
|
3
|
+
const key = (space, revision) => `${space} ${revision}`;
|
|
4
|
+
return {
|
|
5
|
+
held: (space, revision) => texts.get(key(space, revision)),
|
|
6
|
+
keep: (space, revision, text) => void texts.set(key(space, revision), text),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function spaceIdentity(space) {
|
|
10
|
+
return `space:${space}`;
|
|
11
|
+
}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import { type HouseDoor, type HouseMode, type HouseStreamFrame } from './transport.js';
|
|
4
|
+
export type HouseOpeningFrame = Extract<HouseStreamFrame, {
|
|
5
|
+
type: 'opening';
|
|
6
|
+
}>;
|
|
7
|
+
export type HouseAuthorityChangedFrame = Extract<HouseStreamFrame, {
|
|
8
|
+
type: 'authority_changed';
|
|
9
|
+
}>;
|
|
10
|
+
export type HouseDiscovering = {
|
|
11
|
+
opened(frame: HouseOpeningFrame | null): Promise<Discovery | null>;
|
|
12
|
+
changed(frame: HouseAuthorityChangedFrame): AuthorityChange | null;
|
|
13
|
+
expired?(entries: readonly TrackedAuthority[]): void;
|
|
10
14
|
};
|
|
11
15
|
export type HouseNotifications = {
|
|
12
16
|
runtime: string;
|
|
13
17
|
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
14
|
-
send(rooms: readonly
|
|
18
|
+
send(rooms: readonly HeldRoom[]): void;
|
|
15
19
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
16
|
-
reach(authority: string, at: LogPosition): void;
|
|
17
|
-
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): StreamedAdvancement | null;
|
|
18
20
|
conversations: ConversationStream;
|
|
19
21
|
serviceMode: ServiceModeSignal;
|
|
20
22
|
};
|
|
21
|
-
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
|
|
22
|
-
//# sourceMappingURL=stream.d.ts.map
|
|
23
|
+
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering): 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,EAGL,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;AAYvD,OAAO,EACL,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,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,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAyFF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,gBAAgB,GAC5B,kBAAkB,CAoYpB"}
|
package/dist/stream.js
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { acceptedMessage, changeCursor, houseHistory } from './history.js';
|
|
3
|
+
import { spaceSchemaTexts, streamedModels } from './model.js';
|
|
4
|
+
import { spaceSchemas } from './space-schema.js';
|
|
5
|
+
import { answered, answering, documentEntry, folded, forgotten, kept, } from './read.js';
|
|
6
|
+
import { DECIMAL, logPosition, presented, roomVersion } from './version.js';
|
|
5
7
|
function turnOperation(frame) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
return 'at' in frame ? { op: 'begin', at: frame.at } : structuredClone(frame.operation);
|
|
9
|
+
}
|
|
10
|
+
function listedAgent(agent) {
|
|
11
|
+
return {
|
|
12
|
+
id: agent.id,
|
|
13
|
+
name: agent.name,
|
|
14
|
+
revision: agent.revision,
|
|
15
|
+
environment: agent.environment,
|
|
16
|
+
environment_name: agent.environment_name,
|
|
17
|
+
environment_connected: agent.environment_connected,
|
|
18
|
+
launch_directory: agent.launch_directory,
|
|
19
|
+
cli: agent.cli,
|
|
20
|
+
model: agent.model,
|
|
21
|
+
effort: agent.effort,
|
|
22
|
+
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
|
+
};
|
|
8
28
|
}
|
|
9
29
|
function listedConversation(listed) {
|
|
10
30
|
return {
|
|
@@ -14,34 +34,89 @@ function listedConversation(listed) {
|
|
|
14
34
|
created: listed.created_at,
|
|
15
35
|
finished: listed.finished_at,
|
|
16
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,
|
|
17
41
|
};
|
|
18
42
|
}
|
|
19
43
|
function position(value) {
|
|
20
|
-
if (
|
|
44
|
+
if (!DECIMAL.test(value))
|
|
21
45
|
return null;
|
|
22
46
|
return BigInt(value);
|
|
23
47
|
}
|
|
24
|
-
|
|
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 };
|
|
81
|
+
}
|
|
82
|
+
export function houseNotifications(transport, mode, discovering) {
|
|
25
83
|
const stream = transport.stream;
|
|
26
|
-
const
|
|
27
|
-
|
|
84
|
+
const staged = new Map();
|
|
85
|
+
let spaces = spaceSchemas();
|
|
86
|
+
let socket = null;
|
|
87
|
+
const tracking = new Map();
|
|
88
|
+
const located = new Map();
|
|
28
89
|
const observers = new Set();
|
|
90
|
+
const replaying = new Map();
|
|
29
91
|
const conversationObservers = new Set();
|
|
30
92
|
const modeObservers = new Set();
|
|
31
93
|
let replicated = [];
|
|
94
|
+
let listedCursor = null;
|
|
95
|
+
const unanswered = [];
|
|
96
|
+
const heldAtZero = new Set();
|
|
32
97
|
const live = new Set();
|
|
33
98
|
let opening = null;
|
|
99
|
+
let announced = null;
|
|
34
100
|
const runtime = crypto.randomUUID();
|
|
35
101
|
function emit(event) {
|
|
36
|
-
for (const observer of observers)
|
|
37
|
-
observer
|
|
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);
|
|
108
|
+
}
|
|
38
109
|
}
|
|
39
110
|
function emitConversation(event) {
|
|
40
111
|
if (event.kind === 'turn' ||
|
|
41
112
|
event.kind === 'questions' ||
|
|
42
113
|
event.kind === 'process' ||
|
|
43
114
|
event.kind === 'commands' ||
|
|
44
|
-
event.kind === 'options'
|
|
115
|
+
event.kind === 'options' ||
|
|
116
|
+
event.kind === 'starting' ||
|
|
117
|
+
event.kind === 'state' ||
|
|
118
|
+
event.kind === 'link' ||
|
|
119
|
+
event.kind === 'deliveries') {
|
|
45
120
|
live.add(event.conversation);
|
|
46
121
|
}
|
|
47
122
|
for (const observer of conversationObservers)
|
|
@@ -49,11 +124,34 @@ export function houseNotifications(transport, mode) {
|
|
|
49
124
|
}
|
|
50
125
|
function reopened(next) {
|
|
51
126
|
opening = next;
|
|
127
|
+
announced = null;
|
|
128
|
+
socket = next;
|
|
129
|
+
staged.clear();
|
|
130
|
+
spaces = spaceSchemas();
|
|
131
|
+
unanswered.length = 0;
|
|
132
|
+
heldAtZero.clear();
|
|
52
133
|
const gapped = new Set([...replicated, ...live]);
|
|
53
134
|
live.clear();
|
|
54
135
|
for (const conversation of gapped)
|
|
55
136
|
emitConversation({ kind: 'gap', conversation });
|
|
56
137
|
emit({ kind: 'opened' });
|
|
138
|
+
if (mode === 'site')
|
|
139
|
+
announce(next, null);
|
|
140
|
+
}
|
|
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);
|
|
154
|
+
});
|
|
57
155
|
}
|
|
58
156
|
function converse(frame) {
|
|
59
157
|
const conversation = frame.conversation_id;
|
|
@@ -72,6 +170,7 @@ export function houseNotifications(transport, mode) {
|
|
|
72
170
|
return;
|
|
73
171
|
emitConversation({ kind: 'commands', conversation, commands: [] });
|
|
74
172
|
emitConversation({ kind: 'options', conversation, options: [] });
|
|
173
|
+
emitConversation({ kind: 'state', conversation, state: null });
|
|
75
174
|
return;
|
|
76
175
|
}
|
|
77
176
|
if (frame.type === 'commands') {
|
|
@@ -86,6 +185,27 @@ export function houseNotifications(transport, mode) {
|
|
|
86
185
|
emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });
|
|
87
186
|
return;
|
|
88
187
|
}
|
|
188
|
+
if (frame.type === 'starting') {
|
|
189
|
+
emitConversation({ kind: 'starting', conversation, step: frame.step });
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
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') {
|
|
201
|
+
emitConversation({
|
|
202
|
+
kind: 'deliveries',
|
|
203
|
+
conversation,
|
|
204
|
+
waiting: [...frame.waiting],
|
|
205
|
+
unknown: [...frame.unknown],
|
|
206
|
+
});
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
89
209
|
if (frame.type === 'interactions') {
|
|
90
210
|
emitConversation({
|
|
91
211
|
kind: 'questions',
|
|
@@ -99,18 +219,33 @@ export function houseNotifications(transport, mode) {
|
|
|
99
219
|
return;
|
|
100
220
|
emitConversation({ kind: 'accepted-message', conversation, message });
|
|
101
221
|
}
|
|
102
|
-
function
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
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
|
+
}
|
|
106
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);
|
|
107
240
|
}
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
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 ?? []);
|
|
112
247
|
}
|
|
113
|
-
function
|
|
248
|
+
function handle(frame, via) {
|
|
114
249
|
if (frame.type === 'signal') {
|
|
115
250
|
const mode = frame.service_mode;
|
|
116
251
|
if (mode !== 'open' && mode !== 'write-halted')
|
|
@@ -120,20 +255,48 @@ export function houseNotifications(transport, mode) {
|
|
|
120
255
|
return;
|
|
121
256
|
}
|
|
122
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);
|
|
123
265
|
emit({
|
|
124
|
-
kind: '
|
|
125
|
-
expired:
|
|
266
|
+
kind: 'caught-up',
|
|
267
|
+
expired: [...expired.map(({ locator }) => locator), ...(unanswered.shift() ?? [])],
|
|
126
268
|
});
|
|
127
269
|
return;
|
|
128
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
|
+
}
|
|
129
281
|
if (frame.type === 'conversations') {
|
|
130
|
-
emitConversation({
|
|
282
|
+
emitConversation({
|
|
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,
|
|
289
|
+
});
|
|
131
290
|
return;
|
|
132
291
|
}
|
|
133
292
|
if (frame.type === 'conversation') {
|
|
134
293
|
emitConversation({ kind: 'listed', entry: listedConversation(frame.conversation) });
|
|
135
294
|
return;
|
|
136
295
|
}
|
|
296
|
+
if (frame.type === 'agent') {
|
|
297
|
+
emitConversation({ kind: 'agent', agent: listedAgent(frame.agent) });
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
137
300
|
if (frame.type === 'conversation_deleted') {
|
|
138
301
|
emitConversation({ kind: 'unlisted', conversation: frame.conversation_id });
|
|
139
302
|
return;
|
|
@@ -142,40 +305,50 @@ export function houseNotifications(transport, mode) {
|
|
|
142
305
|
frame.type === 'process' ||
|
|
143
306
|
frame.type === 'commands' ||
|
|
144
307
|
frame.type === 'options' ||
|
|
308
|
+
frame.type === 'starting' ||
|
|
309
|
+
frame.type === 'state' ||
|
|
310
|
+
frame.type === 'link' ||
|
|
311
|
+
frame.type === 'deliveries' ||
|
|
145
312
|
frame.type === 'interactions' ||
|
|
146
313
|
frame.type === 'message') {
|
|
147
314
|
converse(frame);
|
|
148
315
|
return;
|
|
149
316
|
}
|
|
150
|
-
if (frame.type
|
|
151
|
-
|
|
317
|
+
if (frame.type === 'part')
|
|
318
|
+
stage(frame, via);
|
|
319
|
+
else if (frame.type === 'carried')
|
|
320
|
+
carried(frame);
|
|
321
|
+
}
|
|
322
|
+
function publish(frame, entries) {
|
|
152
323
|
const at = position(frame.position);
|
|
153
324
|
const after = position(frame.after);
|
|
154
|
-
if (at === null || after === null || after >= at)
|
|
155
|
-
interrupt(frame.authority);
|
|
325
|
+
if (at === null || after === null || after >= at)
|
|
156
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),
|
|
338
|
+
});
|
|
157
339
|
}
|
|
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
340
|
}
|
|
174
|
-
stream.observe(
|
|
341
|
+
stream.observe((frame) => handle(frame, socket));
|
|
175
342
|
stream.opened(reopened);
|
|
176
|
-
stream.closed((revoked) => {
|
|
343
|
+
stream.closed(({ revoked, lost, authorityChanged }) => {
|
|
177
344
|
opening = null;
|
|
178
|
-
|
|
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 });
|
|
179
352
|
});
|
|
180
353
|
return {
|
|
181
354
|
runtime,
|
|
@@ -191,19 +364,29 @@ export function houseNotifications(transport, mode) {
|
|
|
191
364
|
replicate(next) {
|
|
192
365
|
replicated = [...next];
|
|
193
366
|
},
|
|
367
|
+
hold(cursor) {
|
|
368
|
+
listedCursor = cursor;
|
|
369
|
+
},
|
|
194
370
|
observe(notify) {
|
|
195
371
|
conversationObservers.add(notify);
|
|
196
372
|
return () => {
|
|
197
373
|
conversationObservers.delete(notify);
|
|
198
374
|
};
|
|
199
375
|
},
|
|
376
|
+
...(mode === 'credential' ? { history: (request) => houseHistory(transport, request) } : {}),
|
|
200
377
|
},
|
|
201
378
|
observe(notify) {
|
|
202
379
|
observers.add(notify);
|
|
203
380
|
if (opening !== null) {
|
|
381
|
+
const replayed = [{ kind: 'opened' }];
|
|
382
|
+
if (announced !== null)
|
|
383
|
+
replayed.push(announced);
|
|
384
|
+
replaying.set(notify, replayed);
|
|
204
385
|
queueMicrotask(() => {
|
|
205
|
-
|
|
206
|
-
|
|
386
|
+
replaying.delete(notify);
|
|
387
|
+
for (const event of replayed)
|
|
388
|
+
if (observers.has(notify))
|
|
389
|
+
notify(event);
|
|
207
390
|
});
|
|
208
391
|
}
|
|
209
392
|
return () => {
|
|
@@ -211,112 +394,63 @@ export function houseNotifications(transport, mode) {
|
|
|
211
394
|
};
|
|
212
395
|
},
|
|
213
396
|
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
397
|
opening = null;
|
|
223
|
-
|
|
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);
|
|
415
|
+
}
|
|
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
|
+
}
|
|
438
|
+
});
|
|
224
439
|
},
|
|
225
440
|
track(entries) {
|
|
226
|
-
|
|
441
|
+
tracking.clear();
|
|
442
|
+
located.clear();
|
|
227
443
|
for (const entry of entries) {
|
|
228
|
-
|
|
229
|
-
if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {
|
|
230
|
-
lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [], held: null });
|
|
231
|
-
}
|
|
444
|
+
tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
|
|
232
445
|
}
|
|
233
|
-
for (const
|
|
234
|
-
|
|
235
|
-
|
|
446
|
+
for (const held of tracking.values()) {
|
|
447
|
+
for (const entry of held)
|
|
448
|
+
located.set(entry.locator, entry);
|
|
236
449
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const held = position(at.position);
|
|
241
|
-
if (line === undefined || held === null || line.logEpoch !== at.logEpoch)
|
|
242
|
-
return;
|
|
243
|
-
if (line.held !== null && held <= line.held)
|
|
244
|
-
return;
|
|
245
|
-
lines.set(authority, {
|
|
246
|
-
...line,
|
|
247
|
-
frames: line.frames.filter((frame) => frame.position > held),
|
|
248
|
-
held,
|
|
249
|
-
});
|
|
250
|
-
},
|
|
251
|
-
advance(tracked, from, holds) {
|
|
252
|
-
const line = lines.get(tracked.authority);
|
|
253
|
-
const start = position(from.position);
|
|
254
|
-
if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
|
|
255
|
-
return null;
|
|
256
|
-
const pending = line.frames.filter((frame) => frame.position > start);
|
|
257
|
-
const first = pending[0];
|
|
258
|
-
if (first === undefined || first.after > start)
|
|
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
|
-
}
|
|
450
|
+
for (const [carry, held] of staged) {
|
|
451
|
+
if (!tracking.has(held.authority))
|
|
452
|
+
staged.delete(carry);
|
|
304
453
|
}
|
|
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
454
|
},
|
|
321
455
|
};
|
|
322
456
|
}
|