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