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