@agentshouse/mdruntime-adapter 0.1.0-cefa8b4106453 → 0.1.0-cf03cdc5ecb06

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 +1 -1
  2. package/dist/actions.d.ts.map +1 -1
  3. package/dist/actions.js +34 -11
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +124 -116
  6. package/dist/authored-path.d.ts +54 -3
  7. package/dist/authored-path.d.ts.map +1 -1
  8. package/dist/authored-path.js +142 -11
  9. package/dist/chunks.d.ts +2 -3
  10. package/dist/chunks.d.ts.map +1 -1
  11. package/dist/chunks.js +72 -38
  12. package/dist/discovery.d.ts +25 -5
  13. package/dist/discovery.d.ts.map +1 -1
  14. package/dist/discovery.js +169 -21
  15. package/dist/history.d.ts +1 -6
  16. package/dist/history.d.ts.map +1 -1
  17. package/dist/history.js +21 -28
  18. package/dist/index.d.ts +7 -9
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +7 -9
  21. package/dist/model.d.ts +5 -5
  22. package/dist/model.d.ts.map +1 -1
  23. package/dist/model.js +17 -27
  24. package/dist/read.d.ts +11 -24
  25. package/dist/read.d.ts.map +1 -1
  26. package/dist/read.js +74 -47
  27. package/dist/refusal.d.ts +5 -1
  28. package/dist/refusal.d.ts.map +1 -1
  29. package/dist/refusal.js +23 -6
  30. package/dist/renamed.d.ts +10 -0
  31. package/dist/renamed.d.ts.map +1 -0
  32. package/dist/renamed.js +20 -0
  33. package/dist/room-query.d.ts +4 -0
  34. package/dist/room-query.d.ts.map +1 -0
  35. package/dist/room-query.js +63 -0
  36. package/dist/search.d.ts.map +1 -1
  37. package/dist/search.js +4 -4
  38. package/dist/session-content/check.d.ts +4 -2
  39. package/dist/session-content/index.d.ts +3 -4
  40. package/dist/session-content/parts.d.ts +16 -88
  41. package/dist/session-content/state.d.ts +21 -23
  42. package/dist/session-content/turn.d.ts +82 -258
  43. package/dist/site.d.ts.map +1 -1
  44. package/dist/site.js +56 -22
  45. package/dist/space-schema.d.ts.map +1 -1
  46. package/dist/space-schema.js +1 -8
  47. package/dist/stream.d.ts +4 -4
  48. package/dist/stream.d.ts.map +1 -1
  49. package/dist/stream.js +151 -82
  50. package/dist/transport.d.ts +70 -18
  51. package/dist/transport.d.ts.map +1 -1
  52. package/dist/transport.js +47 -9
  53. package/dist/uncertain.d.ts +5 -0
  54. package/dist/uncertain.d.ts.map +1 -0
  55. package/dist/uncertain.js +11 -0
  56. package/dist/upload.d.ts +7 -1
  57. package/dist/upload.d.ts.map +1 -1
  58. package/dist/upload.js +49 -6
  59. package/dist/write.d.ts +3 -8
  60. package/dist/write.d.ts.map +1 -1
  61. package/dist/write.js +88 -106
  62. package/package.json +4 -3
  63. package/dist/app-reference.d.ts +0 -1
  64. package/dist/app-reference.d.ts.map +0 -1
  65. package/dist/app-reference.js +0 -2
  66. package/dist/crockford.d.ts +0 -3
  67. package/dist/crockford.d.ts.map +0 -1
  68. package/dist/crockford.js +0 -3
  69. package/dist/house-model.d.ts +0 -830
  70. package/dist/house-model.d.ts.map +0 -1
  71. package/dist/house-model.js +0 -465
  72. package/dist/room-types.d.ts +0 -4
  73. package/dist/room-types.d.ts.map +0 -1
  74. package/dist/room-types.js +0 -135
  75. package/dist/session-content/bounds.d.ts +0 -7
package/dist/write.js CHANGED
@@ -1,17 +1,14 @@
1
- import { departure, partsChanges, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
- import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
1
+ import { departure, isPart, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { answered, answering, attachmentOf, 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, resetOf, scopedRefusal } from './refusal.js';
5
+ import { answeredFailure, classifyDoor, doorRefusal, resetOf, scopedRefusal } from './refusal.js';
6
6
  import { readPosition, roomVersion } from './version.js';
7
- function priorField(batch, path, name) {
8
- return batch.preconditions.find((precondition) => precondition.kind === 'field' && precondition.path === path && precondition.name === name);
9
- }
10
- function priorSection(batch, path, name) {
11
- return batch.preconditions.find((precondition) => precondition.kind === 'section' && precondition.path === path && precondition.name === name);
12
- }
13
- function priorPreamble(batch, path) {
14
- return batch.preconditions.find((precondition) => precondition.kind === 'preamble' && precondition.path === path);
7
+ import { unusable } from './uncertain.js';
8
+ function priorPart(batch, change) {
9
+ return batch.preconditions.find((held) => held.kind === change.kind &&
10
+ held.path === change.path &&
11
+ (change.kind === 'preamble' || ('name' in held && held.name === change.name)));
15
12
  }
16
13
  function priorAbsence(batch, path) {
17
14
  return batch.preconditions.find((precondition) => precondition.kind === 'absent' && precondition.path === path);
@@ -22,60 +19,30 @@ function priorExistence(batch, path) {
22
19
  return undefined;
23
20
  return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };
24
21
  }
25
- function created(change, path) {
26
- if ('content' in change)
27
- return { op: 'create', path, content: change.content };
28
- const { type, ...fields } = change.fields;
29
- if (typeof type !== 'string' || type.length === 0)
22
+ function textOf(batch, change, path, document) {
23
+ if (isPart(change) && priorPart(batch, change) === undefined)
24
+ return { rule: 'precondition-missing' };
25
+ if (change.kind === 'create' && priorAbsence(batch, change.path) === undefined)
26
+ return { rule: 'precondition-missing' };
27
+ if (change.kind === 'replace' && priorExistence(batch, change.path) === undefined)
28
+ return { rule: 'precondition-missing' };
29
+ if (document === null || document === undefined)
30
30
  return null;
31
- return { op: 'create_typed', path, type, fields, sections: change.sections };
31
+ if (document.stale)
32
+ return { rule: 'precondition-stale' };
33
+ if (document.created)
34
+ return { operation: { op: 'write', path, content: document.content } };
35
+ if (document.base === null)
36
+ return { rule: 'presence-base-unrepresentable' };
37
+ return { operation: { op: 'write', path, base: document.base, content: document.content } };
32
38
  }
33
- function operationOf(batch, change, handle) {
39
+ function operationOf(batch, index, handle, written) {
40
+ const change = batch.changes[index];
34
41
  const path = nativePath(change.path, handle);
35
- if (change.kind === 'field') {
36
- const prior = priorField(batch, change.path, change.name);
37
- if (prior === undefined)
38
- return { rule: 'precondition-missing' };
39
- return {
40
- operation: {
41
- op: 'set_field',
42
- path,
43
- field: change.name,
44
- value: change.value,
45
- ...(prior.value === undefined ? {} : { base: prior.value }),
46
- },
47
- };
48
- }
49
- if (change.kind === 'section') {
50
- const prior = priorSection(batch, change.path, change.name);
51
- if (prior === undefined)
52
- return { rule: 'precondition-missing' };
53
- return {
54
- operation: {
55
- op: 'replace_section',
56
- path,
57
- section: change.name,
58
- base: prior.value,
59
- content: change.value,
60
- },
61
- };
62
- }
63
- if (change.kind === 'preamble') {
64
- const prior = priorPreamble(batch, change.path);
65
- if (prior === undefined)
66
- return { rule: 'precondition-missing' };
67
- return {
68
- operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },
69
- };
70
- }
71
- if (change.kind === 'create') {
72
- if (priorAbsence(batch, change.path) === undefined)
73
- return { rule: 'precondition-missing' };
74
- const operation = created(change, path);
75
- return operation === null ? { rule: 'type-missing' } : { operation };
76
- }
42
+ if (isPart(change) || change.kind === 'create' || change.kind === 'replace')
43
+ return textOf(batch, change, path, written[index]);
77
44
  if (change.kind === 'binary') {
78
- const written = {
45
+ const uploaded = {
79
46
  op: 'upload',
80
47
  path,
81
48
  local_id: change.localId,
@@ -83,45 +50,61 @@ function operationOf(batch, change, handle) {
83
50
  sha256: change.sha256,
84
51
  media_type: change.mediaType,
85
52
  };
86
- const from = departure(batch.changes, batch.changes.indexOf(change));
53
+ const from = departure(batch.changes, index);
87
54
  if (from === change.path && priorAbsence(batch, change.path) !== undefined)
88
- return { operation: written };
55
+ return { operation: uploaded };
89
56
  const replaced = priorExistence(batch, from);
90
57
  if (replaced === undefined)
91
58
  return { rule: 'precondition-missing' };
92
59
  if (!('base' in replaced))
93
60
  return { rule: 'presence-base-unrepresentable' };
94
- return { operation: { ...written, base: replaced.base } };
61
+ return { operation: { ...uploaded, base: replaced.base } };
95
62
  }
96
63
  const existence = priorExistence(batch, change.path);
97
64
  if (existence === undefined)
98
65
  return { rule: 'precondition-missing' };
99
66
  if (!('base' in existence))
100
67
  return { rule: 'presence-base-unrepresentable' };
101
- if (change.kind === 'replace') {
102
- return { operation: { op: 'replace', path, base: existence.base, content: change.content } };
103
- }
104
68
  if (change.kind === 'move') {
105
69
  if (priorAbsence(batch, change.to) === undefined)
106
70
  return { rule: 'precondition-missing' };
107
71
  return {
108
- operation: { op: 'rename', path, to: nativePath(change.to, handle), base: existence.base },
72
+ operation: { op: 'move', path, to: nativePath(change.to, handle), base: existence.base },
109
73
  };
110
74
  }
111
- return { operation: { op: 'remove', path, base: existence.base } };
75
+ return { operation: { op: 'delete', path, base: existence.base } };
112
76
  }
113
- export function houseChanges(batch, handle) {
77
+ export function houseChanges(batch, handle, written) {
114
78
  const changes = [];
115
- for (const change of batch.changes) {
116
- const mapped = operationOf(batch, change, handle);
79
+ const moves = new Map();
80
+ const before = new Map();
81
+ for (const [index, change] of batch.changes.entries()) {
82
+ const mapped = operationOf(batch, index, handle, written);
83
+ if (mapped === null)
84
+ continue;
117
85
  if ('rule' in mapped)
118
86
  return { kind: 'unmapped', path: change.path, rule: mapped.rule };
119
- changes.push(mapped.operation);
87
+ const { operation } = mapped;
88
+ const from = departure(batch.changes, index);
89
+ if (change.kind === 'move' && !moves.has(from))
90
+ moves.set(from, changes.length);
91
+ const moved = moves.get(from);
92
+ if (change.kind !== 'move' &&
93
+ moved !== undefined &&
94
+ operation.op === 'write' &&
95
+ 'base' in operation) {
96
+ before.set(moved, { ...operation, path: nativePath(from, handle) });
97
+ continue;
98
+ }
99
+ changes.push(operation);
120
100
  }
121
- return { kind: 'changes', changes };
122
- }
123
- export function houseParts(saved, handle) {
124
- return houseChanges({ id: '', baseRoomVersion: '', ...partsChanges(saved) }, handle);
101
+ return {
102
+ kind: 'changes',
103
+ changes: changes.flatMap((operation, at) => {
104
+ const written = before.get(at);
105
+ return written === undefined ? [operation] : [written, operation];
106
+ }),
107
+ };
125
108
  }
126
109
  export function houseMove(batch, source, destination) {
127
110
  const changes = [];
@@ -133,7 +116,7 @@ export function houseMove(batch, source, destination) {
133
116
  return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
134
117
  }
135
118
  changes.push({
136
- op: 'rename',
119
+ op: 'move',
137
120
  path: nativePath(path, source),
138
121
  to: nativePath(to, destination),
139
122
  base: existence.base,
@@ -141,14 +124,14 @@ export function houseMove(batch, source, destination) {
141
124
  }
142
125
  return { kind: 'changes', changes };
143
126
  }
144
- export function operationHead(batch, room) {
127
+ export function operationHead(batch) {
145
128
  const writer = batch.writtenBy;
146
- const head = { operation_id: batch.id, room_ref: room };
129
+ const head = { operation_id: batch.id };
147
130
  return writer === undefined ? head : { ...head, app_ref: writer.app, release: writer.release };
148
131
  }
149
132
  export function batchPaths(changes) {
150
133
  return [
151
- ...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
134
+ ...new Set(changes.flatMap((change) => change.op === 'move' ? [String(change.path), String(change.to)] : [String(change.path)])),
152
135
  ];
153
136
  }
154
137
  export function deltaBody(changes) {
@@ -181,7 +164,7 @@ function* material(value, handle, within = () => true) {
181
164
  return null;
182
165
  if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
183
166
  return null;
184
- const binary = binaryFileOf(file);
167
+ const binary = attachmentOf(file);
185
168
  if (binary === null)
186
169
  return null;
187
170
  const head = headChange(file);
@@ -224,14 +207,14 @@ function* acceptedOf(at, contents) {
224
207
  if (entry.content !== null)
225
208
  answer.documents.set(entry.path, entry.content);
226
209
  if (entry.binary !== undefined)
227
- answer.binaryFiles.set(entry.path, entry.binary);
210
+ answer.attachments.set(entry.path, entry.binary);
228
211
  revised(answer, entry.path, entry.revision);
229
212
  if (entry.head !== undefined)
230
213
  answer.changes.set(entry.path, entry.head);
231
214
  }
232
- const unbinaried = answer.binaryFiles.size === 0;
233
- const { binaryFiles, facts: _facts, ...room } = yield* answered(answer);
234
- return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { binaryFiles }) };
215
+ const unbinaried = answer.attachments.size === 0;
216
+ const { attachments, facts: _facts, ...room } = yield* answered(answer);
217
+ return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { attachments }) };
235
218
  }
236
219
  function* movedOutcome(held, move) {
237
220
  const authorities = Array.isArray(held.authorities) ? held.authorities : [];
@@ -244,12 +227,12 @@ function* movedOutcome(held, move) {
244
227
  const left = at(move.source.authority);
245
228
  const arrived = at(move.destination.authority);
246
229
  if (left === null || arrived === null)
247
- return { kind: 'transport-uncertainty' };
230
+ return unusable();
248
231
  const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
249
232
  const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
250
233
  const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
251
234
  if (leaving === null || arriving === null)
252
- return { kind: 'transport-uncertainty' };
235
+ return unusable();
253
236
  return {
254
237
  kind: 'accepted',
255
238
  ...(yield* acceptedOf(left, leaving)),
@@ -300,18 +283,19 @@ export function* mutationOutcome(status, body, locator, handle, move) {
300
283
  retryable: refusal.retryable,
301
284
  };
302
285
  }
303
- if (status !== 200 || typeof body !== 'object' || body === null) {
304
- return { kind: 'transport-uncertainty' };
305
- }
286
+ if (status !== 200)
287
+ return answeredFailure(status, body);
288
+ if (typeof body !== 'object' || body === null)
289
+ return unusable();
306
290
  const held = body;
307
291
  if (move !== undefined)
308
292
  return yield* movedOutcome(held, move);
309
293
  const at = readPosition(held);
310
294
  if (at === null)
311
- return { kind: 'transport-uncertainty' };
295
+ return unusable();
312
296
  const contents = yield* material(held.contents, handle);
313
297
  if (contents === null)
314
- return { kind: 'transport-uncertainty' };
298
+ return unusable();
315
299
  return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
316
300
  }
317
301
  export function rejectedMapping(mapping) {
@@ -360,25 +344,23 @@ export function historyOutcome(status, body, locator, request) {
360
344
  if (classified !== null)
361
345
  return classified;
362
346
  if (status !== 200 || typeof body !== 'object' || body === null) {
363
- return { kind: 'transport-uncertainty' };
347
+ return unusable();
364
348
  }
365
349
  const held = body;
366
350
  if (!Array.isArray(held.revisions))
367
- return { kind: 'transport-uncertainty' };
351
+ return unusable();
368
352
  const entries = [];
369
353
  for (const entry of held.revisions) {
370
354
  if (typeof entry !== 'object' || entry === null)
371
- return { kind: 'transport-uncertainty' };
355
+ return unusable();
372
356
  entries.push(entry);
373
357
  }
374
- if (request.revision !== undefined) {
375
- const named = entries[0];
358
+ const named = entries[0];
359
+ if (request.revision !== undefined && typeof named?.media_type !== 'string') {
376
360
  if (named === undefined)
377
361
  return { kind: 'no-history' };
378
- if (typeof named.media_type === 'string')
379
- return { kind: 'no-history' };
380
362
  if (typeof named.content !== 'string')
381
- return { kind: 'transport-uncertainty' };
363
+ return unusable();
382
364
  return { kind: 'revision', content: named.content };
383
365
  }
384
366
  if (entries.length === 0)
@@ -389,16 +371,16 @@ export function historyOutcome(status, body, locator, request) {
389
371
  if (typeof entry.revision !== 'string' ||
390
372
  author === null ||
391
373
  typeof entry.created_at !== 'string') {
392
- return { kind: 'transport-uncertainty' };
374
+ return unusable();
393
375
  }
394
- const binaryFile = binaryFileOf(entry);
395
- if (binaryFile === null)
396
- return { kind: 'transport-uncertainty' };
376
+ const attachment = attachmentOf(entry);
377
+ if (attachment === null)
378
+ return unusable();
397
379
  revisions.push({
398
380
  revision: entry.revision,
399
381
  author,
400
382
  time: entry.created_at,
401
- ...(binaryFile === undefined ? {} : { binaryFile }),
383
+ ...(attachment === undefined ? {} : { attachment }),
402
384
  });
403
385
  }
404
386
  const next = held.next_before;
package/package.json CHANGED
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-cefa8b4106453",
4
3
  "description": "Agents House Adapter for the MD Runtime",
5
4
  "license": "MIT",
6
5
  "type": "module",
@@ -24,11 +23,13 @@
24
23
  "LICENSE"
25
24
  ],
26
25
  "dependencies": {
27
- "@agentshouse/mdruntime": "0.1.0-c091c0855b688"
26
+ "@agentshouse/mdmodel": "0.1.0-c4c6dbb0dc160",
27
+ "@agentshouse/mdruntime": "0.1.0-c06baa340f68a"
28
28
  },
29
29
  "repository": {
30
30
  "type": "git",
31
31
  "url": "git+https://github.com/agentshouse/core.git",
32
32
  "directory": "mdruntime/packages/mdruntime-adapter"
33
- }
33
+ },
34
+ "version": "0.1.0-cf03cdc5ecb06"
34
35
  }
@@ -1 +0,0 @@
1
- export declare const APP_REFERENCE_PATTERN: RegExp;
@@ -1 +0,0 @@
1
- {"version":3,"file":"app-reference.d.ts","sourceRoot":"","sources":["../src/app-reference.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,QAEjC,CAAC"}
@@ -1,2 +0,0 @@
1
- import { CROCKFORD_CHARACTER } from './crockford.js';
2
- export const APP_REFERENCE_PATTERN = new RegExp(`^a_(${CROCKFORD_CHARACTER}+)\\.(${CROCKFORD_CHARACTER})$`);
@@ -1,3 +0,0 @@
1
- export declare const CROCKFORD_ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
2
- export declare const CROCKFORD_CHARACTER = "[0123456789abcdefghjkmnpqrstvwxyz]";
3
- export declare const CROCKFORD_LEADING_CHARACTER: string;
@@ -1 +0,0 @@
1
- {"version":3,"file":"crockford.d.ts","sourceRoot":"","sources":["../src/crockford.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAErE,eAAO,MAAM,mBAAmB,uCAA4B,CAAC;AAE7D,eAAO,MAAM,2BAA2B,QAAqC,CAAC"}
package/dist/crockford.js DELETED
@@ -1,3 +0,0 @@
1
- export const CROCKFORD_ALPHABET = '0123456789abcdefghjkmnpqrstvwxyz';
2
- export const CROCKFORD_CHARACTER = `[${CROCKFORD_ALPHABET}]`;
3
- export const CROCKFORD_LEADING_CHARACTER = `[${CROCKFORD_ALPHABET.slice(1)}]`;