@agentshouse/mdruntime-adapter 0.1.0-cf75412975d5b → 0.1.0-cf768be36486a
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 +9 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +139 -9
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +177 -186
- 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 -11
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +176 -31
- 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 +20 -28
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +106 -202
- 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 -61
- 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 +4 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +149 -79
- package/dist/transport.d.ts +64 -31
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +52 -16
- 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 -115
- 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 -911
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -496
- 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 -20
- package/dist/room-stream.d.ts.map +0 -1
- package/dist/room-stream.js +0 -78
- package/dist/room-types.d.ts +0 -7
- package/dist/room-types.d.ts.map +0 -1
- package/dist/room-types.js +0 -125
|
@@ -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,6 +1,6 @@
|
|
|
1
|
-
import { type AuthorityChange, type Discovery, type ConversationStream, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
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 HouseDoor, type
|
|
3
|
+
import { type HouseDoor, type HouseMode, type HouseStreamFrame } from './transport.js';
|
|
4
4
|
export type HouseOpeningFrame = Extract<HouseStreamFrame, {
|
|
5
5
|
type: 'opening';
|
|
6
6
|
}>;
|
|
@@ -10,14 +10,14 @@ export type HouseAuthorityChangedFrame = Extract<HouseStreamFrame, {
|
|
|
10
10
|
export type HouseDiscovering = {
|
|
11
11
|
opened(frame: HouseOpeningFrame | null): Promise<Discovery | null>;
|
|
12
12
|
changed(frame: HouseAuthorityChangedFrame): AuthorityChange | null;
|
|
13
|
+
expired?(entries: readonly TrackedAuthority[]): void;
|
|
13
14
|
};
|
|
14
15
|
export type HouseNotifications = {
|
|
15
16
|
runtime: string;
|
|
16
17
|
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
17
|
-
send(rooms: readonly
|
|
18
|
+
send(rooms: readonly HeldRoom[]): void;
|
|
18
19
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
19
20
|
conversations: ConversationStream;
|
|
20
21
|
serviceMode: ServiceModeSignal;
|
|
21
22
|
};
|
|
22
23
|
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering): HouseNotifications;
|
|
23
|
-
//# sourceMappingURL=stream.d.ts.map
|
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,EAGL,KAAK,eAAe,EAEpB,KAAK,SAAS,EACd,KAAK,kBAAkB,
|
|
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;AA4FF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,gBAAgB,GAC5B,kBAAkB,CA6XpB"}
|
package/dist/stream.js
CHANGED
|
@@ -1,38 +1,46 @@
|
|
|
1
1
|
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';
|
|
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
7
|
function turnOperation(frame) {
|
|
8
|
-
|
|
9
|
-
return structuredClone(operation);
|
|
8
|
+
return 'at' in frame ? { op: 'begin', at: frame.at } : structuredClone(frame.operation);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
+
telegram_messages: agent.telegram_messages,
|
|
26
|
+
created: agent.created,
|
|
27
|
+
retired_at: agent.retired_at,
|
|
28
|
+
};
|
|
22
29
|
}
|
|
23
30
|
function listedConversation(listed) {
|
|
24
31
|
return {
|
|
25
32
|
conversation: listed.conversation_id,
|
|
26
33
|
agent: listed.agent_id,
|
|
27
|
-
agentName: listed.agent_name,
|
|
28
|
-
agentRetired: listed.agent_retired,
|
|
29
34
|
name: listed.name,
|
|
30
35
|
created: listed.created_at,
|
|
31
|
-
finished: listed.finished_at,
|
|
32
36
|
outcome: listed.outcome,
|
|
33
37
|
waiting: listed.waiting,
|
|
34
|
-
newest: listed.newest === null ? null :
|
|
38
|
+
newest: listed.newest === null ? null : changeCursor(listed.newest),
|
|
35
39
|
processEnded: listed.process_ended_at,
|
|
40
|
+
subject: listed.subject,
|
|
41
|
+
room: listed.room_ref,
|
|
42
|
+
model: listed.model,
|
|
43
|
+
effort: listed.effort,
|
|
36
44
|
};
|
|
37
45
|
}
|
|
38
46
|
function position(value) {
|
|
@@ -40,63 +48,67 @@ function position(value) {
|
|
|
40
48
|
return null;
|
|
41
49
|
return BigInt(value);
|
|
42
50
|
}
|
|
43
|
-
function* changed(tracked, entries, version, schemas) {
|
|
51
|
+
function* changed(tracked, entries, version, mode, schemas) {
|
|
44
52
|
const answer = answering();
|
|
45
53
|
for (const entry of entries) {
|
|
46
|
-
yield ROW_WEIGHT + (entry.
|
|
54
|
+
yield ROW_WEIGHT + (entry.content?.length ?? 0);
|
|
47
55
|
if (entry.kind === 'folder') {
|
|
48
56
|
folded(answer, entry.path, entry.removed === true);
|
|
49
57
|
continue;
|
|
50
58
|
}
|
|
51
|
-
if (entry.path === tracked.schema)
|
|
52
|
-
schemas.set(entry.path, entry);
|
|
53
|
-
forgotten(answer, entry.path);
|
|
54
59
|
if (entry.kind === 'removed') {
|
|
60
|
+
if (entry.path === tracked.schema)
|
|
61
|
+
schemas.set(entry.path, null);
|
|
62
|
+
forgotten(answer, entry.path);
|
|
55
63
|
answer.removals.add(entry.path);
|
|
56
64
|
continue;
|
|
57
65
|
}
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
answer
|
|
66
|
+
const file = documentEntry(entry, mode);
|
|
67
|
+
if (file === null)
|
|
68
|
+
throw new Error(`the stream carried ${entry.path} as no file`);
|
|
69
|
+
if (entry.path === tracked.schema)
|
|
70
|
+
schemas.set(entry.path, file);
|
|
71
|
+
forgotten(answer, file.path);
|
|
72
|
+
if (file.space === undefined)
|
|
73
|
+
kept(answer, file);
|
|
66
74
|
else
|
|
67
|
-
answer.
|
|
68
|
-
const revision = entry.revision ?? binary?.sha256 ?? entry.sha256;
|
|
69
|
-
if (revision !== undefined)
|
|
70
|
-
revised(answer, entry.path, revision);
|
|
71
|
-
const head = headChange(entry);
|
|
72
|
-
if (head)
|
|
73
|
-
answer.changes.set(entry.path, head);
|
|
75
|
+
answer.removals.add(file.path);
|
|
74
76
|
}
|
|
75
77
|
return { kind: 'net-advancement', roomVersion: version, ...(yield* answered(answer)) };
|
|
76
78
|
}
|
|
77
|
-
async function changePage(tracked, entries, version, mode) {
|
|
79
|
+
async function changePage(tracked, entries, version, mode, whole) {
|
|
78
80
|
const schemas = new Map();
|
|
79
|
-
const page = await stepped(changed(tracked, entries, version, schemas));
|
|
80
|
-
const models = await streamedModels(schemas, tracked,
|
|
81
|
+
const page = await stepped(changed(tracked, entries, version, mode, schemas));
|
|
82
|
+
const models = await streamedModels(schemas, tracked, whole);
|
|
81
83
|
return models === undefined ? page : { ...page, models };
|
|
82
84
|
}
|
|
83
85
|
export function houseNotifications(transport, mode, discovering) {
|
|
84
86
|
const stream = transport.stream;
|
|
85
87
|
const staged = new Map();
|
|
88
|
+
let spaces = spaceSchemas();
|
|
86
89
|
let socket = null;
|
|
87
90
|
const tracking = new Map();
|
|
91
|
+
const located = new Map();
|
|
88
92
|
const observers = new Set();
|
|
93
|
+
const replaying = new Map();
|
|
89
94
|
const conversationObservers = new Set();
|
|
90
95
|
const modeObservers = new Set();
|
|
91
96
|
let replicated = [];
|
|
92
97
|
let listedCursor = null;
|
|
98
|
+
const unanswered = [];
|
|
99
|
+
const heldAtZero = new Set();
|
|
93
100
|
const live = new Set();
|
|
94
101
|
let opening = null;
|
|
95
102
|
let announced = null;
|
|
96
103
|
const runtime = crypto.randomUUID();
|
|
97
104
|
function emit(event) {
|
|
98
|
-
for (const observer of observers)
|
|
99
|
-
observer
|
|
105
|
+
for (const observer of observers) {
|
|
106
|
+
const held = replaying.get(observer);
|
|
107
|
+
if (held === undefined)
|
|
108
|
+
observer(event);
|
|
109
|
+
else
|
|
110
|
+
held.push(event);
|
|
111
|
+
}
|
|
100
112
|
}
|
|
101
113
|
function emitConversation(event) {
|
|
102
114
|
if (event.kind === 'turn' ||
|
|
@@ -105,8 +117,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
105
117
|
event.kind === 'commands' ||
|
|
106
118
|
event.kind === 'options' ||
|
|
107
119
|
event.kind === 'starting' ||
|
|
108
|
-
event.kind === '
|
|
109
|
-
event.kind === 'link' ||
|
|
120
|
+
event.kind === 'state' ||
|
|
110
121
|
event.kind === 'deliveries') {
|
|
111
122
|
live.add(event.conversation);
|
|
112
123
|
}
|
|
@@ -118,6 +129,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
118
129
|
announced = null;
|
|
119
130
|
socket = next;
|
|
120
131
|
staged.clear();
|
|
132
|
+
spaces = spaceSchemas();
|
|
133
|
+
unanswered.length = 0;
|
|
134
|
+
heldAtZero.clear();
|
|
121
135
|
const gapped = new Set([...replicated, ...live]);
|
|
122
136
|
live.clear();
|
|
123
137
|
for (const conversation of gapped)
|
|
@@ -136,9 +150,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
136
150
|
}
|
|
137
151
|
announced = { kind: 'discovered', discovery };
|
|
138
152
|
emit(announced);
|
|
139
|
-
}, () => {
|
|
153
|
+
}, (failure) => {
|
|
140
154
|
if (socket === via)
|
|
141
|
-
via.close();
|
|
155
|
+
via.close(failure);
|
|
142
156
|
});
|
|
143
157
|
}
|
|
144
158
|
function converse(frame) {
|
|
@@ -158,7 +172,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
158
172
|
return;
|
|
159
173
|
emitConversation({ kind: 'commands', conversation, commands: [] });
|
|
160
174
|
emitConversation({ kind: 'options', conversation, options: [] });
|
|
161
|
-
emitConversation({ kind: '
|
|
175
|
+
emitConversation({ kind: 'state', conversation, state: null });
|
|
162
176
|
return;
|
|
163
177
|
}
|
|
164
178
|
if (frame.type === 'commands') {
|
|
@@ -177,20 +191,17 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
177
191
|
emitConversation({ kind: 'starting', conversation, step: frame.step });
|
|
178
192
|
return;
|
|
179
193
|
}
|
|
180
|
-
if (frame.type === '
|
|
181
|
-
emitConversation({
|
|
182
|
-
kind: 'subagents',
|
|
183
|
-
conversation,
|
|
184
|
-
subagents: structuredClone(frame.subagents),
|
|
185
|
-
});
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (frame.type === 'link') {
|
|
189
|
-
emitConversation({ kind: 'link', conversation, connected: frame.connected });
|
|
194
|
+
if (frame.type === 'state') {
|
|
195
|
+
emitConversation({ kind: 'state', conversation, state: structuredClone(frame.state) });
|
|
190
196
|
return;
|
|
191
197
|
}
|
|
192
198
|
if (frame.type === 'deliveries') {
|
|
193
|
-
emitConversation({
|
|
199
|
+
emitConversation({
|
|
200
|
+
kind: 'deliveries',
|
|
201
|
+
conversation,
|
|
202
|
+
waiting: [...frame.waiting],
|
|
203
|
+
unknown: [...frame.unknown],
|
|
204
|
+
});
|
|
194
205
|
return;
|
|
195
206
|
}
|
|
196
207
|
if (frame.type === 'interactions') {
|
|
@@ -207,6 +218,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
207
218
|
emitConversation({ kind: 'accepted-message', conversation, message });
|
|
208
219
|
}
|
|
209
220
|
function stage(frame, via) {
|
|
221
|
+
const entries = spaceSchemaTexts(frame.entries, spaces);
|
|
210
222
|
const held = staged.get(frame.carry);
|
|
211
223
|
if (frame.index !== (held?.parts ?? 0)) {
|
|
212
224
|
staged.delete(frame.carry);
|
|
@@ -219,7 +231,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
219
231
|
}
|
|
220
232
|
}
|
|
221
233
|
const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
|
|
222
|
-
next.entries.push(...
|
|
234
|
+
next.entries.push(...entries);
|
|
223
235
|
next.parts += 1;
|
|
224
236
|
staged.set(frame.carry, next);
|
|
225
237
|
via?.received(frame.authority, frame.carry, frame.index);
|
|
@@ -246,12 +258,18 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
246
258
|
return;
|
|
247
259
|
}
|
|
248
260
|
if (frame.type === 'caught_up') {
|
|
261
|
+
const expired = frame.expired.flatMap((authority) => tracking.get(authority) ?? []);
|
|
262
|
+
discovering.expired?.(expired);
|
|
249
263
|
emit({
|
|
250
264
|
kind: 'caught-up',
|
|
251
|
-
expired:
|
|
265
|
+
expired: [...expired.map(({ locator }) => locator), ...(unanswered.shift() ?? [])],
|
|
252
266
|
});
|
|
253
267
|
return;
|
|
254
268
|
}
|
|
269
|
+
if (frame.type === 'report') {
|
|
270
|
+
emit({ kind: 'reported' });
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
255
273
|
if (frame.type === 'authority_changed') {
|
|
256
274
|
const change = discovering.changed(frame);
|
|
257
275
|
if (change !== null)
|
|
@@ -261,6 +279,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
261
279
|
if (frame.type === 'conversations') {
|
|
262
280
|
emitConversation({
|
|
263
281
|
kind: 'list',
|
|
282
|
+
agents: frame.agents.map(listedAgent),
|
|
264
283
|
entries: frame.conversations.map(listedConversation),
|
|
265
284
|
whole: frame.whole,
|
|
266
285
|
more: frame.more,
|
|
@@ -272,6 +291,10 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
272
291
|
emitConversation({ kind: 'listed', entry: listedConversation(frame.conversation) });
|
|
273
292
|
return;
|
|
274
293
|
}
|
|
294
|
+
if (frame.type === 'agent') {
|
|
295
|
+
emitConversation({ kind: 'agent', agent: listedAgent(frame.agent) });
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
275
298
|
if (frame.type === 'conversation_deleted') {
|
|
276
299
|
emitConversation({ kind: 'unlisted', conversation: frame.conversation_id });
|
|
277
300
|
return;
|
|
@@ -281,8 +304,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
281
304
|
frame.type === 'commands' ||
|
|
282
305
|
frame.type === 'options' ||
|
|
283
306
|
frame.type === 'starting' ||
|
|
284
|
-
frame.type === '
|
|
285
|
-
frame.type === 'link' ||
|
|
307
|
+
frame.type === 'state' ||
|
|
286
308
|
frame.type === 'deliveries' ||
|
|
287
309
|
frame.type === 'interactions' ||
|
|
288
310
|
frame.type === 'message') {
|
|
@@ -299,7 +321,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
299
321
|
const after = position(frame.after);
|
|
300
322
|
if (at === null || after === null || after >= at)
|
|
301
323
|
return;
|
|
302
|
-
const from =
|
|
324
|
+
const from = after === 0n && !heldAtZero.has(frame.authority)
|
|
325
|
+
? null
|
|
326
|
+
: roomVersion({ position: frame.after, logEpoch: frame.log_epoch });
|
|
303
327
|
const version = roomVersion({ position: frame.position, logEpoch: frame.log_epoch });
|
|
304
328
|
for (const tracked of tracking.get(frame.authority) ?? []) {
|
|
305
329
|
emit({
|
|
@@ -307,7 +331,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
307
331
|
locator: tracked.locator,
|
|
308
332
|
from,
|
|
309
333
|
roomVersion: version,
|
|
310
|
-
read: () => changePage(tracked, entries, version, mode),
|
|
334
|
+
read: () => changePage(tracked, entries, version, mode, from === null),
|
|
311
335
|
});
|
|
312
336
|
}
|
|
313
337
|
}
|
|
@@ -318,6 +342,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
318
342
|
announced = null;
|
|
319
343
|
socket = null;
|
|
320
344
|
staged.clear();
|
|
345
|
+
spaces = spaceSchemas();
|
|
346
|
+
unanswered.length = 0;
|
|
347
|
+
heldAtZero.clear();
|
|
321
348
|
emit({ kind: 'closed', revoked, lost, authorityChanged });
|
|
322
349
|
});
|
|
323
350
|
return {
|
|
@@ -343,20 +370,19 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
343
370
|
conversationObservers.delete(notify);
|
|
344
371
|
};
|
|
345
372
|
},
|
|
346
|
-
...(mode === 'credential'
|
|
347
|
-
? {
|
|
348
|
-
agents: () => houseAgents(transport),
|
|
349
|
-
history: (request) => houseHistory(transport, request),
|
|
350
|
-
}
|
|
351
|
-
: {}),
|
|
373
|
+
...(mode === 'credential' ? { history: (request) => houseHistory(transport, request) } : {}),
|
|
352
374
|
},
|
|
353
375
|
observe(notify) {
|
|
354
376
|
observers.add(notify);
|
|
355
|
-
|
|
356
|
-
|
|
377
|
+
if (opening !== null) {
|
|
378
|
+
const replayed = [{ kind: 'opened' }];
|
|
379
|
+
if (announced !== null)
|
|
380
|
+
replayed.push(announced);
|
|
381
|
+
replaying.set(notify, replayed);
|
|
357
382
|
queueMicrotask(() => {
|
|
383
|
+
replaying.delete(notify);
|
|
358
384
|
for (const event of replayed)
|
|
359
|
-
if (
|
|
385
|
+
if (observers.has(notify))
|
|
360
386
|
notify(event);
|
|
361
387
|
});
|
|
362
388
|
}
|
|
@@ -367,13 +393,57 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
367
393
|
send(rooms) {
|
|
368
394
|
opening = null;
|
|
369
395
|
announced = null;
|
|
370
|
-
socket
|
|
396
|
+
if (socket === null)
|
|
397
|
+
return;
|
|
398
|
+
const named = rooms.flatMap((room) => {
|
|
399
|
+
const entry = located.get(room.locator);
|
|
400
|
+
const at = room.roomVersion === null ? null : logPosition(room.roomVersion);
|
|
401
|
+
return entry === undefined || at === null ? [] : [{ entry, at }];
|
|
402
|
+
});
|
|
403
|
+
const unheld = rooms.flatMap((room) => {
|
|
404
|
+
const entry = located.get(room.locator);
|
|
405
|
+
return entry === undefined || room.roomVersion !== null ? [] : [entry];
|
|
406
|
+
});
|
|
407
|
+
for (const { entry, at } of named) {
|
|
408
|
+
if (at.position === '0')
|
|
409
|
+
heldAtZero.add(entry.authority);
|
|
410
|
+
else
|
|
411
|
+
heldAtZero.delete(entry.authority);
|
|
412
|
+
}
|
|
413
|
+
for (const entry of unheld)
|
|
414
|
+
heldAtZero.delete(entry.authority);
|
|
415
|
+
const site = mode === 'site';
|
|
416
|
+
unanswered.push(site ? unheld.map((entry) => entry.locator) : []);
|
|
417
|
+
socket.hold([
|
|
418
|
+
...named.map(({ entry, at }) => presented(entry.authority, at)),
|
|
419
|
+
...(site ? [] : unheld).map((entry) => presented(entry.authority, { position: '0', logEpoch: entry.logEpoch })),
|
|
420
|
+
], runtime, listedCursor);
|
|
421
|
+
if (site)
|
|
422
|
+
return;
|
|
423
|
+
const made = unheld.filter((entry) => entry.position === '0');
|
|
424
|
+
queueMicrotask(() => {
|
|
425
|
+
for (const entry of made) {
|
|
426
|
+
const version = roomVersion(entry);
|
|
427
|
+
emit({
|
|
428
|
+
kind: 'room-change',
|
|
429
|
+
locator: entry.locator,
|
|
430
|
+
from: null,
|
|
431
|
+
roomVersion: version,
|
|
432
|
+
read: () => changePage(entry, [], version, mode, true),
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
});
|
|
371
436
|
},
|
|
372
437
|
track(entries) {
|
|
373
438
|
tracking.clear();
|
|
439
|
+
located.clear();
|
|
374
440
|
for (const entry of entries) {
|
|
375
441
|
tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
|
|
376
442
|
}
|
|
443
|
+
for (const held of tracking.values()) {
|
|
444
|
+
for (const entry of held)
|
|
445
|
+
located.set(entry.locator, entry);
|
|
446
|
+
}
|
|
377
447
|
for (const [carry, held] of staged) {
|
|
378
448
|
if (!tracking.has(held.authority))
|
|
379
449
|
staged.delete(carry);
|