@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c04b3fdfb64c6
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 +297 -71
- package/README.md +32 -0
- package/dist/actions.d.ts +66 -13
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +279 -354
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +480 -218
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +24 -34
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +157 -230
- package/dist/gather.d.ts +4 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +45 -0
- 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 -3
- package/dist/map.d.ts +2 -2
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +6 -7
- package/dist/model.d.ts +7 -18
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +60 -57
- package/dist/read.d.ts +62 -29
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +290 -203
- 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 -7
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +47 -68
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +242 -155
- package/dist/stream.d.ts +18 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +532 -212
- package/dist/transport.d.ts +119 -35
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +4 -3
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +32 -18
- package/dist/write.d.ts +7 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +201 -207
- package/package.json +4 -13
- package/dist/actions.js.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/digest.js.map +0 -1
- package/dist/discovery.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/map.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/read.js.map +0 -1
- package/dist/refusal.js.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/stream.js.map +0 -1
- package/dist/transport.js.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/write.js.map +0 -1
package/dist/refusal.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
|
|
2
|
-
export
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
2
|
+
export declare function doorRefusal(body: unknown): ProviderRefusal | null;
|
|
3
|
+
export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
|
|
4
|
+
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
|
|
5
|
+
export declare function classifyRead(status: number, body: unknown, locator: string): AdapterFailure | {
|
|
6
6
|
kind: 'beyond-horizon';
|
|
7
7
|
} | null;
|
|
8
|
-
export declare function discoveryFailure(
|
|
9
|
-
kind: 'beyond-horizon';
|
|
10
|
-
}): DiscoverResult;
|
|
8
|
+
export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
|
|
11
9
|
//# 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,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAOjE;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,eAAe,GACvB,aAAa,CAEf;AAqBD,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,CAQrF"}
|
package/dist/refusal.js
CHANGED
|
@@ -1,78 +1,57 @@
|
|
|
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
|
-
'service_mode_write_halted',
|
|
12
|
-
'transaction_budget_exceeded'
|
|
13
|
-
]);
|
|
14
1
|
export function doorRefusal(body) {
|
|
15
|
-
if (typeof body !== 'object' || body === null)
|
|
16
|
-
|
|
2
|
+
if (typeof body !== 'object' || body === null)
|
|
3
|
+
return null;
|
|
4
|
+
if (!('error' in body) || typeof body.error !== 'object' || body.error === null)
|
|
5
|
+
return null;
|
|
17
6
|
const error = body.error;
|
|
18
|
-
if (typeof error.code !== 'string')
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
fields
|
|
23
|
-
};
|
|
7
|
+
if (typeof error.code !== 'string')
|
|
8
|
+
return null;
|
|
9
|
+
const { code, retryable, ...fields } = error;
|
|
10
|
+
return { code, fields, retryable: retryable === true };
|
|
24
11
|
}
|
|
25
12
|
export function scopedRefusal(locator, scope, refusal) {
|
|
26
|
-
return {
|
|
27
|
-
kind: 'scoped-refusal',
|
|
28
|
-
locator,
|
|
29
|
-
scope,
|
|
30
|
-
code: refusal.code,
|
|
31
|
-
fields: refusal.fields
|
|
32
|
-
};
|
|
13
|
+
return { kind: 'scoped-refusal', locator, scope, ...refusal };
|
|
33
14
|
}
|
|
34
|
-
|
|
35
|
-
if (status === 0)
|
|
36
|
-
kind: 'transport-uncertainty'
|
|
37
|
-
};
|
|
15
|
+
function doorFailure(status, body) {
|
|
16
|
+
if (status === 0)
|
|
17
|
+
return { kind: 'transport-uncertainty' };
|
|
38
18
|
const refusal = doorRefusal(body);
|
|
39
|
-
if (status === 401)
|
|
40
|
-
kind: 'revoked-authorization'
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
kind: 'transport-uncertainty'
|
|
44
|
-
};
|
|
45
|
-
if (refusal !== null && refusal.code === 'position_expired') return {
|
|
46
|
-
kind: 'beyond-horizon'
|
|
47
|
-
};
|
|
48
|
-
if (status === 404 || refusal?.code === 'room_not_found') {
|
|
49
|
-
return {
|
|
50
|
-
kind: 'room-not-readable',
|
|
51
|
-
locator
|
|
52
|
-
};
|
|
19
|
+
if (status === 401)
|
|
20
|
+
return { kind: 'revoked-authorization' };
|
|
21
|
+
if (refusal?.retryable === true || refusal?.code === 'update_required') {
|
|
22
|
+
return { kind: 'transport-uncertainty' };
|
|
53
23
|
}
|
|
54
|
-
if (status
|
|
55
|
-
kind: '
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (refusal === null)
|
|
59
|
-
kind: 'transport-uncertainty'
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
|
|
24
|
+
if (status === 404 || refusal?.code === 'room_not_found')
|
|
25
|
+
return { kind: 'room-not-readable' };
|
|
26
|
+
if (status < 400)
|
|
27
|
+
return null;
|
|
28
|
+
if (refusal === null)
|
|
29
|
+
return { kind: 'transport-uncertainty' };
|
|
30
|
+
return { kind: 'refused', scope: status === 403 ? 'operation' : 'undisclosed', refusal };
|
|
31
|
+
}
|
|
32
|
+
export function classifyDoor(status, body, locator) {
|
|
33
|
+
const failure = doorFailure(status, body);
|
|
34
|
+
if (failure === null)
|
|
35
|
+
return null;
|
|
36
|
+
if (failure.kind === 'room-not-readable')
|
|
37
|
+
return { kind: 'room-not-readable', locator };
|
|
38
|
+
if (failure.kind === 'refused')
|
|
39
|
+
return scopedRefusal(locator, failure.scope, failure.refusal);
|
|
40
|
+
return failure;
|
|
41
|
+
}
|
|
42
|
+
export function classifyRead(status, body, locator) {
|
|
43
|
+
if (doorRefusal(body)?.code === 'expired')
|
|
44
|
+
return { kind: 'beyond-horizon' };
|
|
45
|
+
return classifyDoor(status, body, locator);
|
|
63
46
|
}
|
|
64
|
-
export function discoveryFailure(
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
47
|
+
export function discoveryFailure(status, body) {
|
|
48
|
+
const failure = doorFailure(status, body);
|
|
49
|
+
if (failure === null)
|
|
50
|
+
return null;
|
|
51
|
+
if (failure.kind === 'revoked-authorization')
|
|
52
|
+
return failure;
|
|
53
|
+
if (failure.kind === 'refused') {
|
|
54
|
+
return { kind: 'contract-unavailable', ...failure.refusal };
|
|
72
55
|
}
|
|
73
|
-
return {
|
|
74
|
-
kind: 'transport-uncertainty'
|
|
75
|
-
};
|
|
56
|
+
return { kind: 'transport-uncertainty' };
|
|
76
57
|
}
|
|
77
|
-
|
|
78
|
-
//# sourceMappingURL=refusal.js.map
|
package/dist/site.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Adapter } from '@agentshouse/mdruntime';
|
|
2
2
|
import { type HouseSiteTransport } from './transport.js';
|
|
3
|
-
export declare function createSiteAdapter(transport: HouseSiteTransport): Adapter;
|
|
3
|
+
export declare function createSiteAdapter(transport: HouseSiteTransport, snapshot?: boolean): Adapter;
|
|
4
4
|
//# sourceMappingURL=site.d.ts.map
|
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,EAUR,MAAM,wBAAwB,CAAC;AA2BhC,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAyCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAyR1F"}
|
package/dist/site.js
CHANGED
|
@@ -1,198 +1,285 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { actionOutcome, SITE_SUBMIT } from './actions.js';
|
|
2
|
+
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
3
|
+
import { partModels, streamedModels, viewModels } from './model.js';
|
|
4
|
+
import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom, siteBootstrapNext, siteBootstrapOffset, viewOf, wholeView, } from './read.js';
|
|
5
|
+
import { sha256Hex } from './digest.js';
|
|
6
|
+
import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
|
|
5
7
|
import { houseNotifications } from './stream.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, SITE_FILE_RECORD, SITE_FILES, } from './transport.js';
|
|
9
|
+
import { houseReferrer } from './referrer.js';
|
|
10
|
+
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
11
|
+
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
12
|
+
function unfound() {
|
|
13
|
+
return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
|
|
14
|
+
}
|
|
15
|
+
function siteRoom(tracked) {
|
|
13
16
|
return {
|
|
14
|
-
name: tracked.
|
|
17
|
+
name: tracked.handle,
|
|
15
18
|
locator: tracked.locator,
|
|
16
|
-
|
|
19
|
+
handle: tracked.handle,
|
|
17
20
|
roomVersion: roomVersion(tracked),
|
|
18
|
-
operations: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
],
|
|
22
|
-
sync: [
|
|
23
|
-
...read
|
|
24
|
-
],
|
|
25
|
-
write: [],
|
|
26
|
-
delete: []
|
|
27
|
-
},
|
|
28
|
-
replica: {
|
|
29
|
-
selection: tracked.locator,
|
|
30
|
-
admission: 'admitted'
|
|
31
|
-
},
|
|
32
|
-
attachedModel,
|
|
33
|
-
providerOwnedPaths: []
|
|
21
|
+
operations: { read: [''], sync: [''], write: [], delete: [] },
|
|
22
|
+
replica: { selection: tracked.locator, admission: 'admitted' },
|
|
23
|
+
providerOwnedPaths: [],
|
|
34
24
|
};
|
|
35
25
|
}
|
|
36
26
|
function settled(refused) {
|
|
37
27
|
return refused.kind === 'beyond-horizon' ? UNCERTAIN : refused;
|
|
38
28
|
}
|
|
39
|
-
export function createSiteAdapter(transport) {
|
|
29
|
+
export function createSiteAdapter(transport, snapshot = false) {
|
|
40
30
|
const notifications = houseNotifications(transport, 'site');
|
|
41
31
|
const tracked = new Map();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
function published(referrer) {
|
|
33
|
+
const named = houseReferrer(referrer, tracked);
|
|
34
|
+
return named === null || !tracked.has(named.locator) ? null : named;
|
|
35
|
+
}
|
|
36
|
+
function fileRoute(request) {
|
|
37
|
+
const named = published(request.kind === 'path' ? { room: request.locator, path: request.path } : request.referrer);
|
|
38
|
+
if (named === null) {
|
|
39
|
+
return { kind: 'rejected', code: 'referrer_unknown', fields: {}, retryable: false };
|
|
40
|
+
}
|
|
41
|
+
if (request.fileRef === undefined)
|
|
42
|
+
return unfound();
|
|
43
|
+
const { room_ref, path, record } = named.referrer;
|
|
44
|
+
return `${SITE_FILES}${room_ref}/${encodeURIComponent(request.fileRef)}/${path === undefined
|
|
45
|
+
? `${SITE_FILE_RECORD}/${encodeURIComponent(record)}`
|
|
46
|
+
: encodeURIComponent(path)}`;
|
|
47
|
+
}
|
|
48
|
+
async function enumerated(entry, from, page) {
|
|
46
49
|
const answer = await transport.door(SITE_DOOR_ENUMERATE, {
|
|
47
50
|
positions: [
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
page === undefined
|
|
52
|
+
? presented(entry.authority, from)
|
|
53
|
+
: {
|
|
54
|
+
...presented(entry.authority, { position: page.after, logEpoch: from.logEpoch }),
|
|
55
|
+
page: { through: page.through, read: page.read },
|
|
56
|
+
},
|
|
57
|
+
],
|
|
50
58
|
});
|
|
51
|
-
const classified =
|
|
52
|
-
if (classified !== null)
|
|
53
|
-
|
|
59
|
+
const classified = classifyRead(answer.status, answer.body, entry.locator);
|
|
60
|
+
if (classified !== null)
|
|
61
|
+
return classified;
|
|
62
|
+
const found = parseEnumeration(answer.body, 'site');
|
|
63
|
+
if (found === null)
|
|
64
|
+
return UNCERTAIN;
|
|
65
|
+
return viewOf(found, entry) ?? { kind: 'room-not-readable', locator: entry.locator };
|
|
66
|
+
}
|
|
67
|
+
async function enumeration(entry, from) {
|
|
68
|
+
const first = await enumerated(entry, from);
|
|
69
|
+
return 'kind' in first ? first : wholeView(first, (page) => enumerated(entry, from, page));
|
|
54
70
|
}
|
|
55
|
-
async function
|
|
56
|
-
const
|
|
71
|
+
async function bootstrapPart(entry, after, offset) {
|
|
72
|
+
const query = [
|
|
73
|
+
...(after === null ? [] : [`after=${encodeURIComponent(after)}`]),
|
|
74
|
+
...(offset === null ? [] : [`offset=${offset}`]),
|
|
75
|
+
];
|
|
76
|
+
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${query.length === 0 ? '' : `?${query.join('&')}`}`);
|
|
57
77
|
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
58
|
-
if (classified !== null)
|
|
59
|
-
failure:
|
|
60
|
-
};
|
|
78
|
+
if (classified !== null)
|
|
79
|
+
return { failure: classified };
|
|
61
80
|
const scope = parseSiteBootstrap(answer.body);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
return scope === null ? { failure: UNCERTAIN } : { body: answer.body, scope };
|
|
82
|
+
}
|
|
83
|
+
async function assembled(entry, scope, path, offset) {
|
|
84
|
+
const opened = scope.contents.at(-1);
|
|
85
|
+
if (opened === undefined || opened.path !== path || opened.content.length !== offset) {
|
|
86
|
+
return UNCERTAIN;
|
|
87
|
+
}
|
|
88
|
+
let text = opened.content;
|
|
89
|
+
for (;;) {
|
|
90
|
+
const part = await bootstrapPart(entry, path, text.length);
|
|
91
|
+
if ('failure' in part)
|
|
92
|
+
return part.failure;
|
|
93
|
+
const [piece] = part.scope.contents;
|
|
94
|
+
if (piece === undefined ||
|
|
95
|
+
part.scope.contents.length !== 1 ||
|
|
96
|
+
piece.path !== path ||
|
|
97
|
+
piece.content.length === 0) {
|
|
98
|
+
return UNCERTAIN;
|
|
77
99
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
100
|
+
text += piece.content;
|
|
101
|
+
const more = siteBootstrapOffset(part.body);
|
|
102
|
+
if (more === null)
|
|
103
|
+
break;
|
|
104
|
+
if (more !== text.length)
|
|
105
|
+
return UNCERTAIN;
|
|
106
|
+
}
|
|
107
|
+
const file = scope.files.find((held) => held.path === path);
|
|
108
|
+
if (file === undefined || (await sha256Hex(text)) !== file.version)
|
|
109
|
+
return UNCERTAIN;
|
|
110
|
+
return { ...scope, contents: [...scope.contents.slice(0, -1), { path, content: text }] };
|
|
111
|
+
}
|
|
112
|
+
async function caughtUp(entry, after) {
|
|
113
|
+
const part = await bootstrapPart(entry, after, null);
|
|
114
|
+
if ('failure' in part)
|
|
115
|
+
return part;
|
|
116
|
+
const next = siteBootstrapNext(part.body);
|
|
117
|
+
const offset = siteBootstrapOffset(part.body);
|
|
118
|
+
if (offset !== null) {
|
|
119
|
+
if (next === null)
|
|
120
|
+
return { failure: UNCERTAIN };
|
|
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
|
+
}
|
|
128
|
+
const view = await enumeration(entry, scope);
|
|
129
|
+
if ('kind' in view)
|
|
130
|
+
return { failure: settled(view) };
|
|
131
|
+
return { scope: advancedScope(scope, view), next: null };
|
|
82
132
|
}
|
|
83
133
|
async function refreshed(entry, fromRoomVersion) {
|
|
84
134
|
const from = logPosition(fromRoomVersion);
|
|
85
|
-
if (from === null)
|
|
86
|
-
kind: 'beyond-horizon'
|
|
87
|
-
};
|
|
135
|
+
if (from === null)
|
|
136
|
+
return { kind: 'beyond-horizon' };
|
|
88
137
|
const streamed = notifications.advance(entry, from);
|
|
89
|
-
if (streamed !== null)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
model
|
|
103
|
-
});
|
|
104
|
-
return model;
|
|
138
|
+
if (streamed !== null) {
|
|
139
|
+
const models = await streamedModels(streamed.schemas, entry, 'site');
|
|
140
|
+
return models === undefined ? streamed.page : { ...streamed.page, models };
|
|
141
|
+
}
|
|
142
|
+
const view = await enumeration(entry, from);
|
|
143
|
+
if ('kind' in view)
|
|
144
|
+
return view;
|
|
145
|
+
notifications.reach(entry.authority, view);
|
|
146
|
+
const answer = refreshFrom(view, fromRoomVersion);
|
|
147
|
+
if (answer.kind !== 'net-advancement')
|
|
148
|
+
return answer;
|
|
149
|
+
const models = await viewModels(view, entry);
|
|
150
|
+
return models === undefined ? answer : { ...answer, models };
|
|
105
151
|
}
|
|
106
152
|
return {
|
|
107
|
-
|
|
153
|
+
localSaves: true,
|
|
154
|
+
exhaustiveDiscovery: true,
|
|
155
|
+
async authorize() {
|
|
108
156
|
return {};
|
|
109
157
|
},
|
|
110
|
-
async
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);
|
|
116
|
-
if (classified !== null) return discoveryFailure(classified);
|
|
158
|
+
async discover() {
|
|
159
|
+
const answer = await transport.read(SITE_DOOR_DISCOVER);
|
|
160
|
+
const failed = discoveryFailure(answer.status, answer.body);
|
|
161
|
+
if (failed !== null)
|
|
162
|
+
return failed;
|
|
117
163
|
const document = parseSiteDiscovery(answer.body);
|
|
118
|
-
if (document === null)
|
|
164
|
+
if (document === null)
|
|
165
|
+
return UNCERTAIN;
|
|
119
166
|
const entries = siteTracked(document);
|
|
120
167
|
tracked.clear();
|
|
121
|
-
for (const entry of entries)
|
|
168
|
+
for (const entry of entries)
|
|
169
|
+
tracked.set(entry.locator, entry);
|
|
122
170
|
notifications.track(entries);
|
|
123
|
-
|
|
124
|
-
for (const authority of [
|
|
125
|
-
...acquired.keys()
|
|
126
|
-
]){
|
|
127
|
-
if (!published.has(authority)) acquired.delete(authority);
|
|
128
|
-
}
|
|
129
|
-
const fresh = new Map();
|
|
130
|
-
const current = new Map();
|
|
131
|
-
for (const entry of entries){
|
|
132
|
-
if (current.has(entry.authority)) continue;
|
|
133
|
-
const kept = acquired.get(entry.authority);
|
|
134
|
-
if (kept !== undefined && kept.roomVersion === roomVersion(entry)) {
|
|
135
|
-
current.set(entry.authority, kept.model);
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
const held = await caughtUp(entry);
|
|
139
|
-
fresh.set(entry.authority, held);
|
|
140
|
-
current.set(entry.authority, await acquire(entry, held));
|
|
141
|
-
}
|
|
142
|
-
caught = fresh;
|
|
143
|
-
const rooms = entries.map((entry)=>{
|
|
144
|
-
const shelved = models.retain(modelKey(entry.locator, 'collection'), current.get(entry.authority));
|
|
145
|
-
return siteRoom(entry, shelved?.identity ?? null);
|
|
146
|
-
});
|
|
147
|
-
models.keep(entries.map((entry)=>entry.locator));
|
|
148
|
-
return mapDiscovery(document, rooms, siteCapabilities());
|
|
171
|
+
return mapDiscovery(document, entries.map(siteRoom), siteCapabilities());
|
|
149
172
|
},
|
|
150
|
-
async bootstrap
|
|
173
|
+
async bootstrap(_authorization, request) {
|
|
151
174
|
const entry = tracked.get(request.locator);
|
|
152
|
-
if (entry === undefined)
|
|
153
|
-
kind: 'room-not-readable',
|
|
154
|
-
|
|
175
|
+
if (entry === undefined)
|
|
176
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
177
|
+
const continued = request.pageToken === undefined
|
|
178
|
+
? null
|
|
179
|
+
: JSON.parse(request.pageToken);
|
|
180
|
+
const held = await caughtUp(entry, continued?.after ?? null);
|
|
181
|
+
if ('failure' in held)
|
|
182
|
+
return held.failure;
|
|
183
|
+
notifications.reach(entry.authority, held.scope);
|
|
184
|
+
const seen = [
|
|
185
|
+
...(continued?.seen ?? []),
|
|
186
|
+
...entry.schemas.filter((schema) => held.scope.files.some((file) => file.path === schema)),
|
|
187
|
+
];
|
|
188
|
+
const models = await partModels(held.scope, entry, new Set(seen), held.next === null);
|
|
189
|
+
const continuation = held.next === null ? null : { after: held.next, seen };
|
|
190
|
+
return {
|
|
191
|
+
...bootstrapOf(held.scope),
|
|
192
|
+
...(models === undefined ? {} : { models }),
|
|
193
|
+
...(continuation === null ? {} : { pageToken: JSON.stringify(continuation) }),
|
|
155
194
|
};
|
|
156
|
-
if (request.pageToken !== undefined) return UNCERTAIN;
|
|
157
|
-
const held = caught.get(entry.authority) ?? await caughtUp(entry);
|
|
158
|
-
if ('failure' in held) return held.failure;
|
|
159
|
-
return bootstrapOf(held.scope, entry);
|
|
160
195
|
},
|
|
161
|
-
async refresh
|
|
196
|
+
async refresh(_authorization, request) {
|
|
162
197
|
const entry = tracked.get(request.locator);
|
|
163
|
-
if (entry === undefined)
|
|
164
|
-
kind: 'room-not-readable',
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
198
|
+
if (entry === undefined)
|
|
199
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
200
|
+
if (request.pageToken !== undefined)
|
|
201
|
+
return UNCERTAIN;
|
|
202
|
+
if (snapshot) {
|
|
203
|
+
return request.fromRoomVersion === roomVersion(entry)
|
|
204
|
+
? { kind: 'still-current' }
|
|
205
|
+
: { kind: 'beyond-horizon' };
|
|
206
|
+
}
|
|
207
|
+
return refreshed(entry, request.fromRoomVersion);
|
|
171
208
|
},
|
|
172
|
-
async mutate
|
|
173
|
-
return {
|
|
174
|
-
kind: 'rejected',
|
|
175
|
-
affected: {},
|
|
176
|
-
code: 'write-grant',
|
|
177
|
-
fields: {}
|
|
178
|
-
};
|
|
209
|
+
async mutate() {
|
|
210
|
+
return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {}, retryable: false };
|
|
179
211
|
},
|
|
180
|
-
async history
|
|
181
|
-
return {
|
|
182
|
-
kind: 'no-history'
|
|
183
|
-
};
|
|
212
|
+
async history() {
|
|
213
|
+
return { kind: 'no-history' };
|
|
184
214
|
},
|
|
185
|
-
async
|
|
215
|
+
async binary(_authorization, request) {
|
|
216
|
+
const route = fileRoute(request);
|
|
217
|
+
if (typeof route !== 'string')
|
|
218
|
+
return route;
|
|
219
|
+
const read = await transport.download(route);
|
|
220
|
+
if (read.status === 404)
|
|
221
|
+
return unfound();
|
|
222
|
+
return read.status === 200 && read.blob !== null
|
|
223
|
+
? { kind: 'binary', blob: read.blob }
|
|
224
|
+
: UNCERTAIN;
|
|
225
|
+
},
|
|
226
|
+
async link(_authorization, request) {
|
|
227
|
+
const route = fileRoute(request);
|
|
228
|
+
if (typeof route !== 'string')
|
|
229
|
+
return route;
|
|
186
230
|
return {
|
|
187
|
-
kind: '
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
name: request.name
|
|
191
|
-
}
|
|
231
|
+
kind: 'link',
|
|
232
|
+
url: route,
|
|
233
|
+
name: request.path.slice(request.path.lastIndexOf('/') + 1),
|
|
192
234
|
};
|
|
193
235
|
},
|
|
194
|
-
|
|
236
|
+
referrerScope(referrer) {
|
|
237
|
+
const named = published(referrer);
|
|
238
|
+
if (named === null)
|
|
239
|
+
return null;
|
|
240
|
+
const { path } = named.referrer;
|
|
241
|
+
return { kind: 'room', locator: named.locator, ...(path === undefined ? {} : { path }) };
|
|
242
|
+
},
|
|
243
|
+
reached(locator, version, target) {
|
|
244
|
+
return reachedVersion(version, target, tracked.get(locator)?.logEpoch);
|
|
245
|
+
},
|
|
246
|
+
follows(_locator, version, next) {
|
|
247
|
+
return followsVersion(version, next);
|
|
248
|
+
},
|
|
249
|
+
async action(_authorization, request) {
|
|
250
|
+
if (request.name !== SITE_SUBMIT) {
|
|
251
|
+
return {
|
|
252
|
+
kind: 'rejected',
|
|
253
|
+
code: 'action-unimplemented',
|
|
254
|
+
fields: { name: request.name },
|
|
255
|
+
retryable: false,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (!transport.online())
|
|
259
|
+
return UNCERTAIN;
|
|
260
|
+
return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), SITE_SUBMIT);
|
|
261
|
+
},
|
|
262
|
+
roomStream: snapshot
|
|
263
|
+
? undefined
|
|
264
|
+
: {
|
|
265
|
+
hold(rooms) {
|
|
266
|
+
notifications.send(rooms.flatMap((room) => {
|
|
267
|
+
const entry = tracked.get(room.locator);
|
|
268
|
+
const at = logPosition(room.roomVersion);
|
|
269
|
+
if (entry === undefined || at === null)
|
|
270
|
+
return [];
|
|
271
|
+
notifications.reach(entry.authority, at);
|
|
272
|
+
return [presented(entry.authority, at)];
|
|
273
|
+
}), null);
|
|
274
|
+
},
|
|
275
|
+
reopen: notifications.reopen,
|
|
276
|
+
observe: notifications.observe,
|
|
277
|
+
published(locator, roomVersion) {
|
|
278
|
+
const at = logPosition(roomVersion);
|
|
279
|
+
if (at !== null)
|
|
280
|
+
notifications.published(locator, at);
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
serviceMode: notifications.serviceMode,
|
|
195
284
|
};
|
|
196
285
|
}
|
|
197
|
-
|
|
198
|
-
//# sourceMappingURL=site.js.map
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import type { RefreshPage,
|
|
1
|
+
import type { ConversationStream, RefreshPage, RoomStreamEvent, ServiceModeSignal, StreamReceipts } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import {
|
|
4
|
-
import type { HouseMode } from './transport.js';
|
|
3
|
+
import type { HouseDemand, HouseDoor, HouseHeldRoom, HouseMode, HouseStreamEntry } from './transport.js';
|
|
5
4
|
import { type LogPosition } from './version.js';
|
|
6
|
-
export type
|
|
5
|
+
export type HeldRevision = (path: string, revision: string) => boolean;
|
|
6
|
+
export type StreamedAdvancement = {
|
|
7
|
+
page: RefreshPage;
|
|
8
|
+
entries: readonly HouseStreamEntry[];
|
|
9
|
+
schemas: ReadonlyMap<string, HouseStreamEntry>;
|
|
10
|
+
};
|
|
11
|
+
export type HouseNotifications = {
|
|
12
|
+
runtime: string;
|
|
13
|
+
observe(notify: (event: RoomStreamEvent) => void, receipts: StreamReceipts): () => void;
|
|
14
|
+
send(rooms: readonly HouseHeldRoom[], demand: HouseDemand | null): void;
|
|
15
|
+
published(locator: string, at: LogPosition): void;
|
|
16
|
+
reopen(): void;
|
|
7
17
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
reach(authority: string, at: LogPosition): void;
|
|
19
|
+
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): StreamedAdvancement | null;
|
|
20
|
+
conversations: ConversationStream;
|
|
21
|
+
serviceMode: ServiceModeSignal;
|
|
10
22
|
};
|
|
11
23
|
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
|
|
12
24
|
//# sourceMappingURL=stream.d.ts.map
|
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,KAAK,EAGV,kBAAkB,EAElB,WAAW,EACX,eAAe,EAEf,iBAAiB,EACjB,cAAc,EAEf,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EACV,WAAW,EACX,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,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,EAAE,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAAC;IACxF,IAAI,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CAAC;IACxE,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,mBAAmB,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAkFF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CAwhB5F"}
|