@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c055ce6f0fdd0
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 +186 -34
- package/README.md +32 -0
- package/dist/actions.d.ts +5 -13
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +241 -334
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +255 -215
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +23 -33
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +143 -230
- package/dist/gather.d.ts +3 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +40 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/links.d.ts +20 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +104 -0
- 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 +48 -59
- package/dist/read.d.ts +31 -26
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +205 -199
- package/dist/refusal.d.ts +3 -1
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +27 -62
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +103 -151
- package/dist/stream.d.ts +16 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +238 -214
- package/dist/transport.d.ts +69 -30
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +2 -3
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +32 -18
- package/dist/write.d.ts +13 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +132 -215
- package/package.json +4 -12
- 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/site.js
CHANGED
|
@@ -1,36 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { actionOutcome } from './actions.js';
|
|
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';
|
|
4
5
|
import { classifyDoor, discoveryFailure } from './refusal.js';
|
|
5
6
|
import { houseNotifications } from './stream.js';
|
|
6
|
-
import {
|
|
7
|
-
import { logPosition, presented, roomVersion } from './version.js';
|
|
8
|
-
const UNCERTAIN = {
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
function siteRoom(tracked, attachedModel) {
|
|
12
|
-
const read = selectionRoots(tracked);
|
|
7
|
+
import { PRIVATE_LOCATOR, 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
|
+
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
10
|
+
function siteRoom(tracked) {
|
|
13
11
|
return {
|
|
14
|
-
name: tracked.
|
|
12
|
+
name: tracked.handle,
|
|
15
13
|
locator: tracked.locator,
|
|
16
|
-
collectionRoot: tracked.collectionRoot,
|
|
17
14
|
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: []
|
|
15
|
+
operations: { read: [''], sync: [''], write: [], delete: [] },
|
|
16
|
+
replica: { selection: tracked.locator, admission: 'admitted' },
|
|
17
|
+
providerOwnedPaths: [],
|
|
34
18
|
};
|
|
35
19
|
}
|
|
36
20
|
function settled(refused) {
|
|
@@ -39,160 +23,128 @@ function settled(refused) {
|
|
|
39
23
|
export function createSiteAdapter(transport) {
|
|
40
24
|
const notifications = houseNotifications(transport, 'site');
|
|
41
25
|
const tracked = new Map();
|
|
42
|
-
const models = modelShelf();
|
|
43
|
-
const acquired = new Map();
|
|
44
|
-
let caught = new Map();
|
|
45
26
|
async function enumeration(entry, from) {
|
|
46
27
|
const answer = await transport.door(SITE_DOOR_ENUMERATE, {
|
|
47
|
-
positions: [
|
|
48
|
-
presented(entry.authority, from)
|
|
49
|
-
]
|
|
28
|
+
positions: [presented(entry.authority, from)],
|
|
50
29
|
});
|
|
51
30
|
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
52
|
-
if (classified !== null)
|
|
31
|
+
if (classified !== null)
|
|
32
|
+
return classified;
|
|
53
33
|
return parseEnumeration(answer.body, 'site') ?? UNCERTAIN;
|
|
54
34
|
}
|
|
55
35
|
async function caughtUp(entry) {
|
|
56
36
|
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}`);
|
|
57
37
|
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
58
|
-
if (classified !== null)
|
|
59
|
-
failure: settled(classified)
|
|
60
|
-
};
|
|
38
|
+
if (classified !== null)
|
|
39
|
+
return { failure: settled(classified) };
|
|
61
40
|
const scope = parseSiteBootstrap(answer.body);
|
|
62
|
-
if (scope === null)
|
|
63
|
-
failure: UNCERTAIN
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
scope
|
|
67
|
-
};
|
|
41
|
+
if (scope === null)
|
|
42
|
+
return { failure: UNCERTAIN };
|
|
43
|
+
if (roomVersion(scope) === roomVersion(entry))
|
|
44
|
+
return { scope };
|
|
68
45
|
const found = await enumeration(entry, scope);
|
|
69
|
-
if ('kind' in found)
|
|
70
|
-
failure: settled(found)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
kind: 'room-not-readable',
|
|
76
|
-
locator: entry.locator
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
return {
|
|
80
|
-
scope: advancedScope(scope, view)
|
|
81
|
-
};
|
|
46
|
+
if ('kind' in found)
|
|
47
|
+
return { failure: settled(found) };
|
|
48
|
+
const view = viewOf(found, entry);
|
|
49
|
+
if (view === undefined)
|
|
50
|
+
return { failure: { kind: 'room-not-readable', locator: entry.locator } };
|
|
51
|
+
return { scope: advancedScope(scope, view) };
|
|
82
52
|
}
|
|
83
53
|
async function refreshed(entry, fromRoomVersion) {
|
|
84
54
|
const from = logPosition(fromRoomVersion);
|
|
85
|
-
if (from === null)
|
|
86
|
-
kind: 'beyond-horizon'
|
|
87
|
-
};
|
|
55
|
+
if (from === null)
|
|
56
|
+
return { kind: 'beyond-horizon' };
|
|
88
57
|
const streamed = notifications.advance(entry, from);
|
|
89
|
-
if (streamed !== null)
|
|
58
|
+
if (streamed !== null) {
|
|
59
|
+
const models = await streamedModels(streamed.schemas, entry, 'site');
|
|
60
|
+
return models === undefined ? streamed.page : { ...streamed.page, models };
|
|
61
|
+
}
|
|
90
62
|
const found = await enumeration(entry, from);
|
|
91
|
-
if ('kind' in found)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
model
|
|
103
|
-
});
|
|
104
|
-
return model;
|
|
63
|
+
if ('kind' in found)
|
|
64
|
+
return found;
|
|
65
|
+
const view = viewOf(found, entry);
|
|
66
|
+
if (view === undefined)
|
|
67
|
+
return { kind: 'room-not-readable', locator: entry.locator };
|
|
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 };
|
|
105
74
|
}
|
|
106
75
|
return {
|
|
107
|
-
async authorize
|
|
76
|
+
async authorize() {
|
|
108
77
|
return {};
|
|
109
78
|
},
|
|
110
|
-
async
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);
|
|
116
|
-
if (classified !== null) return discoveryFailure(classified);
|
|
79
|
+
async discover() {
|
|
80
|
+
const answer = await transport.read(SITE_DOOR_DISCOVER);
|
|
81
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
82
|
+
if (classified !== null)
|
|
83
|
+
return discoveryFailure(classified);
|
|
117
84
|
const document = parseSiteDiscovery(answer.body);
|
|
118
|
-
if (document === null)
|
|
85
|
+
if (document === null)
|
|
86
|
+
return UNCERTAIN;
|
|
119
87
|
const entries = siteTracked(document);
|
|
120
88
|
tracked.clear();
|
|
121
|
-
for (const entry of entries)
|
|
89
|
+
for (const entry of entries)
|
|
90
|
+
tracked.set(entry.locator, entry);
|
|
122
91
|
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());
|
|
92
|
+
return mapDiscovery(document, entries.map(siteRoom), siteCapabilities());
|
|
149
93
|
},
|
|
150
|
-
async bootstrap
|
|
94
|
+
async bootstrap(_authorization, request) {
|
|
151
95
|
const entry = tracked.get(request.locator);
|
|
152
|
-
if (entry === undefined)
|
|
153
|
-
kind: 'room-not-readable',
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
96
|
+
if (entry === undefined)
|
|
97
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
98
|
+
if (request.pageToken !== undefined)
|
|
99
|
+
return UNCERTAIN;
|
|
100
|
+
const held = await caughtUp(entry);
|
|
101
|
+
if ('failure' in held)
|
|
102
|
+
return held.failure;
|
|
103
|
+
notifications.reach(entry.authority, held.scope);
|
|
104
|
+
const models = await scopeModels(held.scope, entry);
|
|
105
|
+
return { ...bootstrapOf(held.scope), ...(models === undefined ? {} : { models }) };
|
|
160
106
|
},
|
|
161
|
-
async refresh
|
|
107
|
+
async refresh(_authorization, request) {
|
|
162
108
|
const entry = tracked.get(request.locator);
|
|
163
|
-
if (entry === undefined)
|
|
164
|
-
kind: 'room-not-readable',
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return
|
|
109
|
+
if (entry === undefined)
|
|
110
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
111
|
+
if (request.pageToken !== undefined)
|
|
112
|
+
return UNCERTAIN;
|
|
113
|
+
return refreshed(entry, request.fromRoomVersion);
|
|
114
|
+
},
|
|
115
|
+
async mutate() {
|
|
116
|
+
return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {} };
|
|
171
117
|
},
|
|
172
|
-
async
|
|
173
|
-
return {
|
|
174
|
-
kind: 'rejected',
|
|
175
|
-
affected: {},
|
|
176
|
-
code: 'write-grant',
|
|
177
|
-
fields: {}
|
|
178
|
-
};
|
|
118
|
+
async history() {
|
|
119
|
+
return { kind: 'no-history' };
|
|
179
120
|
},
|
|
180
|
-
|
|
181
|
-
return
|
|
182
|
-
|
|
183
|
-
|
|
121
|
+
reached(locator, version, target) {
|
|
122
|
+
return reachedVersion(version, target, tracked.get(locator)?.logEpoch);
|
|
123
|
+
},
|
|
124
|
+
follows(_locator, version, next) {
|
|
125
|
+
return followsVersion(version, next);
|
|
126
|
+
},
|
|
127
|
+
async action(_authorization, request) {
|
|
128
|
+
if (request.name !== 'submit') {
|
|
129
|
+
return { kind: 'rejected', code: 'action-unimplemented', fields: { name: request.name } };
|
|
130
|
+
}
|
|
131
|
+
if (!transport.online())
|
|
132
|
+
return UNCERTAIN;
|
|
133
|
+
return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), 'submit');
|
|
184
134
|
},
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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,
|
|
193
147
|
},
|
|
194
|
-
|
|
148
|
+
serviceMode: notifications.serviceMode,
|
|
195
149
|
};
|
|
196
150
|
}
|
|
197
|
-
|
|
198
|
-
//# sourceMappingURL=site.js.map
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import type { RefreshPage,
|
|
1
|
+
import type { ConversationStream, RefreshPage, RoomStreamEvent, ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import {
|
|
4
|
-
import type { HouseMode } from './transport.js';
|
|
3
|
+
import type { 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): () => void;
|
|
14
|
+
send(rooms: readonly HouseHeldRoom[]): void;
|
|
7
15
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
8
|
-
|
|
9
|
-
|
|
16
|
+
reach(authority: string, at: LogPosition): void;
|
|
17
|
+
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): StreamedAdvancement | null;
|
|
18
|
+
conversations: ConversationStream;
|
|
19
|
+
serviceMode: ServiceModeSignal;
|
|
10
20
|
};
|
|
11
21
|
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
|
|
12
22
|
//# 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,EAEV,WAAW,
|
|
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,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;AAuBF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CAoS5F"}
|