@agentshouse/mdruntime-adapter 0.1.0-c05dbdfc6acd9 → 0.1.0-c068fdf374af0
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/dist/actions.d.ts +120 -9
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +6 -52
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +80 -139
- package/dist/discovery.d.ts +3 -3
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +8 -9
- package/dist/gather.d.ts +0 -1
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +1 -1
- package/dist/house-model.d.ts +2938 -1
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +1618 -484
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/model.d.ts +2 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/part.d.ts +11 -12
- package/dist/part.d.ts.map +1 -1
- package/dist/part.js +63 -55
- package/dist/read.d.ts +10 -15
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +35 -47
- 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 +1 -1
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +2 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +33 -77
- package/dist/stream.d.ts +3 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +37 -287
- package/dist/transport.d.ts +13 -20
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +1 -0
- package/dist/write.d.ts +4 -0
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +10 -2
- package/package.json +2 -2
package/dist/site.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { stepped } from '@agentshouse/mdruntime';
|
|
2
2
|
import { actionOutcome, SITE_SUBMIT } from './actions.js';
|
|
3
3
|
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
4
|
-
import {
|
|
5
|
-
import { bootstrapping,
|
|
6
|
-
import {
|
|
4
|
+
import { streamedModels, viewModels } from './model.js';
|
|
5
|
+
import { bootstrapping, parseEnumeration, refreshFrom, viewOf, wholeView, } from './read.js';
|
|
6
|
+
import { roomStreams } from './room-stream.js';
|
|
7
7
|
import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
|
|
8
8
|
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
9
9
|
import { houseNotifications } from './stream.js';
|
|
@@ -27,7 +27,8 @@ function siteRoom(tracked) {
|
|
|
27
27
|
export function createSiteAdapter(transport, snapshot = false) {
|
|
28
28
|
const notifications = houseNotifications(transport, 'site');
|
|
29
29
|
const tracked = new Map();
|
|
30
|
-
const
|
|
30
|
+
const read = new Map();
|
|
31
|
+
const rooms = roomStreams('site');
|
|
31
32
|
function fileRoute(request) {
|
|
32
33
|
const entry = tracked.get(request.locator);
|
|
33
34
|
if (entry === undefined)
|
|
@@ -57,37 +58,29 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
57
58
|
const first = await enumerated(entry, from);
|
|
58
59
|
return 'kind' in first ? first : wholeView(first, (page) => enumerated(entry, from, page));
|
|
59
60
|
}
|
|
60
|
-
async function
|
|
61
|
-
const cut =
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
61
|
+
async function openedRoom(entry, arriving, signal) {
|
|
62
|
+
const cut = read.get(entry.locator);
|
|
63
|
+
const answered = await transport.streamed(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`, signal ?? new AbortController().signal);
|
|
64
|
+
if (answered.room === null)
|
|
65
|
+
return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN;
|
|
66
|
+
const head = await rooms.head(entry, answered.room, arriving, signal);
|
|
67
|
+
const at = head.kind === 'bootstrap' ? logPosition(head.roomVersion) : null;
|
|
68
|
+
if (at !== null)
|
|
69
|
+
read.set(entry.locator, at.position);
|
|
70
|
+
return head;
|
|
68
71
|
}
|
|
69
|
-
async function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (failure !== null)
|
|
82
|
-
return failure;
|
|
83
|
-
const frame = partFrame(answer.body);
|
|
84
|
-
if (frame === null)
|
|
85
|
-
continue;
|
|
86
|
-
const scope = await housePart(room, frame, listed, 'site');
|
|
87
|
-
if (scope !== null)
|
|
88
|
-
return 'kind' in scope ? scope : { scope, frame };
|
|
89
|
-
}
|
|
90
|
-
return unverifiedPart(entry.locator);
|
|
72
|
+
async function streamedPage(entry, token) {
|
|
73
|
+
const part = await rooms.part(entry, token);
|
|
74
|
+
if ('kind' in part)
|
|
75
|
+
return part;
|
|
76
|
+
notifications.reach(entry.authority, part.scope);
|
|
77
|
+
const { folders: _folders, ...page } = await stepped(bootstrapping(part.scope));
|
|
78
|
+
return {
|
|
79
|
+
...page,
|
|
80
|
+
...(part.models === undefined ? {} : { models: part.models }),
|
|
81
|
+
...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
|
|
82
|
+
bytes: part.bytes,
|
|
83
|
+
};
|
|
91
84
|
}
|
|
92
85
|
async function refreshed(entry, fromRoomVersion) {
|
|
93
86
|
const from = logPosition(fromRoomVersion);
|
|
@@ -135,44 +128,9 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
135
128
|
const entry = tracked.get(request.locator);
|
|
136
129
|
if (entry === undefined)
|
|
137
130
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const room = await partedRoom(entry);
|
|
142
|
-
if ('kind' in room)
|
|
143
|
-
return room;
|
|
144
|
-
const { models, seen } = await manifestedModels(room, entry);
|
|
145
|
-
continued = { room, next: 0, seen };
|
|
146
|
-
inventory = partInventory(room);
|
|
147
|
-
if (inventory.parts > 0) {
|
|
148
|
-
return manifested(room, inventory, JSON.stringify(continued), models);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
else
|
|
152
|
-
continued = JSON.parse(request.pageToken);
|
|
153
|
-
const listed = continued.room.parts[continued.next];
|
|
154
|
-
const sent = listed === undefined
|
|
155
|
-
? { scope: emptyScope(continued.room), frame: null }
|
|
156
|
-
: await fetchedPart(entry, continued.room, listed, request.received, request.arriving);
|
|
157
|
-
if ('kind' in sent)
|
|
158
|
-
return sent;
|
|
159
|
-
const { scope } = sent;
|
|
160
|
-
notifications.reach(entry.authority, scope);
|
|
161
|
-
const next = continued.next + 1;
|
|
162
|
-
const more = next < continued.room.parts.length;
|
|
163
|
-
const seen = [
|
|
164
|
-
...continued.seen,
|
|
165
|
-
...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
|
|
166
|
-
];
|
|
167
|
-
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
168
|
-
const { folders: _folders, ...page } = await stepped(bootstrapping(scope));
|
|
169
|
-
return {
|
|
170
|
-
...page,
|
|
171
|
-
...(models === undefined ? {} : { models }),
|
|
172
|
-
...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
|
|
173
|
-
...(inventory === undefined ? {} : { inventory }),
|
|
174
|
-
...(sent.frame === null ? {} : { received: sent.frame }),
|
|
175
|
-
};
|
|
131
|
+
return request.pageToken === undefined
|
|
132
|
+
? openedRoom(entry, request.arriving, request.signal)
|
|
133
|
+
: streamedPage(entry, request.pageToken);
|
|
176
134
|
},
|
|
177
135
|
async refresh(_authorization, request) {
|
|
178
136
|
const entry = tracked.get(request.locator);
|
|
@@ -190,6 +148,9 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
190
148
|
async mutate() {
|
|
191
149
|
return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {}, retryable: false };
|
|
192
150
|
},
|
|
151
|
+
async attach() {
|
|
152
|
+
return { kind: 'rejected', code: 'write-grant', fields: {}, retryable: false };
|
|
153
|
+
},
|
|
193
154
|
async history() {
|
|
194
155
|
return { kind: 'no-history' };
|
|
195
156
|
},
|
|
@@ -248,11 +209,6 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
248
209
|
},
|
|
249
210
|
reopen: notifications.reopen,
|
|
250
211
|
observe: notifications.observe,
|
|
251
|
-
published(locator, roomVersion) {
|
|
252
|
-
const at = logPosition(roomVersion);
|
|
253
|
-
if (at !== null)
|
|
254
|
-
notifications.published(locator, at);
|
|
255
|
-
},
|
|
256
212
|
},
|
|
257
213
|
serviceMode: notifications.serviceMode,
|
|
258
214
|
};
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import { type ConversationStream, type RefreshPage, type RoomStreamEvent, type ServiceModeSignal
|
|
1
|
+
import { type ConversationStream, type RefreshPage, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
3
|
import type { HouseDoor, HouseHeldRoom, HouseMode, HouseStreamEntry } from './transport.js';
|
|
4
4
|
import { type LogPosition } from './version.js';
|
|
5
|
-
export type HeldRevision = (path: string, revision: string) => boolean;
|
|
6
5
|
export type StreamedAdvancement = {
|
|
7
6
|
page: RefreshPage;
|
|
8
7
|
schemas: ReadonlyMap<string, HouseStreamEntry>;
|
|
9
8
|
};
|
|
10
9
|
export type HouseNotifications = {
|
|
11
10
|
runtime: string;
|
|
12
|
-
observe(notify: (event: RoomStreamEvent) => void
|
|
11
|
+
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
13
12
|
send(rooms: readonly HouseHeldRoom[]): void;
|
|
14
|
-
published(locator: string, at: LogPosition): void;
|
|
15
13
|
reopen(): void;
|
|
16
14
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
17
15
|
reach(authority: string, at: LogPosition): void;
|
|
18
|
-
|
|
19
|
-
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): Generator<number, StreamedAdvancement | null, void>;
|
|
16
|
+
advance(tracked: TrackedAuthority, from: LogPosition): Generator<number, StreamedAdvancement | null, void>;
|
|
20
17
|
conversations: ConversationStream;
|
|
21
18
|
serviceMode: ServiceModeSignal;
|
|
22
19
|
};
|
package/dist/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EAEvB,KAAK,WAAW,EAChB,KAAK,eAAe,EAEpB,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EAEvB,KAAK,WAAW,EAChB,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAUvD,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAEb,SAAS,EAET,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AA0B7D,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAChD,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,aAAa,EAAE,GAAG,IAAI,CAAC;IAC5C,MAAM,IAAI,IAAI,CAAC;IACf,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtD,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD,OAAO,CACL,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,WAAW,GAChB,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;IACvD,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAyBF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CA+W5F"}
|
package/dist/stream.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
|
-
import { acceptedMessage } from './actions.js';
|
|
3
|
-
import { sha256Hex } from './digest.js';
|
|
2
|
+
import { acceptedMessage, cursorPosition } from './actions.js';
|
|
4
3
|
import { answered, answering, binaryFileOf, folded, forgotten, headChange, revised, } from './read.js';
|
|
5
4
|
import { roomVersion } from './version.js';
|
|
6
5
|
const HELD_FRAMES_MAX = 256;
|
|
@@ -17,6 +16,7 @@ function listedConversation(listed) {
|
|
|
17
16
|
finished: listed.finished_at,
|
|
18
17
|
outcome: listed.outcome,
|
|
19
18
|
waiting: listed.waiting,
|
|
19
|
+
newest: listed.newest === null ? null : cursorPosition(listed.newest),
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
function position(value) {
|
|
@@ -24,78 +24,11 @@ function position(value) {
|
|
|
24
24
|
return null;
|
|
25
25
|
return BigInt(value);
|
|
26
26
|
}
|
|
27
|
-
function assembled(entries) {
|
|
28
|
-
const whole = [];
|
|
29
|
-
let open = null;
|
|
30
|
-
for (const entry of entries) {
|
|
31
|
-
if (entry.kind === 'piece') {
|
|
32
|
-
if (open === null || open.entry.path !== entry.path || entry.text === undefined)
|
|
33
|
-
return null;
|
|
34
|
-
open.texts.push(entry.text);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
if (open !== null)
|
|
38
|
-
return null;
|
|
39
|
-
if (entry.continued !== true) {
|
|
40
|
-
whole.push(entry);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (entry.text === undefined)
|
|
44
|
-
return null;
|
|
45
|
-
open = { entry, texts: [entry.text] };
|
|
46
|
-
}
|
|
47
|
-
if (entry.continued === true)
|
|
48
|
-
continue;
|
|
49
|
-
const { continued: _continued, ...head } = open.entry;
|
|
50
|
-
whole.push({ ...head, text: open.texts.join('') });
|
|
51
|
-
open = null;
|
|
52
|
-
}
|
|
53
|
-
return open === null ? whole : null;
|
|
54
|
-
}
|
|
55
|
-
async function verified(entries) {
|
|
56
|
-
try {
|
|
57
|
-
for (const entry of entries) {
|
|
58
|
-
if (entry.text === undefined || entry.sha256 === undefined)
|
|
59
|
-
continue;
|
|
60
|
-
if ((await sha256Hex(entry.text)) !== entry.sha256)
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function resumed(kept, frame) {
|
|
70
|
-
const last = frame.entries.at(-1);
|
|
71
|
-
const point = { parts: frame.index + 1, from: frame.from, target: frame.target };
|
|
72
|
-
if (last?.continued !== true)
|
|
73
|
-
return { ...point, handled: frame.handled, piece: null };
|
|
74
|
-
const text = last.text?.length ?? 0;
|
|
75
|
-
if (last.kind !== 'piece') {
|
|
76
|
-
return last.sha256 === undefined
|
|
77
|
-
? kept.resume
|
|
78
|
-
: { ...point, handled: frame.handled, piece: { sha256: last.sha256, offset: text } };
|
|
79
|
-
}
|
|
80
|
-
const piece = kept.resume?.piece ?? null;
|
|
81
|
-
if (piece === null)
|
|
82
|
-
return kept.resume;
|
|
83
|
-
const pieces = frame.entries.reduce((sum, entry) => sum + (entry.kind === 'piece' ? (entry.text?.length ?? 0) : 0), 0);
|
|
84
|
-
return {
|
|
85
|
-
...point,
|
|
86
|
-
handled: frame.handled,
|
|
87
|
-
piece: { sha256: piece.sha256, offset: piece.offset + pieces },
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
27
|
export function houseNotifications(transport, mode) {
|
|
91
28
|
const stream = transport.stream;
|
|
92
29
|
const lines = new Map();
|
|
93
|
-
const
|
|
94
|
-
let receipts = null;
|
|
95
|
-
let loaded = Promise.resolve();
|
|
30
|
+
const staged = new Map();
|
|
96
31
|
let acknowledging = null;
|
|
97
|
-
let receiving = Promise.resolve();
|
|
98
|
-
let verifying = 0;
|
|
99
32
|
const locators = new Map();
|
|
100
33
|
const observers = new Set();
|
|
101
34
|
const conversationObservers = new Set();
|
|
@@ -125,6 +58,7 @@ export function houseNotifications(transport, mode) {
|
|
|
125
58
|
function reopened(next) {
|
|
126
59
|
opening = next;
|
|
127
60
|
acknowledging = next;
|
|
61
|
+
staged.clear();
|
|
128
62
|
const gapped = new Set([...replicated, ...live]);
|
|
129
63
|
live.clear();
|
|
130
64
|
for (const conversation of gapped)
|
|
@@ -198,160 +132,36 @@ export function houseNotifications(transport, mode) {
|
|
|
198
132
|
if (line !== undefined)
|
|
199
133
|
lines.set(authority, { ...line, frames: [] });
|
|
200
134
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (held.length > 0)
|
|
204
|
-
await receipts?.drop(held).catch(() => { });
|
|
205
|
-
}
|
|
206
|
-
async function lost(authority, carry) {
|
|
135
|
+
function lost(authority, carry) {
|
|
136
|
+
staged.delete(carry);
|
|
207
137
|
interrupt(authority);
|
|
208
|
-
await forget([carry]);
|
|
209
138
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return;
|
|
215
|
-
const held = kept.get(frame.carry);
|
|
216
|
-
if (held === undefined && frame.index !== 0) {
|
|
217
|
-
interrupt(frame.authority);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
if (held !== undefined &&
|
|
221
|
-
(held.fenced !== null || frame.index > held.parts || frame.index < (held.resume?.parts ?? 0))) {
|
|
222
|
-
await lost(frame.authority, frame.carry);
|
|
139
|
+
function stage(frame, via) {
|
|
140
|
+
const held = staged.get(frame.carry);
|
|
141
|
+
if (frame.index !== (held?.parts ?? 0)) {
|
|
142
|
+
lost(frame.authority, frame.carry);
|
|
223
143
|
return;
|
|
224
144
|
}
|
|
225
145
|
if (held === undefined) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const start = held ?? {
|
|
231
|
-
authority: frame.authority,
|
|
232
|
-
carry: frame.carry,
|
|
233
|
-
logEpoch: lines.get(frame.authority)?.logEpoch ?? null,
|
|
234
|
-
after: frame.after,
|
|
235
|
-
parts: 0,
|
|
236
|
-
resume: null,
|
|
237
|
-
fenced: null,
|
|
238
|
-
};
|
|
239
|
-
const next = { ...start, parts: frame.index + 1, resume: resumed(start, frame) };
|
|
240
|
-
const part = { entries: frame.entries };
|
|
241
|
-
try {
|
|
242
|
-
await port.keep(frame.carry, next, { index: frame.index, value: part });
|
|
243
|
-
}
|
|
244
|
-
catch {
|
|
245
|
-
await lost(frame.authority, frame.carry);
|
|
246
|
-
return;
|
|
146
|
+
for (const [carry, other] of staged) {
|
|
147
|
+
if (other.authority === frame.authority)
|
|
148
|
+
staged.delete(carry);
|
|
149
|
+
}
|
|
247
150
|
}
|
|
248
|
-
|
|
151
|
+
const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
|
|
152
|
+
next.entries.push(...frame.entries);
|
|
153
|
+
next.parts += 1;
|
|
154
|
+
staged.set(frame.carry, next);
|
|
249
155
|
via?.received(frame.authority, frame.carry, frame.index);
|
|
250
156
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
const read = (await receipts.parts(carry, parts));
|
|
257
|
-
if (read.length !== parts)
|
|
258
|
-
return null;
|
|
259
|
-
const entries = assembled(read.flatMap((part) => part.entries));
|
|
260
|
-
return entries !== null && (await verified(entries)) ? entries : null;
|
|
261
|
-
}
|
|
262
|
-
async function carried(frame) {
|
|
263
|
-
await loaded;
|
|
264
|
-
const held = kept.get(frame.carry);
|
|
265
|
-
if (frame.parts > 0 && held?.parts !== frame.parts) {
|
|
266
|
-
await lost(frame.authority, frame.carry);
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
const entries = await keptEntries(frame.carry, frame.parts).catch(() => null);
|
|
270
|
-
if (entries === null) {
|
|
271
|
-
await lost(frame.authority, frame.carry);
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
const fenced = {
|
|
275
|
-
...(held ?? {
|
|
276
|
-
authority: frame.authority,
|
|
277
|
-
carry: frame.carry,
|
|
278
|
-
logEpoch: frame.log_epoch,
|
|
279
|
-
after: frame.after,
|
|
280
|
-
parts: 0,
|
|
281
|
-
resume: null,
|
|
282
|
-
}),
|
|
283
|
-
after: frame.after,
|
|
284
|
-
fenced: { position: frame.position, logEpoch: frame.log_epoch },
|
|
285
|
-
};
|
|
286
|
-
try {
|
|
287
|
-
await receipts?.keep(frame.carry, fenced);
|
|
288
|
-
}
|
|
289
|
-
catch {
|
|
290
|
-
await lost(frame.authority, frame.carry);
|
|
157
|
+
function carried(frame) {
|
|
158
|
+
const held = staged.get(frame.carry);
|
|
159
|
+
staged.delete(frame.carry);
|
|
160
|
+
if ((held?.parts ?? 0) !== frame.parts) {
|
|
161
|
+
interrupt(frame.authority);
|
|
291
162
|
return;
|
|
292
163
|
}
|
|
293
|
-
|
|
294
|
-
publish(frame, entries);
|
|
295
|
-
}
|
|
296
|
-
async function load(port) {
|
|
297
|
-
try {
|
|
298
|
-
for (const { key, head } of await port.heads())
|
|
299
|
-
kept.set(key, head);
|
|
300
|
-
}
|
|
301
|
-
catch {
|
|
302
|
-
kept.clear();
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
async function restored(room) {
|
|
306
|
-
const line = lines.get(room.authority);
|
|
307
|
-
let at = room.position;
|
|
308
|
-
const chain = [];
|
|
309
|
-
for (;;) {
|
|
310
|
-
const next = [...kept.values()].find((carry) => carry.authority === room.authority &&
|
|
311
|
-
carry.after === at &&
|
|
312
|
-
carry.fenced?.logEpoch === room.log_epoch);
|
|
313
|
-
if (next?.fenced == null)
|
|
314
|
-
break;
|
|
315
|
-
const entries = await keptEntries(next.carry, next.parts).catch(() => null);
|
|
316
|
-
if (entries === null)
|
|
317
|
-
break;
|
|
318
|
-
chain.push({ carry: next, entries });
|
|
319
|
-
at = next.fenced.position;
|
|
320
|
-
}
|
|
321
|
-
const partial = [...kept.values()].find((carry) => carry.authority === room.authority &&
|
|
322
|
-
carry.fenced === null &&
|
|
323
|
-
carry.logEpoch === room.log_epoch &&
|
|
324
|
-
carry.after === at &&
|
|
325
|
-
carry.resume !== null &&
|
|
326
|
-
carry.resume.parts > 0);
|
|
327
|
-
const stale = [...kept.values()].filter((carry) => carry.authority === room.authority &&
|
|
328
|
-
carry !== partial &&
|
|
329
|
-
!chain.some((link) => link.carry === carry));
|
|
330
|
-
await forget(stale.map((carry) => carry.carry));
|
|
331
|
-
if (line !== undefined && line.logEpoch === room.log_epoch && chain.length > 0) {
|
|
332
|
-
const frames = chain.map(({ carry, entries }) => ({
|
|
333
|
-
after: BigInt(carry.after),
|
|
334
|
-
position: BigInt(carry.fenced.position),
|
|
335
|
-
entries,
|
|
336
|
-
}));
|
|
337
|
-
lines.set(room.authority, { ...line, frames: [...line.frames, ...frames] });
|
|
338
|
-
}
|
|
339
|
-
return {
|
|
340
|
-
...room,
|
|
341
|
-
position: at,
|
|
342
|
-
...(partial?.resume == null
|
|
343
|
-
? {}
|
|
344
|
-
: {
|
|
345
|
-
carry: {
|
|
346
|
-
id: partial.carry,
|
|
347
|
-
parts: partial.resume.parts,
|
|
348
|
-
from: partial.resume.from,
|
|
349
|
-
target: partial.resume.target,
|
|
350
|
-
handled: partial.resume.handled,
|
|
351
|
-
...(partial.resume.piece === null ? {} : { piece: partial.resume.piece }),
|
|
352
|
-
},
|
|
353
|
-
}),
|
|
354
|
-
};
|
|
164
|
+
publish(frame, held?.entries ?? []);
|
|
355
165
|
}
|
|
356
166
|
function handle(frame, via) {
|
|
357
167
|
if (frame.type === 'signal') {
|
|
@@ -398,9 +208,9 @@ export function houseNotifications(transport, mode) {
|
|
|
398
208
|
return;
|
|
399
209
|
}
|
|
400
210
|
if (frame.type === 'part')
|
|
401
|
-
|
|
402
|
-
if (frame.type === 'carried')
|
|
403
|
-
|
|
211
|
+
stage(frame, via);
|
|
212
|
+
else if (frame.type === 'carried')
|
|
213
|
+
carried(frame);
|
|
404
214
|
}
|
|
405
215
|
function publish(frame, entries) {
|
|
406
216
|
const at = position(frame.position);
|
|
@@ -425,29 +235,12 @@ export function houseNotifications(transport, mode) {
|
|
|
425
235
|
}
|
|
426
236
|
announce(frame.authority, { position: frame.position, logEpoch: frame.log_epoch });
|
|
427
237
|
}
|
|
428
|
-
stream.observe((frame) =>
|
|
429
|
-
const via = acknowledging;
|
|
430
|
-
if (verifying === 0) {
|
|
431
|
-
const handled = handle(frame, via);
|
|
432
|
-
if (handled === undefined)
|
|
433
|
-
return;
|
|
434
|
-
verifying += 1;
|
|
435
|
-
receiving = handled.finally(() => {
|
|
436
|
-
verifying -= 1;
|
|
437
|
-
});
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
verifying += 1;
|
|
441
|
-
receiving = receiving
|
|
442
|
-
.then(() => handle(frame, via))
|
|
443
|
-
.finally(() => {
|
|
444
|
-
verifying -= 1;
|
|
445
|
-
});
|
|
446
|
-
});
|
|
238
|
+
stream.observe((frame) => handle(frame, acknowledging));
|
|
447
239
|
stream.opened(reopened);
|
|
448
240
|
stream.closed(({ revoked, lost }) => {
|
|
449
241
|
opening = null;
|
|
450
242
|
acknowledging = null;
|
|
243
|
+
staged.clear();
|
|
451
244
|
emit({ kind: 'closed', revoked, lost });
|
|
452
245
|
});
|
|
453
246
|
return {
|
|
@@ -471,12 +264,8 @@ export function houseNotifications(transport, mode) {
|
|
|
471
264
|
};
|
|
472
265
|
},
|
|
473
266
|
},
|
|
474
|
-
observe(notify
|
|
267
|
+
observe(notify) {
|
|
475
268
|
observers.add(notify);
|
|
476
|
-
if (receipts === null) {
|
|
477
|
-
receipts = port;
|
|
478
|
-
loaded = load(port);
|
|
479
|
-
}
|
|
480
269
|
if (opening !== null) {
|
|
481
270
|
queueMicrotask(() => {
|
|
482
271
|
if (observers.has(notify))
|
|
@@ -497,30 +286,7 @@ export function houseNotifications(transport, mode) {
|
|
|
497
286
|
}
|
|
498
287
|
const current = opening;
|
|
499
288
|
opening = null;
|
|
500
|
-
|
|
501
|
-
return;
|
|
502
|
-
void loaded
|
|
503
|
-
.then(() => Promise.all(rooms.map(restored)))
|
|
504
|
-
.then((presented) => {
|
|
505
|
-
current.hold(presented, runtime);
|
|
506
|
-
for (const [index, room] of presented.entries()) {
|
|
507
|
-
if (room.position === rooms[index].position)
|
|
508
|
-
continue;
|
|
509
|
-
announce(room.authority, { position: room.position, logEpoch: room.log_epoch });
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
},
|
|
513
|
-
published(locator, at) {
|
|
514
|
-
const authority = [...locators].find(([, held]) => held.includes(locator))?.[0];
|
|
515
|
-
const reached = position(at.position);
|
|
516
|
-
if (authority === undefined || reached === null)
|
|
517
|
-
return;
|
|
518
|
-
void forget([...kept.values()]
|
|
519
|
-
.filter((carry) => carry.authority === authority &&
|
|
520
|
-
carry.fenced !== null &&
|
|
521
|
-
carry.fenced.logEpoch === at.logEpoch &&
|
|
522
|
-
BigInt(carry.fenced.position) <= reached)
|
|
523
|
-
.map((carry) => carry.carry));
|
|
289
|
+
current?.hold(rooms, runtime);
|
|
524
290
|
},
|
|
525
291
|
reopen() {
|
|
526
292
|
const current = opening;
|
|
@@ -539,9 +305,10 @@ export function houseNotifications(transport, mode) {
|
|
|
539
305
|
if (!locators.has(authority))
|
|
540
306
|
lines.delete(authority);
|
|
541
307
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
308
|
+
for (const [carry, held] of staged) {
|
|
309
|
+
if (!locators.has(held.authority))
|
|
310
|
+
staged.delete(carry);
|
|
311
|
+
}
|
|
545
312
|
},
|
|
546
313
|
reach(authority, at) {
|
|
547
314
|
const line = lines.get(authority);
|
|
@@ -556,18 +323,7 @@ export function houseNotifications(transport, mode) {
|
|
|
556
323
|
held,
|
|
557
324
|
});
|
|
558
325
|
},
|
|
559
|
-
|
|
560
|
-
const line = lines.get(tracked.authority);
|
|
561
|
-
const start = position(from.position);
|
|
562
|
-
if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
|
|
563
|
-
return [];
|
|
564
|
-
return [
|
|
565
|
-
...new Set(line.frames
|
|
566
|
-
.filter((frame) => frame.position > start)
|
|
567
|
-
.flatMap((frame) => frame.entries.flatMap((entry) => entry.kind === 'edited' && entry.revision !== undefined ? [entry.path] : []))),
|
|
568
|
-
];
|
|
569
|
-
},
|
|
570
|
-
*advance(tracked, from, holds) {
|
|
326
|
+
*advance(tracked, from) {
|
|
571
327
|
const line = lines.get(tracked.authority);
|
|
572
328
|
const start = position(from.position);
|
|
573
329
|
if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
|
|
@@ -585,12 +341,6 @@ export function houseNotifications(transport, mode) {
|
|
|
585
341
|
folded(answer, entry.path, entry.removed === true);
|
|
586
342
|
continue;
|
|
587
343
|
}
|
|
588
|
-
if (entry.kind === 'edited' &&
|
|
589
|
-
entry.revision !== undefined &&
|
|
590
|
-
holds?.(entry.path, entry.revision) === true) {
|
|
591
|
-
forgotten(answer, entry.path);
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
344
|
if (entry.path === tracked.schema)
|
|
595
345
|
schemas.set(entry.path, entry);
|
|
596
346
|
if (entry.kind === 'removed') {
|
|
@@ -599,7 +349,7 @@ export function houseNotifications(transport, mode) {
|
|
|
599
349
|
continue;
|
|
600
350
|
}
|
|
601
351
|
const binary = binaryFileOf(entry);
|
|
602
|
-
if (binary === null
|
|
352
|
+
if (binary === null)
|
|
603
353
|
return null;
|
|
604
354
|
if (mode === 'credential' && entry.revision === undefined)
|
|
605
355
|
return null;
|