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