@agentshouse/mdruntime-adapter 0.1.0-c17fae3d012d0 → 0.1.0-c18e9b633b5bc
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 +5 -5
- package/dist/actions.d.ts +10 -6
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +69 -324
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +310 -264
- package/dist/authored-path.d.ts +61 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +166 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +281 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +48 -28
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +268 -87
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +8 -19
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +43 -39
- package/dist/read.d.ts +55 -48
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +208 -267
- package/dist/refusal.d.ts +10 -13
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +54 -24
- package/dist/renamed.d.ts +10 -0
- package/dist/renamed.d.ts.map +1 -0
- package/dist/renamed.js +29 -0
- package/dist/room-query.d.ts +4 -0
- package/dist/room-query.d.ts.map +1 -0
- package/dist/room-query.js +63 -0
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/check.d.ts +17 -0
- package/dist/session-content/index.d.ts +6 -0
- package/dist/session-content/parts.d.ts +30 -0
- package/dist/session-content/state.d.ts +59 -0
- package/dist/session-content/turn.d.ts +137 -0
- package/dist/site.d.ts +1 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +165 -145
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +17 -12
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +327 -145
- package/dist/transport.d.ts +156 -28
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +95 -10
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +17 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +106 -0
- package/dist/version.d.ts +2 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +10 -1
- package/dist/write.d.ts +18 -4
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +182 -72
- package/package.json +11 -7
- package/AGENTS.md +0 -207
- package/dist/gather.d.ts +0 -3
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -40
- package/dist/links.d.ts +0 -12
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -66
package/dist/adapter.js
CHANGED
|
@@ -1,107 +1,131 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
|
|
2
|
+
import { stepped } from '@agentshouse/mdruntime';
|
|
3
|
+
import { capabilities, discoveredRoom, mapDiscovery, parseAuthorityChange, parseDiscovery, trackedFrom, } from './discovery.js';
|
|
4
4
|
import { createSiteAdapter } from './site.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
import { parseFileAddress, parseGrant } from './read.js';
|
|
6
|
+
import { chunkedHead, chunkLister, chunkPart } from './chunks.js';
|
|
7
|
+
import { finishedUpload, houseUpload, stagedBatch } from './upload.js';
|
|
8
|
+
import { houseAction, HOUSE_LEADING_READS, HOUSE_RENAMED_UNTIL_2026_12_18, HOUSE_RENAMED_UNTIL_2026_12_21, HOUSE_REWRITTEN_UNTIL_2026_12_19, HOUSE_REWRITTEN_UNTIL_2026_12_21, HOUSE_UNKEPT_READS, } from './actions.js';
|
|
9
|
+
import { houseQuery } from './room-query.js';
|
|
10
|
+
import { houseSearch } from './search.js';
|
|
11
|
+
import { answeredFailure, classifyDoor, keyedFailure } from './refusal.js';
|
|
12
|
+
import { UNANSWERED, unusable } from './uncertain.js';
|
|
13
|
+
import { houseNotifications, } from './stream.js';
|
|
14
|
+
import { houseDoorRoute, } from './transport.js';
|
|
15
|
+
import { renamedHandle } from './renamed.js';
|
|
16
|
+
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
17
|
+
import { admittedPath } from './authored-path.js';
|
|
18
|
+
import { followsVersion, reachedVersion, roomVersion } from './version.js';
|
|
19
|
+
const EXPIRED_ADDRESS = 403;
|
|
15
20
|
function lapsedGrant(outcome) {
|
|
16
21
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
17
22
|
}
|
|
18
|
-
function modelFailure(classified, envelope) {
|
|
19
|
-
if (classified === null) {
|
|
20
|
-
return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;
|
|
21
|
-
}
|
|
22
|
-
return failedModel(classified);
|
|
23
|
-
}
|
|
24
23
|
export function createAgentsHouseAdapter(options) {
|
|
25
24
|
if ('site' in options)
|
|
26
|
-
return createSiteAdapter(options.site);
|
|
25
|
+
return createSiteAdapter(options.site, options.snapshot === true);
|
|
27
26
|
const transport = options.transport;
|
|
28
|
-
const notifications = houseNotifications(transport, 'credential'
|
|
27
|
+
const notifications = houseNotifications(transport, 'credential', {
|
|
28
|
+
opened: async (frame) => (frame === null ? null : opened(frame)),
|
|
29
|
+
changed,
|
|
30
|
+
expired: (entries) => lister.askAll(entries),
|
|
31
|
+
});
|
|
29
32
|
const tracked = new Map();
|
|
30
|
-
const
|
|
31
|
-
const
|
|
33
|
+
const lister = chunkLister(transport, () => declared().max_prefixes, (locator) => tracked.get(locator));
|
|
34
|
+
const chunked = new Map();
|
|
35
|
+
const renewals = new WeakMap();
|
|
32
36
|
let bounds;
|
|
33
37
|
function declared() {
|
|
34
38
|
if (bounds === undefined)
|
|
35
39
|
throw new Error('no Discovery declared the bounds');
|
|
36
40
|
return bounds;
|
|
37
41
|
}
|
|
38
|
-
function
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
return { kind: 'room-not-readable', locator: entry.locator };
|
|
42
|
-
handed.set(entry.locator, scopeLinks(scope));
|
|
43
|
-
notifications.hold(entry.authority, scope);
|
|
44
|
-
return bootstrapOf(scope);
|
|
45
|
-
}
|
|
46
|
-
function enumeratedRoom(enumeration, ask) {
|
|
47
|
-
const view = viewOf(enumeration, ask.entry);
|
|
48
|
-
if (view === undefined)
|
|
49
|
-
return { kind: 'room-not-readable', locator: ask.entry.locator };
|
|
50
|
-
notifications.hold(ask.entry.authority, view);
|
|
51
|
-
const answer = refreshFrom(view, ask.fromRoomVersion);
|
|
52
|
-
if (answer.kind === 'net-advancement') {
|
|
53
|
-
handed.set(ask.entry.locator, enumeratedLinks(view, handed.get(ask.entry.locator)));
|
|
54
|
-
}
|
|
55
|
-
return answer;
|
|
56
|
-
}
|
|
57
|
-
function streamed(entry, request, from) {
|
|
58
|
-
const links = handed.get(entry.locator);
|
|
59
|
-
if (links?.roomVersion !== request.fromRoomVersion)
|
|
42
|
+
function opened(frame) {
|
|
43
|
+
const document = parseDiscovery(frame);
|
|
44
|
+
if (document === null)
|
|
60
45
|
return null;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
46
|
+
bounds = document.bounds;
|
|
47
|
+
tracked.clear();
|
|
48
|
+
lister.forget();
|
|
49
|
+
for (const entry of trackedFrom(document))
|
|
50
|
+
tracked.set(entry.locator, entry);
|
|
51
|
+
notifications.track([...tracked.values()]);
|
|
52
|
+
return {
|
|
53
|
+
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
54
|
+
member: document.member,
|
|
55
|
+
timeZone: document.timeZone,
|
|
56
|
+
roomList: document.roomList,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function changed(frame) {
|
|
60
|
+
const change = parseAuthorityChange(frame);
|
|
61
|
+
if (change === null)
|
|
69
62
|
return null;
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
const unheld = [...change.left, ...change.listed];
|
|
64
|
+
for (const locator of unheld)
|
|
65
|
+
tracked.delete(locator);
|
|
66
|
+
for (const entry of trackedFrom(change))
|
|
67
|
+
tracked.set(entry.locator, entry);
|
|
68
|
+
notifications.track([...tracked.values()]);
|
|
69
|
+
return {
|
|
70
|
+
kind: 'authority-changed',
|
|
71
|
+
rooms: change.authorities.map((authority) => discoveredRoom(authority)),
|
|
72
|
+
left: unheld,
|
|
73
|
+
member: change.member,
|
|
74
|
+
timeZone: change.timeZone,
|
|
75
|
+
roomList: { ...change.roomList, left: change.left },
|
|
76
|
+
};
|
|
72
77
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
78
|
+
async function listedRoom(entry) {
|
|
79
|
+
const listed = await lister.list(entry);
|
|
80
|
+
if ('kind' in listed)
|
|
81
|
+
return listed;
|
|
82
|
+
const head = await chunkedHead(listed, entry);
|
|
83
|
+
if (head.kind === 'bootstrap')
|
|
84
|
+
chunked.set(entry.locator, listed);
|
|
85
|
+
return head;
|
|
75
86
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
87
|
+
async function chunkRead(entry, id) {
|
|
88
|
+
const room = chunked.get(entry.locator);
|
|
89
|
+
const address = room?.chunks.get(id);
|
|
90
|
+
if (room === undefined || address === undefined)
|
|
91
|
+
return UNANSWERED;
|
|
92
|
+
const read = await transport.download(address.url);
|
|
93
|
+
if (read.status !== EXPIRED_ADDRESS)
|
|
94
|
+
return { room, read };
|
|
95
|
+
const renewed = await renewal(entry, room);
|
|
96
|
+
if ('kind' in renewed)
|
|
97
|
+
return renewed;
|
|
98
|
+
const renewedAddress = renewed.chunks.get(id);
|
|
99
|
+
if (renewedAddress === undefined)
|
|
100
|
+
return unusable();
|
|
101
|
+
chunked.set(entry.locator, renewed);
|
|
102
|
+
return { room: renewed, read: await transport.download(renewedAddress.url) };
|
|
78
103
|
}
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
104
|
+
function renewal(entry, stale) {
|
|
105
|
+
const held = renewals.get(stale);
|
|
106
|
+
if (held !== undefined)
|
|
107
|
+
return held;
|
|
108
|
+
const renewed = lister.renew(entry, [...chunked.keys()].flatMap((locator) => tracked.get(locator) ?? []));
|
|
109
|
+
renewals.set(stale, renewed);
|
|
110
|
+
return renewed;
|
|
111
|
+
}
|
|
112
|
+
function hold(rooms) {
|
|
113
|
+
for (const room of rooms) {
|
|
114
|
+
const listed = chunked.get(room.locator);
|
|
115
|
+
if (listed !== undefined &&
|
|
116
|
+
room.roomVersion !== null &&
|
|
117
|
+
reachedVersion(room.roomVersion, roomVersion(listed), listed.logEpoch))
|
|
118
|
+
chunked.delete(room.locator);
|
|
94
119
|
}
|
|
95
|
-
|
|
120
|
+
notifications.send(rooms);
|
|
96
121
|
}
|
|
97
|
-
function
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return discoveredRoom(authority, collection?.identity ?? null, selection?.identity ?? null);
|
|
122
|
+
async function chunkPage(entry, id, arriving) {
|
|
123
|
+
const fetched = await chunkRead(entry, id);
|
|
124
|
+
if ('kind' in fetched)
|
|
125
|
+
return fetched;
|
|
126
|
+
if (fetched.read.status !== 200)
|
|
127
|
+
return answeredFailure(fetched.read.status, null);
|
|
128
|
+
return chunkPart(fetched.read.body, fetched.room, id, arriving);
|
|
105
129
|
}
|
|
106
130
|
function authorityFor(locator) {
|
|
107
131
|
return tracked.get(locator);
|
|
@@ -115,244 +139,266 @@ export function createAgentsHouseAdapter(options) {
|
|
|
115
139
|
const { authority, position, log_epoch: logEpoch } = body;
|
|
116
140
|
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
117
141
|
return result;
|
|
118
|
-
const locator = authority ===
|
|
119
|
-
? PRIVATE_LOCATOR
|
|
120
|
-
: [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
142
|
+
const locator = [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
121
143
|
if (locator === undefined)
|
|
122
144
|
return result;
|
|
123
145
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
124
146
|
}
|
|
125
|
-
async function bundled(body) {
|
|
126
|
-
const grant = parseGrant(body);
|
|
127
|
-
if (grant === null)
|
|
128
|
-
return body;
|
|
129
|
-
if (grant.method !== 'GET')
|
|
130
|
-
return null;
|
|
131
|
-
const answer = await transport.transfer({
|
|
132
|
-
act: 'local_copy_bundle',
|
|
133
|
-
method: 'GET',
|
|
134
|
-
url: grant.url,
|
|
135
|
-
answer: 'json',
|
|
136
|
-
});
|
|
137
|
-
return answer.status === 200 ? answer.body : null;
|
|
138
|
-
}
|
|
139
|
-
function weight(entry) {
|
|
140
|
-
return contentPrefixes(entry).length;
|
|
141
|
-
}
|
|
142
|
-
async function bootstrapped(entries) {
|
|
143
|
-
const answers = [];
|
|
144
|
-
for (const part of selections(entries, weight, declared().max_prefixes)) {
|
|
145
|
-
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
146
|
-
prefixes: part.flatMap((entry) => contentPrefixes(entry)),
|
|
147
|
-
});
|
|
148
|
-
const classified = part.map((entry) => classifyDoor(answer.status, answer.body, entry.locator));
|
|
149
|
-
const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
150
|
-
part.forEach((entry, index) => {
|
|
151
|
-
const failure = classified[index];
|
|
152
|
-
if (failure === null || failure === undefined) {
|
|
153
|
-
answers.push(envelope === null ? UNCERTAIN_READ : bootstrappedRoom(envelope, entry));
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
return answers;
|
|
160
|
-
}
|
|
161
|
-
function layered(asks) {
|
|
162
|
-
const depths = new Map();
|
|
163
|
-
const layers = [];
|
|
164
|
-
for (const ask of asks) {
|
|
165
|
-
const depth = depths.get(ask.entry.authority) ?? 0;
|
|
166
|
-
depths.set(ask.entry.authority, depth + 1);
|
|
167
|
-
(layers[depth] ??= []).push(ask);
|
|
168
|
-
}
|
|
169
|
-
return layers;
|
|
170
|
-
}
|
|
171
|
-
async function enumerated(asks) {
|
|
172
|
-
const answers = new Map();
|
|
173
|
-
const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry), declared().max_prefixes));
|
|
174
|
-
for (const part of parts) {
|
|
175
|
-
let open = [...part];
|
|
176
|
-
while (open.length > 0) {
|
|
177
|
-
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
178
|
-
prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),
|
|
179
|
-
positions: open.map((ask) => ({
|
|
180
|
-
...presented(ask.entry.authority, ask.from),
|
|
181
|
-
...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),
|
|
182
|
-
})),
|
|
183
|
-
});
|
|
184
|
-
const refusal = doorRefusal(answer.body);
|
|
185
|
-
if (refusal?.code === 'replica_behind') {
|
|
186
|
-
const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);
|
|
187
|
-
const behind = named.length === 0 ? open : named;
|
|
188
|
-
for (const ask of behind) {
|
|
189
|
-
answers.set(ask, refusal.retryable
|
|
190
|
-
? { kind: 'retryable-refusal', code: refusal.code, fields: refusal.fields }
|
|
191
|
-
: (classifyDoor(answer.status, answer.body, ask.entry.locator) ?? UNCERTAIN_READ));
|
|
192
|
-
}
|
|
193
|
-
open = open.filter((ask) => !behind.includes(ask));
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
const classified = open.map((ask) => classifyDoor(answer.status, answer.body, ask.entry.locator));
|
|
197
|
-
if (classified[0]?.kind === 'beyond-horizon') {
|
|
198
|
-
const named = doorRefusal(answer.body)?.fields.authority;
|
|
199
|
-
const expired = open.filter((ask) => ask.entry.authority === named);
|
|
200
|
-
const answered = expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };
|
|
201
|
-
const gone = expired.length === 0 ? open : expired;
|
|
202
|
-
for (const ask of gone)
|
|
203
|
-
answers.set(ask, answered);
|
|
204
|
-
open = open.filter((ask) => !gone.includes(ask));
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
|
|
208
|
-
open.forEach((ask, index) => {
|
|
209
|
-
const failure = classified[index];
|
|
210
|
-
if (failure !== null && failure !== undefined) {
|
|
211
|
-
answers.set(ask, failure);
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
answers.set(ask, enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask));
|
|
215
|
-
});
|
|
216
|
-
open = [];
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);
|
|
220
|
-
}
|
|
221
|
-
const bootstrapTogether = gathered(bootstrapped);
|
|
222
|
-
const enumerateTogether = gathered(enumerated);
|
|
223
147
|
async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
|
|
224
148
|
const paths = batchPaths(changes);
|
|
225
149
|
const sha256 = await deltaDigest(delta);
|
|
226
150
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
227
|
-
return { body: { ...head, paths, upload: handed } };
|
|
151
|
+
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
228
152
|
}
|
|
229
|
-
const minted = await transport.door(
|
|
153
|
+
const minted = await transport.door(houseDoorRoute('update'), {
|
|
154
|
+
...head,
|
|
155
|
+
op: 'stage',
|
|
156
|
+
paths,
|
|
157
|
+
bytes,
|
|
158
|
+
sha256,
|
|
159
|
+
});
|
|
230
160
|
if (minted.status !== 200) {
|
|
231
|
-
return {
|
|
161
|
+
return {
|
|
162
|
+
outcome: await stepped(mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)),
|
|
163
|
+
};
|
|
232
164
|
}
|
|
233
165
|
const grant = parseGrant(minted.body);
|
|
234
|
-
if (grant === null
|
|
235
|
-
return { outcome:
|
|
166
|
+
if (grant === null)
|
|
167
|
+
return { outcome: unusable() };
|
|
236
168
|
const delivered = await transport.transfer({
|
|
237
|
-
act: 'authored_batch_upload',
|
|
238
|
-
method: 'POST',
|
|
239
169
|
url: grant.url,
|
|
240
|
-
answer: 'json',
|
|
241
170
|
body: `${grant.operation}\n${delta}`,
|
|
242
171
|
});
|
|
243
|
-
if (delivered.status !== 200)
|
|
244
|
-
return { outcome:
|
|
172
|
+
if (delivered.status !== 200) {
|
|
173
|
+
return { outcome: answeredFailure(delivered.status, delivered.body) };
|
|
174
|
+
}
|
|
245
175
|
const holding = parseGrant(delivered.body);
|
|
246
|
-
if (holding === null
|
|
247
|
-
return { outcome:
|
|
176
|
+
if (holding === null)
|
|
177
|
+
return { outcome: unusable() };
|
|
248
178
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
249
179
|
await keep(upload);
|
|
250
|
-
return { body: { ...head, paths, upload } };
|
|
180
|
+
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
251
181
|
}
|
|
252
|
-
async function submit(head, changes, delta, bytes, entry, handed, keep) {
|
|
253
|
-
const inline = { ...head, changes };
|
|
182
|
+
async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
|
|
183
|
+
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
254
184
|
const prepared = uploadable(inline, bytes, declared())
|
|
255
185
|
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
256
186
|
: { body: inline };
|
|
257
187
|
if ('outcome' in prepared)
|
|
258
188
|
return prepared.outcome;
|
|
259
|
-
const
|
|
260
|
-
|
|
189
|
+
const settled = await stagedBatch(transport, prepared.body, (sha256) => {
|
|
190
|
+
const change = request.changeBatch.changes.find((held) => held.kind === 'binary' && held.sha256 === sha256);
|
|
191
|
+
return change === undefined ? null : request.file(change.localId);
|
|
192
|
+
});
|
|
193
|
+
if ('kind' in settled)
|
|
194
|
+
return settled;
|
|
195
|
+
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
196
|
+
? undefined
|
|
197
|
+
: {
|
|
198
|
+
source: { authority: entry.authority, handle: entry.handle },
|
|
199
|
+
destination: { authority: into.authority, handle: into.handle },
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
async function mutated(request, keep, entry, into) {
|
|
203
|
+
const batch = request.changeBatch;
|
|
204
|
+
const mapped = into === undefined
|
|
205
|
+
? houseChanges(batch, entry.handle)
|
|
206
|
+
: houseMove(batch, entry.handle, into.handle);
|
|
207
|
+
if (mapped.kind === 'unmapped')
|
|
208
|
+
return rejectedMapping(mapped);
|
|
209
|
+
const head = operationHead(batch);
|
|
210
|
+
const delta = deltaBody(mapped.changes);
|
|
211
|
+
const bytes = deltaBytes(delta);
|
|
212
|
+
const handed = request.upload;
|
|
213
|
+
const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
|
|
214
|
+
const outcome = await answer(handed);
|
|
215
|
+
if (handed === undefined || !lapsedGrant(outcome))
|
|
216
|
+
return outcome;
|
|
217
|
+
return answer(undefined);
|
|
218
|
+
}
|
|
219
|
+
function refusedOn(answer, locator) {
|
|
220
|
+
if (locator === null)
|
|
221
|
+
return keyedFailure(answer.status, answer.body);
|
|
222
|
+
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
223
|
+
if (failure === null)
|
|
224
|
+
return null;
|
|
225
|
+
return failure.kind === 'scoped-refusal'
|
|
226
|
+
? {
|
|
227
|
+
kind: 'rejected',
|
|
228
|
+
code: failure.code,
|
|
229
|
+
fields: failure.fields,
|
|
230
|
+
retryable: failure.retryable,
|
|
231
|
+
}
|
|
232
|
+
: failure;
|
|
233
|
+
}
|
|
234
|
+
function addressed(answer, locator) {
|
|
235
|
+
const failure = refusedOn(answer, locator);
|
|
236
|
+
if (failure !== null)
|
|
237
|
+
return failure;
|
|
238
|
+
const address = parseFileAddress(answer.body);
|
|
239
|
+
return address === null ? unusable() : { kind: 'address', ...address };
|
|
240
|
+
}
|
|
241
|
+
function linked(answer, locator) {
|
|
242
|
+
const address = addressed(answer, locator);
|
|
243
|
+
return address.kind === 'address'
|
|
244
|
+
? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
|
|
245
|
+
: address;
|
|
246
|
+
}
|
|
247
|
+
async function attached(request, into) {
|
|
248
|
+
const locator = into?.locator ?? null;
|
|
249
|
+
const declared = await transport.door(houseDoorRoute('files/attach'), {
|
|
250
|
+
...(into === null ? {} : { room_ref: into.authority }),
|
|
251
|
+
name: request.name,
|
|
252
|
+
bytes: request.byteLength,
|
|
253
|
+
sha256: request.sha256,
|
|
254
|
+
media_type: request.mediaType,
|
|
255
|
+
});
|
|
256
|
+
const refused = refusedOn(declared, locator);
|
|
257
|
+
if (refused !== null)
|
|
258
|
+
return refused;
|
|
259
|
+
const upload = houseUpload(declared.body?.upload);
|
|
260
|
+
if (upload === null)
|
|
261
|
+
return unusable();
|
|
262
|
+
const finished = await finishedUpload(transport, upload, request.blob);
|
|
263
|
+
if ('unfinished' in finished)
|
|
264
|
+
return answeredFailure(finished.unfinished, null);
|
|
265
|
+
const unfinished = refusedOn(finished, locator);
|
|
266
|
+
if (unfinished !== null)
|
|
267
|
+
return unfinished;
|
|
268
|
+
const { path, revision, link } = (finished.body ?? {});
|
|
269
|
+
if (into === null)
|
|
270
|
+
return typeof link === 'string' ? { kind: 'linked', link } : unusable();
|
|
271
|
+
const root = `/rooms/${into.handle}/`;
|
|
272
|
+
return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
|
|
273
|
+
? { kind: 'attached', path: path.slice(root.length), revision }
|
|
274
|
+
: unusable();
|
|
275
|
+
}
|
|
276
|
+
async function downloaded(ask, locator) {
|
|
277
|
+
let address = addressed(await ask(), locator);
|
|
278
|
+
if (address.kind !== 'address')
|
|
279
|
+
return address;
|
|
280
|
+
let read = await transport.download(address.url);
|
|
281
|
+
if (read.status === EXPIRED_ADDRESS) {
|
|
282
|
+
address = addressed(await ask(), locator);
|
|
283
|
+
if (address.kind !== 'address')
|
|
284
|
+
return address;
|
|
285
|
+
read = await transport.download(address.url);
|
|
286
|
+
}
|
|
287
|
+
if (read.status !== 200)
|
|
288
|
+
return answeredFailure(read.status, null);
|
|
289
|
+
if (read.body === null)
|
|
290
|
+
return unusable();
|
|
291
|
+
return {
|
|
292
|
+
kind: 'binary',
|
|
293
|
+
body: read.body,
|
|
294
|
+
mediaType: address.mediaType,
|
|
295
|
+
sha256: address.sha256,
|
|
296
|
+
url: address.url,
|
|
297
|
+
copies: address.copies,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function pathAddress(request) {
|
|
301
|
+
const entry = authorityFor(request.locator);
|
|
302
|
+
if (entry === undefined)
|
|
303
|
+
return null;
|
|
304
|
+
return () => transport.door(houseDoorRoute('files/read'), {
|
|
305
|
+
room_ref: entry.authority,
|
|
306
|
+
path: request.path,
|
|
307
|
+
revision: request.revision,
|
|
308
|
+
});
|
|
261
309
|
}
|
|
262
310
|
return {
|
|
311
|
+
roomTypes: HOUSE_ROOM_TYPES,
|
|
312
|
+
typedPaths: HOUSE_TYPED_PATHS,
|
|
313
|
+
pathRule: admittedPath,
|
|
314
|
+
unkeptReads: HOUSE_UNKEPT_READS,
|
|
315
|
+
leadingReads: HOUSE_LEADING_READS,
|
|
316
|
+
renamedActions: new Map([...HOUSE_RENAMED_UNTIL_2026_12_18, ...HOUSE_RENAMED_UNTIL_2026_12_21]),
|
|
317
|
+
rewrittenInputs: new Map([
|
|
318
|
+
...HOUSE_REWRITTEN_UNTIL_2026_12_19,
|
|
319
|
+
...HOUSE_REWRITTEN_UNTIL_2026_12_21,
|
|
320
|
+
]),
|
|
263
321
|
async authorize() {
|
|
264
322
|
return options.authorize();
|
|
265
323
|
},
|
|
266
|
-
async model(_authorization, request) {
|
|
267
|
-
return models.answer(request);
|
|
268
|
-
},
|
|
269
|
-
async discover(_authorization) {
|
|
270
|
-
const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });
|
|
271
|
-
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
272
|
-
if (classified !== null)
|
|
273
|
-
return discoveryFailure(classified);
|
|
274
|
-
const document = parseDiscovery(answer.body);
|
|
275
|
-
if (document === null)
|
|
276
|
-
return { kind: 'transport-uncertainty' };
|
|
277
|
-
bounds = document.bounds;
|
|
278
|
-
const entries = trackedFrom(document);
|
|
279
|
-
tracked.clear();
|
|
280
|
-
for (const entry of entries)
|
|
281
|
-
tracked.set(entry.locator, entry);
|
|
282
|
-
for (const locator of handed.keys())
|
|
283
|
-
if (!tracked.has(locator))
|
|
284
|
-
handed.delete(locator);
|
|
285
|
-
notifications.track(entries);
|
|
286
|
-
const acquired = await acquireModels(entries);
|
|
287
|
-
models.keep(entries.map((entry) => entry.locator));
|
|
288
|
-
return mapDiscovery(document, document.authorities.map((authority) => roomOf(authority, acquired)), capabilities(document.actions));
|
|
289
|
-
},
|
|
290
324
|
async bootstrap(_authorization, request) {
|
|
291
325
|
const entry = authorityFor(request.locator);
|
|
292
326
|
if (entry === undefined)
|
|
293
327
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
},
|
|
298
|
-
async refresh(_authorization, request) {
|
|
299
|
-
const entry = authorityFor(request.locator);
|
|
300
|
-
if (entry === undefined)
|
|
301
|
-
return { kind: 'room-not-readable', locator: request.locator };
|
|
302
|
-
if (request.pageToken !== undefined)
|
|
303
|
-
return { kind: 'transport-uncertainty' };
|
|
304
|
-
const from = logPosition(request.fromRoomVersion);
|
|
305
|
-
if (from === null)
|
|
306
|
-
return { kind: 'beyond-horizon' };
|
|
307
|
-
const answered = streamed(entry, request, from);
|
|
308
|
-
if (answered !== null)
|
|
309
|
-
return answered;
|
|
310
|
-
const minPosition = request.minPosition === undefined ? null : logPosition(request.minPosition);
|
|
311
|
-
return enumerateTogether({
|
|
312
|
-
entry,
|
|
313
|
-
from,
|
|
314
|
-
fromRoomVersion: request.fromRoomVersion,
|
|
315
|
-
...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),
|
|
316
|
-
});
|
|
328
|
+
return request.pageToken === undefined
|
|
329
|
+
? listedRoom(entry)
|
|
330
|
+
: chunkPage(entry, request.pageToken, request.arriving);
|
|
317
331
|
},
|
|
318
332
|
async mutate(_authorization, request, keep) {
|
|
319
333
|
const entry = authorityFor(request.locator);
|
|
320
334
|
if (entry === undefined)
|
|
321
335
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
if (handed === undefined || !lapsedGrant(outcome))
|
|
336
|
+
const destination = request.changeBatch.between?.destination.room;
|
|
337
|
+
const into = destination === undefined ? undefined : authorityFor(destination);
|
|
338
|
+
if (destination !== undefined && into === undefined) {
|
|
339
|
+
return { kind: 'room-not-readable', locator: destination };
|
|
340
|
+
}
|
|
341
|
+
const outcome = await mutated(request, keep, entry, into);
|
|
342
|
+
const renamed = renamedHandle(outcome);
|
|
343
|
+
if (renamed === null)
|
|
331
344
|
return outcome;
|
|
332
|
-
|
|
345
|
+
const moved = (held) => held.handle === renamed.from ? { ...held, handle: renamed.to } : held;
|
|
346
|
+
return mutated(request, keep, moved(entry), into === undefined ? undefined : moved(into));
|
|
333
347
|
},
|
|
334
348
|
async history(_authorization, request) {
|
|
335
349
|
const entry = authorityFor(request.locator);
|
|
336
350
|
if (entry === undefined)
|
|
337
351
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
338
|
-
const answer = await transport.door(
|
|
352
|
+
const answer = await transport.door(houseDoorRoute('files/revisions/list'), revisionBody({
|
|
339
353
|
path: request.path,
|
|
340
354
|
handle: entry.handle,
|
|
341
355
|
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
342
356
|
...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
|
|
343
357
|
}));
|
|
344
|
-
return historyOutcome(answer.status, answer.body, entry.locator,
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
358
|
+
return historyOutcome(answer.status, answer.body, entry.locator, request);
|
|
359
|
+
},
|
|
360
|
+
async binary(_authorization, request) {
|
|
361
|
+
const ask = pathAddress(request);
|
|
362
|
+
if (ask === null)
|
|
363
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
364
|
+
return downloaded(ask, request.locator);
|
|
365
|
+
},
|
|
366
|
+
async link(_authorization, request) {
|
|
367
|
+
if (request.kind === 'key') {
|
|
368
|
+
return linked(await transport.door(houseDoorRoute('files/read'), { link: request.link }), null);
|
|
369
|
+
}
|
|
370
|
+
const ask = pathAddress(request);
|
|
371
|
+
if (ask === null)
|
|
372
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
373
|
+
return linked(await ask(), request.locator);
|
|
374
|
+
},
|
|
375
|
+
async attach(_authorization, request) {
|
|
376
|
+
if (request.locator === undefined)
|
|
377
|
+
return attached(request, null);
|
|
378
|
+
const entry = authorityFor(request.locator);
|
|
379
|
+
if (entry === undefined)
|
|
380
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
381
|
+
return attached(request, entry);
|
|
348
382
|
},
|
|
349
383
|
reached(locator, version, target) {
|
|
350
384
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
351
385
|
},
|
|
386
|
+
follows(_locator, version, next) {
|
|
387
|
+
return followsVersion(version, next);
|
|
388
|
+
},
|
|
352
389
|
async action(_authorization, request) {
|
|
353
390
|
return withAt(await houseAction(transport, request));
|
|
354
391
|
},
|
|
355
|
-
|
|
392
|
+
search(_authorization, request) {
|
|
393
|
+
return houseSearch(transport, [...tracked.values()], request);
|
|
394
|
+
},
|
|
395
|
+
queryHouse(_authorization, request) {
|
|
396
|
+
return houseQuery(transport, request);
|
|
397
|
+
},
|
|
398
|
+
roomStream: {
|
|
399
|
+
hold,
|
|
400
|
+
observe: notifications.observe,
|
|
401
|
+
},
|
|
356
402
|
conversations: notifications.conversations,
|
|
357
403
|
serviceMode: notifications.serviceMode,
|
|
358
404
|
};
|