@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/adapter.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { stepped } from '@agentshouse/mdruntime';
|
|
2
2
|
import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
|
|
3
|
-
import { manifestedModels, partModels, streamedModels, viewModels } from './model.js';
|
|
4
|
-
import { gathered, gatheredEach, selections } from './gather.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,
|
|
9
|
+
import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
|
|
12
10
|
import { houseNotifications } from './stream.js';
|
|
13
|
-
import {
|
|
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';
|
|
@@ -52,159 +51,49 @@ export function createAgentsHouseAdapter(options) {
|
|
|
52
51
|
const transport = options.transport;
|
|
53
52
|
const notifications = houseNotifications(transport, 'credential');
|
|
54
53
|
const tracked = new Map();
|
|
55
|
-
const
|
|
56
|
-
|
|
54
|
+
const rooms = roomStreams('credential');
|
|
55
|
+
const unreused = new Set();
|
|
57
56
|
let bounds;
|
|
58
57
|
function declared() {
|
|
59
58
|
if (bounds === undefined)
|
|
60
59
|
throw new Error('no Discovery declared the bounds');
|
|
61
60
|
return bounds;
|
|
62
61
|
}
|
|
63
|
-
async function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return 'kind' in held ? held : { scope: held, frame: kept };
|
|
69
|
-
}
|
|
70
|
-
for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
|
|
71
|
-
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
72
|
-
prefixes: [authorityRoot(entry.handle)],
|
|
73
|
-
part: listed.part,
|
|
74
|
-
...(continued.held === undefined ? {} : { held: [continued.held] }),
|
|
75
|
-
}, partArrival(listed, arriving));
|
|
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);
|
|
87
|
-
}
|
|
88
|
-
async function manifestPage(asked, continued) {
|
|
89
|
-
const inventory = partInventory(continued.room);
|
|
90
|
-
if (inventory.parts === 0) {
|
|
91
|
-
const page = await partPage(asked, continued, undefined, undefined);
|
|
92
|
-
return page.kind === 'bootstrap' ? { ...page, inventory } : page;
|
|
93
|
-
}
|
|
94
|
-
const { models, seen } = await manifestedModels(continued.room, asked.entry);
|
|
95
|
-
return manifested(continued.room, inventory, JSON.stringify({ ...continued, seen }), models);
|
|
96
|
-
}
|
|
97
|
-
async function partPage(asked, continued, received, arriving) {
|
|
98
|
-
const { entry } = asked;
|
|
99
|
-
const listed = continued.room.parts[continued.next];
|
|
100
|
-
const sent = listed === undefined
|
|
101
|
-
? { scope: emptyScope(continued.room), frame: null }
|
|
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);
|
|
62
|
+
async function streamedPage(entry, token, held) {
|
|
63
|
+
const part = await rooms.part(entry, token);
|
|
64
|
+
if ('kind' in part)
|
|
65
|
+
return part;
|
|
66
|
+
const scope = await reused(part.scope, held);
|
|
106
67
|
if (scope === null) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
: bootstrapTogether({ entry, held: undefined });
|
|
68
|
+
unreused.add(entry.locator);
|
|
69
|
+
return UNCERTAIN_READ;
|
|
110
70
|
}
|
|
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
|
-
...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
|
|
121
|
-
];
|
|
122
|
-
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
123
71
|
return {
|
|
124
72
|
...(await stepped(bootstrapping(scope))),
|
|
125
|
-
...(models === undefined ? {} : { models }),
|
|
126
|
-
...(
|
|
127
|
-
|
|
73
|
+
...(part.models === undefined ? {} : { models: part.models }),
|
|
74
|
+
...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
|
|
75
|
+
bytes: part.bytes,
|
|
128
76
|
};
|
|
129
77
|
}
|
|
130
|
-
async function
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return failure;
|
|
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 };
|
|
78
|
+
async function openedRoom(entry, request) {
|
|
79
|
+
const reusing = unreused.delete(entry.locator) ? undefined : request.held;
|
|
80
|
+
const files = reusing === undefined
|
|
81
|
+
? null
|
|
82
|
+
: await heldFiles(entry.authority, reusing, declared().max_held_files);
|
|
83
|
+
const answered = await transport.streamed(houseDoorRoute('bootstrap'), {
|
|
84
|
+
prefixes: [authorityRoot(entry.handle)],
|
|
85
|
+
...(files === null ? {} : { held: [files] }),
|
|
86
|
+
}, request.signal ?? new AbortController().signal);
|
|
87
|
+
if (answered.room === null)
|
|
88
|
+
return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN_READ;
|
|
89
|
+
return rooms.head(entry, answered.room, request.arriving, request.signal);
|
|
176
90
|
}
|
|
177
91
|
function held(rooms) {
|
|
178
|
-
|
|
92
|
+
notifications.send(rooms.flatMap((room) => {
|
|
179
93
|
const entry = tracked.get(room.locator);
|
|
180
94
|
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;
|
|
95
|
+
return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
|
|
96
|
+
}));
|
|
208
97
|
}
|
|
209
98
|
function authorityFor(locator) {
|
|
210
99
|
return tracked.get(locator);
|
|
@@ -223,116 +112,18 @@ export function createAgentsHouseAdapter(options) {
|
|
|
223
112
|
return result;
|
|
224
113
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
225
114
|
}
|
|
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
115
|
async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
|
|
330
116
|
const paths = batchPaths(changes);
|
|
331
117
|
const sha256 = await deltaDigest(delta);
|
|
332
118
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
333
119
|
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
334
120
|
}
|
|
335
|
-
const minted = await transport.door(
|
|
121
|
+
const minted = await transport.door(houseDoorRoute('batch-upload'), {
|
|
122
|
+
...head,
|
|
123
|
+
paths,
|
|
124
|
+
bytes,
|
|
125
|
+
sha256,
|
|
126
|
+
});
|
|
336
127
|
if (minted.status !== 200) {
|
|
337
128
|
return {
|
|
338
129
|
outcome: await stepped(mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)),
|
|
@@ -380,11 +171,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
380
171
|
: { body: inline };
|
|
381
172
|
if ('outcome' in prepared)
|
|
382
173
|
return prepared.outcome;
|
|
383
|
-
const answer = await transport.door(
|
|
174
|
+
const answer = await transport.door(houseDoorRoute('batch'), prepared.body);
|
|
384
175
|
const stagedFiles = await staged(answer, request);
|
|
385
176
|
if (stagedFiles === false)
|
|
386
177
|
return UNCERTAIN;
|
|
387
|
-
const settled = stagedFiles === null ? answer : await transport.door(
|
|
178
|
+
const settled = stagedFiles === null ? answer : await transport.door(houseDoorRoute('batch'), prepared.body);
|
|
388
179
|
if (stagedFiles === true && (await staged(settled, request)) !== null)
|
|
389
180
|
return UNCERTAIN;
|
|
390
181
|
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
@@ -412,9 +203,22 @@ export function createAgentsHouseAdapter(options) {
|
|
|
412
203
|
function linked(answer, locator) {
|
|
413
204
|
const address = addressed(answer, locator);
|
|
414
205
|
return address.kind === 'address'
|
|
415
|
-
? { kind: 'link', url: address.url, name: address.name }
|
|
206
|
+
? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
|
|
416
207
|
: address;
|
|
417
208
|
}
|
|
209
|
+
function refusedAttach(answer, locator) {
|
|
210
|
+
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
211
|
+
if (failure === null)
|
|
212
|
+
return null;
|
|
213
|
+
return failure.kind === 'scoped-refusal'
|
|
214
|
+
? {
|
|
215
|
+
kind: 'rejected',
|
|
216
|
+
code: failure.code,
|
|
217
|
+
fields: failure.fields,
|
|
218
|
+
retryable: failure.retryable,
|
|
219
|
+
}
|
|
220
|
+
: failure;
|
|
221
|
+
}
|
|
418
222
|
async function downloaded(ask, locator) {
|
|
419
223
|
let address = addressed(await ask(), locator);
|
|
420
224
|
if (address.kind !== 'address')
|
|
@@ -439,7 +243,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
439
243
|
const entry = authorityFor(request.locator);
|
|
440
244
|
if (entry === undefined)
|
|
441
245
|
return null;
|
|
442
|
-
return () => transport.door(
|
|
246
|
+
return () => transport.door(houseDoorRoute('files/get'), {
|
|
443
247
|
room_ref: entry.authority,
|
|
444
248
|
path: request.path,
|
|
445
249
|
revision: request.revision,
|
|
@@ -452,7 +256,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
452
256
|
return options.authorize();
|
|
453
257
|
},
|
|
454
258
|
async discover(_authorization, scope) {
|
|
455
|
-
const answer = await transport.door(
|
|
259
|
+
const answer = await transport.door(houseDoorRoute('discover'), {
|
|
456
260
|
prefixes: [...DISCOVER_PREFIXES],
|
|
457
261
|
...(scope === undefined ? {} : { rooms: scope.authorities }),
|
|
458
262
|
});
|
|
@@ -481,12 +285,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
481
285
|
tracked.delete(locator);
|
|
482
286
|
for (const entry of entries)
|
|
483
287
|
tracked.set(entry.locator, entry);
|
|
484
|
-
for (const locator of handed.keys())
|
|
485
|
-
if (!tracked.has(locator))
|
|
486
|
-
handed.delete(locator);
|
|
487
288
|
notifications.track([...tracked.values()]);
|
|
488
289
|
return {
|
|
489
|
-
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions
|
|
290
|
+
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
490
291
|
member: document.member,
|
|
491
292
|
...(covered === null ? {} : { covered }),
|
|
492
293
|
};
|
|
@@ -495,25 +296,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
495
296
|
const entry = authorityFor(request.locator);
|
|
496
297
|
if (entry === undefined)
|
|
497
298
|
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 });
|
|
299
|
+
return request.pageToken === undefined
|
|
300
|
+
? openedRoom(entry, request)
|
|
301
|
+
: streamedPage(entry, request.pageToken, request.held);
|
|
517
302
|
},
|
|
518
303
|
async mutate(_authorization, request, keep) {
|
|
519
304
|
const entry = authorityFor(request.locator);
|
|
@@ -535,17 +320,16 @@ export function createAgentsHouseAdapter(options) {
|
|
|
535
320
|
const bytes = deltaBytes(delta);
|
|
536
321
|
const handed = request.upload;
|
|
537
322
|
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
323
|
const outcome = await answer(handed);
|
|
540
324
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
541
|
-
return
|
|
542
|
-
return
|
|
325
|
+
return outcome;
|
|
326
|
+
return answer(undefined);
|
|
543
327
|
},
|
|
544
328
|
async history(_authorization, request) {
|
|
545
329
|
const entry = authorityFor(request.locator);
|
|
546
330
|
if (entry === undefined)
|
|
547
331
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
548
|
-
const answer = await transport.door(
|
|
332
|
+
const answer = await transport.door(houseDoorRoute('revisions'), revisionBody({
|
|
549
333
|
path: request.path,
|
|
550
334
|
handle: entry.handle,
|
|
551
335
|
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
@@ -568,6 +352,35 @@ export function createAgentsHouseAdapter(options) {
|
|
|
568
352
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
569
353
|
return linked(await ask(), request.locator);
|
|
570
354
|
},
|
|
355
|
+
async attach(_authorization, request) {
|
|
356
|
+
const entry = authorityFor(request.locator);
|
|
357
|
+
if (entry === undefined)
|
|
358
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
359
|
+
const declared = await transport.door(houseDoorRoute('files/attach'), {
|
|
360
|
+
room_ref: entry.authority,
|
|
361
|
+
name: request.name,
|
|
362
|
+
bytes: request.byteLength,
|
|
363
|
+
sha256: request.sha256,
|
|
364
|
+
media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
|
|
365
|
+
});
|
|
366
|
+
const refused = refusedAttach(declared, request.locator);
|
|
367
|
+
if (refused !== null)
|
|
368
|
+
return refused;
|
|
369
|
+
const upload = houseUpload(declared.body?.upload);
|
|
370
|
+
if (upload === null)
|
|
371
|
+
return UNCERTAIN_READ;
|
|
372
|
+
const finished = await finishedUpload(transport, upload, request.blob);
|
|
373
|
+
if (finished === null)
|
|
374
|
+
return UNCERTAIN_READ;
|
|
375
|
+
const unfinished = refusedAttach(finished, request.locator);
|
|
376
|
+
if (unfinished !== null)
|
|
377
|
+
return unfinished;
|
|
378
|
+
const { path, revision } = (finished.body ?? {});
|
|
379
|
+
const root = `/rooms/${entry.handle}/`;
|
|
380
|
+
return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
|
|
381
|
+
? { kind: 'attached', path: path.slice(root.length), revision }
|
|
382
|
+
: UNCERTAIN_READ;
|
|
383
|
+
},
|
|
571
384
|
reached(locator, version, target) {
|
|
572
385
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
573
386
|
},
|
|
@@ -580,15 +393,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
580
393
|
roomStream: {
|
|
581
394
|
hold: held,
|
|
582
395
|
reopen: notifications.reopen,
|
|
583
|
-
observe
|
|
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
|
-
},
|
|
396
|
+
observe: notifications.observe,
|
|
592
397
|
},
|
|
593
398
|
conversations: notifications.conversations,
|
|
594
399
|
serviceMode: notifications.serviceMode,
|
package/dist/discovery.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type HouseOperations = {
|
|
|
22
22
|
write: readonly string[];
|
|
23
23
|
delete: readonly string[];
|
|
24
24
|
};
|
|
25
|
-
export type
|
|
25
|
+
export type HouseAccessLevel = 'search' | 'open' | 'keep';
|
|
26
26
|
export type HouseAuthority = LogPosition & {
|
|
27
27
|
roomRef: string;
|
|
28
28
|
roomHandle: string;
|
|
@@ -31,7 +31,7 @@ export type HouseAuthority = LogPosition & {
|
|
|
31
31
|
typedSelection: readonly string[] | null;
|
|
32
32
|
managedReplication: 'admitted' | 'unavailable';
|
|
33
33
|
protectedPaths: readonly string[];
|
|
34
|
-
|
|
34
|
+
level: HouseAccessLevel;
|
|
35
35
|
operations: HouseOperations;
|
|
36
36
|
};
|
|
37
37
|
export type HouseDiscoveryDocument = {
|
|
@@ -62,7 +62,7 @@ export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthor
|
|
|
62
62
|
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
63
63
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
64
64
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
65
|
-
export declare function capabilities(actions: HouseDiscoveryDocument['actions']
|
|
65
|
+
export declare function capabilities(actions: HouseDiscoveryDocument['actions']): readonly Capability[];
|
|
66
66
|
export declare function siteCapabilities(): readonly Capability[];
|
|
67
67
|
export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
|
|
68
68
|
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;AAEhC,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAAU,CAAC;AAE1D,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,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,eAAe,G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AED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,sBAAsB,GAAG,gBAAgB,EAAE,CAUhF;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,aAAa,EAAE,CAa5E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAMhE;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,GAAG,SAAS,UAAU,EAAE,CAE9F;AAED,wBAAgB,gBAAgB,IAAI,SAAS,UAAU,EAAE,CAOxD;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,cAAc,GAAG,cAAc,CAqBxE;AAED,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,EAChD,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,QAAQ,EAAE,SAAS,UAAU,EAAE,GAC9B,SAAS,CAQX"}
|
package/dist/discovery.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { declaredActions,
|
|
1
|
+
import { declaredActions, SITE_SUBMIT } from './actions.js';
|
|
2
2
|
import { readPosition, roomVersion } from './version.js';
|
|
3
3
|
export const PROVIDER_ACTIONS = 'provider-actions';
|
|
4
4
|
export const DISCOVER_PREFIXES = ['/'];
|
|
@@ -18,7 +18,7 @@ const BOUND_KEYS = [
|
|
|
18
18
|
'operation_retention_seconds',
|
|
19
19
|
];
|
|
20
20
|
const OPERATION_KEYS = ['write', 'delete'];
|
|
21
|
-
const
|
|
21
|
+
const ACCESS_LEVELS = ['search', 'open', 'keep'];
|
|
22
22
|
function stringList(value) {
|
|
23
23
|
if (!Array.isArray(value))
|
|
24
24
|
return null;
|
|
@@ -86,11 +86,11 @@ function parseAuthority(value) {
|
|
|
86
86
|
const typedSelection = parseTypedSelection(held.typed_selection);
|
|
87
87
|
const protectedPaths = stringList(held.protected_paths);
|
|
88
88
|
const operations = parseOperations(held.operations);
|
|
89
|
-
const
|
|
89
|
+
const level = ACCESS_LEVELS.find((one) => one === held.level);
|
|
90
90
|
if (at === null ||
|
|
91
91
|
typedSelection === undefined ||
|
|
92
92
|
protectedPaths === null ||
|
|
93
|
-
|
|
93
|
+
level === undefined ||
|
|
94
94
|
operations === null)
|
|
95
95
|
return null;
|
|
96
96
|
if (typeof held.room_ref !== 'string' || held.room_ref.length === 0)
|
|
@@ -105,7 +105,7 @@ function parseAuthority(value) {
|
|
|
105
105
|
typedSelection,
|
|
106
106
|
managedReplication: held.managed_replication,
|
|
107
107
|
protectedPaths,
|
|
108
|
-
|
|
108
|
+
level,
|
|
109
109
|
operations,
|
|
110
110
|
...at,
|
|
111
111
|
};
|
|
@@ -219,17 +219,8 @@ export function declaredRetention(bounds) {
|
|
|
219
219
|
refreshHorizon: bounds.change_retention_seconds,
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
-
export function capabilities(actions
|
|
223
|
-
|
|
224
|
-
return [
|
|
225
|
-
{
|
|
226
|
-
name: PROVIDER_ACTIONS,
|
|
227
|
-
actions: declaredActions(actions),
|
|
228
|
-
...(house === undefined
|
|
229
|
-
? {}
|
|
230
|
-
: { conversationAgents: houseConversationAgents(house.authority) }),
|
|
231
|
-
},
|
|
232
|
-
];
|
|
222
|
+
export function capabilities(actions) {
|
|
223
|
+
return [{ name: PROVIDER_ACTIONS, actions: declaredActions(actions) }];
|
|
233
224
|
}
|
|
234
225
|
export function siteCapabilities() {
|
|
235
226
|
return [
|
|
@@ -253,7 +244,7 @@ export function discoveredRoom(authority) {
|
|
|
253
244
|
replica: {
|
|
254
245
|
selection: locator,
|
|
255
246
|
admission: authority.managedReplication,
|
|
256
|
-
offline: authority.
|
|
247
|
+
offline: authority.level === 'open' ? 'locked' : 'open',
|
|
257
248
|
},
|
|
258
249
|
...(authority.typedSelection === null
|
|
259
250
|
? {}
|