@agentshouse/mdruntime-adapter 0.1.0-alpha.8 → 0.1.0-c6ddfd288ac81
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/AGENTS.md +157 -26
- package/README.md +32 -0
- package/dist/actions.d.ts +4 -12
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +239 -332
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +257 -194
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +20 -18
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +182 -210
- package/dist/gather.d.ts +3 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +40 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/links.d.ts +11 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +51 -0
- package/dist/map.d.ts +2 -2
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +6 -7
- package/dist/model.d.ts +2 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +21 -39
- package/dist/read.d.ts +29 -23
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +222 -195
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +30 -51
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +108 -124
- package/dist/stream.d.ts +9 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +186 -203
- package/dist/transport.d.ts +45 -28
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -3
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +23 -18
- package/dist/write.d.ts +9 -3
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +123 -196
- package/package.json +4 -12
- 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.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;AA0ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAuBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAiCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA4YpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,61 +1,89 @@
|
|
|
1
|
-
import { DISCOVER_PREFIXES,
|
|
2
|
-
import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf } from './model.js';
|
|
1
|
+
import { DISCOVER_PREFIXES, HOUSE_SCHEMA, capabilities, discoveredRoom, locatorOf, mapDiscovery, parseDiscovery, providerSelection, trackedFrom, } from './discovery.js';
|
|
2
|
+
import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf, } from './model.js';
|
|
3
|
+
import { gathered, selections } from './gather.js';
|
|
3
4
|
import { createSiteAdapter } from './site.js';
|
|
4
|
-
import {
|
|
5
|
+
import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, schemaFrom, schemaPath, viewOf, } from './read.js';
|
|
6
|
+
import { enumeratedLinks, scopeLinks, streamedLinks } from './links.js';
|
|
5
7
|
import { houseAction } from './actions.js';
|
|
6
|
-
import { classifyDoor, discoveryFailure } from './refusal.js';
|
|
8
|
+
import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
|
|
7
9
|
import { houseNotifications } from './stream.js';
|
|
8
|
-
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS,
|
|
9
|
-
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, rejectedMapping, revisionBody, uploadable } from './write.js';
|
|
10
|
-
import { logPosition, presented } from './version.js';
|
|
11
|
-
const UNCERTAIN = {
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
const RESOLVED_OUTCOMES = new Set([
|
|
15
|
-
'accepted',
|
|
16
|
-
'conflicted',
|
|
17
|
-
'rejected',
|
|
18
|
-
'expired'
|
|
19
|
-
]);
|
|
10
|
+
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, DOOR_SELECTION_MAX, PRIVATE_LOCATOR, } from './transport.js';
|
|
11
|
+
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
12
|
+
import { logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
13
|
+
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
14
|
+
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
20
15
|
function lapsedGrant(outcome) {
|
|
21
16
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
22
17
|
}
|
|
23
18
|
function modelFailure(classified, envelope) {
|
|
24
19
|
if (classified === null) {
|
|
25
|
-
return envelope === null ? {
|
|
26
|
-
kind: 'transport-uncertainty'
|
|
27
|
-
} : MODEL_ABSENT;
|
|
20
|
+
return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;
|
|
28
21
|
}
|
|
29
22
|
return failedModel(classified);
|
|
30
23
|
}
|
|
31
24
|
export function createAgentsHouseAdapter(options) {
|
|
32
|
-
if ('site' in options)
|
|
25
|
+
if ('site' in options)
|
|
26
|
+
return createSiteAdapter(options.site);
|
|
33
27
|
const transport = options.transport;
|
|
34
28
|
const notifications = houseNotifications(transport, 'credential');
|
|
35
29
|
const tracked = new Map();
|
|
30
|
+
const handed = new Map();
|
|
36
31
|
const models = modelShelf();
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
function bootstrappedRoom(envelope, entry) {
|
|
33
|
+
const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
|
|
34
|
+
if (scope === undefined)
|
|
35
|
+
return { kind: 'room-not-readable', locator: entry.locator };
|
|
36
|
+
handed.set(entry.locator, scopeLinks(scope));
|
|
37
|
+
return bootstrapOf(scope, entry);
|
|
38
|
+
}
|
|
39
|
+
function enumeratedRoom(enumeration, ask) {
|
|
40
|
+
const view = viewOf(enumeration, ask.entry);
|
|
41
|
+
if (view === undefined)
|
|
42
|
+
return { kind: 'room-not-readable', locator: ask.entry.locator };
|
|
43
|
+
const answer = refreshFrom(view, ask.entry, ask.fromRoomVersion);
|
|
44
|
+
if (answer.kind === 'net-advancement') {
|
|
45
|
+
handed.set(ask.entry.locator, enumeratedLinks(view, handed.get(ask.entry.locator)));
|
|
46
|
+
}
|
|
47
|
+
return answer;
|
|
48
|
+
}
|
|
49
|
+
function streamed(entry, request, from) {
|
|
50
|
+
const links = handed.get(entry.locator);
|
|
51
|
+
if (links?.roomVersion !== request.fromRoomVersion)
|
|
52
|
+
return null;
|
|
53
|
+
const advanced = notifications.advance(entry, from);
|
|
54
|
+
if (advanced === null)
|
|
55
|
+
return null;
|
|
56
|
+
if (request.minPosition !== undefined &&
|
|
57
|
+
!reachedVersion(advanced.page.roomVersion, request.minPosition, entry.logEpoch))
|
|
58
|
+
return null;
|
|
59
|
+
const relinked = streamedLinks(links, advanced);
|
|
60
|
+
if (relinked === null)
|
|
61
|
+
return null;
|
|
62
|
+
handed.set(entry.locator, relinked);
|
|
63
|
+
return advanced.page;
|
|
64
|
+
}
|
|
65
|
+
function held(envelope, entry, schema, failure) {
|
|
66
|
+
return heldModel(envelope === null ? null : schemaFrom(envelope, entry, schema), schemaPath(entry.handle, schema), failure);
|
|
67
|
+
}
|
|
68
|
+
function modelPrefixes(entry) {
|
|
69
|
+
return entry.schemas.map((schema) => schemaPath(entry.handle, schema));
|
|
40
70
|
}
|
|
41
71
|
async function acquireModels(entries) {
|
|
42
72
|
const acquired = new Map();
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (privateEntry !== undefined) {
|
|
58
|
-
acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, PROVIDER_SELECTION_MODEL_ROOT, `${authorityRoot(undefined)}/${PROVIDER_SELECTION_MODEL_ROOT}`, failure));
|
|
73
|
+
for (const part of selections(entries, (entry) => modelPrefixes(entry).length, DOOR_SELECTION_MAX)) {
|
|
74
|
+
const privateEntry = part.find((entry) => entry.locator === PRIVATE_LOCATOR);
|
|
75
|
+
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
76
|
+
prefixes: part.flatMap((entry) => modelPrefixes(entry)),
|
|
77
|
+
});
|
|
78
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
79
|
+
const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
80
|
+
const failure = modelFailure(classified, envelope);
|
|
81
|
+
for (const entry of part) {
|
|
82
|
+
acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.schema, failure));
|
|
83
|
+
}
|
|
84
|
+
if (privateEntry !== undefined) {
|
|
85
|
+
acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, HOUSE_SCHEMA, failure));
|
|
86
|
+
}
|
|
59
87
|
}
|
|
60
88
|
return acquired;
|
|
61
89
|
}
|
|
@@ -63,7 +91,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
63
91
|
const locator = locatorOf(authority);
|
|
64
92
|
const key = modelKey(locator, 'collection');
|
|
65
93
|
const collection = models.retain(key, acquired.get(key));
|
|
66
|
-
if (
|
|
94
|
+
if (locator !== PRIVATE_LOCATOR) {
|
|
67
95
|
return discoveredRoom(authority, collection?.identity ?? null, undefined);
|
|
68
96
|
}
|
|
69
97
|
const selection = models.retain(modelKey(locator, 'typed-selection'), acquired.get(modelKey(locator, 'typed-selection')));
|
|
@@ -72,214 +100,249 @@ export function createAgentsHouseAdapter(options) {
|
|
|
72
100
|
function authorityFor(locator) {
|
|
73
101
|
return tracked.get(locator);
|
|
74
102
|
}
|
|
103
|
+
function withAt(result) {
|
|
104
|
+
if (result.kind !== 'action')
|
|
105
|
+
return result;
|
|
106
|
+
const body = result.result;
|
|
107
|
+
if (typeof body !== 'object' || body === null)
|
|
108
|
+
return result;
|
|
109
|
+
const { authority, position, log_epoch: logEpoch } = body;
|
|
110
|
+
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
111
|
+
return result;
|
|
112
|
+
const locator = authority === undefined
|
|
113
|
+
? PRIVATE_LOCATOR
|
|
114
|
+
: [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
115
|
+
if (locator === undefined)
|
|
116
|
+
return result;
|
|
117
|
+
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
118
|
+
}
|
|
75
119
|
async function bundled(body) {
|
|
76
120
|
const grant = parseGrant(body);
|
|
77
|
-
if (grant === null)
|
|
78
|
-
|
|
121
|
+
if (grant === null)
|
|
122
|
+
return body;
|
|
123
|
+
if (grant.method !== 'GET')
|
|
124
|
+
return null;
|
|
79
125
|
const answer = await transport.transfer({
|
|
80
|
-
act: '
|
|
126
|
+
act: 'local_copy_bundle',
|
|
81
127
|
method: 'GET',
|
|
82
|
-
url: grant.url
|
|
128
|
+
url: grant.url,
|
|
129
|
+
answer: 'json',
|
|
83
130
|
});
|
|
84
131
|
return answer.status === 200 ? answer.body : null;
|
|
85
132
|
}
|
|
86
|
-
|
|
133
|
+
function weight(entry) {
|
|
134
|
+
return contentPrefixes(entry).length;
|
|
135
|
+
}
|
|
136
|
+
async function bootstrapped(entries) {
|
|
137
|
+
const answers = [];
|
|
138
|
+
for (const part of selections(entries, weight, DOOR_SELECTION_MAX)) {
|
|
139
|
+
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
140
|
+
prefixes: part.flatMap((entry) => contentPrefixes(entry)),
|
|
141
|
+
});
|
|
142
|
+
const classified = part.map((entry) => classifyDoor(answer.status, answer.body, entry.locator));
|
|
143
|
+
const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
144
|
+
part.forEach((entry, index) => {
|
|
145
|
+
const failure = classified[index];
|
|
146
|
+
if (failure === null || failure === undefined) {
|
|
147
|
+
answers.push(envelope === null ? UNCERTAIN_READ : bootstrappedRoom(envelope, entry));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return answers;
|
|
154
|
+
}
|
|
155
|
+
function layered(asks) {
|
|
156
|
+
const depths = new Map();
|
|
157
|
+
const layers = [];
|
|
158
|
+
for (const ask of asks) {
|
|
159
|
+
const depth = depths.get(ask.entry.authority) ?? 0;
|
|
160
|
+
depths.set(ask.entry.authority, depth + 1);
|
|
161
|
+
(layers[depth] ??= []).push(ask);
|
|
162
|
+
}
|
|
163
|
+
return layers;
|
|
164
|
+
}
|
|
165
|
+
async function enumerated(asks) {
|
|
166
|
+
const answers = new Map();
|
|
167
|
+
const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry), DOOR_SELECTION_MAX));
|
|
168
|
+
for (const part of parts) {
|
|
169
|
+
let open = [...part];
|
|
170
|
+
while (open.length > 0) {
|
|
171
|
+
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
172
|
+
prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),
|
|
173
|
+
positions: open.map((ask) => ({
|
|
174
|
+
...presented(ask.entry.authority, ask.from),
|
|
175
|
+
...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),
|
|
176
|
+
})),
|
|
177
|
+
});
|
|
178
|
+
const refusal = doorRefusal(answer.body);
|
|
179
|
+
if (refusal?.code === 'replica_behind') {
|
|
180
|
+
const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);
|
|
181
|
+
const behind = named.length === 0 ? open : named;
|
|
182
|
+
for (const ask of behind)
|
|
183
|
+
answers.set(ask, { kind: 'retryable-refusal', ...refusal });
|
|
184
|
+
open = open.filter((ask) => !behind.includes(ask));
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const classified = open.map((ask) => classifyDoor(answer.status, answer.body, ask.entry.locator));
|
|
188
|
+
if (classified[0]?.kind === 'beyond-horizon') {
|
|
189
|
+
const named = doorRefusal(answer.body)?.fields.authority;
|
|
190
|
+
const expired = open.filter((ask) => ask.entry.authority === named);
|
|
191
|
+
const answered = expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };
|
|
192
|
+
const gone = expired.length === 0 ? open : expired;
|
|
193
|
+
for (const ask of gone)
|
|
194
|
+
answers.set(ask, answered);
|
|
195
|
+
open = open.filter((ask) => !gone.includes(ask));
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
|
|
199
|
+
open.forEach((ask, index) => {
|
|
200
|
+
const failure = classified[index];
|
|
201
|
+
if (failure !== null && failure !== undefined) {
|
|
202
|
+
answers.set(ask, failure);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
answers.set(ask, enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask));
|
|
206
|
+
});
|
|
207
|
+
open = [];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);
|
|
211
|
+
}
|
|
212
|
+
const bootstrapTogether = gathered(bootstrapped);
|
|
213
|
+
const enumerateTogether = gathered(enumerated);
|
|
214
|
+
async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
|
|
87
215
|
const paths = batchPaths(changes);
|
|
88
216
|
const sha256 = await deltaDigest(delta);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
const minted = await transport.door(DOOR_BATCH_UPLOAD, {
|
|
94
|
-
operation_id: identity,
|
|
95
|
-
paths,
|
|
96
|
-
bytes,
|
|
97
|
-
sha256
|
|
98
|
-
});
|
|
217
|
+
if (handed !== undefined && handed.sha256 === sha256) {
|
|
218
|
+
return { body: { ...head, paths, upload: handed } };
|
|
219
|
+
}
|
|
220
|
+
const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
|
|
99
221
|
if (minted.status !== 200) {
|
|
100
|
-
return {
|
|
101
|
-
outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)
|
|
102
|
-
};
|
|
222
|
+
return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };
|
|
103
223
|
}
|
|
104
224
|
const grant = parseGrant(minted.body);
|
|
105
|
-
if (grant === null || grant.method !== 'POST')
|
|
106
|
-
outcome: UNCERTAIN
|
|
107
|
-
};
|
|
225
|
+
if (grant === null || grant.method !== 'POST')
|
|
226
|
+
return { outcome: UNCERTAIN };
|
|
108
227
|
const delivered = await transport.transfer({
|
|
109
228
|
act: 'authored_batch_upload',
|
|
110
229
|
method: 'POST',
|
|
111
230
|
url: grant.url,
|
|
112
|
-
|
|
231
|
+
answer: 'json',
|
|
232
|
+
body: `${grant.operation}\n${delta}`,
|
|
113
233
|
});
|
|
114
|
-
if (delivered.status !== 200)
|
|
115
|
-
outcome: UNCERTAIN
|
|
116
|
-
};
|
|
234
|
+
if (delivered.status !== 200)
|
|
235
|
+
return { outcome: UNCERTAIN };
|
|
117
236
|
const holding = parseGrant(delivered.body);
|
|
118
|
-
if (holding === null
|
|
119
|
-
outcome: UNCERTAIN
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
paths,
|
|
124
|
-
upload: {
|
|
125
|
-
url: holding.url,
|
|
126
|
-
operation: holding.operation,
|
|
127
|
-
bytes,
|
|
128
|
-
sha256
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
submissions.set(identity, {
|
|
132
|
-
sha256,
|
|
133
|
-
body
|
|
134
|
-
});
|
|
135
|
-
return {
|
|
136
|
-
body
|
|
137
|
-
};
|
|
237
|
+
if (holding === null || holding.method !== 'POST')
|
|
238
|
+
return { outcome: UNCERTAIN };
|
|
239
|
+
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
240
|
+
await keep(upload);
|
|
241
|
+
return { body: { ...head, paths, upload } };
|
|
138
242
|
}
|
|
139
|
-
async function submit(
|
|
140
|
-
const prepared = uploadable(bytes)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
};
|
|
146
|
-
if ('outcome' in prepared) return prepared.outcome;
|
|
243
|
+
async function submit(head, changes, delta, bytes, entry, handed, keep) {
|
|
244
|
+
const prepared = uploadable(bytes)
|
|
245
|
+
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
246
|
+
: { body: { ...head, changes } };
|
|
247
|
+
if ('outcome' in prepared)
|
|
248
|
+
return prepared.outcome;
|
|
147
249
|
const answer = await transport.door(DOOR_BATCH, prepared.body);
|
|
148
250
|
return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);
|
|
149
251
|
}
|
|
150
252
|
return {
|
|
151
|
-
async authorize
|
|
253
|
+
async authorize() {
|
|
152
254
|
return options.authorize();
|
|
153
255
|
},
|
|
154
|
-
async model
|
|
256
|
+
async model(_authorization, request) {
|
|
155
257
|
return models.answer(request);
|
|
156
258
|
},
|
|
157
|
-
async discover
|
|
158
|
-
const answer = await transport.door(DOOR_DISCOVER, {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
});
|
|
163
|
-
const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);
|
|
164
|
-
if (classified !== null) return discoveryFailure(classified);
|
|
259
|
+
async discover(_authorization) {
|
|
260
|
+
const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });
|
|
261
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
262
|
+
if (classified !== null)
|
|
263
|
+
return discoveryFailure(classified);
|
|
165
264
|
const document = parseDiscovery(answer.body);
|
|
166
|
-
if (document === null)
|
|
167
|
-
kind: 'transport-uncertainty'
|
|
168
|
-
};
|
|
265
|
+
if (document === null)
|
|
266
|
+
return { kind: 'transport-uncertainty' };
|
|
169
267
|
const entries = trackedFrom(document);
|
|
170
268
|
tracked.clear();
|
|
171
|
-
for (const entry of entries)
|
|
269
|
+
for (const entry of entries)
|
|
270
|
+
tracked.set(entry.locator, entry);
|
|
271
|
+
for (const locator of handed.keys())
|
|
272
|
+
if (!tracked.has(locator))
|
|
273
|
+
handed.delete(locator);
|
|
172
274
|
notifications.track(entries);
|
|
173
275
|
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());
|
|
276
|
+
models.keep(entries.map((entry) => entry.locator));
|
|
277
|
+
return mapDiscovery(document, document.authorities.map((authority) => roomOf(authority, acquired)), capabilities(document.actions));
|
|
176
278
|
},
|
|
177
|
-
async bootstrap
|
|
279
|
+
async bootstrap(_authorization, request) {
|
|
178
280
|
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);
|
|
281
|
+
if (entry === undefined)
|
|
282
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
283
|
+
if (request.pageToken !== undefined)
|
|
284
|
+
return { kind: 'transport-uncertainty' };
|
|
285
|
+
return bootstrapTogether(entry);
|
|
202
286
|
},
|
|
203
|
-
async refresh
|
|
287
|
+
async refresh(_authorization, request) {
|
|
204
288
|
const entry = authorityFor(request.locator);
|
|
205
|
-
if (entry === undefined)
|
|
206
|
-
kind: 'room-not-readable',
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (request.pageToken !== undefined) return {
|
|
210
|
-
kind: 'transport-uncertainty'
|
|
211
|
-
};
|
|
289
|
+
if (entry === undefined)
|
|
290
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
291
|
+
if (request.pageToken !== undefined)
|
|
292
|
+
return { kind: 'transport-uncertainty' };
|
|
212
293
|
const from = logPosition(request.fromRoomVersion);
|
|
213
|
-
if (from === null)
|
|
214
|
-
kind: 'beyond-horizon'
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
]
|
|
294
|
+
if (from === null)
|
|
295
|
+
return { kind: 'beyond-horizon' };
|
|
296
|
+
const answered = streamed(entry, request, from);
|
|
297
|
+
if (answered !== null)
|
|
298
|
+
return answered;
|
|
299
|
+
const minPosition = request.minPosition === undefined ? null : logPosition(request.minPosition);
|
|
300
|
+
return enumerateTogether({
|
|
301
|
+
entry,
|
|
302
|
+
from,
|
|
303
|
+
fromRoomVersion: request.fromRoomVersion,
|
|
304
|
+
...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),
|
|
225
305
|
});
|
|
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
306
|
},
|
|
234
|
-
async mutate
|
|
307
|
+
async mutate(_authorization, request, keep) {
|
|
235
308
|
const entry = authorityFor(request.locator);
|
|
236
|
-
if (entry === undefined)
|
|
237
|
-
kind: 'room-not-readable',
|
|
238
|
-
locator: request.locator
|
|
239
|
-
};
|
|
309
|
+
if (entry === undefined)
|
|
310
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
240
311
|
const mapped = houseChanges(request.changeBatch, entry.handle);
|
|
241
|
-
if (mapped.kind === 'unmapped')
|
|
242
|
-
|
|
312
|
+
if (mapped.kind === 'unmapped')
|
|
313
|
+
return rejectedMapping(mapped);
|
|
314
|
+
const head = operationHead(request.changeBatch);
|
|
243
315
|
const delta = deltaBody(mapped.changes);
|
|
244
316
|
const bytes = deltaBytes(delta);
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
if (RESOLVED_OUTCOMES.has(outcome.kind)) submissions.delete(identity);
|
|
252
|
-
return outcome;
|
|
317
|
+
const handed = request.upload;
|
|
318
|
+
const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);
|
|
319
|
+
if (handed === undefined || !lapsedGrant(outcome))
|
|
320
|
+
return outcome;
|
|
321
|
+
return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);
|
|
253
322
|
},
|
|
254
|
-
async history
|
|
323
|
+
async history(_authorization, request) {
|
|
255
324
|
const entry = authorityFor(request.locator);
|
|
256
|
-
if (entry === undefined)
|
|
257
|
-
kind: 'room-not-readable',
|
|
258
|
-
locator: request.locator
|
|
259
|
-
};
|
|
325
|
+
if (entry === undefined)
|
|
326
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
260
327
|
const answer = await transport.door(DOOR_REVISIONS, revisionBody({
|
|
261
328
|
path: request.path,
|
|
262
329
|
handle: entry.handle,
|
|
263
|
-
...request.revision === undefined ? {} : {
|
|
264
|
-
|
|
265
|
-
},
|
|
266
|
-
...request.pageToken === undefined ? {} : {
|
|
267
|
-
pageToken: request.pageToken
|
|
268
|
-
}
|
|
330
|
+
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
331
|
+
...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
|
|
269
332
|
}));
|
|
270
333
|
return historyOutcome(answer.status, answer.body, entry.locator, {
|
|
271
334
|
path: request.path,
|
|
272
|
-
...request.revision === undefined ? {} : {
|
|
273
|
-
revision: request.revision
|
|
274
|
-
}
|
|
335
|
+
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
275
336
|
});
|
|
276
337
|
},
|
|
277
|
-
|
|
278
|
-
return
|
|
338
|
+
reached(locator, version, target) {
|
|
339
|
+
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
340
|
+
},
|
|
341
|
+
async action(_authorization, request) {
|
|
342
|
+
return withAt(await houseAction(transport, request));
|
|
279
343
|
},
|
|
280
344
|
roomVersions: notifications,
|
|
281
|
-
conversations: notifications.conversations
|
|
345
|
+
conversations: notifications.conversations,
|
|
346
|
+
serviceMode: notifications.serviceMode,
|
|
282
347
|
};
|
|
283
348
|
}
|
|
284
|
-
|
|
285
|
-
//# sourceMappingURL=adapter.js.map
|
package/dist/digest.js
CHANGED
|
@@ -3,9 +3,5 @@ export function textBytes(value) {
|
|
|
3
3
|
}
|
|
4
4
|
export async function sha256Hex(value) {
|
|
5
5
|
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
|
|
6
|
-
return [
|
|
7
|
-
...new Uint8Array(digest)
|
|
8
|
-
].map((byte)=>byte.toString(16).padStart(2, '0')).join('');
|
|
6
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
9
7
|
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=digest.js.map
|
package/dist/discovery.d.ts
CHANGED
|
@@ -7,10 +7,14 @@ export declare const PROVIDER_ACTIONS = "provider-actions";
|
|
|
7
7
|
export declare const MOVE_REFERENCE_REWRITES = "move-reference-rewrites";
|
|
8
8
|
export declare const DISCOVER_PREFIXES: readonly string[];
|
|
9
9
|
export declare const PROVIDER_SELECTION_ROOTS: readonly string[];
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const UNTYPED_FOLDERS: readonly string[];
|
|
11
|
+
export declare const RESERVED_NAMES: readonly string[];
|
|
12
|
+
export declare const HOUSE_SCHEMA = "house/schema.yaml";
|
|
13
|
+
export declare const PRIVATE_HANDLE = "private";
|
|
11
14
|
export type HouseBounds = {
|
|
12
15
|
max_authored_file_bytes: number;
|
|
13
16
|
max_batch_operations: number;
|
|
17
|
+
max_batch_documents: number;
|
|
14
18
|
max_path_length: number;
|
|
15
19
|
max_path_depth: number;
|
|
16
20
|
max_mount_files: number;
|
|
@@ -25,12 +29,10 @@ export type HouseOperations = {
|
|
|
25
29
|
delete: readonly string[];
|
|
26
30
|
};
|
|
27
31
|
export type HouseAuthority = LogPosition & {
|
|
28
|
-
kind: 'room' | 'private';
|
|
29
32
|
roomRef: string;
|
|
30
|
-
roomHandle: string
|
|
33
|
+
roomHandle: string;
|
|
31
34
|
name: string;
|
|
32
|
-
|
|
33
|
-
modelRoot: string;
|
|
35
|
+
schema: string;
|
|
34
36
|
managedReplication: 'admitted' | 'unavailable';
|
|
35
37
|
protectedPaths: readonly string[];
|
|
36
38
|
operations: HouseOperations;
|
|
@@ -39,24 +41,27 @@ export type HouseDiscoveryDocument = {
|
|
|
39
41
|
bounds: HouseBounds;
|
|
40
42
|
mdModelVersion: string;
|
|
41
43
|
authorities: readonly HouseAuthority[];
|
|
44
|
+
actions: readonly string[];
|
|
42
45
|
};
|
|
43
46
|
export type TrackedAuthority = LogPosition & {
|
|
44
47
|
locator: string;
|
|
45
48
|
authority: string;
|
|
46
|
-
handle: string
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
handle: string;
|
|
50
|
+
schema: string;
|
|
51
|
+
schemas: readonly string[];
|
|
52
|
+
};
|
|
53
|
+
export type HouseSiteEntry = {
|
|
54
|
+
roomRef: string;
|
|
55
|
+
segment: string;
|
|
50
56
|
};
|
|
51
57
|
export type HouseSiteSlot = {
|
|
52
58
|
slot: string;
|
|
53
|
-
|
|
59
|
+
entries: readonly HouseSiteEntry[];
|
|
54
60
|
};
|
|
55
61
|
export type HouseSiteAuthority = LogPosition & {
|
|
56
62
|
roomRef: string;
|
|
57
63
|
roomHandle: string;
|
|
58
|
-
|
|
59
|
-
modelRoot: string;
|
|
64
|
+
schema: string;
|
|
60
65
|
};
|
|
61
66
|
export type HouseSiteDiscovery = {
|
|
62
67
|
bounds: HouseBounds;
|
|
@@ -64,18 +69,15 @@ export type HouseSiteDiscovery = {
|
|
|
64
69
|
slots: readonly HouseSiteSlot[];
|
|
65
70
|
authorities: readonly HouseSiteAuthority[];
|
|
66
71
|
};
|
|
67
|
-
export type SiteTracked = TrackedAuthority & {
|
|
68
|
-
slot: string;
|
|
69
|
-
};
|
|
70
72
|
export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
|
|
71
73
|
export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
|
|
72
|
-
export declare function
|
|
73
|
-
export declare function
|
|
74
|
+
export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
|
|
75
|
+
export declare function siteSlots(document: HouseSiteDiscovery): Discovery['slots'];
|
|
74
76
|
export declare function locatorOf(authority: HouseAuthority): string;
|
|
75
77
|
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
76
78
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
77
79
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
78
|
-
export declare function capabilities(): readonly Capability[];
|
|
80
|
+
export declare function capabilities(actions: readonly string[]): readonly Capability[];
|
|
79
81
|
export declare function siteCapabilities(): readonly Capability[];
|
|
80
82
|
export declare function providerSelection(attachedModel: TypedSelection['attachedModel']): TypedSelection;
|
|
81
83
|
export declare function discoveredRoom(authority: HouseAuthority, attachedModel: DiscoveredRoom['attachedModel'], typedSelection: TypedSelection | undefined): DiscoveredRoom;
|