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