@agentshouse/mdruntime-adapter 0.1.0-c4e5de8f794bd → 0.1.0-c4f0f45520c6f

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.
Files changed (75) hide show
  1. package/README.md +3 -3
  2. package/dist/actions.d.ts +6 -67
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +26 -344
  5. package/dist/adapter.d.ts +0 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +262 -406
  8. package/dist/authored-path.d.ts +9 -0
  9. package/dist/authored-path.d.ts.map +1 -0
  10. package/dist/authored-path.js +34 -0
  11. package/dist/chunks.d.ts +36 -0
  12. package/dist/chunks.d.ts.map +1 -0
  13. package/dist/chunks.js +289 -0
  14. package/dist/digest.d.ts +0 -1
  15. package/dist/discovery.d.ts +24 -18
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +95 -58
  18. package/dist/history.d.ts +6 -0
  19. package/dist/history.d.ts.map +1 -0
  20. package/dist/history.js +85 -0
  21. package/dist/index.d.ts +9 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +8 -1
  24. package/dist/map.d.ts +0 -1
  25. package/dist/model.d.ts +5 -5
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +33 -41
  28. package/dist/read.d.ts +57 -65
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +155 -319
  31. package/dist/refusal.d.ts +3 -5
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +17 -12
  34. package/dist/search.d.ts +4 -0
  35. package/dist/search.d.ts.map +1 -0
  36. package/dist/search.js +47 -0
  37. package/dist/session-content/bounds.d.ts +7 -0
  38. package/dist/session-content/check.d.ts +18 -0
  39. package/dist/session-content/index.d.ts +7 -0
  40. package/dist/session-content/parts.d.ts +103 -0
  41. package/dist/session-content/state.d.ts +61 -0
  42. package/dist/session-content/turn.d.ts +328 -0
  43. package/dist/site.d.ts +0 -1
  44. package/dist/site.d.ts.map +1 -1
  45. package/dist/site.js +89 -206
  46. package/dist/space-schema.d.ts +6 -0
  47. package/dist/space-schema.d.ts.map +1 -0
  48. package/dist/space-schema.js +11 -0
  49. package/dist/stream.d.ts +15 -16
  50. package/dist/stream.d.ts.map +1 -1
  51. package/dist/stream.js +264 -423
  52. package/dist/transport.d.ts +74 -45
  53. package/dist/transport.d.ts.map +1 -1
  54. package/dist/transport.js +54 -11
  55. package/dist/uncertain.d.ts +5 -0
  56. package/dist/uncertain.d.ts.map +1 -0
  57. package/dist/uncertain.js +11 -0
  58. package/dist/upload.d.ts +13 -0
  59. package/dist/upload.d.ts.map +1 -0
  60. package/dist/upload.js +65 -0
  61. package/dist/version.d.ts +0 -1
  62. package/dist/write.d.ts +18 -4
  63. package/dist/write.d.ts.map +1 -1
  64. package/dist/write.js +122 -92
  65. package/package.json +9 -4
  66. package/AGENTS.md +0 -299
  67. package/dist/gather.d.ts +0 -4
  68. package/dist/gather.d.ts.map +0 -1
  69. package/dist/gather.js +0 -45
  70. package/dist/handed.d.ts +0 -15
  71. package/dist/handed.d.ts.map +0 -1
  72. package/dist/handed.js +0 -38
  73. package/dist/referrer.d.ts +0 -7
  74. package/dist/referrer.d.ts.map +0 -1
  75. 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, identities } 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, sections: change.sections };
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 operationHead(batch) {
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
- return writer === undefined
126
- ? { operation_id: batch.id }
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
- ].sort();
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,30 +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
- export function mutationOutcome(status, body, locator, handle) {
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 refusal.fields.restored === true
199
- ? { kind: 'expired', restored: true }
200
- : { kind: 'expired' };
201
- }
202
265
  if (refusal !== null && refusal.code === 'edit_conflict') {
203
266
  const { current, ...fields } = refusal.fields;
204
- const held = material(current, handle) ?? [];
267
+ const held = (yield* material(current, handle)) ?? [];
205
268
  return {
206
269
  kind: 'conflicted',
207
- affected: affectedOf(held),
270
+ affected: yield* affectedOf(held),
208
271
  code: refusal.code,
209
272
  fields,
210
273
  retryable: refusal.retryable,
@@ -214,10 +277,8 @@ export function mutationOutcome(status, body, locator, handle) {
214
277
  return scopedRefusal(locator, 'undisclosed', refusal);
215
278
  }
216
279
  const classified = classifyDoor(status, body, locator);
217
- const reset = refusal?.fields.retry_at;
218
- if (refusal?.retryable === true &&
219
- typeof reset === 'string' &&
220
- classified?.kind === 'transport-uncertainty') {
280
+ const reset = resetOf(refusal);
281
+ if (refusal !== null && reset !== undefined && classified?.kind === 'transport-uncertainty') {
221
282
  return {
222
283
  kind: 'retryable-refusal',
223
284
  code: refusal.code,
@@ -228,8 +289,9 @@ export function mutationOutcome(status, body, locator, handle) {
228
289
  }
229
290
  if (classified !== null && classified.kind !== 'scoped-refusal')
230
291
  return classified;
231
- if (classified !== null && status === 403)
292
+ if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
232
293
  return classified;
294
+ }
233
295
  if (refusal !== null && status >= 400) {
234
296
  return {
235
297
  kind: 'rejected',
@@ -239,44 +301,20 @@ export function mutationOutcome(status, body, locator, handle) {
239
301
  retryable: refusal.retryable,
240
302
  };
241
303
  }
242
- if (status !== 200 || typeof body !== 'object' || body === null) {
243
- return { kind: 'transport-uncertainty' };
244
- }
304
+ if (status !== 200)
305
+ return answeredFailure(status, body);
306
+ if (typeof body !== 'object' || body === null)
307
+ return unusable();
245
308
  const held = body;
309
+ if (move !== undefined)
310
+ return yield* movedOutcome(held, move);
246
311
  const at = readPosition(held);
247
312
  if (at === null)
248
- return { kind: 'transport-uncertainty' };
249
- const contents = material(held.contents, handle);
313
+ return unusable();
314
+ const contents = yield* material(held.contents, handle);
250
315
  if (contents === null)
251
- return { kind: 'transport-uncertainty' };
252
- const documents = {};
253
- const revisions = {};
254
- const changes = {};
255
- const binaryFiles = {};
256
- const removals = [];
257
- for (const entry of contents) {
258
- if (entry.revision === null) {
259
- removals.push(entry.path);
260
- continue;
261
- }
262
- if (entry.content !== null)
263
- documents[entry.path] = entry.content;
264
- if (entry.binary !== undefined)
265
- binaryFiles[entry.path] = entry.binary;
266
- revisions[entry.path] = entry.revision;
267
- if (entry.head !== undefined)
268
- changes[entry.path] = entry.head;
269
- }
270
- return {
271
- kind: 'accepted',
272
- roomVersion: roomVersion(at),
273
- documents,
274
- revisions,
275
- ...identities(revisions),
276
- changes,
277
- removals: removals.sort(),
278
- ...(Object.keys(binaryFiles).length === 0 ? {} : { binaryFiles }),
279
- };
316
+ return unusable();
317
+ return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
280
318
  }
281
319
  export function rejectedMapping(mapping) {
282
320
  return {
@@ -296,61 +334,53 @@ export function revisionBody(input) {
296
334
  }
297
335
  function revisionAuthor(entry) {
298
336
  const user = entry.author_user;
337
+ const userName = entry.author_user_name;
299
338
  const site = entry.author_site;
300
- const name = entry.author_site_name;
301
- if (typeof user === 'string' && site === undefined && name === undefined) {
302
- return { kind: 'user', id: user };
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 };
303
351
  }
304
- if (user === null && typeof site === 'string' && typeof name === 'string') {
305
- return { kind: 'site', id: site, name };
352
+ if (typeof inbox === 'string' && typeof inboxName === 'string') {
353
+ return { kind: 'inbox', id: inbox, name: inboxName };
354
+ }
355
+ if (typeof app === 'string' && typeof appName === 'string') {
356
+ return { kind: 'app', id: app, name: appName };
306
357
  }
307
358
  return null;
308
359
  }
309
- function historyBinary(entry) {
310
- if (entry.file === undefined)
311
- return undefined;
312
- const { file, bytes, media_type: mediaType, sha256 } = entry;
313
- if (typeof file !== 'string' ||
314
- typeof bytes !== 'number' ||
315
- typeof mediaType !== 'string' ||
316
- typeof sha256 !== 'string')
317
- return null;
318
- return { fileRef: file, byteLength: bytes, mediaType, sha256 };
319
- }
320
360
  export function historyOutcome(status, body, locator, request) {
321
361
  const classified = classifyDoor(status, body, locator);
322
362
  if (classified !== null)
323
363
  return classified;
324
364
  if (status !== 200 || typeof body !== 'object' || body === null) {
325
- return { kind: 'transport-uncertainty' };
365
+ return unusable();
326
366
  }
327
367
  const held = body;
328
368
  if (!Array.isArray(held.revisions))
329
- return { kind: 'transport-uncertainty' };
369
+ return unusable();
330
370
  const entries = [];
331
371
  for (const entry of held.revisions) {
332
372
  if (typeof entry !== 'object' || entry === null)
333
- return { kind: 'transport-uncertainty' };
373
+ return unusable();
334
374
  entries.push(entry);
335
375
  }
336
376
  if (request.revision !== undefined) {
337
377
  const named = entries[0];
338
378
  if (named === undefined)
339
379
  return { kind: 'no-history' };
340
- if (named.unavailable === true) {
341
- return {
342
- kind: 'scoped-refusal',
343
- locator,
344
- scope: 'operation',
345
- code: 'retained_history_unavailable',
346
- fields: { path: request.path, revision: request.revision },
347
- retryable: false,
348
- };
349
- }
350
- if (typeof named.file === 'string')
380
+ if (typeof named.media_type === 'string')
351
381
  return { kind: 'no-history' };
352
382
  if (typeof named.content !== 'string')
353
- return { kind: 'transport-uncertainty' };
383
+ return unusable();
354
384
  return { kind: 'revision', content: named.content };
355
385
  }
356
386
  if (entries.length === 0)
@@ -361,11 +391,11 @@ export function historyOutcome(status, body, locator, request) {
361
391
  if (typeof entry.revision !== 'string' ||
362
392
  author === null ||
363
393
  typeof entry.created_at !== 'string') {
364
- return { kind: 'transport-uncertainty' };
394
+ return unusable();
365
395
  }
366
- const binaryFile = historyBinary(entry);
396
+ const binaryFile = binaryFileOf(entry);
367
397
  if (binaryFile === null)
368
- return { kind: 'transport-uncertainty' };
398
+ return unusable();
369
399
  revisions.push({
370
400
  revision: entry.revision,
371
401
  author,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-c4e5de8f794bd",
3
+ "version": "0.1.0-c4f0f45520c6f",
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.21.0"
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/mdruntime": "0.1.0-c1c827aa23c34"
27
+ "@agentshouse/mdmodel": "0.1.0-c807a6b98e2b4",
28
+ "@agentshouse/mdruntime": "0.1.0-c36943a474174"
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
  }