@agentshouse/mdruntime-adapter 0.1.0-alpha.40 → 0.1.0-alpha.42
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 +22 -11
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +153 -49
- package/dist/adapter.js.map +1 -1
- package/dist/gather.d.ts +3 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +41 -0
- package/dist/gather.js.map +1 -0
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +51 -5
- package/dist/read.js.map +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +19 -3
- package/dist/site.js.map +1 -1
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +8 -1
- package/dist/stream.js.map +1 -1
- package/dist/transport.d.ts +9 -0
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +1 -0
- package/dist/transport.js.map +1 -1
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +10 -0
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
package/AGENTS.md
CHANGED
|
@@ -7,7 +7,7 @@ enforcement.
|
|
|
7
7
|
## The MD Runtime API
|
|
8
8
|
|
|
9
9
|
App code reaches the MD Runtime through the remote client. The surfaces are
|
|
10
|
-
Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, History, Call, Log,
|
|
10
|
+
Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, History, Call, Reached, Log,
|
|
11
11
|
storage loss, the reported persistence answer, deployment facts, Sync Status, the Service Mode,
|
|
12
12
|
reauthorization, conversation, the chat draft, and Presentation State.
|
|
13
13
|
|
|
@@ -33,9 +33,12 @@ queued.
|
|
|
33
33
|
Slots answers each Slot the Provider declares, in its order, with its entries
|
|
34
34
|
in order, each a Room and its segment; a Room two Slots list is the same Room.
|
|
35
35
|
|
|
36
|
-
Rooms, Slots, Query, Search, Observe, Types, Room Draft, and
|
|
37
|
-
network.
|
|
38
|
-
History and Call go to the Provider through the Adapter.
|
|
36
|
+
Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, and Reached never
|
|
37
|
+
touch the network.
|
|
38
|
+
History and Call go to the Provider through the Adapter. A Call result whose
|
|
39
|
+
effect the Provider places in a Room carries `at`, that Room and Room Version;
|
|
40
|
+
`reached(room, roomVersion)` answers whether the Room's confirmed state has
|
|
41
|
+
reached it, and the MD Runtime keeps refreshing that Room until it has. Each History revision
|
|
39
42
|
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`. Every
|
|
40
43
|
member of the
|
|
41
44
|
client is asynchronous. Results are detached snapshots. Nothing in this
|
|
@@ -73,11 +76,18 @@ data:
|
|
|
73
76
|
`backlinks: { field, types, where, pathPrefix }` keeps Documents that a
|
|
74
77
|
matching Document of the same Room references. Each keeps a Document once.
|
|
75
78
|
- **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
|
|
76
|
-
`preamble`, `markdown` and `
|
|
77
|
-
`'all'` or a list of names. Room and Path always return; a Markdown
|
|
78
|
-
also returns its MD Type. A non-Markdown Document or binary link
|
|
79
|
-
only Room and Path. An unselected part is absent. Select only
|
|
80
|
-
shows: a list that selects the Markdown hears every edit of it.
|
|
79
|
+
`preamble`, `markdown`, `backlinks` and `change`, where `fields` and `sections`
|
|
80
|
+
are `'all'` or a list of names. Room and Path always return; a Markdown
|
|
81
|
+
Document also returns its MD Type. A non-Markdown Document or binary link
|
|
82
|
+
target returns only Room and Path. An unselected part is absent. Select only
|
|
83
|
+
what a screen shows: a list that selects the Markdown hears every edit of it.
|
|
84
|
+
- **Change.** `change` is `{ author, time }` of the Document's head revision as
|
|
85
|
+
the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
|
|
86
|
+
or `null` for a write the Provider made itself, and `time` is the Provider's
|
|
87
|
+
ISO 8601 change time. It is `null` where the Provider delivered no time, as at
|
|
88
|
+
a Site. An unsent edit or move keeps it, an unsent creation has none, and a
|
|
89
|
+
saved write takes the Provider's own once it is Accepted and refreshed. A
|
|
90
|
+
Room's last change is its Document with the latest `time`.
|
|
81
91
|
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
|
|
82
92
|
with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
|
|
83
93
|
`room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
|
|
@@ -130,8 +140,9 @@ state, or by a local validation rule, and then creates nothing and leaves every
|
|
|
130
140
|
Room Draft in place. A directory move or removal is a move or removal part on
|
|
131
141
|
each Document and binary link target beneath it, saved together.
|
|
132
142
|
|
|
133
|
-
Outcomes follow the Provider's answer. Accepted
|
|
134
|
-
|
|
143
|
+
Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
|
|
144
|
+
queue, drawn over the confirmed layer, until the confirmed layer reaches the
|
|
145
|
+
Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired outcome record, and a change that no
|
|
135
146
|
longer applies over the Room each leave the queue and return as Room Drafts on
|
|
136
147
|
the Documents they changed, marked with why: the Provider's structured refusal
|
|
137
148
|
code and fields as returned, not known to have applied, or withdrawn locally.
|
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;AAqChC,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,CAqXpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { DISCOVER_PREFIXES, HOUSE_SCHEMA, capabilities, discoveredRoom, locatorOf, mapDiscovery, parseDiscovery, providerSelection, trackedFrom } from './discovery.js';
|
|
2
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
5
|
import { bootstrapFrom, contentPrefixes, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, schemaFrom, schemaPath } from './read.js';
|
|
5
6
|
import { houseAction } from './actions.js';
|
|
6
|
-
import { classifyDoor, discoveryFailure } from './refusal.js';
|
|
7
|
+
import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
|
|
7
8
|
import { houseNotifications } from './stream.js';
|
|
8
|
-
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, PRIVATE_LOCATOR } from './transport.js';
|
|
9
|
+
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, DOOR_SELECTION_MAX, PRIVATE_LOCATOR } from './transport.js';
|
|
9
10
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable } from './write.js';
|
|
10
|
-
import { logPosition, presented } from './version.js';
|
|
11
|
+
import { logPosition, presented, reachedVersion, roomVersion } from './version.js';
|
|
11
12
|
const UNCERTAIN = {
|
|
12
13
|
kind: 'transport-uncertainty'
|
|
13
14
|
};
|
|
15
|
+
const UNCERTAIN_READ = {
|
|
16
|
+
kind: 'transport-uncertainty'
|
|
17
|
+
};
|
|
14
18
|
function lapsedGrant(outcome) {
|
|
15
19
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
16
20
|
}
|
|
@@ -31,22 +35,31 @@ export function createAgentsHouseAdapter(options) {
|
|
|
31
35
|
function held(envelope, entry, schema, failure) {
|
|
32
36
|
return heldModel(envelope === null ? null : schemaFrom(envelope, entry, schema), schemaPath(entry.handle, schema), failure);
|
|
33
37
|
}
|
|
38
|
+
function modelPrefixes(entry) {
|
|
39
|
+
const own = schemaPath(entry.handle, entry.schema);
|
|
40
|
+
return entry.locator === PRIVATE_LOCATOR ? [
|
|
41
|
+
own,
|
|
42
|
+
schemaPath(undefined, HOUSE_SCHEMA)
|
|
43
|
+
] : [
|
|
44
|
+
own
|
|
45
|
+
];
|
|
46
|
+
}
|
|
34
47
|
async function acquireModels(entries) {
|
|
35
48
|
const acquired = new Map();
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
for (const part of selections(entries, (entry)=>modelPrefixes(entry).length, DOOR_SELECTION_MAX)){
|
|
50
|
+
const privateEntry = part.find((entry)=>entry.locator === PRIVATE_LOCATOR);
|
|
51
|
+
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
52
|
+
prefixes: part.flatMap((entry)=>modelPrefixes(entry))
|
|
53
|
+
});
|
|
54
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
55
|
+
const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
56
|
+
const failure = modelFailure(classified, envelope);
|
|
57
|
+
for (const entry of part){
|
|
58
|
+
acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.schema, failure));
|
|
59
|
+
}
|
|
60
|
+
if (privateEntry !== undefined) {
|
|
61
|
+
acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, HOUSE_SCHEMA, failure));
|
|
62
|
+
}
|
|
50
63
|
}
|
|
51
64
|
return acquired;
|
|
52
65
|
}
|
|
@@ -63,6 +76,27 @@ export function createAgentsHouseAdapter(options) {
|
|
|
63
76
|
function authorityFor(locator) {
|
|
64
77
|
return tracked.get(locator);
|
|
65
78
|
}
|
|
79
|
+
function withAt(result) {
|
|
80
|
+
if (result.kind !== 'action') return result;
|
|
81
|
+
const body = result.result;
|
|
82
|
+
if (typeof body !== 'object' || body === null) return result;
|
|
83
|
+
const { authority, position, log_epoch: logEpoch } = body;
|
|
84
|
+
if (typeof position !== 'string' || typeof logEpoch !== 'string') return result;
|
|
85
|
+
const locator = authority === undefined ? PRIVATE_LOCATOR : [
|
|
86
|
+
...tracked.values()
|
|
87
|
+
].find((entry)=>entry.authority === authority)?.locator;
|
|
88
|
+
if (locator === undefined) return result;
|
|
89
|
+
return {
|
|
90
|
+
...result,
|
|
91
|
+
at: {
|
|
92
|
+
locator,
|
|
93
|
+
roomVersion: roomVersion({
|
|
94
|
+
position,
|
|
95
|
+
logEpoch
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
66
100
|
async function bundled(body) {
|
|
67
101
|
const grant = parseGrant(body);
|
|
68
102
|
if (grant === null) return body;
|
|
@@ -75,6 +109,94 @@ export function createAgentsHouseAdapter(options) {
|
|
|
75
109
|
});
|
|
76
110
|
return answer.status === 200 ? answer.body : null;
|
|
77
111
|
}
|
|
112
|
+
function weight(entry) {
|
|
113
|
+
return contentPrefixes(entry).length;
|
|
114
|
+
}
|
|
115
|
+
async function bootstrapped(entries) {
|
|
116
|
+
const answers = [];
|
|
117
|
+
for (const part of selections(entries, weight, DOOR_SELECTION_MAX)){
|
|
118
|
+
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
119
|
+
prefixes: part.flatMap((entry)=>contentPrefixes(entry))
|
|
120
|
+
});
|
|
121
|
+
const classified = part.map((entry)=>classifyDoor(answer.status, answer.body, entry.locator));
|
|
122
|
+
const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
123
|
+
part.forEach((entry, index)=>{
|
|
124
|
+
const failure = classified[index];
|
|
125
|
+
if (failure === null || failure === undefined) {
|
|
126
|
+
answers.push(envelope === null ? UNCERTAIN_READ : bootstrapFrom(envelope, entry));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return answers;
|
|
133
|
+
}
|
|
134
|
+
function layered(asks) {
|
|
135
|
+
const depths = new Map();
|
|
136
|
+
const layers = [];
|
|
137
|
+
for (const ask of asks){
|
|
138
|
+
const depth = depths.get(ask.entry.authority) ?? 0;
|
|
139
|
+
depths.set(ask.entry.authority, depth + 1);
|
|
140
|
+
(layers[depth] ??= []).push(ask);
|
|
141
|
+
}
|
|
142
|
+
return layers;
|
|
143
|
+
}
|
|
144
|
+
async function enumerated(asks) {
|
|
145
|
+
const answers = new Map();
|
|
146
|
+
const parts = layered(asks).flatMap((layer)=>selections(layer, (ask)=>weight(ask.entry), DOOR_SELECTION_MAX));
|
|
147
|
+
for (const part of parts){
|
|
148
|
+
let open = [
|
|
149
|
+
...part
|
|
150
|
+
];
|
|
151
|
+
while(open.length > 0){
|
|
152
|
+
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
153
|
+
prefixes: open.flatMap((ask)=>contentPrefixes(ask.entry)),
|
|
154
|
+
positions: open.map((ask)=>({
|
|
155
|
+
...presented(ask.entry.authority, ask.from),
|
|
156
|
+
...ask.reach === undefined ? {} : {
|
|
157
|
+
reach: ask.reach
|
|
158
|
+
}
|
|
159
|
+
}))
|
|
160
|
+
});
|
|
161
|
+
const refusal = doorRefusal(answer.body);
|
|
162
|
+
if (refusal?.code === 'replica_behind') {
|
|
163
|
+
const named = open.filter((ask)=>ask.entry.authority === refusal.fields.authority);
|
|
164
|
+
const behind = named.length === 0 ? open : named;
|
|
165
|
+
for (const ask of behind)answers.set(ask, {
|
|
166
|
+
kind: 'retryable-refusal',
|
|
167
|
+
...refusal
|
|
168
|
+
});
|
|
169
|
+
open = open.filter((ask)=>!behind.includes(ask));
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const classified = open.map((ask)=>classifyDoor(answer.status, answer.body, ask.entry.locator));
|
|
173
|
+
if (classified[0]?.kind === 'beyond-horizon') {
|
|
174
|
+
const named = doorRefusal(answer.body)?.fields.authority;
|
|
175
|
+
const expired = open.filter((ask)=>ask.entry.authority === named);
|
|
176
|
+
const answered = expired.length === 0 ? UNCERTAIN_READ : {
|
|
177
|
+
kind: 'beyond-horizon'
|
|
178
|
+
};
|
|
179
|
+
const gone = expired.length === 0 ? open : expired;
|
|
180
|
+
for (const ask of gone)answers.set(ask, answered);
|
|
181
|
+
open = open.filter((ask)=>!gone.includes(ask));
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
|
|
185
|
+
open.forEach((ask, index)=>{
|
|
186
|
+
const failure = classified[index];
|
|
187
|
+
if (failure !== null && failure !== undefined) {
|
|
188
|
+
answers.set(ask, failure);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
answers.set(ask, enumeration === null ? UNCERTAIN_READ : refreshFrom(enumeration, ask.entry, ask.fromRoomVersion));
|
|
192
|
+
});
|
|
193
|
+
open = [];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return asks.map((ask)=>answers.get(ask) ?? UNCERTAIN_READ);
|
|
197
|
+
}
|
|
198
|
+
const bootstrapTogether = gathered(bootstrapped);
|
|
199
|
+
const enumerateTogether = gathered(enumerated);
|
|
78
200
|
async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
|
|
79
201
|
const paths = batchPaths(changes);
|
|
80
202
|
const sha256 = await deltaDigest(delta);
|
|
@@ -178,22 +300,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
178
300
|
if (request.pageToken !== undefined) return {
|
|
179
301
|
kind: 'transport-uncertainty'
|
|
180
302
|
};
|
|
181
|
-
|
|
182
|
-
prefixes: [
|
|
183
|
-
...contentPrefixes(entry)
|
|
184
|
-
]
|
|
185
|
-
});
|
|
186
|
-
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
187
|
-
if (classified !== null) {
|
|
188
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
189
|
-
kind: 'transport-uncertainty'
|
|
190
|
-
} : classified;
|
|
191
|
-
}
|
|
192
|
-
const envelope = parseEnvelope(await bundled(answer.body));
|
|
193
|
-
if (envelope === null) return {
|
|
194
|
-
kind: 'transport-uncertainty'
|
|
195
|
-
};
|
|
196
|
-
return bootstrapFrom(envelope, entry);
|
|
303
|
+
return bootstrapTogether(entry);
|
|
197
304
|
},
|
|
198
305
|
async refresh (_authorization, request) {
|
|
199
306
|
const entry = authorityFor(request.locator);
|
|
@@ -209,22 +316,16 @@ export function createAgentsHouseAdapter(options) {
|
|
|
209
316
|
kind: 'beyond-horizon'
|
|
210
317
|
};
|
|
211
318
|
const streamed = notifications.advance(entry, from);
|
|
212
|
-
if (streamed !== null) return streamed;
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
319
|
+
if (streamed !== null && (request.reach === undefined || reachedVersion(streamed.roomVersion, request.reach, entry.logEpoch))) return streamed;
|
|
320
|
+
const reach = request.reach === undefined ? null : logPosition(request.reach);
|
|
321
|
+
return enumerateTogether({
|
|
322
|
+
entry,
|
|
323
|
+
from,
|
|
324
|
+
fromRoomVersion: request.fromRoomVersion,
|
|
325
|
+
...reach?.logEpoch === from.logEpoch ? {
|
|
326
|
+
reach: reach.position
|
|
327
|
+
} : {}
|
|
220
328
|
});
|
|
221
|
-
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
222
|
-
if (classified !== null) return classified;
|
|
223
|
-
const enumeration = parseEnumeration(answer.body, 'credential');
|
|
224
|
-
if (enumeration === null) return {
|
|
225
|
-
kind: 'transport-uncertainty'
|
|
226
|
-
};
|
|
227
|
-
return refreshFrom(enumeration, entry, request.fromRoomVersion);
|
|
228
329
|
},
|
|
229
330
|
async mutate (_authorization, request, keep) {
|
|
230
331
|
const entry = authorityFor(request.locator);
|
|
@@ -265,8 +366,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
265
366
|
}
|
|
266
367
|
});
|
|
267
368
|
},
|
|
369
|
+
reached (locator, version, target) {
|
|
370
|
+
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
371
|
+
},
|
|
268
372
|
async action (_authorization, request) {
|
|
269
|
-
const result = await houseAction(transport, request);
|
|
373
|
+
const result = withAt(await houseAction(transport, request));
|
|
270
374
|
const answered = request.input?.conversation;
|
|
271
375
|
if (request.name === 'conversation.answer' && result.kind === 'action' && typeof answered === 'string') {
|
|
272
376
|
notifications.question(answered);
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/adapter.ts"],"sourcesContent":["import type {\n ActionRequest,\n ActionResult,\n Adapter,\n Authorization,\n BootstrapRequest,\n BootstrapResult,\n DiscoverResult,\n DiscoveredRoom,\n HistoryRequest,\n HistoryResult,\n ModelRequest,\n ModelResult,\n MutationRequest,\n MutationResult,\n RefreshRequest,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport {\n DISCOVER_PREFIXES,\n HOUSE_SCHEMA,\n capabilities,\n discoveredRoom,\n locatorOf,\n mapDiscovery,\n parseDiscovery,\n providerSelection,\n trackedFrom,\n type HouseAuthority,\n type TrackedAuthority,\n} from './discovery.js';\nimport {\n MODEL_ABSENT,\n failedModel,\n heldModel,\n modelKey,\n modelShelf,\n type HeldModel,\n} from './model.js';\nimport { createSiteAdapter } from './site.js';\nimport {\n bootstrapFrom,\n contentPrefixes,\n parseEnumeration,\n parseEnvelope,\n parseGrant,\n refreshFrom,\n schemaFrom,\n schemaPath,\n} from './read.js';\nimport { houseAction } from './actions.js';\nimport { classifyDoor, discoveryFailure } from './refusal.js';\nimport { houseNotifications } from './stream.js';\nimport {\n DOOR_BATCH,\n DOOR_BATCH_UPLOAD,\n DOOR_BOOTSTRAP,\n DOOR_DISCOVER,\n DOOR_ENUMERATE,\n DOOR_REVISIONS,\n PRIVATE_LOCATOR,\n type HouseSiteTransport,\n type HouseTransport,\n} from './transport.js';\nimport {\n batchPaths,\n deltaBody,\n deltaBytes,\n deltaDigest,\n historyOutcome,\n houseChanges,\n mutationOutcome,\n operationHead,\n rejectedMapping,\n revisionBody,\n uploadable,\n type OperationHead,\n} from './write.js';\nimport { logPosition, presented } from './version.js';\n\nexport type AgentsHouseAdapterOptions =\n | {\n transport: HouseTransport;\n authorize(): Promise<Authorization>;\n }\n | { site: HouseSiteTransport };\n\nconst UNCERTAIN: MutationResult = { kind: 'transport-uncertainty' };\n\ntype Submission = { body: Record<string, unknown> } | { outcome: MutationResult };\n\ntype Upload = { url: string; operation: string; bytes: number; sha256: string };\n\ntype Keep = (upload: unknown) => Promise<void>;\n\nfunction lapsedGrant(outcome: MutationResult): boolean {\n return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';\n}\n\nfunction modelFailure(\n classified: ReturnType<typeof classifyDoor>,\n envelope: ReturnType<typeof parseEnvelope>,\n): ModelResult {\n if (classified === null) {\n return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;\n }\n return failedModel(classified);\n}\n\nexport function createAgentsHouseAdapter(options: AgentsHouseAdapterOptions): Adapter {\n if ('site' in options) return createSiteAdapter(options.site);\n const transport = options.transport;\n const notifications = houseNotifications(transport, 'credential');\n const tracked = new Map<string, TrackedAuthority>();\n const models = modelShelf();\n\n function held(\n envelope: ReturnType<typeof parseEnvelope>,\n entry: TrackedAuthority,\n schema: string,\n failure: ModelResult,\n ): Promise<HeldModel> {\n return heldModel(\n envelope === null ? null : schemaFrom(envelope, entry, schema),\n schemaPath(entry.handle, schema),\n failure,\n );\n }\n\n async function acquireModels(\n entries: readonly TrackedAuthority[],\n ): Promise<Map<string, HeldModel>> {\n const acquired = new Map<string, HeldModel>();\n const privateEntry = entries.find((entry) => entry.locator === PRIVATE_LOCATOR);\n const prefixes = entries.map((entry) => schemaPath(entry.handle, entry.schema));\n if (privateEntry !== undefined) prefixes.push(schemaPath(undefined, HOUSE_SCHEMA));\n const answer = await transport.door(DOOR_BOOTSTRAP, { prefixes });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;\n const failure: ModelResult = modelFailure(classified, envelope);\n for (const entry of entries) {\n acquired.set(\n modelKey(entry.locator, 'collection'),\n await held(envelope, entry, entry.schema, failure),\n );\n }\n if (privateEntry !== undefined) {\n acquired.set(\n modelKey(privateEntry.locator, 'typed-selection'),\n await held(envelope, privateEntry, HOUSE_SCHEMA, failure),\n );\n }\n return acquired;\n }\n\n function roomOf(authority: HouseAuthority, acquired: Map<string, HeldModel>): DiscoveredRoom {\n const locator = locatorOf(authority);\n const key = modelKey(locator, 'collection');\n const collection = models.retain(key, acquired.get(key));\n if (authority.roomHandle !== null) {\n return discoveredRoom(authority, collection?.identity ?? null, undefined);\n }\n const selection = models.retain(\n modelKey(locator, 'typed-selection'),\n acquired.get(modelKey(locator, 'typed-selection')),\n );\n return discoveredRoom(\n authority,\n collection?.identity ?? null,\n providerSelection(selection?.identity ?? null),\n );\n }\n\n function authorityFor(locator: string): TrackedAuthority | undefined {\n return tracked.get(locator);\n }\n\n async function bundled(body: unknown): Promise<unknown> {\n const grant = parseGrant(body);\n if (grant === null) return body;\n if (grant.method !== 'GET') return null;\n const answer = await transport.transfer({\n act: 'working_copy_bundle',\n method: 'GET',\n url: grant.url,\n answer: 'json',\n });\n return answer.status === 200 ? answer.body : null;\n }\n\n async function uploaded(\n head: OperationHead,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n handed: Upload | undefined,\n keep: Keep,\n ): Promise<Submission> {\n const paths = batchPaths(changes);\n const sha256 = await deltaDigest(delta);\n if (handed !== undefined && handed.sha256 === sha256) {\n return { body: { ...head, paths, upload: handed } };\n }\n const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });\n if (minted.status !== 200) {\n return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };\n }\n const grant = parseGrant(minted.body);\n if (grant === null || grant.method !== 'POST') return { outcome: UNCERTAIN };\n const delivered = await transport.transfer({\n act: 'authored_batch_upload',\n method: 'POST',\n url: grant.url,\n answer: 'json',\n body: `${grant.operation}\\n${delta}`,\n });\n if (delivered.status !== 200) return { outcome: UNCERTAIN };\n const holding = parseGrant(delivered.body);\n if (holding === null || holding.method !== 'POST') return { outcome: UNCERTAIN };\n const upload: Upload = { url: holding.url, operation: holding.operation, bytes, sha256 };\n await keep(upload);\n return { body: { ...head, paths, upload } };\n }\n\n async function submit(\n head: OperationHead,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n handed: Upload | undefined,\n keep: Keep,\n ): Promise<MutationResult> {\n const prepared: Submission = uploadable(bytes)\n ? await uploaded(head, changes, delta, bytes, entry, handed, keep)\n : { body: { ...head, changes } };\n if ('outcome' in prepared) return prepared.outcome;\n const answer = await transport.door(DOOR_BATCH, prepared.body);\n return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);\n }\n\n return {\n async authorize() {\n return options.authorize();\n },\n\n async model(_authorization: Authorization, request: ModelRequest): Promise<ModelResult> {\n return models.answer(request);\n },\n\n async discover(_authorization: Authorization): Promise<DiscoverResult> {\n const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n if (classified !== null) return discoveryFailure(classified);\n const document = parseDiscovery(answer.body);\n if (document === null) return { kind: 'transport-uncertainty' };\n const entries = trackedFrom(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n notifications.track(entries);\n const acquired = await acquireModels(entries);\n models.keep(entries.map((entry) => entry.locator));\n return mapDiscovery(\n document,\n document.authorities.map((authority) => roomOf(authority, acquired)),\n capabilities(document.actions),\n );\n },\n\n async bootstrap(\n _authorization: Authorization,\n request: BootstrapRequest,\n ): Promise<BootstrapResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n const answer = await transport.door(DOOR_BOOTSTRAP, {\n prefixes: [...contentPrefixes(entry)],\n });\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) {\n return classified.kind === 'beyond-horizon'\n ? { kind: 'transport-uncertainty' }\n : classified;\n }\n const envelope = parseEnvelope(await bundled(answer.body));\n if (envelope === null) return { kind: 'transport-uncertainty' };\n return bootstrapFrom(envelope, entry);\n },\n\n async refresh(_authorization: Authorization, request: RefreshRequest): Promise<RefreshResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n const from = logPosition(request.fromRoomVersion);\n if (from === null) return { kind: 'beyond-horizon' };\n const streamed = notifications.advance(entry, from);\n if (streamed !== null) return streamed;\n const answer = await transport.door(DOOR_ENUMERATE, {\n prefixes: [...contentPrefixes(entry)],\n positions: [presented(entry.authority, from)],\n });\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return classified;\n const enumeration = parseEnumeration(answer.body, 'credential');\n if (enumeration === null) return { kind: 'transport-uncertainty' };\n return refreshFrom(enumeration, entry, request.fromRoomVersion);\n },\n\n async mutate(\n _authorization: Authorization,\n request: MutationRequest,\n keep: Keep,\n ): Promise<MutationResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const mapped = houseChanges(request.changeBatch, entry.handle);\n if (mapped.kind === 'unmapped') return rejectedMapping(mapped);\n const head = operationHead(request.changeBatch);\n const delta = deltaBody(mapped.changes);\n const bytes = deltaBytes(delta);\n const handed = request.upload as Upload | undefined;\n const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);\n if (handed === undefined || !lapsedGrant(outcome)) return outcome;\n return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);\n },\n\n async history(_authorization: Authorization, request: HistoryRequest): Promise<HistoryResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const answer = await transport.door(\n DOOR_REVISIONS,\n revisionBody({\n path: request.path,\n handle: entry.handle,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n ...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),\n }),\n );\n return historyOutcome(answer.status, answer.body, entry.locator, {\n path: request.path,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n });\n },\n\n async action(_authorization: Authorization, request: ActionRequest): Promise<ActionResult> {\n const result = await houseAction(transport, request);\n const answered = (request.input as { conversation?: unknown } | null)?.conversation;\n if (\n request.name === 'conversation.answer' &&\n result.kind === 'action' &&\n typeof answered === 'string'\n ) {\n notifications.question(answered);\n }\n return result;\n },\n\n roomVersions: notifications,\n conversations: notifications.conversations,\n serviceMode: notifications.serviceMode,\n };\n}\n"],"names":["DISCOVER_PREFIXES","HOUSE_SCHEMA","capabilities","discoveredRoom","locatorOf","mapDiscovery","parseDiscovery","providerSelection","trackedFrom","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","createSiteAdapter","bootstrapFrom","contentPrefixes","parseEnumeration","parseEnvelope","parseGrant","refreshFrom","schemaFrom","schemaPath","houseAction","classifyDoor","discoveryFailure","houseNotifications","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_BOOTSTRAP","DOOR_DISCOVER","DOOR_ENUMERATE","DOOR_REVISIONS","PRIVATE_LOCATOR","batchPaths","deltaBody","deltaBytes","deltaDigest","historyOutcome","houseChanges","mutationOutcome","operationHead","rejectedMapping","revisionBody","uploadable","logPosition","presented","UNCERTAIN","kind","lapsedGrant","outcome","code","modelFailure","classified","envelope","createAgentsHouseAdapter","options","site","transport","notifications","tracked","Map","models","held","entry","schema","failure","handle","acquireModels","entries","acquired","privateEntry","find","locator","prefixes","map","undefined","push","answer","door","status","body","bundled","set","roomOf","authority","key","collection","retain","get","roomHandle","identity","selection","authorityFor","grant","method","transfer","act","url","uploaded","head","changes","delta","bytes","handed","keep","paths","sha256","upload","minted","delivered","operation","holding","submit","prepared","authorize","model","_authorization","request","discover","document","clear","track","authorities","actions","bootstrap","pageToken","refresh","from","fromRoomVersion","streamed","advance","positions","enumeration","mutate","mapped","changeBatch","history","path","revision","action","result","answered","input","conversation","name","question","roomVersions","conversations","serviceMode"],"mappings":"AAkBA,SACEA,iBAAiB,EACjBC,YAAY,EACZC,YAAY,EACZC,cAAc,EACdC,SAAS,EACTC,YAAY,EACZC,cAAc,EACdC,iBAAiB,EACjBC,WAAW,QAGN,iBAAiB;AACxB,SACEC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,UAAU,QAEL,aAAa;AACpB,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SACEC,aAAa,EACbC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,EACbC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,UAAU,QACL,YAAY;AACnB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,eAAe;AAC9D,SAASC,kBAAkB,QAAQ,cAAc;AACjD,SACEC,UAAU,EACVC,iB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Aa,UACpB;gBACAnF,cAAcuF,QAAQ,CAACJ;YACzB;YACA,OAAOD;QACT;QAEAM,cAAcxF;QACdyF,eAAezF,cAAcyF,aAAa;QAC1CC,aAAa1F,cAAc0F,WAAW;IACxC;AACF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/adapter.ts"],"sourcesContent":["import type {\n ActionRequest,\n ActionResult,\n Adapter,\n Authorization,\n BootstrapRequest,\n BootstrapResult,\n DiscoverResult,\n DiscoveredRoom,\n HistoryRequest,\n HistoryResult,\n ModelRequest,\n ModelResult,\n MutationRequest,\n MutationResult,\n RefreshRequest,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport {\n DISCOVER_PREFIXES,\n HOUSE_SCHEMA,\n capabilities,\n discoveredRoom,\n locatorOf,\n mapDiscovery,\n parseDiscovery,\n providerSelection,\n trackedFrom,\n type HouseAuthority,\n type TrackedAuthority,\n} from './discovery.js';\nimport {\n MODEL_ABSENT,\n failedModel,\n heldModel,\n modelKey,\n modelShelf,\n type HeldModel,\n} from './model.js';\nimport { gathered, selections } from './gather.js';\nimport { createSiteAdapter } from './site.js';\nimport {\n bootstrapFrom,\n contentPrefixes,\n parseEnumeration,\n parseEnvelope,\n parseGrant,\n refreshFrom,\n schemaFrom,\n schemaPath,\n} from './read.js';\nimport { houseAction } from './actions.js';\nimport { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';\nimport { houseNotifications } from './stream.js';\nimport {\n DOOR_BATCH,\n DOOR_BATCH_UPLOAD,\n DOOR_BOOTSTRAP,\n DOOR_DISCOVER,\n DOOR_ENUMERATE,\n DOOR_REVISIONS,\n DOOR_SELECTION_MAX,\n PRIVATE_LOCATOR,\n type HouseSiteTransport,\n type HouseTransport,\n} from './transport.js';\nimport {\n batchPaths,\n deltaBody,\n deltaBytes,\n deltaDigest,\n historyOutcome,\n houseChanges,\n mutationOutcome,\n operationHead,\n rejectedMapping,\n revisionBody,\n uploadable,\n type OperationHead,\n} from './write.js';\nimport {\n logPosition,\n presented,\n reachedVersion,\n roomVersion,\n type LogPosition,\n} from './version.js';\n\nexport type AgentsHouseAdapterOptions =\n | {\n transport: HouseTransport;\n authorize(): Promise<Authorization>;\n }\n | { site: HouseSiteTransport };\n\nconst UNCERTAIN: MutationResult = { kind: 'transport-uncertainty' };\n\nconst UNCERTAIN_READ = { kind: 'transport-uncertainty' } as const;\n\ntype Enumerating = {\n entry: TrackedAuthority;\n from: LogPosition;\n fromRoomVersion: string;\n reach?: string;\n};\n\ntype Submission = { body: Record<string, unknown> } | { outcome: MutationResult };\n\ntype Upload = { url: string; operation: string; bytes: number; sha256: string };\n\ntype Keep = (upload: unknown) => Promise<void>;\n\nfunction lapsedGrant(outcome: MutationResult): boolean {\n return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';\n}\n\nfunction modelFailure(\n classified: ReturnType<typeof classifyDoor>,\n envelope: ReturnType<typeof parseEnvelope>,\n): ModelResult {\n if (classified === null) {\n return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;\n }\n return failedModel(classified);\n}\n\nexport function createAgentsHouseAdapter(options: AgentsHouseAdapterOptions): Adapter {\n if ('site' in options) return createSiteAdapter(options.site);\n const transport = options.transport;\n const notifications = houseNotifications(transport, 'credential');\n const tracked = new Map<string, TrackedAuthority>();\n const models = modelShelf();\n\n function held(\n envelope: ReturnType<typeof parseEnvelope>,\n entry: TrackedAuthority,\n schema: string,\n failure: ModelResult,\n ): Promise<HeldModel> {\n return heldModel(\n envelope === null ? null : schemaFrom(envelope, entry, schema),\n schemaPath(entry.handle, schema),\n failure,\n );\n }\n\n function modelPrefixes(entry: TrackedAuthority): readonly string[] {\n const own = schemaPath(entry.handle, entry.schema);\n return entry.locator === PRIVATE_LOCATOR ? [own, schemaPath(undefined, HOUSE_SCHEMA)] : [own];\n }\n\n async function acquireModels(\n entries: readonly TrackedAuthority[],\n ): Promise<Map<string, HeldModel>> {\n const acquired = new Map<string, HeldModel>();\n for (const part of selections(\n entries,\n (entry) => modelPrefixes(entry).length,\n DOOR_SELECTION_MAX,\n )) {\n const privateEntry = part.find((entry) => entry.locator === PRIVATE_LOCATOR);\n const answer = await transport.door(DOOR_BOOTSTRAP, {\n prefixes: part.flatMap((entry) => modelPrefixes(entry)),\n });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;\n const failure: ModelResult = modelFailure(classified, envelope);\n for (const entry of part) {\n acquired.set(\n modelKey(entry.locator, 'collection'),\n await held(envelope, entry, entry.schema, failure),\n );\n }\n if (privateEntry !== undefined) {\n acquired.set(\n modelKey(privateEntry.locator, 'typed-selection'),\n await held(envelope, privateEntry, HOUSE_SCHEMA, failure),\n );\n }\n }\n return acquired;\n }\n\n function roomOf(authority: HouseAuthority, acquired: Map<string, HeldModel>): DiscoveredRoom {\n const locator = locatorOf(authority);\n const key = modelKey(locator, 'collection');\n const collection = models.retain(key, acquired.get(key));\n if (authority.roomHandle !== null) {\n return discoveredRoom(authority, collection?.identity ?? null, undefined);\n }\n const selection = models.retain(\n modelKey(locator, 'typed-selection'),\n acquired.get(modelKey(locator, 'typed-selection')),\n );\n return discoveredRoom(\n authority,\n collection?.identity ?? null,\n providerSelection(selection?.identity ?? null),\n );\n }\n\n function authorityFor(locator: string): TrackedAuthority | undefined {\n return tracked.get(locator);\n }\n\n function withAt(result: ActionResult): ActionResult {\n if (result.kind !== 'action') return result;\n const body = result.result as Record<string, unknown> | null;\n if (typeof body !== 'object' || body === null) return result;\n const { authority, position, log_epoch: logEpoch } = body;\n if (typeof position !== 'string' || typeof logEpoch !== 'string') return result;\n const locator =\n authority === undefined\n ? PRIVATE_LOCATOR\n : [...tracked.values()].find((entry) => entry.authority === authority)?.locator;\n if (locator === undefined) return result;\n return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };\n }\n\n async function bundled(body: unknown): Promise<unknown> {\n const grant = parseGrant(body);\n if (grant === null) return body;\n if (grant.method !== 'GET') return null;\n const answer = await transport.transfer({\n act: 'working_copy_bundle',\n method: 'GET',\n url: grant.url,\n answer: 'json',\n });\n return answer.status === 200 ? answer.body : null;\n }\n\n function weight(entry: TrackedAuthority): number {\n return contentPrefixes(entry).length;\n }\n\n async function bootstrapped(entries: readonly TrackedAuthority[]): Promise<BootstrapResult[]> {\n const answers: BootstrapResult[] = [];\n for (const part of selections(entries, weight, DOOR_SELECTION_MAX)) {\n const answer = await transport.door(DOOR_BOOTSTRAP, {\n prefixes: part.flatMap((entry) => contentPrefixes(entry)),\n });\n const classified = part.map((entry) =>\n classifyDoor(answer.status, answer.body, entry.locator),\n );\n const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;\n part.forEach((entry, index) => {\n const failure = classified[index];\n if (failure === null || failure === undefined) {\n answers.push(envelope === null ? UNCERTAIN_READ : bootstrapFrom(envelope, entry));\n return;\n }\n answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);\n });\n }\n return answers;\n }\n\n function layered(asks: readonly Enumerating[]): readonly (readonly Enumerating[])[] {\n const depths = new Map<string, number>();\n const layers: Enumerating[][] = [];\n for (const ask of asks) {\n const depth = depths.get(ask.entry.authority) ?? 0;\n depths.set(ask.entry.authority, depth + 1);\n (layers[depth] ??= []).push(ask);\n }\n return layers;\n }\n\n async function enumerated(asks: readonly Enumerating[]): Promise<RefreshResult[]> {\n const answers = new Map<Enumerating, RefreshResult>();\n const parts = layered(asks).flatMap((layer) =>\n selections(layer, (ask) => weight(ask.entry), DOOR_SELECTION_MAX),\n );\n for (const part of parts) {\n let open = [...part];\n while (open.length > 0) {\n const answer = await transport.door(DOOR_ENUMERATE, {\n prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),\n positions: open.map((ask) => ({\n ...presented(ask.entry.authority, ask.from),\n ...(ask.reach === undefined ? {} : { reach: ask.reach }),\n })),\n });\n const refusal = doorRefusal(answer.body);\n if (refusal?.code === 'replica_behind') {\n const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);\n const behind = named.length === 0 ? open : named;\n for (const ask of behind) answers.set(ask, { kind: 'retryable-refusal', ...refusal });\n open = open.filter((ask) => !behind.includes(ask));\n continue;\n }\n const classified = open.map((ask) =>\n classifyDoor(answer.status, answer.body, ask.entry.locator),\n );\n if (classified[0]?.kind === 'beyond-horizon') {\n const named = doorRefusal(answer.body)?.fields.authority;\n const expired = open.filter((ask) => ask.entry.authority === named);\n const answered: RefreshResult =\n expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };\n const gone = expired.length === 0 ? open : expired;\n for (const ask of gone) answers.set(ask, answered);\n open = open.filter((ask) => !gone.includes(ask));\n continue;\n }\n const enumeration =\n classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;\n open.forEach((ask, index) => {\n const failure = classified[index];\n if (failure !== null && failure !== undefined) {\n answers.set(ask, failure);\n return;\n }\n answers.set(\n ask,\n enumeration === null\n ? UNCERTAIN_READ\n : refreshFrom(enumeration, ask.entry, ask.fromRoomVersion),\n );\n });\n open = [];\n }\n }\n return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);\n }\n\n const bootstrapTogether = gathered(bootstrapped);\n\n const enumerateTogether = gathered(enumerated);\n\n async function uploaded(\n head: OperationHead,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n handed: Upload | undefined,\n keep: Keep,\n ): Promise<Submission> {\n const paths = batchPaths(changes);\n const sha256 = await deltaDigest(delta);\n if (handed !== undefined && handed.sha256 === sha256) {\n return { body: { ...head, paths, upload: handed } };\n }\n const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });\n if (minted.status !== 200) {\n return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };\n }\n const grant = parseGrant(minted.body);\n if (grant === null || grant.method !== 'POST') return { outcome: UNCERTAIN };\n const delivered = await transport.transfer({\n act: 'authored_batch_upload',\n method: 'POST',\n url: grant.url,\n answer: 'json',\n body: `${grant.operation}\\n${delta}`,\n });\n if (delivered.status !== 200) return { outcome: UNCERTAIN };\n const holding = parseGrant(delivered.body);\n if (holding === null || holding.method !== 'POST') return { outcome: UNCERTAIN };\n const upload: Upload = { url: holding.url, operation: holding.operation, bytes, sha256 };\n await keep(upload);\n return { body: { ...head, paths, upload } };\n }\n\n async function submit(\n head: OperationHead,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n handed: Upload | undefined,\n keep: Keep,\n ): Promise<MutationResult> {\n const prepared: Submission = uploadable(bytes)\n ? await uploaded(head, changes, delta, bytes, entry, handed, keep)\n : { body: { ...head, changes } };\n if ('outcome' in prepared) return prepared.outcome;\n const answer = await transport.door(DOOR_BATCH, prepared.body);\n return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);\n }\n\n return {\n async authorize() {\n return options.authorize();\n },\n\n async model(_authorization: Authorization, request: ModelRequest): Promise<ModelResult> {\n return models.answer(request);\n },\n\n async discover(_authorization: Authorization): Promise<DiscoverResult> {\n const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n if (classified !== null) return discoveryFailure(classified);\n const document = parseDiscovery(answer.body);\n if (document === null) return { kind: 'transport-uncertainty' };\n const entries = trackedFrom(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n notifications.track(entries);\n const acquired = await acquireModels(entries);\n models.keep(entries.map((entry) => entry.locator));\n return mapDiscovery(\n document,\n document.authorities.map((authority) => roomOf(authority, acquired)),\n capabilities(document.actions),\n );\n },\n\n async bootstrap(\n _authorization: Authorization,\n request: BootstrapRequest,\n ): Promise<BootstrapResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n return bootstrapTogether(entry);\n },\n\n async refresh(_authorization: Authorization, request: RefreshRequest): Promise<RefreshResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n const from = logPosition(request.fromRoomVersion);\n if (from === null) return { kind: 'beyond-horizon' };\n const streamed = notifications.advance(entry, from);\n if (\n streamed !== null &&\n (request.reach === undefined ||\n reachedVersion(streamed.roomVersion, request.reach, entry.logEpoch))\n )\n return streamed;\n const reach = request.reach === undefined ? null : logPosition(request.reach);\n return enumerateTogether({\n entry,\n from,\n fromRoomVersion: request.fromRoomVersion,\n ...(reach?.logEpoch === from.logEpoch ? { reach: reach.position } : {}),\n });\n },\n\n async mutate(\n _authorization: Authorization,\n request: MutationRequest,\n keep: Keep,\n ): Promise<MutationResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const mapped = houseChanges(request.changeBatch, entry.handle);\n if (mapped.kind === 'unmapped') return rejectedMapping(mapped);\n const head = operationHead(request.changeBatch);\n const delta = deltaBody(mapped.changes);\n const bytes = deltaBytes(delta);\n const handed = request.upload as Upload | undefined;\n const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);\n if (handed === undefined || !lapsedGrant(outcome)) return outcome;\n return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);\n },\n\n async history(_authorization: Authorization, request: HistoryRequest): Promise<HistoryResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const answer = await transport.door(\n DOOR_REVISIONS,\n revisionBody({\n path: request.path,\n handle: entry.handle,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n ...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),\n }),\n );\n return historyOutcome(answer.status, answer.body, entry.locator, {\n path: request.path,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n });\n },\n\n reached(locator: string, version: string, target: string): boolean {\n return reachedVersion(version, target, authorityFor(locator)?.logEpoch);\n },\n\n async action(_authorization: Authorization, request: ActionRequest): Promise<ActionResult> {\n const result = withAt(await houseAction(transport, request));\n const answered = (request.input as { conversation?: unknown } | null)?.conversation;\n if (\n request.name === 'conversation.answer' &&\n result.kind === 'action' &&\n typeof answered === 'string'\n ) {\n notifications.question(answered);\n }\n return result;\n },\n\n roomVersions: notifications,\n conversations: notifications.conversations,\n serviceMode: notifications.serviceMode,\n };\n}\n"],"names":["DISCOVER_PREFIXES","HOUSE_SCHEMA","capabilities","discoveredRoom","locatorOf","mapDiscovery","parseDiscovery","providerSelection","trackedFrom","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","gathered","selections","createSiteAdapter","bootstrapFrom","contentPrefixes","parseEnumeration","parseEnvelope","parseGrant","refreshFrom","schemaFrom","schemaPath","houseAction","classifyDoor","discoveryFailure","doorRefusal","houseNotifications","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_BOOTSTRAP","DOOR_DISCOVER","DOOR_ENUMERATE","DOOR_REVISIONS","DOOR_SELECTION_MAX","PRIVATE_LOCATOR","batchPaths","deltaBody","deltaBytes","deltaDigest","historyOutcome","houseChanges","mutationOutcome","operationHead","rejectedMapping","revisionBody","uploadable","logPosition","presented","reachedVersion","roomVersion","UNCERTAIN","kind","UNCERTAIN_READ","lapsedGrant","outcome","code","modelFailure","classified","envelope","createAgentsHouseAdapter","options","site","transport","notifications","tracked","Map","models","held","entry","schema","failure","handle","modelPrefixes","own","locator","undefined","acquireModels","entries","acquired","part","length","privateEntry","find","answer","door","prefixes","flatMap","status","body","bundled","set","roomOf","authority","key","collection","retain","get","roomHandle","identity","selection","authorityFor","withAt","result","position","log_epoch","logEpoch","values","at","grant","method","transfer","act","url","weight","bootstrapped","answers","map","forEach","index","push","layered","asks","depths","layers","ask","depth","enumerated","parts","layer","open","positions","from","reach","refusal","named","filter","fields","behind","includes","expired","answered","gone","enumeration","fromRoomVersion","bootstrapTogether","enumerateTogether","uploaded","head","changes","delta","bytes","handed","keep","paths","sha256","upload","minted","delivered","operation","holding","submit","prepared","authorize","model","_authorization","request","discover","document","clear","track","authorities","actions","bootstrap","pageToken","refresh","streamed","advance","mutate","mapped","changeBatch","history","path","revision","reached","version","target","action","input","conversation","name","question","roomVersions","conversations","serviceMode"],"mappings":"AAkBA,SACEA,iBAAiB,EACjBC,YAAY,EACZC,YAAY,EACZC,cAAc,EACdC,SAAS,EACTC,YAAY,EACZC,cAAc,EACdC,iBAAiB,EACjBC,WAAW,QAGN,iBAAiB;AACxB,SACEC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,UAAU,QAEL,aAAa;AACpB,SAASC,QAAQ,EAAEC,UAAU,QAAQ,cAAc;AACnD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SACEC,aAAa,EACbC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,EACbC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,UAAU,QACL,YAAY;AACnB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,YAAY,EAAEC,gBAAgB,EAAEC,WAAW,QAAQ,eAAe;AAC3E,SAASC,kBAAkB,QAAQ,cAAc;AACjD,SACEC,UAAU,EACVC,iBAAiB,EACjBC,cAAc,EACdC,aAAa,EACbC,cAAc,EACdC,cAAc,EACdC,kBAAkB,EAClBC,eAAe,QAGV,iBAAiB;AACxB,SACEC,UAAU,EACVC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,cAAc,EACdC,YAAY,EACZC,eAAe,EACfC,aAAa,EACbC,eAAe,EACfC,YAAY,EACZC,UAAU,QAEL,aAAa;AACpB,SACEC,WAAW,EACXC,SAAS,EACTC,cAAc,EACdC,WAAW,QAEN,eAAe;AAStB,MAAMC,YAA4B;IAAEC,MAAM;AAAwB;AAElE,MAAMC,iBAAiB;IAAED,MAAM;AAAwB;AAevD,SAASE,YAAYC,OAAuB;IAC1C,OAAOA,QAAQH,IAAI,KAAK,cAAcG,QAAQC,IAAI,K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OtC;QACT;QAEAyF,cAAchI;QACdiI,eAAejI,cAAciI,aAAa;QAC1CC,aAAalI,cAAckI,WAAW;IACxC;AACF"}
|
package/dist/gather.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function gathered<A, R>(send: (asks: readonly A[]) => Promise<readonly R[]>): (ask: A) => Promise<R>;
|
|
2
|
+
export declare function selections<T>(items: readonly T[], weight: (item: T) => number, limit: number): readonly (readonly T[])[];
|
|
3
|
+
//# sourceMappingURL=gather.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gather.d.ts","sourceRoot":"","sources":["../src/gather.ts"],"names":[],"mappings":"AAMA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,GAClD,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAuBxB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAC1B,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,EAC3B,KAAK,EAAE,MAAM,GACZ,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAgB3B"}
|
package/dist/gather.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function gathered(send) {
|
|
2
|
+
let held = [];
|
|
3
|
+
function flush() {
|
|
4
|
+
const taken = held;
|
|
5
|
+
held = [];
|
|
6
|
+
send(taken.map((entry)=>entry.ask)).then((answers)=>{
|
|
7
|
+
taken.forEach((entry, index)=>{
|
|
8
|
+
entry.resolve(answers[index]);
|
|
9
|
+
});
|
|
10
|
+
}, (reason)=>{
|
|
11
|
+
for (const entry of taken)entry.reject(reason);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return (ask)=>new Promise((resolve, reject)=>{
|
|
15
|
+
if (held.length === 0) setTimeout(flush, 0);
|
|
16
|
+
held.push({
|
|
17
|
+
ask,
|
|
18
|
+
resolve,
|
|
19
|
+
reject
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function selections(items, weight, limit) {
|
|
24
|
+
const parts = [];
|
|
25
|
+
let part = [];
|
|
26
|
+
let carried = 0;
|
|
27
|
+
for (const item of items){
|
|
28
|
+
const weighed = weight(item);
|
|
29
|
+
if (part.length > 0 && carried + weighed > limit) {
|
|
30
|
+
parts.push(part);
|
|
31
|
+
part = [];
|
|
32
|
+
carried = 0;
|
|
33
|
+
}
|
|
34
|
+
part.push(item);
|
|
35
|
+
carried += weighed;
|
|
36
|
+
}
|
|
37
|
+
if (part.length > 0) parts.push(part);
|
|
38
|
+
return parts;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=gather.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/gather.ts"],"sourcesContent":["type Held<A, R> = {\n ask: A;\n resolve: (answer: R) => void;\n reject: (reason: unknown) => void;\n};\n\nexport function gathered<A, R>(\n send: (asks: readonly A[]) => Promise<readonly R[]>,\n): (ask: A) => Promise<R> {\n let held: Held<A, R>[] = [];\n\n function flush() {\n const taken = held;\n held = [];\n send(taken.map((entry) => entry.ask)).then(\n (answers) => {\n taken.forEach((entry, index) => {\n entry.resolve(answers[index] as R);\n });\n },\n (reason: unknown) => {\n for (const entry of taken) entry.reject(reason);\n },\n );\n }\n\n return (ask) =>\n new Promise<R>((resolve, reject) => {\n if (held.length === 0) setTimeout(flush, 0);\n held.push({ ask, resolve, reject });\n });\n}\n\nexport function selections<T>(\n items: readonly T[],\n weight: (item: T) => number,\n limit: number,\n): readonly (readonly T[])[] {\n const parts: T[][] = [];\n let part: T[] = [];\n let carried = 0;\n for (const item of items) {\n const weighed = weight(item);\n if (part.length > 0 && carried + weighed > limit) {\n parts.push(part);\n part = [];\n carried = 0;\n }\n part.push(item);\n carried += weighed;\n }\n if (part.length > 0) parts.push(part);\n return parts;\n}\n"],"names":["gathered","send","held","flush","taken","map","entry","ask","then","answers","forEach","index","resolve","reason","reject","Promise","length","setTimeout","push","selections","items","weight","limit","parts","part","carried","item","weighed"],"mappings":"AAMA,OAAO,SAASA,SACdC,IAAmD;IAEnD,IAAIC,OAAqB,EAAE;IAE3B,SAASC;QACP,MAAMC,QAAQF;QACdA,OAAO,EAAE;QACTD,KAAKG,MAAMC,GAAG,CAAC,CAACC,QAAUA,MAAMC,GAAG,GAAGC,IAAI,CACxC,CAACC;YACCL,MAAMM,OAAO,CAAC,CAACJ,OAAOK;gBACpBL,MAAMM,OAAO,CAACH,OAAO,CAACE,MAAM;YAC9B;QACF,GACA,CAACE;YACC,KAAK,MAAMP,SAASF,MAAOE,MAAMQ,MAAM,CAACD;QAC1C;IAEJ;IAEA,OAAO,CAACN,MACN,IAAIQ,QAAW,CAACH,SAASE;YACvB,IAAIZ,KAAKc,MAAM,KAAK,GAAGC,WAAWd,OAAO;YACzCD,KAAKgB,IAAI,CAAC;gBAAEX;gBAAKK;gBAASE;YAAO;QACnC;AACJ;AAEA,OAAO,SAASK,WACdC,KAAmB,EACnBC,MAA2B,EAC3BC,KAAa;IAEb,MAAMC,QAAe,EAAE;IACvB,IAAIC,OAAY,EAAE;IAClB,IAAIC,UAAU;IACd,KAAK,MAAMC,QAAQN,MAAO;QACxB,MAAMO,UAAUN,OAAOK;QACvB,IAAIF,KAAKR,MAAM,GAAG,KAAKS,UAAUE,UAAUL,OAAO;YAChDC,MAAML,IAAI,CAACM;YACXA,OAAO,EAAE;YACTC,UAAU;QACZ;QACAD,KAAKN,IAAI,CAACQ;QACVD,WAAWE;IACb;IACA,IAAIH,KAAKR,MAAM,GAAG,GAAGO,MAAML,IAAI,CAACM;IAChC,OAAOD;AACT"}
|
package/dist/read.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ import type { BootstrapPage, BootstrapResult, RefreshResult } from '@agentshouse
|
|
|
2
2
|
import { type TrackedAuthority } from './discovery.js';
|
|
3
3
|
import type { HouseMode } from './transport.js';
|
|
4
4
|
import { type LogPosition } from './version.js';
|
|
5
|
+
export type HeadChange = BootstrapPage['changes'][string];
|
|
5
6
|
export type HouseManifestFile = {
|
|
6
7
|
path: string;
|
|
7
8
|
revision: string | undefined;
|
|
8
9
|
version: string;
|
|
10
|
+
head?: HeadChange;
|
|
9
11
|
};
|
|
10
12
|
export type HouseContent = {
|
|
11
13
|
path: string;
|
|
@@ -35,6 +37,7 @@ export type HouseChange = {
|
|
|
35
37
|
content: string;
|
|
36
38
|
revision: string | undefined;
|
|
37
39
|
version: string;
|
|
40
|
+
head?: HeadChange;
|
|
38
41
|
} | {
|
|
39
42
|
path: string;
|
|
40
43
|
reference: {
|
|
@@ -53,6 +56,10 @@ export declare function selectionRoots(tracked: TrackedAuthority): readonly stri
|
|
|
53
56
|
export declare function contentPrefixes(tracked: TrackedAuthority): readonly string[];
|
|
54
57
|
export declare function schemaPath(handle: string | undefined, schema: string): string;
|
|
55
58
|
export declare function parseGrant(body: unknown): HouseGrant | null;
|
|
59
|
+
export declare function headChange(held: {
|
|
60
|
+
readonly author?: unknown;
|
|
61
|
+
readonly created_at?: unknown;
|
|
62
|
+
}): HeadChange | undefined | null;
|
|
56
63
|
export declare function parseEnvelope(body: unknown): HouseEnvelope | null;
|
|
57
64
|
export declare function parseSiteBootstrap(body: unknown): HouseScope | null;
|
|
58
65
|
export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
|
package/dist/read.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,E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