@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c506c7d6e6199

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 (61) hide show
  1. package/AGENTS.md +156 -27
  2. package/README.md +32 -0
  3. package/dist/actions.d.ts +4 -12
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +239 -332
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +271 -197
  8. package/dist/digest.js +1 -5
  9. package/dist/discovery.d.ts +22 -26
  10. package/dist/discovery.d.ts.map +1 -1
  11. package/dist/discovery.js +154 -223
  12. package/dist/gather.d.ts +3 -0
  13. package/dist/gather.d.ts.map +1 -0
  14. package/dist/gather.js +40 -0
  15. package/dist/index.d.ts +1 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +0 -3
  18. package/dist/links.d.ts +12 -0
  19. package/dist/links.d.ts.map +1 -0
  20. package/dist/links.js +66 -0
  21. package/dist/map.d.ts +2 -2
  22. package/dist/map.d.ts.map +1 -1
  23. package/dist/map.js +6 -7
  24. package/dist/model.d.ts +2 -2
  25. package/dist/model.d.ts.map +1 -1
  26. package/dist/model.js +21 -39
  27. package/dist/read.d.ts +31 -26
  28. package/dist/read.d.ts.map +1 -1
  29. package/dist/read.js +208 -199
  30. package/dist/refusal.d.ts +3 -1
  31. package/dist/refusal.d.ts.map +1 -1
  32. package/dist/refusal.js +27 -62
  33. package/dist/site.d.ts.map +1 -1
  34. package/dist/site.js +110 -124
  35. package/dist/stream.d.ts +11 -5
  36. package/dist/stream.d.ts.map +1 -1
  37. package/dist/stream.js +209 -213
  38. package/dist/transport.d.ts +45 -28
  39. package/dist/transport.d.ts.map +1 -1
  40. package/dist/transport.js +2 -3
  41. package/dist/version.d.ts +1 -0
  42. package/dist/version.d.ts.map +1 -1
  43. package/dist/version.js +23 -18
  44. package/dist/write.d.ts +5 -7
  45. package/dist/write.d.ts.map +1 -1
  46. package/dist/write.js +127 -215
  47. package/package.json +4 -12
  48. package/dist/actions.js.map +0 -1
  49. package/dist/adapter.js.map +0 -1
  50. package/dist/digest.js.map +0 -1
  51. package/dist/discovery.js.map +0 -1
  52. package/dist/index.js.map +0 -1
  53. package/dist/map.js.map +0 -1
  54. package/dist/model.js.map +0 -1
  55. package/dist/read.js.map +0 -1
  56. package/dist/refusal.js.map +0 -1
  57. package/dist/site.js.map +0 -1
  58. package/dist/stream.js.map +0 -1
  59. package/dist/transport.js.map +0 -1
  60. package/dist/version.js.map +0 -1
  61. package/dist/write.js.map +0 -1
package/dist/version.d.ts CHANGED
@@ -11,4 +11,5 @@ 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 function reachedVersion(roomVersion: string, target: string, currentEpoch: string | undefined): boolean;
14
15
  //# 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,GAAG,WAAW,GAAG,IAAI,CAKxF;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,iBAAiB,CAE/E"}
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,GAAG,WAAW,GAAG,IAAI,CAKxF;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,iBAAiB,CAE/E;AAID,wBAAgB,cAAc,CAC5B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,OAAO,CAQT"}
package/dist/version.js CHANGED
@@ -3,27 +3,32 @@ export function roomVersion(at) {
3
3
  }
4
4
  export function logPosition(version) {
5
5
  const split = version.lastIndexOf(':');
6
- if (split < 1 || split === version.length - 1) return null;
7
- return {
8
- logEpoch: version.slice(0, split),
9
- position: version.slice(split + 1)
10
- };
6
+ if (split < 1 || split === version.length - 1)
7
+ return null;
8
+ return { logEpoch: version.slice(0, split), position: version.slice(split + 1) };
11
9
  }
12
10
  export function readPosition(held) {
13
11
  const { position, log_epoch: logEpoch } = held;
14
- if (typeof position !== 'string' || position.length === 0) return null;
15
- if (typeof logEpoch !== 'string' || logEpoch.length === 0) return null;
16
- return {
17
- position,
18
- logEpoch
19
- };
12
+ if (typeof position !== 'string' || position.length === 0)
13
+ return null;
14
+ if (typeof logEpoch !== 'string' || logEpoch.length === 0)
15
+ return null;
16
+ return { position, logEpoch };
20
17
  }
21
18
  export function presented(authority, at) {
22
- return {
23
- authority,
24
- position: at.position,
25
- log_epoch: at.logEpoch
26
- };
19
+ return { authority, position: at.position, log_epoch: at.logEpoch };
20
+ }
21
+ const DECIMAL = /^(?:0|[1-9][0-9]*)$/;
22
+ export function reachedVersion(roomVersion, target, currentEpoch) {
23
+ if (roomVersion === target)
24
+ return true;
25
+ const held = logPosition(roomVersion);
26
+ const wanted = logPosition(target);
27
+ if (held === null || wanted === null)
28
+ return false;
29
+ if (!DECIMAL.test(held.position) || !DECIMAL.test(wanted.position))
30
+ return false;
31
+ if (held.logEpoch === wanted.logEpoch)
32
+ return BigInt(held.position) >= BigInt(wanted.position);
33
+ return held.logEpoch === currentEpoch;
27
34
  }
28
-
29
- //# sourceMappingURL=version.js.map
package/dist/write.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import type { ChangeBatch, HistoryResult, MutationResult } from '@agentshouse/mdruntime';
2
- export declare const INLINE_BODY_LIMIT_BYTES: number;
3
- export declare const UPLOAD_LINE_BYTES = 37;
4
- export declare const UPLOAD_BYTES_MAX: number;
2
+ import type { HouseBounds } from './discovery.js';
5
3
  export type HouseOperation = Readonly<Record<string, unknown>>;
6
4
  export type ChangeMapping = {
7
5
  kind: 'changes';
@@ -11,7 +9,7 @@ export type ChangeMapping = {
11
9
  path: string;
12
10
  rule: string;
13
11
  };
14
- export declare function houseChanges(batch: ChangeBatch, handle: string | undefined): ChangeMapping;
12
+ export declare function houseChanges(batch: ChangeBatch, handle: string): ChangeMapping;
15
13
  export type OperationHead = {
16
14
  readonly operation_id: string;
17
15
  readonly app_ref?: string;
@@ -21,9 +19,9 @@ export declare function operationHead(batch: ChangeBatch): OperationHead;
21
19
  export declare function batchPaths(changes: readonly HouseOperation[]): readonly string[];
22
20
  export declare function deltaBody(changes: readonly HouseOperation[]): string;
23
21
  export declare function deltaBytes(delta: string): number;
24
- export declare function uploadable(bytes: number): boolean;
22
+ export declare function uploadable(inline: Readonly<Record<string, unknown>>, bytes: number, bounds: Pick<HouseBounds, 'max_inline_body_bytes' | 'max_upload_bytes'>): boolean;
25
23
  export declare function deltaDigest(delta: string): Promise<string>;
26
- export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string | undefined): MutationResult;
24
+ export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string): MutationResult;
27
25
  export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
28
26
  kind: 'unmapped';
29
27
  }>): {
@@ -36,7 +34,7 @@ export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
36
34
  };
37
35
  export declare function revisionBody(input: {
38
36
  path: string;
39
- handle: string | undefined;
37
+ handle: string;
40
38
  revision?: string;
41
39
  pageToken?: string;
42
40
  }): Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EACX,aAAa,EAEb,cAAc,EAEf,MAAM,wBAAwB,CAAC;AAMhC,eAAO,MAAM,uBAAuB,QAAkB,CAAC;AAEvD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,gBAAgB,QAAuC,CAAC;AAErE,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;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from './map.js';
3
3
  import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
4
4
  import { readPosition, roomVersion } from './version.js';
5
- export const INLINE_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
6
- export const UPLOAD_LINE_BYTES = 37;
7
- export const UPLOAD_BYTES_MAX = 32 * 1024 * 1024 - UPLOAD_LINE_BYTES;
8
5
  function priorField(batch, path, name) {
9
- return batch.preconditions.find((precondition)=>precondition.kind === 'field' && precondition.path === path && precondition.name === name);
6
+ return batch.preconditions.find((precondition) => precondition.kind === 'field' && precondition.path === path && precondition.name === name);
10
7
  }
11
8
  function priorSection(batch, path, name) {
12
- return batch.preconditions.find((precondition)=>precondition.kind === 'section' && precondition.path === path && precondition.name === name);
9
+ return batch.preconditions.find((precondition) => precondition.kind === 'section' && precondition.path === path && precondition.name === name);
13
10
  }
14
11
  function priorPreamble(batch, path) {
15
- return batch.preconditions.find((precondition)=>precondition.kind === 'preamble' && precondition.path === path);
12
+ return batch.preconditions.find((precondition) => precondition.kind === 'preamble' && precondition.path === path);
16
13
  }
17
14
  function priorAbsence(batch, path) {
18
- return batch.preconditions.find((precondition)=>precondition.kind === 'absent' && precondition.path === path);
15
+ return batch.preconditions.find((precondition) => precondition.kind === 'absent' && precondition.path === path);
19
16
  }
20
17
  function priorExistence(batch, path) {
21
- const precondition = batch.preconditions.find((held)=>held.path === path && (held.kind === 'revision' || held.kind === 'present'));
22
- if (precondition === undefined) return undefined;
23
- return precondition.kind === 'revision' ? {
24
- base: precondition.revision
25
- } : {
26
- kind: 'presence'
27
- };
18
+ const precondition = batch.preconditions.find((held) => held.path === path && (held.kind === 'revision' || held.kind === 'present'));
19
+ if (precondition === undefined)
20
+ return undefined;
21
+ return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };
28
22
  }
29
- function typedCreate(change, path) {
23
+ function created(change, path) {
24
+ if ('content' in change)
25
+ return { op: 'create', path, content: change.content };
30
26
  const { type, ...fields } = change.fields;
31
- if (typeof type !== 'string' || type.length === 0) return null;
32
- return {
33
- op: 'create_typed',
34
- path,
35
- type,
36
- fields,
37
- sections: change.sections
38
- };
27
+ if (typeof type !== 'string' || type.length === 0)
28
+ return null;
29
+ return { op: 'create_typed', path, type, fields, sections: change.sections };
39
30
  }
40
31
  function operationOf(batch, change, handle) {
41
32
  const path = nativePath(change.path, handle);
42
33
  if (change.kind === 'field') {
43
34
  const prior = priorField(batch, change.path, change.name);
44
- if (prior === undefined) return {
45
- rule: 'precondition-missing'
46
- };
35
+ if (prior === undefined)
36
+ return { rule: 'precondition-missing' };
47
37
  return {
48
38
  operation: {
49
39
  op: 'set_field',
50
40
  path,
51
41
  field: change.name,
52
42
  value: change.value,
53
- ...prior.value === undefined ? {} : {
54
- base: prior.value
55
- }
56
- }
43
+ ...(prior.value === undefined ? {} : { base: prior.value }),
44
+ },
57
45
  };
58
46
  }
59
47
  if (change.kind === 'section') {
60
48
  const prior = priorSection(batch, change.path, change.name);
61
- if (prior === undefined) return {
62
- rule: 'precondition-missing'
63
- };
49
+ if (prior === undefined)
50
+ return { rule: 'precondition-missing' };
64
51
  return {
65
52
  operation: {
66
53
  op: 'replace_section',
67
54
  path,
68
55
  section: change.name,
69
56
  base: prior.value,
70
- content: change.value
71
- }
57
+ content: change.value,
58
+ },
72
59
  };
73
60
  }
74
61
  if (change.kind === 'preamble') {
75
62
  const prior = priorPreamble(batch, change.path);
76
- if (prior === undefined) return {
77
- rule: 'precondition-missing'
78
- };
63
+ if (prior === undefined)
64
+ return { rule: 'precondition-missing' };
79
65
  return {
80
- operation: {
81
- op: 'replace_preamble',
82
- path,
83
- base: prior.value,
84
- content: change.value
85
- }
66
+ operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },
86
67
  };
87
68
  }
88
69
  if (change.kind === 'create') {
89
- if (priorAbsence(batch, change.path) === undefined) return {
90
- rule: 'precondition-missing'
91
- };
92
- const created = typedCreate(change, path);
93
- return created === null ? {
94
- rule: 'type-missing'
95
- } : {
96
- operation: created
97
- };
70
+ if (priorAbsence(batch, change.path) === undefined)
71
+ return { rule: 'precondition-missing' };
72
+ const operation = created(change, path);
73
+ return operation === null ? { rule: 'type-missing' } : { operation };
98
74
  }
99
75
  const existence = priorExistence(batch, change.path);
100
- if (existence === undefined) return {
101
- rule: 'precondition-missing'
102
- };
103
- if (!('base' in existence)) return {
104
- rule: 'presence-base-unrepresentable'
105
- };
76
+ if (existence === undefined)
77
+ return { rule: 'precondition-missing' };
78
+ if (!('base' in existence))
79
+ return { rule: 'presence-base-unrepresentable' };
106
80
  if (change.kind === 'replace') {
107
- return {
108
- operation: {
109
- op: 'replace',
110
- path,
111
- base: existence.base,
112
- content: change.content
113
- }
114
- };
81
+ return { operation: { op: 'replace', path, base: existence.base, content: change.content } };
115
82
  }
116
83
  if (change.kind === 'move') {
117
- if (priorAbsence(batch, change.to) === undefined) return {
118
- rule: 'precondition-missing'
119
- };
84
+ if (priorAbsence(batch, change.to) === undefined)
85
+ return { rule: 'precondition-missing' };
120
86
  return {
121
- operation: {
122
- op: 'rename',
123
- path,
124
- to: nativePath(change.to, handle),
125
- base: existence.base
126
- }
87
+ operation: { op: 'rename', path, to: nativePath(change.to, handle), base: existence.base },
127
88
  };
128
89
  }
129
- return {
130
- operation: {
131
- op: 'remove',
132
- path,
133
- base: existence.base
134
- }
135
- };
90
+ return { operation: { op: 'remove', path, base: existence.base } };
136
91
  }
137
92
  export function houseChanges(batch, handle) {
138
93
  const changes = [];
139
- for (const change of batch.changes){
94
+ for (const change of batch.changes) {
140
95
  const mapped = operationOf(batch, change, handle);
141
- if ('rule' in mapped) return {
142
- kind: 'unmapped',
143
- path: change.path,
144
- rule: mapped.rule
145
- };
96
+ if ('rule' in mapped)
97
+ return { kind: 'unmapped', path: change.path, rule: mapped.rule };
146
98
  changes.push(mapped.operation);
147
99
  }
148
- return {
149
- kind: 'changes',
150
- changes
151
- };
100
+ return { kind: 'changes', changes };
152
101
  }
153
102
  export function operationHead(batch) {
154
103
  const writer = batch.writtenBy;
155
- return writer === undefined ? {
156
- operation_id: batch.id
157
- } : {
158
- operation_id: batch.id,
159
- app_ref: writer.app,
160
- release: writer.release
161
- };
104
+ return writer === undefined
105
+ ? { operation_id: batch.id }
106
+ : { operation_id: batch.id, app_ref: writer.app, release: writer.release };
162
107
  }
163
108
  export function batchPaths(changes) {
164
109
  return [
165
- ...new Set(changes.flatMap((change)=>change.op === 'rename' ? [
166
- String(change.path),
167
- String(change.to)
168
- ] : [
169
- String(change.path)
170
- ]))
110
+ ...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
171
111
  ].sort();
172
112
  }
173
113
  export function deltaBody(changes) {
174
- return JSON.stringify({
175
- changes
176
- });
114
+ return JSON.stringify({ changes });
177
115
  }
178
116
  export function deltaBytes(delta) {
179
117
  return textBytes(delta);
180
118
  }
181
- export function uploadable(bytes) {
182
- return bytes > INLINE_BODY_LIMIT_BYTES && bytes <= UPLOAD_BYTES_MAX;
119
+ export function uploadable(inline, bytes, bounds) {
120
+ return (textBytes(JSON.stringify(inline)) > bounds.max_inline_body_bytes &&
121
+ bytes <= bounds.max_upload_bytes);
183
122
  }
184
123
  export function deltaDigest(delta) {
185
124
  return sha256Hex(delta);
186
125
  }
187
126
  function material(value, handle) {
188
- if (!Array.isArray(value)) return null;
127
+ if (!Array.isArray(value))
128
+ return null;
189
129
  const held = [];
190
- for (const entry of value){
191
- if (typeof entry !== 'object' || entry === null) return null;
130
+ for (const entry of value) {
131
+ if (typeof entry !== 'object' || entry === null)
132
+ return null;
192
133
  const file = entry;
193
- if (typeof file.path !== 'string') return null;
194
- if (file.content !== null && typeof file.content !== 'string') return null;
195
- if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string') return null;
134
+ if (typeof file.path !== 'string')
135
+ return null;
136
+ if (file.content !== null && typeof file.content !== 'string')
137
+ return null;
138
+ if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
139
+ return null;
196
140
  let path;
197
141
  try {
198
142
  path = roomLocalPath(file.path, handle);
199
- } catch {
143
+ }
144
+ catch {
200
145
  return null;
201
146
  }
202
147
  held.push({
203
148
  path,
204
149
  content: file.content,
205
- revision: typeof file.revision === 'string' ? file.revision : null
150
+ revision: typeof file.revision === 'string' ? file.revision : null,
206
151
  });
207
152
  }
208
153
  return held;
209
154
  }
210
155
  function affectedOf(held) {
211
156
  const affected = {};
212
- for (const entry of held){
213
- if (entry.content !== null) affected[entry.path] = entry.content;
157
+ for (const entry of held) {
158
+ if (entry.content !== null)
159
+ affected[entry.path] = entry.content;
214
160
  }
215
161
  return affected;
216
162
  }
217
163
  export function mutationOutcome(status, body, locator, handle) {
218
164
  const refusal = doorRefusal(body);
219
- if (refusal !== null && refusal.code === 'rate_limited') {
220
- const reset = refusal.fields.retry_at;
221
- return {
222
- kind: 'retryable-refusal',
223
- code: refusal.code,
224
- fields: refusal.fields,
225
- ...typeof reset === 'string' ? {
226
- reset
227
- } : {}
228
- };
165
+ if (refusal !== null && refusal.code === 'service_mode_write_halted') {
166
+ return { kind: 'write-halted' };
229
167
  }
230
- if (refusal !== null && refusal.code === 'operation_expired') return {
231
- kind: 'expired'
232
- };
168
+ if (refusal !== null && refusal.code === 'operation_expired')
169
+ return { kind: 'expired' };
233
170
  if (refusal !== null && refusal.code === 'edit_conflict') {
234
171
  const { current, ...fields } = refusal.fields;
235
172
  const held = material(current, handle) ?? [];
236
- return {
237
- kind: 'conflicted',
238
- affected: affectedOf(held),
239
- code: refusal.code,
240
- fields
241
- };
173
+ return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };
242
174
  }
243
175
  if (refusal !== null && status === 404) {
244
176
  return scopedRefusal(locator, 'undisclosed', refusal);
245
177
  }
246
178
  const classified = classifyDoor(status, body, locator);
179
+ const reset = refusal?.fields.retry_at;
180
+ if (refusal?.retryable === true &&
181
+ typeof reset === 'string' &&
182
+ classified?.kind === 'transport-uncertainty') {
183
+ return { kind: 'retryable-refusal', code: refusal.code, fields: refusal.fields, reset };
184
+ }
247
185
  if (classified !== null && classified.kind !== 'scoped-refusal') {
248
- return classified.kind === 'beyond-horizon' ? {
249
- kind: 'expired'
250
- } : classified;
186
+ return classified.kind === 'beyond-horizon' ? { kind: 'expired' } : classified;
251
187
  }
252
- if (classified !== null && status === 403) return classified;
188
+ if (classified !== null && status === 403)
189
+ return classified;
253
190
  if (refusal !== null && status >= 400) {
254
- return {
255
- kind: 'rejected',
256
- affected: {},
257
- code: refusal.code,
258
- fields: refusal.fields
259
- };
191
+ return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
260
192
  }
261
193
  if (status !== 200 || typeof body !== 'object' || body === null) {
262
- return {
263
- kind: 'transport-uncertainty'
264
- };
194
+ return { kind: 'transport-uncertainty' };
265
195
  }
266
196
  const held = body;
267
197
  const at = readPosition(held);
268
- if (at === null) return {
269
- kind: 'transport-uncertainty'
270
- };
198
+ if (at === null)
199
+ return { kind: 'transport-uncertainty' };
271
200
  const contents = material(held.contents, handle);
272
- if (contents === null) return {
273
- kind: 'transport-uncertainty'
274
- };
201
+ if (contents === null)
202
+ return { kind: 'transport-uncertainty' };
275
203
  const documents = {};
276
204
  const revisions = {};
277
205
  const removals = [];
278
- for (const entry of contents){
206
+ for (const entry of contents) {
279
207
  if (entry.content === null || entry.revision === null) {
280
208
  removals.push(entry.path);
281
209
  continue;
@@ -288,7 +216,7 @@ export function mutationOutcome(status, body, locator, handle) {
288
216
  roomVersion: roomVersion(at),
289
217
  documents,
290
218
  revisions,
291
- removals: removals.sort()
219
+ removals: removals.sort(),
292
220
  };
293
221
  }
294
222
  export function rejectedMapping(mapping) {
@@ -296,94 +224,78 @@ export function rejectedMapping(mapping) {
296
224
  kind: 'rejected',
297
225
  affected: {},
298
226
  code: mapping.rule,
299
- fields: {
300
- path: mapping.path
301
- }
227
+ fields: { path: mapping.path },
302
228
  };
303
229
  }
304
230
  export function revisionBody(input) {
305
231
  return {
306
232
  path: nativePath(input.path, input.handle),
307
- ...input.revision === undefined ? {} : {
308
- revision: input.revision
309
- },
310
- ...input.pageToken === undefined ? {} : {
311
- before: Number(input.pageToken)
312
- }
233
+ ...(input.revision === undefined ? {} : { revision: input.revision }),
234
+ ...(input.pageToken === undefined ? {} : { before: Number(input.pageToken) }),
313
235
  };
314
236
  }
237
+ function revisionAuthor(entry) {
238
+ const user = entry.author_user;
239
+ const site = entry.author_site;
240
+ const name = entry.author_site_name;
241
+ if (typeof user === 'string' && site === undefined && name === undefined) {
242
+ return { kind: 'user', id: user };
243
+ }
244
+ if (user === null && typeof site === 'string' && typeof name === 'string') {
245
+ return { kind: 'site', id: site, name };
246
+ }
247
+ return null;
248
+ }
315
249
  export function historyOutcome(status, body, locator, request) {
316
250
  const classified = classifyDoor(status, body, locator);
317
251
  if (classified !== null) {
318
- return classified.kind === 'beyond-horizon' ? {
319
- kind: 'transport-uncertainty'
320
- } : classified;
252
+ return classified.kind === 'beyond-horizon' ? { kind: 'transport-uncertainty' } : classified;
321
253
  }
322
254
  if (status !== 200 || typeof body !== 'object' || body === null) {
323
- return {
324
- kind: 'transport-uncertainty'
325
- };
255
+ return { kind: 'transport-uncertainty' };
326
256
  }
327
257
  const held = body;
328
- if (!Array.isArray(held.revisions)) return {
329
- kind: 'transport-uncertainty'
330
- };
258
+ if (!Array.isArray(held.revisions))
259
+ return { kind: 'transport-uncertainty' };
331
260
  const entries = [];
332
- for (const entry of held.revisions){
333
- if (typeof entry !== 'object' || entry === null) return {
334
- kind: 'transport-uncertainty'
335
- };
261
+ for (const entry of held.revisions) {
262
+ if (typeof entry !== 'object' || entry === null)
263
+ return { kind: 'transport-uncertainty' };
336
264
  entries.push(entry);
337
265
  }
338
266
  if (request.revision !== undefined) {
339
267
  const named = entries[0];
340
- if (named === undefined) return {
341
- kind: 'no-history'
342
- };
268
+ if (named === undefined)
269
+ return { kind: 'no-history' };
343
270
  if (named.unavailable === true) {
344
271
  return {
345
272
  kind: 'scoped-refusal',
346
273
  locator,
347
274
  scope: 'content',
348
275
  code: 'retained_history_unavailable',
349
- fields: {
350
- path: request.path,
351
- revision: request.revision
352
- }
276
+ fields: { path: request.path, revision: request.revision },
353
277
  };
354
278
  }
355
- if (typeof named.content !== 'string') return {
356
- kind: 'transport-uncertainty'
357
- };
358
- return {
359
- kind: 'revision',
360
- content: named.content
361
- };
279
+ if (typeof named.content !== 'string')
280
+ return { kind: 'transport-uncertainty' };
281
+ return { kind: 'revision', content: named.content };
362
282
  }
363
- if (entries.length === 0) return {
364
- kind: 'no-history'
365
- };
283
+ if (entries.length === 0)
284
+ return { kind: 'no-history' };
366
285
  const revisions = [];
367
- for (const entry of entries){
368
- if (typeof entry.revision !== 'string' || typeof entry.author_user !== 'string' || typeof entry.created_at !== 'string') {
369
- return {
370
- kind: 'transport-uncertainty'
371
- };
286
+ for (const entry of entries) {
287
+ const author = revisionAuthor(entry);
288
+ if (typeof entry.revision !== 'string' ||
289
+ author === null ||
290
+ typeof entry.created_at !== 'string') {
291
+ return { kind: 'transport-uncertainty' };
372
292
  }
373
- revisions.push({
374
- revision: entry.revision,
375
- author: entry.author_user,
376
- time: entry.created_at
377
- });
293
+ revisions.push({ revision: entry.revision, author, time: entry.created_at });
378
294
  }
379
295
  const next = held.next_before;
380
296
  return {
381
297
  kind: 'history',
382
298
  revisions,
383
- ...typeof next === 'number' ? {
384
- pageToken: String(next)
385
- } : {}
299
+ ...(typeof next === 'number' ? { pageToken: String(next) } : {}),
386
300
  };
387
301
  }
388
-
389
- //# sourceMappingURL=write.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-alpha.9",
3
+ "version": "0.1.0-c506c7d6e6199",
4
4
  "description": "Agents House Adapter for the MD Runtime",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,19 +21,11 @@
21
21
  "files": [
22
22
  "dist",
23
23
  "AGENTS.md",
24
+ "README.md",
24
25
  "LICENSE"
25
26
  ],
26
- "repository": {
27
- "type": "git",
28
- "url": "git+https://github.com/agentshouse/mdruntime.git",
29
- "directory": "packages/mdruntime-adapter"
30
- },
31
- "homepage": "https://github.com/agentshouse/mdruntime#readme",
32
- "bugs": {
33
- "url": "https://github.com/agentshouse/mdruntime/issues"
34
- },
35
27
  "dependencies": {
36
- "@agentshouse/mdmodel": "0.1.0-alpha.11",
37
- "@agentshouse/mdruntime": "0.1.0-alpha.16"
28
+ "@agentshouse/mdmodel": "0.1.0-ce804f6363a19",
29
+ "@agentshouse/mdruntime": "0.1.0-c009335e08279"
38
30
  }
39
31
  }