@agentshouse/mdruntime-adapter 0.1.0-cb0bbc4ccacd0 → 0.1.0-cb1a2f809f691
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 +9 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +129 -9
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +179 -182
- 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 +26 -9
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +174 -27
- package/dist/history.d.ts +1 -7
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +22 -29
- package/dist/index.d.ts +8 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -8
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +5 -10
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +19 -39
- package/dist/read.d.ts +15 -29
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +91 -183
- package/dist/refusal.d.ts +6 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +28 -7
- package/dist/renamed.d.ts +10 -0
- package/dist/renamed.d.ts.map +1 -0
- package/dist/renamed.js +20 -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 +0 -1
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +5 -5
- 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 +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +81 -55
- package/dist/space-schema.d.ts +0 -1
- package/dist/space-schema.d.ts.map +1 -1
- package/dist/space-schema.js +1 -8
- package/dist/stream.d.ts +5 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +151 -83
- package/dist/transport.d.ts +62 -30
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +52 -16
- 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 +7 -2
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +49 -6
- package/dist/version.d.ts +0 -1
- package/dist/write.d.ts +3 -10
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +90 -110
- package/package.json +4 -3
- package/dist/app-reference.d.ts +0 -2
- package/dist/app-reference.d.ts.map +0 -1
- package/dist/app-reference.js +0 -2
- package/dist/crockford.d.ts +0 -4
- package/dist/crockford.d.ts.map +0 -1
- package/dist/crockford.js +0 -3
- package/dist/house-model.d.ts +0 -641
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -361
- package/dist/part.d.ts +0 -14
- package/dist/part.d.ts.map +0 -1
- package/dist/part.js +0 -90
- package/dist/room-stream.d.ts +0 -20
- package/dist/room-stream.d.ts.map +0 -1
- package/dist/room-stream.js +0 -57
- package/dist/room-types.d.ts +0 -7
- package/dist/room-types.d.ts.map +0 -1
- package/dist/room-types.js +0 -123
package/dist/adapter.js
CHANGED
|
@@ -1,65 +1,38 @@
|
|
|
1
|
+
import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
|
|
1
2
|
import { stepped } from '@agentshouse/mdruntime';
|
|
2
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 { houseAction } from './actions.js';
|
|
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, rewrittenInTurn, } from './actions.js';
|
|
9
|
+
import { houseQuery } from './room-query.js';
|
|
10
10
|
import { houseSearch } from './search.js';
|
|
11
|
-
import { classifyDoor,
|
|
11
|
+
import { answeredFailure, classifyDoor, keyedFailure } from './refusal.js';
|
|
12
|
+
import { UNANSWERED, unusable } from './uncertain.js';
|
|
12
13
|
import { houseNotifications, } from './stream.js';
|
|
13
14
|
import { houseDoorRoute, } from './transport.js';
|
|
15
|
+
import { renamedHandle } from './renamed.js';
|
|
14
16
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { followsVersion, logPosition, presented, reachedVersion, roomVersion } from './version.js';
|
|
18
|
-
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
19
|
-
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
20
|
-
const OCTET_STREAM = 'application/octet-stream';
|
|
17
|
+
import { admittedPath } from './authored-path.js';
|
|
18
|
+
import { followsVersion, reachedVersion, roomVersion } from './version.js';
|
|
21
19
|
const EXPIRED_ADDRESS = 403;
|
|
22
20
|
function lapsedGrant(outcome) {
|
|
23
21
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
24
22
|
}
|
|
25
|
-
async function heldFiles(authority, held, bound) {
|
|
26
|
-
const listed = await held.files(null, bound + 1);
|
|
27
|
-
const files = listed.slice(0, bound);
|
|
28
|
-
const through = listed.length > bound ? (files.at(-1)?.path ?? null) : null;
|
|
29
|
-
return files.length === 0 ? null : { room: authority, through, files };
|
|
30
|
-
}
|
|
31
|
-
async function reused(scope, held) {
|
|
32
|
-
const sent = new Set(scope.contents.map((entry) => entry.path));
|
|
33
|
-
const contents = [...scope.contents];
|
|
34
|
-
const asked = scope.files.filter((file) => file.binary === undefined && !sent.has(file.path));
|
|
35
|
-
if (asked.length === 0)
|
|
36
|
-
return scope;
|
|
37
|
-
if (held === undefined)
|
|
38
|
-
return null;
|
|
39
|
-
const kept = await held.contents(asked.map(({ path }) => path));
|
|
40
|
-
for (const file of asked) {
|
|
41
|
-
const found = kept.get(file.path);
|
|
42
|
-
if (found === undefined ||
|
|
43
|
-
found.revision !== file.revision ||
|
|
44
|
-
(await sha256Hex(found.content)) !== file.sha256) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
contents.push({ path: file.path, content: found.content });
|
|
48
|
-
}
|
|
49
|
-
return { ...scope, contents };
|
|
50
|
-
}
|
|
51
23
|
export function createAgentsHouseAdapter(options) {
|
|
52
24
|
if ('site' in options)
|
|
53
25
|
return createSiteAdapter(options.site, options.snapshot === true);
|
|
54
26
|
const transport = options.transport;
|
|
55
|
-
const spaces = spaceSchemas();
|
|
56
27
|
const notifications = houseNotifications(transport, 'credential', {
|
|
57
28
|
opened: async (frame) => (frame === null ? null : opened(frame)),
|
|
58
29
|
changed,
|
|
59
|
-
|
|
30
|
+
expired: (entries) => lister.askAll(entries),
|
|
31
|
+
});
|
|
60
32
|
const tracked = new Map();
|
|
61
|
-
const
|
|
62
|
-
const
|
|
33
|
+
const lister = chunkLister(transport, () => declared().max_prefixes, (locator) => tracked.get(locator));
|
|
34
|
+
const chunked = new Map();
|
|
35
|
+
const renewals = new WeakMap();
|
|
63
36
|
let bounds;
|
|
64
37
|
function declared() {
|
|
65
38
|
if (bounds === undefined)
|
|
@@ -72,19 +45,23 @@ export function createAgentsHouseAdapter(options) {
|
|
|
72
45
|
return null;
|
|
73
46
|
bounds = document.bounds;
|
|
74
47
|
tracked.clear();
|
|
48
|
+
lister.forget();
|
|
75
49
|
for (const entry of trackedFrom(document))
|
|
76
50
|
tracked.set(entry.locator, entry);
|
|
77
51
|
notifications.track([...tracked.values()]);
|
|
78
52
|
return {
|
|
79
53
|
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
80
54
|
member: document.member,
|
|
55
|
+
timeZone: document.timeZone,
|
|
56
|
+
roomList: document.roomList,
|
|
81
57
|
};
|
|
82
58
|
}
|
|
83
59
|
function changed(frame) {
|
|
84
60
|
const change = parseAuthorityChange(frame);
|
|
85
61
|
if (change === null)
|
|
86
62
|
return null;
|
|
87
|
-
|
|
63
|
+
const unheld = [...change.left, ...change.listed];
|
|
64
|
+
for (const locator of unheld)
|
|
88
65
|
tracked.delete(locator);
|
|
89
66
|
for (const entry of trackedFrom(change))
|
|
90
67
|
tracked.set(entry.locator, entry);
|
|
@@ -92,46 +69,63 @@ export function createAgentsHouseAdapter(options) {
|
|
|
92
69
|
return {
|
|
93
70
|
kind: 'authority-changed',
|
|
94
71
|
rooms: change.authorities.map((authority) => discoveredRoom(authority)),
|
|
95
|
-
left:
|
|
72
|
+
left: unheld,
|
|
96
73
|
member: change.member,
|
|
74
|
+
timeZone: change.timeZone,
|
|
75
|
+
roomList: { ...change.roomList, left: change.left },
|
|
97
76
|
};
|
|
98
77
|
}
|
|
99
|
-
async function
|
|
100
|
-
const
|
|
101
|
-
if ('kind' in
|
|
102
|
-
return
|
|
103
|
-
const
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
...(await stepped(bootstrapping(scope))),
|
|
110
|
-
...(part.models === undefined ? {} : { models: part.models }),
|
|
111
|
-
...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
|
|
112
|
-
bytes: part.bytes,
|
|
113
|
-
};
|
|
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;
|
|
114
86
|
}
|
|
115
|
-
async function
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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) };
|
|
128
103
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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);
|
|
119
|
+
}
|
|
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);
|
|
135
129
|
}
|
|
136
130
|
function authorityFor(locator) {
|
|
137
131
|
return tracked.get(locator);
|
|
@@ -156,8 +150,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
156
150
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
157
151
|
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
158
152
|
}
|
|
159
|
-
const minted = await transport.door(houseDoorRoute('
|
|
153
|
+
const minted = await transport.door(houseDoorRoute('update'), {
|
|
160
154
|
...head,
|
|
155
|
+
op: 'stage',
|
|
161
156
|
paths,
|
|
162
157
|
bytes,
|
|
163
158
|
sha256,
|
|
@@ -169,39 +164,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
169
164
|
}
|
|
170
165
|
const grant = parseGrant(minted.body);
|
|
171
166
|
if (grant === null)
|
|
172
|
-
return { outcome:
|
|
167
|
+
return { outcome: unusable() };
|
|
173
168
|
const delivered = await transport.transfer({
|
|
174
|
-
act: 'authored_batch_upload',
|
|
175
169
|
url: grant.url,
|
|
176
170
|
body: `${grant.operation}\n${delta}`,
|
|
177
171
|
});
|
|
178
|
-
if (delivered.status !== 200)
|
|
179
|
-
return { outcome:
|
|
172
|
+
if (delivered.status !== 200) {
|
|
173
|
+
return { outcome: answeredFailure(delivered.status, delivered.body) };
|
|
174
|
+
}
|
|
180
175
|
const holding = parseGrant(delivered.body);
|
|
181
176
|
if (holding === null)
|
|
182
|
-
return { outcome:
|
|
177
|
+
return { outcome: unusable() };
|
|
183
178
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
184
179
|
await keep(upload);
|
|
185
180
|
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
186
181
|
}
|
|
187
|
-
async function staged(answer, { changeBatch: batch, file }) {
|
|
188
|
-
const refusal = doorRefusal(answer.body);
|
|
189
|
-
if (refusal?.code !== 'files_unstaged')
|
|
190
|
-
return null;
|
|
191
|
-
const uploads = refusal.fields.upload;
|
|
192
|
-
if (!Array.isArray(uploads))
|
|
193
|
-
return false;
|
|
194
|
-
for (const named of uploads) {
|
|
195
|
-
const upload = houseUpload(named);
|
|
196
|
-
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
|
|
197
|
-
if (upload === null || change === undefined)
|
|
198
|
-
return false;
|
|
199
|
-
const finished = await finishedUpload(transport, upload, await file(change.localId));
|
|
200
|
-
if (finished?.body?.staged !== true)
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
182
|
async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
|
|
206
183
|
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
207
184
|
const prepared = uploadable(inline, bytes, declared())
|
|
@@ -209,13 +186,12 @@ export function createAgentsHouseAdapter(options) {
|
|
|
209
186
|
: { body: inline };
|
|
210
187
|
if ('outcome' in prepared)
|
|
211
188
|
return prepared.outcome;
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return UNCERTAIN;
|
|
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;
|
|
219
195
|
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
220
196
|
? undefined
|
|
221
197
|
: {
|
|
@@ -223,28 +199,26 @@ export function createAgentsHouseAdapter(options) {
|
|
|
223
199
|
destination: { authority: into.authority, handle: into.handle },
|
|
224
200
|
}));
|
|
225
201
|
}
|
|
226
|
-
function
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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;
|
|
202
|
+
async function mutated(request, keep, entry, into) {
|
|
203
|
+
const batch = request.changeBatch;
|
|
204
|
+
const mapped = into === undefined
|
|
205
|
+
? houseChanges(batch, entry.handle, request.written)
|
|
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);
|
|
246
218
|
}
|
|
247
|
-
function
|
|
219
|
+
function refusedOn(answer, locator) {
|
|
220
|
+
if (locator === null)
|
|
221
|
+
return keyedFailure(answer.status, answer.body);
|
|
248
222
|
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
249
223
|
if (failure === null)
|
|
250
224
|
return null;
|
|
@@ -257,6 +231,48 @@ export function createAgentsHouseAdapter(options) {
|
|
|
257
231
|
}
|
|
258
232
|
: failure;
|
|
259
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
|
+
}
|
|
260
276
|
async function downloaded(ask, locator) {
|
|
261
277
|
let address = addressed(await ask(), locator);
|
|
262
278
|
if (address.kind !== 'address')
|
|
@@ -268,20 +284,24 @@ export function createAgentsHouseAdapter(options) {
|
|
|
268
284
|
return address;
|
|
269
285
|
read = await transport.download(address.url);
|
|
270
286
|
}
|
|
271
|
-
if (read.status !== 200
|
|
272
|
-
return
|
|
287
|
+
if (read.status !== 200)
|
|
288
|
+
return answeredFailure(read.status, null);
|
|
289
|
+
if (read.body === null)
|
|
290
|
+
return unusable();
|
|
273
291
|
return {
|
|
274
292
|
kind: 'binary',
|
|
275
293
|
body: read.body,
|
|
276
294
|
mediaType: address.mediaType,
|
|
277
295
|
sha256: address.sha256,
|
|
296
|
+
url: address.url,
|
|
297
|
+
copies: address.copies,
|
|
278
298
|
};
|
|
279
299
|
}
|
|
280
300
|
function pathAddress(request) {
|
|
281
301
|
const entry = authorityFor(request.locator);
|
|
282
302
|
if (entry === undefined)
|
|
283
303
|
return null;
|
|
284
|
-
return () => transport.door(houseDoorRoute('files/
|
|
304
|
+
return () => transport.door(houseDoorRoute('files/read'), {
|
|
285
305
|
room_ref: entry.authority,
|
|
286
306
|
path: request.path,
|
|
287
307
|
revision: request.revision,
|
|
@@ -289,8 +309,12 @@ export function createAgentsHouseAdapter(options) {
|
|
|
289
309
|
}
|
|
290
310
|
return {
|
|
291
311
|
roomTypes: HOUSE_ROOM_TYPES,
|
|
292
|
-
nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
|
|
293
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: rewrittenInTurn(HOUSE_REWRITTEN_UNTIL_2026_12_19, HOUSE_REWRITTEN_UNTIL_2026_12_21),
|
|
294
318
|
async authorize() {
|
|
295
319
|
return options.authorize();
|
|
296
320
|
},
|
|
@@ -299,48 +323,36 @@ export function createAgentsHouseAdapter(options) {
|
|
|
299
323
|
if (entry === undefined)
|
|
300
324
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
301
325
|
return request.pageToken === undefined
|
|
302
|
-
?
|
|
303
|
-
:
|
|
326
|
+
? listedRoom(entry)
|
|
327
|
+
: chunkPage(entry, request.pageToken, request.arriving);
|
|
304
328
|
},
|
|
305
329
|
async mutate(_authorization, request, keep) {
|
|
306
330
|
const entry = authorityFor(request.locator);
|
|
307
331
|
if (entry === undefined)
|
|
308
332
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
309
|
-
const
|
|
310
|
-
const destination = batch.between?.destination.room;
|
|
333
|
+
const destination = request.changeBatch.between?.destination.room;
|
|
311
334
|
const into = destination === undefined ? undefined : authorityFor(destination);
|
|
312
335
|
if (destination !== undefined && into === undefined) {
|
|
313
336
|
return { kind: 'room-not-readable', locator: destination };
|
|
314
337
|
}
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (mapped.kind === 'unmapped')
|
|
319
|
-
return rejectedMapping(mapped);
|
|
320
|
-
const head = operationHead(batch, entry.authority);
|
|
321
|
-
const delta = deltaBody(mapped.changes);
|
|
322
|
-
const bytes = deltaBytes(delta);
|
|
323
|
-
const handed = request.upload;
|
|
324
|
-
const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
|
|
325
|
-
const outcome = await answer(handed);
|
|
326
|
-
if (handed === undefined || !lapsedGrant(outcome))
|
|
338
|
+
const outcome = await mutated(request, keep, entry, into);
|
|
339
|
+
const renamed = renamedHandle(outcome);
|
|
340
|
+
if (renamed === null)
|
|
327
341
|
return outcome;
|
|
328
|
-
|
|
342
|
+
const moved = (held) => held.handle === renamed.from ? { ...held, handle: renamed.to } : held;
|
|
343
|
+
return mutated(request, keep, moved(entry), into === undefined ? undefined : moved(into));
|
|
329
344
|
},
|
|
330
345
|
async history(_authorization, request) {
|
|
331
346
|
const entry = authorityFor(request.locator);
|
|
332
347
|
if (entry === undefined)
|
|
333
348
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
334
|
-
const answer = await transport.door(houseDoorRoute('revisions'), revisionBody({
|
|
349
|
+
const answer = await transport.door(houseDoorRoute('files/revisions/list'), revisionBody({
|
|
335
350
|
path: request.path,
|
|
336
351
|
handle: entry.handle,
|
|
337
352
|
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
338
353
|
...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
|
|
339
354
|
}));
|
|
340
|
-
return historyOutcome(answer.status, answer.body, entry.locator,
|
|
341
|
-
path: request.path,
|
|
342
|
-
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
343
|
-
});
|
|
355
|
+
return historyOutcome(answer.status, answer.body, entry.locator, request);
|
|
344
356
|
},
|
|
345
357
|
async binary(_authorization, request) {
|
|
346
358
|
const ask = pathAddress(request);
|
|
@@ -349,39 +361,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
349
361
|
return downloaded(ask, request.locator);
|
|
350
362
|
},
|
|
351
363
|
async link(_authorization, request) {
|
|
364
|
+
if (request.kind === 'key') {
|
|
365
|
+
return linked(await transport.door(houseDoorRoute('files/read'), { link: request.link }), null);
|
|
366
|
+
}
|
|
352
367
|
const ask = pathAddress(request);
|
|
353
368
|
if (ask === null)
|
|
354
369
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
355
370
|
return linked(await ask(), request.locator);
|
|
356
371
|
},
|
|
357
372
|
async attach(_authorization, request) {
|
|
373
|
+
if (request.locator === undefined)
|
|
374
|
+
return attached(request, null);
|
|
358
375
|
const entry = authorityFor(request.locator);
|
|
359
376
|
if (entry === undefined)
|
|
360
377
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
361
|
-
|
|
362
|
-
room_ref: entry.authority,
|
|
363
|
-
name: request.name,
|
|
364
|
-
bytes: request.byteLength,
|
|
365
|
-
sha256: request.sha256,
|
|
366
|
-
media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
|
|
367
|
-
});
|
|
368
|
-
const refused = refusedAttach(declared, request.locator);
|
|
369
|
-
if (refused !== null)
|
|
370
|
-
return refused;
|
|
371
|
-
const upload = houseUpload(declared.body?.upload);
|
|
372
|
-
if (upload === null)
|
|
373
|
-
return UNCERTAIN_READ;
|
|
374
|
-
const finished = await finishedUpload(transport, upload, request.blob);
|
|
375
|
-
if (finished === null)
|
|
376
|
-
return UNCERTAIN_READ;
|
|
377
|
-
const unfinished = refusedAttach(finished, request.locator);
|
|
378
|
-
if (unfinished !== null)
|
|
379
|
-
return unfinished;
|
|
380
|
-
const { path, revision } = (finished.body ?? {});
|
|
381
|
-
const root = `/rooms/${entry.handle}/`;
|
|
382
|
-
return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
|
|
383
|
-
? { kind: 'attached', path: path.slice(root.length), revision }
|
|
384
|
-
: UNCERTAIN_READ;
|
|
378
|
+
return attached(request, entry);
|
|
385
379
|
},
|
|
386
380
|
reached(locator, version, target) {
|
|
387
381
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
@@ -395,8 +389,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
395
389
|
search(_authorization, request) {
|
|
396
390
|
return houseSearch(transport, [...tracked.values()], request);
|
|
397
391
|
},
|
|
392
|
+
queryHouse(_authorization, request) {
|
|
393
|
+
return houseQuery(transport, request);
|
|
394
|
+
},
|
|
398
395
|
roomStream: {
|
|
399
|
-
hold
|
|
396
|
+
hold,
|
|
400
397
|
observe: notifications.observe,
|
|
401
398
|
},
|
|
402
399
|
conversations: notifications.conversations,
|
|
@@ -0,0 +1,61 @@
|
|
|
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 LOCAL_COPY_MANIFEST = ".house";
|
|
6
|
+
export declare const LOCAL_COPY_ROOT_NAMES: readonly string[];
|
|
7
|
+
export declare const AUTHORED_NAME_MAX_BYTES = 255;
|
|
8
|
+
export declare const AUTHORED_PATH_MAX_BYTES = 768;
|
|
9
|
+
export declare const AUTHORED_NAME_RULE: {
|
|
10
|
+
readonly refusedCharacters: '/\\:*?"<>|';
|
|
11
|
+
readonly controlCharacters: 'Cc';
|
|
12
|
+
readonly refusedEnds: ' .';
|
|
13
|
+
readonly refusedStart: '-';
|
|
14
|
+
readonly gitNames: readonly ['.git', 'git~1'];
|
|
15
|
+
readonly windowsNames: readonly ["CON", "PRN", "AUX", "NUL", ...string[]];
|
|
16
|
+
readonly generatedNames: readonly ["_provenance", "_revisions", "_derived"];
|
|
17
|
+
readonly nameMaxBytes: 255;
|
|
18
|
+
readonly pathMaxBytes: 768;
|
|
19
|
+
};
|
|
20
|
+
export type NameRefusal = {
|
|
21
|
+
readonly rule: 'unicode';
|
|
22
|
+
} | {
|
|
23
|
+
readonly rule: 'character';
|
|
24
|
+
readonly character: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly rule: 'empty';
|
|
27
|
+
} | {
|
|
28
|
+
readonly rule: 'dots';
|
|
29
|
+
} | {
|
|
30
|
+
readonly rule: 'end';
|
|
31
|
+
readonly character: string;
|
|
32
|
+
} | {
|
|
33
|
+
readonly rule: 'git';
|
|
34
|
+
} | {
|
|
35
|
+
readonly rule: 'windows';
|
|
36
|
+
readonly reserved: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly rule: 'name_bytes';
|
|
39
|
+
readonly bytes: number;
|
|
40
|
+
} | {
|
|
41
|
+
readonly rule: 'start';
|
|
42
|
+
} | {
|
|
43
|
+
readonly rule: 'generated';
|
|
44
|
+
} | {
|
|
45
|
+
readonly rule: 'nfc';
|
|
46
|
+
};
|
|
47
|
+
export type PathRefusal = (NameRefusal & {
|
|
48
|
+
readonly name: string;
|
|
49
|
+
}) | {
|
|
50
|
+
readonly rule: 'root';
|
|
51
|
+
readonly name: string;
|
|
52
|
+
} | {
|
|
53
|
+
readonly rule: 'path_bytes';
|
|
54
|
+
readonly bytes: number;
|
|
55
|
+
};
|
|
56
|
+
export declare function utf8Bytes(text: string): number;
|
|
57
|
+
export declare function nameRefusal(name: string): NameRefusal | null;
|
|
58
|
+
export declare function pathRefusal(path: string): PathRefusal | null;
|
|
59
|
+
export declare function admittedPath(path: string): boolean;
|
|
60
|
+
export declare function sameName(left: string, right: string): boolean;
|
|
61
|
+
export declare function fittedName(name: string, count?: number, tail?: string): string;
|
|
@@ -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,mBAAmB,WAAW,CAAC;AAI5C,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAKlD,CAAC;AAEF,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAI3C,eAAO,MAAM,kBAAkB;aAC7B,iBAAiB,EAAE,YAAY;aAC/B,iBAAiB,EAAE,IAAI;aACvB,WAAW,EAAE,IAAI;aACjB,YAAY,EAAE,GAAG;aACjB,QAAQ,YAAG,MAAM,EAAE,OAAO;aAC1B,YAAY;aAUZ,cAAc;aACd,YAAY;aACZ,YAAY;CACJ,CAAC;AAEX,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC;AAE7B,MAAM,MAAM,WAAW,GACnB,CAAC,WAAW,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GACzC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAsB5D,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO9C;AAYD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAiB5D;AASD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAU5D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKlD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7D;AAyCD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAI,EAAE,IAAI,SAAK,GAAG,MAAM,CAUrE"}
|