@agentshouse/mdruntime-adapter 0.1.0-cb8fc491b1a92 → 0.1.0-cb9d322ed68c3
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 +12 -163
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +195 -223
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +219 -214
- 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 +39 -9
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +224 -35
- 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 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -8
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -9
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +28 -26
- package/dist/read.d.ts +20 -24
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +106 -176
- 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 +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 +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +102 -67
- 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 +15 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +195 -67
- package/dist/transport.d.ts +79 -27
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +53 -13
- 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 +2 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +94 -129
- 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 -2983
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -1643
- 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 -19
- 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 -126
package/dist/adapter.d.ts
CHANGED
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAkBd,MAAM,wBAAwB,CAAC;AAqChC,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAoBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAcrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAmdpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,99 +1,131 @@
|
|
|
1
|
+
import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
|
|
1
2
|
import { stepped } from '@agentshouse/mdruntime';
|
|
2
|
-
import {
|
|
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 {
|
|
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_RENAMED_UNTIL_2026_12_22, HOUSE_REWRITTEN_UNTIL_2026_12_19, HOUSE_REWRITTEN_UNTIL_2026_12_21, HOUSE_REWRITTEN_UNTIL_2026_12_22, HOUSE_UNKEPT_READS, rewrittenInTurn, } 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';
|
|
11
14
|
import { houseDoorRoute, } from './transport.js';
|
|
15
|
+
import { renamedHandle } from './renamed.js';
|
|
12
16
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
13
|
-
import {
|
|
14
|
-
import { followsVersion,
|
|
15
|
-
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
16
|
-
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
17
|
-
const OCTET_STREAM = 'application/octet-stream';
|
|
17
|
+
import { admittedPath } from './authored-path.js';
|
|
18
|
+
import { followsVersion, reachedVersion, roomVersion } from './version.js';
|
|
18
19
|
const EXPIRED_ADDRESS = 403;
|
|
19
20
|
function lapsedGrant(outcome) {
|
|
20
21
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
21
22
|
}
|
|
22
|
-
async function heldFiles(authority, held, bound) {
|
|
23
|
-
const listed = await held.files(null, bound + 1);
|
|
24
|
-
const files = listed.slice(0, bound);
|
|
25
|
-
const through = listed.length > bound ? (files.at(-1)?.path ?? null) : null;
|
|
26
|
-
return files.length === 0 ? null : { room: authority, through, files };
|
|
27
|
-
}
|
|
28
|
-
async function reused(scope, held) {
|
|
29
|
-
const sent = new Set(scope.contents.map((entry) => entry.path));
|
|
30
|
-
const contents = [...scope.contents];
|
|
31
|
-
const asked = scope.files.filter((file) => file.binary === undefined && !sent.has(file.path));
|
|
32
|
-
if (asked.length === 0)
|
|
33
|
-
return scope;
|
|
34
|
-
if (held === undefined)
|
|
35
|
-
return null;
|
|
36
|
-
const kept = await held.contents(asked.map(({ path }) => path));
|
|
37
|
-
for (const file of asked) {
|
|
38
|
-
const found = kept.get(file.path);
|
|
39
|
-
if (found === undefined ||
|
|
40
|
-
found.revision !== file.revision ||
|
|
41
|
-
(await sha256Hex(found.content)) !== file.sha256) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
contents.push({ path: file.path, content: found.content });
|
|
45
|
-
}
|
|
46
|
-
return { ...scope, contents };
|
|
47
|
-
}
|
|
48
23
|
export function createAgentsHouseAdapter(options) {
|
|
49
24
|
if ('site' in options)
|
|
50
25
|
return createSiteAdapter(options.site, options.snapshot === true);
|
|
51
26
|
const transport = options.transport;
|
|
52
|
-
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
|
+
});
|
|
53
32
|
const tracked = new Map();
|
|
54
|
-
const
|
|
55
|
-
const
|
|
33
|
+
const lister = chunkLister(transport, () => declared().max_prefixes, (locator) => tracked.get(locator));
|
|
34
|
+
const chunked = new Map();
|
|
35
|
+
const renewals = new WeakMap();
|
|
56
36
|
let bounds;
|
|
57
37
|
function declared() {
|
|
58
38
|
if (bounds === undefined)
|
|
59
39
|
throw new Error('no Discovery declared the bounds');
|
|
60
40
|
return bounds;
|
|
61
41
|
}
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
42
|
+
function opened(frame) {
|
|
43
|
+
const document = parseDiscovery(frame);
|
|
44
|
+
if (document === null)
|
|
45
|
+
return null;
|
|
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()]);
|
|
71
52
|
return {
|
|
72
|
-
...(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
53
|
+
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
54
|
+
member: document.member,
|
|
55
|
+
timeZone: document.timeZone,
|
|
56
|
+
roomList: document.roomList,
|
|
76
57
|
};
|
|
77
58
|
}
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
59
|
+
function changed(frame) {
|
|
60
|
+
const change = parseAuthorityChange(frame);
|
|
61
|
+
if (change === null)
|
|
62
|
+
return null;
|
|
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
|
+
};
|
|
90
77
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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);
|
|
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);
|
|
97
129
|
}
|
|
98
130
|
function authorityFor(locator) {
|
|
99
131
|
return tracked.get(locator);
|
|
@@ -118,8 +150,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
118
150
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
119
151
|
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
120
152
|
}
|
|
121
|
-
const minted = await transport.door(houseDoorRoute('
|
|
153
|
+
const minted = await transport.door(houseDoorRoute('update'), {
|
|
122
154
|
...head,
|
|
155
|
+
op: 'stage',
|
|
123
156
|
paths,
|
|
124
157
|
bytes,
|
|
125
158
|
sha256,
|
|
@@ -131,39 +164,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
131
164
|
}
|
|
132
165
|
const grant = parseGrant(minted.body);
|
|
133
166
|
if (grant === null)
|
|
134
|
-
return { outcome:
|
|
167
|
+
return { outcome: unusable() };
|
|
135
168
|
const delivered = await transport.transfer({
|
|
136
|
-
act: 'authored_batch_upload',
|
|
137
169
|
url: grant.url,
|
|
138
170
|
body: `${grant.operation}\n${delta}`,
|
|
139
171
|
});
|
|
140
|
-
if (delivered.status !== 200)
|
|
141
|
-
return { outcome:
|
|
172
|
+
if (delivered.status !== 200) {
|
|
173
|
+
return { outcome: answeredFailure(delivered.status, delivered.body) };
|
|
174
|
+
}
|
|
142
175
|
const holding = parseGrant(delivered.body);
|
|
143
176
|
if (holding === null)
|
|
144
|
-
return { outcome:
|
|
177
|
+
return { outcome: unusable() };
|
|
145
178
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
146
179
|
await keep(upload);
|
|
147
180
|
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
148
181
|
}
|
|
149
|
-
async function staged(answer, { changeBatch: batch, file }) {
|
|
150
|
-
const refusal = doorRefusal(answer.body);
|
|
151
|
-
if (refusal?.code !== 'files_unstaged')
|
|
152
|
-
return null;
|
|
153
|
-
const uploads = refusal.fields.upload;
|
|
154
|
-
if (!Array.isArray(uploads))
|
|
155
|
-
return false;
|
|
156
|
-
for (const named of uploads) {
|
|
157
|
-
const upload = houseUpload(named);
|
|
158
|
-
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
|
|
159
|
-
if (upload === null || change === undefined)
|
|
160
|
-
return false;
|
|
161
|
-
const finished = await finishedUpload(transport, upload, await file(change.localId));
|
|
162
|
-
if (finished?.body?.staged !== true)
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
182
|
async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
|
|
168
183
|
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
169
184
|
const prepared = uploadable(inline, bytes, declared())
|
|
@@ -171,13 +186,12 @@ export function createAgentsHouseAdapter(options) {
|
|
|
171
186
|
: { body: inline };
|
|
172
187
|
if ('outcome' in prepared)
|
|
173
188
|
return prepared.outcome;
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
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;
|
|
181
195
|
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
182
196
|
? undefined
|
|
183
197
|
: {
|
|
@@ -185,28 +199,26 @@ export function createAgentsHouseAdapter(options) {
|
|
|
185
199
|
destination: { authority: into.authority, handle: into.handle },
|
|
186
200
|
}));
|
|
187
201
|
}
|
|
188
|
-
function
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
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);
|
|
202
218
|
}
|
|
203
|
-
function
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
|
|
207
|
-
: address;
|
|
208
|
-
}
|
|
209
|
-
function refusedAttach(answer, locator) {
|
|
219
|
+
function refusedOn(answer, locator) {
|
|
220
|
+
if (locator === null)
|
|
221
|
+
return keyedFailure(answer.status, answer.body);
|
|
210
222
|
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
211
223
|
if (failure === null)
|
|
212
224
|
return null;
|
|
@@ -219,6 +231,48 @@ export function createAgentsHouseAdapter(options) {
|
|
|
219
231
|
}
|
|
220
232
|
: failure;
|
|
221
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
|
+
}
|
|
222
276
|
async function downloaded(ask, locator) {
|
|
223
277
|
let address = addressed(await ask(), locator);
|
|
224
278
|
if (address.kind !== 'address')
|
|
@@ -230,20 +284,24 @@ export function createAgentsHouseAdapter(options) {
|
|
|
230
284
|
return address;
|
|
231
285
|
read = await transport.download(address.url);
|
|
232
286
|
}
|
|
233
|
-
if (read.status !== 200
|
|
234
|
-
return
|
|
287
|
+
if (read.status !== 200)
|
|
288
|
+
return answeredFailure(read.status, null);
|
|
289
|
+
if (read.body === null)
|
|
290
|
+
return unusable();
|
|
235
291
|
return {
|
|
236
292
|
kind: 'binary',
|
|
237
293
|
body: read.body,
|
|
238
294
|
mediaType: address.mediaType,
|
|
239
295
|
sha256: address.sha256,
|
|
296
|
+
url: address.url,
|
|
297
|
+
copies: address.copies,
|
|
240
298
|
};
|
|
241
299
|
}
|
|
242
300
|
function pathAddress(request) {
|
|
243
301
|
const entry = authorityFor(request.locator);
|
|
244
302
|
if (entry === undefined)
|
|
245
303
|
return null;
|
|
246
|
-
return () => transport.door(houseDoorRoute('files/
|
|
304
|
+
return () => transport.door(houseDoorRoute('files/read'), {
|
|
247
305
|
room_ref: entry.authority,
|
|
248
306
|
path: request.path,
|
|
249
307
|
revision: request.revision,
|
|
@@ -251,94 +309,54 @@ export function createAgentsHouseAdapter(options) {
|
|
|
251
309
|
}
|
|
252
310
|
return {
|
|
253
311
|
roomTypes: HOUSE_ROOM_TYPES,
|
|
254
|
-
|
|
312
|
+
typedPaths: HOUSE_TYPED_PATHS,
|
|
313
|
+
pathRule: admittedPath,
|
|
314
|
+
unkeptReads: HOUSE_UNKEPT_READS,
|
|
315
|
+
leadingReads: HOUSE_LEADING_READS,
|
|
316
|
+
renamedActions: new Map([
|
|
317
|
+
...HOUSE_RENAMED_UNTIL_2026_12_18,
|
|
318
|
+
...HOUSE_RENAMED_UNTIL_2026_12_21,
|
|
319
|
+
...HOUSE_RENAMED_UNTIL_2026_12_22,
|
|
320
|
+
]),
|
|
321
|
+
rewrittenInputs: rewrittenInTurn(HOUSE_REWRITTEN_UNTIL_2026_12_19, HOUSE_REWRITTEN_UNTIL_2026_12_21, HOUSE_REWRITTEN_UNTIL_2026_12_22),
|
|
255
322
|
async authorize() {
|
|
256
323
|
return options.authorize();
|
|
257
324
|
},
|
|
258
|
-
async discover(_authorization, scope) {
|
|
259
|
-
const answer = await transport.door(houseDoorRoute('discover'), {
|
|
260
|
-
prefixes: [...DISCOVER_PREFIXES],
|
|
261
|
-
...(scope === undefined ? {} : { rooms: scope.authorities }),
|
|
262
|
-
});
|
|
263
|
-
const failed = discoveryFailure(answer.status, answer.body);
|
|
264
|
-
if (failed !== null)
|
|
265
|
-
return failed;
|
|
266
|
-
const document = parseDiscovery(answer.body);
|
|
267
|
-
if (document === null)
|
|
268
|
-
return { kind: 'transport-uncertainty' };
|
|
269
|
-
bounds = document.bounds;
|
|
270
|
-
const entries = trackedFrom(document);
|
|
271
|
-
const covered = scope === undefined
|
|
272
|
-
? null
|
|
273
|
-
: [
|
|
274
|
-
...new Set([
|
|
275
|
-
...[...tracked.values()]
|
|
276
|
-
.filter((entry) => scope.authorities.includes(entry.authority))
|
|
277
|
-
.map((entry) => entry.locator),
|
|
278
|
-
...entries.map((entry) => entry.locator),
|
|
279
|
-
]),
|
|
280
|
-
];
|
|
281
|
-
if (covered === null)
|
|
282
|
-
tracked.clear();
|
|
283
|
-
else
|
|
284
|
-
for (const locator of covered)
|
|
285
|
-
tracked.delete(locator);
|
|
286
|
-
for (const entry of entries)
|
|
287
|
-
tracked.set(entry.locator, entry);
|
|
288
|
-
notifications.track([...tracked.values()]);
|
|
289
|
-
return {
|
|
290
|
-
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
291
|
-
member: document.member,
|
|
292
|
-
...(covered === null ? {} : { covered }),
|
|
293
|
-
};
|
|
294
|
-
},
|
|
295
325
|
async bootstrap(_authorization, request) {
|
|
296
326
|
const entry = authorityFor(request.locator);
|
|
297
327
|
if (entry === undefined)
|
|
298
328
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
299
329
|
return request.pageToken === undefined
|
|
300
|
-
?
|
|
301
|
-
:
|
|
330
|
+
? listedRoom(entry)
|
|
331
|
+
: chunkPage(entry, request.pageToken, request.arriving);
|
|
302
332
|
},
|
|
303
333
|
async mutate(_authorization, request, keep) {
|
|
304
334
|
const entry = authorityFor(request.locator);
|
|
305
335
|
if (entry === undefined)
|
|
306
336
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
307
|
-
const
|
|
308
|
-
const destination = batch.between?.destination.room;
|
|
337
|
+
const destination = request.changeBatch.between?.destination.room;
|
|
309
338
|
const into = destination === undefined ? undefined : authorityFor(destination);
|
|
310
339
|
if (destination !== undefined && into === undefined) {
|
|
311
340
|
return { kind: 'room-not-readable', locator: destination };
|
|
312
341
|
}
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (mapped.kind === 'unmapped')
|
|
317
|
-
return rejectedMapping(mapped);
|
|
318
|
-
const head = operationHead(batch);
|
|
319
|
-
const delta = deltaBody(mapped.changes);
|
|
320
|
-
const bytes = deltaBytes(delta);
|
|
321
|
-
const handed = request.upload;
|
|
322
|
-
const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
|
|
323
|
-
const outcome = await answer(handed);
|
|
324
|
-
if (handed === undefined || !lapsedGrant(outcome))
|
|
342
|
+
const outcome = await mutated(request, keep, entry, into);
|
|
343
|
+
const renamed = renamedHandle(outcome);
|
|
344
|
+
if (renamed === null)
|
|
325
345
|
return outcome;
|
|
326
|
-
|
|
346
|
+
const moved = (held) => held.handle === renamed.from ? { ...held, handle: renamed.to } : held;
|
|
347
|
+
return mutated(request, keep, moved(entry), into === undefined ? undefined : moved(into));
|
|
327
348
|
},
|
|
328
349
|
async history(_authorization, request) {
|
|
329
350
|
const entry = authorityFor(request.locator);
|
|
330
351
|
if (entry === undefined)
|
|
331
352
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
332
|
-
const answer = await transport.door(houseDoorRoute('revisions'), revisionBody({
|
|
353
|
+
const answer = await transport.door(houseDoorRoute('files/revisions/list'), revisionBody({
|
|
333
354
|
path: request.path,
|
|
334
355
|
handle: entry.handle,
|
|
335
356
|
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
336
357
|
...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
|
|
337
358
|
}));
|
|
338
|
-
return historyOutcome(answer.status, answer.body, entry.locator,
|
|
339
|
-
path: request.path,
|
|
340
|
-
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
341
|
-
});
|
|
359
|
+
return historyOutcome(answer.status, answer.body, entry.locator, request);
|
|
342
360
|
},
|
|
343
361
|
async binary(_authorization, request) {
|
|
344
362
|
const ask = pathAddress(request);
|
|
@@ -347,39 +365,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
347
365
|
return downloaded(ask, request.locator);
|
|
348
366
|
},
|
|
349
367
|
async link(_authorization, request) {
|
|
368
|
+
if (request.kind === 'key') {
|
|
369
|
+
return linked(await transport.door(houseDoorRoute('files/read'), { link: request.link }), null);
|
|
370
|
+
}
|
|
350
371
|
const ask = pathAddress(request);
|
|
351
372
|
if (ask === null)
|
|
352
373
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
353
374
|
return linked(await ask(), request.locator);
|
|
354
375
|
},
|
|
355
376
|
async attach(_authorization, request) {
|
|
377
|
+
if (request.locator === undefined)
|
|
378
|
+
return attached(request, null);
|
|
356
379
|
const entry = authorityFor(request.locator);
|
|
357
380
|
if (entry === undefined)
|
|
358
381
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
359
|
-
|
|
360
|
-
room_ref: entry.authority,
|
|
361
|
-
name: request.name,
|
|
362
|
-
bytes: request.byteLength,
|
|
363
|
-
sha256: request.sha256,
|
|
364
|
-
media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
|
|
365
|
-
});
|
|
366
|
-
const refused = refusedAttach(declared, request.locator);
|
|
367
|
-
if (refused !== null)
|
|
368
|
-
return refused;
|
|
369
|
-
const upload = houseUpload(declared.body?.upload);
|
|
370
|
-
if (upload === null)
|
|
371
|
-
return UNCERTAIN_READ;
|
|
372
|
-
const finished = await finishedUpload(transport, upload, request.blob);
|
|
373
|
-
if (finished === null)
|
|
374
|
-
return UNCERTAIN_READ;
|
|
375
|
-
const unfinished = refusedAttach(finished, request.locator);
|
|
376
|
-
if (unfinished !== null)
|
|
377
|
-
return unfinished;
|
|
378
|
-
const { path, revision } = (finished.body ?? {});
|
|
379
|
-
const root = `/rooms/${entry.handle}/`;
|
|
380
|
-
return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
|
|
381
|
-
? { kind: 'attached', path: path.slice(root.length), revision }
|
|
382
|
-
: UNCERTAIN_READ;
|
|
382
|
+
return attached(request, entry);
|
|
383
383
|
},
|
|
384
384
|
reached(locator, version, target) {
|
|
385
385
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
@@ -390,9 +390,14 @@ export function createAgentsHouseAdapter(options) {
|
|
|
390
390
|
async action(_authorization, request) {
|
|
391
391
|
return withAt(await houseAction(transport, request));
|
|
392
392
|
},
|
|
393
|
+
search(_authorization, request) {
|
|
394
|
+
return houseSearch(transport, [...tracked.values()], request);
|
|
395
|
+
},
|
|
396
|
+
queryHouse(_authorization, request) {
|
|
397
|
+
return houseQuery(transport, request);
|
|
398
|
+
},
|
|
393
399
|
roomStream: {
|
|
394
|
-
hold
|
|
395
|
-
reopen: notifications.reopen,
|
|
400
|
+
hold,
|
|
396
401
|
observe: notifications.observe,
|
|
397
402
|
},
|
|
398
403
|
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"}
|