@agentshouse/mdruntime-adapter 0.1.0-c1ae4a2aa7934 → 0.1.0-c1ed76857ddce
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 +3 -4
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +10 -327
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +279 -208
- package/dist/app-reference.d.ts +2 -0
- package/dist/app-reference.d.ts.map +1 -0
- package/dist/app-reference.js +2 -0
- package/dist/crockford.d.ts +4 -0
- package/dist/crockford.d.ts.map +1 -0
- package/dist/crockford.js +3 -0
- package/dist/discovery.d.ts +16 -15
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +77 -52
- package/dist/history.d.ts +12 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +91 -0
- package/dist/house-model.d.ts +955 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +521 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/model.d.ts +6 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +23 -28
- package/dist/part.d.ts +14 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +90 -0
- package/dist/read.d.ts +52 -41
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +248 -234
- package/dist/refusal.d.ts +4 -11
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +26 -17
- package/dist/room-stream.d.ts +19 -0
- package/dist/room-stream.d.ts.map +1 -0
- package/dist/room-stream.js +57 -0
- package/dist/room-types.d.ts +7 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +125 -0
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +128 -104
- package/dist/stream.d.ts +12 -11
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +201 -146
- package/dist/transport.d.ts +88 -24
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +54 -10
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/write.d.ts +18 -9
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +169 -47
- package/package.json +9 -6
- package/AGENTS.md +0 -232
- package/dist/gather.d.ts +0 -3
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -40
- package/dist/links.d.ts +0 -20
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -104
package/dist/stream.js
CHANGED
|
@@ -1,36 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { acceptedMessage, cursorPosition, houseHistory } from './history.js';
|
|
3
|
+
import { streamedModels } from './model.js';
|
|
4
|
+
import { answered, answering, binaryFileOf, folded, forgotten, headChange, revised, } from './read.js';
|
|
5
|
+
import { houseDoorRoute, } from './transport.js';
|
|
6
|
+
import { DECIMAL, roomVersion } from './version.js';
|
|
5
7
|
function turnOperation(frame) {
|
|
6
8
|
const { type: _type, conversation_id: _conversation, turn_id: _turn, ...operation } = frame;
|
|
7
9
|
return structuredClone(operation);
|
|
8
10
|
}
|
|
11
|
+
async function houseAgents(transport) {
|
|
12
|
+
const answer = await transport.door(houseDoorRoute('agents/read'), {});
|
|
13
|
+
const agents = answer.status === 200 ? answer.body?.agents : null;
|
|
14
|
+
if (!Array.isArray(agents))
|
|
15
|
+
return null;
|
|
16
|
+
return agents.flatMap((one) => {
|
|
17
|
+
const { id, name, retired_at: retired } = (one ?? {});
|
|
18
|
+
return typeof id === 'string' && typeof name === 'string'
|
|
19
|
+
? [{ agent: id, name, retired: retired !== null && retired !== undefined }]
|
|
20
|
+
: [];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
9
23
|
function listedConversation(listed) {
|
|
10
24
|
return {
|
|
11
25
|
conversation: listed.conversation_id,
|
|
12
26
|
agent: listed.agent_id,
|
|
27
|
+
agentName: listed.agent_name,
|
|
28
|
+
agentRetired: listed.agent_retired,
|
|
13
29
|
name: listed.name,
|
|
14
30
|
created: listed.created_at,
|
|
15
31
|
finished: listed.finished_at,
|
|
16
32
|
outcome: listed.outcome,
|
|
33
|
+
waiting: listed.waiting,
|
|
34
|
+
newest: listed.newest === null ? null : cursorPosition(listed.newest),
|
|
17
35
|
};
|
|
18
36
|
}
|
|
19
37
|
function position(value) {
|
|
20
|
-
if (
|
|
38
|
+
if (!DECIMAL.test(value))
|
|
21
39
|
return null;
|
|
22
40
|
return BigInt(value);
|
|
23
41
|
}
|
|
24
|
-
|
|
42
|
+
function* changed(tracked, entries, version, schemas) {
|
|
43
|
+
const answer = answering();
|
|
44
|
+
for (const entry of entries) {
|
|
45
|
+
yield ROW_WEIGHT + (entry.text?.length ?? 0);
|
|
46
|
+
if (entry.kind === 'folder') {
|
|
47
|
+
folded(answer, entry.path, entry.removed === true);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (entry.path === tracked.schema)
|
|
51
|
+
schemas.set(entry.path, entry);
|
|
52
|
+
forgotten(answer, entry.path);
|
|
53
|
+
if (entry.kind === 'removed') {
|
|
54
|
+
answer.removals.add(entry.path);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const binary = binaryFileOf(entry);
|
|
58
|
+
if (binary === undefined)
|
|
59
|
+
answer.documents.set(entry.path, entry.text ?? '');
|
|
60
|
+
else if (binary !== null)
|
|
61
|
+
answer.binaryFiles.set(entry.path, binary);
|
|
62
|
+
const revision = entry.revision ?? binary?.sha256;
|
|
63
|
+
if (revision !== undefined)
|
|
64
|
+
revised(answer, entry.path, revision);
|
|
65
|
+
const head = headChange(entry);
|
|
66
|
+
if (head)
|
|
67
|
+
answer.changes.set(entry.path, head);
|
|
68
|
+
}
|
|
69
|
+
return { kind: 'net-advancement', roomVersion: version, ...(yield* answered(answer)) };
|
|
70
|
+
}
|
|
71
|
+
async function changePage(tracked, entries, version, mode) {
|
|
72
|
+
const schemas = new Map();
|
|
73
|
+
const page = await stepped(changed(tracked, entries, version, schemas));
|
|
74
|
+
const models = await streamedModels(schemas, tracked, mode);
|
|
75
|
+
return models === undefined ? page : { ...page, models };
|
|
76
|
+
}
|
|
77
|
+
export function houseNotifications(transport, mode, discovering) {
|
|
25
78
|
const stream = transport.stream;
|
|
26
|
-
const
|
|
27
|
-
|
|
79
|
+
const staged = new Map();
|
|
80
|
+
let socket = null;
|
|
81
|
+
const tracking = new Map();
|
|
28
82
|
const observers = new Set();
|
|
29
83
|
const conversationObservers = new Set();
|
|
30
84
|
const modeObservers = new Set();
|
|
31
85
|
let replicated = [];
|
|
86
|
+
let listedCursor = null;
|
|
32
87
|
const live = new Set();
|
|
33
88
|
let opening = null;
|
|
89
|
+
let announced = null;
|
|
34
90
|
const runtime = crypto.randomUUID();
|
|
35
91
|
function emit(event) {
|
|
36
92
|
for (const observer of observers)
|
|
@@ -41,7 +97,11 @@ export function houseNotifications(transport, mode) {
|
|
|
41
97
|
event.kind === 'questions' ||
|
|
42
98
|
event.kind === 'process' ||
|
|
43
99
|
event.kind === 'commands' ||
|
|
44
|
-
event.kind === 'options'
|
|
100
|
+
event.kind === 'options' ||
|
|
101
|
+
event.kind === 'starting' ||
|
|
102
|
+
event.kind === 'subagents' ||
|
|
103
|
+
event.kind === 'link' ||
|
|
104
|
+
event.kind === 'deliveries') {
|
|
45
105
|
live.add(event.conversation);
|
|
46
106
|
}
|
|
47
107
|
for (const observer of conversationObservers)
|
|
@@ -49,11 +109,31 @@ export function houseNotifications(transport, mode) {
|
|
|
49
109
|
}
|
|
50
110
|
function reopened(next) {
|
|
51
111
|
opening = next;
|
|
112
|
+
announced = null;
|
|
113
|
+
socket = next;
|
|
114
|
+
staged.clear();
|
|
52
115
|
const gapped = new Set([...replicated, ...live]);
|
|
53
116
|
live.clear();
|
|
54
117
|
for (const conversation of gapped)
|
|
55
118
|
emitConversation({ kind: 'gap', conversation });
|
|
56
119
|
emit({ kind: 'opened' });
|
|
120
|
+
if (mode === 'site')
|
|
121
|
+
announce(next, null);
|
|
122
|
+
}
|
|
123
|
+
function announce(via, frame) {
|
|
124
|
+
void discovering.opened(frame).then((discovery) => {
|
|
125
|
+
if (socket !== via)
|
|
126
|
+
return;
|
|
127
|
+
if (discovery === null) {
|
|
128
|
+
via.close();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
announced = { kind: 'discovered', discovery };
|
|
132
|
+
emit(announced);
|
|
133
|
+
}, () => {
|
|
134
|
+
if (socket === via)
|
|
135
|
+
via.close();
|
|
136
|
+
});
|
|
57
137
|
}
|
|
58
138
|
function converse(frame) {
|
|
59
139
|
const conversation = frame.conversation_id;
|
|
@@ -72,6 +152,7 @@ export function houseNotifications(transport, mode) {
|
|
|
72
152
|
return;
|
|
73
153
|
emitConversation({ kind: 'commands', conversation, commands: [] });
|
|
74
154
|
emitConversation({ kind: 'options', conversation, options: [] });
|
|
155
|
+
emitConversation({ kind: 'subagents', conversation, subagents: [] });
|
|
75
156
|
return;
|
|
76
157
|
}
|
|
77
158
|
if (frame.type === 'commands') {
|
|
@@ -86,6 +167,26 @@ export function houseNotifications(transport, mode) {
|
|
|
86
167
|
emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });
|
|
87
168
|
return;
|
|
88
169
|
}
|
|
170
|
+
if (frame.type === 'starting') {
|
|
171
|
+
emitConversation({ kind: 'starting', conversation, step: frame.step });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (frame.type === 'subagents') {
|
|
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 });
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (frame.type === 'deliveries') {
|
|
187
|
+
emitConversation({ kind: 'deliveries', conversation, unknown: [...frame.unknown] });
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
89
190
|
if (frame.type === 'interactions') {
|
|
90
191
|
emitConversation({
|
|
91
192
|
kind: 'questions',
|
|
@@ -99,18 +200,32 @@ export function houseNotifications(transport, mode) {
|
|
|
99
200
|
return;
|
|
100
201
|
emitConversation({ kind: 'accepted-message', conversation, message });
|
|
101
202
|
}
|
|
102
|
-
function
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
203
|
+
function stage(frame, via) {
|
|
204
|
+
const held = staged.get(frame.carry);
|
|
205
|
+
if (frame.index !== (held?.parts ?? 0)) {
|
|
206
|
+
staged.delete(frame.carry);
|
|
207
|
+
return;
|
|
106
208
|
}
|
|
209
|
+
if (held === undefined) {
|
|
210
|
+
for (const [carry, other] of staged) {
|
|
211
|
+
if (other.authority === frame.authority)
|
|
212
|
+
staged.delete(carry);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
|
|
216
|
+
next.entries.push(...frame.entries);
|
|
217
|
+
next.parts += 1;
|
|
218
|
+
staged.set(frame.carry, next);
|
|
219
|
+
via?.received(frame.authority, frame.carry, frame.index);
|
|
107
220
|
}
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
221
|
+
function carried(frame) {
|
|
222
|
+
const held = staged.get(frame.carry);
|
|
223
|
+
staged.delete(frame.carry);
|
|
224
|
+
if ((held?.parts ?? 0) !== frame.parts)
|
|
225
|
+
return;
|
|
226
|
+
publish(frame, held?.entries ?? []);
|
|
112
227
|
}
|
|
113
|
-
function
|
|
228
|
+
function handle(frame, via) {
|
|
114
229
|
if (frame.type === 'signal') {
|
|
115
230
|
const mode = frame.service_mode;
|
|
116
231
|
if (mode !== 'open' && mode !== 'write-halted')
|
|
@@ -120,14 +235,31 @@ export function houseNotifications(transport, mode) {
|
|
|
120
235
|
return;
|
|
121
236
|
}
|
|
122
237
|
if (frame.type === 'opening') {
|
|
238
|
+
if (via !== null && mode === 'credential')
|
|
239
|
+
announce(via, frame);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (frame.type === 'caught_up') {
|
|
123
243
|
emit({
|
|
124
|
-
kind: '
|
|
125
|
-
expired: frame.expired.flatMap((authority) =>
|
|
244
|
+
kind: 'caught-up',
|
|
245
|
+
expired: frame.expired.flatMap((authority) => (tracking.get(authority) ?? []).map((tracked) => tracked.locator)),
|
|
126
246
|
});
|
|
127
247
|
return;
|
|
128
248
|
}
|
|
249
|
+
if (frame.type === 'authority_changed') {
|
|
250
|
+
const change = discovering.changed(frame);
|
|
251
|
+
if (change !== null)
|
|
252
|
+
emit(change);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
129
255
|
if (frame.type === 'conversations') {
|
|
130
|
-
emitConversation({
|
|
256
|
+
emitConversation({
|
|
257
|
+
kind: 'list',
|
|
258
|
+
entries: frame.conversations.map(listedConversation),
|
|
259
|
+
whole: frame.whole,
|
|
260
|
+
more: frame.more,
|
|
261
|
+
cursor: frame.cursor,
|
|
262
|
+
});
|
|
131
263
|
return;
|
|
132
264
|
}
|
|
133
265
|
if (frame.type === 'conversation') {
|
|
@@ -142,40 +274,45 @@ export function houseNotifications(transport, mode) {
|
|
|
142
274
|
frame.type === 'process' ||
|
|
143
275
|
frame.type === 'commands' ||
|
|
144
276
|
frame.type === 'options' ||
|
|
277
|
+
frame.type === 'starting' ||
|
|
278
|
+
frame.type === 'subagents' ||
|
|
279
|
+
frame.type === 'link' ||
|
|
280
|
+
frame.type === 'deliveries' ||
|
|
145
281
|
frame.type === 'interactions' ||
|
|
146
282
|
frame.type === 'message') {
|
|
147
283
|
converse(frame);
|
|
148
284
|
return;
|
|
149
285
|
}
|
|
150
|
-
if (frame.type
|
|
151
|
-
|
|
286
|
+
if (frame.type === 'part')
|
|
287
|
+
stage(frame, via);
|
|
288
|
+
else if (frame.type === 'carried')
|
|
289
|
+
carried(frame);
|
|
290
|
+
}
|
|
291
|
+
function publish(frame, entries) {
|
|
152
292
|
const at = position(frame.position);
|
|
153
293
|
const after = position(frame.after);
|
|
154
|
-
if (at === null || after === null || after >= at)
|
|
155
|
-
interrupt(frame.authority);
|
|
294
|
+
if (at === null || after === null || after >= at)
|
|
156
295
|
return;
|
|
296
|
+
const from = roomVersion({ position: frame.after, logEpoch: frame.log_epoch });
|
|
297
|
+
const version = roomVersion({ position: frame.position, logEpoch: frame.log_epoch });
|
|
298
|
+
for (const tracked of tracking.get(frame.authority) ?? []) {
|
|
299
|
+
emit({
|
|
300
|
+
kind: 'room-change',
|
|
301
|
+
locator: tracked.locator,
|
|
302
|
+
from,
|
|
303
|
+
roomVersion: version,
|
|
304
|
+
read: () => changePage(tracked, entries, version, mode),
|
|
305
|
+
});
|
|
157
306
|
}
|
|
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
307
|
}
|
|
174
|
-
stream.observe(
|
|
308
|
+
stream.observe((frame) => handle(frame, socket));
|
|
175
309
|
stream.opened(reopened);
|
|
176
|
-
stream.closed((revoked) => {
|
|
310
|
+
stream.closed(({ revoked, lost }) => {
|
|
177
311
|
opening = null;
|
|
178
|
-
|
|
312
|
+
announced = null;
|
|
313
|
+
socket = null;
|
|
314
|
+
staged.clear();
|
|
315
|
+
emit({ kind: 'closed', revoked, lost });
|
|
179
316
|
});
|
|
180
317
|
return {
|
|
181
318
|
runtime,
|
|
@@ -191,19 +328,30 @@ export function houseNotifications(transport, mode) {
|
|
|
191
328
|
replicate(next) {
|
|
192
329
|
replicated = [...next];
|
|
193
330
|
},
|
|
331
|
+
hold(cursor) {
|
|
332
|
+
listedCursor = cursor;
|
|
333
|
+
},
|
|
194
334
|
observe(notify) {
|
|
195
335
|
conversationObservers.add(notify);
|
|
196
336
|
return () => {
|
|
197
337
|
conversationObservers.delete(notify);
|
|
198
338
|
};
|
|
199
339
|
},
|
|
340
|
+
...(mode === 'credential'
|
|
341
|
+
? {
|
|
342
|
+
agents: () => houseAgents(transport),
|
|
343
|
+
history: (request) => houseHistory(transport, request),
|
|
344
|
+
}
|
|
345
|
+
: {}),
|
|
200
346
|
},
|
|
201
347
|
observe(notify) {
|
|
202
348
|
observers.add(notify);
|
|
203
|
-
|
|
349
|
+
const replayed = opening === null ? [] : [{ kind: 'opened' }, announced];
|
|
350
|
+
if (replayed.length > 0) {
|
|
204
351
|
queueMicrotask(() => {
|
|
205
|
-
|
|
206
|
-
|
|
352
|
+
for (const event of replayed)
|
|
353
|
+
if (event !== null && observers.has(notify))
|
|
354
|
+
notify(event);
|
|
207
355
|
});
|
|
208
356
|
}
|
|
209
357
|
return () => {
|
|
@@ -211,112 +359,19 @@ export function houseNotifications(transport, mode) {
|
|
|
211
359
|
};
|
|
212
360
|
},
|
|
213
361
|
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
362
|
opening = null;
|
|
223
|
-
|
|
363
|
+
announced = null;
|
|
364
|
+
socket?.hold(rooms, runtime, listedCursor);
|
|
224
365
|
},
|
|
225
366
|
track(entries) {
|
|
226
|
-
|
|
367
|
+
tracking.clear();
|
|
227
368
|
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
|
-
}
|
|
369
|
+
tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
|
|
232
370
|
}
|
|
233
|
-
for (const
|
|
234
|
-
if (!
|
|
235
|
-
|
|
371
|
+
for (const [carry, held] of staged) {
|
|
372
|
+
if (!tracking.has(held.authority))
|
|
373
|
+
staged.delete(carry);
|
|
236
374
|
}
|
|
237
375
|
},
|
|
238
|
-
reach(authority, at) {
|
|
239
|
-
const line = lines.get(authority);
|
|
240
|
-
const held = position(at.position);
|
|
241
|
-
if (line === undefined || held === null || line.logEpoch !== at.logEpoch)
|
|
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
|
-
}
|
|
304
|
-
}
|
|
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
|
-
},
|
|
321
376
|
};
|
|
322
377
|
}
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
import type { ConversationEvent, TurnOperation } from '@agentshouse/mdruntime';
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export declare
|
|
9
|
-
export declare
|
|
10
|
-
export declare const
|
|
2
|
+
export declare const HOUSE_RUNTIME_READS: {
|
|
3
|
+
readonly acts: readonly ['account/push', 'agents/read', 'apps/features/set', 'apps/source/download', 'apps/source/top', 'batch', 'batch-upload', 'bootstrap', 'conversations/history', 'discover', 'files/attach', 'files/finish', 'files/get', 'revisions', 'sites/screenshot/read'];
|
|
4
|
+
readonly frames: readonly ['app-message', 'authority_changed', 'carried', 'caught_up', 'commands', 'conversation', 'conversation_deleted', 'conversations', 'deliveries', 'deployment', 'held', 'interactions', 'link', 'message', 'opening', 'options', 'part', 'process', 'received', 'signal', 'site', 'starting', 'subagents', 'tab-icon', 'turn'];
|
|
5
|
+
};
|
|
6
|
+
export type HouseRuntimeAct = (typeof HOUSE_RUNTIME_READS.acts)[number];
|
|
7
|
+
export type HouseRuntimeFrame = (typeof HOUSE_RUNTIME_READS.frames)[number];
|
|
8
|
+
export declare function houseDoorRoute(act: HouseRuntimeAct): string;
|
|
9
|
+
export declare function houseSiteRoute(act: Extract<HouseRuntimeAct, 'bootstrap' | 'discover'>): string;
|
|
10
|
+
export declare const SITE_SUBMISSION = "site/submission";
|
|
11
11
|
export declare const SITE_DOOR_SUBMIT = "/_house/door/submit";
|
|
12
|
-
export declare const PRIVATE_LOCATOR = "private";
|
|
13
12
|
export type HouseMode = 'credential' | 'site';
|
|
14
13
|
export type HouseDoorAnswer = {
|
|
15
14
|
status: number;
|
|
16
15
|
body: unknown;
|
|
17
16
|
};
|
|
18
|
-
export
|
|
19
|
-
export type
|
|
20
|
-
export type
|
|
17
|
+
export declare const SITE_FILES = "/_house/files/";
|
|
18
|
+
export type HouseByteAct = 'authored_batch_upload';
|
|
19
|
+
export type HouseBytesAnswer = {
|
|
20
|
+
status: number;
|
|
21
|
+
body: ReadableStream<Uint8Array> | null;
|
|
22
|
+
mediaType: string;
|
|
23
|
+
};
|
|
21
24
|
export type HouseByteTransfer = {
|
|
22
25
|
act: HouseByteAct;
|
|
23
|
-
method: 'GET' | 'POST';
|
|
24
26
|
url: string;
|
|
25
|
-
|
|
26
|
-
body?: HouseByteBody;
|
|
27
|
-
operation?: string;
|
|
27
|
+
body: string;
|
|
28
28
|
};
|
|
29
29
|
export type HouseStreamEntry = {
|
|
30
30
|
path: string;
|
|
31
|
-
kind: 'edited' | 'removed';
|
|
31
|
+
kind: 'edited' | 'removed' | 'folder';
|
|
32
|
+
removed?: true;
|
|
32
33
|
revision?: string;
|
|
33
34
|
sha256?: string;
|
|
34
35
|
text?: string;
|
|
36
|
+
bytes?: number;
|
|
37
|
+
media_type?: string;
|
|
35
38
|
author?: {
|
|
36
39
|
user: string;
|
|
37
40
|
name: string;
|
|
@@ -47,21 +50,49 @@ type LiveFact<K extends ConversationEvent['kind']> = Extract<ConversationEvent,
|
|
|
47
50
|
export type HouseListedConversation = {
|
|
48
51
|
conversation_id: string;
|
|
49
52
|
agent_id: string;
|
|
53
|
+
agent_name: string;
|
|
54
|
+
agent_retired: boolean;
|
|
50
55
|
name: string;
|
|
51
56
|
created_at: string;
|
|
52
57
|
finished_at: string | null;
|
|
53
58
|
outcome: string | null;
|
|
59
|
+
waiting: boolean;
|
|
60
|
+
newest: {
|
|
61
|
+
accepted_at: string;
|
|
62
|
+
message_id: string;
|
|
63
|
+
} | null;
|
|
54
64
|
};
|
|
55
|
-
|
|
56
|
-
type:
|
|
65
|
+
type Listed<Frame extends {
|
|
66
|
+
readonly type: HouseRuntimeFrame;
|
|
67
|
+
}> = Frame;
|
|
68
|
+
export type HouseStreamFrame = Listed<{
|
|
69
|
+
type: 'part';
|
|
70
|
+
authority: string;
|
|
71
|
+
carry: string;
|
|
72
|
+
index: number;
|
|
73
|
+
entries: readonly HouseStreamEntry[];
|
|
74
|
+
} | {
|
|
75
|
+
type: 'carried';
|
|
57
76
|
authority: string;
|
|
77
|
+
carry: string;
|
|
78
|
+
parts: number;
|
|
58
79
|
after: string;
|
|
59
80
|
position: string;
|
|
60
81
|
log_epoch: string;
|
|
61
|
-
entries: readonly HouseStreamEntry[];
|
|
62
82
|
} | {
|
|
63
83
|
type: 'opening';
|
|
84
|
+
member: unknown;
|
|
85
|
+
bounds: unknown;
|
|
86
|
+
actions: readonly unknown[];
|
|
87
|
+
authorities: readonly unknown[];
|
|
88
|
+
} | {
|
|
89
|
+
type: 'caught_up';
|
|
64
90
|
expired: readonly string[];
|
|
91
|
+
} | {
|
|
92
|
+
type: 'authority_changed';
|
|
93
|
+
member: unknown;
|
|
94
|
+
authorities: readonly unknown[];
|
|
95
|
+
left: readonly string[];
|
|
65
96
|
} | ({
|
|
66
97
|
type: 'turn';
|
|
67
98
|
conversation_id: string;
|
|
@@ -74,6 +105,10 @@ export type HouseStreamFrame = {
|
|
|
74
105
|
type: 'interactions';
|
|
75
106
|
conversation_id: string;
|
|
76
107
|
interactions: readonly unknown[];
|
|
108
|
+
} | {
|
|
109
|
+
type: 'deliveries';
|
|
110
|
+
conversation_id: string;
|
|
111
|
+
unknown: readonly string[];
|
|
77
112
|
} | {
|
|
78
113
|
type: 'process';
|
|
79
114
|
conversation_id: string;
|
|
@@ -86,9 +121,24 @@ export type HouseStreamFrame = {
|
|
|
86
121
|
type: 'options';
|
|
87
122
|
conversation_id: string;
|
|
88
123
|
options: LiveFact<'options'>['options'];
|
|
124
|
+
} | {
|
|
125
|
+
type: 'starting';
|
|
126
|
+
conversation_id: string;
|
|
127
|
+
step: string | null;
|
|
128
|
+
} | {
|
|
129
|
+
type: 'subagents';
|
|
130
|
+
conversation_id: string;
|
|
131
|
+
subagents: LiveFact<'subagents'>['subagents'];
|
|
132
|
+
} | {
|
|
133
|
+
type: 'link';
|
|
134
|
+
conversation_id: string;
|
|
135
|
+
connected: boolean;
|
|
89
136
|
} | {
|
|
90
137
|
type: 'conversations';
|
|
91
138
|
conversations: readonly HouseListedConversation[];
|
|
139
|
+
whole: boolean;
|
|
140
|
+
more: boolean;
|
|
141
|
+
cursor: string | null;
|
|
92
142
|
} | {
|
|
93
143
|
type: 'conversation';
|
|
94
144
|
conversation: HouseListedConversation;
|
|
@@ -98,30 +148,44 @@ export type HouseStreamFrame = {
|
|
|
98
148
|
} | {
|
|
99
149
|
type: 'signal';
|
|
100
150
|
service_mode: string;
|
|
101
|
-
}
|
|
151
|
+
}>;
|
|
102
152
|
export type HouseHeldRoom = {
|
|
103
153
|
authority: string;
|
|
104
154
|
position: string;
|
|
105
155
|
log_epoch: string;
|
|
106
156
|
};
|
|
107
157
|
export type HouseOpening = {
|
|
108
|
-
hold(rooms: readonly HouseHeldRoom[], runtime: string): void;
|
|
158
|
+
hold(rooms: readonly HouseHeldRoom[], runtime: string, conversations: string | null): void;
|
|
159
|
+
received(authority: string, carry: string, index: number): void;
|
|
160
|
+
close(): void;
|
|
161
|
+
};
|
|
162
|
+
export type HouseClosing = {
|
|
163
|
+
revoked: boolean;
|
|
164
|
+
lost: boolean;
|
|
109
165
|
};
|
|
110
166
|
export type HouseStream = {
|
|
111
167
|
observe(receive: (frame: HouseStreamFrame) => void): () => void;
|
|
112
168
|
opened(notify: (opening: HouseOpening) => void): () => void;
|
|
113
|
-
closed(notify: (
|
|
169
|
+
closed(notify: (closing: HouseClosing) => void): () => void;
|
|
170
|
+
};
|
|
171
|
+
export type HouseStreamed = HouseDoorAnswer & {
|
|
172
|
+
room: ReadableStream<Uint8Array> | null;
|
|
114
173
|
};
|
|
115
174
|
export type HouseDoor = {
|
|
116
175
|
door(route: string, body: unknown): Promise<HouseDoorAnswer>;
|
|
117
176
|
stream: HouseStream;
|
|
118
177
|
};
|
|
119
178
|
export type HouseTransport = HouseDoor & {
|
|
179
|
+
streamed(route: string, body: unknown, signal: AbortSignal): Promise<HouseStreamed>;
|
|
120
180
|
transfer(request: HouseByteTransfer): Promise<HouseDoorAnswer>;
|
|
181
|
+
put(url: string, body: Blob, headers: Readonly<Record<string, string>>): Promise<number>;
|
|
182
|
+
download(url: string): Promise<HouseBytesAnswer>;
|
|
121
183
|
};
|
|
122
184
|
export type HouseSiteTransport = HouseDoor & {
|
|
123
185
|
online(): boolean;
|
|
124
186
|
read(route: string): Promise<HouseDoorAnswer>;
|
|
187
|
+
streamed(route: string, signal: AbortSignal): Promise<HouseStreamed>;
|
|
188
|
+
download(route: string): Promise<HouseBytesAnswer>;
|
|
125
189
|
};
|
|
126
190
|
export {};
|
|
127
191
|
//# sourceMappingURL=transport.d.ts.map
|