@agentshouse/mdruntime-adapter 0.1.0-c4c8594e5b8d9 → 0.1.0-c4d6f3cc9ec0c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/actions.d.ts +6 -67
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -342
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +302 -310
- package/dist/authored-path.d.ts +9 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +34 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +281 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +45 -18
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +252 -66
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -6
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +31 -48
- package/dist/read.d.ts +51 -53
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +176 -256
- package/dist/refusal.d.ts +6 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +27 -11
- package/dist/room-query.d.ts +4 -0
- package/dist/room-query.d.ts.map +1 -0
- package/dist/room-query.js +48 -0
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/check.d.ts +17 -0
- package/dist/session-content/index.d.ts +6 -0
- package/dist/session-content/parts.d.ts +30 -0
- package/dist/session-content/state.d.ts +59 -0
- package/dist/session-content/turn.d.ts +137 -0
- package/dist/site.d.ts +1 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +127 -193
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +14 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +267 -253
- package/dist/transport.d.ts +108 -30
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +89 -11
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +13 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +65 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/write.d.ts +18 -4
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +123 -91
- package/package.json +9 -4
- package/AGENTS.md +0 -299
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -45
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -38
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -35
package/dist/write.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { departure, } from '@agentshouse/mdruntime';
|
|
2
|
-
import { binaryFileOf, headChange } from './read.js';
|
|
1
|
+
import { departure, partsChanges, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
|
|
3
3
|
import { sha256Hex, textBytes } from './digest.js';
|
|
4
4
|
import { nativePath, roomLocalPath } from './map.js';
|
|
5
|
-
import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
|
|
5
|
+
import { answeredFailure, classifyDoor, doorRefusal, resetOf, scopedRefusal } from './refusal.js';
|
|
6
6
|
import { readPosition, roomVersion } from './version.js';
|
|
7
|
+
import { unusable } from './uncertain.js';
|
|
7
8
|
function priorField(batch, path, name) {
|
|
8
9
|
return batch.preconditions.find((precondition) => precondition.kind === 'field' && precondition.path === path && precondition.name === name);
|
|
9
10
|
}
|
|
@@ -28,7 +29,7 @@ function created(change, path) {
|
|
|
28
29
|
const { type, ...fields } = change.fields;
|
|
29
30
|
if (typeof type !== 'string' || type.length === 0)
|
|
30
31
|
return null;
|
|
31
|
-
return { op: 'create_typed', path, type, fields
|
|
32
|
+
return { op: 'create_typed', path, type, fields };
|
|
32
33
|
}
|
|
33
34
|
function operationOf(batch, change, handle) {
|
|
34
35
|
const path = nativePath(change.path, handle);
|
|
@@ -120,16 +121,36 @@ export function houseChanges(batch, handle) {
|
|
|
120
121
|
}
|
|
121
122
|
return { kind: 'changes', changes };
|
|
122
123
|
}
|
|
123
|
-
export function
|
|
124
|
+
export function houseParts(saved, handle) {
|
|
125
|
+
return houseChanges({ id: '', baseRoomVersion: '', ...partsChanges(saved) }, handle);
|
|
126
|
+
}
|
|
127
|
+
export function houseMove(batch, source, destination) {
|
|
128
|
+
const changes = [];
|
|
129
|
+
for (const { path, to } of batch.between?.moves ?? []) {
|
|
130
|
+
const existence = priorExistence(batch, path);
|
|
131
|
+
if (existence === undefined)
|
|
132
|
+
return { kind: 'unmapped', path, rule: 'precondition-missing' };
|
|
133
|
+
if (!('base' in existence)) {
|
|
134
|
+
return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
|
|
135
|
+
}
|
|
136
|
+
changes.push({
|
|
137
|
+
op: 'rename',
|
|
138
|
+
path: nativePath(path, source),
|
|
139
|
+
to: nativePath(to, destination),
|
|
140
|
+
base: existence.base,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return { kind: 'changes', changes };
|
|
144
|
+
}
|
|
145
|
+
export function operationHead(batch, room) {
|
|
124
146
|
const writer = batch.writtenBy;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
: { operation_id: batch.id, app_ref: writer.app, release: writer.release };
|
|
147
|
+
const head = { operation_id: batch.id, room_ref: room };
|
|
148
|
+
return writer === undefined ? head : { ...head, app_ref: writer.app, release: writer.release };
|
|
128
149
|
}
|
|
129
150
|
export function batchPaths(changes) {
|
|
130
151
|
return [
|
|
131
152
|
...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
132
|
-
]
|
|
153
|
+
];
|
|
133
154
|
}
|
|
134
155
|
export function deltaBody(changes) {
|
|
135
156
|
return JSON.stringify({ changes });
|
|
@@ -144,16 +165,19 @@ export function uploadable(inline, bytes, bounds) {
|
|
|
144
165
|
export function deltaDigest(delta) {
|
|
145
166
|
return sha256Hex(delta);
|
|
146
167
|
}
|
|
147
|
-
function material(value, handle) {
|
|
168
|
+
function* material(value, handle, within = () => true) {
|
|
148
169
|
if (!Array.isArray(value))
|
|
149
170
|
return null;
|
|
150
171
|
const held = [];
|
|
151
172
|
for (const entry of value) {
|
|
173
|
+
yield ROW_WEIGHT;
|
|
152
174
|
if (typeof entry !== 'object' || entry === null)
|
|
153
175
|
return null;
|
|
154
176
|
const file = entry;
|
|
155
177
|
if (typeof file.path !== 'string')
|
|
156
178
|
return null;
|
|
179
|
+
if (!within(file.path))
|
|
180
|
+
continue;
|
|
157
181
|
if (file.content !== null && typeof file.content !== 'string')
|
|
158
182
|
return null;
|
|
159
183
|
if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
|
|
@@ -181,27 +205,69 @@ function material(value, handle) {
|
|
|
181
205
|
}
|
|
182
206
|
return held;
|
|
183
207
|
}
|
|
184
|
-
function affectedOf(held) {
|
|
208
|
+
function* affectedOf(held) {
|
|
185
209
|
const affected = {};
|
|
186
210
|
for (const entry of held) {
|
|
187
211
|
if (entry.content !== null)
|
|
188
212
|
affected[entry.path] = entry.content;
|
|
213
|
+
yield ROW_WEIGHT;
|
|
189
214
|
}
|
|
190
215
|
return affected;
|
|
191
216
|
}
|
|
192
|
-
|
|
217
|
+
function* acceptedOf(at, contents) {
|
|
218
|
+
const answer = answering();
|
|
219
|
+
for (const entry of contents) {
|
|
220
|
+
yield ROW_WEIGHT + (entry.content?.length ?? 0);
|
|
221
|
+
if (entry.revision === null) {
|
|
222
|
+
answer.removals.add(entry.path);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (entry.content !== null)
|
|
226
|
+
answer.documents.set(entry.path, entry.content);
|
|
227
|
+
if (entry.binary !== undefined)
|
|
228
|
+
answer.binaryFiles.set(entry.path, entry.binary);
|
|
229
|
+
revised(answer, entry.path, entry.revision);
|
|
230
|
+
if (entry.head !== undefined)
|
|
231
|
+
answer.changes.set(entry.path, entry.head);
|
|
232
|
+
}
|
|
233
|
+
const unbinaried = answer.binaryFiles.size === 0;
|
|
234
|
+
const { binaryFiles, facts: _facts, ...room } = yield* answered(answer);
|
|
235
|
+
return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { binaryFiles }) };
|
|
236
|
+
}
|
|
237
|
+
function* movedOutcome(held, move) {
|
|
238
|
+
const authorities = Array.isArray(held.authorities) ? held.authorities : [];
|
|
239
|
+
const at = (authority) => {
|
|
240
|
+
const entry = authorities.find((one) => typeof one === 'object' &&
|
|
241
|
+
one !== null &&
|
|
242
|
+
one.authority === authority);
|
|
243
|
+
return entry === undefined ? null : readPosition(entry);
|
|
244
|
+
};
|
|
245
|
+
const left = at(move.source.authority);
|
|
246
|
+
const arrived = at(move.destination.authority);
|
|
247
|
+
if (left === null || arrived === null)
|
|
248
|
+
return unusable();
|
|
249
|
+
const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
|
|
250
|
+
const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
|
|
251
|
+
const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
|
|
252
|
+
if (leaving === null || arriving === null)
|
|
253
|
+
return unusable();
|
|
254
|
+
return {
|
|
255
|
+
kind: 'accepted',
|
|
256
|
+
...(yield* acceptedOf(left, leaving)),
|
|
257
|
+
destination: yield* acceptedOf(arrived, arriving),
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
export function* mutationOutcome(status, body, locator, handle, move) {
|
|
193
261
|
const refusal = doorRefusal(body);
|
|
194
262
|
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
195
263
|
return { kind: 'write-halted' };
|
|
196
264
|
}
|
|
197
|
-
if (refusal !== null && refusal.code === 'expired')
|
|
198
|
-
return { kind: 'expired' };
|
|
199
265
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
200
266
|
const { current, ...fields } = refusal.fields;
|
|
201
|
-
const held = material(current, handle) ?? [];
|
|
267
|
+
const held = (yield* material(current, handle)) ?? [];
|
|
202
268
|
return {
|
|
203
269
|
kind: 'conflicted',
|
|
204
|
-
affected: affectedOf(held),
|
|
270
|
+
affected: yield* affectedOf(held),
|
|
205
271
|
code: refusal.code,
|
|
206
272
|
fields,
|
|
207
273
|
retryable: refusal.retryable,
|
|
@@ -211,10 +277,8 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
211
277
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
212
278
|
}
|
|
213
279
|
const classified = classifyDoor(status, body, locator);
|
|
214
|
-
const reset = refusal
|
|
215
|
-
if (refusal?.
|
|
216
|
-
typeof reset === 'string' &&
|
|
217
|
-
classified?.kind === 'transport-uncertainty') {
|
|
280
|
+
const reset = resetOf(refusal);
|
|
281
|
+
if (refusal !== null && reset !== undefined && classified?.kind === 'transport-uncertainty') {
|
|
218
282
|
return {
|
|
219
283
|
kind: 'retryable-refusal',
|
|
220
284
|
code: refusal.code,
|
|
@@ -225,8 +289,9 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
225
289
|
}
|
|
226
290
|
if (classified !== null && classified.kind !== 'scoped-refusal')
|
|
227
291
|
return classified;
|
|
228
|
-
if (classified !== null && status === 403)
|
|
292
|
+
if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
|
|
229
293
|
return classified;
|
|
294
|
+
}
|
|
230
295
|
if (refusal !== null && status >= 400) {
|
|
231
296
|
return {
|
|
232
297
|
kind: 'rejected',
|
|
@@ -236,43 +301,20 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
236
301
|
retryable: refusal.retryable,
|
|
237
302
|
};
|
|
238
303
|
}
|
|
239
|
-
if (status !== 200
|
|
240
|
-
return
|
|
241
|
-
|
|
304
|
+
if (status !== 200)
|
|
305
|
+
return answeredFailure(status, body);
|
|
306
|
+
if (typeof body !== 'object' || body === null)
|
|
307
|
+
return unusable();
|
|
242
308
|
const held = body;
|
|
309
|
+
if (move !== undefined)
|
|
310
|
+
return yield* movedOutcome(held, move);
|
|
243
311
|
const at = readPosition(held);
|
|
244
312
|
if (at === null)
|
|
245
|
-
return
|
|
246
|
-
const contents = material(held.contents, handle);
|
|
313
|
+
return unusable();
|
|
314
|
+
const contents = yield* material(held.contents, handle);
|
|
247
315
|
if (contents === null)
|
|
248
|
-
return
|
|
249
|
-
|
|
250
|
-
const revisions = {};
|
|
251
|
-
const changes = {};
|
|
252
|
-
const binaryFiles = {};
|
|
253
|
-
const removals = [];
|
|
254
|
-
for (const entry of contents) {
|
|
255
|
-
if (entry.revision === null) {
|
|
256
|
-
removals.push(entry.path);
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
if (entry.content !== null)
|
|
260
|
-
documents[entry.path] = entry.content;
|
|
261
|
-
if (entry.binary !== undefined)
|
|
262
|
-
binaryFiles[entry.path] = entry.binary;
|
|
263
|
-
revisions[entry.path] = entry.revision;
|
|
264
|
-
if (entry.head !== undefined)
|
|
265
|
-
changes[entry.path] = entry.head;
|
|
266
|
-
}
|
|
267
|
-
return {
|
|
268
|
-
kind: 'accepted',
|
|
269
|
-
roomVersion: roomVersion(at),
|
|
270
|
-
documents,
|
|
271
|
-
revisions,
|
|
272
|
-
changes,
|
|
273
|
-
removals: removals.sort(),
|
|
274
|
-
...(Object.keys(binaryFiles).length === 0 ? {} : { binaryFiles }),
|
|
275
|
-
};
|
|
316
|
+
return unusable();
|
|
317
|
+
return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
|
|
276
318
|
}
|
|
277
319
|
export function rejectedMapping(mapping) {
|
|
278
320
|
return {
|
|
@@ -292,61 +334,51 @@ export function revisionBody(input) {
|
|
|
292
334
|
}
|
|
293
335
|
function revisionAuthor(entry) {
|
|
294
336
|
const user = entry.author_user;
|
|
337
|
+
const userName = entry.author_user_name;
|
|
295
338
|
const site = entry.author_site;
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
339
|
+
const siteName = entry.author_site_name;
|
|
340
|
+
const inbox = entry.author_inbox;
|
|
341
|
+
const inboxName = entry.author_inbox_name;
|
|
342
|
+
const app = entry.author_app;
|
|
343
|
+
const appName = entry.author_app_name;
|
|
344
|
+
const named = [site, siteName, inbox, inboxName, app, appName].filter((held) => held !== undefined);
|
|
345
|
+
if (typeof user === 'string' && typeof userName === 'string' && named.length === 0)
|
|
346
|
+
return { kind: 'user', id: user, name: userName };
|
|
347
|
+
if (user !== null || userName !== undefined || named.length !== 2)
|
|
348
|
+
return null;
|
|
349
|
+
if (typeof site === 'string' && typeof siteName === 'string') {
|
|
350
|
+
return { kind: 'site', id: site, name: siteName };
|
|
351
|
+
}
|
|
352
|
+
if (typeof inbox === 'string' && typeof inboxName === 'string') {
|
|
353
|
+
return { kind: 'inbox', id: inbox, name: inboxName };
|
|
299
354
|
}
|
|
300
|
-
if (
|
|
301
|
-
return { kind: '
|
|
355
|
+
if (typeof app === 'string' && typeof appName === 'string') {
|
|
356
|
+
return { kind: 'app', id: app, name: appName };
|
|
302
357
|
}
|
|
303
358
|
return null;
|
|
304
359
|
}
|
|
305
|
-
function historyBinary(entry) {
|
|
306
|
-
if (entry.file === undefined)
|
|
307
|
-
return undefined;
|
|
308
|
-
const { file, bytes, media_type: mediaType, sha256 } = entry;
|
|
309
|
-
if (typeof file !== 'string' ||
|
|
310
|
-
typeof bytes !== 'number' ||
|
|
311
|
-
typeof mediaType !== 'string' ||
|
|
312
|
-
typeof sha256 !== 'string')
|
|
313
|
-
return null;
|
|
314
|
-
return { fileRef: file, byteLength: bytes, mediaType, sha256 };
|
|
315
|
-
}
|
|
316
360
|
export function historyOutcome(status, body, locator, request) {
|
|
317
361
|
const classified = classifyDoor(status, body, locator);
|
|
318
362
|
if (classified !== null)
|
|
319
363
|
return classified;
|
|
320
364
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
321
|
-
return
|
|
365
|
+
return unusable();
|
|
322
366
|
}
|
|
323
367
|
const held = body;
|
|
324
368
|
if (!Array.isArray(held.revisions))
|
|
325
|
-
return
|
|
369
|
+
return unusable();
|
|
326
370
|
const entries = [];
|
|
327
371
|
for (const entry of held.revisions) {
|
|
328
372
|
if (typeof entry !== 'object' || entry === null)
|
|
329
|
-
return
|
|
373
|
+
return unusable();
|
|
330
374
|
entries.push(entry);
|
|
331
375
|
}
|
|
332
|
-
|
|
333
|
-
|
|
376
|
+
const named = entries[0];
|
|
377
|
+
if (request.revision !== undefined && typeof named?.media_type !== 'string') {
|
|
334
378
|
if (named === undefined)
|
|
335
379
|
return { kind: 'no-history' };
|
|
336
|
-
if (named.unavailable === true) {
|
|
337
|
-
return {
|
|
338
|
-
kind: 'scoped-refusal',
|
|
339
|
-
locator,
|
|
340
|
-
scope: 'content',
|
|
341
|
-
code: 'retained_history_unavailable',
|
|
342
|
-
fields: { path: request.path, revision: request.revision },
|
|
343
|
-
retryable: false,
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
if (typeof named.file === 'string')
|
|
347
|
-
return { kind: 'no-history' };
|
|
348
380
|
if (typeof named.content !== 'string')
|
|
349
|
-
return
|
|
381
|
+
return unusable();
|
|
350
382
|
return { kind: 'revision', content: named.content };
|
|
351
383
|
}
|
|
352
384
|
if (entries.length === 0)
|
|
@@ -357,11 +389,11 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
357
389
|
if (typeof entry.revision !== 'string' ||
|
|
358
390
|
author === null ||
|
|
359
391
|
typeof entry.created_at !== 'string') {
|
|
360
|
-
return
|
|
392
|
+
return unusable();
|
|
361
393
|
}
|
|
362
|
-
const binaryFile =
|
|
394
|
+
const binaryFile = binaryFileOf(entry);
|
|
363
395
|
if (binaryFile === null)
|
|
364
|
-
return
|
|
396
|
+
return unusable();
|
|
365
397
|
revisions.push({
|
|
366
398
|
revision: entry.revision,
|
|
367
399
|
author,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-c4d6f3cc9ec0c",
|
|
4
4
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
11
|
"engines": {
|
|
12
|
-
"node": ">=24.
|
|
12
|
+
"node": ">=24.22.1"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
@@ -20,11 +20,16 @@
|
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|
|
23
|
-
"AGENTS.md",
|
|
24
23
|
"README.md",
|
|
25
24
|
"LICENSE"
|
|
26
25
|
],
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"@agentshouse/
|
|
27
|
+
"@agentshouse/mdmodel": "0.1.0-ceaa149100378",
|
|
28
|
+
"@agentshouse/mdruntime": "0.1.0-cc158c791f648"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/agentshouse/core.git",
|
|
33
|
+
"directory": "mdruntime/packages/mdruntime-adapter"
|
|
29
34
|
}
|
|
30
35
|
}
|