@agentshouse/mdruntime-adapter 0.1.0-c7c9c23528dbf → 0.1.0-c7ccdcd8a539c
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/README.md +2 -2
- package/dist/actions.d.ts +3 -58
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +1 -287
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +128 -327
- package/dist/discovery.d.ts +12 -12
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +44 -51
- package/dist/history.d.ts +12 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +91 -0
- package/dist/house-model.d.ts +955 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +521 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/model.d.ts +2 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +4 -30
- 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 +4 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +73 -158
- package/dist/stream.d.ts +13 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +160 -423
- package/dist/transport.d.ts +45 -35
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +53 -11
- 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 +13 -6
- package/package.json +2 -3
- package/AGENTS.md +0 -312
- 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,21 +1,20 @@
|
|
|
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 { classifyDoor,
|
|
12
|
-
import { houseNotifications } from './stream.js';
|
|
13
|
-
import {
|
|
9
|
+
import { classifyDoor, doorRefusal } from './refusal.js';
|
|
10
|
+
import { houseNotifications, } from './stream.js';
|
|
11
|
+
import { houseDoorRoute, } from './transport.js';
|
|
14
12
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
15
13
|
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
16
|
-
import { followsVersion, logPosition, presented, reachedVersion, roomVersion
|
|
14
|
+
import { followsVersion, logPosition, presented, reachedVersion, roomVersion } from './version.js';
|
|
17
15
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
18
16
|
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
17
|
+
const OCTET_STREAM = 'application/octet-stream';
|
|
19
18
|
const EXPIRED_ADDRESS = 403;
|
|
20
19
|
function lapsedGrant(outcome) {
|
|
21
20
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
@@ -50,161 +49,85 @@ export function createAgentsHouseAdapter(options) {
|
|
|
50
49
|
if ('site' in options)
|
|
51
50
|
return createSiteAdapter(options.site, options.snapshot === true);
|
|
52
51
|
const transport = options.transport;
|
|
53
|
-
const notifications = houseNotifications(transport, 'credential'
|
|
52
|
+
const notifications = houseNotifications(transport, 'credential', {
|
|
53
|
+
opened: async (frame) => (frame === null ? null : opened(frame)),
|
|
54
|
+
changed,
|
|
55
|
+
});
|
|
54
56
|
const tracked = new Map();
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
+
const rooms = roomStreams('credential');
|
|
58
|
+
const unreused = new Set();
|
|
57
59
|
let bounds;
|
|
58
60
|
function declared() {
|
|
59
61
|
if (bounds === undefined)
|
|
60
62
|
throw new Error('no Discovery declared the bounds');
|
|
61
63
|
return bounds;
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const failure = classifyRead(answered.status, answered.body, entry.locator);
|
|
77
|
-
if (failure !== null)
|
|
78
|
-
return failure;
|
|
79
|
-
const frame = partFrame(answered.body);
|
|
80
|
-
if (frame === null)
|
|
81
|
-
continue;
|
|
82
|
-
const scope = await housePart(continued.room, frame, listed, 'credential');
|
|
83
|
-
if (scope !== null)
|
|
84
|
-
return 'kind' in scope ? scope : { scope, frame };
|
|
85
|
-
}
|
|
86
|
-
return unverifiedPart(entry.locator);
|
|
65
|
+
function opened(frame) {
|
|
66
|
+
const document = parseDiscovery(frame);
|
|
67
|
+
if (document === null)
|
|
68
|
+
return null;
|
|
69
|
+
bounds = document.bounds;
|
|
70
|
+
tracked.clear();
|
|
71
|
+
for (const entry of trackedFrom(document))
|
|
72
|
+
tracked.set(entry.locator, entry);
|
|
73
|
+
notifications.track([...tracked.values()]);
|
|
74
|
+
return {
|
|
75
|
+
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
76
|
+
member: document.member,
|
|
77
|
+
};
|
|
87
78
|
}
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
79
|
+
function changed(frame) {
|
|
80
|
+
const change = parseAuthorityChange(frame);
|
|
81
|
+
if (change === null)
|
|
82
|
+
return null;
|
|
83
|
+
for (const locator of change.left)
|
|
84
|
+
tracked.delete(locator);
|
|
85
|
+
for (const entry of trackedFrom(change))
|
|
86
|
+
tracked.set(entry.locator, entry);
|
|
87
|
+
notifications.track([...tracked.values()]);
|
|
88
|
+
return {
|
|
89
|
+
kind: 'authority-changed',
|
|
90
|
+
rooms: change.authorities.map((authority) => discoveredRoom(authority)),
|
|
91
|
+
left: change.left,
|
|
92
|
+
member: change.member,
|
|
93
|
+
};
|
|
96
94
|
}
|
|
97
|
-
async function
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
: await fetchedPart(entry, continued, listed, received, arriving);
|
|
103
|
-
if ('kind' in sent)
|
|
104
|
-
return sent;
|
|
105
|
-
const scope = await reused(sent.scope, asked.held);
|
|
95
|
+
async function streamedPage(entry, token, held) {
|
|
96
|
+
const part = await rooms.part(entry, token);
|
|
97
|
+
if ('kind' in part)
|
|
98
|
+
return part;
|
|
99
|
+
const scope = await reused(part.scope, held);
|
|
106
100
|
if (scope === null) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
: bootstrapTogether({ entry, held: undefined });
|
|
101
|
+
unreused.add(entry.locator);
|
|
102
|
+
return UNCERTAIN_READ;
|
|
110
103
|
}
|
|
111
|
-
const next = continued.next + 1;
|
|
112
|
-
const more = next < continued.room.parts.length;
|
|
113
|
-
if (continued.next === 0 && !more)
|
|
114
|
-
handed.set(entry.locator, roomVersion(scope));
|
|
115
|
-
else
|
|
116
|
-
handed.delete(entry.locator);
|
|
117
|
-
notifications.reach(entry.authority, scope);
|
|
118
|
-
const seen = [
|
|
119
|
-
...continued.seen,
|
|
120
|
-
...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
|
|
121
|
-
];
|
|
122
|
-
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
123
104
|
return {
|
|
124
105
|
...(await stepped(bootstrapping(scope))),
|
|
125
|
-
...(models === undefined ? {} : { models }),
|
|
126
|
-
...(
|
|
127
|
-
|
|
106
|
+
...(part.models === undefined ? {} : { models: part.models }),
|
|
107
|
+
...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
|
|
108
|
+
bytes: part.bytes,
|
|
128
109
|
};
|
|
129
110
|
}
|
|
130
|
-
async function
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
],
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const enumeration = parseEnumeration(answer.body, 'credential');
|
|
144
|
-
if (enumeration === null)
|
|
145
|
-
return UNCERTAIN_READ;
|
|
146
|
-
return (viewOf(enumeration, ask.entry) ?? { kind: 'room-not-readable', locator: ask.entry.locator });
|
|
147
|
-
}
|
|
148
|
-
async function enumeratedRoom(enumeration, ask) {
|
|
149
|
-
const first = viewOf(enumeration, ask.entry);
|
|
150
|
-
if (first === undefined)
|
|
151
|
-
return { kind: 'room-not-readable', locator: ask.entry.locator };
|
|
152
|
-
const view = await wholeView(first, (page) => enumeratedPage(ask, page));
|
|
153
|
-
if ('kind' in view)
|
|
154
|
-
return view;
|
|
155
|
-
notifications.reach(ask.entry.authority, view);
|
|
156
|
-
const answer = await refreshFrom(view, ask.fromRoomVersion);
|
|
157
|
-
if (answer.kind !== 'net-advancement')
|
|
158
|
-
return answer;
|
|
159
|
-
handed.set(ask.entry.locator, roomVersion(view));
|
|
160
|
-
const models = await viewModels(view, ask.entry);
|
|
161
|
-
return models === undefined ? answer : { ...answer, models };
|
|
162
|
-
}
|
|
163
|
-
async function streamed(entry, request, from) {
|
|
164
|
-
if (handed.get(entry.locator) !== request.fromRoomVersion)
|
|
165
|
-
return null;
|
|
166
|
-
const asked = notifications.edited(entry, from);
|
|
167
|
-
const kept = asked.length === 0 || heldRevisions === undefined
|
|
168
|
-
? new Map()
|
|
169
|
-
: await heldRevisions(entry.locator, asked);
|
|
170
|
-
const advanced = await stepped(notifications.advance(entry, from, (path, revision) => kept.get(path) === revision));
|
|
171
|
-
if (advanced === null)
|
|
172
|
-
return null;
|
|
173
|
-
handed.set(entry.locator, advanced.page.roomVersion);
|
|
174
|
-
const models = await streamedModels(advanced.schemas, entry, 'credential');
|
|
175
|
-
return models === undefined ? advanced.page : { ...advanced.page, models };
|
|
111
|
+
async function openedRoom(entry, request) {
|
|
112
|
+
const reusing = unreused.delete(entry.locator) ? undefined : request.held;
|
|
113
|
+
const files = reusing === undefined
|
|
114
|
+
? null
|
|
115
|
+
: await heldFiles(entry.authority, reusing, declared().max_held_files);
|
|
116
|
+
const answered = await transport.streamed(houseDoorRoute('bootstrap'), {
|
|
117
|
+
room_ref: entry.authority,
|
|
118
|
+
prefixes: [authorityRoot(entry.handle)],
|
|
119
|
+
...(files === null ? {} : { held: [files] }),
|
|
120
|
+
}, request.signal ?? new AbortController().signal);
|
|
121
|
+
if (answered.room === null)
|
|
122
|
+
return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN_READ;
|
|
123
|
+
return rooms.head(entry, answered.room, request.arriving, request.signal);
|
|
176
124
|
}
|
|
177
125
|
function held(rooms) {
|
|
178
|
-
|
|
126
|
+
notifications.send(rooms.flatMap((room) => {
|
|
179
127
|
const entry = tracked.get(room.locator);
|
|
180
128
|
const at = logPosition(room.roomVersion);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
handed.set(room.locator, room.roomVersion);
|
|
184
|
-
notifications.reach(entry.authority, at);
|
|
185
|
-
return [presented(entry.authority, at)];
|
|
186
|
-
});
|
|
187
|
-
notifications.send(kept);
|
|
188
|
-
}
|
|
189
|
-
async function adoptedMove(entry, into, outcome) {
|
|
190
|
-
if (outcome.kind === 'accepted' && outcome.destination !== undefined) {
|
|
191
|
-
await adopted(into, { kind: 'accepted', ...outcome.destination });
|
|
192
|
-
}
|
|
193
|
-
return adopted(entry, outcome);
|
|
194
|
-
}
|
|
195
|
-
async function adopted(entry, outcome) {
|
|
196
|
-
if (outcome.kind !== 'accepted')
|
|
197
|
-
return outcome;
|
|
198
|
-
const held = handed.get(entry.locator);
|
|
199
|
-
if (held === undefined)
|
|
200
|
-
return outcome;
|
|
201
|
-
const follows = followsVersion(held, outcome.roomVersion);
|
|
202
|
-
if (follows)
|
|
203
|
-
handed.set(entry.locator, outcome.roomVersion);
|
|
204
|
-
const at = logPosition(outcome.roomVersion);
|
|
205
|
-
if (follows && at !== null)
|
|
206
|
-
notifications.reach(entry.authority, at);
|
|
207
|
-
return outcome;
|
|
129
|
+
return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
|
|
130
|
+
}));
|
|
208
131
|
}
|
|
209
132
|
function authorityFor(locator) {
|
|
210
133
|
return tracked.get(locator);
|
|
@@ -223,116 +146,18 @@ export function createAgentsHouseAdapter(options) {
|
|
|
223
146
|
return result;
|
|
224
147
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
225
148
|
}
|
|
226
|
-
async function holding(asks) {
|
|
227
|
-
const bound = Math.floor(declared().max_held_files / Math.max(1, asks.filter((ask) => ask.held !== undefined).length));
|
|
228
|
-
const held = [];
|
|
229
|
-
for (const ask of asks) {
|
|
230
|
-
if (ask.held === undefined || bound === 0)
|
|
231
|
-
continue;
|
|
232
|
-
const files = await heldFiles(ask.entry.authority, ask.held, bound);
|
|
233
|
-
if (files !== null)
|
|
234
|
-
held.push(files);
|
|
235
|
-
}
|
|
236
|
-
return held;
|
|
237
|
-
}
|
|
238
|
-
async function bootstrapped(asks, answer) {
|
|
239
|
-
let open = asks.map((asked, ask) => ({ entry: asked.entry, asked, ask }));
|
|
240
|
-
while (open.length > 0) {
|
|
241
|
-
const unreached = [];
|
|
242
|
-
for (const part of selections(open, declared().max_prefixes)) {
|
|
243
|
-
const held = await holding(part.map(({ asked }) => asked));
|
|
244
|
-
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
245
|
-
prefixes: part.map(({ entry }) => authorityRoot(entry.handle)),
|
|
246
|
-
...(held.length === 0 ? {} : { held }),
|
|
247
|
-
});
|
|
248
|
-
const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
|
|
249
|
-
const parted = classified[0] === null ? parseParted(answered.body) : null;
|
|
250
|
-
for (const [index, asked] of part.entries()) {
|
|
251
|
-
const failure = classified[index];
|
|
252
|
-
if (failure !== null && failure !== undefined) {
|
|
253
|
-
answer(asked.ask, failure);
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
if (parted === null) {
|
|
257
|
-
answer(asked.ask, UNCERTAIN_READ);
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
const room = parted.rooms.find((candidate) => candidate.anchor === asked.entry.authority);
|
|
261
|
-
if (room === undefined && parted.next !== undefined) {
|
|
262
|
-
unreached.push(asked);
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
if (room === undefined) {
|
|
266
|
-
answer(asked.ask, { kind: 'room-not-readable', locator: asked.entry.locator });
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
const kept = held.find((files) => files.room === asked.entry.authority);
|
|
270
|
-
answer(asked.ask, await manifestPage(asked.asked, {
|
|
271
|
-
room,
|
|
272
|
-
next: 0,
|
|
273
|
-
seen: [],
|
|
274
|
-
...(kept === undefined ? {} : { held: kept }),
|
|
275
|
-
}));
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
open = unreached;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
function layered(asks) {
|
|
282
|
-
const depths = new Map();
|
|
283
|
-
const layers = [];
|
|
284
|
-
for (const ask of asks) {
|
|
285
|
-
const depth = depths.get(ask.ask.entry.authority) ?? 0;
|
|
286
|
-
depths.set(ask.ask.entry.authority, depth + 1);
|
|
287
|
-
(layers[depth] ??= []).push(ask);
|
|
288
|
-
}
|
|
289
|
-
return layers;
|
|
290
|
-
}
|
|
291
|
-
async function enumerated(asks) {
|
|
292
|
-
const answers = [];
|
|
293
|
-
const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer, declared().max_prefixes));
|
|
294
|
-
for (const part of parts) {
|
|
295
|
-
let open = [...part];
|
|
296
|
-
while (open.length > 0) {
|
|
297
|
-
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
298
|
-
prefixes: open.map(({ ask }) => authorityRoot(ask.entry.handle)),
|
|
299
|
-
positions: open.map(({ ask }) => presented(ask.entry.authority, ask.from)),
|
|
300
|
-
});
|
|
301
|
-
const classified = open.map(({ ask }) => classifyRead(answer.status, answer.body, ask.entry.locator));
|
|
302
|
-
if (classified[0]?.kind === 'beyond-horizon') {
|
|
303
|
-
const named = doorRefusal(answer.body)?.fields.authority;
|
|
304
|
-
const expired = open.filter(({ ask }) => ask.entry.authority === named);
|
|
305
|
-
const answered = expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };
|
|
306
|
-
const gone = expired.length === 0 ? open : expired;
|
|
307
|
-
for (const ask of gone)
|
|
308
|
-
answers[ask.index] = answered;
|
|
309
|
-
open = open.filter((ask) => !gone.includes(ask));
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
|
|
313
|
-
for (const [answerIndex, { ask, index }] of open.entries()) {
|
|
314
|
-
const failure = classified[answerIndex];
|
|
315
|
-
if (failure !== null && failure !== undefined) {
|
|
316
|
-
answers[index] = failure;
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
answers[index] =
|
|
320
|
-
enumeration === null ? UNCERTAIN_READ : await enumeratedRoom(enumeration, ask);
|
|
321
|
-
}
|
|
322
|
-
open = [];
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
return answers;
|
|
326
|
-
}
|
|
327
|
-
const bootstrapTogether = gatheredEach(bootstrapped);
|
|
328
|
-
const enumerateTogether = gathered(enumerated);
|
|
329
149
|
async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
|
|
330
150
|
const paths = batchPaths(changes);
|
|
331
151
|
const sha256 = await deltaDigest(delta);
|
|
332
152
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
333
153
|
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
334
154
|
}
|
|
335
|
-
const minted = await transport.door(
|
|
155
|
+
const minted = await transport.door(houseDoorRoute('batch-upload'), {
|
|
156
|
+
...head,
|
|
157
|
+
paths,
|
|
158
|
+
bytes,
|
|
159
|
+
sha256,
|
|
160
|
+
});
|
|
336
161
|
if (minted.status !== 200) {
|
|
337
162
|
return {
|
|
338
163
|
outcome: await stepped(mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)),
|
|
@@ -380,11 +205,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
380
205
|
: { body: inline };
|
|
381
206
|
if ('outcome' in prepared)
|
|
382
207
|
return prepared.outcome;
|
|
383
|
-
const answer = await transport.door(
|
|
208
|
+
const answer = await transport.door(houseDoorRoute('batch'), prepared.body);
|
|
384
209
|
const stagedFiles = await staged(answer, request);
|
|
385
210
|
if (stagedFiles === false)
|
|
386
211
|
return UNCERTAIN;
|
|
387
|
-
const settled = stagedFiles === null ? answer : await transport.door(
|
|
212
|
+
const settled = stagedFiles === null ? answer : await transport.door(houseDoorRoute('batch'), prepared.body);
|
|
388
213
|
if (stagedFiles === true && (await staged(settled, request)) !== null)
|
|
389
214
|
return UNCERTAIN;
|
|
390
215
|
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
@@ -412,9 +237,22 @@ export function createAgentsHouseAdapter(options) {
|
|
|
412
237
|
function linked(answer, locator) {
|
|
413
238
|
const address = addressed(answer, locator);
|
|
414
239
|
return address.kind === 'address'
|
|
415
|
-
? { kind: 'link', url: address.url, name: address.name }
|
|
240
|
+
? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
|
|
416
241
|
: address;
|
|
417
242
|
}
|
|
243
|
+
function refusedAttach(answer, locator) {
|
|
244
|
+
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
245
|
+
if (failure === null)
|
|
246
|
+
return null;
|
|
247
|
+
return failure.kind === 'scoped-refusal'
|
|
248
|
+
? {
|
|
249
|
+
kind: 'rejected',
|
|
250
|
+
code: failure.code,
|
|
251
|
+
fields: failure.fields,
|
|
252
|
+
retryable: failure.retryable,
|
|
253
|
+
}
|
|
254
|
+
: failure;
|
|
255
|
+
}
|
|
418
256
|
async function downloaded(ask, locator) {
|
|
419
257
|
let address = addressed(await ask(), locator);
|
|
420
258
|
if (address.kind !== 'address')
|
|
@@ -439,7 +277,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
439
277
|
const entry = authorityFor(request.locator);
|
|
440
278
|
if (entry === undefined)
|
|
441
279
|
return null;
|
|
442
|
-
return () => transport.door(
|
|
280
|
+
return () => transport.door(houseDoorRoute('files/get'), {
|
|
443
281
|
room_ref: entry.authority,
|
|
444
282
|
path: request.path,
|
|
445
283
|
revision: request.revision,
|
|
@@ -451,69 +289,13 @@ export function createAgentsHouseAdapter(options) {
|
|
|
451
289
|
async authorize() {
|
|
452
290
|
return options.authorize();
|
|
453
291
|
},
|
|
454
|
-
async discover(_authorization, scope) {
|
|
455
|
-
const answer = await transport.door(DOOR_DISCOVER, {
|
|
456
|
-
prefixes: [...DISCOVER_PREFIXES],
|
|
457
|
-
...(scope === undefined ? {} : { rooms: scope.authorities }),
|
|
458
|
-
});
|
|
459
|
-
const failed = discoveryFailure(answer.status, answer.body);
|
|
460
|
-
if (failed !== null)
|
|
461
|
-
return failed;
|
|
462
|
-
const document = parseDiscovery(answer.body);
|
|
463
|
-
if (document === null)
|
|
464
|
-
return { kind: 'transport-uncertainty' };
|
|
465
|
-
bounds = document.bounds;
|
|
466
|
-
const entries = trackedFrom(document);
|
|
467
|
-
const covered = scope === undefined
|
|
468
|
-
? null
|
|
469
|
-
: [
|
|
470
|
-
...new Set([
|
|
471
|
-
...[...tracked.values()]
|
|
472
|
-
.filter((entry) => scope.authorities.includes(entry.authority))
|
|
473
|
-
.map((entry) => entry.locator),
|
|
474
|
-
...entries.map((entry) => entry.locator),
|
|
475
|
-
]),
|
|
476
|
-
];
|
|
477
|
-
if (covered === null)
|
|
478
|
-
tracked.clear();
|
|
479
|
-
else
|
|
480
|
-
for (const locator of covered)
|
|
481
|
-
tracked.delete(locator);
|
|
482
|
-
for (const entry of entries)
|
|
483
|
-
tracked.set(entry.locator, entry);
|
|
484
|
-
for (const locator of handed.keys())
|
|
485
|
-
if (!tracked.has(locator))
|
|
486
|
-
handed.delete(locator);
|
|
487
|
-
notifications.track([...tracked.values()]);
|
|
488
|
-
return {
|
|
489
|
-
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions, [...tracked.values()])),
|
|
490
|
-
member: document.member,
|
|
491
|
-
...(covered === null ? {} : { covered }),
|
|
492
|
-
};
|
|
493
|
-
},
|
|
494
292
|
async bootstrap(_authorization, request) {
|
|
495
293
|
const entry = authorityFor(request.locator);
|
|
496
294
|
if (entry === undefined)
|
|
497
295
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
return bootstrapTogether(asked);
|
|
503
|
-
},
|
|
504
|
-
async refresh(_authorization, request) {
|
|
505
|
-
const entry = authorityFor(request.locator);
|
|
506
|
-
if (entry === undefined)
|
|
507
|
-
return { kind: 'room-not-readable', locator: request.locator };
|
|
508
|
-
if (request.pageToken !== undefined)
|
|
509
|
-
return { kind: 'transport-uncertainty' };
|
|
510
|
-
const from = logPosition(request.fromRoomVersion);
|
|
511
|
-
if (from === null)
|
|
512
|
-
return { kind: 'beyond-horizon' };
|
|
513
|
-
const answered = await streamed(entry, request, from);
|
|
514
|
-
if (answered !== null)
|
|
515
|
-
return answered;
|
|
516
|
-
return enumerateTogether({ entry, from, fromRoomVersion: request.fromRoomVersion });
|
|
296
|
+
return request.pageToken === undefined
|
|
297
|
+
? openedRoom(entry, request)
|
|
298
|
+
: streamedPage(entry, request.pageToken, request.held);
|
|
517
299
|
},
|
|
518
300
|
async mutate(_authorization, request, keep) {
|
|
519
301
|
const entry = authorityFor(request.locator);
|
|
@@ -530,22 +312,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
530
312
|
: houseMove(batch, entry.handle, into.handle);
|
|
531
313
|
if (mapped.kind === 'unmapped')
|
|
532
314
|
return rejectedMapping(mapped);
|
|
533
|
-
const head = operationHead(batch);
|
|
315
|
+
const head = operationHead(batch, entry.authority);
|
|
534
316
|
const delta = deltaBody(mapped.changes);
|
|
535
317
|
const bytes = deltaBytes(delta);
|
|
536
318
|
const handed = request.upload;
|
|
537
319
|
const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
|
|
538
|
-
const settle = (outcome) => into === undefined ? adopted(entry, outcome) : adoptedMove(entry, into, outcome);
|
|
539
320
|
const outcome = await answer(handed);
|
|
540
321
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
541
|
-
return
|
|
542
|
-
return
|
|
322
|
+
return outcome;
|
|
323
|
+
return answer(undefined);
|
|
543
324
|
},
|
|
544
325
|
async history(_authorization, request) {
|
|
545
326
|
const entry = authorityFor(request.locator);
|
|
546
327
|
if (entry === undefined)
|
|
547
328
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
548
|
-
const answer = await transport.door(
|
|
329
|
+
const answer = await transport.door(houseDoorRoute('revisions'), revisionBody({
|
|
549
330
|
path: request.path,
|
|
550
331
|
handle: entry.handle,
|
|
551
332
|
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
@@ -568,6 +349,35 @@ export function createAgentsHouseAdapter(options) {
|
|
|
568
349
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
569
350
|
return linked(await ask(), request.locator);
|
|
570
351
|
},
|
|
352
|
+
async attach(_authorization, request) {
|
|
353
|
+
const entry = authorityFor(request.locator);
|
|
354
|
+
if (entry === undefined)
|
|
355
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
356
|
+
const declared = await transport.door(houseDoorRoute('files/attach'), {
|
|
357
|
+
room_ref: entry.authority,
|
|
358
|
+
name: request.name,
|
|
359
|
+
bytes: request.byteLength,
|
|
360
|
+
sha256: request.sha256,
|
|
361
|
+
media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
|
|
362
|
+
});
|
|
363
|
+
const refused = refusedAttach(declared, request.locator);
|
|
364
|
+
if (refused !== null)
|
|
365
|
+
return refused;
|
|
366
|
+
const upload = houseUpload(declared.body?.upload);
|
|
367
|
+
if (upload === null)
|
|
368
|
+
return UNCERTAIN_READ;
|
|
369
|
+
const finished = await finishedUpload(transport, upload, request.blob);
|
|
370
|
+
if (finished === null)
|
|
371
|
+
return UNCERTAIN_READ;
|
|
372
|
+
const unfinished = refusedAttach(finished, request.locator);
|
|
373
|
+
if (unfinished !== null)
|
|
374
|
+
return unfinished;
|
|
375
|
+
const { path, revision } = (finished.body ?? {});
|
|
376
|
+
const root = `/rooms/${entry.handle}/`;
|
|
377
|
+
return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
|
|
378
|
+
? { kind: 'attached', path: path.slice(root.length), revision }
|
|
379
|
+
: UNCERTAIN_READ;
|
|
380
|
+
},
|
|
571
381
|
reached(locator, version, target) {
|
|
572
382
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
573
383
|
},
|
|
@@ -579,16 +389,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
579
389
|
},
|
|
580
390
|
roomStream: {
|
|
581
391
|
hold: held,
|
|
582
|
-
|
|
583
|
-
observe(notify, receipts, revisions) {
|
|
584
|
-
heldRevisions = revisions;
|
|
585
|
-
return notifications.observe(notify, receipts);
|
|
586
|
-
},
|
|
587
|
-
published(locator, roomVersion) {
|
|
588
|
-
const at = logPosition(roomVersion);
|
|
589
|
-
if (at !== null)
|
|
590
|
-
notifications.published(locator, at);
|
|
591
|
-
},
|
|
392
|
+
observe: notifications.observe,
|
|
592
393
|
},
|
|
593
394
|
conversations: notifications.conversations,
|
|
594
395
|
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,20 +21,16 @@ export type HouseOperations = {
|
|
|
22
21
|
write: readonly string[];
|
|
23
22
|
delete: readonly string[];
|
|
24
23
|
};
|
|
25
|
-
export type
|
|
26
|
-
export type HouseModel = {
|
|
27
|
-
root: string;
|
|
28
|
-
paths: readonly string[];
|
|
29
|
-
};
|
|
24
|
+
export type HouseAccessLevel = 'search' | 'open' | 'keep';
|
|
30
25
|
export type HouseAuthority = LogPosition & {
|
|
31
26
|
roomRef: string;
|
|
32
27
|
roomHandle: string;
|
|
33
28
|
name: string;
|
|
34
29
|
schema: string;
|
|
35
|
-
|
|
30
|
+
typedSelection: readonly string[] | null;
|
|
36
31
|
managedReplication: 'admitted' | 'unavailable';
|
|
37
32
|
protectedPaths: readonly string[];
|
|
38
|
-
|
|
33
|
+
level: HouseAccessLevel;
|
|
39
34
|
operations: HouseOperations;
|
|
40
35
|
};
|
|
41
36
|
export type HouseDiscoveryDocument = {
|
|
@@ -44,13 +39,17 @@ export type HouseDiscoveryDocument = {
|
|
|
44
39
|
authorities: readonly HouseAuthority[];
|
|
45
40
|
actions: readonly string[];
|
|
46
41
|
};
|
|
42
|
+
export type HouseAuthorityChange = {
|
|
43
|
+
member: Member;
|
|
44
|
+
authorities: readonly HouseAuthority[];
|
|
45
|
+
left: readonly string[];
|
|
46
|
+
};
|
|
47
47
|
export type TrackedAuthority = LogPosition & {
|
|
48
48
|
locator: string;
|
|
49
49
|
authority: string;
|
|
50
50
|
handle: string;
|
|
51
51
|
schema: string;
|
|
52
|
-
|
|
53
|
-
schemas: readonly string[];
|
|
52
|
+
typedSelection: readonly string[] | null;
|
|
54
53
|
};
|
|
55
54
|
export type HouseSiteAuthority = LogPosition & {
|
|
56
55
|
roomRef: string;
|
|
@@ -62,12 +61,13 @@ export type HouseSiteDiscovery = {
|
|
|
62
61
|
authorities: readonly HouseSiteAuthority[];
|
|
63
62
|
};
|
|
64
63
|
export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
|
|
64
|
+
export declare function parseAuthorityChange(body: unknown): HouseAuthorityChange | null;
|
|
65
65
|
export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
|
|
66
66
|
export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
|
|
67
|
-
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
67
|
+
export declare function trackedFrom(document: Pick<HouseDiscoveryDocument, 'authorities'>): TrackedAuthority[];
|
|
68
68
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
69
69
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
70
|
-
export declare function capabilities(actions: HouseDiscoveryDocument['actions']
|
|
70
|
+
export declare function capabilities(actions: HouseDiscoveryDocument['actions']): readonly Capability[];
|
|
71
71
|
export declare function siteCapabilities(): readonly Capability[];
|
|
72
72
|
export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
|
|
73
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,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