@agentshouse/mdruntime-adapter 0.1.0-cc63dd043d0e2 → 0.1.0-cca5d676bc88e
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 +24 -8
- package/README.md +3 -3
- package/dist/actions.d.ts +2 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +4 -4
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +67 -101
- package/dist/discovery.d.ts +3 -9
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +9 -27
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/links.d.ts +9 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +40 -2
- package/dist/model.d.ts +7 -18
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +48 -41
- package/dist/read.d.ts +1 -1
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +5 -8
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +38 -72
- package/dist/stream.d.ts +8 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +89 -37
- package/dist/transport.d.ts +31 -1
- package/dist/transport.d.ts.map +1 -1
- 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 +9 -2
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +5 -0
- package/package.json +3 -3
package/dist/links.js
CHANGED
|
@@ -8,7 +8,7 @@ function linkedBy(text) {
|
|
|
8
8
|
return references.size === 0 ? NONE : references;
|
|
9
9
|
}
|
|
10
10
|
function handedOf(attachments) {
|
|
11
|
-
return new
|
|
11
|
+
return new Map((attachments ?? []).map((attachment) => [attachment.reference, attachment]));
|
|
12
12
|
}
|
|
13
13
|
export function scopeLinks(scope) {
|
|
14
14
|
return {
|
|
@@ -24,6 +24,44 @@ function revised(revisions, path, revision) {
|
|
|
24
24
|
else
|
|
25
25
|
revisions.set(path, revision);
|
|
26
26
|
}
|
|
27
|
+
export function heldLinks(held) {
|
|
28
|
+
return {
|
|
29
|
+
roomVersion: held.roomVersion,
|
|
30
|
+
handed: handedOf(held.attachments),
|
|
31
|
+
paths: new Map(Object.entries(held.documents).map(([path, text]) => [path, linkedBy(text)])),
|
|
32
|
+
revisions: new Map(Object.entries(held.revisions)),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function acceptedLinks(held, accepted, roomVersion, originals) {
|
|
36
|
+
const paths = new Map(held.paths);
|
|
37
|
+
const revisions = new Map(held.revisions);
|
|
38
|
+
const handed = new Map(held.handed);
|
|
39
|
+
const answered = handedOf(originals);
|
|
40
|
+
for (const [path, text] of Object.entries(accepted.documents)) {
|
|
41
|
+
const linked = linkedBy(text);
|
|
42
|
+
for (const reference of linked) {
|
|
43
|
+
const original = answered.get(reference);
|
|
44
|
+
if (!handed.has(reference) && original !== undefined)
|
|
45
|
+
handed.set(reference, original);
|
|
46
|
+
}
|
|
47
|
+
paths.set(path, linked);
|
|
48
|
+
}
|
|
49
|
+
for (const [path, revision] of Object.entries(accepted.revisions))
|
|
50
|
+
revisions.set(path, revision);
|
|
51
|
+
for (const path of accepted.removals) {
|
|
52
|
+
paths.delete(path);
|
|
53
|
+
revisions.delete(path);
|
|
54
|
+
}
|
|
55
|
+
const linked = new Set([...paths.values()].flatMap((references) => [...references]));
|
|
56
|
+
for (const reference of held.handed.keys()) {
|
|
57
|
+
const before = [...held.paths.values()].some((references) => references.has(reference));
|
|
58
|
+
if (before && !linked.has(reference))
|
|
59
|
+
handed.delete(reference);
|
|
60
|
+
}
|
|
61
|
+
const links = { roomVersion, handed, paths, revisions };
|
|
62
|
+
const changed = handed.size !== held.handed.size || [...handed.keys()].some((key) => !held.handed.has(key));
|
|
63
|
+
return changed ? { links, attachments: [...handed.values()] } : { links };
|
|
64
|
+
}
|
|
27
65
|
export function enumeratedLinks(view, earlier) {
|
|
28
66
|
const paths = new Map(earlier?.paths);
|
|
29
67
|
const revisions = new Map(earlier?.revisions);
|
|
@@ -50,7 +88,7 @@ export function streamedLinks(held, advanced) {
|
|
|
50
88
|
for (const reference of linked)
|
|
51
89
|
if (!held.handed.has(reference))
|
|
52
90
|
return null;
|
|
53
|
-
for (const reference of paths.get(entry.path) ?? held.handed) {
|
|
91
|
+
for (const reference of paths.get(entry.path) ?? held.handed.keys()) {
|
|
54
92
|
if (held.handed.has(reference) && !linked.has(reference))
|
|
55
93
|
dropped.add(reference);
|
|
56
94
|
}
|
package/dist/model.d.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare
|
|
8
|
-
export declare function failedModel(failure: AdapterFailure | {
|
|
9
|
-
kind: 'beyond-horizon';
|
|
10
|
-
}): ModelResult;
|
|
11
|
-
export declare function modelKey(locator: string, attached: ModelRequest['attached']): string;
|
|
12
|
-
export declare function heldModel(read: HouseSchema | null, identity: string, failure: ModelResult): Promise<HeldModel>;
|
|
13
|
-
export type ModelShelf = {
|
|
14
|
-
retain(key: string, acquired: HeldModel | undefined): HeldModel | undefined;
|
|
15
|
-
answer(request: ModelRequest): ModelResult;
|
|
16
|
-
keep(locators: readonly string[]): void;
|
|
17
|
-
};
|
|
18
|
-
export declare function modelShelf(): ModelShelf;
|
|
1
|
+
import type { RoomModels } from '@agentshouse/mdruntime';
|
|
2
|
+
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
+
import { type HouseScope, type HouseView } from './read.js';
|
|
4
|
+
import type { HouseMode, HouseStreamEntry } from './transport.js';
|
|
5
|
+
export declare function scopeModels(scope: HouseScope, tracked: TrackedAuthority): Promise<RoomModels | undefined>;
|
|
6
|
+
export declare function viewModels(view: HouseView, tracked: TrackedAuthority): Promise<RoomModels | undefined>;
|
|
7
|
+
export declare function streamedModels(schemas: ReadonlyMap<string, HouseStreamEntry>, tracked: TrackedAuthority, mode: HouseMode): Promise<RoomModels | undefined>;
|
|
19
8
|
//# sourceMappingURL=model.d.ts.map
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAA0C,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACpG,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAiClE,wBAAgB,WAAW,CACzB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAEjC;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAQjC;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAC9C,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CASjC"}
|
package/dist/model.js
CHANGED
|
@@ -1,46 +1,53 @@
|
|
|
1
1
|
import { sha256Hex } from './digest.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (failure.kind === 'transport-uncertainty')
|
|
7
|
-
return { kind: 'transport-uncertainty' };
|
|
8
|
-
return MODEL_ABSENT;
|
|
9
|
-
}
|
|
10
|
-
export function modelKey(locator, attached) {
|
|
11
|
-
return `${locator} ${attached}`;
|
|
12
|
-
}
|
|
13
|
-
export async function heldModel(read, identity, failure) {
|
|
2
|
+
import { schemaOf, schemaPath } from './read.js';
|
|
3
|
+
const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
|
|
4
|
+
const ABSENT_SCHEMA = { schema: null, version: null };
|
|
5
|
+
async function heldModel(read, identity) {
|
|
14
6
|
if (read === null)
|
|
15
|
-
return
|
|
7
|
+
return MODEL_ABSENT;
|
|
16
8
|
const version = await sha256Hex(JSON.stringify(read.version));
|
|
17
|
-
return {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
9
|
+
return { kind: 'model', snapshot: { identity, version, schema: read.schema } };
|
|
10
|
+
}
|
|
11
|
+
async function modelsOf(tracked, read) {
|
|
12
|
+
const models = {};
|
|
13
|
+
const collection = read(tracked.schema);
|
|
14
|
+
if (collection !== undefined) {
|
|
15
|
+
models.collection = await heldModel(collection, schemaPath(tracked.handle, tracked.schema));
|
|
16
|
+
}
|
|
17
|
+
if (tracked.houseModel !== null) {
|
|
18
|
+
const root = tracked.houseModel.root;
|
|
19
|
+
const selection = read(root);
|
|
20
|
+
if (selection !== undefined) {
|
|
21
|
+
models.selection = await heldModel(selection, schemaPath(tracked.handle, root));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return models.collection === undefined && models.selection === undefined ? undefined : models;
|
|
25
|
+
}
|
|
26
|
+
export function scopeModels(scope, tracked) {
|
|
27
|
+
return modelsOf(tracked, (schema) => schemaOf(scope, schema));
|
|
28
|
+
}
|
|
29
|
+
export function viewModels(view, tracked) {
|
|
30
|
+
return modelsOf(tracked, (schema) => {
|
|
31
|
+
const change = view.changes.find((candidate) => candidate.path === schema);
|
|
32
|
+
if (change === undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
if ('removed' in change)
|
|
35
|
+
return ABSENT_SCHEMA;
|
|
36
|
+
if ('content' in change)
|
|
37
|
+
return { schema: change.content, version: change.version };
|
|
38
|
+
return null;
|
|
39
|
+
});
|
|
21
40
|
}
|
|
22
|
-
export function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return acquired;
|
|
35
|
-
},
|
|
36
|
-
answer(request) {
|
|
37
|
-
return models.get(modelKey(request.locator, request.attached))?.snapshot ?? MODEL_ABSENT;
|
|
38
|
-
},
|
|
39
|
-
keep(locators) {
|
|
40
|
-
for (const key of [...models.keys()]) {
|
|
41
|
-
if (!locators.some((locator) => key.startsWith(`${locator} `)))
|
|
42
|
-
models.delete(key);
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
};
|
|
41
|
+
export function streamedModels(schemas, tracked, mode) {
|
|
42
|
+
return modelsOf(tracked, (schema) => {
|
|
43
|
+
const entry = schemas.get(schema);
|
|
44
|
+
if (entry === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
if (entry.kind === 'removed')
|
|
47
|
+
return ABSENT_SCHEMA;
|
|
48
|
+
if (entry.text === undefined)
|
|
49
|
+
return null;
|
|
50
|
+
const version = mode === 'site' ? entry.sha256 : entry.revision;
|
|
51
|
+
return version === undefined ? null : { schema: entry.text, version };
|
|
52
|
+
});
|
|
46
53
|
}
|
package/dist/read.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export declare function headChange(held: {
|
|
|
61
61
|
readonly author?: unknown;
|
|
62
62
|
readonly created_at?: unknown;
|
|
63
63
|
}): HeadChange | undefined | null;
|
|
64
|
+
export declare function parseOriginals(value: unknown): readonly RoomAttachment[] | null;
|
|
64
65
|
export declare function parseEnvelope(body: unknown): HouseEnvelope | null;
|
|
65
66
|
export declare function parseSiteBootstrap(body: unknown): HouseScope | null;
|
|
66
67
|
export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
|
|
@@ -71,7 +72,6 @@ export type HouseSchema = {
|
|
|
71
72
|
schema: string | null;
|
|
72
73
|
version: string | null;
|
|
73
74
|
};
|
|
74
|
-
export declare function schemaFrom(envelope: HouseEnvelope, tracked: TrackedAuthority, schema: string): HouseSchema | null;
|
|
75
75
|
export declare function schemaOf(scope: HouseScope, schema: string): HouseSchema | null;
|
|
76
76
|
export declare function viewOf(enumeration: HouseEnumeration, tracked: TrackedAuthority): HouseView | undefined;
|
|
77
77
|
export declare function refreshFrom(view: HouseView, fromRoomVersion: string): RefreshResult;
|
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,aAAa,EACb,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACpC,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IAClC,WAAW,CAAC,EAAE,SAAS,cAAc,E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gB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,GAAG,gBAAgB,GAAG,IAAI,CAyBxF;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,GAAG,UAAU,CA2B5E;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAElF;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,aAAa,CAsB5D;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAK9E;AAED,wBAAgB,MAAM,CACpB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,gBAAgB,GACxB,SAAS,GAAG,SAAS,CAEvB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,GAAG,aAAa,CA+BnF"}
|
package/dist/read.js
CHANGED
|
@@ -3,7 +3,10 @@ export function authorityRoot(handle) {
|
|
|
3
3
|
return `/rooms/${handle}`;
|
|
4
4
|
}
|
|
5
5
|
export function contentPrefixes(tracked) {
|
|
6
|
-
return [
|
|
6
|
+
return [
|
|
7
|
+
authorityRoot(tracked.handle),
|
|
8
|
+
...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
|
|
9
|
+
];
|
|
7
10
|
}
|
|
8
11
|
export function schemaPath(handle, schema) {
|
|
9
12
|
return `${authorityRoot(handle)}/${schema}`;
|
|
@@ -60,7 +63,7 @@ function parseOriginal(value) {
|
|
|
60
63
|
return null;
|
|
61
64
|
return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
|
|
62
65
|
}
|
|
63
|
-
function parseOriginals(value) {
|
|
66
|
+
export function parseOriginals(value) {
|
|
64
67
|
if (!Array.isArray(value))
|
|
65
68
|
return null;
|
|
66
69
|
const attachments = [];
|
|
@@ -282,12 +285,6 @@ export function bootstrapOf(scope) {
|
|
|
282
285
|
...declared(scope.attachments),
|
|
283
286
|
};
|
|
284
287
|
}
|
|
285
|
-
export function schemaFrom(envelope, tracked, schema) {
|
|
286
|
-
const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));
|
|
287
|
-
if (scope === undefined)
|
|
288
|
-
return null;
|
|
289
|
-
return schemaOf(scope, schema);
|
|
290
|
-
}
|
|
291
288
|
export function schemaOf(scope, schema) {
|
|
292
289
|
const file = scope.files.find((entry) => entry.path === schema);
|
|
293
290
|
if (file === undefined)
|
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,EAML,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AA+BxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAiIxE"}
|
package/dist/site.js
CHANGED
|
@@ -1,42 +1,32 @@
|
|
|
1
1
|
import { actionOutcome } from './actions.js';
|
|
2
2
|
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
3
|
-
import {
|
|
4
|
-
import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom,
|
|
5
|
-
import { classifyDoor, discoveryFailure
|
|
3
|
+
import { scopeModels, streamedModels, viewModels } from './model.js';
|
|
4
|
+
import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom, viewOf, } from './read.js';
|
|
5
|
+
import { classifyDoor, discoveryFailure } from './refusal.js';
|
|
6
6
|
import { houseNotifications } from './stream.js';
|
|
7
7
|
import { PRIVATE_LOCATOR, SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, } from './transport.js';
|
|
8
|
-
import { logPosition, presented, reachedVersion, roomVersion, } from './version.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
14
|
roomVersion: roomVersion(tracked),
|
|
15
15
|
operations: { read: [''], sync: [''], write: [], delete: [] },
|
|
16
16
|
replica: { selection: tracked.locator, admission: 'admitted' },
|
|
17
|
-
attachedModel,
|
|
18
17
|
providerOwnedPaths: [],
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
function settled(refused) {
|
|
22
|
-
return refused.kind === 'beyond-horizon'
|
|
23
|
-
? UNCERTAIN
|
|
24
|
-
: refused;
|
|
21
|
+
return refused.kind === 'beyond-horizon' ? UNCERTAIN : refused;
|
|
25
22
|
}
|
|
26
23
|
export function createSiteAdapter(transport) {
|
|
27
24
|
const notifications = houseNotifications(transport, 'site');
|
|
28
25
|
const tracked = new Map();
|
|
29
|
-
const models = modelShelf();
|
|
30
|
-
const acquired = new Map();
|
|
31
|
-
let caught = new Map();
|
|
32
26
|
async function enumeration(entry, from) {
|
|
33
27
|
const answer = await transport.door(SITE_DOOR_ENUMERATE, {
|
|
34
28
|
positions: [presented(entry.authority, from)],
|
|
35
29
|
});
|
|
36
|
-
const behind = doorRefusal(answer.body);
|
|
37
|
-
if (behind?.code === 'replica_behind' && behind.retryable) {
|
|
38
|
-
return { kind: 'retryable-refusal', code: behind.code, fields: behind.fields };
|
|
39
|
-
}
|
|
40
30
|
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
41
31
|
if (classified !== null)
|
|
42
32
|
return classified;
|
|
@@ -65,31 +55,27 @@ export function createSiteAdapter(transport) {
|
|
|
65
55
|
if (from === null)
|
|
66
56
|
return { kind: 'beyond-horizon' };
|
|
67
57
|
const streamed = notifications.advance(entry, from);
|
|
68
|
-
if (streamed !== null)
|
|
69
|
-
|
|
58
|
+
if (streamed !== null) {
|
|
59
|
+
const models = await streamedModels(streamed.schemas, entry, 'site');
|
|
60
|
+
return models === undefined ? streamed.page : { ...streamed.page, models };
|
|
61
|
+
}
|
|
70
62
|
const found = await enumeration(entry, from);
|
|
71
63
|
if ('kind' in found)
|
|
72
64
|
return found;
|
|
73
65
|
const view = viewOf(found, entry);
|
|
74
66
|
if (view === undefined)
|
|
75
67
|
return { kind: 'room-not-readable', locator: entry.locator };
|
|
76
|
-
notifications.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const model = await heldModel(schemaOf(held.scope, entry.schema), schemaPath(entry.handle, entry.schema), MODEL_ABSENT);
|
|
83
|
-
acquired.set(entry.authority, { roomVersion: roomVersion(held.scope), model });
|
|
84
|
-
return model;
|
|
68
|
+
notifications.reach(entry.authority, view);
|
|
69
|
+
const answer = refreshFrom(view, fromRoomVersion);
|
|
70
|
+
if (answer.kind !== 'net-advancement')
|
|
71
|
+
return answer;
|
|
72
|
+
const models = await viewModels(view, entry);
|
|
73
|
+
return models === undefined ? answer : { ...answer, models };
|
|
85
74
|
}
|
|
86
75
|
return {
|
|
87
76
|
async authorize() {
|
|
88
77
|
return {};
|
|
89
78
|
},
|
|
90
|
-
async model(_authorization, request) {
|
|
91
|
-
return models.answer(request);
|
|
92
|
-
},
|
|
93
79
|
async discover() {
|
|
94
80
|
const answer = await transport.read(SITE_DOOR_DISCOVER);
|
|
95
81
|
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
@@ -103,30 +89,7 @@ export function createSiteAdapter(transport) {
|
|
|
103
89
|
for (const entry of entries)
|
|
104
90
|
tracked.set(entry.locator, entry);
|
|
105
91
|
notifications.track(entries);
|
|
106
|
-
|
|
107
|
-
for (const authority of [...acquired.keys()]) {
|
|
108
|
-
if (!published.has(authority))
|
|
109
|
-
acquired.delete(authority);
|
|
110
|
-
}
|
|
111
|
-
const fresh = new Map();
|
|
112
|
-
const current = new Map();
|
|
113
|
-
for (const entry of entries) {
|
|
114
|
-
const kept = acquired.get(entry.authority);
|
|
115
|
-
if (kept !== undefined && kept.roomVersion === roomVersion(entry)) {
|
|
116
|
-
current.set(entry.authority, kept.model);
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
const held = await caughtUp(entry);
|
|
120
|
-
fresh.set(entry.authority, held);
|
|
121
|
-
current.set(entry.authority, await acquire(entry, held));
|
|
122
|
-
}
|
|
123
|
-
caught = fresh;
|
|
124
|
-
const rooms = entries.map((entry) => {
|
|
125
|
-
const shelved = models.retain(modelKey(entry.locator, 'collection'), current.get(entry.authority));
|
|
126
|
-
return siteRoom(entry, shelved?.identity ?? null);
|
|
127
|
-
});
|
|
128
|
-
models.keep(entries.map((entry) => entry.locator));
|
|
129
|
-
return mapDiscovery(document, rooms, siteCapabilities());
|
|
92
|
+
return mapDiscovery(document, entries.map(siteRoom), siteCapabilities());
|
|
130
93
|
},
|
|
131
94
|
async bootstrap(_authorization, request) {
|
|
132
95
|
const entry = tracked.get(request.locator);
|
|
@@ -134,11 +97,12 @@ export function createSiteAdapter(transport) {
|
|
|
134
97
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
135
98
|
if (request.pageToken !== undefined)
|
|
136
99
|
return UNCERTAIN;
|
|
137
|
-
const held =
|
|
100
|
+
const held = await caughtUp(entry);
|
|
138
101
|
if ('failure' in held)
|
|
139
102
|
return held.failure;
|
|
140
|
-
notifications.
|
|
141
|
-
|
|
103
|
+
notifications.reach(entry.authority, held.scope);
|
|
104
|
+
const models = await scopeModels(held.scope, entry);
|
|
105
|
+
return { ...bootstrapOf(held.scope), ...(models === undefined ? {} : { models }) };
|
|
142
106
|
},
|
|
143
107
|
async refresh(_authorization, request) {
|
|
144
108
|
const entry = tracked.get(request.locator);
|
|
@@ -146,20 +110,7 @@ export function createSiteAdapter(transport) {
|
|
|
146
110
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
147
111
|
if (request.pageToken !== undefined)
|
|
148
112
|
return UNCERTAIN;
|
|
149
|
-
|
|
150
|
-
if (result.kind === 'beyond-horizon')
|
|
151
|
-
caught.delete(entry.authority);
|
|
152
|
-
const answered = result.kind === 'net-advancement'
|
|
153
|
-
? result.roomVersion
|
|
154
|
-
: result.kind === 'still-current'
|
|
155
|
-
? request.fromRoomVersion
|
|
156
|
-
: null;
|
|
157
|
-
if (request.minPosition !== undefined &&
|
|
158
|
-
answered !== null &&
|
|
159
|
-
!reachedVersion(answered, request.minPosition, entry.logEpoch)) {
|
|
160
|
-
return { kind: 'retryable-refusal', code: 'replica_behind', fields: {} };
|
|
161
|
-
}
|
|
162
|
-
return result;
|
|
113
|
+
return refreshed(entry, request.fromRoomVersion);
|
|
163
114
|
},
|
|
164
115
|
async mutate() {
|
|
165
116
|
return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {} };
|
|
@@ -170,6 +121,9 @@ export function createSiteAdapter(transport) {
|
|
|
170
121
|
reached(locator, version, target) {
|
|
171
122
|
return reachedVersion(version, target, tracked.get(locator)?.logEpoch);
|
|
172
123
|
},
|
|
124
|
+
follows(_locator, version, next) {
|
|
125
|
+
return followsVersion(version, next);
|
|
126
|
+
},
|
|
173
127
|
async action(_authorization, request) {
|
|
174
128
|
if (request.name !== 'submit') {
|
|
175
129
|
return { kind: 'rejected', code: 'action-unimplemented', fields: { name: request.name } };
|
|
@@ -178,7 +132,19 @@ export function createSiteAdapter(transport) {
|
|
|
178
132
|
return UNCERTAIN;
|
|
179
133
|
return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), 'submit');
|
|
180
134
|
},
|
|
181
|
-
|
|
135
|
+
roomStream: {
|
|
136
|
+
hold(rooms) {
|
|
137
|
+
notifications.send(rooms.flatMap((room) => {
|
|
138
|
+
const entry = tracked.get(room.locator);
|
|
139
|
+
const at = logPosition(room.roomVersion);
|
|
140
|
+
if (entry === undefined || at === null)
|
|
141
|
+
return [];
|
|
142
|
+
notifications.reach(entry.authority, at);
|
|
143
|
+
return [presented(entry.authority, at)];
|
|
144
|
+
}));
|
|
145
|
+
},
|
|
146
|
+
observe: notifications.observe,
|
|
147
|
+
},
|
|
182
148
|
serviceMode: notifications.serviceMode,
|
|
183
149
|
};
|
|
184
150
|
}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
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
5
|
export type HeldRevision = (path: string, revision: string) => boolean;
|
|
6
6
|
export type StreamedAdvancement = {
|
|
7
7
|
page: RefreshPage;
|
|
8
8
|
entries: readonly HouseStreamEntry[];
|
|
9
|
+
schemas: ReadonlyMap<string, HouseStreamEntry>;
|
|
9
10
|
};
|
|
10
|
-
export type HouseNotifications =
|
|
11
|
+
export type HouseNotifications = {
|
|
12
|
+
runtime: string;
|
|
13
|
+
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
14
|
+
send(rooms: readonly HouseHeldRoom[]): void;
|
|
11
15
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
12
|
-
|
|
16
|
+
reach(authority: string, at: LogPosition): void;
|
|
13
17
|
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): StreamedAdvancement | null;
|
|
14
18
|
conversations: ConversationStream;
|
|
15
19
|
serviceMode: ServiceModeSignal;
|
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,IAAI,CAAC;IAC9D,IAAI,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,IAAI,CAAC;IAC5C,KAAK,CAAC,WAAW,EAAE,SAAS,gBAA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