@agentshouse/mdruntime-adapter 0.1.0-c6ddfd288ac81 → 0.1.0-c7d05e09c73b7
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 +85 -42
- package/README.md +3 -3
- package/dist/actions.d.ts +2 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +3 -7
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +147 -143
- package/dist/discovery.d.ts +14 -27
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +52 -101
- package/dist/gather.d.ts +1 -0
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +11 -6
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/links.d.ts +10 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +57 -4
- package/dist/model.d.ts +8 -18
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +63 -39
- package/dist/read.d.ts +10 -5
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +23 -31
- package/dist/refusal.d.ts +6 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +33 -30
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +47 -77
- package/dist/stream.d.ts +11 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +144 -98
- package/dist/transport.d.ts +37 -15
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +0 -2
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +9 -0
- package/dist/write.d.ts +11 -6
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +27 -20
- package/package.json +3 -3
package/dist/read.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAEb,aAA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_SELECTION_ROOTS, RESERVED_NAMES, } from './discovery.js';
|
|
2
1
|
import { readPosition, roomVersion } from './version.js';
|
|
3
2
|
export function authorityRoot(handle) {
|
|
4
3
|
return `/rooms/${handle}`;
|
|
5
4
|
}
|
|
6
5
|
export function contentPrefixes(tracked) {
|
|
7
|
-
return [
|
|
6
|
+
return [
|
|
7
|
+
authorityRoot(tracked.handle),
|
|
8
|
+
...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
|
|
9
|
+
];
|
|
8
10
|
}
|
|
9
11
|
export function schemaPath(handle, schema) {
|
|
10
12
|
return `${authorityRoot(handle)}/${schema}`;
|
|
@@ -61,7 +63,7 @@ function parseOriginal(value) {
|
|
|
61
63
|
return null;
|
|
62
64
|
return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
|
|
63
65
|
}
|
|
64
|
-
function parseOriginals(value) {
|
|
66
|
+
export function parseOriginals(value) {
|
|
65
67
|
if (!Array.isArray(value))
|
|
66
68
|
return null;
|
|
67
69
|
const attachments = [];
|
|
@@ -135,6 +137,14 @@ function parseScope(value, mode) {
|
|
|
135
137
|
return null;
|
|
136
138
|
return { anchor: manifest.anchor, ...at, files, contents, attachments };
|
|
137
139
|
}
|
|
140
|
+
function parseCursor(value) {
|
|
141
|
+
if (typeof value !== 'object' || value === null)
|
|
142
|
+
return null;
|
|
143
|
+
const { room, path } = value;
|
|
144
|
+
if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
|
|
145
|
+
return null;
|
|
146
|
+
return { room, path };
|
|
147
|
+
}
|
|
138
148
|
export function parseEnvelope(body) {
|
|
139
149
|
if (typeof body !== 'object' || body === null)
|
|
140
150
|
return null;
|
|
@@ -147,7 +157,10 @@ export function parseEnvelope(body) {
|
|
|
147
157
|
return null;
|
|
148
158
|
scopes.push(scope);
|
|
149
159
|
}
|
|
150
|
-
|
|
160
|
+
if (!('next' in body) || body.next === undefined)
|
|
161
|
+
return { scopes };
|
|
162
|
+
const next = parseCursor(body.next);
|
|
163
|
+
return next === null ? null : { scopes, next };
|
|
151
164
|
}
|
|
152
165
|
export function parseSiteBootstrap(body) {
|
|
153
166
|
return parseScope(body, 'site');
|
|
@@ -256,28 +269,13 @@ export function advancedScope(scope, view) {
|
|
|
256
269
|
export function matchesScope(scope, tracked) {
|
|
257
270
|
return scope.anchor === tracked.authority;
|
|
258
271
|
}
|
|
259
|
-
|
|
260
|
-
function homes(tracked) {
|
|
261
|
-
return tracked.handle === PRIVATE_HANDLE
|
|
262
|
-
? [...ROOM_HOMES, ...PROVIDER_SELECTION_ROOTS]
|
|
263
|
-
: ROOM_HOMES;
|
|
264
|
-
}
|
|
265
|
-
export function selects(tracked, path) {
|
|
266
|
-
if (tracked.schemas.includes(path))
|
|
267
|
-
return false;
|
|
268
|
-
const first = path.split('/', 1)[0].toLowerCase();
|
|
269
|
-
return (!RESERVED_NAMES.some((name) => name.toLowerCase() === first) ||
|
|
270
|
-
homes(tracked).some((home) => path === home || path.startsWith(`${home}/`)));
|
|
271
|
-
}
|
|
272
|
-
export function bootstrapOf(scope, tracked) {
|
|
272
|
+
export function bootstrapOf(scope) {
|
|
273
273
|
const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
|
|
274
274
|
const documents = {};
|
|
275
275
|
const revisions = {};
|
|
276
276
|
const changes = {};
|
|
277
277
|
const binaryTargets = [];
|
|
278
278
|
for (const file of scope.files) {
|
|
279
|
-
if (!selects(tracked, file.path))
|
|
280
|
-
continue;
|
|
281
279
|
if (file.revision !== undefined)
|
|
282
280
|
revisions[file.path] = file.revision;
|
|
283
281
|
if (file.head !== undefined)
|
|
@@ -298,23 +296,19 @@ export function bootstrapOf(scope, tracked) {
|
|
|
298
296
|
...declared(scope.attachments),
|
|
299
297
|
};
|
|
300
298
|
}
|
|
301
|
-
export function schemaFrom(envelope, tracked, schema) {
|
|
302
|
-
const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));
|
|
303
|
-
if (scope === undefined)
|
|
304
|
-
return null;
|
|
305
|
-
return schemaOf(scope, schema);
|
|
306
|
-
}
|
|
307
299
|
export function schemaOf(scope, schema) {
|
|
308
300
|
const file = scope.files.find((entry) => entry.path === schema);
|
|
309
301
|
if (file === undefined)
|
|
310
|
-
return { schema: null, version: null };
|
|
302
|
+
return { schema: null, version: null, revision: null };
|
|
311
303
|
const content = scope.contents.find((entry) => entry.path === schema);
|
|
312
|
-
return content === undefined
|
|
304
|
+
return content === undefined
|
|
305
|
+
? null
|
|
306
|
+
: { schema: content.content, version: file.version, revision: file.revision ?? null };
|
|
313
307
|
}
|
|
314
308
|
export function viewOf(enumeration, tracked) {
|
|
315
309
|
return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
|
|
316
310
|
}
|
|
317
|
-
export function refreshFrom(view,
|
|
311
|
+
export function refreshFrom(view, fromRoomVersion) {
|
|
318
312
|
if (roomVersion(view) === fromRoomVersion)
|
|
319
313
|
return { kind: 'still-current' };
|
|
320
314
|
const documents = {};
|
|
@@ -323,8 +317,6 @@ export function refreshFrom(view, tracked, fromRoomVersion) {
|
|
|
323
317
|
const binaryTargets = [];
|
|
324
318
|
const removals = [];
|
|
325
319
|
for (const change of view.changes) {
|
|
326
|
-
if (!selects(tracked, change.path))
|
|
327
|
-
continue;
|
|
328
320
|
if ('removed' in change) {
|
|
329
321
|
removals.push(change.path);
|
|
330
322
|
continue;
|
package/dist/refusal.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
|
|
2
|
-
export type DoorRefusal = ProviderRefusal
|
|
2
|
+
export type DoorRefusal = ProviderRefusal & {
|
|
3
|
+
retryable: boolean;
|
|
4
|
+
};
|
|
3
5
|
export declare function doorRefusal(body: unknown): DoorRefusal | null;
|
|
4
6
|
export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: DoorRefusal): ScopedRefusal;
|
|
5
|
-
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure |
|
|
7
|
+
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
|
|
8
|
+
export declare function classifyRead(status: number, body: unknown, locator: string): AdapterFailure | {
|
|
6
9
|
kind: 'beyond-horizon';
|
|
7
10
|
} | null;
|
|
8
|
-
export declare function discoveryFailure(
|
|
9
|
-
kind: 'beyond-horizon';
|
|
10
|
-
}): DiscoverResult;
|
|
11
|
+
export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
|
|
11
12
|
//# sourceMappingURL=refusal.d.ts.map
|
package/dist/refusal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAEnE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAO7D;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,WAAW,GACnB,aAAa,CAEf;AAmBD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG,IAAI,CAMvB;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG,IAAI,CAGpD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAYrF"}
|
package/dist/refusal.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
const RETRYABLE_CODES = new Set([
|
|
2
|
-
'auth_unavailable',
|
|
3
|
-
'replica_behind',
|
|
4
|
-
'read_replica_unavailable',
|
|
5
|
-
'read_replica_lagging',
|
|
6
|
-
'read_pool_acquisition_timed_out',
|
|
7
|
-
'sync_unavailable',
|
|
8
|
-
'sync_failed',
|
|
9
|
-
'rate_limited',
|
|
10
|
-
'operation_contended',
|
|
11
|
-
'transaction_budget_exceeded',
|
|
12
|
-
]);
|
|
13
1
|
export function doorRefusal(body) {
|
|
14
2
|
if (typeof body !== 'object' || body === null)
|
|
15
3
|
return null;
|
|
@@ -19,39 +7,54 @@ export function doorRefusal(body) {
|
|
|
19
7
|
if (typeof error.code !== 'string')
|
|
20
8
|
return null;
|
|
21
9
|
const { code, ...fields } = error;
|
|
22
|
-
return { code, fields };
|
|
10
|
+
return { code, fields, retryable: error.retryable === true };
|
|
23
11
|
}
|
|
24
12
|
export function scopedRefusal(locator, scope, refusal) {
|
|
25
13
|
return { kind: 'scoped-refusal', locator, scope, code: refusal.code, fields: refusal.fields };
|
|
26
14
|
}
|
|
27
|
-
|
|
15
|
+
function doorFailure(status, body) {
|
|
28
16
|
if (status === 0)
|
|
29
17
|
return { kind: 'transport-uncertainty' };
|
|
30
18
|
const refusal = doorRefusal(body);
|
|
31
19
|
if (status === 401)
|
|
32
20
|
return { kind: 'revoked-authorization' };
|
|
33
|
-
if (refusal
|
|
34
|
-
return { kind: 'transport-uncertainty' };
|
|
35
|
-
if (refusal !== null && refusal.code === 'position_expired')
|
|
36
|
-
return { kind: 'beyond-horizon' };
|
|
37
|
-
if (status === 404 || refusal?.code === 'room_not_found') {
|
|
38
|
-
return { kind: 'room-not-readable', locator };
|
|
39
|
-
}
|
|
40
|
-
if (status >= 500)
|
|
21
|
+
if (refusal?.retryable === true)
|
|
41
22
|
return { kind: 'transport-uncertainty' };
|
|
23
|
+
if (status === 404 || refusal?.code === 'room_not_found')
|
|
24
|
+
return { kind: 'room-not-readable' };
|
|
42
25
|
if (status < 400)
|
|
43
26
|
return null;
|
|
44
27
|
if (refusal === null)
|
|
45
28
|
return { kind: 'transport-uncertainty' };
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
return { kind: 'refused', scope: status === 403 ? 'operation' : 'undisclosed', refusal };
|
|
30
|
+
}
|
|
31
|
+
export function classifyDoor(status, body, locator) {
|
|
32
|
+
const failure = doorFailure(status, body);
|
|
33
|
+
if (failure === null)
|
|
34
|
+
return null;
|
|
35
|
+
if (failure.kind === 'room-not-readable')
|
|
36
|
+
return { kind: 'room-not-readable', locator };
|
|
37
|
+
if (failure.kind === 'refused')
|
|
38
|
+
return scopedRefusal(locator, failure.scope, failure.refusal);
|
|
39
|
+
return failure;
|
|
49
40
|
}
|
|
50
|
-
export function
|
|
51
|
-
if (
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
export function classifyRead(status, body, locator) {
|
|
42
|
+
if (doorRefusal(body)?.code === 'expired')
|
|
43
|
+
return { kind: 'beyond-horizon' };
|
|
44
|
+
return classifyDoor(status, body, locator);
|
|
45
|
+
}
|
|
46
|
+
export function discoveryFailure(status, body) {
|
|
47
|
+
const failure = doorFailure(status, body);
|
|
48
|
+
if (failure === null)
|
|
49
|
+
return null;
|
|
50
|
+
if (failure.kind === 'revoked-authorization')
|
|
51
|
+
return failure;
|
|
52
|
+
if (failure.kind === 'refused') {
|
|
53
|
+
return {
|
|
54
|
+
kind: 'contract-unavailable',
|
|
55
|
+
code: failure.refusal.code,
|
|
56
|
+
fields: failure.refusal.fields,
|
|
57
|
+
};
|
|
55
58
|
}
|
|
56
59
|
return { kind: 'transport-uncertainty' };
|
|
57
60
|
}
|
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,
|
|
1
|
+
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAMR,MAAM,wBAAwB,CAAC;AAsBhC,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAgCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAkIxE"}
|
package/dist/site.js
CHANGED
|
@@ -1,43 +1,34 @@
|
|
|
1
1
|
import { actionOutcome } from './actions.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom,
|
|
5
|
-
import { classifyDoor,
|
|
2
|
+
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
3
|
+
import { scopeModels, streamedModels, viewModels } from './model.js';
|
|
4
|
+
import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom, viewOf, } from './read.js';
|
|
5
|
+
import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
|
|
6
6
|
import { houseNotifications } from './stream.js';
|
|
7
|
-
import {
|
|
8
|
-
import { logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
7
|
+
import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, } from './transport.js';
|
|
8
|
+
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
9
9
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
10
|
-
function siteRoom(tracked
|
|
10
|
+
function siteRoom(tracked) {
|
|
11
11
|
return {
|
|
12
12
|
name: tracked.handle,
|
|
13
13
|
locator: tracked.locator,
|
|
14
|
+
handle: tracked.handle,
|
|
14
15
|
roomVersion: roomVersion(tracked),
|
|
15
16
|
operations: { read: [''], sync: [''], write: [], delete: [] },
|
|
16
17
|
replica: { selection: tracked.locator, admission: 'admitted' },
|
|
17
|
-
attachedModel,
|
|
18
|
-
untypedFolders: [...UNTYPED_FOLDERS],
|
|
19
18
|
providerOwnedPaths: [],
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
21
|
function settled(refused) {
|
|
23
|
-
return refused.kind === 'beyond-horizon'
|
|
24
|
-
? UNCERTAIN
|
|
25
|
-
: refused;
|
|
22
|
+
return refused.kind === 'beyond-horizon' ? UNCERTAIN : refused;
|
|
26
23
|
}
|
|
27
24
|
export function createSiteAdapter(transport) {
|
|
28
25
|
const notifications = houseNotifications(transport, 'site');
|
|
29
26
|
const tracked = new Map();
|
|
30
|
-
const models = modelShelf();
|
|
31
|
-
const acquired = new Map();
|
|
32
|
-
let caught = new Map();
|
|
33
27
|
async function enumeration(entry, from) {
|
|
34
28
|
const answer = await transport.door(SITE_DOOR_ENUMERATE, {
|
|
35
29
|
positions: [presented(entry.authority, from)],
|
|
36
30
|
});
|
|
37
|
-
const
|
|
38
|
-
if (behind?.code === 'replica_behind')
|
|
39
|
-
return { kind: 'retryable-refusal', ...behind };
|
|
40
|
-
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
31
|
+
const classified = classifyRead(answer.status, answer.body, entry.locator);
|
|
41
32
|
if (classified !== null)
|
|
42
33
|
return classified;
|
|
43
34
|
return parseEnumeration(answer.body, 'site') ?? UNCERTAIN;
|
|
@@ -46,7 +37,7 @@ export function createSiteAdapter(transport) {
|
|
|
46
37
|
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}`);
|
|
47
38
|
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
48
39
|
if (classified !== null)
|
|
49
|
-
return { failure:
|
|
40
|
+
return { failure: classified };
|
|
50
41
|
const scope = parseSiteBootstrap(answer.body);
|
|
51
42
|
if (scope === null)
|
|
52
43
|
return { failure: UNCERTAIN };
|
|
@@ -65,35 +56,32 @@ export function createSiteAdapter(transport) {
|
|
|
65
56
|
if (from === null)
|
|
66
57
|
return { kind: 'beyond-horizon' };
|
|
67
58
|
const streamed = notifications.advance(entry, from);
|
|
68
|
-
if (streamed !== null)
|
|
69
|
-
|
|
59
|
+
if (streamed !== null) {
|
|
60
|
+
const models = await streamedModels(streamed.schemas, entry, 'site');
|
|
61
|
+
return models === undefined ? streamed.page : { ...streamed.page, models };
|
|
62
|
+
}
|
|
70
63
|
const found = await enumeration(entry, from);
|
|
71
64
|
if ('kind' in found)
|
|
72
65
|
return found;
|
|
73
66
|
const view = viewOf(found, entry);
|
|
74
67
|
if (view === undefined)
|
|
75
68
|
return { kind: 'room-not-readable', locator: entry.locator };
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
acquired.set(entry.authority, { roomVersion: roomVersion(held.scope), model });
|
|
83
|
-
return model;
|
|
69
|
+
notifications.reach(entry.authority, view);
|
|
70
|
+
const answer = refreshFrom(view, fromRoomVersion);
|
|
71
|
+
if (answer.kind !== 'net-advancement')
|
|
72
|
+
return answer;
|
|
73
|
+
const models = await viewModels(view, entry);
|
|
74
|
+
return models === undefined ? answer : { ...answer, models };
|
|
84
75
|
}
|
|
85
76
|
return {
|
|
86
77
|
async authorize() {
|
|
87
78
|
return {};
|
|
88
79
|
},
|
|
89
|
-
async model(_authorization, request) {
|
|
90
|
-
return models.answer(request);
|
|
91
|
-
},
|
|
92
80
|
async discover() {
|
|
93
81
|
const answer = await transport.read(SITE_DOOR_DISCOVER);
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
return
|
|
82
|
+
const failed = discoveryFailure(answer.status, answer.body);
|
|
83
|
+
if (failed !== null)
|
|
84
|
+
return failed;
|
|
97
85
|
const document = parseSiteDiscovery(answer.body);
|
|
98
86
|
if (document === null)
|
|
99
87
|
return UNCERTAIN;
|
|
@@ -102,30 +90,7 @@ export function createSiteAdapter(transport) {
|
|
|
102
90
|
for (const entry of entries)
|
|
103
91
|
tracked.set(entry.locator, entry);
|
|
104
92
|
notifications.track(entries);
|
|
105
|
-
|
|
106
|
-
for (const authority of [...acquired.keys()]) {
|
|
107
|
-
if (!published.has(authority))
|
|
108
|
-
acquired.delete(authority);
|
|
109
|
-
}
|
|
110
|
-
const fresh = new Map();
|
|
111
|
-
const current = new Map();
|
|
112
|
-
for (const entry of entries) {
|
|
113
|
-
const kept = acquired.get(entry.authority);
|
|
114
|
-
if (kept !== undefined && kept.roomVersion === roomVersion(entry)) {
|
|
115
|
-
current.set(entry.authority, kept.model);
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
const held = await caughtUp(entry);
|
|
119
|
-
fresh.set(entry.authority, held);
|
|
120
|
-
current.set(entry.authority, await acquire(entry, held));
|
|
121
|
-
}
|
|
122
|
-
caught = fresh;
|
|
123
|
-
const rooms = entries.map((entry) => {
|
|
124
|
-
const shelved = models.retain(modelKey(entry.locator, 'collection'), current.get(entry.authority));
|
|
125
|
-
return siteRoom(entry, shelved?.identity ?? null);
|
|
126
|
-
});
|
|
127
|
-
models.keep(entries.map((entry) => entry.locator));
|
|
128
|
-
return { ...mapDiscovery(document, rooms, siteCapabilities()), slots: siteSlots(document) };
|
|
93
|
+
return mapDiscovery(document, entries.map(siteRoom), siteCapabilities());
|
|
129
94
|
},
|
|
130
95
|
async bootstrap(_authorization, request) {
|
|
131
96
|
const entry = tracked.get(request.locator);
|
|
@@ -133,10 +98,12 @@ export function createSiteAdapter(transport) {
|
|
|
133
98
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
134
99
|
if (request.pageToken !== undefined)
|
|
135
100
|
return UNCERTAIN;
|
|
136
|
-
const held =
|
|
101
|
+
const held = await caughtUp(entry);
|
|
137
102
|
if ('failure' in held)
|
|
138
103
|
return held.failure;
|
|
139
|
-
|
|
104
|
+
notifications.reach(entry.authority, held.scope);
|
|
105
|
+
const models = await scopeModels(held.scope, entry);
|
|
106
|
+
return { ...bootstrapOf(held.scope), ...(models === undefined ? {} : { models }) };
|
|
140
107
|
},
|
|
141
108
|
async refresh(_authorization, request) {
|
|
142
109
|
const entry = tracked.get(request.locator);
|
|
@@ -144,20 +111,7 @@ export function createSiteAdapter(transport) {
|
|
|
144
111
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
145
112
|
if (request.pageToken !== undefined)
|
|
146
113
|
return UNCERTAIN;
|
|
147
|
-
|
|
148
|
-
if (result.kind === 'beyond-horizon')
|
|
149
|
-
caught.delete(entry.authority);
|
|
150
|
-
const answered = result.kind === 'net-advancement'
|
|
151
|
-
? result.roomVersion
|
|
152
|
-
: result.kind === 'still-current'
|
|
153
|
-
? request.fromRoomVersion
|
|
154
|
-
: null;
|
|
155
|
-
if (request.minPosition !== undefined &&
|
|
156
|
-
answered !== null &&
|
|
157
|
-
!reachedVersion(answered, request.minPosition, entry.logEpoch)) {
|
|
158
|
-
return { kind: 'retryable-refusal', code: 'replica_behind', fields: {} };
|
|
159
|
-
}
|
|
160
|
-
return result;
|
|
114
|
+
return refreshed(entry, request.fromRoomVersion);
|
|
161
115
|
},
|
|
162
116
|
async mutate() {
|
|
163
117
|
return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {} };
|
|
@@ -168,6 +122,9 @@ export function createSiteAdapter(transport) {
|
|
|
168
122
|
reached(locator, version, target) {
|
|
169
123
|
return reachedVersion(version, target, tracked.get(locator)?.logEpoch);
|
|
170
124
|
},
|
|
125
|
+
follows(_locator, version, next) {
|
|
126
|
+
return followsVersion(version, next);
|
|
127
|
+
},
|
|
171
128
|
async action(_authorization, request) {
|
|
172
129
|
if (request.name !== 'submit') {
|
|
173
130
|
return { kind: 'rejected', code: 'action-unimplemented', fields: { name: request.name } };
|
|
@@ -176,7 +133,20 @@ export function createSiteAdapter(transport) {
|
|
|
176
133
|
return UNCERTAIN;
|
|
177
134
|
return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), 'submit');
|
|
178
135
|
},
|
|
179
|
-
|
|
136
|
+
roomStream: {
|
|
137
|
+
hold(rooms) {
|
|
138
|
+
notifications.send(rooms.flatMap((room) => {
|
|
139
|
+
const entry = tracked.get(room.locator);
|
|
140
|
+
const at = logPosition(room.roomVersion);
|
|
141
|
+
if (entry === undefined || at === null)
|
|
142
|
+
return [];
|
|
143
|
+
notifications.reach(entry.authority, at);
|
|
144
|
+
return [presented(entry.authority, at)];
|
|
145
|
+
}));
|
|
146
|
+
},
|
|
147
|
+
reopen: notifications.reopen,
|
|
148
|
+
observe: notifications.observe,
|
|
149
|
+
},
|
|
180
150
|
serviceMode: notifications.serviceMode,
|
|
181
151
|
};
|
|
182
152
|
}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import type { ConversationStream, RefreshPage,
|
|
1
|
+
import type { ConversationStream, RefreshPage, RoomStreamEvent, ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import type { HouseDoor, HouseMode, HouseStreamEntry } from './transport.js';
|
|
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;
|
|
5
6
|
export type StreamedAdvancement = {
|
|
6
7
|
page: RefreshPage;
|
|
7
8
|
entries: readonly HouseStreamEntry[];
|
|
9
|
+
schemas: ReadonlyMap<string, HouseStreamEntry>;
|
|
8
10
|
};
|
|
9
|
-
export type HouseNotifications =
|
|
11
|
+
export type HouseNotifications = {
|
|
12
|
+
runtime: string;
|
|
13
|
+
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
14
|
+
send(rooms: readonly HouseHeldRoom[]): void;
|
|
15
|
+
reopen(): void;
|
|
10
16
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
11
|
-
|
|
17
|
+
reach(authority: string, at: LogPosition): void;
|
|
18
|
+
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): StreamedAdvancement | null;
|
|
12
19
|
conversations: ConversationStream;
|
|
13
20
|
serviceMode: ServiceModeSignal;
|
|
14
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,EAEV,kBAAkB,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAElB,WAAW,EACX,eAAe,EAEf,iBAAiB,EAElB,MAAM,wBAAwB,CAAC;AAEhC,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;AAgB7D,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,SAAS,gBAAgB,EAAE,CAAC;IACrC,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,IAA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