@agentshouse/mdruntime-adapter 0.1.0-alpha.8 → 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 +256 -216
- 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 +19 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +135 -208
- 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,271 +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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
101
|
+
return { kind: 'changes', changes };
|
|
102
|
+
}
|
|
103
|
+
export function operationHead(batch) {
|
|
104
|
+
const writer = batch.writtenBy;
|
|
105
|
+
return writer === undefined
|
|
106
|
+
? { operation_id: batch.id }
|
|
107
|
+
: { operation_id: batch.id, app_ref: writer.app, release: writer.release };
|
|
152
108
|
}
|
|
153
109
|
export function batchPaths(changes) {
|
|
154
110
|
return [
|
|
155
|
-
...new Set(changes.flatMap((change)=>change.op === 'rename' ? [
|
|
156
|
-
String(change.path),
|
|
157
|
-
String(change.to)
|
|
158
|
-
] : [
|
|
159
|
-
String(change.path)
|
|
160
|
-
]))
|
|
111
|
+
...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
161
112
|
].sort();
|
|
162
113
|
}
|
|
163
114
|
export function deltaBody(changes) {
|
|
164
|
-
return JSON.stringify({
|
|
165
|
-
changes
|
|
166
|
-
});
|
|
115
|
+
return JSON.stringify({ changes });
|
|
167
116
|
}
|
|
168
117
|
export function deltaBytes(delta) {
|
|
169
118
|
return textBytes(delta);
|
|
170
119
|
}
|
|
171
|
-
export function uploadable(bytes) {
|
|
172
|
-
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);
|
|
173
123
|
}
|
|
174
124
|
export function deltaDigest(delta) {
|
|
175
125
|
return sha256Hex(delta);
|
|
176
126
|
}
|
|
177
127
|
function material(value, handle) {
|
|
178
|
-
if (!Array.isArray(value))
|
|
128
|
+
if (!Array.isArray(value))
|
|
129
|
+
return null;
|
|
179
130
|
const held = [];
|
|
180
|
-
for (const entry of value){
|
|
181
|
-
if (typeof entry !== 'object' || entry === null)
|
|
131
|
+
for (const entry of value) {
|
|
132
|
+
if (typeof entry !== 'object' || entry === null)
|
|
133
|
+
return null;
|
|
182
134
|
const file = entry;
|
|
183
|
-
if (typeof file.path !== 'string')
|
|
184
|
-
|
|
185
|
-
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;
|
|
186
141
|
let path;
|
|
187
142
|
try {
|
|
188
143
|
path = roomLocalPath(file.path, handle);
|
|
189
|
-
}
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
190
146
|
return null;
|
|
191
147
|
}
|
|
192
148
|
held.push({
|
|
193
149
|
path,
|
|
194
150
|
content: file.content,
|
|
195
|
-
revision: typeof file.revision === 'string' ? file.revision : null
|
|
151
|
+
revision: typeof file.revision === 'string' ? file.revision : null,
|
|
196
152
|
});
|
|
197
153
|
}
|
|
198
154
|
return held;
|
|
199
155
|
}
|
|
200
156
|
function affectedOf(held) {
|
|
201
157
|
const affected = {};
|
|
202
|
-
for (const entry of held){
|
|
203
|
-
if (entry.content !== null)
|
|
158
|
+
for (const entry of held) {
|
|
159
|
+
if (entry.content !== null)
|
|
160
|
+
affected[entry.path] = entry.content;
|
|
204
161
|
}
|
|
205
162
|
return affected;
|
|
206
163
|
}
|
|
207
164
|
export function mutationOutcome(status, body, locator, handle) {
|
|
208
165
|
const refusal = doorRefusal(body);
|
|
209
|
-
if (refusal !== null && refusal.code === '
|
|
210
|
-
|
|
211
|
-
return {
|
|
212
|
-
kind: 'retryable-refusal',
|
|
213
|
-
code: refusal.code,
|
|
214
|
-
fields: refusal.fields,
|
|
215
|
-
...typeof reset === 'string' ? {
|
|
216
|
-
reset
|
|
217
|
-
} : {}
|
|
218
|
-
};
|
|
166
|
+
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
167
|
+
return { kind: 'write-halted' };
|
|
219
168
|
}
|
|
220
|
-
if (refusal !== null && refusal.code === 'operation_expired')
|
|
221
|
-
kind: 'expired'
|
|
222
|
-
};
|
|
169
|
+
if (refusal !== null && refusal.code === 'operation_expired')
|
|
170
|
+
return { kind: 'expired' };
|
|
223
171
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
224
172
|
const { current, ...fields } = refusal.fields;
|
|
225
173
|
const held = material(current, handle) ?? [];
|
|
226
|
-
return {
|
|
227
|
-
kind: 'conflicted',
|
|
228
|
-
affected: affectedOf(held),
|
|
229
|
-
code: refusal.code,
|
|
230
|
-
fields
|
|
231
|
-
};
|
|
174
|
+
return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };
|
|
232
175
|
}
|
|
233
176
|
if (refusal !== null && status === 404) {
|
|
234
177
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
235
178
|
}
|
|
236
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
|
+
}
|
|
237
186
|
if (classified !== null && classified.kind !== 'scoped-refusal') {
|
|
238
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
239
|
-
kind: 'expired'
|
|
240
|
-
} : classified;
|
|
187
|
+
return classified.kind === 'beyond-horizon' ? { kind: 'expired' } : classified;
|
|
241
188
|
}
|
|
242
|
-
if (classified !== null && status === 403)
|
|
189
|
+
if (classified !== null && status === 403)
|
|
190
|
+
return classified;
|
|
243
191
|
if (refusal !== null && status >= 400) {
|
|
244
|
-
return {
|
|
245
|
-
kind: 'rejected',
|
|
246
|
-
affected: {},
|
|
247
|
-
code: refusal.code,
|
|
248
|
-
fields: refusal.fields
|
|
249
|
-
};
|
|
192
|
+
return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
|
|
250
193
|
}
|
|
251
194
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
252
|
-
return {
|
|
253
|
-
kind: 'transport-uncertainty'
|
|
254
|
-
};
|
|
195
|
+
return { kind: 'transport-uncertainty' };
|
|
255
196
|
}
|
|
256
197
|
const held = body;
|
|
257
198
|
const at = readPosition(held);
|
|
258
|
-
if (at === null)
|
|
259
|
-
kind: 'transport-uncertainty'
|
|
260
|
-
};
|
|
199
|
+
if (at === null)
|
|
200
|
+
return { kind: 'transport-uncertainty' };
|
|
261
201
|
const contents = material(held.contents, handle);
|
|
262
|
-
if (contents === null)
|
|
263
|
-
kind: 'transport-uncertainty'
|
|
264
|
-
|
|
202
|
+
if (contents === null)
|
|
203
|
+
return { kind: 'transport-uncertainty' };
|
|
204
|
+
const originals = parseOriginals(held.originals);
|
|
205
|
+
if (originals === null)
|
|
206
|
+
return { kind: 'transport-uncertainty' };
|
|
265
207
|
const documents = {};
|
|
266
208
|
const revisions = {};
|
|
267
209
|
const removals = [];
|
|
268
|
-
for (const entry of contents){
|
|
210
|
+
for (const entry of contents) {
|
|
269
211
|
if (entry.content === null || entry.revision === null) {
|
|
270
212
|
removals.push(entry.path);
|
|
271
213
|
continue;
|
|
@@ -278,7 +220,8 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
278
220
|
roomVersion: roomVersion(at),
|
|
279
221
|
documents,
|
|
280
222
|
revisions,
|
|
281
|
-
removals: removals.sort()
|
|
223
|
+
removals: removals.sort(),
|
|
224
|
+
originals,
|
|
282
225
|
};
|
|
283
226
|
}
|
|
284
227
|
export function rejectedMapping(mapping) {
|
|
@@ -286,94 +229,78 @@ export function rejectedMapping(mapping) {
|
|
|
286
229
|
kind: 'rejected',
|
|
287
230
|
affected: {},
|
|
288
231
|
code: mapping.rule,
|
|
289
|
-
fields: {
|
|
290
|
-
path: mapping.path
|
|
291
|
-
}
|
|
232
|
+
fields: { path: mapping.path },
|
|
292
233
|
};
|
|
293
234
|
}
|
|
294
235
|
export function revisionBody(input) {
|
|
295
236
|
return {
|
|
296
237
|
path: nativePath(input.path, input.handle),
|
|
297
|
-
...input.revision === undefined ? {} : {
|
|
298
|
-
|
|
299
|
-
},
|
|
300
|
-
...input.pageToken === undefined ? {} : {
|
|
301
|
-
before: Number(input.pageToken)
|
|
302
|
-
}
|
|
238
|
+
...(input.revision === undefined ? {} : { revision: input.revision }),
|
|
239
|
+
...(input.pageToken === undefined ? {} : { before: Number(input.pageToken) }),
|
|
303
240
|
};
|
|
304
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
|
+
}
|
|
305
254
|
export function historyOutcome(status, body, locator, request) {
|
|
306
255
|
const classified = classifyDoor(status, body, locator);
|
|
307
256
|
if (classified !== null) {
|
|
308
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
309
|
-
kind: 'transport-uncertainty'
|
|
310
|
-
} : classified;
|
|
257
|
+
return classified.kind === 'beyond-horizon' ? { kind: 'transport-uncertainty' } : classified;
|
|
311
258
|
}
|
|
312
259
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
313
|
-
return {
|
|
314
|
-
kind: 'transport-uncertainty'
|
|
315
|
-
};
|
|
260
|
+
return { kind: 'transport-uncertainty' };
|
|
316
261
|
}
|
|
317
262
|
const held = body;
|
|
318
|
-
if (!Array.isArray(held.revisions))
|
|
319
|
-
kind: 'transport-uncertainty'
|
|
320
|
-
};
|
|
263
|
+
if (!Array.isArray(held.revisions))
|
|
264
|
+
return { kind: 'transport-uncertainty' };
|
|
321
265
|
const entries = [];
|
|
322
|
-
for (const entry of held.revisions){
|
|
323
|
-
if (typeof entry !== 'object' || entry === null)
|
|
324
|
-
kind: 'transport-uncertainty'
|
|
325
|
-
};
|
|
266
|
+
for (const entry of held.revisions) {
|
|
267
|
+
if (typeof entry !== 'object' || entry === null)
|
|
268
|
+
return { kind: 'transport-uncertainty' };
|
|
326
269
|
entries.push(entry);
|
|
327
270
|
}
|
|
328
271
|
if (request.revision !== undefined) {
|
|
329
272
|
const named = entries[0];
|
|
330
|
-
if (named === undefined)
|
|
331
|
-
kind: 'no-history'
|
|
332
|
-
};
|
|
273
|
+
if (named === undefined)
|
|
274
|
+
return { kind: 'no-history' };
|
|
333
275
|
if (named.unavailable === true) {
|
|
334
276
|
return {
|
|
335
277
|
kind: 'scoped-refusal',
|
|
336
278
|
locator,
|
|
337
279
|
scope: 'content',
|
|
338
280
|
code: 'retained_history_unavailable',
|
|
339
|
-
fields: {
|
|
340
|
-
path: request.path,
|
|
341
|
-
revision: request.revision
|
|
342
|
-
}
|
|
281
|
+
fields: { path: request.path, revision: request.revision },
|
|
343
282
|
};
|
|
344
283
|
}
|
|
345
|
-
if (typeof named.content !== 'string')
|
|
346
|
-
kind: 'transport-uncertainty'
|
|
347
|
-
};
|
|
348
|
-
return {
|
|
349
|
-
kind: 'revision',
|
|
350
|
-
content: named.content
|
|
351
|
-
};
|
|
284
|
+
if (typeof named.content !== 'string')
|
|
285
|
+
return { kind: 'transport-uncertainty' };
|
|
286
|
+
return { kind: 'revision', content: named.content };
|
|
352
287
|
}
|
|
353
|
-
if (entries.length === 0)
|
|
354
|
-
kind: 'no-history'
|
|
355
|
-
};
|
|
288
|
+
if (entries.length === 0)
|
|
289
|
+
return { kind: 'no-history' };
|
|
356
290
|
const revisions = [];
|
|
357
|
-
for (const entry of entries){
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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' };
|
|
362
297
|
}
|
|
363
|
-
revisions.push({
|
|
364
|
-
revision: entry.revision,
|
|
365
|
-
author: entry.author_user,
|
|
366
|
-
time: entry.created_at
|
|
367
|
-
});
|
|
298
|
+
revisions.push({ revision: entry.revision, author, time: entry.created_at });
|
|
368
299
|
}
|
|
369
300
|
const next = held.next_before;
|
|
370
301
|
return {
|
|
371
302
|
kind: 'history',
|
|
372
303
|
revisions,
|
|
373
|
-
...typeof next === 'number' ? {
|
|
374
|
-
pageToken: String(next)
|
|
375
|
-
} : {}
|
|
304
|
+
...(typeof next === 'number' ? { pageToken: String(next) } : {}),
|
|
376
305
|
};
|
|
377
306
|
}
|
|
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-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,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