@agentshouse/mdruntime-adapter 0.1.0-c13e5bc38b145 → 0.1.0-c14f4ba3ce8c5
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 +83 -75
- package/dist/actions.d.ts +11 -21
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +59 -127
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +160 -175
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/model.d.ts +5 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -1
- package/dist/part.d.ts +15 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +82 -0
- package/dist/read.d.ts +37 -21
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +205 -121
- package/dist/room-types.d.ts +6 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +83 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +72 -100
- package/dist/stream.d.ts +1 -0
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +16 -1
- package/dist/transport.d.ts +10 -10
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +1 -1
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -0
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +13 -17
- package/package.json +3 -3
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -45
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -35
package/dist/adapter.js
CHANGED
|
@@ -1,67 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { stepped } from '@agentshouse/mdruntime';
|
|
2
2
|
import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
|
|
3
|
-
import { partModels, streamedModels, viewModels } from './model.js';
|
|
3
|
+
import { manifestedModels, partModels, streamedModels, viewModels } from './model.js';
|
|
4
4
|
import { gathered, gatheredEach, selections } from './gather.js';
|
|
5
5
|
import { createSiteAdapter } from './site.js';
|
|
6
|
-
import { authorityRoot, bootstrapping,
|
|
6
|
+
import { authorityRoot, bootstrapping, emptyScope, housePart, manifested, parseEnumeration, parseFileAddress, parseGrant, parseParted, partInventory, refreshFrom, viewOf, wholeView, } from './read.js';
|
|
7
|
+
import { PART_ATTEMPTS, partArrival, partFrame, unverifiedPart } from './part.js';
|
|
7
8
|
import { sha256Hex } from './digest.js';
|
|
8
|
-
import {
|
|
9
|
+
import { finishedUpload, houseUpload } from './upload.js';
|
|
9
10
|
import { houseAction } from './actions.js';
|
|
10
11
|
import { classifyDoor, classifyRead, discoveryFailure, doorRefusal } from './refusal.js';
|
|
11
12
|
import { houseNotifications } from './stream.js';
|
|
12
13
|
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
|
|
13
14
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
14
|
-
import {
|
|
15
|
+
import { HOUSE_ROOM_TYPES } from './room-types.js';
|
|
15
16
|
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
16
17
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
17
18
|
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
19
|
+
const EXPIRED_ADDRESS = 403;
|
|
18
20
|
function lapsedGrant(outcome) {
|
|
19
21
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
return known;
|
|
26
|
-
const sorted = await stepped(sortedKeys(held.documents));
|
|
27
|
-
heldPaths.set(held.documents, sorted);
|
|
28
|
-
return sorted;
|
|
29
|
-
}
|
|
30
|
-
function heldFiles(authority, held, paths, after, bound) {
|
|
31
|
-
let low = 0;
|
|
32
|
-
for (let high = paths.length; low < high;) {
|
|
33
|
-
const middle = (low + high) >>> 1;
|
|
34
|
-
if (after !== null && paths[middle] <= after)
|
|
35
|
-
low = middle + 1;
|
|
36
|
-
else
|
|
37
|
-
high = middle;
|
|
38
|
-
}
|
|
39
|
-
const files = [];
|
|
40
|
-
let through = null;
|
|
41
|
-
for (let at = low; at < paths.length && through === null; at += 1) {
|
|
42
|
-
const revision = held.revisions[paths[at]];
|
|
43
|
-
if (revision === undefined)
|
|
44
|
-
continue;
|
|
45
|
-
if (files.length === bound)
|
|
46
|
-
through = files.at(-1).path;
|
|
47
|
-
else
|
|
48
|
-
files.push({ path: paths[at], revision });
|
|
49
|
-
}
|
|
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;
|
|
50
27
|
return files.length === 0 ? null : { room: authority, through, files };
|
|
51
28
|
}
|
|
52
29
|
async function reused(scope, held) {
|
|
53
30
|
const sent = new Set(scope.contents.map((entry) => entry.path));
|
|
54
31
|
const contents = [...scope.contents];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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) {
|
|
62
43
|
return null;
|
|
63
44
|
}
|
|
64
|
-
contents.push({ path: file.path, content });
|
|
45
|
+
contents.push({ path: file.path, content: found.content });
|
|
65
46
|
}
|
|
66
47
|
return { ...scope, contents };
|
|
67
48
|
}
|
|
@@ -72,57 +53,78 @@ export function createAgentsHouseAdapter(options) {
|
|
|
72
53
|
const notifications = houseNotifications(transport, 'credential');
|
|
73
54
|
const tracked = new Map();
|
|
74
55
|
const handed = new Map();
|
|
56
|
+
let heldRevisions;
|
|
75
57
|
let bounds;
|
|
76
58
|
function declared() {
|
|
77
59
|
if (bounds === undefined)
|
|
78
60
|
throw new Error('no Discovery declared the bounds');
|
|
79
61
|
return bounds;
|
|
80
62
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
async function fetchedPart(entry, continued, listed, received, arriving) {
|
|
64
|
+
if (received !== undefined) {
|
|
65
|
+
const kept = new Uint8Array(received);
|
|
66
|
+
const held = await housePart(continued.room, kept, listed, 'credential');
|
|
67
|
+
if (held !== null)
|
|
68
|
+
return 'kind' in held ? held : { scope: held, frame: kept };
|
|
87
69
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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);
|
|
94
87
|
}
|
|
95
|
-
async function
|
|
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) {
|
|
96
98
|
const { entry } = asked;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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);
|
|
100
106
|
if (scope === null) {
|
|
101
107
|
return asked.held === undefined
|
|
102
108
|
? UNCERTAIN_READ
|
|
103
|
-
:
|
|
104
|
-
? bootstrapTogether({ entry, held: undefined })
|
|
105
|
-
: continuedBootstrap({ entry, held: undefined }, continued);
|
|
109
|
+
: bootstrapTogether({ entry, held: undefined });
|
|
106
110
|
}
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
if (continued ===
|
|
110
|
-
|
|
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));
|
|
111
115
|
else
|
|
112
116
|
handed.delete(entry.locator);
|
|
113
117
|
notifications.reach(entry.authority, scope);
|
|
114
118
|
const seen = [
|
|
115
|
-
...
|
|
119
|
+
...continued.seen,
|
|
116
120
|
...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
|
|
117
121
|
];
|
|
118
|
-
const models = await partModels(scope, entry, new Set(seen),
|
|
119
|
-
const continuation = next === null
|
|
120
|
-
? null
|
|
121
|
-
: { after: next, seen, ...(cursor?.cut === undefined ? {} : { cut: cursor.cut }) };
|
|
122
|
+
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
122
123
|
return {
|
|
123
124
|
...(await stepped(bootstrapping(scope))),
|
|
124
125
|
...(models === undefined ? {} : { models }),
|
|
125
|
-
...(
|
|
126
|
+
...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
|
|
127
|
+
...(sent.frame === null ? {} : { received: sent.frame }),
|
|
126
128
|
};
|
|
127
129
|
}
|
|
128
130
|
async function enumeratedPage(ask, page) {
|
|
@@ -154,18 +156,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
154
156
|
const answer = await refreshFrom(view, ask.fromRoomVersion);
|
|
155
157
|
if (answer.kind !== 'net-advancement')
|
|
156
158
|
return answer;
|
|
157
|
-
|
|
159
|
+
handed.set(ask.entry.locator, roomVersion(view));
|
|
158
160
|
const models = await viewModels(view, ask.entry);
|
|
159
161
|
return models === undefined ? answer : { ...answer, models };
|
|
160
162
|
}
|
|
161
163
|
async function streamed(entry, request, from) {
|
|
162
|
-
|
|
163
|
-
if (held?.roomVersion !== request.fromRoomVersion)
|
|
164
|
+
if (handed.get(entry.locator) !== request.fromRoomVersion)
|
|
164
165
|
return null;
|
|
165
|
-
const
|
|
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));
|
|
166
171
|
if (advanced === null)
|
|
167
172
|
return null;
|
|
168
|
-
|
|
173
|
+
handed.set(entry.locator, advanced.page.roomVersion);
|
|
169
174
|
const models = await streamedModels(advanced.schemas, entry, 'credential');
|
|
170
175
|
return models === undefined ? advanced.page : { ...advanced.page, models };
|
|
171
176
|
}
|
|
@@ -175,7 +180,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
175
180
|
const at = logPosition(room.roomVersion);
|
|
176
181
|
if (entry === undefined || at === null)
|
|
177
182
|
return [];
|
|
178
|
-
handed.set(room.locator,
|
|
183
|
+
handed.set(room.locator, room.roomVersion);
|
|
179
184
|
notifications.reach(entry.authority, at);
|
|
180
185
|
return [presented(entry.authority, at)];
|
|
181
186
|
});
|
|
@@ -193,8 +198,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
193
198
|
const held = handed.get(entry.locator);
|
|
194
199
|
if (held === undefined)
|
|
195
200
|
return outcome;
|
|
196
|
-
const follows = followsVersion(held
|
|
197
|
-
|
|
201
|
+
const follows = followsVersion(held, outcome.roomVersion);
|
|
202
|
+
if (follows)
|
|
203
|
+
handed.set(entry.locator, outcome.roomVersion);
|
|
198
204
|
const at = logPosition(outcome.roomVersion);
|
|
199
205
|
if (follows && at !== null)
|
|
200
206
|
notifications.reach(entry.authority, at);
|
|
@@ -217,14 +223,13 @@ export function createAgentsHouseAdapter(options) {
|
|
|
217
223
|
return result;
|
|
218
224
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
219
225
|
}
|
|
220
|
-
async function holding(asks
|
|
226
|
+
async function holding(asks) {
|
|
221
227
|
const bound = Math.floor(declared().max_held_files / Math.max(1, asks.filter((ask) => ask.held !== undefined).length));
|
|
222
228
|
const held = [];
|
|
223
229
|
for (const ask of asks) {
|
|
224
230
|
if (ask.held === undefined || bound === 0)
|
|
225
231
|
continue;
|
|
226
|
-
const
|
|
227
|
-
const files = heldFiles(ask.entry.authority, ask.held, paths, after, bound);
|
|
232
|
+
const files = await heldFiles(ask.entry.authority, ask.held, bound);
|
|
228
233
|
if (files !== null)
|
|
229
234
|
held.push(files);
|
|
230
235
|
}
|
|
@@ -235,56 +240,44 @@ export function createAgentsHouseAdapter(options) {
|
|
|
235
240
|
while (open.length > 0) {
|
|
236
241
|
const unreached = [];
|
|
237
242
|
for (const part of selections(open, declared().max_prefixes)) {
|
|
238
|
-
const held = await holding(part.map(({ asked }) => asked)
|
|
243
|
+
const held = await holding(part.map(({ asked }) => asked));
|
|
239
244
|
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
240
245
|
prefixes: part.map(({ entry }) => authorityRoot(entry.handle)),
|
|
241
246
|
...(held.length === 0 ? {} : { held }),
|
|
242
247
|
});
|
|
243
248
|
const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
|
|
244
|
-
const
|
|
249
|
+
const parted = classified[0] === null ? parseParted(answered.body) : null;
|
|
245
250
|
for (const [index, asked] of part.entries()) {
|
|
246
251
|
const failure = classified[index];
|
|
247
252
|
if (failure !== null && failure !== undefined) {
|
|
248
253
|
answer(asked.ask, failure);
|
|
249
254
|
continue;
|
|
250
255
|
}
|
|
251
|
-
if (
|
|
256
|
+
if (parted === null) {
|
|
252
257
|
answer(asked.ask, UNCERTAIN_READ);
|
|
253
258
|
continue;
|
|
254
259
|
}
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
260
|
+
const room = parted.rooms.find((candidate) => candidate.anchor === asked.entry.authority);
|
|
261
|
+
if (room === undefined && parted.next !== undefined) {
|
|
257
262
|
unreached.push(asked);
|
|
258
263
|
continue;
|
|
259
264
|
}
|
|
260
|
-
|
|
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
|
+
}));
|
|
261
276
|
}
|
|
262
277
|
}
|
|
263
278
|
open = unreached;
|
|
264
279
|
}
|
|
265
280
|
}
|
|
266
|
-
async function continuedBootstrap(asked, continued) {
|
|
267
|
-
const { entry } = asked;
|
|
268
|
-
const after = {
|
|
269
|
-
room: entry.authority,
|
|
270
|
-
path: continued.after,
|
|
271
|
-
...(continued.cut === undefined ? {} : { cut: continued.cut }),
|
|
272
|
-
};
|
|
273
|
-
const held = await holding([asked], continued.after);
|
|
274
|
-
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
275
|
-
prefixes: [authorityRoot(entry.handle)],
|
|
276
|
-
after,
|
|
277
|
-
...(held.length === 0 ? {} : { held }),
|
|
278
|
-
});
|
|
279
|
-
const failure = classifyRead(answered.status, answered.body, entry.locator);
|
|
280
|
-
if (failure !== null)
|
|
281
|
-
return failure;
|
|
282
|
-
const envelope = await stepped(parseEnvelope(answered.body));
|
|
283
|
-
if (envelope === null)
|
|
284
|
-
return UNCERTAIN_READ;
|
|
285
|
-
const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
|
|
286
|
-
return bootstrappedRoom(envelope, scope, asked, continued);
|
|
287
|
-
}
|
|
288
281
|
function layered(asks) {
|
|
289
282
|
const depths = new Map();
|
|
290
283
|
const layers = [];
|
|
@@ -346,7 +339,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
346
339
|
};
|
|
347
340
|
}
|
|
348
341
|
const grant = parseGrant(minted.body);
|
|
349
|
-
if (grant === null
|
|
342
|
+
if (grant === null)
|
|
350
343
|
return { outcome: UNCERTAIN };
|
|
351
344
|
const delivered = await transport.transfer({
|
|
352
345
|
act: 'authored_batch_upload',
|
|
@@ -356,36 +349,31 @@ export function createAgentsHouseAdapter(options) {
|
|
|
356
349
|
if (delivered.status !== 200)
|
|
357
350
|
return { outcome: UNCERTAIN };
|
|
358
351
|
const holding = parseGrant(delivered.body);
|
|
359
|
-
if (holding === null
|
|
352
|
+
if (holding === null)
|
|
360
353
|
return { outcome: UNCERTAIN };
|
|
361
354
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
362
355
|
await keep(upload);
|
|
363
356
|
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
364
357
|
}
|
|
365
|
-
async function staged(answer, batch) {
|
|
358
|
+
async function staged(answer, { changeBatch: batch, file }) {
|
|
366
359
|
const refusal = doorRefusal(answer.body);
|
|
367
360
|
if (refusal?.code !== 'files_unstaged')
|
|
368
361
|
return null;
|
|
369
|
-
const
|
|
370
|
-
if (!Array.isArray(
|
|
362
|
+
const uploads = refusal.fields.upload;
|
|
363
|
+
if (!Array.isArray(uploads))
|
|
371
364
|
return false;
|
|
372
|
-
for (const
|
|
373
|
-
const
|
|
374
|
-
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === sha256);
|
|
375
|
-
if (
|
|
365
|
+
for (const named of uploads) {
|
|
366
|
+
const upload = houseUpload(named);
|
|
367
|
+
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
|
|
368
|
+
if (upload === null || change === undefined)
|
|
376
369
|
return false;
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
url,
|
|
380
|
-
body: change.blob,
|
|
381
|
-
operation,
|
|
382
|
-
});
|
|
383
|
-
if (delivered.status !== 200)
|
|
370
|
+
const finished = await finishedUpload(transport, upload, await file(change.localId));
|
|
371
|
+
if (finished?.body?.staged !== true)
|
|
384
372
|
return false;
|
|
385
373
|
}
|
|
386
374
|
return true;
|
|
387
375
|
}
|
|
388
|
-
async function submit(
|
|
376
|
+
async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
|
|
389
377
|
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
390
378
|
const prepared = uploadable(inline, bytes, declared())
|
|
391
379
|
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
@@ -393,11 +381,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
393
381
|
if ('outcome' in prepared)
|
|
394
382
|
return prepared.outcome;
|
|
395
383
|
const answer = await transport.door(DOOR_BATCH, prepared.body);
|
|
396
|
-
const stagedFiles = await staged(answer,
|
|
384
|
+
const stagedFiles = await staged(answer, request);
|
|
397
385
|
if (stagedFiles === false)
|
|
398
386
|
return UNCERTAIN;
|
|
399
387
|
const settled = stagedFiles === null ? answer : await transport.door(DOOR_BATCH, prepared.body);
|
|
400
|
-
if (stagedFiles === true && (await staged(settled,
|
|
388
|
+
if (stagedFiles === true && (await staged(settled, request)) !== null)
|
|
401
389
|
return UNCERTAIN;
|
|
402
390
|
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
403
391
|
? undefined
|
|
@@ -406,7 +394,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
406
394
|
destination: { authority: into.authority, handle: into.handle },
|
|
407
395
|
}));
|
|
408
396
|
}
|
|
409
|
-
function
|
|
397
|
+
function addressed(answer, locator) {
|
|
410
398
|
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
411
399
|
if (failure !== null) {
|
|
412
400
|
return failure.kind === 'scoped-refusal'
|
|
@@ -418,33 +406,47 @@ export function createAgentsHouseAdapter(options) {
|
|
|
418
406
|
}
|
|
419
407
|
: failure;
|
|
420
408
|
}
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
if (grant === null || grant.method !== 'GET' || typeof name !== 'string') {
|
|
424
|
-
return UNCERTAIN_READ;
|
|
425
|
-
}
|
|
426
|
-
return { kind: 'link', url: grant.url, name };
|
|
409
|
+
const address = parseFileAddress(answer.body);
|
|
410
|
+
return address === null ? UNCERTAIN_READ : { kind: 'address', ...address };
|
|
427
411
|
}
|
|
428
|
-
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
412
|
+
function linked(answer, locator) {
|
|
413
|
+
const address = addressed(answer, locator);
|
|
414
|
+
return address.kind === 'address'
|
|
415
|
+
? { kind: 'link', url: address.url, name: address.name }
|
|
416
|
+
: address;
|
|
417
|
+
}
|
|
418
|
+
async function downloaded(ask, locator) {
|
|
419
|
+
let address = addressed(await ask(), locator);
|
|
420
|
+
if (address.kind !== 'address')
|
|
421
|
+
return address;
|
|
422
|
+
let read = await transport.download(address.url);
|
|
423
|
+
if (read.status === EXPIRED_ADDRESS) {
|
|
424
|
+
address = addressed(await ask(), locator);
|
|
425
|
+
if (address.kind !== 'address')
|
|
426
|
+
return address;
|
|
427
|
+
read = await transport.download(address.url);
|
|
428
|
+
}
|
|
429
|
+
if (read.status !== 200 || read.body === null)
|
|
434
430
|
return UNCERTAIN_READ;
|
|
435
|
-
return {
|
|
431
|
+
return {
|
|
432
|
+
kind: 'binary',
|
|
433
|
+
body: read.body,
|
|
434
|
+
mediaType: address.mediaType,
|
|
435
|
+
sha256: address.sha256,
|
|
436
|
+
};
|
|
436
437
|
}
|
|
437
|
-
function
|
|
438
|
+
function pathAddress(request) {
|
|
438
439
|
const entry = authorityFor(request.locator);
|
|
439
440
|
if (entry === undefined)
|
|
440
441
|
return null;
|
|
441
|
-
return transport.door(DOOR_FILES_GET, {
|
|
442
|
+
return () => transport.door(DOOR_FILES_GET, {
|
|
442
443
|
room_ref: entry.authority,
|
|
443
444
|
path: request.path,
|
|
444
445
|
revision: request.revision,
|
|
445
446
|
});
|
|
446
447
|
}
|
|
447
448
|
return {
|
|
449
|
+
roomTypes: HOUSE_ROOM_TYPES,
|
|
448
450
|
async authorize() {
|
|
449
451
|
return options.authorize();
|
|
450
452
|
},
|
|
@@ -494,7 +496,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
494
496
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
495
497
|
const asked = { entry, held: request.held };
|
|
496
498
|
if (request.pageToken !== undefined) {
|
|
497
|
-
return
|
|
499
|
+
return partPage(asked, JSON.parse(request.pageToken), request.received, request.arriving);
|
|
498
500
|
}
|
|
499
501
|
return bootstrapTogether(asked);
|
|
500
502
|
},
|
|
@@ -531,7 +533,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
531
533
|
const delta = deltaBody(mapped.changes);
|
|
532
534
|
const bytes = deltaBytes(delta);
|
|
533
535
|
const handed = request.upload;
|
|
534
|
-
const answer = (upload) => submit(
|
|
536
|
+
const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
|
|
535
537
|
const settle = (outcome) => into === undefined ? adopted(entry, outcome) : adoptedMove(entry, into, outcome);
|
|
536
538
|
const outcome = await answer(handed);
|
|
537
539
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
@@ -554,36 +556,16 @@ export function createAgentsHouseAdapter(options) {
|
|
|
554
556
|
});
|
|
555
557
|
},
|
|
556
558
|
async binary(_authorization, request) {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
return downloaded(await asked, request.locator);
|
|
562
|
-
}
|
|
563
|
-
const referrer = houseReferrer(request.referrer, tracked);
|
|
564
|
-
if (referrer === null) {
|
|
565
|
-
return { kind: 'rejected', code: 'referrer_unknown', fields: {}, retryable: false };
|
|
566
|
-
}
|
|
567
|
-
const answer = await transport.door(DOOR_FILES_GET, {
|
|
568
|
-
file: request.fileRef,
|
|
569
|
-
referrer: referrer.referrer,
|
|
570
|
-
});
|
|
571
|
-
return downloaded(answer, referrer.locator);
|
|
559
|
+
const ask = pathAddress(request);
|
|
560
|
+
if (ask === null)
|
|
561
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
562
|
+
return downloaded(ask, request.locator);
|
|
572
563
|
},
|
|
573
564
|
async link(_authorization, request) {
|
|
574
|
-
const
|
|
575
|
-
if (
|
|
565
|
+
const ask = pathAddress(request);
|
|
566
|
+
if (ask === null)
|
|
576
567
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
577
|
-
return
|
|
578
|
-
},
|
|
579
|
-
referrerScope(referrer) {
|
|
580
|
-
const held = houseReferrer(referrer, tracked);
|
|
581
|
-
if (held === null)
|
|
582
|
-
return null;
|
|
583
|
-
if (held.locator === '')
|
|
584
|
-
return { kind: 'conversations' };
|
|
585
|
-
const { path } = held.referrer;
|
|
586
|
-
return { kind: 'room', locator: held.locator, ...(path === undefined ? {} : { path }) };
|
|
568
|
+
return linked(await ask(), request.locator);
|
|
587
569
|
},
|
|
588
570
|
reached(locator, version, target) {
|
|
589
571
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
@@ -597,7 +579,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
597
579
|
roomStream: {
|
|
598
580
|
hold: held,
|
|
599
581
|
reopen: notifications.reopen,
|
|
600
|
-
observe
|
|
582
|
+
observe(notify, receipts, revisions) {
|
|
583
|
+
heldRevisions = revisions;
|
|
584
|
+
return notifications.observe(notify, receipts);
|
|
585
|
+
},
|
|
601
586
|
published(locator, roomVersion) {
|
|
602
587
|
const at = logPosition(roomVersion);
|
|
603
588
|
if (at !== null)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { createAgentsHouseAdapter, type AgentsHouseAdapterOptions } from './adapter.js';
|
|
2
|
-
export {
|
|
2
|
+
export { finishedUpload, houseUpload, type HouseUpload } from './upload.js';
|
|
3
|
+
export { HISTORY_PAGE, HOUSE_APP_ACTS, HOUSE_APP_BATCHES, HOUSE_SITE_ACTS, TRIGGER_ROOMS, } from './actions.js';
|
|
4
|
+
export { HOUSE_ROOM_TYPES, INBOX_CHANNEL_KINDS, INBOX_CHAT_TYPE, INBOX_MESSAGE_TYPE, type InboxChannelKind, } from './room-types.js';
|
|
3
5
|
export type { HouseByteAct, HouseByteTransfer, HouseBytesAnswer, HouseClosing, HouseDoorAnswer, HouseHeldRoom, HouseOpening, HouseStream, HouseStreamEntry, HouseStreamFrame, HouseSiteTransport, HouseTransport, } from './transport.js';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EACL,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { createAgentsHouseAdapter } from './adapter.js';
|
|
2
|
-
export {
|
|
2
|
+
export { finishedUpload, houseUpload } from './upload.js';
|
|
3
|
+
export { HISTORY_PAGE, HOUSE_APP_ACTS, HOUSE_APP_BATCHES, HOUSE_SITE_ACTS, TRIGGER_ROOMS, } from './actions.js';
|
|
4
|
+
export { HOUSE_ROOM_TYPES, INBOX_CHANNEL_KINDS, INBOX_CHAT_TYPE, INBOX_MESSAGE_TYPE, } from './room-types.js';
|
package/dist/model.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { RoomModels } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import { type HouseScope, type HouseView } from './read.js';
|
|
3
|
+
import { type HouseRoomParts, type HouseScope, type HouseView } from './read.js';
|
|
4
4
|
import type { HouseMode, HouseStreamEntry } from './transport.js';
|
|
5
5
|
export declare function partModels(scope: HouseScope, tracked: TrackedAuthority, seen: ReadonlySet<string>, final: boolean): Promise<RoomModels | undefined>;
|
|
6
|
+
export declare function manifestedModels(room: HouseRoomParts, tracked: TrackedAuthority): Promise<{
|
|
7
|
+
readonly models: RoomModels | undefined;
|
|
8
|
+
readonly seen: string[];
|
|
9
|
+
}>;
|
|
6
10
|
export declare function viewModels(view: HouseView, tracked: TrackedAuthority): Promise<RoomModels | undefined>;
|
|
7
11
|
export declare function streamedModels(schemas: ReadonlyMap<string, HouseStreamEntry>, tracked: TrackedAuthority, mode: HouseMode): Promise<RoomModels | undefined>;
|
|
8
12
|
//# sourceMappingURL=model.d.ts.map
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAIL,KAAK,cAAc,EAEnB,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAoClE,wBAAgB,UAAU,CACxB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EACzB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAKjC;AAED,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC;IAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAM/E;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAcjC;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAC9C,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAWjC"}
|
package/dist/model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sha256Hex } from './digest.js';
|
|
2
|
-
import { schemaOf, schemaPath } from './read.js';
|
|
2
|
+
import { modelScope, schemaOf, schemaPath, } from './read.js';
|
|
3
3
|
const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
|
|
4
4
|
const ABSENT_SCHEMA = { schema: null, version: null, revision: null };
|
|
5
5
|
async function heldModel(read, identity) {
|
|
@@ -33,6 +33,13 @@ export function partModels(scope, tracked, seen, final) {
|
|
|
33
33
|
return final && !seen.has(schema) ? ABSENT_SCHEMA : undefined;
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
+
export async function manifestedModels(room, tracked) {
|
|
37
|
+
const scope = modelScope(room);
|
|
38
|
+
return {
|
|
39
|
+
models: await partModels(scope, tracked, new Set(), true),
|
|
40
|
+
seen: tracked.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
36
43
|
export function viewModels(view, tracked) {
|
|
37
44
|
return modelsOf(tracked, (schema) => {
|
|
38
45
|
const change = view.changes.find((candidate) => candidate.path === schema);
|
package/dist/part.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ScopedRefusal } from '@agentshouse/mdruntime';
|
|
2
|
+
export declare const PART_ATTEMPTS = 3;
|
|
3
|
+
export declare const PART_UNVERIFIED = "part_unverified";
|
|
4
|
+
export type HousePart = {
|
|
5
|
+
part: string;
|
|
6
|
+
bytes: number;
|
|
7
|
+
sha256: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function parsePart(value: unknown): HousePart | null;
|
|
10
|
+
export declare function partArrival(listed: HousePart, arriving: ((bytes: number) => void) | undefined): ((answered: number) => void) | undefined;
|
|
11
|
+
export declare function partFrame(body: unknown): Uint8Array<ArrayBuffer> | null;
|
|
12
|
+
export declare function checkedPayload(frame: Uint8Array<ArrayBuffer>, listed: HousePart): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
13
|
+
export declare function gunzipped(payload: Uint8Array<ArrayBuffer>): ReadableStream<string>;
|
|
14
|
+
export declare function unverifiedPart(locator: string): ScopedRefusal;
|
|
15
|
+
//# sourceMappingURL=part.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"part.d.ts","sourceRoot":"","sources":["../src/part.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAU5D,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAEjD,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAO1D;AAoBD,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,GAC9C,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAG1C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAIvE;AAED,wBAAsB,cAAc,CAClC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,EAC9B,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAazC;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAKlF;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAS7D"}
|