@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c09c6f263662c
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 +272 -33
- package/README.md +32 -0
- package/dist/actions.d.ts +43 -13
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +270 -351
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +361 -221
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +23 -34
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +154 -231
- 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 +8 -18
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +63 -57
- package/dist/read.d.ts +40 -29
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +209 -208
- 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 -69
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +144 -153
- package/dist/stream.d.ts +17 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +251 -215
- package/dist/transport.d.ts +81 -33
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +4 -3
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +32 -18
- package/dist/write.d.ts +7 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +196 -206
- package/package.json +5 -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,235 +1,201 @@
|
|
|
1
|
+
import { departure, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { binaryFileOf, headChange } 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
|
-
kind: 'changes',
|
|
150
|
-
changes
|
|
151
|
-
};
|
|
121
|
+
return { kind: 'changes', changes };
|
|
152
122
|
}
|
|
153
123
|
export function operationHead(batch) {
|
|
154
124
|
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
|
-
};
|
|
125
|
+
return writer === undefined
|
|
126
|
+
? { operation_id: batch.id }
|
|
127
|
+
: { operation_id: batch.id, app_ref: writer.app, release: writer.release };
|
|
162
128
|
}
|
|
163
129
|
export function batchPaths(changes) {
|
|
164
130
|
return [
|
|
165
|
-
...new Set(changes.flatMap((change)=>change.op === 'rename' ? [
|
|
166
|
-
String(change.path),
|
|
167
|
-
String(change.to)
|
|
168
|
-
] : [
|
|
169
|
-
String(change.path)
|
|
170
|
-
]))
|
|
131
|
+
...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
171
132
|
].sort();
|
|
172
133
|
}
|
|
173
134
|
export function deltaBody(changes) {
|
|
174
|
-
return JSON.stringify({
|
|
175
|
-
changes
|
|
176
|
-
});
|
|
135
|
+
return JSON.stringify({ changes });
|
|
177
136
|
}
|
|
178
137
|
export function deltaBytes(delta) {
|
|
179
138
|
return textBytes(delta);
|
|
180
139
|
}
|
|
181
|
-
export function uploadable(bytes) {
|
|
182
|
-
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);
|
|
183
143
|
}
|
|
184
144
|
export function deltaDigest(delta) {
|
|
185
145
|
return sha256Hex(delta);
|
|
186
146
|
}
|
|
187
147
|
function material(value, handle) {
|
|
188
|
-
if (!Array.isArray(value))
|
|
148
|
+
if (!Array.isArray(value))
|
|
149
|
+
return null;
|
|
189
150
|
const held = [];
|
|
190
|
-
for (const entry of value){
|
|
191
|
-
if (typeof entry !== 'object' || entry === null)
|
|
151
|
+
for (const entry of value) {
|
|
152
|
+
if (typeof entry !== 'object' || entry === null)
|
|
153
|
+
return null;
|
|
192
154
|
const file = entry;
|
|
193
|
-
if (typeof file.path !== 'string')
|
|
194
|
-
|
|
195
|
-
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;
|
|
196
167
|
let path;
|
|
197
168
|
try {
|
|
198
169
|
path = roomLocalPath(file.path, handle);
|
|
199
|
-
}
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
200
172
|
return null;
|
|
201
173
|
}
|
|
202
174
|
held.push({
|
|
203
175
|
path,
|
|
204
176
|
content: file.content,
|
|
205
|
-
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 }),
|
|
206
180
|
});
|
|
207
181
|
}
|
|
208
182
|
return held;
|
|
209
183
|
}
|
|
210
184
|
function affectedOf(held) {
|
|
211
185
|
const affected = {};
|
|
212
|
-
for (const entry of held){
|
|
213
|
-
if (entry.content !== null)
|
|
186
|
+
for (const entry of held) {
|
|
187
|
+
if (entry.content !== null)
|
|
188
|
+
affected[entry.path] = entry.content;
|
|
214
189
|
}
|
|
215
190
|
return affected;
|
|
216
191
|
}
|
|
217
192
|
export function mutationOutcome(status, body, locator, handle) {
|
|
218
193
|
const refusal = doorRefusal(body);
|
|
219
|
-
if (refusal !== null && refusal.code === '
|
|
220
|
-
|
|
221
|
-
return {
|
|
222
|
-
kind: 'retryable-refusal',
|
|
223
|
-
code: refusal.code,
|
|
224
|
-
fields: refusal.fields,
|
|
225
|
-
...typeof reset === 'string' ? {
|
|
226
|
-
reset
|
|
227
|
-
} : {}
|
|
228
|
-
};
|
|
194
|
+
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
195
|
+
return { kind: 'write-halted' };
|
|
229
196
|
}
|
|
230
|
-
if (refusal !== null && refusal.code === '
|
|
231
|
-
kind: 'expired'
|
|
232
|
-
};
|
|
197
|
+
if (refusal !== null && refusal.code === 'expired')
|
|
198
|
+
return { kind: 'expired' };
|
|
233
199
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
234
200
|
const { current, ...fields } = refusal.fields;
|
|
235
201
|
const held = material(current, handle) ?? [];
|
|
@@ -237,58 +203,75 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
237
203
|
kind: 'conflicted',
|
|
238
204
|
affected: affectedOf(held),
|
|
239
205
|
code: refusal.code,
|
|
240
|
-
fields
|
|
206
|
+
fields,
|
|
207
|
+
retryable: refusal.retryable,
|
|
241
208
|
};
|
|
242
209
|
}
|
|
243
210
|
if (refusal !== null && status === 404) {
|
|
244
211
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
245
212
|
}
|
|
246
213
|
const classified = classifyDoor(status, body, locator);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
214
|
+
const reset = refusal?.fields.retry_at;
|
|
215
|
+
if (refusal?.retryable === true &&
|
|
216
|
+
typeof reset === 'string' &&
|
|
217
|
+
classified?.kind === 'transport-uncertainty') {
|
|
218
|
+
return {
|
|
219
|
+
kind: 'retryable-refusal',
|
|
220
|
+
code: refusal.code,
|
|
221
|
+
fields: refusal.fields,
|
|
222
|
+
retryable: true,
|
|
223
|
+
reset,
|
|
224
|
+
};
|
|
251
225
|
}
|
|
252
|
-
if (classified !== null &&
|
|
226
|
+
if (classified !== null && classified.kind !== 'scoped-refusal')
|
|
227
|
+
return classified;
|
|
228
|
+
if (classified !== null && status === 403)
|
|
229
|
+
return classified;
|
|
253
230
|
if (refusal !== null && status >= 400) {
|
|
254
231
|
return {
|
|
255
232
|
kind: 'rejected',
|
|
256
233
|
affected: {},
|
|
257
234
|
code: refusal.code,
|
|
258
|
-
fields: refusal.fields
|
|
235
|
+
fields: refusal.fields,
|
|
236
|
+
retryable: refusal.retryable,
|
|
259
237
|
};
|
|
260
238
|
}
|
|
261
239
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
262
|
-
return {
|
|
263
|
-
kind: 'transport-uncertainty'
|
|
264
|
-
};
|
|
240
|
+
return { kind: 'transport-uncertainty' };
|
|
265
241
|
}
|
|
266
242
|
const held = body;
|
|
267
243
|
const at = readPosition(held);
|
|
268
|
-
if (at === null)
|
|
269
|
-
kind: 'transport-uncertainty'
|
|
270
|
-
};
|
|
244
|
+
if (at === null)
|
|
245
|
+
return { kind: 'transport-uncertainty' };
|
|
271
246
|
const contents = material(held.contents, handle);
|
|
272
|
-
if (contents === null)
|
|
273
|
-
kind: 'transport-uncertainty'
|
|
274
|
-
};
|
|
247
|
+
if (contents === null)
|
|
248
|
+
return { kind: 'transport-uncertainty' };
|
|
275
249
|
const documents = {};
|
|
276
250
|
const revisions = {};
|
|
251
|
+
const changes = {};
|
|
252
|
+
const binaryFiles = {};
|
|
277
253
|
const removals = [];
|
|
278
|
-
for (const entry of contents){
|
|
279
|
-
if (entry.
|
|
254
|
+
for (const entry of contents) {
|
|
255
|
+
if (entry.revision === null) {
|
|
280
256
|
removals.push(entry.path);
|
|
281
257
|
continue;
|
|
282
258
|
}
|
|
283
|
-
|
|
259
|
+
if (entry.content !== null)
|
|
260
|
+
documents[entry.path] = entry.content;
|
|
261
|
+
if (entry.binary !== undefined)
|
|
262
|
+
binaryFiles[entry.path] = entry.binary;
|
|
284
263
|
revisions[entry.path] = entry.revision;
|
|
264
|
+
if (entry.head !== undefined)
|
|
265
|
+
changes[entry.path] = entry.head;
|
|
285
266
|
}
|
|
286
267
|
return {
|
|
287
268
|
kind: 'accepted',
|
|
288
269
|
roomVersion: roomVersion(at),
|
|
289
270
|
documents,
|
|
290
271
|
revisions,
|
|
291
|
-
|
|
272
|
+
changes,
|
|
273
|
+
removals: removals.sort(),
|
|
274
|
+
...(Object.keys(binaryFiles).length === 0 ? {} : { binaryFiles }),
|
|
292
275
|
};
|
|
293
276
|
}
|
|
294
277
|
export function rejectedMapping(mapping) {
|
|
@@ -296,94 +279,101 @@ export function rejectedMapping(mapping) {
|
|
|
296
279
|
kind: 'rejected',
|
|
297
280
|
affected: {},
|
|
298
281
|
code: mapping.rule,
|
|
299
|
-
fields: {
|
|
300
|
-
|
|
301
|
-
}
|
|
282
|
+
fields: { path: mapping.path },
|
|
283
|
+
retryable: false,
|
|
302
284
|
};
|
|
303
285
|
}
|
|
304
286
|
export function revisionBody(input) {
|
|
305
287
|
return {
|
|
306
288
|
path: nativePath(input.path, input.handle),
|
|
307
|
-
...input.revision === undefined ? {} : {
|
|
308
|
-
|
|
309
|
-
},
|
|
310
|
-
...input.pageToken === undefined ? {} : {
|
|
311
|
-
before: Number(input.pageToken)
|
|
312
|
-
}
|
|
289
|
+
...(input.revision === undefined ? {} : { revision: input.revision }),
|
|
290
|
+
...(input.pageToken === undefined ? {} : { before: Number(input.pageToken) }),
|
|
313
291
|
};
|
|
314
292
|
}
|
|
293
|
+
function revisionAuthor(entry) {
|
|
294
|
+
const user = entry.author_user;
|
|
295
|
+
const site = entry.author_site;
|
|
296
|
+
const name = entry.author_site_name;
|
|
297
|
+
if (typeof user === 'string' && site === undefined && name === undefined) {
|
|
298
|
+
return { kind: 'user', id: user };
|
|
299
|
+
}
|
|
300
|
+
if (user === null && typeof site === 'string' && typeof name === 'string') {
|
|
301
|
+
return { kind: 'site', id: site, name };
|
|
302
|
+
}
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
function historyBinary(entry) {
|
|
306
|
+
if (entry.file === undefined)
|
|
307
|
+
return undefined;
|
|
308
|
+
const { file, bytes, media_type: mediaType, sha256 } = entry;
|
|
309
|
+
if (typeof file !== 'string' ||
|
|
310
|
+
typeof bytes !== 'number' ||
|
|
311
|
+
typeof mediaType !== 'string' ||
|
|
312
|
+
typeof sha256 !== 'string')
|
|
313
|
+
return null;
|
|
314
|
+
return { fileRef: file, byteLength: bytes, mediaType, sha256 };
|
|
315
|
+
}
|
|
315
316
|
export function historyOutcome(status, body, locator, request) {
|
|
316
317
|
const classified = classifyDoor(status, body, locator);
|
|
317
|
-
if (classified !== null)
|
|
318
|
-
return classified
|
|
319
|
-
kind: 'transport-uncertainty'
|
|
320
|
-
} : classified;
|
|
321
|
-
}
|
|
318
|
+
if (classified !== null)
|
|
319
|
+
return classified;
|
|
322
320
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
323
|
-
return {
|
|
324
|
-
kind: 'transport-uncertainty'
|
|
325
|
-
};
|
|
321
|
+
return { kind: 'transport-uncertainty' };
|
|
326
322
|
}
|
|
327
323
|
const held = body;
|
|
328
|
-
if (!Array.isArray(held.revisions))
|
|
329
|
-
kind: 'transport-uncertainty'
|
|
330
|
-
};
|
|
324
|
+
if (!Array.isArray(held.revisions))
|
|
325
|
+
return { kind: 'transport-uncertainty' };
|
|
331
326
|
const entries = [];
|
|
332
|
-
for (const entry of held.revisions){
|
|
333
|
-
if (typeof entry !== 'object' || entry === null)
|
|
334
|
-
kind: 'transport-uncertainty'
|
|
335
|
-
};
|
|
327
|
+
for (const entry of held.revisions) {
|
|
328
|
+
if (typeof entry !== 'object' || entry === null)
|
|
329
|
+
return { kind: 'transport-uncertainty' };
|
|
336
330
|
entries.push(entry);
|
|
337
331
|
}
|
|
338
332
|
if (request.revision !== undefined) {
|
|
339
333
|
const named = entries[0];
|
|
340
|
-
if (named === undefined)
|
|
341
|
-
kind: 'no-history'
|
|
342
|
-
};
|
|
334
|
+
if (named === undefined)
|
|
335
|
+
return { kind: 'no-history' };
|
|
343
336
|
if (named.unavailable === true) {
|
|
344
337
|
return {
|
|
345
338
|
kind: 'scoped-refusal',
|
|
346
339
|
locator,
|
|
347
340
|
scope: 'content',
|
|
348
341
|
code: 'retained_history_unavailable',
|
|
349
|
-
fields: {
|
|
350
|
-
|
|
351
|
-
revision: request.revision
|
|
352
|
-
}
|
|
342
|
+
fields: { path: request.path, revision: request.revision },
|
|
343
|
+
retryable: false,
|
|
353
344
|
};
|
|
354
345
|
}
|
|
355
|
-
if (typeof named.
|
|
356
|
-
kind: '
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
content: named.content
|
|
361
|
-
};
|
|
346
|
+
if (typeof named.file === 'string')
|
|
347
|
+
return { kind: 'no-history' };
|
|
348
|
+
if (typeof named.content !== 'string')
|
|
349
|
+
return { kind: 'transport-uncertainty' };
|
|
350
|
+
return { kind: 'revision', content: named.content };
|
|
362
351
|
}
|
|
363
|
-
if (entries.length === 0)
|
|
364
|
-
kind: 'no-history'
|
|
365
|
-
};
|
|
352
|
+
if (entries.length === 0)
|
|
353
|
+
return { kind: 'no-history' };
|
|
366
354
|
const revisions = [];
|
|
367
|
-
for (const entry of entries){
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
355
|
+
for (const entry of entries) {
|
|
356
|
+
const author = revisionAuthor(entry);
|
|
357
|
+
if (typeof entry.revision !== 'string' ||
|
|
358
|
+
author === null ||
|
|
359
|
+
typeof entry.created_at !== 'string') {
|
|
360
|
+
return { kind: 'transport-uncertainty' };
|
|
372
361
|
}
|
|
362
|
+
const binaryFile = historyBinary(entry);
|
|
363
|
+
if (binaryFile === null)
|
|
364
|
+
return { kind: 'transport-uncertainty' };
|
|
373
365
|
revisions.push({
|
|
374
366
|
revision: entry.revision,
|
|
375
|
-
author
|
|
376
|
-
time: entry.created_at
|
|
367
|
+
author,
|
|
368
|
+
time: entry.created_at,
|
|
369
|
+
...(binaryFile === undefined ? {} : { binaryFile }),
|
|
377
370
|
});
|
|
378
371
|
}
|
|
379
372
|
const next = held.next_before;
|
|
380
373
|
return {
|
|
381
374
|
kind: 'history',
|
|
382
375
|
revisions,
|
|
383
|
-
...typeof next === 'number' ? {
|
|
384
|
-
|
|
385
|
-
} : {}
|
|
376
|
+
...(typeof next === 'number' ? { pageToken: String(next) } : {}),
|
|
377
|
+
...(held.deleted === true ? { deleted: true } : {}),
|
|
386
378
|
};
|
|
387
379
|
}
|
|
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-
|
|
3
|
+
"version": "0.1.0-c09c6f263662c",
|
|
4
4
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,26 +14,18 @@
|
|
|
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/mdmodel": "0.1.0-
|
|
37
|
-
"@agentshouse/mdruntime": "0.1.0-
|
|
28
|
+
"@agentshouse/mdmodel": "0.1.0-c64451b2127b4",
|
|
29
|
+
"@agentshouse/mdruntime": "0.1.0-cf96c797c5fa8"
|
|
38
30
|
}
|
|
39
31
|
}
|