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