@agentshouse/mdruntime-adapter 0.1.0-c40400228d833 → 0.1.0-c43b33ffa2341
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/actions.d.ts +4 -25
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +18 -150
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +205 -176
- package/dist/app-reference.d.ts +2 -0
- package/dist/app-reference.d.ts.map +1 -0
- package/dist/app-reference.js +2 -0
- package/dist/crockford.d.ts +4 -0
- package/dist/crockford.d.ts.map +1 -0
- package/dist/crockford.js +3 -0
- package/dist/discovery.d.ts +3 -8
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +13 -27
- package/dist/house-model.d.ts +2 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +485 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/model.d.ts +5 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +11 -13
- 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 +7 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +125 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +76 -100
- package/dist/stream.d.ts +1 -0
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +17 -2
- package/dist/transport.d.ts +11 -10
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +2 -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 +8 -4
- package/AGENTS.md +0 -304
- 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,49 @@
|
|
|
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
|
-
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
|
|
13
|
+
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_ATTACH, 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_NAMEABLE_ROOM_TYPES, 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 OCTET_STREAM = 'application/octet-stream';
|
|
20
|
+
const EXPIRED_ADDRESS = 403;
|
|
18
21
|
function lapsedGrant(outcome) {
|
|
19
22
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
20
23
|
}
|
|
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
|
-
}
|
|
24
|
+
async function heldFiles(authority, held, bound) {
|
|
25
|
+
const listed = await held.files(null, bound + 1);
|
|
26
|
+
const files = listed.slice(0, bound);
|
|
27
|
+
const through = listed.length > bound ? (files.at(-1)?.path ?? null) : null;
|
|
50
28
|
return files.length === 0 ? null : { room: authority, through, files };
|
|
51
29
|
}
|
|
52
30
|
async function reused(scope, held) {
|
|
53
31
|
const sent = new Set(scope.contents.map((entry) => entry.path));
|
|
54
32
|
const contents = [...scope.contents];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
33
|
+
const asked = scope.files.filter((file) => file.binary === undefined && !sent.has(file.path));
|
|
34
|
+
if (asked.length === 0)
|
|
35
|
+
return scope;
|
|
36
|
+
if (held === undefined)
|
|
37
|
+
return null;
|
|
38
|
+
const kept = await held.contents(asked.map(({ path }) => path));
|
|
39
|
+
for (const file of asked) {
|
|
40
|
+
const found = kept.get(file.path);
|
|
41
|
+
if (found === undefined ||
|
|
42
|
+
found.revision !== file.revision ||
|
|
43
|
+
(await sha256Hex(found.content)) !== file.sha256) {
|
|
62
44
|
return null;
|
|
63
45
|
}
|
|
64
|
-
contents.push({ path: file.path, content });
|
|
46
|
+
contents.push({ path: file.path, content: found.content });
|
|
65
47
|
}
|
|
66
48
|
return { ...scope, contents };
|
|
67
49
|
}
|
|
@@ -72,57 +54,78 @@ export function createAgentsHouseAdapter(options) {
|
|
|
72
54
|
const notifications = houseNotifications(transport, 'credential');
|
|
73
55
|
const tracked = new Map();
|
|
74
56
|
const handed = new Map();
|
|
57
|
+
let heldRevisions;
|
|
75
58
|
let bounds;
|
|
76
59
|
function declared() {
|
|
77
60
|
if (bounds === undefined)
|
|
78
61
|
throw new Error('no Discovery declared the bounds');
|
|
79
62
|
return bounds;
|
|
80
63
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
64
|
+
async function fetchedPart(entry, continued, listed, received, arriving) {
|
|
65
|
+
if (received !== undefined) {
|
|
66
|
+
const kept = new Uint8Array(received);
|
|
67
|
+
const held = await housePart(continued.room, kept, listed, 'credential');
|
|
68
|
+
if (held !== null)
|
|
69
|
+
return 'kind' in held ? held : { scope: held, frame: kept };
|
|
87
70
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
71
|
+
for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
|
|
72
|
+
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
73
|
+
prefixes: [authorityRoot(entry.handle)],
|
|
74
|
+
part: listed.part,
|
|
75
|
+
...(continued.held === undefined ? {} : { held: [continued.held] }),
|
|
76
|
+
}, partArrival(listed, arriving));
|
|
77
|
+
const failure = classifyRead(answered.status, answered.body, entry.locator);
|
|
78
|
+
if (failure !== null)
|
|
79
|
+
return failure;
|
|
80
|
+
const frame = partFrame(answered.body);
|
|
81
|
+
if (frame === null)
|
|
82
|
+
continue;
|
|
83
|
+
const scope = await housePart(continued.room, frame, listed, 'credential');
|
|
84
|
+
if (scope !== null)
|
|
85
|
+
return 'kind' in scope ? scope : { scope, frame };
|
|
86
|
+
}
|
|
87
|
+
return unverifiedPart(entry.locator);
|
|
88
|
+
}
|
|
89
|
+
async function manifestPage(asked, continued) {
|
|
90
|
+
const inventory = partInventory(continued.room);
|
|
91
|
+
if (inventory.parts === 0) {
|
|
92
|
+
const page = await partPage(asked, continued, undefined, undefined);
|
|
93
|
+
return page.kind === 'bootstrap' ? { ...page, inventory } : page;
|
|
94
|
+
}
|
|
95
|
+
const { models, seen } = await manifestedModels(continued.room, asked.entry);
|
|
96
|
+
return manifested(continued.room, inventory, JSON.stringify({ ...continued, seen }), models);
|
|
94
97
|
}
|
|
95
|
-
async function
|
|
98
|
+
async function partPage(asked, continued, received, arriving) {
|
|
96
99
|
const { entry } = asked;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
const listed = continued.room.parts[continued.next];
|
|
101
|
+
const sent = listed === undefined
|
|
102
|
+
? { scope: emptyScope(continued.room), frame: null }
|
|
103
|
+
: await fetchedPart(entry, continued, listed, received, arriving);
|
|
104
|
+
if ('kind' in sent)
|
|
105
|
+
return sent;
|
|
106
|
+
const scope = await reused(sent.scope, asked.held);
|
|
100
107
|
if (scope === null) {
|
|
101
108
|
return asked.held === undefined
|
|
102
109
|
? UNCERTAIN_READ
|
|
103
|
-
:
|
|
104
|
-
? bootstrapTogether({ entry, held: undefined })
|
|
105
|
-
: continuedBootstrap({ entry, held: undefined }, continued);
|
|
110
|
+
: bootstrapTogether({ entry, held: undefined });
|
|
106
111
|
}
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
if (continued ===
|
|
110
|
-
|
|
112
|
+
const next = continued.next + 1;
|
|
113
|
+
const more = next < continued.room.parts.length;
|
|
114
|
+
if (continued.next === 0 && !more)
|
|
115
|
+
handed.set(entry.locator, roomVersion(scope));
|
|
111
116
|
else
|
|
112
117
|
handed.delete(entry.locator);
|
|
113
118
|
notifications.reach(entry.authority, scope);
|
|
114
119
|
const seen = [
|
|
115
|
-
...
|
|
116
|
-
...
|
|
120
|
+
...continued.seen,
|
|
121
|
+
...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
|
|
117
122
|
];
|
|
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 }) };
|
|
123
|
+
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
122
124
|
return {
|
|
123
125
|
...(await stepped(bootstrapping(scope))),
|
|
124
126
|
...(models === undefined ? {} : { models }),
|
|
125
|
-
...(
|
|
127
|
+
...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
|
|
128
|
+
...(sent.frame === null ? {} : { received: sent.frame }),
|
|
126
129
|
};
|
|
127
130
|
}
|
|
128
131
|
async function enumeratedPage(ask, page) {
|
|
@@ -154,18 +157,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
154
157
|
const answer = await refreshFrom(view, ask.fromRoomVersion);
|
|
155
158
|
if (answer.kind !== 'net-advancement')
|
|
156
159
|
return answer;
|
|
157
|
-
|
|
160
|
+
handed.set(ask.entry.locator, roomVersion(view));
|
|
158
161
|
const models = await viewModels(view, ask.entry);
|
|
159
162
|
return models === undefined ? answer : { ...answer, models };
|
|
160
163
|
}
|
|
161
164
|
async function streamed(entry, request, from) {
|
|
162
|
-
|
|
163
|
-
if (held?.roomVersion !== request.fromRoomVersion)
|
|
165
|
+
if (handed.get(entry.locator) !== request.fromRoomVersion)
|
|
164
166
|
return null;
|
|
165
|
-
const
|
|
167
|
+
const asked = notifications.edited(entry, from);
|
|
168
|
+
const kept = asked.length === 0 || heldRevisions === undefined
|
|
169
|
+
? new Map()
|
|
170
|
+
: await heldRevisions(entry.locator, asked);
|
|
171
|
+
const advanced = await stepped(notifications.advance(entry, from, (path, revision) => kept.get(path) === revision));
|
|
166
172
|
if (advanced === null)
|
|
167
173
|
return null;
|
|
168
|
-
|
|
174
|
+
handed.set(entry.locator, advanced.page.roomVersion);
|
|
169
175
|
const models = await streamedModels(advanced.schemas, entry, 'credential');
|
|
170
176
|
return models === undefined ? advanced.page : { ...advanced.page, models };
|
|
171
177
|
}
|
|
@@ -175,7 +181,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
175
181
|
const at = logPosition(room.roomVersion);
|
|
176
182
|
if (entry === undefined || at === null)
|
|
177
183
|
return [];
|
|
178
|
-
handed.set(room.locator,
|
|
184
|
+
handed.set(room.locator, room.roomVersion);
|
|
179
185
|
notifications.reach(entry.authority, at);
|
|
180
186
|
return [presented(entry.authority, at)];
|
|
181
187
|
});
|
|
@@ -193,8 +199,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
193
199
|
const held = handed.get(entry.locator);
|
|
194
200
|
if (held === undefined)
|
|
195
201
|
return outcome;
|
|
196
|
-
const follows = followsVersion(held
|
|
197
|
-
|
|
202
|
+
const follows = followsVersion(held, outcome.roomVersion);
|
|
203
|
+
if (follows)
|
|
204
|
+
handed.set(entry.locator, outcome.roomVersion);
|
|
198
205
|
const at = logPosition(outcome.roomVersion);
|
|
199
206
|
if (follows && at !== null)
|
|
200
207
|
notifications.reach(entry.authority, at);
|
|
@@ -217,14 +224,13 @@ export function createAgentsHouseAdapter(options) {
|
|
|
217
224
|
return result;
|
|
218
225
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
219
226
|
}
|
|
220
|
-
async function holding(asks
|
|
227
|
+
async function holding(asks) {
|
|
221
228
|
const bound = Math.floor(declared().max_held_files / Math.max(1, asks.filter((ask) => ask.held !== undefined).length));
|
|
222
229
|
const held = [];
|
|
223
230
|
for (const ask of asks) {
|
|
224
231
|
if (ask.held === undefined || bound === 0)
|
|
225
232
|
continue;
|
|
226
|
-
const
|
|
227
|
-
const files = heldFiles(ask.entry.authority, ask.held, paths, after, bound);
|
|
233
|
+
const files = await heldFiles(ask.entry.authority, ask.held, bound);
|
|
228
234
|
if (files !== null)
|
|
229
235
|
held.push(files);
|
|
230
236
|
}
|
|
@@ -235,56 +241,44 @@ export function createAgentsHouseAdapter(options) {
|
|
|
235
241
|
while (open.length > 0) {
|
|
236
242
|
const unreached = [];
|
|
237
243
|
for (const part of selections(open, declared().max_prefixes)) {
|
|
238
|
-
const held = await holding(part.map(({ asked }) => asked)
|
|
244
|
+
const held = await holding(part.map(({ asked }) => asked));
|
|
239
245
|
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
240
246
|
prefixes: part.map(({ entry }) => authorityRoot(entry.handle)),
|
|
241
247
|
...(held.length === 0 ? {} : { held }),
|
|
242
248
|
});
|
|
243
249
|
const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
|
|
244
|
-
const
|
|
250
|
+
const parted = classified[0] === null ? parseParted(answered.body) : null;
|
|
245
251
|
for (const [index, asked] of part.entries()) {
|
|
246
252
|
const failure = classified[index];
|
|
247
253
|
if (failure !== null && failure !== undefined) {
|
|
248
254
|
answer(asked.ask, failure);
|
|
249
255
|
continue;
|
|
250
256
|
}
|
|
251
|
-
if (
|
|
257
|
+
if (parted === null) {
|
|
252
258
|
answer(asked.ask, UNCERTAIN_READ);
|
|
253
259
|
continue;
|
|
254
260
|
}
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
261
|
+
const room = parted.rooms.find((candidate) => candidate.anchor === asked.entry.authority);
|
|
262
|
+
if (room === undefined && parted.next !== undefined) {
|
|
257
263
|
unreached.push(asked);
|
|
258
264
|
continue;
|
|
259
265
|
}
|
|
260
|
-
|
|
266
|
+
if (room === undefined) {
|
|
267
|
+
answer(asked.ask, { kind: 'room-not-readable', locator: asked.entry.locator });
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const kept = held.find((files) => files.room === asked.entry.authority);
|
|
271
|
+
answer(asked.ask, await manifestPage(asked.asked, {
|
|
272
|
+
room,
|
|
273
|
+
next: 0,
|
|
274
|
+
seen: [],
|
|
275
|
+
...(kept === undefined ? {} : { held: kept }),
|
|
276
|
+
}));
|
|
261
277
|
}
|
|
262
278
|
}
|
|
263
279
|
open = unreached;
|
|
264
280
|
}
|
|
265
281
|
}
|
|
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
282
|
function layered(asks) {
|
|
289
283
|
const depths = new Map();
|
|
290
284
|
const layers = [];
|
|
@@ -346,7 +340,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
346
340
|
};
|
|
347
341
|
}
|
|
348
342
|
const grant = parseGrant(minted.body);
|
|
349
|
-
if (grant === null
|
|
343
|
+
if (grant === null)
|
|
350
344
|
return { outcome: UNCERTAIN };
|
|
351
345
|
const delivered = await transport.transfer({
|
|
352
346
|
act: 'authored_batch_upload',
|
|
@@ -356,36 +350,31 @@ export function createAgentsHouseAdapter(options) {
|
|
|
356
350
|
if (delivered.status !== 200)
|
|
357
351
|
return { outcome: UNCERTAIN };
|
|
358
352
|
const holding = parseGrant(delivered.body);
|
|
359
|
-
if (holding === null
|
|
353
|
+
if (holding === null)
|
|
360
354
|
return { outcome: UNCERTAIN };
|
|
361
355
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
362
356
|
await keep(upload);
|
|
363
357
|
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
364
358
|
}
|
|
365
|
-
async function staged(answer, batch) {
|
|
359
|
+
async function staged(answer, { changeBatch: batch, file }) {
|
|
366
360
|
const refusal = doorRefusal(answer.body);
|
|
367
361
|
if (refusal?.code !== 'files_unstaged')
|
|
368
362
|
return null;
|
|
369
|
-
const
|
|
370
|
-
if (!Array.isArray(
|
|
363
|
+
const uploads = refusal.fields.upload;
|
|
364
|
+
if (!Array.isArray(uploads))
|
|
371
365
|
return false;
|
|
372
|
-
for (const
|
|
373
|
-
const
|
|
374
|
-
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === sha256);
|
|
375
|
-
if (
|
|
366
|
+
for (const named of uploads) {
|
|
367
|
+
const upload = houseUpload(named);
|
|
368
|
+
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
|
|
369
|
+
if (upload === null || change === undefined)
|
|
376
370
|
return false;
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
url,
|
|
380
|
-
body: change.blob,
|
|
381
|
-
operation,
|
|
382
|
-
});
|
|
383
|
-
if (delivered.status !== 200)
|
|
371
|
+
const finished = await finishedUpload(transport, upload, await file(change.localId));
|
|
372
|
+
if (finished?.body?.staged !== true)
|
|
384
373
|
return false;
|
|
385
374
|
}
|
|
386
375
|
return true;
|
|
387
376
|
}
|
|
388
|
-
async function submit(
|
|
377
|
+
async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
|
|
389
378
|
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
390
379
|
const prepared = uploadable(inline, bytes, declared())
|
|
391
380
|
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
@@ -393,11 +382,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
393
382
|
if ('outcome' in prepared)
|
|
394
383
|
return prepared.outcome;
|
|
395
384
|
const answer = await transport.door(DOOR_BATCH, prepared.body);
|
|
396
|
-
const stagedFiles = await staged(answer,
|
|
385
|
+
const stagedFiles = await staged(answer, request);
|
|
397
386
|
if (stagedFiles === false)
|
|
398
387
|
return UNCERTAIN;
|
|
399
388
|
const settled = stagedFiles === null ? answer : await transport.door(DOOR_BATCH, prepared.body);
|
|
400
|
-
if (stagedFiles === true && (await staged(settled,
|
|
389
|
+
if (stagedFiles === true && (await staged(settled, request)) !== null)
|
|
401
390
|
return UNCERTAIN;
|
|
402
391
|
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
403
392
|
? undefined
|
|
@@ -406,7 +395,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
406
395
|
destination: { authority: into.authority, handle: into.handle },
|
|
407
396
|
}));
|
|
408
397
|
}
|
|
409
|
-
function
|
|
398
|
+
function addressed(answer, locator) {
|
|
410
399
|
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
411
400
|
if (failure !== null) {
|
|
412
401
|
return failure.kind === 'scoped-refusal'
|
|
@@ -418,33 +407,61 @@ export function createAgentsHouseAdapter(options) {
|
|
|
418
407
|
}
|
|
419
408
|
: failure;
|
|
420
409
|
}
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
return
|
|
410
|
+
const address = parseFileAddress(answer.body);
|
|
411
|
+
return address === null ? UNCERTAIN_READ : { kind: 'address', ...address };
|
|
412
|
+
}
|
|
413
|
+
function linked(answer, locator) {
|
|
414
|
+
const address = addressed(answer, locator);
|
|
415
|
+
return address.kind === 'address'
|
|
416
|
+
? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
|
|
417
|
+
: address;
|
|
418
|
+
}
|
|
419
|
+
function refusedAttach(answer, locator) {
|
|
420
|
+
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
421
|
+
if (failure === null)
|
|
422
|
+
return null;
|
|
423
|
+
return failure.kind === 'scoped-refusal'
|
|
424
|
+
? {
|
|
425
|
+
kind: 'rejected',
|
|
426
|
+
code: failure.code,
|
|
427
|
+
fields: failure.fields,
|
|
428
|
+
retryable: failure.retryable,
|
|
429
|
+
}
|
|
430
|
+
: failure;
|
|
427
431
|
}
|
|
428
|
-
async function downloaded(
|
|
429
|
-
|
|
430
|
-
if (
|
|
431
|
-
return
|
|
432
|
-
|
|
433
|
-
if (read.status
|
|
432
|
+
async function downloaded(ask, locator) {
|
|
433
|
+
let address = addressed(await ask(), locator);
|
|
434
|
+
if (address.kind !== 'address')
|
|
435
|
+
return address;
|
|
436
|
+
let read = await transport.download(address.url);
|
|
437
|
+
if (read.status === EXPIRED_ADDRESS) {
|
|
438
|
+
address = addressed(await ask(), locator);
|
|
439
|
+
if (address.kind !== 'address')
|
|
440
|
+
return address;
|
|
441
|
+
read = await transport.download(address.url);
|
|
442
|
+
}
|
|
443
|
+
if (read.status !== 200 || read.body === null)
|
|
434
444
|
return UNCERTAIN_READ;
|
|
435
|
-
return {
|
|
445
|
+
return {
|
|
446
|
+
kind: 'binary',
|
|
447
|
+
body: read.body,
|
|
448
|
+
mediaType: address.mediaType,
|
|
449
|
+
sha256: address.sha256,
|
|
450
|
+
};
|
|
436
451
|
}
|
|
437
|
-
function
|
|
452
|
+
function pathAddress(request) {
|
|
438
453
|
const entry = authorityFor(request.locator);
|
|
439
454
|
if (entry === undefined)
|
|
440
455
|
return null;
|
|
441
|
-
return transport.door(DOOR_FILES_GET, {
|
|
456
|
+
return () => transport.door(DOOR_FILES_GET, {
|
|
442
457
|
room_ref: entry.authority,
|
|
443
458
|
path: request.path,
|
|
444
459
|
revision: request.revision,
|
|
445
460
|
});
|
|
446
461
|
}
|
|
447
462
|
return {
|
|
463
|
+
roomTypes: HOUSE_ROOM_TYPES,
|
|
464
|
+
nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
|
|
448
465
|
async authorize() {
|
|
449
466
|
return options.authorize();
|
|
450
467
|
},
|
|
@@ -494,7 +511,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
494
511
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
495
512
|
const asked = { entry, held: request.held };
|
|
496
513
|
if (request.pageToken !== undefined) {
|
|
497
|
-
return
|
|
514
|
+
return partPage(asked, JSON.parse(request.pageToken), request.received, request.arriving);
|
|
498
515
|
}
|
|
499
516
|
return bootstrapTogether(asked);
|
|
500
517
|
},
|
|
@@ -531,7 +548,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
531
548
|
const delta = deltaBody(mapped.changes);
|
|
532
549
|
const bytes = deltaBytes(delta);
|
|
533
550
|
const handed = request.upload;
|
|
534
|
-
const answer = (upload) => submit(
|
|
551
|
+
const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
|
|
535
552
|
const settle = (outcome) => into === undefined ? adopted(entry, outcome) : adoptedMove(entry, into, outcome);
|
|
536
553
|
const outcome = await answer(handed);
|
|
537
554
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
@@ -554,36 +571,45 @@ export function createAgentsHouseAdapter(options) {
|
|
|
554
571
|
});
|
|
555
572
|
},
|
|
556
573
|
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);
|
|
574
|
+
const ask = pathAddress(request);
|
|
575
|
+
if (ask === null)
|
|
576
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
577
|
+
return downloaded(ask, request.locator);
|
|
572
578
|
},
|
|
573
579
|
async link(_authorization, request) {
|
|
574
|
-
const
|
|
575
|
-
if (
|
|
580
|
+
const ask = pathAddress(request);
|
|
581
|
+
if (ask === null)
|
|
576
582
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
577
|
-
return
|
|
583
|
+
return linked(await ask(), request.locator);
|
|
578
584
|
},
|
|
579
|
-
|
|
580
|
-
const
|
|
581
|
-
if (
|
|
582
|
-
return
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
585
|
+
async attach(_authorization, request) {
|
|
586
|
+
const entry = authorityFor(request.locator);
|
|
587
|
+
if (entry === undefined)
|
|
588
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
589
|
+
const declared = await transport.door(DOOR_FILES_ATTACH, {
|
|
590
|
+
room_ref: entry.authority,
|
|
591
|
+
name: request.name,
|
|
592
|
+
bytes: request.byteLength,
|
|
593
|
+
sha256: request.sha256,
|
|
594
|
+
media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
|
|
595
|
+
});
|
|
596
|
+
const refused = refusedAttach(declared, request.locator);
|
|
597
|
+
if (refused !== null)
|
|
598
|
+
return refused;
|
|
599
|
+
const upload = houseUpload(declared.body?.upload);
|
|
600
|
+
if (upload === null)
|
|
601
|
+
return UNCERTAIN_READ;
|
|
602
|
+
const finished = await finishedUpload(transport, upload, request.blob);
|
|
603
|
+
if (finished === null)
|
|
604
|
+
return UNCERTAIN_READ;
|
|
605
|
+
const unfinished = refusedAttach(finished, request.locator);
|
|
606
|
+
if (unfinished !== null)
|
|
607
|
+
return unfinished;
|
|
608
|
+
const { path, revision } = (finished.body ?? {});
|
|
609
|
+
const root = `/rooms/${entry.handle}/`;
|
|
610
|
+
return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
|
|
611
|
+
? { kind: 'attached', path: path.slice(root.length), revision }
|
|
612
|
+
: UNCERTAIN_READ;
|
|
587
613
|
},
|
|
588
614
|
reached(locator, version, target) {
|
|
589
615
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
@@ -597,7 +623,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
597
623
|
roomStream: {
|
|
598
624
|
hold: held,
|
|
599
625
|
reopen: notifications.reopen,
|
|
600
|
-
observe
|
|
626
|
+
observe(notify, receipts, revisions) {
|
|
627
|
+
heldRevisions = revisions;
|
|
628
|
+
return notifications.observe(notify, receipts);
|
|
629
|
+
},
|
|
601
630
|
published(locator, roomVersion) {
|
|
602
631
|
const at = logPosition(roomVersion);
|
|
603
632
|
if (at !== null)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-reference.d.ts","sourceRoot":"","sources":["../src/app-reference.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,QAEjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crockford.d.ts","sourceRoot":"","sources":["../src/crockford.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAErE,eAAO,MAAM,mBAAmB,uCAA4B,CAAC;AAE7D,eAAO,MAAM,2BAA2B,QAAqC,CAAC"}
|