@agentshouse/mdruntime-adapter 0.1.0-alpha.1 → 0.1.0-alpha.3
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 +78 -0
- package/dist/actions.d.ts +16 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +454 -0
- package/dist/actions.js.map +1 -0
- package/dist/adapter.d.ts +8 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +341 -0
- package/dist/adapter.js.map +1 -0
- package/dist/digest.d.ts +3 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +11 -0
- package/dist/digest.js.map +1 -0
- package/dist/discovery.d.ts +60 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +242 -0
- package/dist/discovery.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/map.d.ts +3 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/map.js +15 -0
- package/dist/map.js.map +1 -0
- package/dist/read.d.ts +67 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +244 -0
- package/dist/read.js.map +1 -0
- package/dist/refusal.d.ts +8 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +65 -0
- package/dist/refusal.js.map +1 -0
- package/dist/stream.d.ts +10 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +239 -0
- package/dist/stream.js.map +1 -0
- package/dist/transport.d.ts +77 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +9 -0
- package/dist/transport.js.map +1 -0
- package/dist/write.d.ts +41 -0
- package/dist/write.d.ts.map +1 -0
- package/dist/write.js +377 -0
- package/dist/write.js.map +1 -0
- package/package.json +7 -2
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { DISCOVER_PREFIXES, PROVIDER_SELECTION_MODEL_ROOT, discoveredRoom, locatorOf, mapDiscovery, parseDiscovery, providerSelection, trackedFrom } from './discovery.js';
|
|
2
|
+
import { authorityRoot, bootstrapFrom, contentPrefixes, definitionsFrom, modelPrefix, parseEnumeration, parseEnvelope, parseGrant, refreshFrom } from './read.js';
|
|
3
|
+
import { houseAction } from './actions.js';
|
|
4
|
+
import { classifyDoor } from './refusal.js';
|
|
5
|
+
import { houseNotifications } from './stream.js';
|
|
6
|
+
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, PRIVATE_AUTHORITY } from './transport.js';
|
|
7
|
+
import { sha256Hex } from './digest.js';
|
|
8
|
+
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, rejectedMapping, revisionBody, uploadable } from './write.js';
|
|
9
|
+
const MODEL_ABSENT = {
|
|
10
|
+
kind: 'model-unavailable',
|
|
11
|
+
reason: 'not-readable'
|
|
12
|
+
};
|
|
13
|
+
const UNCERTAIN = {
|
|
14
|
+
kind: 'transport-uncertainty'
|
|
15
|
+
};
|
|
16
|
+
const RESOLVED_OUTCOMES = new Set([
|
|
17
|
+
'accepted',
|
|
18
|
+
'conflicted',
|
|
19
|
+
'rejected',
|
|
20
|
+
'expired'
|
|
21
|
+
]);
|
|
22
|
+
function lapsedGrant(outcome) {
|
|
23
|
+
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
24
|
+
}
|
|
25
|
+
function modelFailure(classified, envelope) {
|
|
26
|
+
if (classified === null) {
|
|
27
|
+
return envelope === null ? {
|
|
28
|
+
kind: 'transport-uncertainty'
|
|
29
|
+
} : MODEL_ABSENT;
|
|
30
|
+
}
|
|
31
|
+
if (classified.kind === 'revoked-authorization') return {
|
|
32
|
+
kind: 'revoked-authorization'
|
|
33
|
+
};
|
|
34
|
+
if (classified.kind === 'transport-uncertainty') return {
|
|
35
|
+
kind: 'transport-uncertainty'
|
|
36
|
+
};
|
|
37
|
+
return MODEL_ABSENT;
|
|
38
|
+
}
|
|
39
|
+
function modelVersion(revisions) {
|
|
40
|
+
return sha256Hex(JSON.stringify(revisions));
|
|
41
|
+
}
|
|
42
|
+
export function createAgentsHouseAdapter(options) {
|
|
43
|
+
const transport = options.transport;
|
|
44
|
+
const notifications = houseNotifications(transport);
|
|
45
|
+
const tracked = new Map();
|
|
46
|
+
const models = new Map();
|
|
47
|
+
const submissions = new Map();
|
|
48
|
+
function modelKey(locator, attached) {
|
|
49
|
+
return `${locator} ${attached}`;
|
|
50
|
+
}
|
|
51
|
+
async function held(envelope, entry, modelRoot, identity, failure) {
|
|
52
|
+
const read = envelope === null ? null : definitionsFrom(envelope, entry, modelRoot);
|
|
53
|
+
if (read === null) return {
|
|
54
|
+
snapshot: failure,
|
|
55
|
+
identity: null
|
|
56
|
+
};
|
|
57
|
+
const version = await modelVersion(read.revisions);
|
|
58
|
+
return {
|
|
59
|
+
snapshot: {
|
|
60
|
+
kind: 'model',
|
|
61
|
+
snapshot: {
|
|
62
|
+
identity,
|
|
63
|
+
version,
|
|
64
|
+
definitions: read.definitions
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
identity: {
|
|
68
|
+
identity,
|
|
69
|
+
version
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function acquireModels(entries) {
|
|
74
|
+
const acquired = new Map();
|
|
75
|
+
const privateEntry = entries.find((entry)=>entry.authority === PRIVATE_AUTHORITY);
|
|
76
|
+
const prefixes = entries.map((entry)=>modelPrefix(entry, entry.modelRoot));
|
|
77
|
+
if (privateEntry !== undefined) {
|
|
78
|
+
prefixes.push(`${authorityRoot(undefined)}/${PROVIDER_SELECTION_MODEL_ROOT}`);
|
|
79
|
+
}
|
|
80
|
+
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
81
|
+
prefixes
|
|
82
|
+
});
|
|
83
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);
|
|
84
|
+
const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
85
|
+
const failure = modelFailure(classified, envelope);
|
|
86
|
+
for (const entry of entries){
|
|
87
|
+
acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.modelRoot, `${authorityRoot(entry.handle)}/${entry.modelRoot}`, failure));
|
|
88
|
+
}
|
|
89
|
+
if (privateEntry !== undefined) {
|
|
90
|
+
acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, PROVIDER_SELECTION_MODEL_ROOT, `${authorityRoot(undefined)}/${PROVIDER_SELECTION_MODEL_ROOT}`, failure));
|
|
91
|
+
}
|
|
92
|
+
return acquired;
|
|
93
|
+
}
|
|
94
|
+
function retainModel(key, acquired) {
|
|
95
|
+
if (acquired === undefined) return models.get(key);
|
|
96
|
+
if (acquired.snapshot.kind === 'transport-uncertainty') {
|
|
97
|
+
const previous = models.get(key);
|
|
98
|
+
if (previous !== undefined && previous.identity !== null) return previous;
|
|
99
|
+
}
|
|
100
|
+
models.set(key, acquired);
|
|
101
|
+
return acquired;
|
|
102
|
+
}
|
|
103
|
+
function roomOf(authority, acquired) {
|
|
104
|
+
const locator = locatorOf(authority);
|
|
105
|
+
const key = modelKey(locator, 'collection');
|
|
106
|
+
const collection = retainModel(key, acquired.get(key));
|
|
107
|
+
if (authority.kind !== 'private') {
|
|
108
|
+
return discoveredRoom(authority, collection?.identity ?? null, undefined);
|
|
109
|
+
}
|
|
110
|
+
const selection = retainModel(modelKey(locator, 'typed-selection'), acquired.get(modelKey(locator, 'typed-selection')));
|
|
111
|
+
return discoveredRoom(authority, collection?.identity ?? null, providerSelection(selection?.identity ?? null));
|
|
112
|
+
}
|
|
113
|
+
function authorityFor(locator) {
|
|
114
|
+
return tracked.get(locator);
|
|
115
|
+
}
|
|
116
|
+
async function bundled(body) {
|
|
117
|
+
const grant = parseGrant(body);
|
|
118
|
+
if (grant === null) return body;
|
|
119
|
+
if (grant.method !== 'GET') return null;
|
|
120
|
+
const answer = await transport.transfer({
|
|
121
|
+
act: 'working_copy_bundle',
|
|
122
|
+
method: 'GET',
|
|
123
|
+
url: grant.url
|
|
124
|
+
});
|
|
125
|
+
return answer.status === 200 ? answer.body : null;
|
|
126
|
+
}
|
|
127
|
+
async function uploaded(identity, changes, delta, bytes, entry) {
|
|
128
|
+
const paths = batchPaths(changes);
|
|
129
|
+
const sha256 = await deltaDigest(delta);
|
|
130
|
+
const retained = submissions.get(identity);
|
|
131
|
+
if (retained !== undefined && retained.sha256 === sha256) return {
|
|
132
|
+
body: retained.body
|
|
133
|
+
};
|
|
134
|
+
const minted = await transport.door(DOOR_BATCH_UPLOAD, {
|
|
135
|
+
operation_id: identity,
|
|
136
|
+
paths,
|
|
137
|
+
bytes,
|
|
138
|
+
sha256
|
|
139
|
+
});
|
|
140
|
+
if (minted.status !== 200) {
|
|
141
|
+
return {
|
|
142
|
+
outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const grant = parseGrant(minted.body);
|
|
146
|
+
if (grant === null || grant.method !== 'POST') return {
|
|
147
|
+
outcome: UNCERTAIN
|
|
148
|
+
};
|
|
149
|
+
const delivered = await transport.transfer({
|
|
150
|
+
act: 'authored_batch_upload',
|
|
151
|
+
method: 'POST',
|
|
152
|
+
url: grant.url,
|
|
153
|
+
body: `${grant.operation}\n${delta}`
|
|
154
|
+
});
|
|
155
|
+
if (delivered.status !== 200) return {
|
|
156
|
+
outcome: UNCERTAIN
|
|
157
|
+
};
|
|
158
|
+
const holding = parseGrant(delivered.body);
|
|
159
|
+
if (holding === null) return {
|
|
160
|
+
outcome: UNCERTAIN
|
|
161
|
+
};
|
|
162
|
+
const body = {
|
|
163
|
+
operation_id: identity,
|
|
164
|
+
paths,
|
|
165
|
+
upload: {
|
|
166
|
+
url: holding.url,
|
|
167
|
+
operation: holding.operation,
|
|
168
|
+
bytes,
|
|
169
|
+
sha256
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
submissions.set(identity, {
|
|
173
|
+
sha256,
|
|
174
|
+
body
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
body
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
async function submit(identity, changes, delta, bytes, entry) {
|
|
181
|
+
const prepared = uploadable(bytes) ? await uploaded(identity, changes, delta, bytes, entry) : {
|
|
182
|
+
body: {
|
|
183
|
+
operation_id: identity,
|
|
184
|
+
changes
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
if ('outcome' in prepared) return prepared.outcome;
|
|
188
|
+
const answer = await transport.door(DOOR_BATCH, prepared.body);
|
|
189
|
+
return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
async authorize () {
|
|
193
|
+
return options.authorize();
|
|
194
|
+
},
|
|
195
|
+
async model (_authorization, request) {
|
|
196
|
+
return models.get(modelKey(request.locator, request.attached))?.snapshot ?? MODEL_ABSENT;
|
|
197
|
+
},
|
|
198
|
+
async discover (_authorization) {
|
|
199
|
+
const answer = await transport.door(DOOR_DISCOVER, {
|
|
200
|
+
prefixes: [
|
|
201
|
+
...DISCOVER_PREFIXES
|
|
202
|
+
]
|
|
203
|
+
});
|
|
204
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);
|
|
205
|
+
if (classified !== null) {
|
|
206
|
+
if (classified.kind === 'revoked-authorization') return classified;
|
|
207
|
+
if (classified.kind === 'scoped-refusal') {
|
|
208
|
+
return {
|
|
209
|
+
kind: 'contract-unavailable',
|
|
210
|
+
code: classified.code,
|
|
211
|
+
fields: classified.fields
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
kind: 'transport-uncertainty'
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
const document = parseDiscovery(answer.body);
|
|
219
|
+
if (document === null) return {
|
|
220
|
+
kind: 'transport-uncertainty'
|
|
221
|
+
};
|
|
222
|
+
const entries = trackedFrom(document);
|
|
223
|
+
tracked.clear();
|
|
224
|
+
for (const entry of entries)tracked.set(entry.locator, entry);
|
|
225
|
+
notifications.track(entries);
|
|
226
|
+
const acquired = await acquireModels(entries);
|
|
227
|
+
for (const key of [
|
|
228
|
+
...models.keys()
|
|
229
|
+
]){
|
|
230
|
+
if (!entries.some((entry)=>key.startsWith(`${entry.locator} `))) models.delete(key);
|
|
231
|
+
}
|
|
232
|
+
return mapDiscovery(document, document.authorities.map((authority)=>roomOf(authority, acquired)));
|
|
233
|
+
},
|
|
234
|
+
async bootstrap (_authorization, request) {
|
|
235
|
+
const entry = authorityFor(request.locator);
|
|
236
|
+
if (entry === undefined) return {
|
|
237
|
+
kind: 'room-not-readable',
|
|
238
|
+
locator: request.locator
|
|
239
|
+
};
|
|
240
|
+
if (request.pageToken !== undefined) return {
|
|
241
|
+
kind: 'transport-uncertainty'
|
|
242
|
+
};
|
|
243
|
+
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
244
|
+
prefixes: [
|
|
245
|
+
...contentPrefixes(entry)
|
|
246
|
+
]
|
|
247
|
+
});
|
|
248
|
+
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
249
|
+
if (classified !== null) {
|
|
250
|
+
return classified.kind === 'beyond-horizon' ? {
|
|
251
|
+
kind: 'transport-uncertainty'
|
|
252
|
+
} : classified;
|
|
253
|
+
}
|
|
254
|
+
const envelope = parseEnvelope(await bundled(answer.body));
|
|
255
|
+
if (envelope === null) return {
|
|
256
|
+
kind: 'transport-uncertainty'
|
|
257
|
+
};
|
|
258
|
+
return bootstrapFrom(envelope, entry);
|
|
259
|
+
},
|
|
260
|
+
async refresh (_authorization, request) {
|
|
261
|
+
const entry = authorityFor(request.locator);
|
|
262
|
+
if (entry === undefined) return {
|
|
263
|
+
kind: 'room-not-readable',
|
|
264
|
+
locator: request.locator
|
|
265
|
+
};
|
|
266
|
+
if (request.pageToken !== undefined) return {
|
|
267
|
+
kind: 'transport-uncertainty'
|
|
268
|
+
};
|
|
269
|
+
const streamed = notifications.advance(entry, request.fromRoomVersion);
|
|
270
|
+
if (streamed !== null) return streamed;
|
|
271
|
+
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
272
|
+
prefixes: [
|
|
273
|
+
...contentPrefixes(entry)
|
|
274
|
+
],
|
|
275
|
+
positions: [
|
|
276
|
+
{
|
|
277
|
+
authority: entry.authority,
|
|
278
|
+
position: request.fromRoomVersion
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
});
|
|
282
|
+
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
283
|
+
if (classified !== null) return classified;
|
|
284
|
+
const enumeration = parseEnumeration(answer.body);
|
|
285
|
+
if (enumeration === null) return {
|
|
286
|
+
kind: 'transport-uncertainty'
|
|
287
|
+
};
|
|
288
|
+
return refreshFrom(enumeration, entry, request.fromRoomVersion);
|
|
289
|
+
},
|
|
290
|
+
async mutate (_authorization, request) {
|
|
291
|
+
const entry = authorityFor(request.locator);
|
|
292
|
+
if (entry === undefined) return {
|
|
293
|
+
kind: 'room-not-readable',
|
|
294
|
+
locator: request.locator
|
|
295
|
+
};
|
|
296
|
+
const mapped = houseChanges(request.changeBatch, entry.handle);
|
|
297
|
+
if (mapped.kind === 'unmapped') return rejectedMapping(mapped);
|
|
298
|
+
const identity = request.changeBatch.id;
|
|
299
|
+
const delta = deltaBody(mapped.changes);
|
|
300
|
+
const bytes = deltaBytes(delta);
|
|
301
|
+
const resent = submissions.has(identity);
|
|
302
|
+
let outcome = await submit(identity, mapped.changes, delta, bytes, entry);
|
|
303
|
+
if (resent && lapsedGrant(outcome)) {
|
|
304
|
+
submissions.delete(identity);
|
|
305
|
+
outcome = await submit(identity, mapped.changes, delta, bytes, entry);
|
|
306
|
+
}
|
|
307
|
+
if (RESOLVED_OUTCOMES.has(outcome.kind)) submissions.delete(identity);
|
|
308
|
+
return outcome;
|
|
309
|
+
},
|
|
310
|
+
async history (_authorization, request) {
|
|
311
|
+
const entry = authorityFor(request.locator);
|
|
312
|
+
if (entry === undefined) return {
|
|
313
|
+
kind: 'room-not-readable',
|
|
314
|
+
locator: request.locator
|
|
315
|
+
};
|
|
316
|
+
const answer = await transport.door(DOOR_REVISIONS, revisionBody({
|
|
317
|
+
path: request.path,
|
|
318
|
+
handle: entry.handle,
|
|
319
|
+
...request.revision === undefined ? {} : {
|
|
320
|
+
revision: request.revision
|
|
321
|
+
},
|
|
322
|
+
...request.pageToken === undefined ? {} : {
|
|
323
|
+
pageToken: request.pageToken
|
|
324
|
+
}
|
|
325
|
+
}));
|
|
326
|
+
return historyOutcome(answer.status, answer.body, entry.locator, {
|
|
327
|
+
path: request.path,
|
|
328
|
+
...request.revision === undefined ? {} : {
|
|
329
|
+
revision: request.revision
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
async action (_authorization, request) {
|
|
334
|
+
return houseAction(transport, request);
|
|
335
|
+
},
|
|
336
|
+
roomVersions: notifications,
|
|
337
|
+
conversations: notifications.conversations
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +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 ModelIdentity,\n ModelRequest,\n ModelResult,\n MutationRequest,\n MutationResult,\n RefreshRequest,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport {\n DISCOVER_PREFIXES,\n PROVIDER_SELECTION_MODEL_ROOT,\n discoveredRoom,\n locatorOf,\n mapDiscovery,\n parseDiscovery,\n providerSelection,\n trackedFrom,\n type HouseAuthority,\n type TrackedAuthority,\n} from './discovery.js';\nimport {\n authorityRoot,\n bootstrapFrom,\n contentPrefixes,\n definitionsFrom,\n modelPrefix,\n parseEnumeration,\n parseEnvelope,\n parseGrant,\n refreshFrom,\n} from './read.js';\nimport { houseAction } from './actions.js';\nimport { classifyDoor } 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_AUTHORITY,\n type HouseTransport,\n} from './transport.js';\nimport { sha256Hex } from './digest.js';\nimport {\n batchPaths,\n deltaBody,\n deltaBytes,\n deltaDigest,\n historyOutcome,\n houseChanges,\n mutationOutcome,\n rejectedMapping,\n revisionBody,\n uploadable,\n} from './write.js';\n\nexport type AgentsHouseAdapterOptions = {\n transport: HouseTransport;\n authorize(): Promise<Authorization>;\n};\n\ntype HeldModel = { snapshot: ModelResult; identity: ModelIdentity | null };\n\nconst MODEL_ABSENT: ModelResult = { kind: 'model-unavailable', reason: 'not-readable' };\n\nconst UNCERTAIN: MutationResult = { kind: 'transport-uncertainty' };\n\nconst RESOLVED_OUTCOMES: ReadonlySet<MutationResult['kind']> = new Set([\n 'accepted',\n 'conflicted',\n 'rejected',\n 'expired',\n]);\n\ntype Submission = { body: Record<string, unknown> } | { outcome: MutationResult };\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 if (classified.kind === 'revoked-authorization') return { kind: 'revoked-authorization' };\n if (classified.kind === 'transport-uncertainty') return { kind: 'transport-uncertainty' };\n return MODEL_ABSENT;\n}\n\nfunction modelVersion(revisions: readonly string[]): Promise<string> {\n return sha256Hex(JSON.stringify(revisions));\n}\n\nexport function createAgentsHouseAdapter(options: AgentsHouseAdapterOptions): Adapter {\n const transport = options.transport;\n const notifications = houseNotifications(transport);\n const tracked = new Map<string, TrackedAuthority>();\n const models = new Map<string, HeldModel>();\n const submissions = new Map<string, { sha256: string; body: Record<string, unknown> }>();\n\n function modelKey(locator: string, attached: ModelRequest['attached']): string {\n return `${locator} ${attached}`;\n }\n\n async function held(\n envelope: ReturnType<typeof parseEnvelope>,\n entry: TrackedAuthority,\n modelRoot: string,\n identity: string,\n failure: ModelResult,\n ): Promise<HeldModel> {\n const read = envelope === null ? null : definitionsFrom(envelope, entry, modelRoot);\n if (read === null) return { snapshot: failure, identity: null };\n const version = await modelVersion(read.revisions);\n return {\n snapshot: { kind: 'model', snapshot: { identity, version, definitions: read.definitions } },\n identity: { identity, version },\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.authority === PRIVATE_AUTHORITY);\n const prefixes = entries.map((entry) => modelPrefix(entry, entry.modelRoot));\n if (privateEntry !== undefined) {\n prefixes.push(`${authorityRoot(undefined)}/${PROVIDER_SELECTION_MODEL_ROOT}`);\n }\n const answer = await transport.door(DOOR_BOOTSTRAP, { prefixes });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);\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(\n envelope,\n entry,\n entry.modelRoot,\n `${authorityRoot(entry.handle)}/${entry.modelRoot}`,\n failure,\n ),\n );\n }\n if (privateEntry !== undefined) {\n acquired.set(\n modelKey(privateEntry.locator, 'typed-selection'),\n await held(\n envelope,\n privateEntry,\n PROVIDER_SELECTION_MODEL_ROOT,\n `${authorityRoot(undefined)}/${PROVIDER_SELECTION_MODEL_ROOT}`,\n failure,\n ),\n );\n }\n return acquired;\n }\n\n function retainModel(key: string, acquired: HeldModel | undefined): HeldModel | undefined {\n if (acquired === undefined) return models.get(key);\n if (acquired.snapshot.kind === 'transport-uncertainty') {\n const previous = models.get(key);\n if (previous !== undefined && previous.identity !== null) return previous;\n }\n models.set(key, acquired);\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 = retainModel(key, acquired.get(key));\n if (authority.kind !== 'private') {\n return discoveredRoom(authority, collection?.identity ?? null, undefined);\n }\n const selection = retainModel(\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 });\n return answer.status === 200 ? answer.body : null;\n }\n\n async function uploaded(\n identity: string,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n ): Promise<Submission> {\n const paths = batchPaths(changes);\n const sha256 = await deltaDigest(delta);\n const retained = submissions.get(identity);\n if (retained !== undefined && retained.sha256 === sha256) return { body: retained.body };\n const minted = await transport.door(DOOR_BATCH_UPLOAD, {\n operation_id: identity,\n paths,\n bytes,\n sha256,\n });\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 body: `${grant.operation}\\n${delta}`,\n });\n if (delivered.status !== 200) return { outcome: UNCERTAIN };\n const holding = parseGrant(delivered.body);\n if (holding === null) return { outcome: UNCERTAIN };\n const body = {\n operation_id: identity,\n paths,\n upload: { url: holding.url, operation: holding.operation, bytes, sha256 },\n };\n submissions.set(identity, { sha256, body });\n return { body };\n }\n\n async function submit(\n identity: string,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n ): Promise<MutationResult> {\n const prepared: Submission = uploadable(bytes)\n ? await uploaded(identity, changes, delta, bytes, entry)\n : { body: { operation_id: identity, 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.get(modelKey(request.locator, request.attached))?.snapshot ?? MODEL_ABSENT;\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_AUTHORITY);\n if (classified !== null) {\n if (classified.kind === 'revoked-authorization') return classified;\n if (classified.kind === 'scoped-refusal') {\n return { kind: 'contract-unavailable', code: classified.code, fields: classified.fields };\n }\n return { kind: 'transport-uncertainty' };\n }\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 for (const key of [...models.keys()]) {\n if (!entries.some((entry) => key.startsWith(`${entry.locator} `))) models.delete(key);\n }\n return mapDiscovery(\n document,\n document.authorities.map((authority) => roomOf(authority, acquired)),\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 streamed = notifications.advance(entry, request.fromRoomVersion);\n if (streamed !== null) return streamed;\n const answer = await transport.door(DOOR_ENUMERATE, {\n prefixes: [...contentPrefixes(entry)],\n positions: [{ authority: entry.authority, position: request.fromRoomVersion }],\n });\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return classified;\n const enumeration = parseEnumeration(answer.body);\n if (enumeration === null) return { kind: 'transport-uncertainty' };\n return refreshFrom(enumeration, entry, request.fromRoomVersion);\n },\n\n async mutate(_authorization: Authorization, request: MutationRequest): 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 identity = request.changeBatch.id;\n const delta = deltaBody(mapped.changes);\n const bytes = deltaBytes(delta);\n const resent = submissions.has(identity);\n let outcome = await submit(identity, mapped.changes, delta, bytes, entry);\n if (resent && lapsedGrant(outcome)) {\n submissions.delete(identity);\n outcome = await submit(identity, mapped.changes, delta, bytes, entry);\n }\n if (RESOLVED_OUTCOMES.has(outcome.kind)) submissions.delete(identity);\n return outcome;\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 return houseAction(transport, request);\n },\n\n roomVersions: notifications,\n conversations: notifications.conversations,\n };\n}\n"],"names":["DISCOVER_PREFIXES","PROVIDER_SELECTION_MODEL_ROOT","discoveredRoom","locatorOf","mapDiscovery","parseDiscovery","providerSelection","trackedFrom","authorityRoot","bootstrapFrom","contentPrefixes","definitionsFrom","modelPrefix","parseEnumeration","parseEnvelope","parseGrant","refreshFrom","houseAction","classifyDoor","houseNotifications","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_BOOTSTRAP","DOOR_DISCOVER","DOOR_ENUMERATE","DOOR_REVISIONS","PRIVATE_AUTHORITY","sha256Hex","batchPaths","deltaBody","deltaBytes","deltaDigest","historyOutcome","houseChanges","mutationOutcome","rejectedMapping","revisionBody","uploadable","MODEL_ABSENT","kind","reason","UNCERTAIN","RESOLVED_OUTCOMES","Set","lapsedGrant","outcome","code","modelFailure","classified","envelope","modelVersion","revisions","JSON","stringify","createAgentsHouseAdapter","options","transport","notifications","tracked","Map","models","submissions","modelKey","locator","attached","held","entry","modelRoot","identity","failure","read","snapshot","version","definitions","acquireModels","entries","acquired","privateEntry","find","authority","prefixes","map","undefined","push","answer","door","status","body","bundled","set","handle","retainModel","key","get","previous","roomOf","collection","selection","authorityFor","grant","method","transfer","act","url","uploaded","changes","delta","bytes","paths","sha256","retained","minted","operation_id","delivered","operation","holding","upload","submit","prepared","authorize","model","_authorization","request","discover","fields","document","clear","track","keys","some","startsWith","delete","authorities","bootstrap","pageToken","refresh","streamed","advance","fromRoomVersion","positions","position","enumeration","mutate","mapped","changeBatch","id","resent","has","history","path","revision","action","roomVersions","conversations"],"mappings":"AAmBA,SACEA,iBAAiB,EACjBC,6BAA6B,EAC7BC,cAAc,EACdC,SAAS,EACTC,YAAY,EACZC,cAAc,EACdC,iBAAiB,EACjBC,WAAW,QAGN,iBAAiB;AACxB,SACEC,aAAa,EACbC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,WAAW,EACXC,gBAAgB,EAChBC,aAAa,EACbC,UAAU,EACVC,WAAW,QACN,YAAY;AACnB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,YAAY,QAAQ,eAAe;AAC5C,SAASC,kBAAkB,QAAQ,cAAc;AACjD,SACEC,UAAU,EACVC,iBAAiB,EACjBC,cAAc,EACdC,aAAa,EACbC,cAAc,EACdC,cAAc,EACdC,iBAAiB,QAEZ,iBAAiB;AACxB,SAASC,SAAS,QAAQ,cAAc;AACxC,SACEC,UAAU,EACVC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,cAAc,EACdC,YAAY,EACZC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,UAAU,QACL,aAAa;AASpB,MAAMC,eAA4B;IAAEC,MAAM;IAAqBC,QAAQ;AAAe;AAEtF,MAAMC,YAA4B;IAAEF,MAAM;AAAwB;AAElE,MAAMG,oBAAyD,IAAIC,IAAI;IACrE;IACA;IACA;IACA;CACD;AAID,SAASC,YAAYC,OAAuB;IAC1C,OAAOA,QAAQN,IAAI,KAAK,cAAcM,QAAQC,IAAI,KAAK;AACzD;AAEA,SAASC,aACPC,UAA2C,EAC3CC,QAA0C;IAE1C,IAAID,eAAe,MAAM;QACvB,OAAOC,aAAa,OAAO;YAAEV,MAAM;QAAwB,IAAID;IACjE;IACA,IAAIU,WAAWT,IAAI,KAAK,yBAAyB,OAAO;QAAEA,MAAM;IAAwB;IACxF,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AM3B,QAAQ2B,IAAI;gBAClB3D,QAAQxB,MAAMwB,MAAM;gBACpB,GAAIgC,QAAQ4B,QAAQ,KAAKpE,YAAY,CAAC,IAAI;oBAAEoE,UAAU5B,QAAQ4B,QAAQ;gBAAC,CAAC;gBACxE,GAAI5B,QAAQY,SAAS,KAAKpD,YAAY,CAAC,IAAI;oBAAEoD,WAAWZ,QAAQY,SAAS;gBAAC,CAAC;YAC7E;YAEF,OAAOtG,eAAeoD,OAAOE,MAAM,EAAEF,OAAOG,IAAI,EAAErB,MAAMH,OAAO,EAAE;gBAC/DsF,MAAM3B,QAAQ2B,IAAI;gBAClB,GAAI3B,QAAQ4B,QAAQ,KAAKpE,YAAY,CAAC,IAAI;oBAAEoE,UAAU5B,QAAQ4B,QAAQ;gBAAC,CAAC;YAC1E;QACF;QAEA,MAAMC,QAAO9B,cAA6B,EAAEC,OAAsB;YAChE,OAAOzG,YAAYuC,WAAWkE;QAChC;QAEA8B,cAAc/F;QACdgG,eAAehG,cAAcgG,aAAa;IAC5C;AACF"}
|
package/dist/digest.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../src/digest.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG9D"}
|
package/dist/digest.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function textBytes(value) {
|
|
2
|
+
return new TextEncoder().encode(value).length;
|
|
3
|
+
}
|
|
4
|
+
export async function sha256Hex(value) {
|
|
5
|
+
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
|
|
6
|
+
return [
|
|
7
|
+
...new Uint8Array(digest)
|
|
8
|
+
].map((byte)=>byte.toString(16).padStart(2, '0')).join('');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=digest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/digest.ts"],"sourcesContent":["export function textBytes(value: string): number {\n return new TextEncoder().encode(value).length;\n}\n\nexport async function sha256Hex(value: string): Promise<string> {\n const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));\n return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');\n}\n"],"names":["textBytes","value","TextEncoder","encode","length","sha256Hex","digest","crypto","subtle","Uint8Array","map","byte","toString","padStart","join"],"mappings":"AAAA,OAAO,SAASA,UAAUC,KAAa;IACrC,OAAO,IAAIC,cAAcC,MAAM,CAACF,OAAOG,MAAM;AAC/C;AAEA,OAAO,eAAeC,UAAUJ,KAAa;IAC3C,MAAMK,SAAS,MAAMC,OAAOC,MAAM,CAACF,MAAM,CAAC,WAAW,IAAIJ,cAAcC,MAAM,CAACF;IAC9E,OAAO;WAAI,IAAIQ,WAAWH;KAAQ,CAACI,GAAG,CAAC,CAACC,OAASA,KAAKC,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG,MAAMC,IAAI,CAAC;AAC5F"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Capability, DiscoveredRoom, Discovery, ProviderLimit, Retention, TypedSelection } from '@agentshouse/mdruntime';
|
|
2
|
+
export declare const ROOM_CONTRACT_VERSION = 1;
|
|
3
|
+
export declare const MD_MODEL_IDENTITY = "@agentshouse/mdmodel";
|
|
4
|
+
export declare const ROOM_VERSION_NOTIFICATIONS = "room-version-notifications";
|
|
5
|
+
export declare const PROVIDER_ACTIONS = "provider-actions";
|
|
6
|
+
export declare const DISCOVER_PREFIXES: readonly string[];
|
|
7
|
+
export declare const PROVIDER_SELECTION_ROOTS: readonly string[];
|
|
8
|
+
export declare const PROVIDER_SELECTION_MODEL_ROOT = "house/settings/model";
|
|
9
|
+
export type HouseBounds = {
|
|
10
|
+
max_authored_file_bytes: number;
|
|
11
|
+
max_batch_operations: number;
|
|
12
|
+
max_path_length: number;
|
|
13
|
+
max_path_depth: number;
|
|
14
|
+
max_mount_files: number;
|
|
15
|
+
max_mount_bytes: number;
|
|
16
|
+
change_retention_seconds: number;
|
|
17
|
+
operation_retention_seconds: number;
|
|
18
|
+
};
|
|
19
|
+
export type HouseOperations = {
|
|
20
|
+
read: readonly string[];
|
|
21
|
+
sync: readonly string[];
|
|
22
|
+
write: readonly string[];
|
|
23
|
+
delete: readonly string[];
|
|
24
|
+
};
|
|
25
|
+
export type HouseAuthority = {
|
|
26
|
+
kind: 'room' | 'private';
|
|
27
|
+
roomRef: string;
|
|
28
|
+
roomHandle: string | null;
|
|
29
|
+
name: string;
|
|
30
|
+
collectionRoot: string;
|
|
31
|
+
modelRoot: string;
|
|
32
|
+
managedReplication: 'admitted' | 'unavailable';
|
|
33
|
+
protectedPaths: readonly string[];
|
|
34
|
+
operations: HouseOperations;
|
|
35
|
+
position: string;
|
|
36
|
+
};
|
|
37
|
+
export type HouseDiscoveryDocument = {
|
|
38
|
+
bounds: HouseBounds;
|
|
39
|
+
mdModelVersion: string;
|
|
40
|
+
authorities: readonly HouseAuthority[];
|
|
41
|
+
};
|
|
42
|
+
export type TrackedAuthority = {
|
|
43
|
+
locator: string;
|
|
44
|
+
authority: string;
|
|
45
|
+
handle: string | undefined;
|
|
46
|
+
collectionRoot: string;
|
|
47
|
+
modelRoot: string;
|
|
48
|
+
modelRoots: readonly string[];
|
|
49
|
+
roomVersion: string;
|
|
50
|
+
};
|
|
51
|
+
export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
|
|
52
|
+
export declare function locatorOf(authority: HouseAuthority): string;
|
|
53
|
+
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
54
|
+
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
55
|
+
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
56
|
+
export declare function capabilities(): readonly Capability[];
|
|
57
|
+
export declare function providerSelection(attachedModel: TypedSelection['attachedModel']): TypedSelection;
|
|
58
|
+
export declare function discoveredRoom(authority: HouseAuthority, attachedModel: DiscoveredRoom['attachedModel'], typedSelection: TypedSelection | undefined): DiscoveredRoom;
|
|
59
|
+
export declare function mapDiscovery(document: HouseDiscoveryDocument, rooms: readonly DiscoveredRoom[]): Discovery;
|
|
60
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +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,EACT,cAAc,EACf,MAAM,wBAAwB,CAAC;AAIhC,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AAExD,eAAO,MAAM,0BAA0B,+BAA+B,CAAC;AAEvE,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAAU,CAAC;AAE1D,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAAwB,CAAC;AAE/E,eAAO,MAAM,6BAA6B,yBAAyB,CAAC;AAEpE,MAAM,MAAM,WAAW,GAAG;IACxB,uBAAuB,EAAE,MAAM,CAAC;IAChC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,EAAE,MAAM,CAAC;IACjC,2BAA2B,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC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