@agentshouse/mdruntime-adapter 0.1.0-c6296cfbceb56 → 0.1.0-c63f5d0daa11b

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 (79) hide show
  1. package/README.md +3 -3
  2. package/dist/actions.d.ts +6 -44
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +26 -338
  5. package/dist/adapter.d.ts +1 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +302 -310
  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 +281 -0
  14. package/dist/digest.d.ts +0 -1
  15. package/dist/discovery.d.ts +45 -18
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +254 -65
  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 +10 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +9 -1
  24. package/dist/map.d.ts +0 -1
  25. package/dist/model.d.ts +6 -7
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +30 -50
  28. package/dist/read.d.ts +51 -51
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +176 -244
  31. package/dist/refusal.d.ts +6 -5
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +27 -10
  34. package/dist/room-query.d.ts +4 -0
  35. package/dist/room-query.d.ts.map +1 -0
  36. package/dist/room-query.js +48 -0
  37. package/dist/search.d.ts +4 -0
  38. package/dist/search.d.ts.map +1 -0
  39. package/dist/search.js +47 -0
  40. package/dist/session-content/check.d.ts +17 -0
  41. package/dist/session-content/index.d.ts +6 -0
  42. package/dist/session-content/parts.d.ts +30 -0
  43. package/dist/session-content/state.d.ts +59 -0
  44. package/dist/session-content/turn.d.ts +137 -0
  45. package/dist/site.d.ts +1 -2
  46. package/dist/site.d.ts.map +1 -1
  47. package/dist/site.js +126 -133
  48. package/dist/space-schema.d.ts +6 -0
  49. package/dist/space-schema.d.ts.map +1 -0
  50. package/dist/space-schema.js +11 -0
  51. package/dist/stream.d.ts +14 -14
  52. package/dist/stream.d.ts.map +1 -1
  53. package/dist/stream.js +276 -160
  54. package/dist/transport.d.ts +113 -31
  55. package/dist/transport.d.ts.map +1 -1
  56. package/dist/transport.js +88 -11
  57. package/dist/uncertain.d.ts +5 -0
  58. package/dist/uncertain.d.ts.map +1 -0
  59. package/dist/uncertain.js +11 -0
  60. package/dist/upload.d.ts +13 -0
  61. package/dist/upload.d.ts.map +1 -0
  62. package/dist/upload.js +65 -0
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.d.ts.map +1 -1
  65. package/dist/version.js +1 -1
  66. package/dist/write.d.ts +18 -4
  67. package/dist/write.d.ts.map +1 -1
  68. package/dist/write.js +126 -93
  69. package/package.json +9 -5
  70. package/AGENTS.md +0 -318
  71. package/dist/gather.d.ts +0 -4
  72. package/dist/gather.d.ts.map +0 -1
  73. package/dist/gather.js +0 -45
  74. package/dist/handed.d.ts +0 -15
  75. package/dist/handed.d.ts.map +0 -1
  76. package/dist/handed.js +0 -38
  77. package/dist/referrer.d.ts +0 -7
  78. package/dist/referrer.d.ts.map +0 -1
  79. package/dist/referrer.js +0 -35
package/dist/write.js CHANGED
@@ -1,9 +1,10 @@
1
- import { departure, } from '@agentshouse/mdruntime';
2
- import { 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, 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,21 +165,25 @@ 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')
160
184
  return null;
161
- if (file.file !== undefined && typeof file.file !== 'string')
185
+ const binary = binaryFileOf(file);
186
+ if (binary === null)
162
187
  return null;
163
188
  const head = headChange(file);
164
189
  if (head === null)
@@ -174,33 +199,75 @@ function material(value, handle) {
174
199
  path,
175
200
  content: file.content,
176
201
  revision: typeof file.revision === 'string' ? file.revision : null,
177
- file: typeof file.file === 'string' ? file.file : null,
202
+ ...(binary === undefined ? {} : { binary }),
178
203
  ...(head === undefined ? {} : { head }),
179
204
  });
180
205
  }
181
206
  return held;
182
207
  }
183
- function affectedOf(held) {
208
+ function* affectedOf(held) {
184
209
  const affected = {};
185
210
  for (const entry of held) {
186
211
  if (entry.content !== null)
187
212
  affected[entry.path] = entry.content;
213
+ yield ROW_WEIGHT;
188
214
  }
189
215
  return affected;
190
216
  }
191
- 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) {
192
261
  const refusal = doorRefusal(body);
193
262
  if (refusal !== null && refusal.code === 'service_mode_write_halted') {
194
263
  return { kind: 'write-halted' };
195
264
  }
196
- if (refusal !== null && refusal.code === 'expired')
197
- return { kind: 'expired' };
198
265
  if (refusal !== null && refusal.code === 'edit_conflict') {
199
266
  const { current, ...fields } = refusal.fields;
200
- const held = material(current, handle) ?? [];
267
+ const held = (yield* material(current, handle)) ?? [];
201
268
  return {
202
269
  kind: 'conflicted',
203
- affected: affectedOf(held),
270
+ affected: yield* affectedOf(held),
204
271
  code: refusal.code,
205
272
  fields,
206
273
  retryable: refusal.retryable,
@@ -210,10 +277,8 @@ export function mutationOutcome(status, body, locator, handle) {
210
277
  return scopedRefusal(locator, 'undisclosed', refusal);
211
278
  }
212
279
  const classified = classifyDoor(status, body, locator);
213
- const reset = refusal?.fields.retry_at;
214
- if (refusal?.retryable === true &&
215
- typeof reset === 'string' &&
216
- classified?.kind === 'transport-uncertainty') {
280
+ const reset = resetOf(refusal);
281
+ if (refusal !== null && reset !== undefined && classified?.kind === 'transport-uncertainty') {
217
282
  return {
218
283
  kind: 'retryable-refusal',
219
284
  code: refusal.code,
@@ -224,8 +289,9 @@ export function mutationOutcome(status, body, locator, handle) {
224
289
  }
225
290
  if (classified !== null && classified.kind !== 'scoped-refusal')
226
291
  return classified;
227
- if (classified !== null && status === 403)
292
+ if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
228
293
  return classified;
294
+ }
229
295
  if (refusal !== null && status >= 400) {
230
296
  return {
231
297
  kind: 'rejected',
@@ -235,43 +301,20 @@ export function mutationOutcome(status, body, locator, handle) {
235
301
  retryable: refusal.retryable,
236
302
  };
237
303
  }
238
- if (status !== 200 || typeof body !== 'object' || body === null) {
239
- return { kind: 'transport-uncertainty' };
240
- }
304
+ if (status !== 200)
305
+ return answeredFailure(status, body);
306
+ if (typeof body !== 'object' || body === null)
307
+ return unusable();
241
308
  const held = body;
309
+ if (move !== undefined)
310
+ return yield* movedOutcome(held, move);
242
311
  const at = readPosition(held);
243
312
  if (at === null)
244
- return { kind: 'transport-uncertainty' };
245
- const contents = material(held.contents, handle);
313
+ return unusable();
314
+ const contents = yield* material(held.contents, handle);
246
315
  if (contents === null)
247
- return { kind: 'transport-uncertainty' };
248
- const documents = {};
249
- const revisions = {};
250
- const changes = {};
251
- const fileRefs = {};
252
- const removals = [];
253
- for (const entry of contents) {
254
- if (entry.revision === null) {
255
- removals.push(entry.path);
256
- continue;
257
- }
258
- if (entry.content !== null)
259
- documents[entry.path] = entry.content;
260
- if (entry.file !== null)
261
- fileRefs[entry.path] = entry.file;
262
- revisions[entry.path] = entry.revision;
263
- if (entry.head !== undefined)
264
- changes[entry.path] = entry.head;
265
- }
266
- return {
267
- kind: 'accepted',
268
- roomVersion: roomVersion(at),
269
- documents,
270
- revisions,
271
- changes,
272
- removals: removals.sort(),
273
- ...(Object.keys(fileRefs).length === 0 ? {} : { fileRefs }),
274
- };
316
+ return unusable();
317
+ return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
275
318
  }
276
319
  export function rejectedMapping(mapping) {
277
320
  return {
@@ -291,61 +334,51 @@ export function revisionBody(input) {
291
334
  }
292
335
  function revisionAuthor(entry) {
293
336
  const user = entry.author_user;
337
+ const userName = entry.author_user_name;
294
338
  const site = entry.author_site;
295
- const name = entry.author_site_name;
296
- if (typeof user === 'string' && site === undefined && name === undefined) {
297
- 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 };
351
+ }
352
+ if (typeof inbox === 'string' && typeof inboxName === 'string') {
353
+ return { kind: 'inbox', id: inbox, name: inboxName };
298
354
  }
299
- if (user === null && typeof site === 'string' && typeof name === 'string') {
300
- return { kind: 'site', id: site, name };
355
+ if (typeof app === 'string' && typeof appName === 'string') {
356
+ return { kind: 'app', id: app, name: appName };
301
357
  }
302
358
  return null;
303
359
  }
304
- function historyBinary(entry) {
305
- if (entry.file === undefined)
306
- return undefined;
307
- const { file, bytes, media_type: mediaType, sha256 } = entry;
308
- if (typeof file !== 'string' ||
309
- typeof bytes !== 'number' ||
310
- typeof mediaType !== 'string' ||
311
- typeof sha256 !== 'string')
312
- return null;
313
- return { fileRef: file, byteLength: bytes, mediaType, sha256 };
314
- }
315
360
  export function historyOutcome(status, body, locator, request) {
316
361
  const classified = classifyDoor(status, body, locator);
317
362
  if (classified !== null)
318
363
  return classified;
319
364
  if (status !== 200 || typeof body !== 'object' || body === null) {
320
- return { kind: 'transport-uncertainty' };
365
+ return unusable();
321
366
  }
322
367
  const held = body;
323
368
  if (!Array.isArray(held.revisions))
324
- return { kind: 'transport-uncertainty' };
369
+ return unusable();
325
370
  const entries = [];
326
371
  for (const entry of held.revisions) {
327
372
  if (typeof entry !== 'object' || entry === null)
328
- return { kind: 'transport-uncertainty' };
373
+ return unusable();
329
374
  entries.push(entry);
330
375
  }
331
- if (request.revision !== undefined) {
332
- const named = entries[0];
376
+ const named = entries[0];
377
+ if (request.revision !== undefined && typeof named?.media_type !== 'string') {
333
378
  if (named === undefined)
334
379
  return { kind: 'no-history' };
335
- if (named.unavailable === true) {
336
- return {
337
- kind: 'scoped-refusal',
338
- locator,
339
- scope: 'content',
340
- code: 'retained_history_unavailable',
341
- fields: { path: request.path, revision: request.revision },
342
- retryable: false,
343
- };
344
- }
345
- if (typeof named.file === 'string')
346
- return { kind: 'no-history' };
347
380
  if (typeof named.content !== 'string')
348
- return { kind: 'transport-uncertainty' };
381
+ return unusable();
349
382
  return { kind: 'revision', content: named.content };
350
383
  }
351
384
  if (entries.length === 0)
@@ -356,11 +389,11 @@ export function historyOutcome(status, body, locator, request) {
356
389
  if (typeof entry.revision !== 'string' ||
357
390
  author === null ||
358
391
  typeof entry.created_at !== 'string') {
359
- return { kind: 'transport-uncertainty' };
392
+ return unusable();
360
393
  }
361
- const binaryFile = historyBinary(entry);
394
+ const binaryFile = binaryFileOf(entry);
362
395
  if (binaryFile === null)
363
- return { kind: 'transport-uncertainty' };
396
+ return unusable();
364
397
  revisions.push({
365
398
  revision: entry.revision,
366
399
  author,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-c6296cfbceb56",
3
+ "version": "0.1.0-c63f5d0daa11b",
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,12 +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/mdmodel": "0.1.0-cc9fa0498a7f7",
29
- "@agentshouse/mdruntime": "0.1.0-cde2b99d2fcbc"
27
+ "@agentshouse/mdmodel": "0.1.0-ce7e4efd1b42d",
28
+ "@agentshouse/mdruntime": "0.1.0-c3f16416a4f32"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/agentshouse/core.git",
33
+ "directory": "mdruntime/packages/mdruntime-adapter"
30
34
  }
31
35
  }