@agentshouse/mdruntime-adapter 0.1.0-c8b338faa5c2d → 0.1.0-c8cad855cc8e8
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/AGENTS.md +225 -215
- package/dist/actions.d.ts +12 -5
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +89 -98
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +220 -147
- package/dist/discovery.d.ts +4 -3
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +28 -10
- package/dist/gather.d.ts +1 -1
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +4 -14
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/part.d.ts +13 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +80 -0
- package/dist/read.d.ts +51 -27
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +241 -124
- package/dist/referrer.d.ts +2 -0
- package/dist/referrer.d.ts.map +1 -1
- package/dist/referrer.js +8 -2
- package/dist/room-types.d.ts +6 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +66 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +95 -91
- package/dist/stream.d.ts +5 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +65 -39
- package/dist/transport.d.ts +27 -9
- package/dist/transport.d.ts.map +1 -1
- package/dist/write.d.ts +12 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +91 -43
- package/package.json +2 -2
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -38
package/dist/adapter.js
CHANGED
|
@@ -1,46 +1,48 @@
|
|
|
1
|
+
import { stepped } from '@agentshouse/mdruntime';
|
|
1
2
|
import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
|
|
2
3
|
import { partModels, streamedModels, viewModels } from './model.js';
|
|
3
4
|
import { gathered, gatheredEach, selections } from './gather.js';
|
|
4
5
|
import { createSiteAdapter } from './site.js';
|
|
5
|
-
import {
|
|
6
|
+
import { authorityRoot, bootstrapping, emptyScope, housePart, parseEnumeration, parseFileAddress, parseGrant, parseParted, refreshFrom, viewOf, wholeView, } from './read.js';
|
|
7
|
+
import { PART_ATTEMPTS, unverifiedPart } from './part.js';
|
|
6
8
|
import { sha256Hex } from './digest.js';
|
|
7
|
-
import { acceptedHanded, enumeratedHanded, heldHanded, scopeHanded, streamedHanded, } from './handed.js';
|
|
8
9
|
import { houseAction } from './actions.js';
|
|
9
10
|
import { classifyDoor, classifyRead, discoveryFailure, doorRefusal } from './refusal.js';
|
|
10
11
|
import { houseNotifications } from './stream.js';
|
|
11
12
|
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
|
|
12
|
-
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
13
|
-
import { houseReferrer } from './referrer.js';
|
|
13
|
+
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
14
|
+
import { houseReferrer, houseReferrerScope } from './referrer.js';
|
|
15
|
+
import { HOUSE_ROOM_TYPES } from './room-types.js';
|
|
14
16
|
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
15
17
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
16
18
|
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
19
|
+
const EXPIRED_ADDRESS = 403;
|
|
17
20
|
function lapsedGrant(outcome) {
|
|
18
21
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
19
22
|
}
|
|
20
|
-
function heldFiles(authority, held,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
.sort();
|
|
26
|
-
if (paths.length === 0)
|
|
27
|
-
return null;
|
|
28
|
-
const files = paths.slice(0, budget).map((path) => ({ path, revision: held.revisions[path] }));
|
|
29
|
-
return { room: authority, through: paths.length > budget ? files.at(-1).path : null, files };
|
|
23
|
+
async function heldFiles(authority, held, bound) {
|
|
24
|
+
const listed = await held.files(null, bound + 1);
|
|
25
|
+
const files = listed.slice(0, bound);
|
|
26
|
+
const through = listed.length > bound ? (files.at(-1)?.path ?? null) : null;
|
|
27
|
+
return files.length === 0 ? null : { room: authority, through, files };
|
|
30
28
|
}
|
|
31
29
|
async function reused(scope, held) {
|
|
32
30
|
const sent = new Set(scope.contents.map((entry) => entry.path));
|
|
33
31
|
const contents = [...scope.contents];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
const asked = scope.files.filter((file) => file.binary === undefined && !sent.has(file.path));
|
|
33
|
+
if (asked.length === 0)
|
|
34
|
+
return scope;
|
|
35
|
+
if (held === undefined)
|
|
36
|
+
return null;
|
|
37
|
+
const kept = await held.contents(asked.map(({ path }) => path));
|
|
38
|
+
for (const file of asked) {
|
|
39
|
+
const found = kept.get(file.path);
|
|
40
|
+
if (found === undefined ||
|
|
41
|
+
found.revision !== file.revision ||
|
|
42
|
+
(await sha256Hex(found.content)) !== file.sha256) {
|
|
41
43
|
return null;
|
|
42
44
|
}
|
|
43
|
-
contents.push({ path: file.path, content });
|
|
45
|
+
contents.push({ path: file.path, content: found.content });
|
|
44
46
|
}
|
|
45
47
|
return { ...scope, contents };
|
|
46
48
|
}
|
|
@@ -51,48 +53,64 @@ export function createAgentsHouseAdapter(options) {
|
|
|
51
53
|
const notifications = houseNotifications(transport, 'credential');
|
|
52
54
|
const tracked = new Map();
|
|
53
55
|
const handed = new Map();
|
|
56
|
+
let heldRevisions;
|
|
54
57
|
let bounds;
|
|
55
58
|
function declared() {
|
|
56
59
|
if (bounds === undefined)
|
|
57
60
|
throw new Error('no Discovery declared the bounds');
|
|
58
61
|
return bounds;
|
|
59
62
|
}
|
|
60
|
-
async function
|
|
63
|
+
async function fetchedPart(entry, continued, listed) {
|
|
64
|
+
for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
|
|
65
|
+
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
66
|
+
prefixes: [authorityRoot(entry.handle)],
|
|
67
|
+
part: listed.part,
|
|
68
|
+
...(continued.held === undefined ? {} : { held: [continued.held] }),
|
|
69
|
+
});
|
|
70
|
+
const failure = classifyRead(answered.status, answered.body, entry.locator);
|
|
71
|
+
if (failure !== null)
|
|
72
|
+
return failure;
|
|
73
|
+
const scope = await housePart(continued.room, answered.body, listed, 'credential');
|
|
74
|
+
if (scope !== null)
|
|
75
|
+
return scope;
|
|
76
|
+
}
|
|
77
|
+
return unverifiedPart(entry.locator);
|
|
78
|
+
}
|
|
79
|
+
async function partPage(asked, continued) {
|
|
61
80
|
const { entry } = asked;
|
|
62
|
-
|
|
63
|
-
|
|
81
|
+
const listed = continued.room.parts[continued.next];
|
|
82
|
+
const sent = listed === undefined
|
|
83
|
+
? emptyScope(continued.room)
|
|
84
|
+
: await fetchedPart(entry, continued, listed);
|
|
85
|
+
if ('kind' in sent)
|
|
86
|
+
return sent;
|
|
64
87
|
const scope = await reused(sent, asked.held);
|
|
65
88
|
if (scope === null) {
|
|
66
89
|
return asked.held === undefined
|
|
67
90
|
? UNCERTAIN_READ
|
|
68
|
-
:
|
|
69
|
-
? bootstrapTogether({ entry, held: undefined })
|
|
70
|
-
: continuedBootstrap({ entry, held: undefined }, continued);
|
|
91
|
+
: bootstrapTogether({ entry, held: undefined });
|
|
71
92
|
}
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
if (continued ===
|
|
75
|
-
handed.set(entry.locator,
|
|
93
|
+
const next = continued.next + 1;
|
|
94
|
+
const more = next < continued.room.parts.length;
|
|
95
|
+
if (continued.next === 0 && !more)
|
|
96
|
+
handed.set(entry.locator, roomVersion(scope));
|
|
76
97
|
else
|
|
77
98
|
handed.delete(entry.locator);
|
|
78
99
|
notifications.reach(entry.authority, scope);
|
|
79
100
|
const seen = [
|
|
80
|
-
...
|
|
101
|
+
...continued.seen,
|
|
81
102
|
...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
|
|
82
103
|
];
|
|
83
|
-
const models = await partModels(scope, entry, new Set(seen),
|
|
84
|
-
const continuation = next === null
|
|
85
|
-
? null
|
|
86
|
-
: { after: next, seen, ...(cursor?.cut === undefined ? {} : { cut: cursor.cut }) };
|
|
104
|
+
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
87
105
|
return {
|
|
88
|
-
...
|
|
106
|
+
...(await stepped(bootstrapping(scope))),
|
|
89
107
|
...(models === undefined ? {} : { models }),
|
|
90
|
-
...(
|
|
108
|
+
...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
|
|
91
109
|
};
|
|
92
110
|
}
|
|
93
111
|
async function enumeratedPage(ask, page) {
|
|
94
112
|
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
95
|
-
prefixes:
|
|
113
|
+
prefixes: [authorityRoot(ask.entry.handle)],
|
|
96
114
|
positions: [
|
|
97
115
|
{
|
|
98
116
|
...presented(ask.entry.authority, { position: page.after, logEpoch: ask.from.logEpoch }),
|
|
@@ -116,52 +134,54 @@ export function createAgentsHouseAdapter(options) {
|
|
|
116
134
|
if ('kind' in view)
|
|
117
135
|
return view;
|
|
118
136
|
notifications.reach(ask.entry.authority, view);
|
|
119
|
-
const answer = refreshFrom(view, ask.fromRoomVersion);
|
|
137
|
+
const answer = await refreshFrom(view, ask.fromRoomVersion);
|
|
120
138
|
if (answer.kind !== 'net-advancement')
|
|
121
139
|
return answer;
|
|
122
|
-
handed.set(ask.entry.locator,
|
|
140
|
+
handed.set(ask.entry.locator, roomVersion(view));
|
|
123
141
|
const models = await viewModels(view, ask.entry);
|
|
124
142
|
return models === undefined ? answer : { ...answer, models };
|
|
125
143
|
}
|
|
126
144
|
async function streamed(entry, request, from) {
|
|
127
|
-
|
|
128
|
-
if (held?.roomVersion !== request.fromRoomVersion)
|
|
145
|
+
if (handed.get(entry.locator) !== request.fromRoomVersion)
|
|
129
146
|
return null;
|
|
130
|
-
const
|
|
147
|
+
const asked = notifications.edited(entry, from);
|
|
148
|
+
const kept = asked.length === 0 || heldRevisions === undefined
|
|
149
|
+
? new Map()
|
|
150
|
+
: await heldRevisions(entry.locator, asked);
|
|
151
|
+
const advanced = await stepped(notifications.advance(entry, from, (path, revision) => kept.get(path) === revision));
|
|
131
152
|
if (advanced === null)
|
|
132
153
|
return null;
|
|
133
|
-
handed.set(entry.locator,
|
|
154
|
+
handed.set(entry.locator, advanced.page.roomVersion);
|
|
134
155
|
const models = await streamedModels(advanced.schemas, entry, 'credential');
|
|
135
156
|
return models === undefined ? advanced.page : { ...advanced.page, models };
|
|
136
157
|
}
|
|
137
|
-
function held(rooms
|
|
158
|
+
function held(rooms) {
|
|
138
159
|
const kept = rooms.flatMap((room) => {
|
|
139
160
|
const entry = tracked.get(room.locator);
|
|
140
161
|
const at = logPosition(room.roomVersion);
|
|
141
162
|
if (entry === undefined || at === null)
|
|
142
163
|
return [];
|
|
143
|
-
handed.set(room.locator,
|
|
164
|
+
handed.set(room.locator, room.roomVersion);
|
|
144
165
|
notifications.reach(entry.authority, at);
|
|
145
166
|
return [presented(entry.authority, at)];
|
|
146
167
|
});
|
|
147
|
-
notifications.send(kept
|
|
148
|
-
? null
|
|
149
|
-
: {
|
|
150
|
-
rooms: demand.rooms.flatMap((locator) => {
|
|
151
|
-
const entry = tracked.get(locator);
|
|
152
|
-
return entry === undefined ? [] : [entry.authority];
|
|
153
|
-
}),
|
|
154
|
-
conversations: demand.conversations,
|
|
155
|
-
});
|
|
168
|
+
notifications.send(kept);
|
|
156
169
|
}
|
|
157
|
-
function
|
|
170
|
+
async function adoptedMove(entry, into, outcome) {
|
|
171
|
+
if (outcome.kind === 'accepted' && outcome.destination !== undefined) {
|
|
172
|
+
await adopted(into, { kind: 'accepted', ...outcome.destination });
|
|
173
|
+
}
|
|
174
|
+
return adopted(entry, outcome);
|
|
175
|
+
}
|
|
176
|
+
async function adopted(entry, outcome) {
|
|
158
177
|
if (outcome.kind !== 'accepted')
|
|
159
178
|
return outcome;
|
|
160
179
|
const held = handed.get(entry.locator);
|
|
161
180
|
if (held === undefined)
|
|
162
181
|
return outcome;
|
|
163
|
-
const follows = followsVersion(held
|
|
164
|
-
|
|
182
|
+
const follows = followsVersion(held, outcome.roomVersion);
|
|
183
|
+
if (follows)
|
|
184
|
+
handed.set(entry.locator, outcome.roomVersion);
|
|
165
185
|
const at = logPosition(outcome.roomVersion);
|
|
166
186
|
if (follows && at !== null)
|
|
167
187
|
notifications.reach(entry.authority, at);
|
|
@@ -184,68 +204,61 @@ export function createAgentsHouseAdapter(options) {
|
|
|
184
204
|
return result;
|
|
185
205
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
186
206
|
}
|
|
187
|
-
function
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
207
|
+
async function holding(asks) {
|
|
208
|
+
const bound = Math.floor(declared().max_held_files / Math.max(1, asks.filter((ask) => ask.held !== undefined).length));
|
|
209
|
+
const held = [];
|
|
210
|
+
for (const ask of asks) {
|
|
211
|
+
if (ask.held === undefined || bound === 0)
|
|
212
|
+
continue;
|
|
213
|
+
const files = await heldFiles(ask.entry.authority, ask.held, bound);
|
|
214
|
+
if (files !== null)
|
|
215
|
+
held.push(files);
|
|
216
|
+
}
|
|
217
|
+
return held;
|
|
193
218
|
}
|
|
194
219
|
async function bootstrapped(asks, answer) {
|
|
195
220
|
let open = asks.map((asked, ask) => ({ entry: asked.entry, asked, ask }));
|
|
196
221
|
while (open.length > 0) {
|
|
197
222
|
const unreached = [];
|
|
198
|
-
for (const part of selections(open,
|
|
199
|
-
const held = holding(part.map(({ asked }) => asked)
|
|
223
|
+
for (const part of selections(open, declared().max_prefixes)) {
|
|
224
|
+
const held = await holding(part.map(({ asked }) => asked));
|
|
200
225
|
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
201
|
-
prefixes: part.
|
|
226
|
+
prefixes: part.map(({ entry }) => authorityRoot(entry.handle)),
|
|
202
227
|
...(held.length === 0 ? {} : { held }),
|
|
203
228
|
});
|
|
204
229
|
const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
|
|
205
|
-
const
|
|
230
|
+
const parted = classified[0] === null ? parseParted(answered.body) : null;
|
|
206
231
|
for (const [index, asked] of part.entries()) {
|
|
207
232
|
const failure = classified[index];
|
|
208
233
|
if (failure !== null && failure !== undefined) {
|
|
209
234
|
answer(asked.ask, failure);
|
|
210
235
|
continue;
|
|
211
236
|
}
|
|
212
|
-
if (
|
|
237
|
+
if (parted === null) {
|
|
213
238
|
answer(asked.ask, UNCERTAIN_READ);
|
|
214
239
|
continue;
|
|
215
240
|
}
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
241
|
+
const room = parted.rooms.find((candidate) => candidate.anchor === asked.entry.authority);
|
|
242
|
+
if (room === undefined && parted.next !== undefined) {
|
|
218
243
|
unreached.push(asked);
|
|
219
244
|
continue;
|
|
220
245
|
}
|
|
221
|
-
|
|
246
|
+
if (room === undefined) {
|
|
247
|
+
answer(asked.ask, { kind: 'room-not-readable', locator: asked.entry.locator });
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const kept = held.find((files) => files.room === asked.entry.authority);
|
|
251
|
+
answer(asked.ask, await partPage(asked.asked, {
|
|
252
|
+
room,
|
|
253
|
+
next: 0,
|
|
254
|
+
seen: [],
|
|
255
|
+
...(kept === undefined ? {} : { held: kept }),
|
|
256
|
+
}));
|
|
222
257
|
}
|
|
223
258
|
}
|
|
224
259
|
open = unreached;
|
|
225
260
|
}
|
|
226
261
|
}
|
|
227
|
-
async function continuedBootstrap(asked, continued) {
|
|
228
|
-
const { entry } = asked;
|
|
229
|
-
const after = {
|
|
230
|
-
room: entry.authority,
|
|
231
|
-
path: continued.after,
|
|
232
|
-
...(continued.cut === undefined ? {} : { cut: continued.cut }),
|
|
233
|
-
};
|
|
234
|
-
const held = holding([asked], continued.after);
|
|
235
|
-
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
236
|
-
prefixes: contentPrefixes(entry),
|
|
237
|
-
after,
|
|
238
|
-
...(held.length === 0 ? {} : { held }),
|
|
239
|
-
});
|
|
240
|
-
const failure = classifyRead(answered.status, answered.body, entry.locator);
|
|
241
|
-
if (failure !== null)
|
|
242
|
-
return failure;
|
|
243
|
-
const envelope = parseEnvelope(answered.body);
|
|
244
|
-
if (envelope === null)
|
|
245
|
-
return UNCERTAIN_READ;
|
|
246
|
-
const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
|
|
247
|
-
return bootstrappedRoom(envelope, scope, asked, continued);
|
|
248
|
-
}
|
|
249
262
|
function layered(asks) {
|
|
250
263
|
const depths = new Map();
|
|
251
264
|
const layers = [];
|
|
@@ -258,12 +271,12 @@ export function createAgentsHouseAdapter(options) {
|
|
|
258
271
|
}
|
|
259
272
|
async function enumerated(asks) {
|
|
260
273
|
const answers = [];
|
|
261
|
-
const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer,
|
|
274
|
+
const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer, declared().max_prefixes));
|
|
262
275
|
for (const part of parts) {
|
|
263
276
|
let open = [...part];
|
|
264
277
|
while (open.length > 0) {
|
|
265
278
|
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
266
|
-
prefixes: open.
|
|
279
|
+
prefixes: open.map(({ ask }) => authorityRoot(ask.entry.handle)),
|
|
267
280
|
positions: open.map(({ ask }) => presented(ask.entry.authority, ask.from)),
|
|
268
281
|
});
|
|
269
282
|
const classified = open.map(({ ask }) => classifyRead(answer.status, answer.body, ask.entry.locator));
|
|
@@ -302,10 +315,12 @@ export function createAgentsHouseAdapter(options) {
|
|
|
302
315
|
}
|
|
303
316
|
const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
|
|
304
317
|
if (minted.status !== 200) {
|
|
305
|
-
return {
|
|
318
|
+
return {
|
|
319
|
+
outcome: await stepped(mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)),
|
|
320
|
+
};
|
|
306
321
|
}
|
|
307
322
|
const grant = parseGrant(minted.body);
|
|
308
|
-
if (grant === null
|
|
323
|
+
if (grant === null)
|
|
309
324
|
return { outcome: UNCERTAIN };
|
|
310
325
|
const delivered = await transport.transfer({
|
|
311
326
|
act: 'authored_batch_upload',
|
|
@@ -315,13 +330,13 @@ export function createAgentsHouseAdapter(options) {
|
|
|
315
330
|
if (delivered.status !== 200)
|
|
316
331
|
return { outcome: UNCERTAIN };
|
|
317
332
|
const holding = parseGrant(delivered.body);
|
|
318
|
-
if (holding === null
|
|
333
|
+
if (holding === null)
|
|
319
334
|
return { outcome: UNCERTAIN };
|
|
320
335
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
321
336
|
await keep(upload);
|
|
322
337
|
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
323
338
|
}
|
|
324
|
-
async function staged(answer, batch) {
|
|
339
|
+
async function staged(answer, { changeBatch: batch, file }) {
|
|
325
340
|
const refusal = doorRefusal(answer.body);
|
|
326
341
|
if (refusal?.code !== 'files_unstaged')
|
|
327
342
|
return null;
|
|
@@ -336,7 +351,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
336
351
|
const delivered = await transport.transfer({
|
|
337
352
|
act: 'binary_stage',
|
|
338
353
|
url,
|
|
339
|
-
body: change.
|
|
354
|
+
body: await file(change.localId),
|
|
340
355
|
operation,
|
|
341
356
|
});
|
|
342
357
|
if (delivered.status !== 200)
|
|
@@ -344,7 +359,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
344
359
|
}
|
|
345
360
|
return true;
|
|
346
361
|
}
|
|
347
|
-
async function submit(
|
|
362
|
+
async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
|
|
348
363
|
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
349
364
|
const prepared = uploadable(inline, bytes, declared())
|
|
350
365
|
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
@@ -352,15 +367,20 @@ export function createAgentsHouseAdapter(options) {
|
|
|
352
367
|
if ('outcome' in prepared)
|
|
353
368
|
return prepared.outcome;
|
|
354
369
|
const answer = await transport.door(DOOR_BATCH, prepared.body);
|
|
355
|
-
const stagedFiles = await staged(answer,
|
|
370
|
+
const stagedFiles = await staged(answer, request);
|
|
356
371
|
if (stagedFiles === false)
|
|
357
372
|
return UNCERTAIN;
|
|
358
373
|
const settled = stagedFiles === null ? answer : await transport.door(DOOR_BATCH, prepared.body);
|
|
359
|
-
if (stagedFiles === true && (await staged(settled,
|
|
374
|
+
if (stagedFiles === true && (await staged(settled, request)) !== null)
|
|
360
375
|
return UNCERTAIN;
|
|
361
|
-
return mutationOutcome(settled.status, settled.body, entry.locator, entry.handle
|
|
376
|
+
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
377
|
+
? undefined
|
|
378
|
+
: {
|
|
379
|
+
source: { authority: entry.authority, handle: entry.handle },
|
|
380
|
+
destination: { authority: into.authority, handle: into.handle },
|
|
381
|
+
}));
|
|
362
382
|
}
|
|
363
|
-
|
|
383
|
+
function addressed(answer, locator) {
|
|
364
384
|
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
365
385
|
if (failure !== null) {
|
|
366
386
|
return failure.kind === 'scoped-refusal'
|
|
@@ -372,20 +392,55 @@ export function createAgentsHouseAdapter(options) {
|
|
|
372
392
|
}
|
|
373
393
|
: failure;
|
|
374
394
|
}
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
395
|
+
const address = parseFileAddress(answer.body);
|
|
396
|
+
return address === null ? UNCERTAIN_READ : { kind: 'address', ...address };
|
|
397
|
+
}
|
|
398
|
+
function linked(answer, locator) {
|
|
399
|
+
const address = addressed(answer, locator);
|
|
400
|
+
return address.kind === 'address'
|
|
401
|
+
? { kind: 'link', url: address.url, name: address.name }
|
|
402
|
+
: address;
|
|
403
|
+
}
|
|
404
|
+
async function downloaded(ask, locator) {
|
|
405
|
+
let address = addressed(await ask(), locator);
|
|
406
|
+
if (address.kind !== 'address')
|
|
407
|
+
return address;
|
|
408
|
+
let read = await transport.download(address.url);
|
|
409
|
+
if (read.status === EXPIRED_ADDRESS) {
|
|
410
|
+
address = addressed(await ask(), locator);
|
|
411
|
+
if (address.kind !== 'address')
|
|
412
|
+
return address;
|
|
413
|
+
read = await transport.download(address.url);
|
|
414
|
+
}
|
|
415
|
+
if (read.status !== 200 || read.body === null)
|
|
380
416
|
return UNCERTAIN_READ;
|
|
381
|
-
return {
|
|
417
|
+
return {
|
|
418
|
+
kind: 'binary',
|
|
419
|
+
body: read.body,
|
|
420
|
+
mediaType: address.mediaType,
|
|
421
|
+
sha256: address.sha256,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function pathAddress(request) {
|
|
425
|
+
const entry = authorityFor(request.locator);
|
|
426
|
+
if (entry === undefined)
|
|
427
|
+
return null;
|
|
428
|
+
return () => transport.door(DOOR_FILES_GET, {
|
|
429
|
+
room_ref: entry.authority,
|
|
430
|
+
path: request.path,
|
|
431
|
+
revision: request.revision,
|
|
432
|
+
});
|
|
382
433
|
}
|
|
383
434
|
return {
|
|
435
|
+
roomTypes: HOUSE_ROOM_TYPES,
|
|
384
436
|
async authorize() {
|
|
385
437
|
return options.authorize();
|
|
386
438
|
},
|
|
387
|
-
async discover(_authorization) {
|
|
388
|
-
const answer = await transport.door(DOOR_DISCOVER, {
|
|
439
|
+
async discover(_authorization, scope) {
|
|
440
|
+
const answer = await transport.door(DOOR_DISCOVER, {
|
|
441
|
+
prefixes: [...DISCOVER_PREFIXES],
|
|
442
|
+
...(scope === undefined ? {} : { rooms: scope.authorities }),
|
|
443
|
+
});
|
|
389
444
|
const failed = discoveryFailure(answer.status, answer.body);
|
|
390
445
|
if (failed !== null)
|
|
391
446
|
return failed;
|
|
@@ -394,16 +449,31 @@ export function createAgentsHouseAdapter(options) {
|
|
|
394
449
|
return { kind: 'transport-uncertainty' };
|
|
395
450
|
bounds = document.bounds;
|
|
396
451
|
const entries = trackedFrom(document);
|
|
397
|
-
|
|
452
|
+
const covered = scope === undefined
|
|
453
|
+
? null
|
|
454
|
+
: [
|
|
455
|
+
...new Set([
|
|
456
|
+
...[...tracked.values()]
|
|
457
|
+
.filter((entry) => scope.authorities.includes(entry.authority))
|
|
458
|
+
.map((entry) => entry.locator),
|
|
459
|
+
...entries.map((entry) => entry.locator),
|
|
460
|
+
]),
|
|
461
|
+
];
|
|
462
|
+
if (covered === null)
|
|
463
|
+
tracked.clear();
|
|
464
|
+
else
|
|
465
|
+
for (const locator of covered)
|
|
466
|
+
tracked.delete(locator);
|
|
398
467
|
for (const entry of entries)
|
|
399
468
|
tracked.set(entry.locator, entry);
|
|
400
469
|
for (const locator of handed.keys())
|
|
401
470
|
if (!tracked.has(locator))
|
|
402
471
|
handed.delete(locator);
|
|
403
|
-
notifications.track(
|
|
472
|
+
notifications.track([...tracked.values()]);
|
|
404
473
|
return {
|
|
405
|
-
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document)),
|
|
474
|
+
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions, [...tracked.values()])),
|
|
406
475
|
member: document.member,
|
|
476
|
+
...(covered === null ? {} : { covered }),
|
|
407
477
|
};
|
|
408
478
|
},
|
|
409
479
|
async bootstrap(_authorization, request) {
|
|
@@ -412,7 +482,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
412
482
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
413
483
|
const asked = { entry, held: request.held };
|
|
414
484
|
if (request.pageToken !== undefined) {
|
|
415
|
-
return
|
|
485
|
+
return partPage(asked, JSON.parse(request.pageToken));
|
|
416
486
|
}
|
|
417
487
|
return bootstrapTogether(asked);
|
|
418
488
|
},
|
|
@@ -434,18 +504,27 @@ export function createAgentsHouseAdapter(options) {
|
|
|
434
504
|
const entry = authorityFor(request.locator);
|
|
435
505
|
if (entry === undefined)
|
|
436
506
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
437
|
-
const
|
|
507
|
+
const batch = request.changeBatch;
|
|
508
|
+
const destination = batch.between?.destination.room;
|
|
509
|
+
const into = destination === undefined ? undefined : authorityFor(destination);
|
|
510
|
+
if (destination !== undefined && into === undefined) {
|
|
511
|
+
return { kind: 'room-not-readable', locator: destination };
|
|
512
|
+
}
|
|
513
|
+
const mapped = into === undefined
|
|
514
|
+
? houseChanges(batch, entry.handle)
|
|
515
|
+
: houseMove(batch, entry.handle, into.handle);
|
|
438
516
|
if (mapped.kind === 'unmapped')
|
|
439
517
|
return rejectedMapping(mapped);
|
|
440
|
-
const head = operationHead(
|
|
518
|
+
const head = operationHead(batch);
|
|
441
519
|
const delta = deltaBody(mapped.changes);
|
|
442
520
|
const bytes = deltaBytes(delta);
|
|
443
521
|
const handed = request.upload;
|
|
444
|
-
const
|
|
445
|
-
const
|
|
522
|
+
const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
|
|
523
|
+
const settle = (outcome) => into === undefined ? adopted(entry, outcome) : adoptedMove(entry, into, outcome);
|
|
524
|
+
const outcome = await answer(handed);
|
|
446
525
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
447
|
-
return
|
|
448
|
-
return
|
|
526
|
+
return settle(outcome);
|
|
527
|
+
return settle(await answer(undefined));
|
|
449
528
|
},
|
|
450
529
|
async history(_authorization, request) {
|
|
451
530
|
const entry = authorityFor(request.locator);
|
|
@@ -464,34 +543,25 @@ export function createAgentsHouseAdapter(options) {
|
|
|
464
543
|
},
|
|
465
544
|
async binary(_authorization, request) {
|
|
466
545
|
if (request.kind === 'path') {
|
|
467
|
-
const
|
|
468
|
-
if (
|
|
546
|
+
const ask = pathAddress(request);
|
|
547
|
+
if (ask === null)
|
|
469
548
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
470
|
-
|
|
471
|
-
room_ref: entry.authority,
|
|
472
|
-
path: request.path,
|
|
473
|
-
revision: request.revision,
|
|
474
|
-
});
|
|
475
|
-
return downloaded(answer, request.locator);
|
|
549
|
+
return downloaded(ask, request.locator);
|
|
476
550
|
}
|
|
477
551
|
const referrer = houseReferrer(request.referrer, tracked);
|
|
478
552
|
if (referrer === null) {
|
|
479
553
|
return { kind: 'rejected', code: 'referrer_unknown', fields: {}, retryable: false };
|
|
480
554
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
555
|
+
return downloaded(() => transport.door(DOOR_FILES_GET, { file: request.fileRef, referrer: referrer.referrer }), referrer.locator);
|
|
556
|
+
},
|
|
557
|
+
async link(_authorization, request) {
|
|
558
|
+
const ask = pathAddress(request);
|
|
559
|
+
if (ask === null)
|
|
560
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
561
|
+
return linked(await ask(), request.locator);
|
|
486
562
|
},
|
|
487
563
|
referrerScope(referrer) {
|
|
488
|
-
|
|
489
|
-
if (held === null)
|
|
490
|
-
return null;
|
|
491
|
-
if (held.locator === '')
|
|
492
|
-
return { kind: 'conversations' };
|
|
493
|
-
const { path } = held.referrer;
|
|
494
|
-
return { kind: 'room', locator: held.locator, ...(path === undefined ? {} : { path }) };
|
|
564
|
+
return houseReferrerScope(referrer, tracked);
|
|
495
565
|
},
|
|
496
566
|
reached(locator, version, target) {
|
|
497
567
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
@@ -505,7 +575,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
505
575
|
roomStream: {
|
|
506
576
|
hold: held,
|
|
507
577
|
reopen: notifications.reopen,
|
|
508
|
-
observe
|
|
578
|
+
observe(notify, receipts, revisions) {
|
|
579
|
+
heldRevisions = revisions;
|
|
580
|
+
return notifications.observe(notify, receipts);
|
|
581
|
+
},
|
|
509
582
|
published(locator, roomVersion) {
|
|
510
583
|
const at = logPosition(roomVersion);
|
|
511
584
|
if (at !== null)
|
package/dist/discovery.d.ts
CHANGED
|
@@ -16,13 +16,13 @@ export type HouseBounds = {
|
|
|
16
16
|
max_held_files: number;
|
|
17
17
|
change_retention_seconds: number;
|
|
18
18
|
operation_retention_seconds: number;
|
|
19
|
+
max_move_documents?: number;
|
|
19
20
|
};
|
|
20
21
|
export type HouseOperations = {
|
|
21
|
-
read: readonly string[];
|
|
22
|
-
sync: readonly string[];
|
|
23
22
|
write: readonly string[];
|
|
24
23
|
delete: readonly string[];
|
|
25
24
|
};
|
|
25
|
+
export type HouseReadLevel = 'mcp' | 'online' | 'local';
|
|
26
26
|
export type HouseModel = {
|
|
27
27
|
root: string;
|
|
28
28
|
paths: readonly string[];
|
|
@@ -35,6 +35,7 @@ export type HouseAuthority = LogPosition & {
|
|
|
35
35
|
houseModel: HouseModel | null;
|
|
36
36
|
managedReplication: 'admitted' | 'unavailable';
|
|
37
37
|
protectedPaths: readonly string[];
|
|
38
|
+
read: HouseReadLevel;
|
|
38
39
|
operations: HouseOperations;
|
|
39
40
|
};
|
|
40
41
|
export type HouseDiscoveryDocument = {
|
|
@@ -66,7 +67,7 @@ export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthor
|
|
|
66
67
|
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
67
68
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
68
69
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
69
|
-
export declare function capabilities(
|
|
70
|
+
export declare function capabilities(actions: HouseDiscoveryDocument['actions'], rooms: readonly Pick<TrackedAuthority, 'authority' | 'houseModel'>[]): readonly Capability[];
|
|
70
71
|
export declare function siteCapabilities(): readonly Capability[];
|
|
71
72
|
export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
|
|
72
73
|
export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
|