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