@agentshouse/mdruntime-adapter 0.1.0-c5b15f4efd6f3 → 0.1.0-c5c5ff2bcc92c
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/AGENTS.md +278 -196
- package/dist/actions.d.ts +63 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +158 -138
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +325 -103
- package/dist/discovery.d.ts +6 -6
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +40 -17
- package/dist/gather.d.ts +1 -0
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +11 -6
- package/dist/handed.d.ts +15 -0
- package/dist/handed.d.ts.map +1 -0
- package/dist/handed.js +38 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/model.d.ts +1 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +21 -7
- package/dist/read.d.ts +35 -7
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +160 -79
- package/dist/referrer.d.ts +7 -0
- package/dist/referrer.d.ts.map +1 -0
- package/dist/referrer.js +35 -0
- package/dist/refusal.d.ts +5 -9
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +31 -17
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +191 -56
- package/dist/stream.d.ts +5 -2
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +360 -16
- package/dist/transport.d.ts +83 -12
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -1
- 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 +3 -9
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +97 -20
- package/package.json +3 -4
- 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,19 +1,100 @@
|
|
|
1
1
|
import { acceptedMessage } from './actions.js';
|
|
2
|
-
import {
|
|
2
|
+
import { sha256Hex } from './digest.js';
|
|
3
|
+
import { binaryFileOf, headChange, identities } from './read.js';
|
|
3
4
|
import { roomVersion } from './version.js';
|
|
4
5
|
const HELD_FRAMES_MAX = 256;
|
|
5
6
|
function turnOperation(frame) {
|
|
6
7
|
const { type: _type, conversation_id: _conversation, turn_id: _turn, ...operation } = frame;
|
|
7
8
|
return structuredClone(operation);
|
|
8
9
|
}
|
|
10
|
+
function listedConversation(listed) {
|
|
11
|
+
return {
|
|
12
|
+
conversation: listed.conversation_id,
|
|
13
|
+
agent: listed.agent_id,
|
|
14
|
+
name: listed.name,
|
|
15
|
+
created: listed.created_at,
|
|
16
|
+
finished: listed.finished_at,
|
|
17
|
+
outcome: listed.outcome,
|
|
18
|
+
waiting: listed.waiting,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
9
21
|
function position(value) {
|
|
10
22
|
if (!/^(?:0|[1-9][0-9]*)$/.test(value))
|
|
11
23
|
return null;
|
|
12
24
|
return BigInt(value);
|
|
13
25
|
}
|
|
26
|
+
function assembled(entries) {
|
|
27
|
+
const whole = [];
|
|
28
|
+
let open = null;
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
if (entry.kind === 'piece') {
|
|
31
|
+
if (open === null || open.entry.path !== entry.path || entry.text === undefined)
|
|
32
|
+
return null;
|
|
33
|
+
open.texts.push(entry.text);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (open !== null)
|
|
37
|
+
return null;
|
|
38
|
+
if (entry.continued !== true) {
|
|
39
|
+
whole.push(entry);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (entry.text === undefined)
|
|
43
|
+
return null;
|
|
44
|
+
open = { entry, texts: [entry.text] };
|
|
45
|
+
}
|
|
46
|
+
if (entry.continued === true)
|
|
47
|
+
continue;
|
|
48
|
+
const { continued: _continued, ...head } = open.entry;
|
|
49
|
+
whole.push({ ...head, text: open.texts.join('') });
|
|
50
|
+
open = null;
|
|
51
|
+
}
|
|
52
|
+
return open === null ? whole : null;
|
|
53
|
+
}
|
|
54
|
+
async function verified(entries) {
|
|
55
|
+
try {
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
if (entry.text === undefined || entry.sha256 === undefined)
|
|
58
|
+
continue;
|
|
59
|
+
if ((await sha256Hex(entry.text)) !== entry.sha256)
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function resumed(kept, frame) {
|
|
69
|
+
const last = frame.entries.at(-1);
|
|
70
|
+
const point = { parts: frame.index + 1, from: frame.from, target: frame.target };
|
|
71
|
+
if (last?.continued !== true)
|
|
72
|
+
return { ...point, handled: frame.handled, piece: null };
|
|
73
|
+
const text = last.text?.length ?? 0;
|
|
74
|
+
if (last.kind !== 'piece') {
|
|
75
|
+
return last.sha256 === undefined
|
|
76
|
+
? kept.resume
|
|
77
|
+
: { ...point, handled: frame.handled, piece: { sha256: last.sha256, offset: text } };
|
|
78
|
+
}
|
|
79
|
+
const piece = kept.resume?.piece ?? null;
|
|
80
|
+
if (piece === null)
|
|
81
|
+
return kept.resume;
|
|
82
|
+
const pieces = frame.entries.reduce((sum, entry) => sum + (entry.kind === 'piece' ? (entry.text?.length ?? 0) : 0), 0);
|
|
83
|
+
return {
|
|
84
|
+
...point,
|
|
85
|
+
handled: frame.handled,
|
|
86
|
+
piece: { sha256: piece.sha256, offset: piece.offset + pieces },
|
|
87
|
+
};
|
|
88
|
+
}
|
|
14
89
|
export function houseNotifications(transport, mode) {
|
|
15
90
|
const stream = transport.stream;
|
|
16
91
|
const lines = new Map();
|
|
92
|
+
const kept = new Map();
|
|
93
|
+
let receipts = null;
|
|
94
|
+
let loaded = Promise.resolve();
|
|
95
|
+
let acknowledging = null;
|
|
96
|
+
let receiving = Promise.resolve();
|
|
97
|
+
let verifying = 0;
|
|
17
98
|
const locators = new Map();
|
|
18
99
|
const observers = new Set();
|
|
19
100
|
const conversationObservers = new Set();
|
|
@@ -21,18 +102,28 @@ export function houseNotifications(transport, mode) {
|
|
|
21
102
|
let replicated = [];
|
|
22
103
|
const live = new Set();
|
|
23
104
|
let opening = null;
|
|
105
|
+
const runtime = crypto.randomUUID();
|
|
24
106
|
function emit(event) {
|
|
25
107
|
for (const observer of observers)
|
|
26
108
|
observer(event);
|
|
27
109
|
}
|
|
28
110
|
function emitConversation(event) {
|
|
29
|
-
if (event.kind
|
|
111
|
+
if (event.kind === 'turn' ||
|
|
112
|
+
event.kind === 'questions' ||
|
|
113
|
+
event.kind === 'process' ||
|
|
114
|
+
event.kind === 'commands' ||
|
|
115
|
+
event.kind === 'options' ||
|
|
116
|
+
event.kind === 'starting' ||
|
|
117
|
+
event.kind === 'link' ||
|
|
118
|
+
event.kind === 'deliveries') {
|
|
30
119
|
live.add(event.conversation);
|
|
120
|
+
}
|
|
31
121
|
for (const observer of conversationObservers)
|
|
32
122
|
observer(event);
|
|
33
123
|
}
|
|
34
124
|
function reopened(next) {
|
|
35
125
|
opening = next;
|
|
126
|
+
acknowledging = next;
|
|
36
127
|
const gapped = new Set([...replicated, ...live]);
|
|
37
128
|
live.clear();
|
|
38
129
|
for (const conversation of gapped)
|
|
@@ -70,6 +161,18 @@ export function houseNotifications(transport, mode) {
|
|
|
70
161
|
emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });
|
|
71
162
|
return;
|
|
72
163
|
}
|
|
164
|
+
if (frame.type === 'starting') {
|
|
165
|
+
emitConversation({ kind: 'starting', conversation, step: frame.step });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (frame.type === 'link') {
|
|
169
|
+
emitConversation({ kind: 'link', conversation, connected: frame.connected });
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (frame.type === 'deliveries') {
|
|
173
|
+
emitConversation({ kind: 'deliveries', conversation, unknown: [...frame.unknown] });
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
73
176
|
if (frame.type === 'interactions') {
|
|
74
177
|
emitConversation({
|
|
75
178
|
kind: 'questions',
|
|
@@ -94,7 +197,162 @@ export function houseNotifications(transport, mode) {
|
|
|
94
197
|
if (line !== undefined)
|
|
95
198
|
lines.set(authority, { ...line, frames: [] });
|
|
96
199
|
}
|
|
97
|
-
function
|
|
200
|
+
async function forget(carries) {
|
|
201
|
+
const held = carries.filter((carry) => kept.delete(carry));
|
|
202
|
+
if (held.length > 0)
|
|
203
|
+
await receipts?.drop(held).catch(() => { });
|
|
204
|
+
}
|
|
205
|
+
async function lost(authority, carry) {
|
|
206
|
+
interrupt(authority);
|
|
207
|
+
await forget([carry]);
|
|
208
|
+
}
|
|
209
|
+
async function stage(frame, via) {
|
|
210
|
+
await loaded;
|
|
211
|
+
const port = receipts;
|
|
212
|
+
if (port === null)
|
|
213
|
+
return;
|
|
214
|
+
const held = kept.get(frame.carry);
|
|
215
|
+
if (held === undefined && frame.index !== 0) {
|
|
216
|
+
interrupt(frame.authority);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (held !== undefined &&
|
|
220
|
+
(held.fenced !== null || frame.index > held.parts || frame.index < (held.resume?.parts ?? 0))) {
|
|
221
|
+
await lost(frame.authority, frame.carry);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (held === undefined) {
|
|
225
|
+
await forget([...kept.values()]
|
|
226
|
+
.filter((other) => other.authority === frame.authority && other.fenced === null)
|
|
227
|
+
.map((other) => other.carry));
|
|
228
|
+
}
|
|
229
|
+
const start = held ?? {
|
|
230
|
+
authority: frame.authority,
|
|
231
|
+
carry: frame.carry,
|
|
232
|
+
logEpoch: lines.get(frame.authority)?.logEpoch ?? null,
|
|
233
|
+
after: frame.after,
|
|
234
|
+
parts: 0,
|
|
235
|
+
resume: null,
|
|
236
|
+
fenced: null,
|
|
237
|
+
};
|
|
238
|
+
const next = { ...start, parts: frame.index + 1, resume: resumed(start, frame) };
|
|
239
|
+
const part = { entries: frame.entries };
|
|
240
|
+
try {
|
|
241
|
+
await port.keep(frame.carry, next, { index: frame.index, value: part });
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
await lost(frame.authority, frame.carry);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
kept.set(frame.carry, next);
|
|
248
|
+
via?.received(frame.authority, frame.carry, frame.index);
|
|
249
|
+
}
|
|
250
|
+
async function keptEntries(carry, parts) {
|
|
251
|
+
if (parts === 0)
|
|
252
|
+
return [];
|
|
253
|
+
if (receipts === null)
|
|
254
|
+
return null;
|
|
255
|
+
const read = (await receipts.parts(carry, parts));
|
|
256
|
+
if (read.length !== parts)
|
|
257
|
+
return null;
|
|
258
|
+
const entries = assembled(read.flatMap((part) => part.entries));
|
|
259
|
+
return entries !== null && (await verified(entries)) ? entries : null;
|
|
260
|
+
}
|
|
261
|
+
async function carried(frame) {
|
|
262
|
+
await loaded;
|
|
263
|
+
const held = kept.get(frame.carry);
|
|
264
|
+
if (frame.parts > 0 && held?.parts !== frame.parts) {
|
|
265
|
+
await lost(frame.authority, frame.carry);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const entries = await keptEntries(frame.carry, frame.parts).catch(() => null);
|
|
269
|
+
if (entries === null) {
|
|
270
|
+
await lost(frame.authority, frame.carry);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const fenced = {
|
|
274
|
+
...(held ?? {
|
|
275
|
+
authority: frame.authority,
|
|
276
|
+
carry: frame.carry,
|
|
277
|
+
logEpoch: frame.log_epoch,
|
|
278
|
+
after: frame.after,
|
|
279
|
+
parts: 0,
|
|
280
|
+
resume: null,
|
|
281
|
+
}),
|
|
282
|
+
after: frame.after,
|
|
283
|
+
fenced: { position: frame.position, logEpoch: frame.log_epoch },
|
|
284
|
+
};
|
|
285
|
+
try {
|
|
286
|
+
await receipts?.keep(frame.carry, fenced);
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
await lost(frame.authority, frame.carry);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
kept.set(frame.carry, fenced);
|
|
293
|
+
publish(frame, entries);
|
|
294
|
+
}
|
|
295
|
+
async function load(port) {
|
|
296
|
+
try {
|
|
297
|
+
for (const { key, head } of await port.heads())
|
|
298
|
+
kept.set(key, head);
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
kept.clear();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async function restored(room) {
|
|
305
|
+
const line = lines.get(room.authority);
|
|
306
|
+
let at = room.position;
|
|
307
|
+
const chain = [];
|
|
308
|
+
for (;;) {
|
|
309
|
+
const next = [...kept.values()].find((carry) => carry.authority === room.authority &&
|
|
310
|
+
carry.after === at &&
|
|
311
|
+
carry.fenced?.logEpoch === room.log_epoch);
|
|
312
|
+
if (next?.fenced == null)
|
|
313
|
+
break;
|
|
314
|
+
const entries = await keptEntries(next.carry, next.parts).catch(() => null);
|
|
315
|
+
if (entries === null)
|
|
316
|
+
break;
|
|
317
|
+
chain.push({ carry: next, entries });
|
|
318
|
+
at = next.fenced.position;
|
|
319
|
+
}
|
|
320
|
+
const partial = [...kept.values()].find((carry) => carry.authority === room.authority &&
|
|
321
|
+
carry.fenced === null &&
|
|
322
|
+
carry.logEpoch === room.log_epoch &&
|
|
323
|
+
carry.after === at &&
|
|
324
|
+
carry.resume !== null &&
|
|
325
|
+
carry.resume.parts > 0);
|
|
326
|
+
const stale = [...kept.values()].filter((carry) => carry.authority === room.authority &&
|
|
327
|
+
carry !== partial &&
|
|
328
|
+
!chain.some((link) => link.carry === carry));
|
|
329
|
+
await forget(stale.map((carry) => carry.carry));
|
|
330
|
+
if (line !== undefined && line.logEpoch === room.log_epoch && chain.length > 0) {
|
|
331
|
+
const frames = chain.map(({ carry, entries }) => ({
|
|
332
|
+
after: BigInt(carry.after),
|
|
333
|
+
position: BigInt(carry.fenced.position),
|
|
334
|
+
entries,
|
|
335
|
+
}));
|
|
336
|
+
lines.set(room.authority, { ...line, frames: [...line.frames, ...frames] });
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
...room,
|
|
340
|
+
position: at,
|
|
341
|
+
...(partial?.resume == null
|
|
342
|
+
? {}
|
|
343
|
+
: {
|
|
344
|
+
carry: {
|
|
345
|
+
id: partial.carry,
|
|
346
|
+
parts: partial.resume.parts,
|
|
347
|
+
from: partial.resume.from,
|
|
348
|
+
target: partial.resume.target,
|
|
349
|
+
handled: partial.resume.handled,
|
|
350
|
+
...(partial.resume.piece === null ? {} : { piece: partial.resume.piece }),
|
|
351
|
+
},
|
|
352
|
+
}),
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function handle(frame, via) {
|
|
98
356
|
if (frame.type === 'signal') {
|
|
99
357
|
const mode = frame.service_mode;
|
|
100
358
|
if (mode !== 'open' && mode !== 'write-halted')
|
|
@@ -110,17 +368,40 @@ export function houseNotifications(transport, mode) {
|
|
|
110
368
|
});
|
|
111
369
|
return;
|
|
112
370
|
}
|
|
371
|
+
if (frame.type === 'authority_changed') {
|
|
372
|
+
emit({ kind: 'authority-changed', scope: { authorities: frame.rooms } });
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (frame.type === 'conversations') {
|
|
376
|
+
emitConversation({ kind: 'list', entries: frame.conversations.map(listedConversation) });
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (frame.type === 'conversation') {
|
|
380
|
+
emitConversation({ kind: 'listed', entry: listedConversation(frame.conversation) });
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (frame.type === 'conversation_deleted') {
|
|
384
|
+
emitConversation({ kind: 'unlisted', conversation: frame.conversation_id });
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
113
387
|
if (frame.type === 'turn' ||
|
|
114
388
|
frame.type === 'process' ||
|
|
115
389
|
frame.type === 'commands' ||
|
|
116
390
|
frame.type === 'options' ||
|
|
391
|
+
frame.type === 'starting' ||
|
|
392
|
+
frame.type === 'link' ||
|
|
393
|
+
frame.type === 'deliveries' ||
|
|
117
394
|
frame.type === 'interactions' ||
|
|
118
395
|
frame.type === 'message') {
|
|
119
396
|
converse(frame);
|
|
120
397
|
return;
|
|
121
398
|
}
|
|
122
|
-
if (frame.type
|
|
123
|
-
return;
|
|
399
|
+
if (frame.type === 'part')
|
|
400
|
+
return stage(frame, via);
|
|
401
|
+
if (frame.type === 'carried')
|
|
402
|
+
return carried(frame);
|
|
403
|
+
}
|
|
404
|
+
function publish(frame, entries) {
|
|
124
405
|
const at = position(frame.position);
|
|
125
406
|
const after = position(frame.after);
|
|
126
407
|
if (at === null || after === null || after >= at) {
|
|
@@ -134,7 +415,7 @@ export function houseNotifications(transport, mode) {
|
|
|
134
415
|
const last = line.frames.at(-1);
|
|
135
416
|
if (last !== undefined && at <= last.position)
|
|
136
417
|
return;
|
|
137
|
-
const held = { after, position: at, entries
|
|
418
|
+
const held = { after, position: at, entries };
|
|
138
419
|
const next = last !== undefined && after <= last.position ? [...line.frames, held] : [held];
|
|
139
420
|
lines.set(frame.authority, { ...line, frames: next.length > HELD_FRAMES_MAX ? [] : next });
|
|
140
421
|
}
|
|
@@ -143,13 +424,33 @@ export function houseNotifications(transport, mode) {
|
|
|
143
424
|
}
|
|
144
425
|
announce(frame.authority, { position: frame.position, logEpoch: frame.log_epoch });
|
|
145
426
|
}
|
|
146
|
-
stream.observe(
|
|
427
|
+
stream.observe((frame) => {
|
|
428
|
+
const via = acknowledging;
|
|
429
|
+
if (verifying === 0) {
|
|
430
|
+
const handled = handle(frame, via);
|
|
431
|
+
if (handled === undefined)
|
|
432
|
+
return;
|
|
433
|
+
verifying += 1;
|
|
434
|
+
receiving = handled.finally(() => {
|
|
435
|
+
verifying -= 1;
|
|
436
|
+
});
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
verifying += 1;
|
|
440
|
+
receiving = receiving
|
|
441
|
+
.then(() => handle(frame, via))
|
|
442
|
+
.finally(() => {
|
|
443
|
+
verifying -= 1;
|
|
444
|
+
});
|
|
445
|
+
});
|
|
147
446
|
stream.opened(reopened);
|
|
148
|
-
stream.closed((revoked) => {
|
|
447
|
+
stream.closed(({ revoked, lost }) => {
|
|
149
448
|
opening = null;
|
|
150
|
-
|
|
449
|
+
acknowledging = null;
|
|
450
|
+
emit({ kind: 'closed', revoked, lost });
|
|
151
451
|
});
|
|
152
452
|
return {
|
|
453
|
+
runtime,
|
|
153
454
|
serviceMode: {
|
|
154
455
|
observe(notify) {
|
|
155
456
|
modeObservers.add(notify);
|
|
@@ -169,8 +470,12 @@ export function houseNotifications(transport, mode) {
|
|
|
169
470
|
};
|
|
170
471
|
},
|
|
171
472
|
},
|
|
172
|
-
observe(notify) {
|
|
473
|
+
observe(notify, port) {
|
|
173
474
|
observers.add(notify);
|
|
475
|
+
if (receipts === null) {
|
|
476
|
+
receipts = port;
|
|
477
|
+
loaded = load(port);
|
|
478
|
+
}
|
|
174
479
|
if (opening !== null) {
|
|
175
480
|
queueMicrotask(() => {
|
|
176
481
|
if (observers.has(notify))
|
|
@@ -191,7 +496,35 @@ export function houseNotifications(transport, mode) {
|
|
|
191
496
|
}
|
|
192
497
|
const current = opening;
|
|
193
498
|
opening = null;
|
|
194
|
-
current
|
|
499
|
+
if (current === null)
|
|
500
|
+
return;
|
|
501
|
+
void loaded
|
|
502
|
+
.then(() => Promise.all(rooms.map(restored)))
|
|
503
|
+
.then((presented) => {
|
|
504
|
+
current.hold(presented, runtime);
|
|
505
|
+
for (const [index, room] of presented.entries()) {
|
|
506
|
+
if (room.position === rooms[index].position)
|
|
507
|
+
continue;
|
|
508
|
+
announce(room.authority, { position: room.position, logEpoch: room.log_epoch });
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
},
|
|
512
|
+
published(locator, at) {
|
|
513
|
+
const authority = [...locators].find(([, held]) => held.includes(locator))?.[0];
|
|
514
|
+
const reached = position(at.position);
|
|
515
|
+
if (authority === undefined || reached === null)
|
|
516
|
+
return;
|
|
517
|
+
void forget([...kept.values()]
|
|
518
|
+
.filter((carry) => carry.authority === authority &&
|
|
519
|
+
carry.fenced !== null &&
|
|
520
|
+
carry.fenced.logEpoch === at.logEpoch &&
|
|
521
|
+
BigInt(carry.fenced.position) <= reached)
|
|
522
|
+
.map((carry) => carry.carry));
|
|
523
|
+
},
|
|
524
|
+
reopen() {
|
|
525
|
+
const current = opening;
|
|
526
|
+
opening = null;
|
|
527
|
+
current?.close();
|
|
195
528
|
},
|
|
196
529
|
track(entries) {
|
|
197
530
|
locators.clear();
|
|
@@ -205,6 +538,9 @@ export function houseNotifications(transport, mode) {
|
|
|
205
538
|
if (!locators.has(authority))
|
|
206
539
|
lines.delete(authority);
|
|
207
540
|
}
|
|
541
|
+
void loaded.then(() => forget([...kept.values()]
|
|
542
|
+
.filter((carry) => !locators.has(carry.authority))
|
|
543
|
+
.map((carry) => carry.carry)));
|
|
208
544
|
},
|
|
209
545
|
reach(authority, at) {
|
|
210
546
|
const line = lines.get(authority);
|
|
@@ -231,6 +567,7 @@ export function houseNotifications(transport, mode) {
|
|
|
231
567
|
const documents = {};
|
|
232
568
|
const revisions = {};
|
|
233
569
|
const changes = {};
|
|
570
|
+
const binaryFiles = {};
|
|
234
571
|
const removals = [];
|
|
235
572
|
const applied = [];
|
|
236
573
|
const schemas = new Map();
|
|
@@ -238,6 +575,7 @@ export function houseNotifications(transport, mode) {
|
|
|
238
575
|
delete documents[path];
|
|
239
576
|
delete revisions[path];
|
|
240
577
|
delete changes[path];
|
|
578
|
+
delete binaryFiles[path];
|
|
241
579
|
const removed = removals.indexOf(path);
|
|
242
580
|
if (removed !== -1)
|
|
243
581
|
removals.splice(removed, 1);
|
|
@@ -258,7 +596,8 @@ export function houseNotifications(transport, mode) {
|
|
|
258
596
|
removals.push(entry.path);
|
|
259
597
|
continue;
|
|
260
598
|
}
|
|
261
|
-
|
|
599
|
+
const binary = binaryFileOf(entry);
|
|
600
|
+
if (binary === null || (binary === undefined && entry.text === undefined))
|
|
262
601
|
return null;
|
|
263
602
|
if (mode === 'credential' && entry.revision === undefined)
|
|
264
603
|
return null;
|
|
@@ -266,9 +605,13 @@ export function houseNotifications(transport, mode) {
|
|
|
266
605
|
if (head === null)
|
|
267
606
|
return null;
|
|
268
607
|
forget(entry.path);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
608
|
+
if (binary === undefined)
|
|
609
|
+
documents[entry.path] = entry.text;
|
|
610
|
+
else
|
|
611
|
+
binaryFiles[entry.path] = binary;
|
|
612
|
+
const revision = entry.revision ?? binary?.sha256;
|
|
613
|
+
if (revision !== undefined)
|
|
614
|
+
revisions[entry.path] = revision;
|
|
272
615
|
if (head !== undefined)
|
|
273
616
|
changes[entry.path] = head;
|
|
274
617
|
}
|
|
@@ -281,8 +624,9 @@ export function houseNotifications(transport, mode) {
|
|
|
281
624
|
roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),
|
|
282
625
|
documents,
|
|
283
626
|
revisions,
|
|
627
|
+
...identities(revisions),
|
|
284
628
|
changes,
|
|
285
|
-
|
|
629
|
+
binaryFiles,
|
|
286
630
|
removals: removals.sort(),
|
|
287
631
|
},
|
|
288
632
|
entries: applied,
|
package/dist/transport.d.ts
CHANGED
|
@@ -9,29 +9,35 @@ export declare const SITE_DOOR_DISCOVER = "/_house/door/discover";
|
|
|
9
9
|
export declare const SITE_DOOR_BOOTSTRAP = "/_house/door/bootstrap/";
|
|
10
10
|
export declare const SITE_DOOR_ENUMERATE = "/_house/door/enumerate";
|
|
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
|
|
20
|
-
export
|
|
17
|
+
export declare const DOOR_FILES_GET = "/door/files/get";
|
|
18
|
+
export declare const SITE_FILES = "/_house/files/";
|
|
19
|
+
export declare const SITE_FILE_RECORD = "record";
|
|
20
|
+
export type HouseByteAct = 'authored_batch_upload' | 'conversation_file_upload' | 'binary_stage';
|
|
21
|
+
export type HouseByteBody = string | ArrayBuffer | Uint8Array | Blob;
|
|
22
|
+
export type HouseBytesAnswer = {
|
|
23
|
+
status: number;
|
|
24
|
+
blob: Blob | null;
|
|
25
|
+
};
|
|
21
26
|
export type HouseByteTransfer = {
|
|
22
27
|
act: HouseByteAct;
|
|
23
|
-
method: 'GET' | 'POST';
|
|
24
28
|
url: string;
|
|
25
|
-
|
|
26
|
-
body?: HouseByteBody;
|
|
29
|
+
body: HouseByteBody;
|
|
27
30
|
operation?: string;
|
|
28
31
|
};
|
|
29
32
|
export type HouseStreamEntry = {
|
|
30
33
|
path: string;
|
|
31
|
-
kind: 'edited' | 'removed';
|
|
34
|
+
kind: 'edited' | 'removed' | 'piece';
|
|
32
35
|
revision?: string;
|
|
33
36
|
sha256?: string;
|
|
34
37
|
text?: string;
|
|
38
|
+
file?: string;
|
|
39
|
+
bytes?: number;
|
|
40
|
+
media_type?: string;
|
|
35
41
|
author?: {
|
|
36
42
|
user: string;
|
|
37
43
|
name: string;
|
|
@@ -40,20 +46,44 @@ export type HouseStreamEntry = {
|
|
|
40
46
|
name: string;
|
|
41
47
|
};
|
|
42
48
|
created_at?: string;
|
|
49
|
+
continued?: true;
|
|
43
50
|
};
|
|
44
51
|
type LiveFact<K extends ConversationEvent['kind']> = Extract<ConversationEvent, {
|
|
45
52
|
kind: K;
|
|
46
53
|
}>;
|
|
54
|
+
export type HouseListedConversation = {
|
|
55
|
+
conversation_id: string;
|
|
56
|
+
agent_id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
created_at: string;
|
|
59
|
+
finished_at: string | null;
|
|
60
|
+
outcome: string | null;
|
|
61
|
+
waiting: boolean;
|
|
62
|
+
};
|
|
47
63
|
export type HouseStreamFrame = {
|
|
48
|
-
type: '
|
|
64
|
+
type: 'part';
|
|
65
|
+
authority: string;
|
|
66
|
+
carry: string;
|
|
67
|
+
index: number;
|
|
68
|
+
after: string;
|
|
69
|
+
from: string;
|
|
70
|
+
target: string;
|
|
71
|
+
handled: number;
|
|
72
|
+
entries: readonly HouseStreamEntry[];
|
|
73
|
+
} | {
|
|
74
|
+
type: 'carried';
|
|
49
75
|
authority: string;
|
|
76
|
+
carry: string;
|
|
77
|
+
parts: number;
|
|
50
78
|
after: string;
|
|
51
79
|
position: string;
|
|
52
80
|
log_epoch: string;
|
|
53
|
-
entries: readonly HouseStreamEntry[];
|
|
54
81
|
} | {
|
|
55
82
|
type: 'opening';
|
|
56
83
|
expired: readonly string[];
|
|
84
|
+
} | {
|
|
85
|
+
type: 'authority_changed';
|
|
86
|
+
rooms: readonly string[];
|
|
57
87
|
} | ({
|
|
58
88
|
type: 'turn';
|
|
59
89
|
conversation_id: string;
|
|
@@ -66,6 +96,10 @@ export type HouseStreamFrame = {
|
|
|
66
96
|
type: 'interactions';
|
|
67
97
|
conversation_id: string;
|
|
68
98
|
interactions: readonly unknown[];
|
|
99
|
+
} | {
|
|
100
|
+
type: 'deliveries';
|
|
101
|
+
conversation_id: string;
|
|
102
|
+
unknown: readonly string[];
|
|
69
103
|
} | {
|
|
70
104
|
type: 'process';
|
|
71
105
|
conversation_id: string;
|
|
@@ -78,22 +112,57 @@ export type HouseStreamFrame = {
|
|
|
78
112
|
type: 'options';
|
|
79
113
|
conversation_id: string;
|
|
80
114
|
options: LiveFact<'options'>['options'];
|
|
115
|
+
} | {
|
|
116
|
+
type: 'starting';
|
|
117
|
+
conversation_id: string;
|
|
118
|
+
step: string | null;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'link';
|
|
121
|
+
conversation_id: string;
|
|
122
|
+
connected: boolean;
|
|
123
|
+
} | {
|
|
124
|
+
type: 'conversations';
|
|
125
|
+
conversations: readonly HouseListedConversation[];
|
|
126
|
+
} | {
|
|
127
|
+
type: 'conversation';
|
|
128
|
+
conversation: HouseListedConversation;
|
|
129
|
+
} | {
|
|
130
|
+
type: 'conversation_deleted';
|
|
131
|
+
conversation_id: string;
|
|
81
132
|
} | {
|
|
82
133
|
type: 'signal';
|
|
83
134
|
service_mode: string;
|
|
84
135
|
};
|
|
136
|
+
export type HouseHeldCarry = {
|
|
137
|
+
id: string;
|
|
138
|
+
parts: number;
|
|
139
|
+
from: string;
|
|
140
|
+
target: string;
|
|
141
|
+
handled: number;
|
|
142
|
+
piece?: {
|
|
143
|
+
sha256: string;
|
|
144
|
+
offset: number;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
85
147
|
export type HouseHeldRoom = {
|
|
86
148
|
authority: string;
|
|
87
149
|
position: string;
|
|
88
150
|
log_epoch: string;
|
|
151
|
+
carry?: HouseHeldCarry;
|
|
89
152
|
};
|
|
90
153
|
export type HouseOpening = {
|
|
91
|
-
hold(rooms: readonly HouseHeldRoom[]): void;
|
|
154
|
+
hold(rooms: readonly HouseHeldRoom[], runtime: string): void;
|
|
155
|
+
received(authority: string, carry: string, index: number): void;
|
|
156
|
+
close(): void;
|
|
157
|
+
};
|
|
158
|
+
export type HouseClosing = {
|
|
159
|
+
revoked: boolean;
|
|
160
|
+
lost: boolean;
|
|
92
161
|
};
|
|
93
162
|
export type HouseStream = {
|
|
94
163
|
observe(receive: (frame: HouseStreamFrame) => void): () => void;
|
|
95
164
|
opened(notify: (opening: HouseOpening) => void): () => void;
|
|
96
|
-
closed(notify: (
|
|
165
|
+
closed(notify: (closing: HouseClosing) => void): () => void;
|
|
97
166
|
};
|
|
98
167
|
export type HouseDoor = {
|
|
99
168
|
door(route: string, body: unknown): Promise<HouseDoorAnswer>;
|
|
@@ -101,10 +170,12 @@ export type HouseDoor = {
|
|
|
101
170
|
};
|
|
102
171
|
export type HouseTransport = HouseDoor & {
|
|
103
172
|
transfer(request: HouseByteTransfer): Promise<HouseDoorAnswer>;
|
|
173
|
+
download(url: string): Promise<HouseBytesAnswer>;
|
|
104
174
|
};
|
|
105
175
|
export type HouseSiteTransport = HouseDoor & {
|
|
106
176
|
online(): boolean;
|
|
107
177
|
read(route: string): Promise<HouseDoorAnswer>;
|
|
178
|
+
download(route: string): Promise<HouseBytesAnswer>;
|
|
108
179
|
};
|
|
109
180
|
export {};
|
|
110
181
|
//# sourceMappingURL=transport.d.ts.map
|