@agentshouse/mdruntime-adapter 0.1.0-cda5b3be3317e → 0.1.0-ce1149641691d
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 +28 -23
- package/dist/actions.d.ts +3 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +25 -7
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +143 -84
- package/dist/discovery.d.ts +3 -2
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +24 -6
- package/dist/gather.d.ts +1 -1
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +4 -14
- package/dist/handed.d.ts +6 -6
- package/dist/handed.d.ts.map +1 -1
- package/dist/handed.js +36 -29
- package/dist/part.d.ts +13 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +80 -0
- package/dist/read.d.ts +33 -23
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +159 -120
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +57 -73
- package/dist/stream.d.ts +2 -3
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +23 -34
- package/dist/transport.d.ts +1 -0
- package/dist/transport.d.ts.map +1 -1
- package/dist/write.d.ts +12 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +79 -38
- package/package.json +2 -2
package/dist/read.js
CHANGED
|
@@ -1,21 +1,52 @@
|
|
|
1
|
+
import { patching, ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { checkedPayload, gunzipped, parsePart } from './part.js';
|
|
1
3
|
import { DECIMAL, readPosition, roomVersion } from './version.js';
|
|
2
4
|
const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
function fileOf(revision) {
|
|
6
|
+
return REVISION_FILE.exec(revision)?.[1];
|
|
7
|
+
}
|
|
8
|
+
export function answering() {
|
|
9
|
+
return {
|
|
10
|
+
documents: new Map(),
|
|
11
|
+
revisions: new Map(),
|
|
12
|
+
fileIds: new Map(),
|
|
13
|
+
changes: new Map(),
|
|
14
|
+
binaryFiles: new Map(),
|
|
15
|
+
removals: new Set(),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function revised(answer, path, revision) {
|
|
19
|
+
answer.revisions.set(path, revision);
|
|
20
|
+
const file = fileOf(revision);
|
|
21
|
+
if (file !== undefined)
|
|
22
|
+
answer.fileIds.set(path, file);
|
|
23
|
+
}
|
|
24
|
+
export function forgotten(answer, path) {
|
|
25
|
+
answer.documents.delete(path);
|
|
26
|
+
answer.revisions.delete(path);
|
|
27
|
+
answer.fileIds.delete(path);
|
|
28
|
+
answer.changes.delete(path);
|
|
29
|
+
answer.binaryFiles.delete(path);
|
|
30
|
+
answer.removals.delete(path);
|
|
31
|
+
}
|
|
32
|
+
export function* answered(answer) {
|
|
33
|
+
const removals = [];
|
|
34
|
+
for (const path of answer.removals) {
|
|
35
|
+
removals.push(path);
|
|
36
|
+
yield ROW_WEIGHT;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
documents: yield* patching({}, answer.documents),
|
|
40
|
+
revisions: yield* patching({}, answer.revisions),
|
|
41
|
+
...(answer.fileIds.size === 0 ? {} : { fileIds: yield* patching({}, answer.fileIds) }),
|
|
42
|
+
changes: yield* patching({}, answer.changes),
|
|
43
|
+
binaryFiles: yield* patching({}, answer.binaryFiles),
|
|
44
|
+
removals,
|
|
45
|
+
};
|
|
9
46
|
}
|
|
10
47
|
export function authorityRoot(handle) {
|
|
11
48
|
return `/rooms/${handle}`;
|
|
12
49
|
}
|
|
13
|
-
export function contentPrefixes(tracked) {
|
|
14
|
-
return [
|
|
15
|
-
authorityRoot(tracked.handle),
|
|
16
|
-
...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
|
|
17
|
-
];
|
|
18
|
-
}
|
|
19
50
|
export function schemaPath(handle, schema) {
|
|
20
51
|
return `${authorityRoot(handle)}/${schema}`;
|
|
21
52
|
}
|
|
@@ -105,13 +136,13 @@ function parseFile(value, mode) {
|
|
|
105
136
|
...binaried(binary),
|
|
106
137
|
};
|
|
107
138
|
}
|
|
108
|
-
function
|
|
139
|
+
function parseRoomParts(value) {
|
|
109
140
|
if (typeof value !== 'object' || value === null)
|
|
110
141
|
return null;
|
|
111
142
|
const held = value;
|
|
112
143
|
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
113
144
|
return null;
|
|
114
|
-
if (!Array.isArray(held.
|
|
145
|
+
if (!Array.isArray(held.parts))
|
|
115
146
|
return null;
|
|
116
147
|
const manifest = held.manifest;
|
|
117
148
|
if (manifest.scope !== 'room')
|
|
@@ -121,78 +152,89 @@ function parseScope(value, mode) {
|
|
|
121
152
|
return null;
|
|
122
153
|
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
123
154
|
return null;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const file = parseFile(entry, mode);
|
|
129
|
-
if (file === null)
|
|
130
|
-
return null;
|
|
131
|
-
files.push(file);
|
|
132
|
-
}
|
|
133
|
-
const contents = [];
|
|
134
|
-
for (const entry of held.contents) {
|
|
135
|
-
if (typeof entry !== 'object' || entry === null)
|
|
155
|
+
const parts = [];
|
|
156
|
+
for (const entry of held.parts) {
|
|
157
|
+
const part = parsePart(entry);
|
|
158
|
+
if (part === null)
|
|
136
159
|
return null;
|
|
137
|
-
|
|
138
|
-
if (typeof content.path !== 'string' || typeof content.content !== 'string')
|
|
139
|
-
return null;
|
|
140
|
-
contents.push({ path: content.path, content: content.content });
|
|
160
|
+
parts.push(part);
|
|
141
161
|
}
|
|
142
|
-
return { anchor: manifest.anchor, ...at,
|
|
143
|
-
}
|
|
144
|
-
function parseCut(value) {
|
|
145
|
-
if (value === undefined)
|
|
146
|
-
return undefined;
|
|
147
|
-
if (typeof value !== 'object' || value === null)
|
|
148
|
-
return null;
|
|
149
|
-
const { position, log_epoch: logEpoch } = value;
|
|
150
|
-
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
151
|
-
return null;
|
|
152
|
-
return { position, log_epoch: logEpoch };
|
|
162
|
+
return { anchor: manifest.anchor, ...at, parts };
|
|
153
163
|
}
|
|
154
|
-
function
|
|
155
|
-
if (typeof value !== 'object' || value === null)
|
|
156
|
-
return null;
|
|
157
|
-
const { room, path, cut } = value;
|
|
158
|
-
if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
|
|
159
|
-
return null;
|
|
160
|
-
const parsed = parseCut(cut);
|
|
161
|
-
if (parsed === null)
|
|
162
|
-
return null;
|
|
163
|
-
return { room, path, ...(parsed === undefined ? {} : { cut: parsed }) };
|
|
164
|
-
}
|
|
165
|
-
export function parseEnvelope(body) {
|
|
164
|
+
export function parseParted(body) {
|
|
166
165
|
if (typeof body !== 'object' || body === null)
|
|
167
166
|
return null;
|
|
168
167
|
if (!('scopes' in body) || !Array.isArray(body.scopes))
|
|
169
168
|
return null;
|
|
170
|
-
const
|
|
169
|
+
const rooms = [];
|
|
171
170
|
for (const entry of body.scopes) {
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
171
|
+
const room = parseRoomParts(entry);
|
|
172
|
+
if (room === null)
|
|
174
173
|
return null;
|
|
175
|
-
|
|
174
|
+
rooms.push(room);
|
|
176
175
|
}
|
|
177
176
|
if (!('next' in body) || body.next === undefined)
|
|
178
|
-
return {
|
|
179
|
-
const next =
|
|
180
|
-
|
|
177
|
+
return { rooms };
|
|
178
|
+
const next = body.next;
|
|
179
|
+
if (typeof next !== 'object' || next === null || typeof next.room !== 'string')
|
|
180
|
+
return null;
|
|
181
|
+
return { rooms, next: next.room };
|
|
181
182
|
}
|
|
182
|
-
export function
|
|
183
|
-
return
|
|
183
|
+
export function parseSiteParted(body) {
|
|
184
|
+
return parseRoomParts(body);
|
|
184
185
|
}
|
|
185
|
-
export function
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
export function emptyScope(room) {
|
|
187
|
+
return {
|
|
188
|
+
anchor: room.anchor,
|
|
189
|
+
position: room.position,
|
|
190
|
+
logEpoch: room.logEpoch,
|
|
191
|
+
files: [],
|
|
192
|
+
contents: [],
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function* partLines(text, mode) {
|
|
196
|
+
const files = [];
|
|
197
|
+
const contents = [];
|
|
198
|
+
let start = 0;
|
|
199
|
+
while (start < text.length) {
|
|
200
|
+
const end = text.indexOf('\n', start);
|
|
201
|
+
if (end === -1)
|
|
202
|
+
return null;
|
|
203
|
+
let entry;
|
|
204
|
+
try {
|
|
205
|
+
entry = JSON.parse(text.slice(start, end));
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
start = end + 1;
|
|
211
|
+
if (folderLine(entry))
|
|
212
|
+
continue;
|
|
213
|
+
const file = parseFile(entry, mode);
|
|
214
|
+
if (file === null)
|
|
215
|
+
return null;
|
|
216
|
+
files.push(file);
|
|
217
|
+
const { content } = entry;
|
|
218
|
+
if (typeof content === 'string')
|
|
219
|
+
contents.push({ path: file.path, content });
|
|
220
|
+
else if (content !== undefined)
|
|
221
|
+
return null;
|
|
222
|
+
yield ROW_WEIGHT;
|
|
223
|
+
}
|
|
224
|
+
return { files, contents };
|
|
225
|
+
}
|
|
226
|
+
function folderLine(entry) {
|
|
227
|
+
if (typeof entry !== 'object' || entry === null || !('folder' in entry))
|
|
228
|
+
return false;
|
|
229
|
+
return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
|
|
189
230
|
}
|
|
190
|
-
export function
|
|
191
|
-
|
|
231
|
+
export async function housePart(room, body, listed, mode) {
|
|
232
|
+
const payload = await checkedPayload(body, listed);
|
|
233
|
+
if (payload === null)
|
|
192
234
|
return null;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
235
|
+
const text = await gunzipped(payload);
|
|
236
|
+
const read = text === null ? null : await stepped(partLines(text, mode));
|
|
237
|
+
return read === null ? { kind: 'transport-uncertainty' } : { ...emptyScope(room), ...read };
|
|
196
238
|
}
|
|
197
239
|
function parseChange(value, mode) {
|
|
198
240
|
if (typeof value !== 'object' || value === null)
|
|
@@ -310,12 +352,21 @@ export async function wholeView(first, more) {
|
|
|
310
352
|
changes: [...changes.values()],
|
|
311
353
|
};
|
|
312
354
|
}
|
|
313
|
-
export function advancedScope(scope, view) {
|
|
314
|
-
const files = new Map(
|
|
315
|
-
const
|
|
355
|
+
export function* advancedScope(scope, view) {
|
|
356
|
+
const files = new Map();
|
|
357
|
+
for (const file of scope.files) {
|
|
358
|
+
files.set(file.path, file);
|
|
359
|
+
yield ROW_WEIGHT;
|
|
360
|
+
}
|
|
361
|
+
const contents = new Map();
|
|
362
|
+
for (const entry of scope.contents) {
|
|
363
|
+
contents.set(entry.path, entry.content);
|
|
364
|
+
yield ROW_WEIGHT;
|
|
365
|
+
}
|
|
316
366
|
for (const change of view.changes) {
|
|
317
367
|
files.delete(change.path);
|
|
318
368
|
contents.delete(change.path);
|
|
369
|
+
yield ROW_WEIGHT;
|
|
319
370
|
if ('removed' in change)
|
|
320
371
|
continue;
|
|
321
372
|
files.set(change.path, {
|
|
@@ -328,43 +379,40 @@ export function advancedScope(scope, view) {
|
|
|
328
379
|
if ('content' in change)
|
|
329
380
|
contents.set(change.path, change.content);
|
|
330
381
|
}
|
|
382
|
+
const listed = [];
|
|
383
|
+
for (const [path, content] of contents) {
|
|
384
|
+
listed.push({ path, content });
|
|
385
|
+
yield ROW_WEIGHT;
|
|
386
|
+
}
|
|
331
387
|
return {
|
|
332
388
|
...scope,
|
|
333
389
|
position: view.position,
|
|
334
390
|
logEpoch: view.logEpoch,
|
|
335
391
|
files: [...files.values()],
|
|
336
|
-
contents:
|
|
392
|
+
contents: listed,
|
|
337
393
|
};
|
|
338
394
|
}
|
|
339
|
-
export function
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
const changes = {};
|
|
347
|
-
const binaryFiles = {};
|
|
395
|
+
export function* bootstrapping(scope) {
|
|
396
|
+
const contents = new Map();
|
|
397
|
+
for (const entry of scope.contents) {
|
|
398
|
+
contents.set(entry.path, entry.content);
|
|
399
|
+
yield ROW_WEIGHT;
|
|
400
|
+
}
|
|
401
|
+
const answer = answering();
|
|
348
402
|
for (const file of scope.files) {
|
|
349
|
-
|
|
350
|
-
revisions[file.path] = file.revision;
|
|
403
|
+
yield ROW_WEIGHT;
|
|
351
404
|
if (file.head !== undefined)
|
|
352
|
-
changes
|
|
405
|
+
answer.changes.set(file.path, file.head);
|
|
353
406
|
const content = contents.get(file.path);
|
|
354
407
|
if (file.binary !== undefined)
|
|
355
|
-
binaryFiles
|
|
408
|
+
answer.binaryFiles.set(file.path, file.binary);
|
|
356
409
|
else if (content !== undefined)
|
|
357
|
-
documents
|
|
410
|
+
answer.documents.set(file.path, content);
|
|
411
|
+
if (file.revision !== undefined)
|
|
412
|
+
revised(answer, file.path, file.revision);
|
|
358
413
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
roomVersion: roomVersion(scope),
|
|
362
|
-
documents,
|
|
363
|
-
revisions,
|
|
364
|
-
...identities(revisions),
|
|
365
|
-
changes,
|
|
366
|
-
binaryFiles,
|
|
367
|
-
};
|
|
414
|
+
const { removals: _removals, ...page } = yield* answered(answer);
|
|
415
|
+
return { kind: 'bootstrap', roomVersion: roomVersion(scope), ...page };
|
|
368
416
|
}
|
|
369
417
|
export function schemaOf(scope, schema) {
|
|
370
418
|
const file = scope.files.find((entry) => entry.path === schema);
|
|
@@ -378,36 +426,27 @@ export function schemaOf(scope, schema) {
|
|
|
378
426
|
export function viewOf(enumeration, tracked) {
|
|
379
427
|
return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
|
|
380
428
|
}
|
|
381
|
-
|
|
429
|
+
function* refreshing(view, fromRoomVersion) {
|
|
382
430
|
if (roomVersion(view) === fromRoomVersion)
|
|
383
431
|
return { kind: 'still-current' };
|
|
384
|
-
const
|
|
385
|
-
const revisions = {};
|
|
386
|
-
const changes = {};
|
|
387
|
-
const binaryFiles = {};
|
|
388
|
-
const removals = [];
|
|
432
|
+
const answer = answering();
|
|
389
433
|
for (const change of view.changes) {
|
|
434
|
+
yield ROW_WEIGHT;
|
|
390
435
|
if ('removed' in change) {
|
|
391
|
-
removals.
|
|
436
|
+
answer.removals.add(change.path);
|
|
392
437
|
continue;
|
|
393
438
|
}
|
|
394
439
|
if ('content' in change)
|
|
395
|
-
documents
|
|
440
|
+
answer.documents.set(change.path, change.content);
|
|
396
441
|
else
|
|
397
|
-
binaryFiles
|
|
398
|
-
if (change.revision !== undefined)
|
|
399
|
-
revisions[change.path] = change.revision;
|
|
442
|
+
answer.binaryFiles.set(change.path, change.binary);
|
|
400
443
|
if (change.head !== undefined)
|
|
401
|
-
changes
|
|
444
|
+
answer.changes.set(change.path, change.head);
|
|
445
|
+
if (change.revision !== undefined)
|
|
446
|
+
revised(answer, change.path, change.revision);
|
|
402
447
|
}
|
|
403
|
-
return {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
revisions,
|
|
408
|
-
...identities(revisions),
|
|
409
|
-
changes,
|
|
410
|
-
binaryFiles,
|
|
411
|
-
removals: removals.sort(),
|
|
412
|
-
};
|
|
448
|
+
return { kind: 'net-advancement', roomVersion: roomVersion(view), ...(yield* answered(answer)) };
|
|
449
|
+
}
|
|
450
|
+
export async function refreshFrom(view, fromRoomVersion) {
|
|
451
|
+
return stepped(refreshing(view, fromRoomVersion));
|
|
413
452
|
}
|
package/dist/site.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAUR,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAUR,MAAM,wBAAwB,CAAC;AA6BhC,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAuCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAkQ1F"}
|
package/dist/site.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { stepped } from '@agentshouse/mdruntime';
|
|
1
2
|
import { actionOutcome, SITE_SUBMIT } from './actions.js';
|
|
2
3
|
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
3
4
|
import { partModels, streamedModels, viewModels } from './model.js';
|
|
4
|
-
import { advancedScope,
|
|
5
|
-
import {
|
|
5
|
+
import { advancedScope, bootstrapping, emptyScope, housePart, parseEnumeration, parseSiteParted, refreshFrom, viewOf, wholeView, } from './read.js';
|
|
6
|
+
import { PART_ATTEMPTS, unverifiedPart } from './part.js';
|
|
6
7
|
import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
|
|
7
8
|
import { houseNotifications } from './stream.js';
|
|
8
9
|
import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, SITE_FILE_RECORD, SITE_FILES, } from './transport.js';
|
|
@@ -18,8 +19,8 @@ function siteRoom(tracked) {
|
|
|
18
19
|
locator: tracked.locator,
|
|
19
20
|
handle: tracked.handle,
|
|
20
21
|
roomVersion: roomVersion(tracked),
|
|
21
|
-
operations: {
|
|
22
|
-
replica: { selection: tracked.locator, admission: 'admitted' },
|
|
22
|
+
operations: { write: [], delete: [] },
|
|
23
|
+
replica: { selection: tracked.locator, admission: 'admitted', offline: 'open' },
|
|
23
24
|
providerOwnedPaths: [],
|
|
24
25
|
};
|
|
25
26
|
}
|
|
@@ -29,6 +30,7 @@ function settled(refused) {
|
|
|
29
30
|
export function createSiteAdapter(transport, snapshot = false) {
|
|
30
31
|
const notifications = houseNotifications(transport, 'site');
|
|
31
32
|
const tracked = new Map();
|
|
33
|
+
const expired = new Map();
|
|
32
34
|
function published(referrer) {
|
|
33
35
|
const named = houseReferrer(referrer, tracked);
|
|
34
36
|
return named === null || !tracked.has(named.locator) ? null : named;
|
|
@@ -68,73 +70,48 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
68
70
|
const first = await enumerated(entry, from);
|
|
69
71
|
return 'kind' in first ? first : wholeView(first, (page) => enumerated(entry, from, page));
|
|
70
72
|
}
|
|
71
|
-
async function
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
...(offset === null ? [] : [`offset=${offset}`]),
|
|
75
|
-
];
|
|
76
|
-
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${query.length === 0 ? '' : `?${query.join('&')}`}`);
|
|
73
|
+
async function partedRoom(entry) {
|
|
74
|
+
const cut = expired.get(entry.locator);
|
|
75
|
+
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`);
|
|
77
76
|
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
78
77
|
if (classified !== null)
|
|
79
|
-
return
|
|
80
|
-
const
|
|
81
|
-
return
|
|
78
|
+
return classified;
|
|
79
|
+
const room = parseSiteParted(answer.body);
|
|
80
|
+
return room === null || room.anchor !== entry.authority ? UNCERTAIN : room;
|
|
82
81
|
}
|
|
83
|
-
async function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (piece === undefined ||
|
|
95
|
-
part.scope.contents.length !== 1 ||
|
|
96
|
-
piece.path !== path ||
|
|
97
|
-
piece.content.length === 0) {
|
|
98
|
-
return UNCERTAIN;
|
|
99
|
-
}
|
|
100
|
-
text += piece.content;
|
|
101
|
-
const more = siteBootstrapOffset(part.body);
|
|
102
|
-
if (more === null)
|
|
103
|
-
break;
|
|
104
|
-
if (more !== text.length)
|
|
105
|
-
return UNCERTAIN;
|
|
82
|
+
async function fetchedPart(entry, room, listed) {
|
|
83
|
+
for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
|
|
84
|
+
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}?part=${encodeURIComponent(listed.part)}`);
|
|
85
|
+
const failure = classifyRead(answer.status, answer.body, entry.locator);
|
|
86
|
+
if (failure?.kind === 'beyond-horizon')
|
|
87
|
+
expired.set(entry.locator, room.position);
|
|
88
|
+
if (failure !== null)
|
|
89
|
+
return failure;
|
|
90
|
+
const scope = await housePart(room, answer.body, listed, 'site');
|
|
91
|
+
if (scope !== null)
|
|
92
|
+
return scope;
|
|
106
93
|
}
|
|
107
|
-
|
|
108
|
-
if (file === undefined || (await sha256Hex(text)) !== file.version)
|
|
109
|
-
return UNCERTAIN;
|
|
110
|
-
return { ...scope, contents: [...scope.contents.slice(0, -1), { path, content: text }] };
|
|
94
|
+
return unverifiedPart(entry.locator);
|
|
111
95
|
}
|
|
112
|
-
async function caughtUp(entry,
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const scope = await assembled(entry, part.scope, next, offset);
|
|
122
|
-
return 'kind' in scope ? { failure: scope } : { scope, next };
|
|
123
|
-
}
|
|
124
|
-
const { scope } = part;
|
|
125
|
-
if (after !== null || next !== null || roomVersion(scope) === roomVersion(entry)) {
|
|
126
|
-
return { scope, next };
|
|
127
|
-
}
|
|
96
|
+
async function caughtUp(entry, continued) {
|
|
97
|
+
const listed = continued.room.parts[continued.next];
|
|
98
|
+
const scope = listed === undefined
|
|
99
|
+
? emptyScope(continued.room)
|
|
100
|
+
: await fetchedPart(entry, continued.room, listed);
|
|
101
|
+
if ('kind' in scope)
|
|
102
|
+
return scope;
|
|
103
|
+
if (continued.room.parts.length > 1 || roomVersion(scope) === roomVersion(entry))
|
|
104
|
+
return scope;
|
|
128
105
|
const view = await enumeration(entry, scope);
|
|
129
106
|
if ('kind' in view)
|
|
130
|
-
return
|
|
131
|
-
return
|
|
107
|
+
return settled(view);
|
|
108
|
+
return stepped(advancedScope(scope, view));
|
|
132
109
|
}
|
|
133
110
|
async function refreshed(entry, fromRoomVersion) {
|
|
134
111
|
const from = logPosition(fromRoomVersion);
|
|
135
112
|
if (from === null)
|
|
136
113
|
return { kind: 'beyond-horizon' };
|
|
137
|
-
const streamed = notifications.advance(entry, from);
|
|
114
|
+
const streamed = await stepped(notifications.advance(entry, from));
|
|
138
115
|
if (streamed !== null) {
|
|
139
116
|
const models = await streamedModels(streamed.schemas, entry, 'site');
|
|
140
117
|
return models === undefined ? streamed.page : { ...streamed.page, models };
|
|
@@ -143,7 +120,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
143
120
|
if ('kind' in view)
|
|
144
121
|
return view;
|
|
145
122
|
notifications.reach(entry.authority, view);
|
|
146
|
-
const answer = refreshFrom(view, fromRoomVersion);
|
|
123
|
+
const answer = await refreshFrom(view, fromRoomVersion);
|
|
147
124
|
if (answer.kind !== 'net-advancement')
|
|
148
125
|
return answer;
|
|
149
126
|
const models = await viewModels(view, entry);
|
|
@@ -174,23 +151,30 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
174
151
|
const entry = tracked.get(request.locator);
|
|
175
152
|
if (entry === undefined)
|
|
176
153
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
154
|
+
let continued;
|
|
155
|
+
if (request.pageToken === undefined) {
|
|
156
|
+
const room = await partedRoom(entry);
|
|
157
|
+
if ('kind' in room)
|
|
158
|
+
return room;
|
|
159
|
+
continued = { room, next: 0, seen: [] };
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
continued = JSON.parse(request.pageToken);
|
|
163
|
+
const scope = await caughtUp(entry, continued);
|
|
164
|
+
if ('kind' in scope)
|
|
165
|
+
return scope;
|
|
166
|
+
notifications.reach(entry.authority, scope);
|
|
167
|
+
const next = continued.next + 1;
|
|
168
|
+
const more = next < continued.room.parts.length;
|
|
184
169
|
const seen = [
|
|
185
|
-
...
|
|
186
|
-
...entry.schemas.filter((schema) =>
|
|
170
|
+
...continued.seen,
|
|
171
|
+
...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
|
|
187
172
|
];
|
|
188
|
-
const models = await partModels(
|
|
189
|
-
const continuation = held.next === null ? null : { after: held.next, seen };
|
|
173
|
+
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
190
174
|
return {
|
|
191
|
-
...
|
|
175
|
+
...(await stepped(bootstrapping(scope))),
|
|
192
176
|
...(models === undefined ? {} : { models }),
|
|
193
|
-
...(
|
|
177
|
+
...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
|
|
194
178
|
};
|
|
195
179
|
},
|
|
196
180
|
async refresh(_authorization, request) {
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ConversationStream, type RefreshPage, type RoomStreamEvent, type ServiceModeSignal, type StreamReceipts } 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
5
|
export type HeldRevision = (path: string, revision: string) => boolean;
|
|
6
6
|
export type StreamedAdvancement = {
|
|
7
7
|
page: RefreshPage;
|
|
8
|
-
entries: readonly HouseStreamEntry[];
|
|
9
8
|
schemas: ReadonlyMap<string, HouseStreamEntry>;
|
|
10
9
|
};
|
|
11
10
|
export type HouseNotifications = {
|
|
@@ -16,7 +15,7 @@ export type HouseNotifications = {
|
|
|
16
15
|
reopen(): void;
|
|
17
16
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
18
17
|
reach(authority: string, at: LogPosition): void;
|
|
19
|
-
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): StreamedAdvancement | null
|
|
18
|
+
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): Generator<number, StreamedAdvancement | null, void>;
|
|
20
19
|
conversations: ConversationStream;
|
|
21
20
|
serviceMode: ServiceModeSignal;
|
|
22
21
|
};
|
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,KAAK,
|
|
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,EACtB,KAAK,cAAc,EAEpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAEb,SAAS,EAET,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AA0C7D,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;AAEvE,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,EAAE,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAAC;IACxF,IAAI,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,IAAI,CAAC;IAC5C,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,CAAC;IAClD,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,EACjB,KAAK,CAAC,EAAE,YAAY,GACnB,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;IACvD,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAmFF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CA0iB5F"}
|