@agentshouse/mdruntime-adapter 0.1.0-c43b33ffa2341 → 0.1.0-c445f28968612
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 +4 -48
- 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 +97 -327
- package/dist/discovery.d.ts +10 -5
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +34 -27
- 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 +891 -1
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +482 -485
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -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 +14 -58
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +65 -222
- 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.js +1 -1
- 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 +77 -157
- package/dist/stream.d.ts +13 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +168 -426
- package/dist/transport.d.ts +47 -36
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +55 -12
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +2 -2
- package/dist/write.d.ts +6 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +17 -19
- 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/adapter.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { stepped } from '@agentshouse/mdruntime';
|
|
2
|
-
import {
|
|
3
|
-
import { manifestedModels, partModels, streamedModels, viewModels } from './model.js';
|
|
4
|
-
import { gathered, gatheredEach, selections } from './gather.js';
|
|
2
|
+
import { capabilities, discoveredRoom, mapDiscovery, parseAuthorityChange, parseDiscovery, trackedFrom, } from './discovery.js';
|
|
5
3
|
import { createSiteAdapter } from './site.js';
|
|
6
|
-
import { authorityRoot, bootstrapping,
|
|
7
|
-
import {
|
|
4
|
+
import { authorityRoot, bootstrapping, parseFileAddress, parseGrant, } from './read.js';
|
|
5
|
+
import { roomStreams } from './room-stream.js';
|
|
8
6
|
import { sha256Hex } from './digest.js';
|
|
9
7
|
import { finishedUpload, houseUpload } from './upload.js';
|
|
10
8
|
import { houseAction } from './actions.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
9
|
+
import { houseSearch } from './search.js';
|
|
10
|
+
import { classifyDoor, doorRefusal } from './refusal.js';
|
|
11
|
+
import { houseNotifications, } from './stream.js';
|
|
12
|
+
import { houseDoorRoute, } from './transport.js';
|
|
14
13
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
15
14
|
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
16
|
-
import { followsVersion, logPosition, presented, reachedVersion, roomVersion
|
|
15
|
+
import { followsVersion, logPosition, presented, reachedVersion, roomVersion } from './version.js';
|
|
17
16
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
18
17
|
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
19
18
|
const OCTET_STREAM = 'application/octet-stream';
|
|
@@ -30,7 +29,7 @@ async function heldFiles(authority, held, bound) {
|
|
|
30
29
|
async function reused(scope, held) {
|
|
31
30
|
const sent = new Set(scope.contents.map((entry) => entry.path));
|
|
32
31
|
const contents = [...scope.contents];
|
|
33
|
-
const asked = scope.files.filter((file) => file.binary === undefined && !sent.has(file.path));
|
|
32
|
+
const asked = scope.files.filter((file) => file.binary === undefined && file.outline === undefined && !sent.has(file.path));
|
|
34
33
|
if (asked.length === 0)
|
|
35
34
|
return scope;
|
|
36
35
|
if (held === undefined)
|
|
@@ -51,161 +50,91 @@ export function createAgentsHouseAdapter(options) {
|
|
|
51
50
|
if ('site' in options)
|
|
52
51
|
return createSiteAdapter(options.site, options.snapshot === true);
|
|
53
52
|
const transport = options.transport;
|
|
54
|
-
const notifications = houseNotifications(transport, 'credential'
|
|
53
|
+
const notifications = houseNotifications(transport, 'credential', {
|
|
54
|
+
opened: async (frame) => (frame === null ? null : opened(frame)),
|
|
55
|
+
changed,
|
|
56
|
+
});
|
|
55
57
|
const tracked = new Map();
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
+
const rooms = roomStreams('credential');
|
|
59
|
+
const unreused = new Set();
|
|
58
60
|
let bounds;
|
|
59
61
|
function declared() {
|
|
60
62
|
if (bounds === undefined)
|
|
61
63
|
throw new Error('no Discovery declared the bounds');
|
|
62
64
|
return bounds;
|
|
63
65
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const failure = classifyRead(answered.status, answered.body, entry.locator);
|
|
78
|
-
if (failure !== null)
|
|
79
|
-
return failure;
|
|
80
|
-
const frame = partFrame(answered.body);
|
|
81
|
-
if (frame === null)
|
|
82
|
-
continue;
|
|
83
|
-
const scope = await housePart(continued.room, frame, listed, 'credential');
|
|
84
|
-
if (scope !== null)
|
|
85
|
-
return 'kind' in scope ? scope : { scope, frame };
|
|
86
|
-
}
|
|
87
|
-
return unverifiedPart(entry.locator);
|
|
66
|
+
function opened(frame) {
|
|
67
|
+
const document = parseDiscovery(frame);
|
|
68
|
+
if (document === null)
|
|
69
|
+
return null;
|
|
70
|
+
bounds = document.bounds;
|
|
71
|
+
tracked.clear();
|
|
72
|
+
for (const entry of trackedFrom(document))
|
|
73
|
+
tracked.set(entry.locator, entry);
|
|
74
|
+
notifications.track([...tracked.values()]);
|
|
75
|
+
return {
|
|
76
|
+
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
77
|
+
member: document.member,
|
|
78
|
+
};
|
|
88
79
|
}
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
80
|
+
function changed(frame) {
|
|
81
|
+
const change = parseAuthorityChange(frame);
|
|
82
|
+
if (change === null)
|
|
83
|
+
return null;
|
|
84
|
+
for (const locator of change.left)
|
|
85
|
+
tracked.delete(locator);
|
|
86
|
+
for (const entry of trackedFrom(change))
|
|
87
|
+
tracked.set(entry.locator, entry);
|
|
88
|
+
notifications.track([...tracked.values()]);
|
|
89
|
+
return {
|
|
90
|
+
kind: 'authority-changed',
|
|
91
|
+
rooms: change.authorities.map((authority) => discoveredRoom(authority)),
|
|
92
|
+
left: change.left,
|
|
93
|
+
member: change.member,
|
|
94
|
+
};
|
|
97
95
|
}
|
|
98
|
-
async function
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
: await fetchedPart(entry, continued, listed, received, arriving);
|
|
104
|
-
if ('kind' in sent)
|
|
105
|
-
return sent;
|
|
106
|
-
const scope = await reused(sent.scope, asked.held);
|
|
96
|
+
async function streamedPage(entry, token, held) {
|
|
97
|
+
const part = await rooms.part(entry, token);
|
|
98
|
+
if ('kind' in part)
|
|
99
|
+
return part;
|
|
100
|
+
const scope = await reused(part.scope, held);
|
|
107
101
|
if (scope === null) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
: bootstrapTogether({ entry, held: undefined });
|
|
102
|
+
unreused.add(entry.locator);
|
|
103
|
+
return UNCERTAIN_READ;
|
|
111
104
|
}
|
|
112
|
-
const next = continued.next + 1;
|
|
113
|
-
const more = next < continued.room.parts.length;
|
|
114
|
-
if (continued.next === 0 && !more)
|
|
115
|
-
handed.set(entry.locator, roomVersion(scope));
|
|
116
|
-
else
|
|
117
|
-
handed.delete(entry.locator);
|
|
118
|
-
notifications.reach(entry.authority, scope);
|
|
119
|
-
const seen = [
|
|
120
|
-
...continued.seen,
|
|
121
|
-
...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
|
|
122
|
-
];
|
|
123
|
-
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
124
105
|
return {
|
|
125
106
|
...(await stepped(bootstrapping(scope))),
|
|
126
|
-
...(models === undefined ? {} : { models }),
|
|
127
|
-
...(
|
|
128
|
-
|
|
107
|
+
...(part.models === undefined ? {} : { models: part.models }),
|
|
108
|
+
...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
|
|
109
|
+
bytes: part.bytes,
|
|
129
110
|
};
|
|
130
111
|
}
|
|
131
|
-
async function
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
...presented(ask.entry.authority, { position: page.after, logEpoch: ask.from.logEpoch }),
|
|
137
|
-
page: { through: page.through, read: page.read },
|
|
138
|
-
},
|
|
139
|
-
],
|
|
140
|
-
});
|
|
141
|
-
const failure = classifyRead(answer.status, answer.body, ask.entry.locator);
|
|
142
|
-
if (failure !== null)
|
|
143
|
-
return failure;
|
|
144
|
-
const enumeration = parseEnumeration(answer.body, 'credential');
|
|
145
|
-
if (enumeration === null)
|
|
146
|
-
return UNCERTAIN_READ;
|
|
147
|
-
return (viewOf(enumeration, ask.entry) ?? { kind: 'room-not-readable', locator: ask.entry.locator });
|
|
148
|
-
}
|
|
149
|
-
async function enumeratedRoom(enumeration, ask) {
|
|
150
|
-
const first = viewOf(enumeration, ask.entry);
|
|
151
|
-
if (first === undefined)
|
|
152
|
-
return { kind: 'room-not-readable', locator: ask.entry.locator };
|
|
153
|
-
const view = await wholeView(first, (page) => enumeratedPage(ask, page));
|
|
154
|
-
if ('kind' in view)
|
|
155
|
-
return view;
|
|
156
|
-
notifications.reach(ask.entry.authority, view);
|
|
157
|
-
const answer = await refreshFrom(view, ask.fromRoomVersion);
|
|
158
|
-
if (answer.kind !== 'net-advancement')
|
|
159
|
-
return answer;
|
|
160
|
-
handed.set(ask.entry.locator, roomVersion(view));
|
|
161
|
-
const models = await viewModels(view, ask.entry);
|
|
162
|
-
return models === undefined ? answer : { ...answer, models };
|
|
112
|
+
async function namedDocument(entry, path, signal) {
|
|
113
|
+
const answered = await transport.streamed(houseDoorRoute('bootstrap'), { room_ref: entry.authority, prefixes: [`${authorityRoot(entry.handle)}/${path}`] }, signal ?? new AbortController().signal);
|
|
114
|
+
if (answered.room === null)
|
|
115
|
+
return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN_READ;
|
|
116
|
+
return rooms.named(entry, answered.room, signal);
|
|
163
117
|
}
|
|
164
|
-
async function
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
:
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return
|
|
118
|
+
async function openedRoom(entry, request) {
|
|
119
|
+
const reusing = unreused.delete(entry.locator) ? undefined : request.held;
|
|
120
|
+
const files = reusing === undefined
|
|
121
|
+
? null
|
|
122
|
+
: await heldFiles(entry.authority, reusing, declared().max_held_files);
|
|
123
|
+
const answered = await transport.streamed(houseDoorRoute('bootstrap'), {
|
|
124
|
+
room_ref: entry.authority,
|
|
125
|
+
prefixes: [authorityRoot(entry.handle)],
|
|
126
|
+
...(files === null ? {} : { held: [files] }),
|
|
127
|
+
}, request.signal ?? new AbortController().signal);
|
|
128
|
+
if (answered.room === null)
|
|
129
|
+
return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN_READ;
|
|
130
|
+
return rooms.head(entry, answered.room, request.arriving, request.signal);
|
|
177
131
|
}
|
|
178
132
|
function held(rooms) {
|
|
179
|
-
|
|
133
|
+
notifications.send(rooms.flatMap((room) => {
|
|
180
134
|
const entry = tracked.get(room.locator);
|
|
181
135
|
const at = logPosition(room.roomVersion);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
handed.set(room.locator, room.roomVersion);
|
|
185
|
-
notifications.reach(entry.authority, at);
|
|
186
|
-
return [presented(entry.authority, at)];
|
|
187
|
-
});
|
|
188
|
-
notifications.send(kept);
|
|
189
|
-
}
|
|
190
|
-
async function adoptedMove(entry, into, outcome) {
|
|
191
|
-
if (outcome.kind === 'accepted' && outcome.destination !== undefined) {
|
|
192
|
-
await adopted(into, { kind: 'accepted', ...outcome.destination });
|
|
193
|
-
}
|
|
194
|
-
return adopted(entry, outcome);
|
|
195
|
-
}
|
|
196
|
-
async function adopted(entry, outcome) {
|
|
197
|
-
if (outcome.kind !== 'accepted')
|
|
198
|
-
return outcome;
|
|
199
|
-
const held = handed.get(entry.locator);
|
|
200
|
-
if (held === undefined)
|
|
201
|
-
return outcome;
|
|
202
|
-
const follows = followsVersion(held, outcome.roomVersion);
|
|
203
|
-
if (follows)
|
|
204
|
-
handed.set(entry.locator, outcome.roomVersion);
|
|
205
|
-
const at = logPosition(outcome.roomVersion);
|
|
206
|
-
if (follows && at !== null)
|
|
207
|
-
notifications.reach(entry.authority, at);
|
|
208
|
-
return outcome;
|
|
136
|
+
return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
|
|
137
|
+
}));
|
|
209
138
|
}
|
|
210
139
|
function authorityFor(locator) {
|
|
211
140
|
return tracked.get(locator);
|
|
@@ -224,116 +153,18 @@ export function createAgentsHouseAdapter(options) {
|
|
|
224
153
|
return result;
|
|
225
154
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
226
155
|
}
|
|
227
|
-
async function holding(asks) {
|
|
228
|
-
const bound = Math.floor(declared().max_held_files / Math.max(1, asks.filter((ask) => ask.held !== undefined).length));
|
|
229
|
-
const held = [];
|
|
230
|
-
for (const ask of asks) {
|
|
231
|
-
if (ask.held === undefined || bound === 0)
|
|
232
|
-
continue;
|
|
233
|
-
const files = await heldFiles(ask.entry.authority, ask.held, bound);
|
|
234
|
-
if (files !== null)
|
|
235
|
-
held.push(files);
|
|
236
|
-
}
|
|
237
|
-
return held;
|
|
238
|
-
}
|
|
239
|
-
async function bootstrapped(asks, answer) {
|
|
240
|
-
let open = asks.map((asked, ask) => ({ entry: asked.entry, asked, ask }));
|
|
241
|
-
while (open.length > 0) {
|
|
242
|
-
const unreached = [];
|
|
243
|
-
for (const part of selections(open, declared().max_prefixes)) {
|
|
244
|
-
const held = await holding(part.map(({ asked }) => asked));
|
|
245
|
-
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
246
|
-
prefixes: part.map(({ entry }) => authorityRoot(entry.handle)),
|
|
247
|
-
...(held.length === 0 ? {} : { held }),
|
|
248
|
-
});
|
|
249
|
-
const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
|
|
250
|
-
const parted = classified[0] === null ? parseParted(answered.body) : null;
|
|
251
|
-
for (const [index, asked] of part.entries()) {
|
|
252
|
-
const failure = classified[index];
|
|
253
|
-
if (failure !== null && failure !== undefined) {
|
|
254
|
-
answer(asked.ask, failure);
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
if (parted === null) {
|
|
258
|
-
answer(asked.ask, UNCERTAIN_READ);
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
const room = parted.rooms.find((candidate) => candidate.anchor === asked.entry.authority);
|
|
262
|
-
if (room === undefined && parted.next !== undefined) {
|
|
263
|
-
unreached.push(asked);
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
if (room === undefined) {
|
|
267
|
-
answer(asked.ask, { kind: 'room-not-readable', locator: asked.entry.locator });
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
const kept = held.find((files) => files.room === asked.entry.authority);
|
|
271
|
-
answer(asked.ask, await manifestPage(asked.asked, {
|
|
272
|
-
room,
|
|
273
|
-
next: 0,
|
|
274
|
-
seen: [],
|
|
275
|
-
...(kept === undefined ? {} : { held: kept }),
|
|
276
|
-
}));
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
open = unreached;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
function layered(asks) {
|
|
283
|
-
const depths = new Map();
|
|
284
|
-
const layers = [];
|
|
285
|
-
for (const ask of asks) {
|
|
286
|
-
const depth = depths.get(ask.ask.entry.authority) ?? 0;
|
|
287
|
-
depths.set(ask.ask.entry.authority, depth + 1);
|
|
288
|
-
(layers[depth] ??= []).push(ask);
|
|
289
|
-
}
|
|
290
|
-
return layers;
|
|
291
|
-
}
|
|
292
|
-
async function enumerated(asks) {
|
|
293
|
-
const answers = [];
|
|
294
|
-
const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer, declared().max_prefixes));
|
|
295
|
-
for (const part of parts) {
|
|
296
|
-
let open = [...part];
|
|
297
|
-
while (open.length > 0) {
|
|
298
|
-
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
299
|
-
prefixes: open.map(({ ask }) => authorityRoot(ask.entry.handle)),
|
|
300
|
-
positions: open.map(({ ask }) => presented(ask.entry.authority, ask.from)),
|
|
301
|
-
});
|
|
302
|
-
const classified = open.map(({ ask }) => classifyRead(answer.status, answer.body, ask.entry.locator));
|
|
303
|
-
if (classified[0]?.kind === 'beyond-horizon') {
|
|
304
|
-
const named = doorRefusal(answer.body)?.fields.authority;
|
|
305
|
-
const expired = open.filter(({ ask }) => ask.entry.authority === named);
|
|
306
|
-
const answered = expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };
|
|
307
|
-
const gone = expired.length === 0 ? open : expired;
|
|
308
|
-
for (const ask of gone)
|
|
309
|
-
answers[ask.index] = answered;
|
|
310
|
-
open = open.filter((ask) => !gone.includes(ask));
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
|
|
314
|
-
for (const [answerIndex, { ask, index }] of open.entries()) {
|
|
315
|
-
const failure = classified[answerIndex];
|
|
316
|
-
if (failure !== null && failure !== undefined) {
|
|
317
|
-
answers[index] = failure;
|
|
318
|
-
continue;
|
|
319
|
-
}
|
|
320
|
-
answers[index] =
|
|
321
|
-
enumeration === null ? UNCERTAIN_READ : await enumeratedRoom(enumeration, ask);
|
|
322
|
-
}
|
|
323
|
-
open = [];
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return answers;
|
|
327
|
-
}
|
|
328
|
-
const bootstrapTogether = gatheredEach(bootstrapped);
|
|
329
|
-
const enumerateTogether = gathered(enumerated);
|
|
330
156
|
async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
|
|
331
157
|
const paths = batchPaths(changes);
|
|
332
158
|
const sha256 = await deltaDigest(delta);
|
|
333
159
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
334
160
|
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
335
161
|
}
|
|
336
|
-
const minted = await transport.door(
|
|
162
|
+
const minted = await transport.door(houseDoorRoute('batch-upload'), {
|
|
163
|
+
...head,
|
|
164
|
+
paths,
|
|
165
|
+
bytes,
|
|
166
|
+
sha256,
|
|
167
|
+
});
|
|
337
168
|
if (minted.status !== 200) {
|
|
338
169
|
return {
|
|
339
170
|
outcome: await stepped(mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)),
|
|
@@ -381,11 +212,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
381
212
|
: { body: inline };
|
|
382
213
|
if ('outcome' in prepared)
|
|
383
214
|
return prepared.outcome;
|
|
384
|
-
const answer = await transport.door(
|
|
215
|
+
const answer = await transport.door(houseDoorRoute('batch'), prepared.body);
|
|
385
216
|
const stagedFiles = await staged(answer, request);
|
|
386
217
|
if (stagedFiles === false)
|
|
387
218
|
return UNCERTAIN;
|
|
388
|
-
const settled = stagedFiles === null ? answer : await transport.door(
|
|
219
|
+
const settled = stagedFiles === null ? answer : await transport.door(houseDoorRoute('batch'), prepared.body);
|
|
389
220
|
if (stagedFiles === true && (await staged(settled, request)) !== null)
|
|
390
221
|
return UNCERTAIN;
|
|
391
222
|
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
@@ -453,7 +284,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
453
284
|
const entry = authorityFor(request.locator);
|
|
454
285
|
if (entry === undefined)
|
|
455
286
|
return null;
|
|
456
|
-
return () => transport.door(
|
|
287
|
+
return () => transport.door(houseDoorRoute('files/get'), {
|
|
457
288
|
room_ref: entry.authority,
|
|
458
289
|
path: request.path,
|
|
459
290
|
revision: request.revision,
|
|
@@ -465,69 +296,15 @@ export function createAgentsHouseAdapter(options) {
|
|
|
465
296
|
async authorize() {
|
|
466
297
|
return options.authorize();
|
|
467
298
|
},
|
|
468
|
-
async discover(_authorization, scope) {
|
|
469
|
-
const answer = await transport.door(DOOR_DISCOVER, {
|
|
470
|
-
prefixes: [...DISCOVER_PREFIXES],
|
|
471
|
-
...(scope === undefined ? {} : { rooms: scope.authorities }),
|
|
472
|
-
});
|
|
473
|
-
const failed = discoveryFailure(answer.status, answer.body);
|
|
474
|
-
if (failed !== null)
|
|
475
|
-
return failed;
|
|
476
|
-
const document = parseDiscovery(answer.body);
|
|
477
|
-
if (document === null)
|
|
478
|
-
return { kind: 'transport-uncertainty' };
|
|
479
|
-
bounds = document.bounds;
|
|
480
|
-
const entries = trackedFrom(document);
|
|
481
|
-
const covered = scope === undefined
|
|
482
|
-
? null
|
|
483
|
-
: [
|
|
484
|
-
...new Set([
|
|
485
|
-
...[...tracked.values()]
|
|
486
|
-
.filter((entry) => scope.authorities.includes(entry.authority))
|
|
487
|
-
.map((entry) => entry.locator),
|
|
488
|
-
...entries.map((entry) => entry.locator),
|
|
489
|
-
]),
|
|
490
|
-
];
|
|
491
|
-
if (covered === null)
|
|
492
|
-
tracked.clear();
|
|
493
|
-
else
|
|
494
|
-
for (const locator of covered)
|
|
495
|
-
tracked.delete(locator);
|
|
496
|
-
for (const entry of entries)
|
|
497
|
-
tracked.set(entry.locator, entry);
|
|
498
|
-
for (const locator of handed.keys())
|
|
499
|
-
if (!tracked.has(locator))
|
|
500
|
-
handed.delete(locator);
|
|
501
|
-
notifications.track([...tracked.values()]);
|
|
502
|
-
return {
|
|
503
|
-
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions, [...tracked.values()])),
|
|
504
|
-
member: document.member,
|
|
505
|
-
...(covered === null ? {} : { covered }),
|
|
506
|
-
};
|
|
507
|
-
},
|
|
508
299
|
async bootstrap(_authorization, request) {
|
|
509
300
|
const entry = authorityFor(request.locator);
|
|
510
301
|
if (entry === undefined)
|
|
511
302
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
},
|
|
518
|
-
async refresh(_authorization, request) {
|
|
519
|
-
const entry = authorityFor(request.locator);
|
|
520
|
-
if (entry === undefined)
|
|
521
|
-
return { kind: 'room-not-readable', locator: request.locator };
|
|
522
|
-
if (request.pageToken !== undefined)
|
|
523
|
-
return { kind: 'transport-uncertainty' };
|
|
524
|
-
const from = logPosition(request.fromRoomVersion);
|
|
525
|
-
if (from === null)
|
|
526
|
-
return { kind: 'beyond-horizon' };
|
|
527
|
-
const answered = await streamed(entry, request, from);
|
|
528
|
-
if (answered !== null)
|
|
529
|
-
return answered;
|
|
530
|
-
return enumerateTogether({ entry, from, fromRoomVersion: request.fromRoomVersion });
|
|
303
|
+
if (request.path !== undefined)
|
|
304
|
+
return namedDocument(entry, request.path, request.signal);
|
|
305
|
+
return request.pageToken === undefined
|
|
306
|
+
? openedRoom(entry, request)
|
|
307
|
+
: streamedPage(entry, request.pageToken, request.held);
|
|
531
308
|
},
|
|
532
309
|
async mutate(_authorization, request, keep) {
|
|
533
310
|
const entry = authorityFor(request.locator);
|
|
@@ -544,22 +321,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
544
321
|
: houseMove(batch, entry.handle, into.handle);
|
|
545
322
|
if (mapped.kind === 'unmapped')
|
|
546
323
|
return rejectedMapping(mapped);
|
|
547
|
-
const head = operationHead(batch);
|
|
324
|
+
const head = operationHead(batch, entry.authority);
|
|
548
325
|
const delta = deltaBody(mapped.changes);
|
|
549
326
|
const bytes = deltaBytes(delta);
|
|
550
327
|
const handed = request.upload;
|
|
551
328
|
const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
|
|
552
|
-
const settle = (outcome) => into === undefined ? adopted(entry, outcome) : adoptedMove(entry, into, outcome);
|
|
553
329
|
const outcome = await answer(handed);
|
|
554
330
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
555
|
-
return
|
|
556
|
-
return
|
|
331
|
+
return outcome;
|
|
332
|
+
return answer(undefined);
|
|
557
333
|
},
|
|
558
334
|
async history(_authorization, request) {
|
|
559
335
|
const entry = authorityFor(request.locator);
|
|
560
336
|
if (entry === undefined)
|
|
561
337
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
562
|
-
const answer = await transport.door(
|
|
338
|
+
const answer = await transport.door(houseDoorRoute('revisions'), revisionBody({
|
|
563
339
|
path: request.path,
|
|
564
340
|
handle: entry.handle,
|
|
565
341
|
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
@@ -586,7 +362,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
586
362
|
const entry = authorityFor(request.locator);
|
|
587
363
|
if (entry === undefined)
|
|
588
364
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
589
|
-
const declared = await transport.door(
|
|
365
|
+
const declared = await transport.door(houseDoorRoute('files/attach'), {
|
|
590
366
|
room_ref: entry.authority,
|
|
591
367
|
name: request.name,
|
|
592
368
|
bytes: request.byteLength,
|
|
@@ -620,18 +396,12 @@ export function createAgentsHouseAdapter(options) {
|
|
|
620
396
|
async action(_authorization, request) {
|
|
621
397
|
return withAt(await houseAction(transport, request));
|
|
622
398
|
},
|
|
399
|
+
search(_authorization, request) {
|
|
400
|
+
return houseSearch(transport, [...tracked.values()], request);
|
|
401
|
+
},
|
|
623
402
|
roomStream: {
|
|
624
403
|
hold: held,
|
|
625
|
-
|
|
626
|
-
observe(notify, receipts, revisions) {
|
|
627
|
-
heldRevisions = revisions;
|
|
628
|
-
return notifications.observe(notify, receipts);
|
|
629
|
-
},
|
|
630
|
-
published(locator, roomVersion) {
|
|
631
|
-
const at = logPosition(roomVersion);
|
|
632
|
-
if (at !== null)
|
|
633
|
-
notifications.published(locator, at);
|
|
634
|
-
},
|
|
404
|
+
observe: notifications.observe,
|
|
635
405
|
},
|
|
636
406
|
conversations: notifications.conversations,
|
|
637
407
|
serviceMode: notifications.serviceMode,
|
package/dist/discovery.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Capability, DiscoveredRoom, Discovery, Member, ProviderLimit, Retention } from '@agentshouse/mdruntime';
|
|
2
2
|
import { type LogPosition } from './version.js';
|
|
3
3
|
export declare const PROVIDER_ACTIONS = "provider-actions";
|
|
4
|
-
export declare const DISCOVER_PREFIXES: readonly string[];
|
|
5
4
|
export type HouseBounds = {
|
|
6
5
|
max_authored_file_bytes: number;
|
|
7
6
|
max_batch_operations: number;
|
|
@@ -22,7 +21,7 @@ export type HouseOperations = {
|
|
|
22
21
|
write: readonly string[];
|
|
23
22
|
delete: readonly string[];
|
|
24
23
|
};
|
|
25
|
-
export type
|
|
24
|
+
export type HouseAccessLevel = 'search' | 'open' | 'keep';
|
|
26
25
|
export type HouseAuthority = LogPosition & {
|
|
27
26
|
roomRef: string;
|
|
28
27
|
roomHandle: string;
|
|
@@ -31,7 +30,7 @@ export type HouseAuthority = LogPosition & {
|
|
|
31
30
|
typedSelection: readonly string[] | null;
|
|
32
31
|
managedReplication: 'admitted' | 'unavailable';
|
|
33
32
|
protectedPaths: readonly string[];
|
|
34
|
-
|
|
33
|
+
level: HouseAccessLevel;
|
|
35
34
|
operations: HouseOperations;
|
|
36
35
|
};
|
|
37
36
|
export type HouseDiscoveryDocument = {
|
|
@@ -40,6 +39,11 @@ export type HouseDiscoveryDocument = {
|
|
|
40
39
|
authorities: readonly HouseAuthority[];
|
|
41
40
|
actions: readonly string[];
|
|
42
41
|
};
|
|
42
|
+
export type HouseAuthorityChange = {
|
|
43
|
+
member: Member;
|
|
44
|
+
authorities: readonly HouseAuthority[];
|
|
45
|
+
left: readonly string[];
|
|
46
|
+
};
|
|
43
47
|
export type TrackedAuthority = LogPosition & {
|
|
44
48
|
locator: string;
|
|
45
49
|
authority: string;
|
|
@@ -57,12 +61,13 @@ export type HouseSiteDiscovery = {
|
|
|
57
61
|
authorities: readonly HouseSiteAuthority[];
|
|
58
62
|
};
|
|
59
63
|
export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
|
|
64
|
+
export declare function parseAuthorityChange(body: unknown): HouseAuthorityChange | null;
|
|
60
65
|
export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
|
|
61
66
|
export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
|
|
62
|
-
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
67
|
+
export declare function trackedFrom(document: Pick<HouseDiscoveryDocument, 'authorities'>): TrackedAuthority[];
|
|
63
68
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
64
69
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
65
|
-
export declare function capabilities(actions: HouseDiscoveryDocument['actions']
|
|
70
|
+
export declare function capabilities(actions: HouseDiscoveryDocument['actions']): readonly Capability[];
|
|
66
71
|
export declare function siteCapabilities(): readonly Capability[];
|
|
67
72
|
export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
|
|
68
73
|
export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
|
package/dist/discovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,MAAM,EACN,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,MAAM,EACN,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,MAAM,MAAM,WAAW,GAAG;IACxB,uBAAuB,EAAE,MAAM,CAAC;IAChC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,wBAAwB,EAAE,MAAM,CAAC;IACjC,2BAA2B,EAAE,MAAM,CAAC;IACpC,kBAAkB,CAAC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