@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c055ce6f0fdd0
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 +186 -34
- package/README.md +32 -0
- package/dist/actions.d.ts +5 -13
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +241 -334
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +255 -215
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +23 -33
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +143 -230
- package/dist/gather.d.ts +3 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +40 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/links.d.ts +20 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +104 -0
- 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 +48 -59
- package/dist/read.d.ts +31 -26
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +205 -199
- package/dist/refusal.d.ts +3 -1
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +27 -62
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +103 -151
- package/dist/stream.d.ts +16 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +238 -214
- package/dist/transport.d.ts +69 -30
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +2 -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 +13 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +132 -215
- package/package.json +4 -12
- 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,281 +1,213 @@
|
|
|
1
|
+
import { parseOriginals } from './read.js';
|
|
1
2
|
import { sha256Hex, textBytes } from './digest.js';
|
|
2
3
|
import { nativePath, roomLocalPath } from './map.js';
|
|
3
4
|
import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
|
|
4
5
|
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
6
|
function priorField(batch, path, name) {
|
|
9
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'field' && precondition.path === path && precondition.name === name);
|
|
7
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'field' && precondition.path === path && precondition.name === name);
|
|
10
8
|
}
|
|
11
9
|
function priorSection(batch, path, name) {
|
|
12
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'section' && precondition.path === path && precondition.name === name);
|
|
10
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'section' && precondition.path === path && precondition.name === name);
|
|
13
11
|
}
|
|
14
12
|
function priorPreamble(batch, path) {
|
|
15
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'preamble' && precondition.path === path);
|
|
13
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'preamble' && precondition.path === path);
|
|
16
14
|
}
|
|
17
15
|
function priorAbsence(batch, path) {
|
|
18
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'absent' && precondition.path === path);
|
|
16
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'absent' && precondition.path === path);
|
|
19
17
|
}
|
|
20
18
|
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
|
-
};
|
|
19
|
+
const precondition = batch.preconditions.find((held) => held.path === path && (held.kind === 'revision' || held.kind === 'present'));
|
|
20
|
+
if (precondition === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };
|
|
28
23
|
}
|
|
29
|
-
function
|
|
24
|
+
function created(change, path) {
|
|
25
|
+
if ('content' in change)
|
|
26
|
+
return { op: 'create', path, content: change.content };
|
|
30
27
|
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
|
-
};
|
|
28
|
+
if (typeof type !== 'string' || type.length === 0)
|
|
29
|
+
return null;
|
|
30
|
+
return { op: 'create_typed', path, type, fields, sections: change.sections };
|
|
39
31
|
}
|
|
40
32
|
function operationOf(batch, change, handle) {
|
|
41
33
|
const path = nativePath(change.path, handle);
|
|
42
34
|
if (change.kind === 'field') {
|
|
43
35
|
const prior = priorField(batch, change.path, change.name);
|
|
44
|
-
if (prior === undefined)
|
|
45
|
-
rule: 'precondition-missing'
|
|
46
|
-
};
|
|
36
|
+
if (prior === undefined)
|
|
37
|
+
return { rule: 'precondition-missing' };
|
|
47
38
|
return {
|
|
48
39
|
operation: {
|
|
49
40
|
op: 'set_field',
|
|
50
41
|
path,
|
|
51
42
|
field: change.name,
|
|
52
43
|
value: change.value,
|
|
53
|
-
...prior.value === undefined ? {} : {
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}
|
|
44
|
+
...(prior.value === undefined ? {} : { base: prior.value }),
|
|
45
|
+
},
|
|
57
46
|
};
|
|
58
47
|
}
|
|
59
48
|
if (change.kind === 'section') {
|
|
60
49
|
const prior = priorSection(batch, change.path, change.name);
|
|
61
|
-
if (prior === undefined)
|
|
62
|
-
rule: 'precondition-missing'
|
|
63
|
-
};
|
|
50
|
+
if (prior === undefined)
|
|
51
|
+
return { rule: 'precondition-missing' };
|
|
64
52
|
return {
|
|
65
53
|
operation: {
|
|
66
54
|
op: 'replace_section',
|
|
67
55
|
path,
|
|
68
56
|
section: change.name,
|
|
69
57
|
base: prior.value,
|
|
70
|
-
content: change.value
|
|
71
|
-
}
|
|
58
|
+
content: change.value,
|
|
59
|
+
},
|
|
72
60
|
};
|
|
73
61
|
}
|
|
74
62
|
if (change.kind === 'preamble') {
|
|
75
63
|
const prior = priorPreamble(batch, change.path);
|
|
76
|
-
if (prior === undefined)
|
|
77
|
-
rule: 'precondition-missing'
|
|
78
|
-
};
|
|
64
|
+
if (prior === undefined)
|
|
65
|
+
return { rule: 'precondition-missing' };
|
|
79
66
|
return {
|
|
80
|
-
operation: {
|
|
81
|
-
op: 'replace_preamble',
|
|
82
|
-
path,
|
|
83
|
-
base: prior.value,
|
|
84
|
-
content: change.value
|
|
85
|
-
}
|
|
67
|
+
operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },
|
|
86
68
|
};
|
|
87
69
|
}
|
|
88
70
|
if (change.kind === 'create') {
|
|
89
|
-
if (priorAbsence(batch, change.path) === undefined)
|
|
90
|
-
rule: 'precondition-missing'
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return created === null ? {
|
|
94
|
-
rule: 'type-missing'
|
|
95
|
-
} : {
|
|
96
|
-
operation: created
|
|
97
|
-
};
|
|
71
|
+
if (priorAbsence(batch, change.path) === undefined)
|
|
72
|
+
return { rule: 'precondition-missing' };
|
|
73
|
+
const operation = created(change, path);
|
|
74
|
+
return operation === null ? { rule: 'type-missing' } : { operation };
|
|
98
75
|
}
|
|
99
76
|
const existence = priorExistence(batch, change.path);
|
|
100
|
-
if (existence === undefined)
|
|
101
|
-
rule: 'precondition-missing'
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
rule: 'presence-base-unrepresentable'
|
|
105
|
-
};
|
|
77
|
+
if (existence === undefined)
|
|
78
|
+
return { rule: 'precondition-missing' };
|
|
79
|
+
if (!('base' in existence))
|
|
80
|
+
return { rule: 'presence-base-unrepresentable' };
|
|
106
81
|
if (change.kind === 'replace') {
|
|
107
|
-
return {
|
|
108
|
-
operation: {
|
|
109
|
-
op: 'replace',
|
|
110
|
-
path,
|
|
111
|
-
base: existence.base,
|
|
112
|
-
content: change.content
|
|
113
|
-
}
|
|
114
|
-
};
|
|
82
|
+
return { operation: { op: 'replace', path, base: existence.base, content: change.content } };
|
|
115
83
|
}
|
|
116
84
|
if (change.kind === 'move') {
|
|
117
|
-
if (priorAbsence(batch, change.to) === undefined)
|
|
118
|
-
rule: 'precondition-missing'
|
|
119
|
-
};
|
|
85
|
+
if (priorAbsence(batch, change.to) === undefined)
|
|
86
|
+
return { rule: 'precondition-missing' };
|
|
120
87
|
return {
|
|
121
|
-
operation: {
|
|
122
|
-
op: 'rename',
|
|
123
|
-
path,
|
|
124
|
-
to: nativePath(change.to, handle),
|
|
125
|
-
base: existence.base
|
|
126
|
-
}
|
|
88
|
+
operation: { op: 'rename', path, to: nativePath(change.to, handle), base: existence.base },
|
|
127
89
|
};
|
|
128
90
|
}
|
|
129
|
-
return {
|
|
130
|
-
operation: {
|
|
131
|
-
op: 'remove',
|
|
132
|
-
path,
|
|
133
|
-
base: existence.base
|
|
134
|
-
}
|
|
135
|
-
};
|
|
91
|
+
return { operation: { op: 'remove', path, base: existence.base } };
|
|
136
92
|
}
|
|
137
93
|
export function houseChanges(batch, handle) {
|
|
138
94
|
const changes = [];
|
|
139
|
-
for (const change of batch.changes){
|
|
95
|
+
for (const change of batch.changes) {
|
|
140
96
|
const mapped = operationOf(batch, change, handle);
|
|
141
|
-
if ('rule' in mapped)
|
|
142
|
-
kind: 'unmapped',
|
|
143
|
-
path: change.path,
|
|
144
|
-
rule: mapped.rule
|
|
145
|
-
};
|
|
97
|
+
if ('rule' in mapped)
|
|
98
|
+
return { kind: 'unmapped', path: change.path, rule: mapped.rule };
|
|
146
99
|
changes.push(mapped.operation);
|
|
147
100
|
}
|
|
148
|
-
return {
|
|
149
|
-
kind: 'changes',
|
|
150
|
-
changes
|
|
151
|
-
};
|
|
101
|
+
return { kind: 'changes', changes };
|
|
152
102
|
}
|
|
153
103
|
export function operationHead(batch) {
|
|
154
104
|
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
|
-
};
|
|
105
|
+
return writer === undefined
|
|
106
|
+
? { operation_id: batch.id }
|
|
107
|
+
: { operation_id: batch.id, app_ref: writer.app, release: writer.release };
|
|
162
108
|
}
|
|
163
109
|
export function batchPaths(changes) {
|
|
164
110
|
return [
|
|
165
|
-
...new Set(changes.flatMap((change)=>change.op === 'rename' ? [
|
|
166
|
-
String(change.path),
|
|
167
|
-
String(change.to)
|
|
168
|
-
] : [
|
|
169
|
-
String(change.path)
|
|
170
|
-
]))
|
|
111
|
+
...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
171
112
|
].sort();
|
|
172
113
|
}
|
|
173
114
|
export function deltaBody(changes) {
|
|
174
|
-
return JSON.stringify({
|
|
175
|
-
changes
|
|
176
|
-
});
|
|
115
|
+
return JSON.stringify({ changes });
|
|
177
116
|
}
|
|
178
117
|
export function deltaBytes(delta) {
|
|
179
118
|
return textBytes(delta);
|
|
180
119
|
}
|
|
181
|
-
export function uploadable(bytes) {
|
|
182
|
-
return
|
|
120
|
+
export function uploadable(inline, bytes, bounds) {
|
|
121
|
+
return (textBytes(JSON.stringify(inline)) > bounds.max_inline_body_bytes &&
|
|
122
|
+
bytes <= bounds.max_upload_bytes);
|
|
183
123
|
}
|
|
184
124
|
export function deltaDigest(delta) {
|
|
185
125
|
return sha256Hex(delta);
|
|
186
126
|
}
|
|
187
127
|
function material(value, handle) {
|
|
188
|
-
if (!Array.isArray(value))
|
|
128
|
+
if (!Array.isArray(value))
|
|
129
|
+
return null;
|
|
189
130
|
const held = [];
|
|
190
|
-
for (const entry of value){
|
|
191
|
-
if (typeof entry !== 'object' || entry === null)
|
|
131
|
+
for (const entry of value) {
|
|
132
|
+
if (typeof entry !== 'object' || entry === null)
|
|
133
|
+
return null;
|
|
192
134
|
const file = entry;
|
|
193
|
-
if (typeof file.path !== 'string')
|
|
194
|
-
|
|
195
|
-
if (file.
|
|
135
|
+
if (typeof file.path !== 'string')
|
|
136
|
+
return null;
|
|
137
|
+
if (file.content !== null && typeof file.content !== 'string')
|
|
138
|
+
return null;
|
|
139
|
+
if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
|
|
140
|
+
return null;
|
|
196
141
|
let path;
|
|
197
142
|
try {
|
|
198
143
|
path = roomLocalPath(file.path, handle);
|
|
199
|
-
}
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
200
146
|
return null;
|
|
201
147
|
}
|
|
202
148
|
held.push({
|
|
203
149
|
path,
|
|
204
150
|
content: file.content,
|
|
205
|
-
revision: typeof file.revision === 'string' ? file.revision : null
|
|
151
|
+
revision: typeof file.revision === 'string' ? file.revision : null,
|
|
206
152
|
});
|
|
207
153
|
}
|
|
208
154
|
return held;
|
|
209
155
|
}
|
|
210
156
|
function affectedOf(held) {
|
|
211
157
|
const affected = {};
|
|
212
|
-
for (const entry of held){
|
|
213
|
-
if (entry.content !== null)
|
|
158
|
+
for (const entry of held) {
|
|
159
|
+
if (entry.content !== null)
|
|
160
|
+
affected[entry.path] = entry.content;
|
|
214
161
|
}
|
|
215
162
|
return affected;
|
|
216
163
|
}
|
|
217
164
|
export function mutationOutcome(status, body, locator, handle) {
|
|
218
165
|
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
|
-
};
|
|
166
|
+
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
167
|
+
return { kind: 'write-halted' };
|
|
229
168
|
}
|
|
230
|
-
if (refusal !== null && refusal.code === 'operation_expired')
|
|
231
|
-
kind: 'expired'
|
|
232
|
-
};
|
|
169
|
+
if (refusal !== null && refusal.code === 'operation_expired')
|
|
170
|
+
return { kind: 'expired' };
|
|
233
171
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
234
172
|
const { current, ...fields } = refusal.fields;
|
|
235
173
|
const held = material(current, handle) ?? [];
|
|
236
|
-
return {
|
|
237
|
-
kind: 'conflicted',
|
|
238
|
-
affected: affectedOf(held),
|
|
239
|
-
code: refusal.code,
|
|
240
|
-
fields
|
|
241
|
-
};
|
|
174
|
+
return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };
|
|
242
175
|
}
|
|
243
176
|
if (refusal !== null && status === 404) {
|
|
244
177
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
245
178
|
}
|
|
246
179
|
const classified = classifyDoor(status, body, locator);
|
|
180
|
+
const reset = refusal?.fields.retry_at;
|
|
181
|
+
if (refusal?.retryable === true &&
|
|
182
|
+
typeof reset === 'string' &&
|
|
183
|
+
classified?.kind === 'transport-uncertainty') {
|
|
184
|
+
return { kind: 'retryable-refusal', code: refusal.code, fields: refusal.fields, reset };
|
|
185
|
+
}
|
|
247
186
|
if (classified !== null && classified.kind !== 'scoped-refusal') {
|
|
248
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
249
|
-
kind: 'expired'
|
|
250
|
-
} : classified;
|
|
187
|
+
return classified.kind === 'beyond-horizon' ? { kind: 'expired' } : classified;
|
|
251
188
|
}
|
|
252
|
-
if (classified !== null && status === 403)
|
|
189
|
+
if (classified !== null && status === 403)
|
|
190
|
+
return classified;
|
|
253
191
|
if (refusal !== null && status >= 400) {
|
|
254
|
-
return {
|
|
255
|
-
kind: 'rejected',
|
|
256
|
-
affected: {},
|
|
257
|
-
code: refusal.code,
|
|
258
|
-
fields: refusal.fields
|
|
259
|
-
};
|
|
192
|
+
return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
|
|
260
193
|
}
|
|
261
194
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
262
|
-
return {
|
|
263
|
-
kind: 'transport-uncertainty'
|
|
264
|
-
};
|
|
195
|
+
return { kind: 'transport-uncertainty' };
|
|
265
196
|
}
|
|
266
197
|
const held = body;
|
|
267
198
|
const at = readPosition(held);
|
|
268
|
-
if (at === null)
|
|
269
|
-
kind: 'transport-uncertainty'
|
|
270
|
-
};
|
|
199
|
+
if (at === null)
|
|
200
|
+
return { kind: 'transport-uncertainty' };
|
|
271
201
|
const contents = material(held.contents, handle);
|
|
272
|
-
if (contents === null)
|
|
273
|
-
kind: 'transport-uncertainty'
|
|
274
|
-
|
|
202
|
+
if (contents === null)
|
|
203
|
+
return { kind: 'transport-uncertainty' };
|
|
204
|
+
const originals = parseOriginals(held.originals);
|
|
205
|
+
if (originals === null)
|
|
206
|
+
return { kind: 'transport-uncertainty' };
|
|
275
207
|
const documents = {};
|
|
276
208
|
const revisions = {};
|
|
277
209
|
const removals = [];
|
|
278
|
-
for (const entry of contents){
|
|
210
|
+
for (const entry of contents) {
|
|
279
211
|
if (entry.content === null || entry.revision === null) {
|
|
280
212
|
removals.push(entry.path);
|
|
281
213
|
continue;
|
|
@@ -288,7 +220,8 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
288
220
|
roomVersion: roomVersion(at),
|
|
289
221
|
documents,
|
|
290
222
|
revisions,
|
|
291
|
-
removals: removals.sort()
|
|
223
|
+
removals: removals.sort(),
|
|
224
|
+
originals,
|
|
292
225
|
};
|
|
293
226
|
}
|
|
294
227
|
export function rejectedMapping(mapping) {
|
|
@@ -296,94 +229,78 @@ export function rejectedMapping(mapping) {
|
|
|
296
229
|
kind: 'rejected',
|
|
297
230
|
affected: {},
|
|
298
231
|
code: mapping.rule,
|
|
299
|
-
fields: {
|
|
300
|
-
path: mapping.path
|
|
301
|
-
}
|
|
232
|
+
fields: { path: mapping.path },
|
|
302
233
|
};
|
|
303
234
|
}
|
|
304
235
|
export function revisionBody(input) {
|
|
305
236
|
return {
|
|
306
237
|
path: nativePath(input.path, input.handle),
|
|
307
|
-
...input.revision === undefined ? {} : {
|
|
308
|
-
|
|
309
|
-
},
|
|
310
|
-
...input.pageToken === undefined ? {} : {
|
|
311
|
-
before: Number(input.pageToken)
|
|
312
|
-
}
|
|
238
|
+
...(input.revision === undefined ? {} : { revision: input.revision }),
|
|
239
|
+
...(input.pageToken === undefined ? {} : { before: Number(input.pageToken) }),
|
|
313
240
|
};
|
|
314
241
|
}
|
|
242
|
+
function revisionAuthor(entry) {
|
|
243
|
+
const user = entry.author_user;
|
|
244
|
+
const site = entry.author_site;
|
|
245
|
+
const name = entry.author_site_name;
|
|
246
|
+
if (typeof user === 'string' && site === undefined && name === undefined) {
|
|
247
|
+
return { kind: 'user', id: user };
|
|
248
|
+
}
|
|
249
|
+
if (user === null && typeof site === 'string' && typeof name === 'string') {
|
|
250
|
+
return { kind: 'site', id: site, name };
|
|
251
|
+
}
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
315
254
|
export function historyOutcome(status, body, locator, request) {
|
|
316
255
|
const classified = classifyDoor(status, body, locator);
|
|
317
256
|
if (classified !== null) {
|
|
318
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
319
|
-
kind: 'transport-uncertainty'
|
|
320
|
-
} : classified;
|
|
257
|
+
return classified.kind === 'beyond-horizon' ? { kind: 'transport-uncertainty' } : classified;
|
|
321
258
|
}
|
|
322
259
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
323
|
-
return {
|
|
324
|
-
kind: 'transport-uncertainty'
|
|
325
|
-
};
|
|
260
|
+
return { kind: 'transport-uncertainty' };
|
|
326
261
|
}
|
|
327
262
|
const held = body;
|
|
328
|
-
if (!Array.isArray(held.revisions))
|
|
329
|
-
kind: 'transport-uncertainty'
|
|
330
|
-
};
|
|
263
|
+
if (!Array.isArray(held.revisions))
|
|
264
|
+
return { kind: 'transport-uncertainty' };
|
|
331
265
|
const entries = [];
|
|
332
|
-
for (const entry of held.revisions){
|
|
333
|
-
if (typeof entry !== 'object' || entry === null)
|
|
334
|
-
kind: 'transport-uncertainty'
|
|
335
|
-
};
|
|
266
|
+
for (const entry of held.revisions) {
|
|
267
|
+
if (typeof entry !== 'object' || entry === null)
|
|
268
|
+
return { kind: 'transport-uncertainty' };
|
|
336
269
|
entries.push(entry);
|
|
337
270
|
}
|
|
338
271
|
if (request.revision !== undefined) {
|
|
339
272
|
const named = entries[0];
|
|
340
|
-
if (named === undefined)
|
|
341
|
-
kind: 'no-history'
|
|
342
|
-
};
|
|
273
|
+
if (named === undefined)
|
|
274
|
+
return { kind: 'no-history' };
|
|
343
275
|
if (named.unavailable === true) {
|
|
344
276
|
return {
|
|
345
277
|
kind: 'scoped-refusal',
|
|
346
278
|
locator,
|
|
347
279
|
scope: 'content',
|
|
348
280
|
code: 'retained_history_unavailable',
|
|
349
|
-
fields: {
|
|
350
|
-
path: request.path,
|
|
351
|
-
revision: request.revision
|
|
352
|
-
}
|
|
281
|
+
fields: { path: request.path, revision: request.revision },
|
|
353
282
|
};
|
|
354
283
|
}
|
|
355
|
-
if (typeof named.content !== 'string')
|
|
356
|
-
kind: 'transport-uncertainty'
|
|
357
|
-
};
|
|
358
|
-
return {
|
|
359
|
-
kind: 'revision',
|
|
360
|
-
content: named.content
|
|
361
|
-
};
|
|
284
|
+
if (typeof named.content !== 'string')
|
|
285
|
+
return { kind: 'transport-uncertainty' };
|
|
286
|
+
return { kind: 'revision', content: named.content };
|
|
362
287
|
}
|
|
363
|
-
if (entries.length === 0)
|
|
364
|
-
kind: 'no-history'
|
|
365
|
-
};
|
|
288
|
+
if (entries.length === 0)
|
|
289
|
+
return { kind: 'no-history' };
|
|
366
290
|
const revisions = [];
|
|
367
|
-
for (const entry of entries){
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
291
|
+
for (const entry of entries) {
|
|
292
|
+
const author = revisionAuthor(entry);
|
|
293
|
+
if (typeof entry.revision !== 'string' ||
|
|
294
|
+
author === null ||
|
|
295
|
+
typeof entry.created_at !== 'string') {
|
|
296
|
+
return { kind: 'transport-uncertainty' };
|
|
372
297
|
}
|
|
373
|
-
revisions.push({
|
|
374
|
-
revision: entry.revision,
|
|
375
|
-
author: entry.author_user,
|
|
376
|
-
time: entry.created_at
|
|
377
|
-
});
|
|
298
|
+
revisions.push({ revision: entry.revision, author, time: entry.created_at });
|
|
378
299
|
}
|
|
379
300
|
const next = held.next_before;
|
|
380
301
|
return {
|
|
381
302
|
kind: 'history',
|
|
382
303
|
revisions,
|
|
383
|
-
...typeof next === 'number' ? {
|
|
384
|
-
pageToken: String(next)
|
|
385
|
-
} : {}
|
|
304
|
+
...(typeof next === 'number' ? { pageToken: String(next) } : {}),
|
|
386
305
|
};
|
|
387
306
|
}
|
|
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-c055ce6f0fdd0",
|
|
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-
|
|
37
|
-
"@agentshouse/mdruntime": "0.1.0-
|
|
28
|
+
"@agentshouse/mdmodel": "0.1.0-c6b0c6dc1a195",
|
|
29
|
+
"@agentshouse/mdruntime": "0.1.0-ca9a5a0b81b98"
|
|
38
30
|
}
|
|
39
31
|
}
|
package/dist/actions.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/actions.ts"],"sourcesContent":["import { VERSION } from '@agentshouse/mdmodel';\nimport {\n changeBatchIdentity,\n type ActionDeclaration,\n type ActionRequest,\n type ActionResult,\n type ConversationCards,\n} from '@agentshouse/mdruntime';\nimport { doorRefusal } from './refusal.js';\nimport { PRIVATE_AUTHORITY } from './transport.js';\nimport type { HouseDoor, HouseDoorAnswer, HouseTransport } from './transport.js';\n\nexport const CONVERSATION_ACTIONS = [\n 'conversation.create',\n 'conversation.send',\n 'conversation.answer',\n 'conversation.interrupt',\n 'conversation.kill',\n 'conversation.cancel',\n 'conversation.delete',\n 'conversation.history',\n] as const;\n\nexport const HOUSE_ACTS = [\n 'conversations/interaction/read',\n 'conversations/originals/read',\n 'apps/read',\n 'apps/customize',\n 'rooms/read',\n 'rooms/access/read',\n 'rooms/access/invitations',\n 'rooms/access/entries',\n 'rooms/access/invite',\n 'rooms/access/invitation-cancel',\n 'rooms/access/revoke',\n 'rooms/access/leave',\n 'rooms/roles/define',\n 'rooms/roles/remove',\n 'rooms/roles/assign',\n 'rooms/roles/unassign',\n 'rooms/settings/processing/read',\n 'rooms/settings/processing/write',\n 'profiles/create',\n 'profiles/read',\n 'profiles/edit',\n 'profiles/duplicate',\n 'profiles/delegate',\n 'agents/create',\n 'agents/read',\n 'routines/requests',\n 'routines/access',\n 'routines/owned',\n 'routines/granted',\n 'routines/grant',\n 'routines/send',\n 'routines/cancel',\n 'routines/start',\n 'routines/schedules',\n 'routines/schedules/create',\n 'routines/schedules/enabled',\n 'account/security/read',\n 'storage/inventory',\n 'storage/usage',\n 'usage/statement',\n 'storage/blob-store',\n 'storage/blob-store/select',\n 'storage/connections',\n 'storage/archive',\n 'storage/archive/status',\n 'environments/read',\n 'environments/create',\n 'environments/start',\n 'environments/stop',\n 'environments/delete',\n 'environments/renewals/read',\n 'environments/work/read',\n 'nodes/read',\n] as const;\n\nexport const HOUSE_PROVIDER_ACTIONS = [...CONVERSATION_ACTIONS, ...HOUSE_ACTS] as const;\n\nconst DECLARED = new Set<string>(HOUSE_PROVIDER_ACTIONS);\n\nexport const HISTORY_PAGE = 100;\n\nconst OCTET_STREAM = 'application/octet-stream';\n\nconst CONVERSATION_ROUTES: Readonly<Record<string, string>> = {\n 'conversation.create': '/door/conversations/create',\n 'conversation.send': '/door/conversations/send',\n 'conversation.answer': '/door/conversations/interaction/answer',\n 'conversation.interrupt': '/door/conversations/interrupt',\n 'conversation.kill': '/door/conversations/kill',\n 'conversation.cancel': '/door/conversations/cancel',\n 'conversation.delete': '/door/conversations/delete',\n 'conversation.history': '/door/conversations/history',\n 'conversations/interaction/read': '/door/conversations/interaction/read',\n 'conversations/originals/read': '/door/conversations/originals/read',\n};\n\nexport const HOUSE_CONVERSATION_CARDS: ConversationCards = {\n locator: PRIVATE_AUTHORITY,\n type: 'conversation',\n identity: 'conversation',\n agent: 'agent',\n};\n\nexport function declaredActions(): readonly ActionDeclaration[] {\n return HOUSE_PROVIDER_ACTIONS.map((name) => ({\n name,\n inputShape: {},\n resultKind: 'house',\n }));\n}\n\nexport function houseAction(\n transport: HouseTransport,\n request: ActionRequest,\n): Promise<ActionResult> {\n if (!DECLARED.has(request.name)) {\n return Promise.resolve({\n kind: 'rejected',\n code: 'action-unimplemented',\n fields: { name: request.name, mdModel: VERSION },\n });\n }\n if (request.name === 'conversation.send') return sendAction(transport, request.input);\n if (request.name === 'conversation.history') return historyAction(transport, request.input);\n return carry(transport, request.name, request.input);\n}\n\nfunction routeOf(name: string): string {\n return CONVERSATION_ROUTES[name] ?? `/door/${name}`;\n}\n\nfunction record(value: unknown): Record<string, unknown> {\n return typeof value === 'object' && value !== null ? (value as Record<string, unknown>) : {};\n}\n\nfunction text(value: unknown, name: string): string | undefined {\n const held = record(value)[name];\n return typeof held === 'string' ? held : undefined;\n}\n\nfunction operationId(input: unknown): string {\n return text(input, 'operation_id') ?? changeBatchIdentity();\n}\n\nfunction malformed(): ActionResult {\n return { kind: 'rejected', code: 'invalid_request', fields: {} };\n}\n\nfunction bodyOf(name: string, input: unknown): unknown {\n if (name === 'conversation.create') {\n return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };\n }\n if (\n name === 'conversation.interrupt' ||\n name === 'conversation.kill' ||\n name === 'conversation.delete'\n ) {\n return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };\n }\n if (name === 'conversation.cancel') {\n return {\n conversation_id: text(input, 'conversation'),\n message_id: text(input, 'turn'),\n operation_id: operationId(input),\n };\n }\n if (name === 'conversation.answer') {\n const nested = record(record(input).answer);\n return {\n conversation_id: text(input, 'conversation'),\n operation_id: operationId(input),\n interaction_id: text(nested, 'interaction_id'),\n revision: nested.revision,\n response: nested.response,\n };\n }\n return input;\n}\n\nfunction withTurn(body: unknown): unknown {\n const held = record(body);\n const turn = text(held, 'message_id');\n return turn === undefined ? body : { ...held, turn };\n}\n\nexport function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult {\n if (answer.status === 401) return { kind: 'revoked-authorization' };\n const refusal = doorRefusal(answer.body);\n if (refusal !== null) {\n return { kind: 'rejected', code: refusal.code, fields: refusal.fields };\n }\n if (answer.status === 0 || answer.status >= 400) return { kind: 'transport-uncertainty' };\n if (name === 'conversation.send') return { kind: 'action', result: withTurn(answer.body) };\n return { kind: 'action', result: answer.body };\n}\n\nasync function carry(\n transport: HouseTransport,\n name: string,\n input: unknown,\n): Promise<ActionResult> {\n const answer = await transport.door(routeOf(name), bodyOf(name, input));\n return actionOutcome(answer, name);\n}\n\nfunction sendFile(entry: unknown): Record<string, unknown> | null {\n const file = record(entry);\n const name = text(file, 'name');\n const bytes = file.byteLength;\n const sha256 = text(file, 'contentHash');\n if (name === undefined || typeof bytes !== 'number' || sha256 === undefined) return null;\n const mediaType = text(file, 'mediaType');\n const width = file.width;\n const height = file.height;\n return {\n name,\n media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,\n bytes,\n sha256,\n ...(typeof width === 'number' && typeof height === 'number'\n ? { dimensions: { width, height } }\n : {}),\n };\n}\n\nfunction sendFiles(input: unknown): readonly Record<string, unknown>[] | null {\n const files = record(input).files;\n if (files === undefined) return [];\n if (!Array.isArray(files)) return null;\n const declared: Record<string, unknown>[] = [];\n for (const entry of files) {\n const file = sendFile(entry);\n if (file === null) return null;\n declared.push(file);\n }\n return declared;\n}\n\nfunction sendBody(input: unknown): Record<string, unknown> | null {\n const files = sendFiles(input);\n if (files === null) return null;\n const textValue = text(input, 'text');\n return {\n conversation_id: text(input, 'conversation'),\n operation_id: operationId(input),\n ...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),\n ...(files.length === 0 ? {} : { files }),\n };\n}\n\nasync function fileBytes(file: unknown): Promise<Uint8Array | null> {\n const blob = record(file).blob;\n if (blob === undefined || typeof blob !== 'object' || blob === null) return null;\n if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function') return null;\n return new Uint8Array(await (blob as Blob).arrayBuffer());\n}\n\nfunction uploadGrant(\n entry: unknown,\n): { method: 'POST'; operation: string; url: string } | 'absent' | null {\n if (!('upload' in record(entry))) return 'absent';\n const upload = record(record(entry).upload);\n if (upload.method !== 'POST') return null;\n if (typeof upload.operation !== 'string' || typeof upload.url !== 'string') return null;\n return { method: 'POST', operation: upload.operation, url: upload.url };\n}\n\nasync function uploadOriginals(\n transport: HouseTransport,\n input: unknown,\n result: unknown,\n): Promise<ActionResult | null> {\n const originals = record(result).originals;\n if (!Array.isArray(originals) || originals.length === 0) return null;\n const files = Array.isArray(record(input).files) ? (record(input).files as unknown[]) : [];\n for (const [index, entry] of originals.entries()) {\n const grant = uploadGrant(entry);\n if (grant === 'absent') continue;\n if (grant === null) return malformed();\n const bytes = index < files.length ? await fileBytes(files[index]) : null;\n if (bytes === null) {\n return { kind: 'rejected', code: 'conversation_original_descriptor_required', fields: {} };\n }\n const delivered = await transport.transfer({\n act: 'conversation_original_upload',\n method: 'POST',\n url: grant.url,\n body: bytes,\n operation: grant.operation,\n });\n if (delivered.status === 200) continue;\n return actionOutcome(delivered, 'conversation.send');\n }\n return null;\n}\n\nasync function sendAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const body = sendBody(input);\n if (body === null) return malformed();\n const answer = await transport.door('/door/conversations/send', body);\n const outcome = actionOutcome(answer, 'conversation.send');\n if (outcome.kind !== 'action') return outcome;\n const uploaded = await uploadOriginals(transport, input, outcome.result);\n if (uploaded !== null) return uploaded;\n return outcome;\n}\n\ntype HistoryCursor = { accepted_at: string; message_id: string };\n\nfunction historyCursor(value: string): HistoryCursor | null {\n let parsed: unknown;\n try {\n parsed = JSON.parse(value) as unknown;\n } catch {\n return null;\n }\n const acceptedAt = text(parsed, 'accepted_at');\n const messageId = text(parsed, 'message_id');\n if (acceptedAt === undefined || messageId === undefined) return null;\n return { accepted_at: acceptedAt, message_id: messageId };\n}\n\nfunction turned(entry: unknown): { turn: string; message: unknown } | null {\n const turn = text(entry, 'message_id');\n if (turn === undefined) return null;\n return { turn, message: structuredClone(entry) };\n}\n\nfunction olderCursor(entry: { message: unknown }): string | null {\n const acceptedAt = text(entry.message, 'accepted_at');\n const messageId = text(entry.message, 'message_id');\n if (acceptedAt === undefined || messageId === undefined) return null;\n return JSON.stringify({ accepted_at: acceptedAt, message_id: messageId });\n}\n\nexport async function readConversationHistory(\n transport: HouseDoor,\n conversationId: string,\n): Promise<{ messages: unknown[] } | { outcome: ActionResult }> {\n const messages: unknown[] = [];\n let after: HistoryCursor | undefined;\n for (;;) {\n const answer = await transport.door('/door/conversations/history', {\n conversation_id: conversationId,\n ...(after === undefined ? {} : { after }),\n limit: HISTORY_PAGE,\n });\n const outcome = actionOutcome(answer, 'conversation.history');\n if (outcome.kind !== 'action') return { outcome };\n const held = record(outcome.result);\n if (!Array.isArray(held.messages)) return { outcome: { kind: 'transport-uncertainty' } };\n for (const entry of held.messages) {\n if (text(entry, 'message_id') === undefined) {\n return { outcome: { kind: 'transport-uncertainty' } };\n }\n messages.push(entry);\n }\n if (held.next === null || held.next === undefined) return { messages };\n const next = record(held.next);\n const acceptedAt = text(next, 'accepted_at');\n const messageId = text(next, 'message_id');\n if (acceptedAt === undefined || messageId === undefined) {\n return { outcome: { kind: 'transport-uncertainty' } };\n }\n after = { accepted_at: acceptedAt, message_id: messageId };\n }\n}\n\nfunction historyPage(\n conversationId: string,\n messages: readonly { turn: string; message: unknown }[],\n until: number,\n): ActionResult {\n const from = Math.max(0, until - HISTORY_PAGE);\n const page = messages.slice(from, until);\n const first = page[0];\n const cursor = from === 0 || first === undefined ? null : olderCursor(first);\n if (from > 0 && cursor === null) return { kind: 'transport-uncertainty' };\n return {\n kind: 'action',\n result: {\n conversation_id: conversationId,\n messages: page,\n ...(cursor === null ? {} : { cursor }),\n },\n };\n}\n\nasync function historyAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const conversationId = text(input, 'conversation');\n if (conversationId === undefined) return malformed();\n const cursorValue = text(input, 'cursor');\n let olderThan: HistoryCursor | undefined;\n if (cursorValue !== undefined) {\n const parsed = historyCursor(cursorValue);\n if (parsed === null) {\n return { kind: 'rejected', code: 'unknown-cursor', fields: { cursor: cursorValue } };\n }\n olderThan = parsed;\n }\n const held = await readConversationHistory(transport, conversationId);\n if ('outcome' in held) return held.outcome;\n const messages: { turn: string; message: unknown }[] = [];\n for (const entry of held.messages) {\n const mapped = turned(entry);\n if (mapped === null) return { kind: 'transport-uncertainty' };\n messages.push(mapped);\n }\n if (olderThan === undefined) {\n return historyPage(conversationId, messages, messages.length);\n }\n const at = messages.findIndex(\n (entry) =>\n text(entry.message, 'accepted_at') === olderThan.accepted_at &&\n text(entry.message, 'message_id') === olderThan.message_id,\n );\n if (at === -1) {\n return { kind: 'rejected', code: 'unknown-cursor', fields: { cursor: cursorValue } };\n }\n return historyPage(conversationId, messages, at);\n}\n"],"names":["VERSION","changeBatchIdentity","doorRefusal","PRIVATE_AUTHORITY","CONVERSATION_ACTIONS","HOUSE_ACTS","HOUSE_PROVIDER_ACTIONS","DECLARED","Set","HISTORY_PAGE","OCTET_STREAM","CONVERSATION_ROUTES","HOUSE_CONVERSATION_CARDS","locator","type","identity","agent","declaredActions","map","name","inputShape","resultKind","houseAction","transport","request","has","Promise","resolve","kind","code","fields","mdModel","sendAction","input","historyAction","carry","routeOf","record","value","text","held","undefined","operationId","malformed","bodyOf","agent_id","operation_id","conversation_id","message_id","nested","answer","interaction_id","revision","response","withTurn","body","turn","actionOutcome","status","refusal","result","door","sendFile","entry","file","bytes","byteLength","sha256","mediaType","width","height","media_type","length","dimensions","sendFiles","files","Array","isArray","declared","push","sendBody","textValue","fileBytes","blob","arrayBuffer","Uint8Array","uploadGrant","upload","method","operation","url","uploadOriginals","originals","index","entries","grant","delivered","transfer","act","outcome","uploaded","historyCursor","parsed","JSON","parse","acceptedAt","messageId","accepted_at","turned","message","structuredClone","olderCursor","stringify","readConversationHistory","conversationId","messages","after","limit","next","historyPage","until","from","Math","max","page","slice","first","cursor","cursorValue","olderThan","mapped","at","findIndex"],"mappings":"AAAA,SAASA,OAAO,QAAQ,uBAAuB;AAC/C,SACEC,mBAAmB,QAKd,yBAAyB;AAChC,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,iBAAiB,QAAQ,iBAAiB;AAGnD,OAAO,MAAMC,uBAAuB;IAClC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAU;AAEX,OAAO,MAAMC,aAAa;IACxB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAU;AAEX,OAAO,MAAMC,yBAAyB;OAAIF;OAAyBC;CAAW,CAAU;AAExF,MAAME,WAAW,IAAIC,IAAYF;AAEjC,OAAO,MAAMG,eAAe,IAAI;AAEhC,MAAMC,eAAe;AAErB,MAAMC,sBAAwD;IAC5D,uBAAuB;IACvB,qBAAqB;IACrB,uBAAuB;IACvB,0BAA0B;IAC1B,qBAAqB;IACrB,uBAAuB;IACvB,uBAAuB;IACvB,wBAAwB;IACxB,kCAAkC;IAClC,gCAAgC;AAClC;AAEA,OAAO,MAAMC,2BAA8C;IACzDC,SAASV;IACTW,MAAM;IACNC,UAAU;IACVC,OAAO;AACT,EAAE;AAEF,OAAO,SAASC;IACd,OAAOX,uBAAuBY,GAAG,CAAC,CAACC,OAAU,CAAA;YAC3CA;YACAC,YAAY,CAAC;YACbC,YAAY;QACd,CAAA;AACF;AAEA,OAAO,SAASC,YACdC,SAAyB,EACzBC,OAAsB;IAEtB,IAAI,CAACjB,SAASkB,GAAG,CAACD,QAAQL,IAAI,GAAG;QAC/B,OAAOO,QAAQC,OAAO,CAAC;YACrBC,MAA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