@agentshouse/mdruntime-adapter 0.1.0-ccd2ccb1f7214 → 0.1.0-cd23c45caa798
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 +28 -23
- package/dist/actions.d.ts +11 -5
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +77 -97
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +144 -87
- package/dist/discovery.d.ts +3 -2
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +24 -6
- package/dist/gather.d.ts +1 -1
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +4 -14
- package/dist/handed.d.ts +6 -6
- package/dist/handed.d.ts.map +1 -1
- package/dist/handed.js +36 -29
- 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 +33 -23
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +159 -120
- package/dist/referrer.d.ts.map +1 -1
- package/dist/referrer.js +0 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +58 -74
- package/dist/stream.d.ts +2 -3
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +23 -34
- package/dist/transport.d.ts +2 -1
- 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 +79 -38
- package/package.json +2 -2
package/dist/adapter.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import { sortedKeys, 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, parseGrant, parseParted, refreshFrom, viewOf, wholeView, } from './read.js';
|
|
7
|
+
import { PART_ATTEMPTS, unverifiedPart } from './part.js';
|
|
6
8
|
import { sha256Hex } from './digest.js';
|
|
7
9
|
import { acceptedHanded, enumeratedHanded, heldHanded, scopeHanded, streamedHanded, } from './handed.js';
|
|
8
10
|
import { houseAction } from './actions.js';
|
|
9
11
|
import { classifyDoor, classifyRead, discoveryFailure, doorRefusal } from './refusal.js';
|
|
10
12
|
import { houseNotifications } from './stream.js';
|
|
11
13
|
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';
|
|
14
|
+
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
13
15
|
import { houseReferrer } from './referrer.js';
|
|
14
16
|
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
15
17
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
@@ -17,16 +19,28 @@ const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
|
17
19
|
function lapsedGrant(outcome) {
|
|
18
20
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
const heldPaths = new WeakMap();
|
|
23
|
+
async function sortedHeld(held) {
|
|
24
|
+
const known = heldPaths.get(held.documents);
|
|
25
|
+
if (known !== undefined)
|
|
26
|
+
return known;
|
|
27
|
+
const sorted = await stepped(sortedKeys(held.documents));
|
|
28
|
+
heldPaths.set(held.documents, sorted);
|
|
29
|
+
return sorted;
|
|
30
|
+
}
|
|
31
|
+
function heldFiles(authority, held, paths, bound) {
|
|
32
|
+
const files = [];
|
|
33
|
+
let through = null;
|
|
34
|
+
for (let at = 0; at < paths.length && through === null; at += 1) {
|
|
35
|
+
const revision = held.revisions[paths[at]];
|
|
36
|
+
if (revision === undefined)
|
|
37
|
+
continue;
|
|
38
|
+
if (files.length === bound)
|
|
39
|
+
through = files.at(-1).path;
|
|
40
|
+
else
|
|
41
|
+
files.push({ path: paths[at], revision });
|
|
42
|
+
}
|
|
43
|
+
return files.length === 0 ? null : { room: authority, through, files };
|
|
30
44
|
}
|
|
31
45
|
async function reused(scope, held) {
|
|
32
46
|
const sent = new Set(scope.contents.map((entry) => entry.path));
|
|
@@ -57,42 +71,71 @@ export function createAgentsHouseAdapter(options) {
|
|
|
57
71
|
throw new Error('no Discovery declared the bounds');
|
|
58
72
|
return bounds;
|
|
59
73
|
}
|
|
60
|
-
|
|
74
|
+
function hand(locator, steps) {
|
|
75
|
+
const held = handed.get(locator);
|
|
76
|
+
const next = stepped(steps);
|
|
77
|
+
if (!(next instanceof Promise)) {
|
|
78
|
+
handed.set(locator, next);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
return next.then((room) => {
|
|
82
|
+
if (handed.get(locator) === held)
|
|
83
|
+
handed.set(locator, room);
|
|
84
|
+
else
|
|
85
|
+
handed.delete(locator);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function fetchedPart(entry, continued, listed) {
|
|
89
|
+
for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
|
|
90
|
+
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
91
|
+
prefixes: [authorityRoot(entry.handle)],
|
|
92
|
+
part: listed.part,
|
|
93
|
+
...(continued.held === undefined ? {} : { held: [continued.held] }),
|
|
94
|
+
});
|
|
95
|
+
const failure = classifyRead(answered.status, answered.body, entry.locator);
|
|
96
|
+
if (failure !== null)
|
|
97
|
+
return failure;
|
|
98
|
+
const scope = await housePart(continued.room, answered.body, listed, 'credential');
|
|
99
|
+
if (scope !== null)
|
|
100
|
+
return scope;
|
|
101
|
+
}
|
|
102
|
+
return unverifiedPart(entry.locator);
|
|
103
|
+
}
|
|
104
|
+
async function partPage(asked, continued) {
|
|
61
105
|
const { entry } = asked;
|
|
62
|
-
|
|
63
|
-
|
|
106
|
+
const listed = continued.room.parts[continued.next];
|
|
107
|
+
const sent = listed === undefined
|
|
108
|
+
? emptyScope(continued.room)
|
|
109
|
+
: await fetchedPart(entry, continued, listed);
|
|
110
|
+
if ('kind' in sent)
|
|
111
|
+
return sent;
|
|
64
112
|
const scope = await reused(sent, asked.held);
|
|
65
113
|
if (scope === null) {
|
|
66
114
|
return asked.held === undefined
|
|
67
115
|
? UNCERTAIN_READ
|
|
68
|
-
:
|
|
69
|
-
? bootstrapTogether({ entry, held: undefined })
|
|
70
|
-
: continuedBootstrap({ entry, held: undefined }, continued);
|
|
116
|
+
: bootstrapTogether({ entry, held: undefined });
|
|
71
117
|
}
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
if (continued ===
|
|
75
|
-
|
|
118
|
+
const next = continued.next + 1;
|
|
119
|
+
const more = next < continued.room.parts.length;
|
|
120
|
+
if (continued.next === 0 && !more)
|
|
121
|
+
await hand(entry.locator, scopeHanded(scope));
|
|
76
122
|
else
|
|
77
123
|
handed.delete(entry.locator);
|
|
78
124
|
notifications.reach(entry.authority, scope);
|
|
79
125
|
const seen = [
|
|
80
|
-
...
|
|
126
|
+
...continued.seen,
|
|
81
127
|
...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
|
|
82
128
|
];
|
|
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 }) };
|
|
129
|
+
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
87
130
|
return {
|
|
88
|
-
...
|
|
131
|
+
...(await stepped(bootstrapping(scope))),
|
|
89
132
|
...(models === undefined ? {} : { models }),
|
|
90
|
-
...(
|
|
133
|
+
...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
|
|
91
134
|
};
|
|
92
135
|
}
|
|
93
136
|
async function enumeratedPage(ask, page) {
|
|
94
137
|
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
95
|
-
prefixes:
|
|
138
|
+
prefixes: [authorityRoot(ask.entry.handle)],
|
|
96
139
|
positions: [
|
|
97
140
|
{
|
|
98
141
|
...presented(ask.entry.authority, { position: page.after, logEpoch: ask.from.logEpoch }),
|
|
@@ -116,10 +159,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
116
159
|
if ('kind' in view)
|
|
117
160
|
return view;
|
|
118
161
|
notifications.reach(ask.entry.authority, view);
|
|
119
|
-
const answer = refreshFrom(view, ask.fromRoomVersion);
|
|
162
|
+
const answer = await refreshFrom(view, ask.fromRoomVersion);
|
|
120
163
|
if (answer.kind !== 'net-advancement')
|
|
121
164
|
return answer;
|
|
122
|
-
|
|
165
|
+
await hand(ask.entry.locator, enumeratedHanded(view, handed.get(ask.entry.locator)));
|
|
123
166
|
const models = await viewModels(view, ask.entry);
|
|
124
167
|
return models === undefined ? answer : { ...answer, models };
|
|
125
168
|
}
|
|
@@ -127,10 +170,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
127
170
|
const held = handed.get(entry.locator);
|
|
128
171
|
if (held?.roomVersion !== request.fromRoomVersion)
|
|
129
172
|
return null;
|
|
130
|
-
const advanced = notifications.advance(entry, from, (path, revision) => held.revisions
|
|
173
|
+
const advanced = await stepped(notifications.advance(entry, from, (path, revision) => held.revisions[path] === revision));
|
|
131
174
|
if (advanced === null)
|
|
132
175
|
return null;
|
|
133
|
-
|
|
176
|
+
await hand(entry.locator, streamedHanded(held, advanced));
|
|
134
177
|
const models = await streamedModels(advanced.schemas, entry, 'credential');
|
|
135
178
|
return models === undefined ? advanced.page : { ...advanced.page, models };
|
|
136
179
|
}
|
|
@@ -146,14 +189,20 @@ export function createAgentsHouseAdapter(options) {
|
|
|
146
189
|
});
|
|
147
190
|
notifications.send(kept);
|
|
148
191
|
}
|
|
149
|
-
function
|
|
192
|
+
async function adoptedMove(entry, into, outcome) {
|
|
193
|
+
if (outcome.kind === 'accepted' && outcome.destination !== undefined) {
|
|
194
|
+
await adopted(into, { kind: 'accepted', ...outcome.destination });
|
|
195
|
+
}
|
|
196
|
+
return adopted(entry, outcome);
|
|
197
|
+
}
|
|
198
|
+
async function adopted(entry, outcome) {
|
|
150
199
|
if (outcome.kind !== 'accepted')
|
|
151
200
|
return outcome;
|
|
152
201
|
const held = handed.get(entry.locator);
|
|
153
202
|
if (held === undefined)
|
|
154
203
|
return outcome;
|
|
155
204
|
const follows = followsVersion(held.roomVersion, outcome.roomVersion);
|
|
156
|
-
|
|
205
|
+
await hand(entry.locator, acceptedHanded(held, outcome, follows ? outcome.roomVersion : held.roomVersion));
|
|
157
206
|
const at = logPosition(outcome.roomVersion);
|
|
158
207
|
if (follows && at !== null)
|
|
159
208
|
notifications.reach(entry.authority, at);
|
|
@@ -176,68 +225,62 @@ export function createAgentsHouseAdapter(options) {
|
|
|
176
225
|
return result;
|
|
177
226
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
178
227
|
}
|
|
179
|
-
function
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
228
|
+
async function holding(asks) {
|
|
229
|
+
const bound = Math.floor(declared().max_held_files / Math.max(1, asks.filter((ask) => ask.held !== undefined).length));
|
|
230
|
+
const held = [];
|
|
231
|
+
for (const ask of asks) {
|
|
232
|
+
if (ask.held === undefined || bound === 0)
|
|
233
|
+
continue;
|
|
234
|
+
const paths = await sortedHeld(ask.held);
|
|
235
|
+
const files = heldFiles(ask.entry.authority, ask.held, paths, bound);
|
|
236
|
+
if (files !== null)
|
|
237
|
+
held.push(files);
|
|
238
|
+
}
|
|
239
|
+
return held;
|
|
185
240
|
}
|
|
186
241
|
async function bootstrapped(asks, answer) {
|
|
187
242
|
let open = asks.map((asked, ask) => ({ entry: asked.entry, asked, ask }));
|
|
188
243
|
while (open.length > 0) {
|
|
189
244
|
const unreached = [];
|
|
190
|
-
for (const part of selections(open,
|
|
191
|
-
const held = holding(part.map(({ asked }) => asked)
|
|
245
|
+
for (const part of selections(open, declared().max_prefixes)) {
|
|
246
|
+
const held = await holding(part.map(({ asked }) => asked));
|
|
192
247
|
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
193
|
-
prefixes: part.
|
|
248
|
+
prefixes: part.map(({ entry }) => authorityRoot(entry.handle)),
|
|
194
249
|
...(held.length === 0 ? {} : { held }),
|
|
195
250
|
});
|
|
196
251
|
const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
|
|
197
|
-
const
|
|
252
|
+
const parted = classified[0] === null ? parseParted(answered.body) : null;
|
|
198
253
|
for (const [index, asked] of part.entries()) {
|
|
199
254
|
const failure = classified[index];
|
|
200
255
|
if (failure !== null && failure !== undefined) {
|
|
201
256
|
answer(asked.ask, failure);
|
|
202
257
|
continue;
|
|
203
258
|
}
|
|
204
|
-
if (
|
|
259
|
+
if (parted === null) {
|
|
205
260
|
answer(asked.ask, UNCERTAIN_READ);
|
|
206
261
|
continue;
|
|
207
262
|
}
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
263
|
+
const room = parted.rooms.find((candidate) => candidate.anchor === asked.entry.authority);
|
|
264
|
+
if (room === undefined && parted.next !== undefined) {
|
|
210
265
|
unreached.push(asked);
|
|
211
266
|
continue;
|
|
212
267
|
}
|
|
213
|
-
|
|
268
|
+
if (room === undefined) {
|
|
269
|
+
answer(asked.ask, { kind: 'room-not-readable', locator: asked.entry.locator });
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const kept = held.find((files) => files.room === asked.entry.authority);
|
|
273
|
+
answer(asked.ask, await partPage(asked.asked, {
|
|
274
|
+
room,
|
|
275
|
+
next: 0,
|
|
276
|
+
seen: [],
|
|
277
|
+
...(kept === undefined ? {} : { held: kept }),
|
|
278
|
+
}));
|
|
214
279
|
}
|
|
215
280
|
}
|
|
216
281
|
open = unreached;
|
|
217
282
|
}
|
|
218
283
|
}
|
|
219
|
-
async function continuedBootstrap(asked, continued) {
|
|
220
|
-
const { entry } = asked;
|
|
221
|
-
const after = {
|
|
222
|
-
room: entry.authority,
|
|
223
|
-
path: continued.after,
|
|
224
|
-
...(continued.cut === undefined ? {} : { cut: continued.cut }),
|
|
225
|
-
};
|
|
226
|
-
const held = holding([asked], continued.after);
|
|
227
|
-
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
228
|
-
prefixes: contentPrefixes(entry),
|
|
229
|
-
after,
|
|
230
|
-
...(held.length === 0 ? {} : { held }),
|
|
231
|
-
});
|
|
232
|
-
const failure = classifyRead(answered.status, answered.body, entry.locator);
|
|
233
|
-
if (failure !== null)
|
|
234
|
-
return failure;
|
|
235
|
-
const envelope = parseEnvelope(answered.body);
|
|
236
|
-
if (envelope === null)
|
|
237
|
-
return UNCERTAIN_READ;
|
|
238
|
-
const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
|
|
239
|
-
return bootstrappedRoom(envelope, scope, asked, continued);
|
|
240
|
-
}
|
|
241
284
|
function layered(asks) {
|
|
242
285
|
const depths = new Map();
|
|
243
286
|
const layers = [];
|
|
@@ -250,12 +293,12 @@ export function createAgentsHouseAdapter(options) {
|
|
|
250
293
|
}
|
|
251
294
|
async function enumerated(asks) {
|
|
252
295
|
const answers = [];
|
|
253
|
-
const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer,
|
|
296
|
+
const parts = layered(asks.map((ask, index) => ({ ask, index }))).flatMap((layer) => selections(layer, declared().max_prefixes));
|
|
254
297
|
for (const part of parts) {
|
|
255
298
|
let open = [...part];
|
|
256
299
|
while (open.length > 0) {
|
|
257
300
|
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
258
|
-
prefixes: open.
|
|
301
|
+
prefixes: open.map(({ ask }) => authorityRoot(ask.entry.handle)),
|
|
259
302
|
positions: open.map(({ ask }) => presented(ask.entry.authority, ask.from)),
|
|
260
303
|
});
|
|
261
304
|
const classified = open.map(({ ask }) => classifyRead(answer.status, answer.body, ask.entry.locator));
|
|
@@ -294,7 +337,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
294
337
|
}
|
|
295
338
|
const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
|
|
296
339
|
if (minted.status !== 200) {
|
|
297
|
-
return {
|
|
340
|
+
return {
|
|
341
|
+
outcome: await stepped(mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)),
|
|
342
|
+
};
|
|
298
343
|
}
|
|
299
344
|
const grant = parseGrant(minted.body);
|
|
300
345
|
if (grant === null || grant.method !== 'POST')
|
|
@@ -336,7 +381,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
336
381
|
}
|
|
337
382
|
return true;
|
|
338
383
|
}
|
|
339
|
-
async function submit(batch, head, changes, delta, bytes, entry, handed, keep) {
|
|
384
|
+
async function submit(batch, head, changes, delta, bytes, entry, handed, keep, into) {
|
|
340
385
|
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
341
386
|
const prepared = uploadable(inline, bytes, declared())
|
|
342
387
|
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
@@ -350,7 +395,12 @@ export function createAgentsHouseAdapter(options) {
|
|
|
350
395
|
const settled = stagedFiles === null ? answer : await transport.door(DOOR_BATCH, prepared.body);
|
|
351
396
|
if (stagedFiles === true && (await staged(settled, batch)) !== null)
|
|
352
397
|
return UNCERTAIN;
|
|
353
|
-
return mutationOutcome(settled.status, settled.body, entry.locator, entry.handle
|
|
398
|
+
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
399
|
+
? undefined
|
|
400
|
+
: {
|
|
401
|
+
source: { authority: entry.authority, handle: entry.handle },
|
|
402
|
+
destination: { authority: into.authority, handle: into.handle },
|
|
403
|
+
}));
|
|
354
404
|
}
|
|
355
405
|
function granted(answer, locator) {
|
|
356
406
|
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
@@ -440,7 +490,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
440
490
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
441
491
|
const asked = { entry, held: request.held };
|
|
442
492
|
if (request.pageToken !== undefined) {
|
|
443
|
-
return
|
|
493
|
+
return partPage(asked, JSON.parse(request.pageToken));
|
|
444
494
|
}
|
|
445
495
|
return bootstrapTogether(asked);
|
|
446
496
|
},
|
|
@@ -462,18 +512,27 @@ export function createAgentsHouseAdapter(options) {
|
|
|
462
512
|
const entry = authorityFor(request.locator);
|
|
463
513
|
if (entry === undefined)
|
|
464
514
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
465
|
-
const
|
|
515
|
+
const batch = request.changeBatch;
|
|
516
|
+
const destination = batch.between?.destination.room;
|
|
517
|
+
const into = destination === undefined ? undefined : authorityFor(destination);
|
|
518
|
+
if (destination !== undefined && into === undefined) {
|
|
519
|
+
return { kind: 'room-not-readable', locator: destination };
|
|
520
|
+
}
|
|
521
|
+
const mapped = into === undefined
|
|
522
|
+
? houseChanges(batch, entry.handle)
|
|
523
|
+
: houseMove(batch, entry.handle, into.handle);
|
|
466
524
|
if (mapped.kind === 'unmapped')
|
|
467
525
|
return rejectedMapping(mapped);
|
|
468
|
-
const head = operationHead(
|
|
526
|
+
const head = operationHead(batch);
|
|
469
527
|
const delta = deltaBody(mapped.changes);
|
|
470
528
|
const bytes = deltaBytes(delta);
|
|
471
529
|
const handed = request.upload;
|
|
472
|
-
const
|
|
473
|
-
const
|
|
530
|
+
const answer = (upload) => submit(batch, head, mapped.changes, delta, bytes, entry, upload, keep, into);
|
|
531
|
+
const settle = (outcome) => into === undefined ? adopted(entry, outcome) : adoptedMove(entry, into, outcome);
|
|
532
|
+
const outcome = await answer(handed);
|
|
474
533
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
475
|
-
return
|
|
476
|
-
return
|
|
534
|
+
return settle(outcome);
|
|
535
|
+
return settle(await answer(undefined));
|
|
477
536
|
},
|
|
478
537
|
async history(_authorization, request) {
|
|
479
538
|
const entry = authorityFor(request.locator);
|
|
@@ -517,10 +576,8 @@ export function createAgentsHouseAdapter(options) {
|
|
|
517
576
|
const held = houseReferrer(referrer, tracked);
|
|
518
577
|
if (held === null)
|
|
519
578
|
return null;
|
|
520
|
-
if (held.locator === '')
|
|
521
|
-
return { kind: 'conversations' };
|
|
522
579
|
const { path } = held.referrer;
|
|
523
|
-
return {
|
|
580
|
+
return { locator: held.locator, ...(path === undefined ? {} : { path }) };
|
|
524
581
|
},
|
|
525
582
|
reached(locator, version, target) {
|
|
526
583
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
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 = {
|
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;
|
|
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,iBAA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S,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,YAAY,CAAC,EAAE,GACnE,SAAS,UAAU,EAAE,CAWvB;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
|
@@ -17,7 +17,8 @@ const BOUND_KEYS = [
|
|
|
17
17
|
'change_retention_seconds',
|
|
18
18
|
'operation_retention_seconds',
|
|
19
19
|
];
|
|
20
|
-
const OPERATION_KEYS = ['
|
|
20
|
+
const OPERATION_KEYS = ['write', 'delete'];
|
|
21
|
+
const READ_LEVELS = ['mcp', 'online', 'local'];
|
|
21
22
|
function stringList(value) {
|
|
22
23
|
if (!Array.isArray(value))
|
|
23
24
|
return null;
|
|
@@ -34,6 +35,12 @@ function parseBounds(value) {
|
|
|
34
35
|
return null;
|
|
35
36
|
bounds[key] = amount;
|
|
36
37
|
}
|
|
38
|
+
const moves = held.max_move_documents;
|
|
39
|
+
if (moves !== undefined) {
|
|
40
|
+
if (typeof moves !== 'number' || !Number.isFinite(moves))
|
|
41
|
+
return null;
|
|
42
|
+
bounds.max_move_documents = moves;
|
|
43
|
+
}
|
|
37
44
|
return bounds;
|
|
38
45
|
}
|
|
39
46
|
function parseHouseModel(value) {
|
|
@@ -85,7 +92,12 @@ function parseAuthority(value) {
|
|
|
85
92
|
const houseModel = parseHouseModel(held.house_model);
|
|
86
93
|
const protectedPaths = stringList(held.protected_paths);
|
|
87
94
|
const operations = parseOperations(held.operations);
|
|
88
|
-
|
|
95
|
+
const read = READ_LEVELS.find((level) => level === held.read);
|
|
96
|
+
if (at === null ||
|
|
97
|
+
houseModel === undefined ||
|
|
98
|
+
protectedPaths === null ||
|
|
99
|
+
read === undefined ||
|
|
100
|
+
operations === null)
|
|
89
101
|
return null;
|
|
90
102
|
if (typeof held.room_ref !== 'string' || held.room_ref.length === 0)
|
|
91
103
|
return null;
|
|
@@ -99,6 +111,7 @@ function parseAuthority(value) {
|
|
|
99
111
|
houseModel,
|
|
100
112
|
managedReplication: held.managed_replication,
|
|
101
113
|
protectedPaths,
|
|
114
|
+
read,
|
|
102
115
|
operations,
|
|
103
116
|
...at,
|
|
104
117
|
};
|
|
@@ -205,8 +218,11 @@ export function providerLimits(bounds) {
|
|
|
205
218
|
{ name: 'change-documents', value: bounds.max_batch_documents },
|
|
206
219
|
{ name: 'path-length', value: bounds.max_path_length },
|
|
207
220
|
{ name: 'path-depth', value: bounds.max_path_depth },
|
|
221
|
+
...(bounds.max_move_documents === undefined
|
|
222
|
+
? []
|
|
223
|
+
: [{ name: 'move-documents', value: bounds.max_move_documents }]),
|
|
208
224
|
{ name: 'write-rate' },
|
|
209
|
-
{ name: '
|
|
225
|
+
{ name: 'storage-limit' },
|
|
210
226
|
];
|
|
211
227
|
}
|
|
212
228
|
export function declaredRetention(bounds) {
|
|
@@ -244,12 +260,14 @@ export function discoveredRoom(authority) {
|
|
|
244
260
|
handle: authority.roomHandle,
|
|
245
261
|
roomVersion: roomVersion(authority),
|
|
246
262
|
operations: {
|
|
247
|
-
read: [...authority.operations.read],
|
|
248
|
-
sync: [...authority.operations.sync],
|
|
249
263
|
write: [...authority.operations.write],
|
|
250
264
|
delete: [...authority.operations.delete],
|
|
251
265
|
},
|
|
252
|
-
replica: {
|
|
266
|
+
replica: {
|
|
267
|
+
selection: locator,
|
|
268
|
+
admission: authority.managedReplication,
|
|
269
|
+
offline: authority.read === 'online' ? 'locked' : 'open',
|
|
270
|
+
},
|
|
253
271
|
...(authority.houseModel === null
|
|
254
272
|
? {}
|
|
255
273
|
: { typedSelection: { roots: [...authority.houseModel.paths] } }),
|
package/dist/gather.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function gatheredEach<A, R>(send: (asks: readonly A[], answer: (ask: number, result: R) => void) => Promise<void>): (ask: A) => Promise<R>;
|
|
2
2
|
export declare function gathered<A, R>(send: (asks: readonly A[]) => Promise<readonly R[]>): (ask: A) => Promise<R>;
|
|
3
|
-
export declare function selections<T>(items: readonly T[],
|
|
3
|
+
export declare function selections<T>(items: readonly T[], limit: number): readonly (readonly T[])[];
|
|
4
4
|
//# sourceMappingURL=gather.d.ts.map
|
package/dist/gather.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gather.d.ts","sourceRoot":"","sources":["../src/gather.ts"],"names":[],"mappings":"AAMA,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,GACpF,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAwBxB;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,GAClD,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAMxB;AAED,wBAAgB,UAAU,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"gather.d.ts","sourceRoot":"","sources":["../src/gather.ts"],"names":[],"mappings":"AAMA,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,GACpF,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAwBxB;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,GAClD,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAMxB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAO3F"}
|
package/dist/gather.js
CHANGED
|
@@ -25,21 +25,11 @@ export function gathered(send) {
|
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
export function selections(items,
|
|
28
|
+
export function selections(items, limit) {
|
|
29
|
+
const size = Math.max(1, limit);
|
|
29
30
|
const parts = [];
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
for (const item of items) {
|
|
33
|
-
const weighed = weight(item);
|
|
34
|
-
if (part.length > 0 && carried + weighed > limit) {
|
|
35
|
-
parts.push(part);
|
|
36
|
-
part = [];
|
|
37
|
-
carried = 0;
|
|
38
|
-
}
|
|
39
|
-
part.push(item);
|
|
40
|
-
carried += weighed;
|
|
31
|
+
for (let start = 0; start < items.length; start += size) {
|
|
32
|
+
parts.push(items.slice(start, start + size));
|
|
41
33
|
}
|
|
42
|
-
if (part.length > 0)
|
|
43
|
-
parts.push(part);
|
|
44
34
|
return parts;
|
|
45
35
|
}
|
package/dist/handed.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type HeldRoom, type MutationResult } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { HouseScope, HouseView } from './read.js';
|
|
3
3
|
import type { StreamedAdvancement } from './stream.js';
|
|
4
4
|
export type HandedRoom = {
|
|
5
5
|
roomVersion: string;
|
|
6
|
-
revisions:
|
|
6
|
+
revisions: Readonly<Record<string, string>>;
|
|
7
7
|
};
|
|
8
|
-
export declare function scopeHanded(scope: HouseScope): HandedRoom
|
|
8
|
+
export declare function scopeHanded(scope: HouseScope): Generator<number, HandedRoom, void>;
|
|
9
9
|
export declare function heldHanded(held: HeldRoom): HandedRoom;
|
|
10
10
|
export declare function acceptedHanded(held: HandedRoom, accepted: Extract<MutationResult, {
|
|
11
11
|
kind: 'accepted';
|
|
12
|
-
}>, roomVersion: string): HandedRoom
|
|
13
|
-
export declare function enumeratedHanded(view: HouseView, earlier: HandedRoom | undefined): HandedRoom
|
|
14
|
-
export declare function streamedHanded(held: HandedRoom, advanced: StreamedAdvancement): HandedRoom
|
|
12
|
+
}>, roomVersion: string): Generator<number, HandedRoom, void>;
|
|
13
|
+
export declare function enumeratedHanded(view: HouseView, earlier: HandedRoom | undefined): Generator<number, HandedRoom, void>;
|
|
14
|
+
export declare function streamedHanded(held: HandedRoom, advanced: StreamedAdvancement): Generator<number, HandedRoom, void>;
|
|
15
15
|
//# sourceMappingURL=handed.d.ts.map
|
package/dist/handed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handed.d.ts","sourceRoot":"","sources":["../src/handed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"handed.d.ts","sourceRoot":"","sources":["../src/handed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACjG,OAAO,KAAK,EAAqB,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC7C,CAAC;AAMF,wBAAiB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAEnF;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAErD;AAED,wBAAiB,cAAc,CAC7B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,EACvD,WAAW,EAAE,MAAM,GAClB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAKrC;AAgBD,wBAAiB,gBAAgB,CAC/B,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,UAAU,GAAG,SAAS,GAC9B,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAKrC;AAED,wBAAiB,cAAc,CAC7B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,mBAAmB,GAC5B,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAMrC"}
|