@agentshouse/mdruntime-adapter 0.1.0-c8ae0c885a042 → 0.1.0-c8bd3a750f35b
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 +120 -14
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +6 -73
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +94 -289
- package/dist/discovery.d.ts +3 -3
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +8 -17
- package/dist/house-model.d.ts +2950 -1
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +1627 -441
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- 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 +10 -58
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +37 -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 +19 -0
- package/dist/room-stream.d.ts.map +1 -0
- package/dist/room-stream.js +57 -0
- package/dist/room-types.d.ts +1 -1
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +2 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +49 -139
- package/dist/stream.d.ts +3 -13
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +97 -411
- package/dist/transport.d.ts +27 -33
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +49 -11
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +2 -2
- package/dist/write.d.ts +4 -0
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +10 -2
- 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,13 @@
|
|
|
1
1
|
import { stepped } from '@agentshouse/mdruntime';
|
|
2
2
|
import { actionOutcome, SITE_SUBMIT } from './actions.js';
|
|
3
3
|
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
|
|
4
|
+
import { bootstrapping } from './read.js';
|
|
5
|
+
import { roomStreams } from './room-stream.js';
|
|
6
|
+
import { classifyDoor, discoveryFailure } from './refusal.js';
|
|
8
7
|
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
9
8
|
import { houseNotifications } from './stream.js';
|
|
10
|
-
import {
|
|
11
|
-
import { followsVersion, logPosition, presented, reachedVersion, roomVersion
|
|
9
|
+
import { houseSiteRoute, SITE_DOOR_SUBMIT, SITE_FILES, } from './transport.js';
|
|
10
|
+
import { followsVersion, logPosition, presented, reachedVersion, roomVersion } from './version.js';
|
|
12
11
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
13
12
|
function unfound() {
|
|
14
13
|
return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
|
|
@@ -27,86 +26,36 @@ function siteRoom(tracked) {
|
|
|
27
26
|
export function createSiteAdapter(transport, snapshot = false) {
|
|
28
27
|
const notifications = houseNotifications(transport, 'site');
|
|
29
28
|
const tracked = new Map();
|
|
30
|
-
const
|
|
29
|
+
const read = new Map();
|
|
30
|
+
const rooms = roomStreams('site');
|
|
31
31
|
function fileRoute(request) {
|
|
32
32
|
const entry = tracked.get(request.locator);
|
|
33
33
|
if (entry === undefined)
|
|
34
34
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
35
35
|
return `${SITE_FILES}${entry.authority}/${encodeURIComponent(request.revision)}/${encodeURIComponent(request.path)}`;
|
|
36
36
|
}
|
|
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 };
|
|
37
|
+
async function openedRoom(entry, arriving, signal) {
|
|
38
|
+
const cut = read.get(entry.locator);
|
|
39
|
+
const answered = await transport.streamed(`${houseSiteRoute('bootstrap')}/${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`, signal ?? new AbortController().signal);
|
|
40
|
+
if (answered.room === null)
|
|
41
|
+
return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN;
|
|
42
|
+
const head = await rooms.head(entry, answered.room, arriving, signal);
|
|
43
|
+
const at = head.kind === 'bootstrap' ? logPosition(head.roomVersion) : null;
|
|
44
|
+
if (at !== null)
|
|
45
|
+
read.set(entry.locator, at.position);
|
|
46
|
+
return head;
|
|
55
47
|
}
|
|
56
|
-
async function
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return room === null || room.anchor !== entry.authority ? UNCERTAIN : room;
|
|
68
|
-
}
|
|
69
|
-
async function fetchedPart(entry, room, listed, received, arriving) {
|
|
70
|
-
if (received !== undefined) {
|
|
71
|
-
const kept = new Uint8Array(received);
|
|
72
|
-
const held = await housePart(room, kept, listed, 'site');
|
|
73
|
-
if (held !== null)
|
|
74
|
-
return 'kind' in held ? held : { scope: held, frame: kept };
|
|
75
|
-
}
|
|
76
|
-
for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
|
|
77
|
-
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}?part=${encodeURIComponent(listed.part)}`, partArrival(listed, arriving));
|
|
78
|
-
const failure = classifyRead(answer.status, answer.body, entry.locator);
|
|
79
|
-
if (failure?.kind === 'beyond-horizon')
|
|
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);
|
|
91
|
-
}
|
|
92
|
-
async function refreshed(entry, fromRoomVersion) {
|
|
93
|
-
const from = logPosition(fromRoomVersion);
|
|
94
|
-
if (from === null)
|
|
95
|
-
return { kind: 'beyond-horizon' };
|
|
96
|
-
const streamed = await stepped(notifications.advance(entry, from));
|
|
97
|
-
if (streamed !== null) {
|
|
98
|
-
const models = await streamedModels(streamed.schemas, entry, 'site');
|
|
99
|
-
return models === undefined ? streamed.page : { ...streamed.page, models };
|
|
100
|
-
}
|
|
101
|
-
const view = await enumeration(entry, from);
|
|
102
|
-
if ('kind' in view)
|
|
103
|
-
return view;
|
|
104
|
-
notifications.reach(entry.authority, view);
|
|
105
|
-
const answer = await refreshFrom(view, fromRoomVersion);
|
|
106
|
-
if (answer.kind !== 'net-advancement')
|
|
107
|
-
return answer;
|
|
108
|
-
const models = await viewModels(view, entry);
|
|
109
|
-
return models === undefined ? answer : { ...answer, models };
|
|
48
|
+
async function streamedPage(entry, token) {
|
|
49
|
+
const part = await rooms.part(entry, token);
|
|
50
|
+
if ('kind' in part)
|
|
51
|
+
return part;
|
|
52
|
+
const { folders: _folders, ...page } = await stepped(bootstrapping(part.scope));
|
|
53
|
+
return {
|
|
54
|
+
...page,
|
|
55
|
+
...(part.models === undefined ? {} : { models: part.models }),
|
|
56
|
+
...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
|
|
57
|
+
bytes: part.bytes,
|
|
58
|
+
};
|
|
110
59
|
}
|
|
111
60
|
return {
|
|
112
61
|
localSaves: true,
|
|
@@ -117,7 +66,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
117
66
|
return {};
|
|
118
67
|
},
|
|
119
68
|
async discover() {
|
|
120
|
-
const answer = await transport.read(
|
|
69
|
+
const answer = await transport.read(houseSiteRoute('discover'));
|
|
121
70
|
const failed = discoveryFailure(answer.status, answer.body);
|
|
122
71
|
if (failed !== null)
|
|
123
72
|
return failed;
|
|
@@ -135,61 +84,30 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
135
84
|
const entry = tracked.get(request.locator);
|
|
136
85
|
if (entry === undefined)
|
|
137
86
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const room = await partedRoom(entry);
|
|
142
|
-
if ('kind' in room)
|
|
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
|
-
};
|
|
87
|
+
return request.pageToken === undefined
|
|
88
|
+
? openedRoom(entry, request.arriving, request.signal)
|
|
89
|
+
: streamedPage(entry, request.pageToken);
|
|
176
90
|
},
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
91
|
+
...(snapshot
|
|
92
|
+
? {
|
|
93
|
+
async refresh(_authorization, request) {
|
|
94
|
+
const entry = tracked.get(request.locator);
|
|
95
|
+
if (entry === undefined)
|
|
96
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
97
|
+
if (request.pageToken !== undefined)
|
|
98
|
+
return UNCERTAIN;
|
|
99
|
+
return request.fromRoomVersion === roomVersion(entry)
|
|
100
|
+
? { kind: 'still-current' }
|
|
101
|
+
: { kind: 'beyond-horizon' };
|
|
102
|
+
},
|
|
187
103
|
}
|
|
188
|
-
|
|
189
|
-
},
|
|
104
|
+
: {}),
|
|
190
105
|
async mutate() {
|
|
191
106
|
return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {}, retryable: false };
|
|
192
107
|
},
|
|
108
|
+
async attach() {
|
|
109
|
+
return { kind: 'rejected', code: 'write-grant', fields: {}, retryable: false };
|
|
110
|
+
},
|
|
193
111
|
async history() {
|
|
194
112
|
return { kind: 'no-history' };
|
|
195
113
|
},
|
|
@@ -240,19 +158,11 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
240
158
|
notifications.send(rooms.flatMap((room) => {
|
|
241
159
|
const entry = tracked.get(room.locator);
|
|
242
160
|
const at = logPosition(room.roomVersion);
|
|
243
|
-
|
|
244
|
-
return [];
|
|
245
|
-
notifications.reach(entry.authority, at);
|
|
246
|
-
return [presented(entry.authority, at)];
|
|
161
|
+
return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
|
|
247
162
|
}));
|
|
248
163
|
},
|
|
249
164
|
reopen: notifications.reopen,
|
|
250
165
|
observe: notifications.observe,
|
|
251
|
-
published(locator, roomVersion) {
|
|
252
|
-
const at = logPosition(roomVersion);
|
|
253
|
-
if (at !== null)
|
|
254
|
-
notifications.published(locator, at);
|
|
255
|
-
},
|
|
256
166
|
},
|
|
257
167
|
serviceMode: notifications.serviceMode,
|
|
258
168
|
};
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
|
-
import { type ConversationStream, type
|
|
1
|
+
import { type ConversationStream, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import type
|
|
4
|
-
import { type LogPosition } from './version.js';
|
|
5
|
-
export type HeldRevision = (path: string, revision: string) => boolean;
|
|
6
|
-
export type StreamedAdvancement = {
|
|
7
|
-
page: RefreshPage;
|
|
8
|
-
schemas: ReadonlyMap<string, HouseStreamEntry>;
|
|
9
|
-
};
|
|
3
|
+
import { type HouseDoor, type HouseHeldRoom, type HouseMode } from './transport.js';
|
|
10
4
|
export type HouseNotifications = {
|
|
11
5
|
runtime: string;
|
|
12
|
-
observe(notify: (event: RoomStreamEvent) => void
|
|
6
|
+
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
13
7
|
send(rooms: readonly HouseHeldRoom[]): void;
|
|
14
|
-
published(locator: string, at: LogPosition): void;
|
|
15
8
|
reopen(): void;
|
|
16
9
|
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
10
|
conversations: ConversationStream;
|
|
21
11
|
serviceMode: ServiceModeSignal;
|
|
22
12
|
};
|
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,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,kBAAkB,EAIvB,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAWvD,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,aAAa,EAElB,KAAK,SAAS,EAIf,MAAM,gBAAgB,CAAC;AAaxB,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,MAAM,IAAI,IAAI,CAAC;IACf,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtD,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAkFF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CA2Q5F"}
|