@agentshouse/mdruntime-adapter 0.1.0-c9f1e531ad7c8 → 0.1.0-ca3a44982cbe7
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 +181 -92
- package/README.md +3 -3
- package/dist/actions.d.ts +43 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +141 -123
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +231 -156
- package/dist/discovery.d.ts +14 -27
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +56 -102
- package/dist/gather.d.ts +1 -0
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +11 -6
- package/dist/handed.d.ts +15 -0
- package/dist/handed.d.ts.map +1 -0
- package/dist/handed.js +38 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/model.d.ts +8 -18
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +63 -39
- package/dist/read.d.ts +16 -11
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +80 -106
- package/dist/referrer.d.ts +7 -0
- package/dist/referrer.d.ts.map +1 -0
- package/dist/referrer.js +35 -0
- package/dist/refusal.d.ts +5 -7
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +31 -32
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +89 -84
- package/dist/stream.d.ts +9 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +115 -77
- package/dist/transport.d.ts +50 -20
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -2
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +9 -0
- package/dist/write.d.ts +4 -5
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +98 -25
- package/package.json +4 -4
- package/dist/links.d.ts +0 -12
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -66
package/dist/adapter.js
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import { DISCOVER_PREFIXES,
|
|
2
|
-
import {
|
|
3
|
-
import { gathered, selections } from './gather.js';
|
|
1
|
+
import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
|
|
2
|
+
import { partModels, streamedModels, viewModels } from './model.js';
|
|
3
|
+
import { gathered, gatheredEach, selections } from './gather.js';
|
|
4
4
|
import { createSiteAdapter } from './site.js';
|
|
5
|
-
import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom,
|
|
6
|
-
import {
|
|
5
|
+
import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, viewOf, } from './read.js';
|
|
6
|
+
import { acceptedHanded, enumeratedHanded, heldHanded, scopeHanded, streamedHanded, } from './handed.js';
|
|
7
7
|
import { houseAction } from './actions.js';
|
|
8
|
-
import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
|
|
8
|
+
import { classifyDoor, classifyRead, discoveryFailure, doorRefusal } from './refusal.js';
|
|
9
9
|
import { houseNotifications } from './stream.js';
|
|
10
|
-
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE,
|
|
10
|
+
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
|
|
11
11
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
12
|
-
import {
|
|
12
|
+
import { houseReferrer } from './referrer.js';
|
|
13
|
+
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
13
14
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
14
15
|
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
15
16
|
function lapsedGrant(outcome) {
|
|
16
17
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
17
18
|
}
|
|
18
|
-
function modelFailure(classified, envelope) {
|
|
19
|
-
if (classified === null) {
|
|
20
|
-
return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;
|
|
21
|
-
}
|
|
22
|
-
return failedModel(classified);
|
|
23
|
-
}
|
|
24
19
|
export function createAgentsHouseAdapter(options) {
|
|
25
20
|
if ('site' in options)
|
|
26
21
|
return createSiteAdapter(options.site);
|
|
@@ -28,76 +23,80 @@ export function createAgentsHouseAdapter(options) {
|
|
|
28
23
|
const notifications = houseNotifications(transport, 'credential');
|
|
29
24
|
const tracked = new Map();
|
|
30
25
|
const handed = new Map();
|
|
31
|
-
|
|
32
|
-
function
|
|
33
|
-
|
|
26
|
+
let bounds;
|
|
27
|
+
function declared() {
|
|
28
|
+
if (bounds === undefined)
|
|
29
|
+
throw new Error('no Discovery declared the bounds');
|
|
30
|
+
return bounds;
|
|
31
|
+
}
|
|
32
|
+
async function bootstrappedRoom(envelope, scope, entry, continued) {
|
|
34
33
|
if (scope === undefined)
|
|
35
34
|
return { kind: 'room-not-readable', locator: entry.locator };
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const next = envelope.next?.room === entry.authority ? envelope.next.path : null;
|
|
36
|
+
if (continued === null && next === null)
|
|
37
|
+
handed.set(entry.locator, scopeHanded(scope));
|
|
38
|
+
else
|
|
39
|
+
handed.delete(entry.locator);
|
|
40
|
+
notifications.reach(entry.authority, scope);
|
|
41
|
+
const seen = [
|
|
42
|
+
...(continued?.seen ?? []),
|
|
43
|
+
...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
|
|
44
|
+
];
|
|
45
|
+
const models = await partModels(scope, entry, new Set(seen), next === null);
|
|
46
|
+
const continuation = next === null ? null : { after: next, seen };
|
|
47
|
+
return {
|
|
48
|
+
...bootstrapOf(scope),
|
|
49
|
+
...(models === undefined ? {} : { models }),
|
|
50
|
+
...(continuation === null ? {} : { pageToken: JSON.stringify(continuation) }),
|
|
51
|
+
};
|
|
39
52
|
}
|
|
40
|
-
function enumeratedRoom(enumeration, ask) {
|
|
53
|
+
async function enumeratedRoom(enumeration, ask) {
|
|
41
54
|
const view = viewOf(enumeration, ask.entry);
|
|
42
55
|
if (view === undefined)
|
|
43
56
|
return { kind: 'room-not-readable', locator: ask.entry.locator };
|
|
44
|
-
notifications.
|
|
45
|
-
const answer = refreshFrom(view, ask.
|
|
46
|
-
if (answer.kind
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
notifications.reach(ask.entry.authority, view);
|
|
58
|
+
const answer = refreshFrom(view, ask.fromRoomVersion);
|
|
59
|
+
if (answer.kind !== 'net-advancement')
|
|
60
|
+
return answer;
|
|
61
|
+
handed.set(ask.entry.locator, enumeratedHanded(view, handed.get(ask.entry.locator)));
|
|
62
|
+
const models = await viewModels(view, ask.entry);
|
|
63
|
+
return models === undefined ? answer : { ...answer, models };
|
|
50
64
|
}
|
|
51
|
-
function streamed(entry, request, from) {
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
65
|
+
async function streamed(entry, request, from) {
|
|
66
|
+
const held = handed.get(entry.locator);
|
|
67
|
+
if (held?.roomVersion !== request.fromRoomVersion)
|
|
54
68
|
return null;
|
|
55
|
-
const advanced = notifications.advance(entry, from, (path, revision) =>
|
|
69
|
+
const advanced = notifications.advance(entry, from, (path, revision) => held.revisions.get(path) === revision);
|
|
56
70
|
if (advanced === null)
|
|
57
71
|
return null;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const relinked = streamedLinks(links, advanced);
|
|
62
|
-
if (relinked === null)
|
|
63
|
-
return null;
|
|
64
|
-
handed.set(entry.locator, relinked);
|
|
65
|
-
return advanced.page;
|
|
72
|
+
handed.set(entry.locator, streamedHanded(held, advanced));
|
|
73
|
+
const models = await streamedModels(advanced.schemas, entry, 'credential');
|
|
74
|
+
return models === undefined ? advanced.page : { ...advanced.page, models };
|
|
66
75
|
}
|
|
67
|
-
function held(
|
|
68
|
-
|
|
76
|
+
function held(rooms) {
|
|
77
|
+
const kept = rooms.flatMap((room) => {
|
|
78
|
+
const entry = tracked.get(room.locator);
|
|
79
|
+
const at = logPosition(room.roomVersion);
|
|
80
|
+
if (entry === undefined || at === null)
|
|
81
|
+
return [];
|
|
82
|
+
handed.set(room.locator, heldHanded(room));
|
|
83
|
+
notifications.reach(entry.authority, at);
|
|
84
|
+
return [presented(entry.authority, at)];
|
|
85
|
+
});
|
|
86
|
+
notifications.send(kept);
|
|
69
87
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const failure = modelFailure(classified, envelope);
|
|
83
|
-
for (const entry of part) {
|
|
84
|
-
acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.schema, failure));
|
|
85
|
-
}
|
|
86
|
-
if (privateEntry !== undefined) {
|
|
87
|
-
acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, HOUSE_SCHEMA, failure));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return acquired;
|
|
91
|
-
}
|
|
92
|
-
function roomOf(authority, acquired) {
|
|
93
|
-
const locator = locatorOf(authority);
|
|
94
|
-
const key = modelKey(locator, 'collection');
|
|
95
|
-
const collection = models.retain(key, acquired.get(key));
|
|
96
|
-
if (locator !== PRIVATE_LOCATOR) {
|
|
97
|
-
return discoveredRoom(authority, collection?.identity ?? null, undefined);
|
|
98
|
-
}
|
|
99
|
-
const selection = models.retain(modelKey(locator, 'typed-selection'), acquired.get(modelKey(locator, 'typed-selection')));
|
|
100
|
-
return discoveredRoom(authority, collection?.identity ?? null, providerSelection(selection?.identity ?? null));
|
|
88
|
+
function adopted(entry, outcome) {
|
|
89
|
+
if (outcome.kind !== 'accepted')
|
|
90
|
+
return outcome;
|
|
91
|
+
const held = handed.get(entry.locator);
|
|
92
|
+
if (held === undefined)
|
|
93
|
+
return outcome;
|
|
94
|
+
const follows = followsVersion(held.roomVersion, outcome.roomVersion);
|
|
95
|
+
handed.set(entry.locator, acceptedHanded(held, outcome, follows ? outcome.roomVersion : held.roomVersion));
|
|
96
|
+
const at = logPosition(outcome.roomVersion);
|
|
97
|
+
if (follows && at !== null)
|
|
98
|
+
notifications.reach(entry.authority, at);
|
|
99
|
+
return outcome;
|
|
101
100
|
}
|
|
102
101
|
function authorityFor(locator) {
|
|
103
102
|
return tracked.get(locator);
|
|
@@ -111,48 +110,59 @@ export function createAgentsHouseAdapter(options) {
|
|
|
111
110
|
const { authority, position, log_epoch: logEpoch } = body;
|
|
112
111
|
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
113
112
|
return result;
|
|
114
|
-
const locator = authority ===
|
|
115
|
-
? PRIVATE_LOCATOR
|
|
116
|
-
: [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
113
|
+
const locator = [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
117
114
|
if (locator === undefined)
|
|
118
115
|
return result;
|
|
119
116
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
120
117
|
}
|
|
121
|
-
async function bundled(body) {
|
|
122
|
-
const grant = parseGrant(body);
|
|
123
|
-
if (grant === null)
|
|
124
|
-
return body;
|
|
125
|
-
if (grant.method !== 'GET')
|
|
126
|
-
return null;
|
|
127
|
-
const answer = await transport.transfer({
|
|
128
|
-
act: 'local_copy_bundle',
|
|
129
|
-
method: 'GET',
|
|
130
|
-
url: grant.url,
|
|
131
|
-
answer: 'json',
|
|
132
|
-
});
|
|
133
|
-
return answer.status === 200 ? answer.body : null;
|
|
134
|
-
}
|
|
135
118
|
function weight(entry) {
|
|
136
119
|
return contentPrefixes(entry).length;
|
|
137
120
|
}
|
|
138
|
-
async function bootstrapped(entries) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
121
|
+
async function bootstrapped(entries, answer) {
|
|
122
|
+
let open = entries.map((entry, ask) => ({ entry, ask }));
|
|
123
|
+
while (open.length > 0) {
|
|
124
|
+
const unreached = [];
|
|
125
|
+
for (const part of selections(open, ({ entry }) => weight(entry), declared().max_prefixes)) {
|
|
126
|
+
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
127
|
+
prefixes: part.flatMap(({ entry }) => contentPrefixes(entry)),
|
|
128
|
+
});
|
|
129
|
+
const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
|
|
130
|
+
const envelope = classified[0] === null ? parseEnvelope(answered.body) : null;
|
|
131
|
+
for (const [index, asked] of part.entries()) {
|
|
132
|
+
const failure = classified[index];
|
|
133
|
+
if (failure !== null && failure !== undefined) {
|
|
134
|
+
answer(asked.ask, failure);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (envelope === null) {
|
|
138
|
+
answer(asked.ask, UNCERTAIN_READ);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const scope = envelope.scopes.find((candidate) => matchesScope(candidate, asked.entry));
|
|
142
|
+
if (scope === undefined && envelope.next !== undefined) {
|
|
143
|
+
unreached.push(asked);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
answer(asked.ask, await bootstrappedRoom(envelope, scope, asked.entry, null));
|
|
151
147
|
}
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
}
|
|
149
|
+
open = unreached;
|
|
154
150
|
}
|
|
155
|
-
|
|
151
|
+
}
|
|
152
|
+
async function continuedBootstrap(entry, continued) {
|
|
153
|
+
const after = { room: entry.authority, path: continued.after };
|
|
154
|
+
const answered = await transport.door(DOOR_BOOTSTRAP, {
|
|
155
|
+
prefixes: contentPrefixes(entry),
|
|
156
|
+
after,
|
|
157
|
+
});
|
|
158
|
+
const failure = classifyDoor(answered.status, answered.body, entry.locator);
|
|
159
|
+
if (failure !== null)
|
|
160
|
+
return failure;
|
|
161
|
+
const envelope = parseEnvelope(answered.body);
|
|
162
|
+
if (envelope === null)
|
|
163
|
+
return UNCERTAIN_READ;
|
|
164
|
+
const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
|
|
165
|
+
return bootstrappedRoom(envelope, scope, entry, continued);
|
|
156
166
|
}
|
|
157
167
|
function layered(asks) {
|
|
158
168
|
const depths = new Map();
|
|
@@ -166,27 +176,15 @@ export function createAgentsHouseAdapter(options) {
|
|
|
166
176
|
}
|
|
167
177
|
async function enumerated(asks) {
|
|
168
178
|
const answers = new Map();
|
|
169
|
-
const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry),
|
|
179
|
+
const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry), declared().max_prefixes));
|
|
170
180
|
for (const part of parts) {
|
|
171
181
|
let open = [...part];
|
|
172
182
|
while (open.length > 0) {
|
|
173
183
|
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
174
184
|
prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),
|
|
175
|
-
positions: open.map((ask) => (
|
|
176
|
-
...presented(ask.entry.authority, ask.from),
|
|
177
|
-
...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),
|
|
178
|
-
})),
|
|
185
|
+
positions: open.map((ask) => presented(ask.entry.authority, ask.from)),
|
|
179
186
|
});
|
|
180
|
-
const
|
|
181
|
-
if (refusal?.code === 'replica_behind') {
|
|
182
|
-
const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);
|
|
183
|
-
const behind = named.length === 0 ? open : named;
|
|
184
|
-
for (const ask of behind)
|
|
185
|
-
answers.set(ask, { kind: 'retryable-refusal', ...refusal });
|
|
186
|
-
open = open.filter((ask) => !behind.includes(ask));
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
const classified = open.map((ask) => classifyDoor(answer.status, answer.body, ask.entry.locator));
|
|
187
|
+
const classified = open.map((ask) => classifyRead(answer.status, answer.body, ask.entry.locator));
|
|
190
188
|
if (classified[0]?.kind === 'beyond-horizon') {
|
|
191
189
|
const named = doorRefusal(answer.body)?.fields.authority;
|
|
192
190
|
const expired = open.filter((ask) => ask.entry.authority === named);
|
|
@@ -198,26 +196,26 @@ export function createAgentsHouseAdapter(options) {
|
|
|
198
196
|
continue;
|
|
199
197
|
}
|
|
200
198
|
const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
|
|
201
|
-
open.
|
|
199
|
+
for (const [index, ask] of open.entries()) {
|
|
202
200
|
const failure = classified[index];
|
|
203
201
|
if (failure !== null && failure !== undefined) {
|
|
204
202
|
answers.set(ask, failure);
|
|
205
|
-
|
|
203
|
+
continue;
|
|
206
204
|
}
|
|
207
|
-
answers.set(ask, enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask));
|
|
208
|
-
}
|
|
205
|
+
answers.set(ask, enumeration === null ? UNCERTAIN_READ : await enumeratedRoom(enumeration, ask));
|
|
206
|
+
}
|
|
209
207
|
open = [];
|
|
210
208
|
}
|
|
211
209
|
}
|
|
212
210
|
return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);
|
|
213
211
|
}
|
|
214
|
-
const bootstrapTogether =
|
|
212
|
+
const bootstrapTogether = gatheredEach(bootstrapped);
|
|
215
213
|
const enumerateTogether = gathered(enumerated);
|
|
216
214
|
async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
|
|
217
215
|
const paths = batchPaths(changes);
|
|
218
216
|
const sha256 = await deltaDigest(delta);
|
|
219
217
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
220
|
-
return { body: { ...head, paths, upload: handed } };
|
|
218
|
+
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
221
219
|
}
|
|
222
220
|
const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
|
|
223
221
|
if (minted.status !== 200) {
|
|
@@ -228,9 +226,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
228
226
|
return { outcome: UNCERTAIN };
|
|
229
227
|
const delivered = await transport.transfer({
|
|
230
228
|
act: 'authored_batch_upload',
|
|
231
|
-
method: 'POST',
|
|
232
229
|
url: grant.url,
|
|
233
|
-
answer: 'json',
|
|
234
230
|
body: `${grant.operation}\n${delta}`,
|
|
235
231
|
});
|
|
236
232
|
if (delivered.status !== 200)
|
|
@@ -240,32 +236,80 @@ export function createAgentsHouseAdapter(options) {
|
|
|
240
236
|
return { outcome: UNCERTAIN };
|
|
241
237
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
242
238
|
await keep(upload);
|
|
243
|
-
return { body: { ...head, paths, upload } };
|
|
239
|
+
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
244
240
|
}
|
|
245
|
-
async function
|
|
246
|
-
const
|
|
241
|
+
async function staged(answer, batch) {
|
|
242
|
+
const refusal = doorRefusal(answer.body);
|
|
243
|
+
if (refusal?.code !== 'files_unstaged')
|
|
244
|
+
return null;
|
|
245
|
+
const grants = refusal.fields.upload;
|
|
246
|
+
if (!Array.isArray(grants))
|
|
247
|
+
return false;
|
|
248
|
+
for (const grant of grants) {
|
|
249
|
+
const { url, operation, sha256 } = grant;
|
|
250
|
+
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === sha256);
|
|
251
|
+
if (typeof url !== 'string' || typeof operation !== 'string' || change === undefined)
|
|
252
|
+
return false;
|
|
253
|
+
const delivered = await transport.transfer({
|
|
254
|
+
act: 'binary_stage',
|
|
255
|
+
url,
|
|
256
|
+
body: change.blob,
|
|
257
|
+
operation,
|
|
258
|
+
});
|
|
259
|
+
if (delivered.status !== 200)
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
async function submit(batch, head, changes, delta, bytes, entry, handed, keep) {
|
|
265
|
+
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
266
|
+
const prepared = uploadable(inline, bytes, declared())
|
|
247
267
|
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
248
|
-
: { body:
|
|
268
|
+
: { body: inline };
|
|
249
269
|
if ('outcome' in prepared)
|
|
250
270
|
return prepared.outcome;
|
|
251
271
|
const answer = await transport.door(DOOR_BATCH, prepared.body);
|
|
252
|
-
|
|
272
|
+
const stagedFiles = await staged(answer, batch);
|
|
273
|
+
if (stagedFiles === false)
|
|
274
|
+
return UNCERTAIN;
|
|
275
|
+
const settled = stagedFiles === null ? answer : await transport.door(DOOR_BATCH, prepared.body);
|
|
276
|
+
if (stagedFiles === true && (await staged(settled, batch)) !== null)
|
|
277
|
+
return UNCERTAIN;
|
|
278
|
+
return mutationOutcome(settled.status, settled.body, entry.locator, entry.handle);
|
|
279
|
+
}
|
|
280
|
+
async function downloaded(answer, locator) {
|
|
281
|
+
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
282
|
+
if (failure !== null) {
|
|
283
|
+
return failure.kind === 'scoped-refusal'
|
|
284
|
+
? {
|
|
285
|
+
kind: 'rejected',
|
|
286
|
+
code: failure.code,
|
|
287
|
+
fields: failure.fields,
|
|
288
|
+
retryable: failure.retryable,
|
|
289
|
+
}
|
|
290
|
+
: failure;
|
|
291
|
+
}
|
|
292
|
+
const grant = parseGrant(answer.body);
|
|
293
|
+
if (grant === null || grant.method !== 'GET')
|
|
294
|
+
return UNCERTAIN_READ;
|
|
295
|
+
const read = await transport.download(grant.url);
|
|
296
|
+
if (read.status !== 200 || read.blob === null)
|
|
297
|
+
return UNCERTAIN_READ;
|
|
298
|
+
return { kind: 'binary', blob: read.blob };
|
|
253
299
|
}
|
|
254
300
|
return {
|
|
255
301
|
async authorize() {
|
|
256
302
|
return options.authorize();
|
|
257
303
|
},
|
|
258
|
-
async model(_authorization, request) {
|
|
259
|
-
return models.answer(request);
|
|
260
|
-
},
|
|
261
304
|
async discover(_authorization) {
|
|
262
305
|
const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
return
|
|
306
|
+
const failed = discoveryFailure(answer.status, answer.body);
|
|
307
|
+
if (failed !== null)
|
|
308
|
+
return failed;
|
|
266
309
|
const document = parseDiscovery(answer.body);
|
|
267
310
|
if (document === null)
|
|
268
311
|
return { kind: 'transport-uncertainty' };
|
|
312
|
+
bounds = document.bounds;
|
|
269
313
|
const entries = trackedFrom(document);
|
|
270
314
|
tracked.clear();
|
|
271
315
|
for (const entry of entries)
|
|
@@ -274,16 +318,18 @@ export function createAgentsHouseAdapter(options) {
|
|
|
274
318
|
if (!tracked.has(locator))
|
|
275
319
|
handed.delete(locator);
|
|
276
320
|
notifications.track(entries);
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
321
|
+
return {
|
|
322
|
+
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document)),
|
|
323
|
+
member: document.member,
|
|
324
|
+
};
|
|
280
325
|
},
|
|
281
326
|
async bootstrap(_authorization, request) {
|
|
282
327
|
const entry = authorityFor(request.locator);
|
|
283
328
|
if (entry === undefined)
|
|
284
329
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
285
|
-
if (request.pageToken !== undefined)
|
|
286
|
-
return
|
|
330
|
+
if (request.pageToken !== undefined) {
|
|
331
|
+
return continuedBootstrap(entry, JSON.parse(request.pageToken));
|
|
332
|
+
}
|
|
287
333
|
return bootstrapTogether(entry);
|
|
288
334
|
},
|
|
289
335
|
async refresh(_authorization, request) {
|
|
@@ -295,16 +341,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
295
341
|
const from = logPosition(request.fromRoomVersion);
|
|
296
342
|
if (from === null)
|
|
297
343
|
return { kind: 'beyond-horizon' };
|
|
298
|
-
const answered = streamed(entry, request, from);
|
|
344
|
+
const answered = await streamed(entry, request, from);
|
|
299
345
|
if (answered !== null)
|
|
300
346
|
return answered;
|
|
301
|
-
|
|
302
|
-
return enumerateTogether({
|
|
303
|
-
entry,
|
|
304
|
-
from,
|
|
305
|
-
fromRoomVersion: request.fromRoomVersion,
|
|
306
|
-
...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),
|
|
307
|
-
});
|
|
347
|
+
return enumerateTogether({ entry, from, fromRoomVersion: request.fromRoomVersion });
|
|
308
348
|
},
|
|
309
349
|
async mutate(_authorization, request, keep) {
|
|
310
350
|
const entry = authorityFor(request.locator);
|
|
@@ -317,10 +357,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
317
357
|
const delta = deltaBody(mapped.changes);
|
|
318
358
|
const bytes = deltaBytes(delta);
|
|
319
359
|
const handed = request.upload;
|
|
320
|
-
const
|
|
360
|
+
const batch = request.changeBatch;
|
|
361
|
+
const outcome = await submit(batch, head, mapped.changes, delta, bytes, entry, handed, keep);
|
|
321
362
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
322
|
-
return outcome;
|
|
323
|
-
return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);
|
|
363
|
+
return adopted(entry, outcome);
|
|
364
|
+
return adopted(entry, await submit(batch, head, mapped.changes, delta, bytes, entry, undefined, keep));
|
|
324
365
|
},
|
|
325
366
|
async history(_authorization, request) {
|
|
326
367
|
const entry = authorityFor(request.locator);
|
|
@@ -337,13 +378,47 @@ export function createAgentsHouseAdapter(options) {
|
|
|
337
378
|
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
338
379
|
});
|
|
339
380
|
},
|
|
381
|
+
async binary(_authorization, request) {
|
|
382
|
+
if (request.kind === 'path') {
|
|
383
|
+
const entry = authorityFor(request.locator);
|
|
384
|
+
if (entry === undefined)
|
|
385
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
386
|
+
const answer = await transport.door(DOOR_FILES_GET, {
|
|
387
|
+
room_ref: entry.authority,
|
|
388
|
+
path: request.path,
|
|
389
|
+
revision: request.revision,
|
|
390
|
+
});
|
|
391
|
+
return downloaded(answer, request.locator);
|
|
392
|
+
}
|
|
393
|
+
const referrer = houseReferrer(request.referrer, tracked);
|
|
394
|
+
if (referrer === null) {
|
|
395
|
+
return { kind: 'rejected', code: 'referrer_unknown', fields: {}, retryable: false };
|
|
396
|
+
}
|
|
397
|
+
const answer = await transport.door(DOOR_FILES_GET, {
|
|
398
|
+
file: request.fileRef,
|
|
399
|
+
referrer: referrer.referrer,
|
|
400
|
+
});
|
|
401
|
+
return downloaded(answer, referrer.locator);
|
|
402
|
+
},
|
|
403
|
+
referrerScope(referrer) {
|
|
404
|
+
const held = houseReferrer(referrer, tracked);
|
|
405
|
+
if (held === null)
|
|
406
|
+
return null;
|
|
407
|
+
if (held.locator === '')
|
|
408
|
+
return { kind: 'conversations' };
|
|
409
|
+
const { path } = held.referrer;
|
|
410
|
+
return { kind: 'room', locator: held.locator, ...(path === undefined ? {} : { path }) };
|
|
411
|
+
},
|
|
340
412
|
reached(locator, version, target) {
|
|
341
413
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
342
414
|
},
|
|
415
|
+
follows(_locator, version, next) {
|
|
416
|
+
return followsVersion(version, next);
|
|
417
|
+
},
|
|
343
418
|
async action(_authorization, request) {
|
|
344
419
|
return withAt(await houseAction(transport, request));
|
|
345
420
|
},
|
|
346
|
-
|
|
421
|
+
roomStream: { hold: held, reopen: notifications.reopen, observe: notifications.observe },
|
|
347
422
|
conversations: notifications.conversations,
|
|
348
423
|
serviceMode: notifications.serviceMode,
|
|
349
424
|
};
|
package/dist/discovery.d.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import type { Capability, DiscoveredRoom, Discovery, ProviderLimit, Retention
|
|
1
|
+
import type { Capability, DiscoveredRoom, Discovery, Member, ProviderLimit, Retention } from '@agentshouse/mdruntime';
|
|
2
2
|
import { type LogPosition } from './version.js';
|
|
3
|
-
export declare const ROOM_CONTRACT_VERSION = 1;
|
|
4
|
-
export declare const MD_MODEL_IDENTITY = "@agentshouse/mdmodel";
|
|
5
|
-
export declare const ROOM_VERSION_NOTIFICATIONS = "room-version-notifications";
|
|
6
3
|
export declare const PROVIDER_ACTIONS = "provider-actions";
|
|
7
|
-
export declare const MOVE_REFERENCE_REWRITES = "move-reference-rewrites";
|
|
8
4
|
export declare const DISCOVER_PREFIXES: readonly string[];
|
|
9
|
-
export declare const PROVIDER_SELECTION_ROOTS: readonly string[];
|
|
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";
|
|
14
5
|
export type HouseBounds = {
|
|
15
6
|
max_authored_file_bytes: number;
|
|
16
7
|
max_batch_operations: number;
|
|
@@ -19,6 +10,9 @@ export type HouseBounds = {
|
|
|
19
10
|
max_path_depth: number;
|
|
20
11
|
max_mount_files: number;
|
|
21
12
|
max_mount_bytes: number;
|
|
13
|
+
max_inline_body_bytes: number;
|
|
14
|
+
max_upload_bytes: number;
|
|
15
|
+
max_prefixes: number;
|
|
22
16
|
change_retention_seconds: number;
|
|
23
17
|
operation_retention_seconds: number;
|
|
24
18
|
};
|
|
@@ -28,18 +22,23 @@ export type HouseOperations = {
|
|
|
28
22
|
write: readonly string[];
|
|
29
23
|
delete: readonly string[];
|
|
30
24
|
};
|
|
25
|
+
export type HouseModel = {
|
|
26
|
+
root: string;
|
|
27
|
+
paths: readonly string[];
|
|
28
|
+
};
|
|
31
29
|
export type HouseAuthority = LogPosition & {
|
|
32
30
|
roomRef: string;
|
|
33
31
|
roomHandle: string;
|
|
34
32
|
name: string;
|
|
35
33
|
schema: string;
|
|
34
|
+
houseModel: HouseModel | null;
|
|
36
35
|
managedReplication: 'admitted' | 'unavailable';
|
|
37
36
|
protectedPaths: readonly string[];
|
|
38
37
|
operations: HouseOperations;
|
|
39
38
|
};
|
|
40
39
|
export type HouseDiscoveryDocument = {
|
|
40
|
+
member: Member;
|
|
41
41
|
bounds: HouseBounds;
|
|
42
|
-
mdModelVersion: string;
|
|
43
42
|
authorities: readonly HouseAuthority[];
|
|
44
43
|
actions: readonly string[];
|
|
45
44
|
};
|
|
@@ -48,16 +47,9 @@ export type TrackedAuthority = LogPosition & {
|
|
|
48
47
|
authority: string;
|
|
49
48
|
handle: string;
|
|
50
49
|
schema: string;
|
|
50
|
+
houseModel: HouseModel | null;
|
|
51
51
|
schemas: readonly string[];
|
|
52
52
|
};
|
|
53
|
-
export type HouseSiteEntry = {
|
|
54
|
-
roomRef: string;
|
|
55
|
-
segment: string;
|
|
56
|
-
};
|
|
57
|
-
export type HouseSiteSlot = {
|
|
58
|
-
slot: string;
|
|
59
|
-
entries: readonly HouseSiteEntry[];
|
|
60
|
-
};
|
|
61
53
|
export type HouseSiteAuthority = LogPosition & {
|
|
62
54
|
roomRef: string;
|
|
63
55
|
roomHandle: string;
|
|
@@ -65,21 +57,16 @@ export type HouseSiteAuthority = LogPosition & {
|
|
|
65
57
|
};
|
|
66
58
|
export type HouseSiteDiscovery = {
|
|
67
59
|
bounds: HouseBounds;
|
|
68
|
-
mdModelVersion: string;
|
|
69
|
-
slots: readonly HouseSiteSlot[];
|
|
70
60
|
authorities: readonly HouseSiteAuthority[];
|
|
71
61
|
};
|
|
72
62
|
export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
|
|
73
63
|
export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
|
|
74
64
|
export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
|
|
75
|
-
export declare function siteSlots(document: HouseSiteDiscovery): Discovery['slots'];
|
|
76
|
-
export declare function locatorOf(authority: HouseAuthority): string;
|
|
77
65
|
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
78
66
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
79
67
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
80
|
-
export declare function capabilities(
|
|
68
|
+
export declare function capabilities(document: HouseDiscoveryDocument): readonly Capability[];
|
|
81
69
|
export declare function siteCapabilities(): readonly Capability[];
|
|
82
|
-
export declare function
|
|
83
|
-
export declare function
|
|
84
|
-
export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds' | 'mdModelVersion'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
|
|
70
|
+
export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
|
|
71
|
+
export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
|
|
85
72
|
//# sourceMappingURL=discovery.d.ts.map
|
package/dist/discovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,SAAS,
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,MAAM,EACN,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAAU,CAAC;AAE1D,MAAM,MAAM,WAAW,GAAG;IACxB,uBAAuB,EAAE,MAAM,CAAC;IAChC,oBAAoB,EAAE,MAAM,CAAC;IA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