@agentshouse/mdruntime-adapter 0.1.0-c095903579aec → 0.1.0-c0a168d2cd8cc
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/dist/actions.d.ts +2 -47
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +7 -225
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +99 -327
- package/dist/discovery.d.ts +17 -4
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +58 -24
- package/dist/history.d.ts +12 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +92 -0
- package/dist/house-model.d.ts +910 -1
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +501 -486
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/model.d.ts +2 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -17
- package/dist/part.d.ts +11 -12
- package/dist/part.d.ts.map +1 -1
- package/dist/part.js +63 -55
- package/dist/read.d.ts +14 -58
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +61 -220
- package/dist/refusal.d.ts +0 -3
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +0 -5
- package/dist/room-stream.d.ts +20 -0
- package/dist/room-stream.d.ts.map +1 -0
- package/dist/room-stream.js +78 -0
- package/dist/room-types.d.ts +2 -2
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +7 -7
- package/dist/search.d.ts +5 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +79 -157
- package/dist/stream.d.ts +13 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +169 -426
- package/dist/transport.d.ts +49 -36
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +54 -12
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +2 -2
- package/dist/write.d.ts +2 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +7 -22
- package/package.json +2 -2
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -35
package/dist/site.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { stepped } from '@agentshouse/mdruntime';
|
|
2
|
-
import { actionOutcome
|
|
2
|
+
import { actionOutcome } from './actions.js';
|
|
3
3
|
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { bootstrapping } from './read.js';
|
|
5
|
+
import { roomStreams } from './room-stream.js';
|
|
6
|
+
import { classifyDoor, discoveryFailure } from './refusal.js';
|
|
7
|
+
import { HOUSE_TYPED_PATHS } from './house-model.js';
|
|
8
8
|
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
9
9
|
import { houseNotifications } from './stream.js';
|
|
10
|
-
import {
|
|
11
|
-
import { followsVersion, logPosition, presented, reachedVersion, roomVersion
|
|
10
|
+
import { houseSiteRoute, SITE_DOOR_SUBMIT, SITE_FILES, SITE_SUBMISSION, } from './transport.js';
|
|
11
|
+
import { followsVersion, logPosition, presented, reachedVersion, roomVersion } from './version.js';
|
|
12
12
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
13
13
|
function unfound() {
|
|
14
14
|
return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
|
|
@@ -25,168 +25,99 @@ function siteRoom(tracked) {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
export function createSiteAdapter(transport, snapshot = false) {
|
|
28
|
-
const notifications = houseNotifications(transport, 'site'
|
|
28
|
+
const notifications = houseNotifications(transport, 'site', {
|
|
29
|
+
opened: async () => {
|
|
30
|
+
const found = await discovered();
|
|
31
|
+
return found.kind === 'discovery' ? found : null;
|
|
32
|
+
},
|
|
33
|
+
changed: () => null,
|
|
34
|
+
});
|
|
29
35
|
const tracked = new Map();
|
|
30
|
-
const
|
|
36
|
+
const read = new Map();
|
|
37
|
+
const rooms = roomStreams('site');
|
|
31
38
|
function fileRoute(request) {
|
|
32
39
|
const entry = tracked.get(request.locator);
|
|
33
40
|
if (entry === undefined)
|
|
34
41
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
35
42
|
return `${SITE_FILES}${entry.authority}/${encodeURIComponent(request.revision)}/${encodeURIComponent(request.path)}`;
|
|
36
43
|
}
|
|
37
|
-
async function
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
const classified = classifyRead(answer.status, answer.body, entry.locator);
|
|
49
|
-
if (classified !== null)
|
|
50
|
-
return classified;
|
|
51
|
-
const found = parseEnumeration(answer.body, 'site');
|
|
52
|
-
if (found === null)
|
|
53
|
-
return UNCERTAIN;
|
|
54
|
-
return viewOf(found, entry) ?? { kind: 'room-not-readable', locator: entry.locator };
|
|
55
|
-
}
|
|
56
|
-
async function enumeration(entry, from) {
|
|
57
|
-
const first = await enumerated(entry, from);
|
|
58
|
-
return 'kind' in first ? first : wholeView(first, (page) => enumerated(entry, from, page));
|
|
44
|
+
async function openedRoom(entry, arriving, signal) {
|
|
45
|
+
const cut = read.get(entry.locator);
|
|
46
|
+
const answered = await transport.streamed(`${houseSiteRoute('bootstrap')}/${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`, signal ?? new AbortController().signal);
|
|
47
|
+
if (answered.room === null)
|
|
48
|
+
return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN;
|
|
49
|
+
const head = await rooms.head(entry, answered.room, arriving, signal);
|
|
50
|
+
const at = head.kind === 'bootstrap' ? logPosition(head.roomVersion) : null;
|
|
51
|
+
if (at !== null)
|
|
52
|
+
read.set(entry.locator, at.position);
|
|
53
|
+
return head;
|
|
59
54
|
}
|
|
60
|
-
async function
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return classified;
|
|
66
|
-
const room = parseSiteParted(answer.body);
|
|
67
|
-
return room === null || room.anchor !== entry.authority ? UNCERTAIN : room;
|
|
55
|
+
async function namedDocument(entry, path, signal) {
|
|
56
|
+
const answered = await transport.streamed(`${houseSiteRoute('bootstrap')}/${entry.authority}?path=${encodeURIComponent(path)}`, signal ?? new AbortController().signal);
|
|
57
|
+
if (answered.room === null)
|
|
58
|
+
return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN;
|
|
59
|
+
return rooms.named(entry, answered.room, signal);
|
|
68
60
|
}
|
|
69
|
-
async function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
expired.set(entry.locator, room.position);
|
|
81
|
-
if (failure !== null)
|
|
82
|
-
return failure;
|
|
83
|
-
const frame = partFrame(answer.body);
|
|
84
|
-
if (frame === null)
|
|
85
|
-
continue;
|
|
86
|
-
const scope = await housePart(room, frame, listed, 'site');
|
|
87
|
-
if (scope !== null)
|
|
88
|
-
return 'kind' in scope ? scope : { scope, frame };
|
|
89
|
-
}
|
|
90
|
-
return unverifiedPart(entry.locator);
|
|
61
|
+
async function streamedPage(entry, token) {
|
|
62
|
+
const part = await rooms.part(entry, token);
|
|
63
|
+
if ('kind' in part)
|
|
64
|
+
return part;
|
|
65
|
+
const { folders: _folders, ...page } = await stepped(bootstrapping(part.scope));
|
|
66
|
+
return {
|
|
67
|
+
...page,
|
|
68
|
+
...(part.models === undefined ? {} : { models: part.models }),
|
|
69
|
+
...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
|
|
70
|
+
bytes: part.bytes,
|
|
71
|
+
};
|
|
91
72
|
}
|
|
92
|
-
async function
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
notifications.
|
|
105
|
-
|
|
106
|
-
if (answer.kind !== 'net-advancement')
|
|
107
|
-
return answer;
|
|
108
|
-
const models = await viewModels(view, entry);
|
|
109
|
-
return models === undefined ? answer : { ...answer, models };
|
|
73
|
+
async function discovered() {
|
|
74
|
+
const answer = await transport.read(houseSiteRoute('discover'));
|
|
75
|
+
const failed = discoveryFailure(answer.status, answer.body);
|
|
76
|
+
if (failed !== null)
|
|
77
|
+
return failed;
|
|
78
|
+
const document = parseSiteDiscovery(answer.body);
|
|
79
|
+
if (document === null)
|
|
80
|
+
return UNCERTAIN;
|
|
81
|
+
const entries = siteTracked(document);
|
|
82
|
+
tracked.clear();
|
|
83
|
+
for (const entry of entries)
|
|
84
|
+
tracked.set(entry.locator, entry);
|
|
85
|
+
notifications.track(entries);
|
|
86
|
+
return mapDiscovery(document, entries.map(siteRoom), siteCapabilities());
|
|
110
87
|
}
|
|
111
88
|
return {
|
|
112
89
|
localSaves: true,
|
|
113
|
-
exhaustiveDiscovery: true,
|
|
114
90
|
roomTypes: HOUSE_ROOM_TYPES,
|
|
115
91
|
nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
|
|
92
|
+
typedPaths: HOUSE_TYPED_PATHS,
|
|
116
93
|
async authorize() {
|
|
117
94
|
return {};
|
|
118
95
|
},
|
|
119
|
-
async discover() {
|
|
120
|
-
const answer = await transport.read(SITE_DOOR_DISCOVER);
|
|
121
|
-
const failed = discoveryFailure(answer.status, answer.body);
|
|
122
|
-
if (failed !== null)
|
|
123
|
-
return failed;
|
|
124
|
-
const document = parseSiteDiscovery(answer.body);
|
|
125
|
-
if (document === null)
|
|
126
|
-
return UNCERTAIN;
|
|
127
|
-
const entries = siteTracked(document);
|
|
128
|
-
tracked.clear();
|
|
129
|
-
for (const entry of entries)
|
|
130
|
-
tracked.set(entry.locator, entry);
|
|
131
|
-
notifications.track(entries);
|
|
132
|
-
return mapDiscovery(document, entries.map(siteRoom), siteCapabilities());
|
|
133
|
-
},
|
|
134
96
|
async bootstrap(_authorization, request) {
|
|
135
97
|
const entry = tracked.get(request.locator);
|
|
136
98
|
if (entry === undefined)
|
|
137
99
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return room;
|
|
144
|
-
const { models, seen } = await manifestedModels(room, entry);
|
|
145
|
-
continued = { room, next: 0, seen };
|
|
146
|
-
inventory = partInventory(room);
|
|
147
|
-
if (inventory.parts > 0) {
|
|
148
|
-
return manifested(room, inventory, JSON.stringify(continued), models);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
else
|
|
152
|
-
continued = JSON.parse(request.pageToken);
|
|
153
|
-
const listed = continued.room.parts[continued.next];
|
|
154
|
-
const sent = listed === undefined
|
|
155
|
-
? { scope: emptyScope(continued.room), frame: null }
|
|
156
|
-
: await fetchedPart(entry, continued.room, listed, request.received, request.arriving);
|
|
157
|
-
if ('kind' in sent)
|
|
158
|
-
return sent;
|
|
159
|
-
const { scope } = sent;
|
|
160
|
-
notifications.reach(entry.authority, scope);
|
|
161
|
-
const next = continued.next + 1;
|
|
162
|
-
const more = next < continued.room.parts.length;
|
|
163
|
-
const seen = [
|
|
164
|
-
...continued.seen,
|
|
165
|
-
...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
|
|
166
|
-
];
|
|
167
|
-
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
168
|
-
const { folders: _folders, ...page } = await stepped(bootstrapping(scope));
|
|
169
|
-
return {
|
|
170
|
-
...page,
|
|
171
|
-
...(models === undefined ? {} : { models }),
|
|
172
|
-
...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
|
|
173
|
-
...(inventory === undefined ? {} : { inventory }),
|
|
174
|
-
...(sent.frame === null ? {} : { received: sent.frame }),
|
|
175
|
-
};
|
|
100
|
+
if (request.path !== undefined)
|
|
101
|
+
return namedDocument(entry, request.path, request.signal);
|
|
102
|
+
return request.pageToken === undefined
|
|
103
|
+
? openedRoom(entry, request.arriving, request.signal)
|
|
104
|
+
: streamedPage(entry, request.pageToken);
|
|
176
105
|
},
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
106
|
+
...(snapshot
|
|
107
|
+
? {
|
|
108
|
+
discover: discovered,
|
|
109
|
+
async refresh(_authorization, request) {
|
|
110
|
+
const entry = tracked.get(request.locator);
|
|
111
|
+
if (entry === undefined)
|
|
112
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
113
|
+
if (request.pageToken !== undefined)
|
|
114
|
+
return UNCERTAIN;
|
|
115
|
+
return request.fromRoomVersion === roomVersion(entry)
|
|
116
|
+
? { kind: 'still-current' }
|
|
117
|
+
: { kind: 'beyond-horizon' };
|
|
118
|
+
},
|
|
187
119
|
}
|
|
188
|
-
|
|
189
|
-
},
|
|
120
|
+
: {}),
|
|
190
121
|
async mutate() {
|
|
191
122
|
return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {}, retryable: false };
|
|
192
123
|
},
|
|
@@ -224,7 +155,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
224
155
|
return followsVersion(version, next);
|
|
225
156
|
},
|
|
226
157
|
async action(_authorization, request) {
|
|
227
|
-
if (request.name !==
|
|
158
|
+
if (request.name !== SITE_SUBMISSION) {
|
|
228
159
|
return {
|
|
229
160
|
kind: 'rejected',
|
|
230
161
|
code: 'action-unimplemented',
|
|
@@ -234,7 +165,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
234
165
|
}
|
|
235
166
|
if (!transport.online())
|
|
236
167
|
return UNCERTAIN;
|
|
237
|
-
return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input),
|
|
168
|
+
return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), SITE_SUBMISSION, request.input);
|
|
238
169
|
},
|
|
239
170
|
roomStream: snapshot
|
|
240
171
|
? undefined
|
|
@@ -243,19 +174,10 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
243
174
|
notifications.send(rooms.flatMap((room) => {
|
|
244
175
|
const entry = tracked.get(room.locator);
|
|
245
176
|
const at = logPosition(room.roomVersion);
|
|
246
|
-
|
|
247
|
-
return [];
|
|
248
|
-
notifications.reach(entry.authority, at);
|
|
249
|
-
return [presented(entry.authority, at)];
|
|
177
|
+
return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
|
|
250
178
|
}));
|
|
251
179
|
},
|
|
252
|
-
reopen: notifications.reopen,
|
|
253
180
|
observe: notifications.observe,
|
|
254
|
-
published(locator, roomVersion) {
|
|
255
|
-
const at = logPosition(roomVersion);
|
|
256
|
-
if (at !== null)
|
|
257
|
-
notifications.published(locator, at);
|
|
258
|
-
},
|
|
259
181
|
},
|
|
260
182
|
serviceMode: notifications.serviceMode,
|
|
261
183
|
};
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AuthorityChange, type Discovery, type ConversationStream, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { type HouseDoor, type HouseHeldRoom, type HouseMode, type HouseStreamFrame } from './transport.js';
|
|
4
|
+
export type HouseOpeningFrame = Extract<HouseStreamFrame, {
|
|
5
|
+
type: 'opening';
|
|
6
|
+
}>;
|
|
7
|
+
export type HouseAuthorityChangedFrame = Extract<HouseStreamFrame, {
|
|
8
|
+
type: 'authority_changed';
|
|
9
|
+
}>;
|
|
10
|
+
export type HouseDiscovering = {
|
|
11
|
+
opened(frame: HouseOpeningFrame | null): Promise<Discovery | null>;
|
|
12
|
+
changed(frame: HouseAuthorityChangedFrame): AuthorityChange | null;
|
|
9
13
|
};
|
|
10
14
|
export type HouseNotifications = {
|
|
11
15
|
runtime: string;
|
|
12
|
-
observe(notify: (event: RoomStreamEvent) => void
|
|
16
|
+
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
13
17
|
send(rooms: readonly HouseHeldRoom[]): void;
|
|
14
|
-
published(locator: string, at: LogPosition): void;
|
|
15
|
-
reopen(): void;
|
|
16
18
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
17
|
-
reach(authority: string, at: LogPosition): void;
|
|
18
|
-
edited(tracked: TrackedAuthority, from: LogPosition): readonly string[];
|
|
19
|
-
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): Generator<number, StreamedAdvancement | null, void>;
|
|
20
19
|
conversations: ConversationStream;
|
|
21
20
|
serviceMode: ServiceModeSignal;
|
|
22
21
|
};
|
|
23
|
-
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
|
|
22
|
+
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering): HouseNotifications;
|
|
24
23
|
//# 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,EAGL,KAAK,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EAEpB,KAAK,SAAS,EACd,KAAK,kBAAkB,EAIvB,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAYvD,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,aAAa,EAElB,KAAK,SAAS,EAGd,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AAaxB,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAE/E,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC,CAAC;AAElG,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IACnE,OAAO,CAAC,KAAK,EAAE,0BAA0B,GAAG,eAAe,GAAG,IAAI,CAAC;CACpE,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,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAsFF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,gBAAgB,GAC5B,kBAAkB,CA6TpB"}
|