@agentshouse/mdruntime-adapter 0.1.0-c38cdd8a6d962 → 0.1.0-c392f202fd8ec

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 (66) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +163 -3
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +121 -219
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +279 -208
  8. package/dist/app-reference.d.ts +2 -0
  9. package/dist/app-reference.d.ts.map +1 -0
  10. package/dist/app-reference.js +2 -0
  11. package/dist/crockford.d.ts +4 -0
  12. package/dist/crockford.d.ts.map +1 -0
  13. package/dist/crockford.js +3 -0
  14. package/dist/discovery.d.ts +16 -15
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +75 -52
  17. package/dist/house-model.d.ts +2983 -0
  18. package/dist/house-model.d.ts.map +1 -0
  19. package/dist/house-model.js +1643 -0
  20. package/dist/index.d.ts +9 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +8 -1
  23. package/dist/model.d.ts +6 -3
  24. package/dist/model.d.ts.map +1 -1
  25. package/dist/model.js +23 -28
  26. package/dist/part.d.ts +14 -0
  27. package/dist/part.d.ts.map +1 -0
  28. package/dist/part.js +90 -0
  29. package/dist/read.d.ts +52 -41
  30. package/dist/read.d.ts.map +1 -1
  31. package/dist/read.js +248 -234
  32. package/dist/refusal.d.ts +3 -9
  33. package/dist/refusal.d.ts.map +1 -1
  34. package/dist/refusal.js +25 -19
  35. package/dist/room-stream.d.ts +19 -0
  36. package/dist/room-stream.d.ts.map +1 -0
  37. package/dist/room-stream.js +57 -0
  38. package/dist/room-types.d.ts +7 -0
  39. package/dist/room-types.d.ts.map +1 -0
  40. package/dist/room-types.js +126 -0
  41. package/dist/site.d.ts +1 -1
  42. package/dist/site.d.ts.map +1 -1
  43. package/dist/site.js +129 -106
  44. package/dist/stream.d.ts +12 -11
  45. package/dist/stream.d.ts.map +1 -1
  46. package/dist/stream.js +174 -145
  47. package/dist/transport.d.ts +79 -23
  48. package/dist/transport.d.ts.map +1 -1
  49. package/dist/transport.js +51 -10
  50. package/dist/upload.d.ts +12 -0
  51. package/dist/upload.d.ts.map +1 -0
  52. package/dist/upload.js +63 -0
  53. package/dist/version.d.ts +1 -0
  54. package/dist/version.d.ts.map +1 -1
  55. package/dist/version.js +1 -1
  56. package/dist/write.d.ts +18 -9
  57. package/dist/write.d.ts.map +1 -1
  58. package/dist/write.js +165 -41
  59. package/package.json +9 -6
  60. package/AGENTS.md +0 -238
  61. package/dist/gather.d.ts +0 -3
  62. package/dist/gather.d.ts.map +0 -1
  63. package/dist/gather.js +0 -40
  64. package/dist/links.d.ts +0 -20
  65. package/dist/links.d.ts.map +0 -1
  66. package/dist/links.js +0 -104
package/dist/transport.js CHANGED
@@ -1,11 +1,52 @@
1
- export const DOOR_DISCOVER = '/door/discover';
2
- export const DOOR_BOOTSTRAP = '/door/bootstrap';
3
- export const DOOR_ENUMERATE = '/door/enumerate';
4
- export const DOOR_BATCH = '/door/batch';
5
- export const DOOR_BATCH_UPLOAD = '/door/batch-upload';
6
- export const DOOR_REVISIONS = '/door/revisions';
7
- export const SITE_DOOR_DISCOVER = '/_house/door/discover';
8
- export const SITE_DOOR_BOOTSTRAP = '/_house/door/bootstrap/';
9
- export const SITE_DOOR_ENUMERATE = '/_house/door/enumerate';
1
+ export const HOUSE_RUNTIME_READS = {
2
+ acts: [
3
+ 'account/push',
4
+ 'agents/read',
5
+ 'apps/features/set',
6
+ 'apps/source/download',
7
+ 'apps/source/top',
8
+ 'batch',
9
+ 'batch-upload',
10
+ 'bootstrap',
11
+ 'discover',
12
+ 'files/attach',
13
+ 'files/finish',
14
+ 'files/get',
15
+ 'revisions',
16
+ 'sites/screenshot/read',
17
+ ],
18
+ frames: [
19
+ 'app-message',
20
+ 'authority_changed',
21
+ 'carried',
22
+ 'caught_up',
23
+ 'commands',
24
+ 'conversation',
25
+ 'conversation_deleted',
26
+ 'conversations',
27
+ 'deliveries',
28
+ 'deployment',
29
+ 'held',
30
+ 'interactions',
31
+ 'link',
32
+ 'message',
33
+ 'opening',
34
+ 'options',
35
+ 'part',
36
+ 'process',
37
+ 'received',
38
+ 'signal',
39
+ 'site',
40
+ 'starting',
41
+ 'tab-icon',
42
+ 'turn',
43
+ ],
44
+ };
45
+ export function houseDoorRoute(act) {
46
+ return `/door/${act}`;
47
+ }
48
+ export function houseSiteRoute(act) {
49
+ return `/_house/door/${act}`;
50
+ }
10
51
  export const SITE_DOOR_SUBMIT = '/_house/door/submit';
11
- export const PRIVATE_LOCATOR = 'private';
52
+ export const SITE_FILES = '/_house/files/';
@@ -0,0 +1,12 @@
1
+ import { type HouseDoorAnswer, type HouseTransport } from './transport.js';
2
+ export type HouseUpload = {
3
+ readonly id: string;
4
+ readonly partBytes: number;
5
+ readonly parts: readonly {
6
+ readonly part: number;
7
+ readonly url: string;
8
+ }[];
9
+ };
10
+ export declare function houseUpload(value: unknown): HouseUpload | null;
11
+ export declare function finishedUpload(transport: HouseTransport, first: HouseUpload, blob: Blob): Promise<HouseDoorAnswer | null>;
12
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAE3F,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC5E,CAAC;AAeF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAQ9D;AA8BD,wBAAsB,cAAc,CAClC,SAAS,EAAE,cAAc,EACzB,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAejC"}
package/dist/upload.js ADDED
@@ -0,0 +1,63 @@
1
+ import { sha256 } from '@agentshouse/mdruntime/digest';
2
+ import { houseDoorRoute } from './transport.js';
3
+ const FINISHING_ROUNDS = 24;
4
+ function record(value) {
5
+ return value !== null && typeof value === 'object' ? value : {};
6
+ }
7
+ function part(value) {
8
+ const { part: number, url } = record(value);
9
+ return Number.isSafeInteger(number) && number > 0 && typeof url === 'string'
10
+ ? { part: number, url }
11
+ : null;
12
+ }
13
+ export function houseUpload(value) {
14
+ const { id, part_bytes: partBytes, parts = [] } = record(value);
15
+ if (typeof id !== 'string' || !Number.isSafeInteger(partBytes) || partBytes <= 0)
16
+ return null;
17
+ if (!Array.isArray(parts))
18
+ return null;
19
+ const named = parts.map(part);
20
+ if (named.some((one) => one === null))
21
+ return null;
22
+ return { id, partBytes: partBytes, parts: named };
23
+ }
24
+ function checksum(hex) {
25
+ let bytes = '';
26
+ for (let at = 0; at < hex.length; at += 2)
27
+ bytes += String.fromCharCode(Number.parseInt(hex.slice(at, at + 2), 16));
28
+ return { 'x-amz-checksum-sha256': btoa(bytes) };
29
+ }
30
+ async function partSha256(blob, partBytes) {
31
+ const parts = [];
32
+ for (let start = 0; start === 0 || start < blob.size; start += partBytes)
33
+ parts.push(await sha256(blob.slice(start, start + partBytes)));
34
+ return parts;
35
+ }
36
+ async function sent(transport, upload, blob, digests) {
37
+ for (const { part: number, url } of upload.parts) {
38
+ const start = (number - 1) * upload.partBytes;
39
+ const slice = blob.slice(start, start + upload.partBytes);
40
+ if ((await transport.put(url, slice, checksum(digests[number - 1]))) !== 200)
41
+ return false;
42
+ }
43
+ return true;
44
+ }
45
+ export async function finishedUpload(transport, first, blob) {
46
+ const digests = await partSha256(blob, first.partBytes);
47
+ let upload = first;
48
+ for (let round = 0; round < FINISHING_ROUNDS; round += 1) {
49
+ if (!(await sent(transport, upload, blob, digests)))
50
+ return null;
51
+ const answer = await transport.door(houseDoorRoute('files/finish'), {
52
+ upload: upload.id,
53
+ part_sha256: digests,
54
+ });
55
+ if (answer.status !== 200)
56
+ return answer;
57
+ const missing = houseUpload(record(answer.body).upload);
58
+ if (missing === null)
59
+ return answer;
60
+ upload = missing;
61
+ }
62
+ return null;
63
+ }
package/dist/version.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare function roomVersion(at: LogPosition): string;
11
11
  export declare function logPosition(version: string): LogPosition | null;
12
12
  export declare function readPosition(held: Readonly<Record<string, unknown>>): LogPosition | null;
13
13
  export declare function presented(authority: string, at: LogPosition): PresentedPosition;
14
+ export declare const DECIMAL: RegExp;
14
15
  export declare function reachedVersion(roomVersion: string, target: string, currentEpoch: string | undefined): boolean;
15
16
  export declare function followsVersion(roomVersion: string, next: string): boolean;
16
17
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAAE,EAAE,WAAW,GAAG,MAAM,CAEnD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAI/D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GA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zE"}
package/dist/version.js CHANGED
@@ -18,7 +18,7 @@ export function readPosition(held) {
18
18
  export function presented(authority, at) {
19
19
  return { authority, position: at.position, log_epoch: at.logEpoch };
20
20
  }
21
- const DECIMAL = /^(?:0|[1-9][0-9]*)$/;
21
+ export const DECIMAL = /^(?:0|[1-9][0-9]*)$/;
22
22
  export function reachedVersion(roomVersion, target, currentEpoch) {
23
23
  if (roomVersion === target)
24
24
  return true;
package/dist/write.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ChangeBatch, HistoryResult, MutationResult, RoomAttachment } from '@agentshouse/mdruntime';
1
+ import { type ChangeBatch, type HistoryResult, type MutationResult } from '@agentshouse/mdruntime';
2
2
  import type { HouseBounds } from './discovery.js';
3
3
  export type HouseOperation = Readonly<Record<string, unknown>>;
4
4
  export type ChangeMapping = {
@@ -10,6 +10,11 @@ export type ChangeMapping = {
10
10
  rule: string;
11
11
  };
12
12
  export declare function houseChanges(batch: ChangeBatch, handle: string): ChangeMapping;
13
+ export declare function houseParts(saved: readonly {
14
+ readonly path: string;
15
+ readonly parts: unknown;
16
+ }[], handle: string): ChangeMapping;
17
+ export declare function houseMove(batch: ChangeBatch, source: string, destination: string): ChangeMapping;
13
18
  export type OperationHead = {
14
19
  readonly operation_id: string;
15
20
  readonly app_ref?: string;
@@ -21,14 +26,17 @@ export declare function deltaBody(changes: readonly HouseOperation[]): string;
21
26
  export declare function deltaBytes(delta: string): number;
22
27
  export declare function uploadable(inline: Readonly<Record<string, unknown>>, bytes: number, bounds: Pick<HouseBounds, 'max_inline_body_bytes' | 'max_upload_bytes'>): boolean;
23
28
  export declare function deltaDigest(delta: string): Promise<string>;
24
- export type SubmittedOutcome = Exclude<MutationResult, {
25
- kind: 'accepted';
26
- }> | (Extract<MutationResult, {
27
- kind: 'accepted';
28
- }> & {
29
- originals: readonly RoomAttachment[];
30
- });
31
- export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string): SubmittedOutcome;
29
+ export type MoveAuthorities = {
30
+ readonly source: {
31
+ readonly authority: string;
32
+ readonly handle: string;
33
+ };
34
+ readonly destination: {
35
+ readonly authority: string;
36
+ readonly handle: string;
37
+ };
38
+ };
39
+ export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string, move?: MoveAuthorities): Generator<number, MutationResult, void>;
32
40
  export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
33
41
  kind: 'unmapped';
34
42
  }>): {
@@ -38,6 +46,7 @@ export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
38
46
  fields: {
39
47
  path: string;
40
48
  };
49
+ retryable: boolean;
41
50
  };
42
51
  export declare function revisionBody(input: {
43
52
  path: string;
@@ -1 +1 @@
1
- {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,EAEb,cAAc,EAEd,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAOlD,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE/D,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAuGrD,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAQ9E;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,wB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,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,CAAC,CA8DzC;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;IAEjF,IAAI,EAAE,UAAU;IAChB,QAAQ;IACR,IAAI;IACJ,MAAM;QAAI,IAAI;;IACd,SAAS;EAEZ;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM1B;AA2BD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,aAAa,CAyDf"}
package/dist/write.js CHANGED
@@ -1,4 +1,5 @@
1
- import { parseOriginals } from './read.js';
1
+ import { departure, partsChanges, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
2
3
  import { sha256Hex, textBytes } from './digest.js';
3
4
  import { nativePath, roomLocalPath } from './map.js';
4
5
  import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
@@ -73,6 +74,25 @@ function operationOf(batch, change, handle) {
73
74
  const operation = created(change, path);
74
75
  return operation === null ? { rule: 'type-missing' } : { operation };
75
76
  }
77
+ if (change.kind === 'binary') {
78
+ const written = {
79
+ op: 'upload',
80
+ path,
81
+ local_id: change.localId,
82
+ bytes: change.byteLength,
83
+ sha256: change.sha256,
84
+ media_type: change.mediaType,
85
+ };
86
+ const from = departure(batch.changes, batch.changes.indexOf(change));
87
+ if (from === change.path && priorAbsence(batch, change.path) !== undefined)
88
+ return { operation: written };
89
+ const replaced = priorExistence(batch, from);
90
+ if (replaced === undefined)
91
+ return { rule: 'precondition-missing' };
92
+ if (!('base' in replaced))
93
+ return { rule: 'presence-base-unrepresentable' };
94
+ return { operation: { ...written, base: replaced.base } };
95
+ }
76
96
  const existence = priorExistence(batch, change.path);
77
97
  if (existence === undefined)
78
98
  return { rule: 'precondition-missing' };
@@ -100,6 +120,27 @@ export function houseChanges(batch, handle) {
100
120
  }
101
121
  return { kind: 'changes', changes };
102
122
  }
123
+ export function houseParts(saved, handle) {
124
+ return houseChanges({ id: '', baseRoomVersion: '', ...partsChanges(saved) }, handle);
125
+ }
126
+ export function houseMove(batch, source, destination) {
127
+ const changes = [];
128
+ for (const { path, to } of batch.between?.moves ?? []) {
129
+ const existence = priorExistence(batch, path);
130
+ if (existence === undefined)
131
+ return { kind: 'unmapped', path, rule: 'precondition-missing' };
132
+ if (!('base' in existence)) {
133
+ return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
134
+ }
135
+ changes.push({
136
+ op: 'rename',
137
+ path: nativePath(path, source),
138
+ to: nativePath(to, destination),
139
+ base: existence.base,
140
+ });
141
+ }
142
+ return { kind: 'changes', changes };
143
+ }
103
144
  export function operationHead(batch) {
104
145
  const writer = batch.writtenBy;
105
146
  return writer === undefined
@@ -109,7 +150,7 @@ export function operationHead(batch) {
109
150
  export function batchPaths(changes) {
110
151
  return [
111
152
  ...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
112
- ].sort();
153
+ ];
113
154
  }
114
155
  export function deltaBody(changes) {
115
156
  return JSON.stringify({ changes });
@@ -124,20 +165,29 @@ export function uploadable(inline, bytes, bounds) {
124
165
  export function deltaDigest(delta) {
125
166
  return sha256Hex(delta);
126
167
  }
127
- function material(value, handle) {
168
+ function* material(value, handle, within = () => true) {
128
169
  if (!Array.isArray(value))
129
170
  return null;
130
171
  const held = [];
131
172
  for (const entry of value) {
173
+ yield ROW_WEIGHT;
132
174
  if (typeof entry !== 'object' || entry === null)
133
175
  return null;
134
176
  const file = entry;
135
177
  if (typeof file.path !== 'string')
136
178
  return null;
179
+ if (!within(file.path))
180
+ continue;
137
181
  if (file.content !== null && typeof file.content !== 'string')
138
182
  return null;
139
183
  if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
140
184
  return null;
185
+ const binary = binaryFileOf(file);
186
+ if (binary === null)
187
+ return null;
188
+ const head = headChange(file);
189
+ if (head === null)
190
+ return null;
141
191
  let path;
142
192
  try {
143
193
  path = roomLocalPath(file.path, handle);
@@ -149,29 +199,84 @@ function material(value, handle) {
149
199
  path,
150
200
  content: file.content,
151
201
  revision: typeof file.revision === 'string' ? file.revision : null,
202
+ ...(binary === undefined ? {} : { binary }),
203
+ ...(head === undefined ? {} : { head }),
152
204
  });
153
205
  }
154
206
  return held;
155
207
  }
156
- function affectedOf(held) {
208
+ function* affectedOf(held) {
157
209
  const affected = {};
158
210
  for (const entry of held) {
159
211
  if (entry.content !== null)
160
212
  affected[entry.path] = entry.content;
213
+ yield ROW_WEIGHT;
161
214
  }
162
215
  return affected;
163
216
  }
164
- 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, ...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 { kind: 'transport-uncertainty' };
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 { kind: 'transport-uncertainty' };
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) {
165
261
  const refusal = doorRefusal(body);
166
262
  if (refusal !== null && refusal.code === 'service_mode_write_halted') {
167
263
  return { kind: 'write-halted' };
168
264
  }
169
- if (refusal !== null && refusal.code === 'expired')
170
- return { kind: 'expired' };
265
+ if (refusal !== null && refusal.code === 'expired') {
266
+ return refusal.fields.restored === true
267
+ ? { kind: 'expired', restored: true }
268
+ : { kind: 'expired' };
269
+ }
171
270
  if (refusal !== null && refusal.code === 'edit_conflict') {
172
271
  const { current, ...fields } = refusal.fields;
173
- const held = material(current, handle) ?? [];
174
- return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };
272
+ const held = (yield* material(current, handle)) ?? [];
273
+ return {
274
+ kind: 'conflicted',
275
+ affected: yield* affectedOf(held),
276
+ code: refusal.code,
277
+ fields,
278
+ retryable: refusal.retryable,
279
+ };
175
280
  }
176
281
  if (refusal !== null && status === 404) {
177
282
  return scopedRefusal(locator, 'undisclosed', refusal);
@@ -181,47 +286,41 @@ export function mutationOutcome(status, body, locator, handle) {
181
286
  if (refusal?.retryable === true &&
182
287
  typeof reset === 'string' &&
183
288
  classified?.kind === 'transport-uncertainty') {
184
- return { kind: 'retryable-refusal', code: refusal.code, fields: refusal.fields, reset };
289
+ return {
290
+ kind: 'retryable-refusal',
291
+ code: refusal.code,
292
+ fields: refusal.fields,
293
+ retryable: true,
294
+ reset,
295
+ };
185
296
  }
186
297
  if (classified !== null && classified.kind !== 'scoped-refusal')
187
298
  return classified;
188
- if (classified !== null && status === 403)
299
+ if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
189
300
  return classified;
301
+ }
190
302
  if (refusal !== null && status >= 400) {
191
- return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
303
+ return {
304
+ kind: 'rejected',
305
+ affected: {},
306
+ code: refusal.code,
307
+ fields: refusal.fields,
308
+ retryable: refusal.retryable,
309
+ };
192
310
  }
193
311
  if (status !== 200 || typeof body !== 'object' || body === null) {
194
312
  return { kind: 'transport-uncertainty' };
195
313
  }
196
314
  const held = body;
315
+ if (move !== undefined)
316
+ return yield* movedOutcome(held, move);
197
317
  const at = readPosition(held);
198
318
  if (at === null)
199
319
  return { kind: 'transport-uncertainty' };
200
- const contents = material(held.contents, handle);
320
+ const contents = yield* material(held.contents, handle);
201
321
  if (contents === null)
202
322
  return { kind: 'transport-uncertainty' };
203
- const originals = parseOriginals(held.originals);
204
- if (originals === null)
205
- return { kind: 'transport-uncertainty' };
206
- const documents = {};
207
- const revisions = {};
208
- const removals = [];
209
- for (const entry of contents) {
210
- if (entry.content === null || entry.revision === null) {
211
- removals.push(entry.path);
212
- continue;
213
- }
214
- documents[entry.path] = entry.content;
215
- revisions[entry.path] = entry.revision;
216
- }
217
- return {
218
- kind: 'accepted',
219
- roomVersion: roomVersion(at),
220
- documents,
221
- revisions,
222
- removals: removals.sort(),
223
- originals,
224
- };
323
+ return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
225
324
  }
226
325
  export function rejectedMapping(mapping) {
227
326
  return {
@@ -229,6 +328,7 @@ export function rejectedMapping(mapping) {
229
328
  affected: {},
230
329
  code: mapping.rule,
231
330
  fields: { path: mapping.path },
331
+ retryable: false,
232
332
  };
233
333
  }
234
334
  export function revisionBody(input) {
@@ -241,12 +341,24 @@ export function revisionBody(input) {
241
341
  function revisionAuthor(entry) {
242
342
  const user = entry.author_user;
243
343
  const site = entry.author_site;
244
- const name = entry.author_site_name;
245
- if (typeof user === 'string' && site === undefined && name === undefined) {
344
+ const siteName = entry.author_site_name;
345
+ const inbox = entry.author_inbox;
346
+ const inboxName = entry.author_inbox_name;
347
+ const app = entry.author_app;
348
+ const appName = entry.author_app_name;
349
+ const named = [site, siteName, inbox, inboxName, app, appName].filter((held) => held !== undefined);
350
+ if (typeof user === 'string' && named.length === 0)
246
351
  return { kind: 'user', id: user };
352
+ if (user !== null || named.length !== 2)
353
+ return null;
354
+ if (typeof site === 'string' && typeof siteName === 'string') {
355
+ return { kind: 'site', id: site, name: siteName };
356
+ }
357
+ if (typeof inbox === 'string' && typeof inboxName === 'string') {
358
+ return { kind: 'inbox', id: inbox, name: inboxName };
247
359
  }
248
- if (user === null && typeof site === 'string' && typeof name === 'string') {
249
- return { kind: 'site', id: site, name };
360
+ if (typeof app === 'string' && typeof appName === 'string') {
361
+ return { kind: 'app', id: app, name: appName };
250
362
  }
251
363
  return null;
252
364
  }
@@ -274,11 +386,14 @@ export function historyOutcome(status, body, locator, request) {
274
386
  return {
275
387
  kind: 'scoped-refusal',
276
388
  locator,
277
- scope: 'content',
389
+ scope: 'operation',
278
390
  code: 'retained_history_unavailable',
279
391
  fields: { path: request.path, revision: request.revision },
392
+ retryable: false,
280
393
  };
281
394
  }
395
+ if (typeof named.media_type === 'string')
396
+ return { kind: 'no-history' };
282
397
  if (typeof named.content !== 'string')
283
398
  return { kind: 'transport-uncertainty' };
284
399
  return { kind: 'revision', content: named.content };
@@ -293,12 +408,21 @@ export function historyOutcome(status, body, locator, request) {
293
408
  typeof entry.created_at !== 'string') {
294
409
  return { kind: 'transport-uncertainty' };
295
410
  }
296
- revisions.push({ revision: entry.revision, author, time: entry.created_at });
411
+ const binaryFile = binaryFileOf(entry);
412
+ if (binaryFile === null)
413
+ return { kind: 'transport-uncertainty' };
414
+ revisions.push({
415
+ revision: entry.revision,
416
+ author,
417
+ time: entry.created_at,
418
+ ...(binaryFile === undefined ? {} : { binaryFile }),
419
+ });
297
420
  }
298
421
  const next = held.next_before;
299
422
  return {
300
423
  kind: 'history',
301
424
  revisions,
302
425
  ...(typeof next === 'number' ? { pageToken: String(next) } : {}),
426
+ ...(held.deleted === true ? { deleted: true } : {}),
303
427
  };
304
428
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-c38cdd8a6d962",
3
+ "version": "0.1.0-c392f202fd8ec",
4
4
  "description": "Agents House Adapter for the MD Runtime",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,23 +9,26 @@
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
  ".": {
16
16
  "types": "./dist/index.d.ts",
17
- "import": "./dist/index.js"
17
+ "default": "./dist/index.js"
18
18
  },
19
19
  "./package.json": "./package.json"
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-c0bdbbc92d020",
29
- "@agentshouse/mdruntime": "0.1.0-c2647c1a232dd"
27
+ "@agentshouse/mdruntime": "0.1.0-c020867f52b29"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/agentshouse/core.git",
32
+ "directory": "mdruntime/packages/mdruntime-adapter"
30
33
  }
31
34
  }