@agentshouse/mdruntime-adapter 0.1.0-c38cdd8a6d962 → 0.1.0-c38f28dbe538b
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/README.md +3 -3
- package/dist/actions.d.ts +15 -6
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +198 -324
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +309 -228
- package/dist/authored-path.d.ts +61 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +166 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +281 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +46 -20
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +265 -67
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -6
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +35 -38
- package/dist/read.d.ts +55 -48
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +209 -265
- package/dist/refusal.d.ts +9 -11
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +54 -27
- package/dist/renamed.d.ts +10 -0
- package/dist/renamed.d.ts.map +1 -0
- package/dist/renamed.js +20 -0
- package/dist/room-query.d.ts +4 -0
- package/dist/room-query.d.ts.map +1 -0
- package/dist/room-query.js +63 -0
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/check.d.ts +17 -0
- package/dist/session-content/index.d.ts +6 -0
- package/dist/session-content/parts.d.ts +30 -0
- package/dist/session-content/state.d.ts +59 -0
- package/dist/session-content/turn.d.ts +137 -0
- package/dist/site.d.ts +1 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +161 -108
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +14 -13
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +281 -149
- package/dist/transport.d.ts +131 -31
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +90 -10
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +17 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +106 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/write.d.ts +15 -12
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +223 -134
- package/package.json +11 -7
- package/AGENTS.md +0 -238
- package/dist/gather.d.ts +0 -3
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -40
- package/dist/links.d.ts +0 -20
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -104
package/dist/write.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { departure, isPart, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { answered, answering, attachmentOf, headChange, revised } from './read.js';
|
|
2
3
|
import { sha256Hex, textBytes } from './digest.js';
|
|
3
4
|
import { nativePath, roomLocalPath } from './map.js';
|
|
4
|
-
import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
|
|
5
|
+
import { answeredFailure, classifyDoor, doorRefusal, resetOf, scopedRefusal } from './refusal.js';
|
|
5
6
|
import { readPosition, roomVersion } from './version.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
function priorPreamble(batch, path) {
|
|
13
|
-
return batch.preconditions.find((precondition) => precondition.kind === 'preamble' && precondition.path === path);
|
|
7
|
+
import { unusable } from './uncertain.js';
|
|
8
|
+
function priorPart(batch, change) {
|
|
9
|
+
return batch.preconditions.find((held) => held.kind === change.kind &&
|
|
10
|
+
held.path === change.path &&
|
|
11
|
+
(change.kind === 'preamble' || ('name' in held && held.name === change.name)));
|
|
14
12
|
}
|
|
15
13
|
function priorAbsence(batch, path) {
|
|
16
14
|
return batch.preconditions.find((precondition) => precondition.kind === 'absent' && precondition.path === path);
|
|
@@ -21,95 +19,120 @@ function priorExistence(batch, path) {
|
|
|
21
19
|
return undefined;
|
|
22
20
|
return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };
|
|
23
21
|
}
|
|
24
|
-
function
|
|
25
|
-
if (
|
|
26
|
-
return {
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
function textOf(batch, change, path, document) {
|
|
23
|
+
if (isPart(change) && priorPart(batch, change) === undefined)
|
|
24
|
+
return { rule: 'precondition-missing' };
|
|
25
|
+
if (change.kind === 'create' && priorAbsence(batch, change.path) === undefined)
|
|
26
|
+
return { rule: 'precondition-missing' };
|
|
27
|
+
if (change.kind === 'replace' && priorExistence(batch, change.path) === undefined)
|
|
28
|
+
return { rule: 'precondition-missing' };
|
|
29
|
+
if (document === null || document === undefined)
|
|
29
30
|
return null;
|
|
30
|
-
|
|
31
|
+
if (document.stale)
|
|
32
|
+
return { rule: 'precondition-stale' };
|
|
33
|
+
if (document.created)
|
|
34
|
+
return { operation: { op: 'write', path, content: document.content } };
|
|
35
|
+
if (document.base === null)
|
|
36
|
+
return { rule: 'presence-base-unrepresentable' };
|
|
37
|
+
return { operation: { op: 'write', path, base: document.base, content: document.content } };
|
|
31
38
|
}
|
|
32
|
-
function operationOf(batch,
|
|
39
|
+
function operationOf(batch, index, handle, written) {
|
|
40
|
+
const change = batch.changes[index];
|
|
33
41
|
const path = nativePath(change.path, handle);
|
|
34
|
-
if (change.kind === '
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
...(prior.value === undefined ? {} : { base: prior.value }),
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (change.kind === 'section') {
|
|
49
|
-
const prior = priorSection(batch, change.path, change.name);
|
|
50
|
-
if (prior === undefined)
|
|
51
|
-
return { rule: 'precondition-missing' };
|
|
52
|
-
return {
|
|
53
|
-
operation: {
|
|
54
|
-
op: 'replace_section',
|
|
55
|
-
path,
|
|
56
|
-
section: change.name,
|
|
57
|
-
base: prior.value,
|
|
58
|
-
content: change.value,
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
if (change.kind === 'preamble') {
|
|
63
|
-
const prior = priorPreamble(batch, change.path);
|
|
64
|
-
if (prior === undefined)
|
|
65
|
-
return { rule: 'precondition-missing' };
|
|
66
|
-
return {
|
|
67
|
-
operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },
|
|
42
|
+
if (isPart(change) || change.kind === 'create' || change.kind === 'replace')
|
|
43
|
+
return textOf(batch, change, path, written[index]);
|
|
44
|
+
if (change.kind === 'binary') {
|
|
45
|
+
const uploaded = {
|
|
46
|
+
op: 'upload',
|
|
47
|
+
path,
|
|
48
|
+
local_id: change.localId,
|
|
49
|
+
bytes: change.byteLength,
|
|
50
|
+
sha256: change.sha256,
|
|
51
|
+
media_type: change.mediaType,
|
|
68
52
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
const from = departure(batch.changes, index);
|
|
54
|
+
if (from === change.path && priorAbsence(batch, change.path) !== undefined)
|
|
55
|
+
return { operation: uploaded };
|
|
56
|
+
const replaced = priorExistence(batch, from);
|
|
57
|
+
if (replaced === undefined)
|
|
72
58
|
return { rule: 'precondition-missing' };
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
if (!('base' in replaced))
|
|
60
|
+
return { rule: 'presence-base-unrepresentable' };
|
|
61
|
+
return { operation: { ...uploaded, base: replaced.base } };
|
|
75
62
|
}
|
|
76
63
|
const existence = priorExistence(batch, change.path);
|
|
77
64
|
if (existence === undefined)
|
|
78
65
|
return { rule: 'precondition-missing' };
|
|
79
66
|
if (!('base' in existence))
|
|
80
67
|
return { rule: 'presence-base-unrepresentable' };
|
|
81
|
-
if (change.kind === 'replace') {
|
|
82
|
-
return { operation: { op: 'replace', path, base: existence.base, content: change.content } };
|
|
83
|
-
}
|
|
84
68
|
if (change.kind === 'move') {
|
|
85
69
|
if (priorAbsence(batch, change.to) === undefined)
|
|
86
70
|
return { rule: 'precondition-missing' };
|
|
87
71
|
return {
|
|
88
|
-
operation: { op: '
|
|
72
|
+
operation: { op: 'move', path, to: nativePath(change.to, handle), base: existence.base },
|
|
89
73
|
};
|
|
90
74
|
}
|
|
91
|
-
return { operation: { op: '
|
|
75
|
+
return { operation: { op: 'delete', path, base: existence.base } };
|
|
92
76
|
}
|
|
93
|
-
export function houseChanges(batch, handle) {
|
|
77
|
+
export function houseChanges(batch, handle, written) {
|
|
94
78
|
const changes = [];
|
|
95
|
-
|
|
96
|
-
|
|
79
|
+
const moves = new Map();
|
|
80
|
+
const before = new Map();
|
|
81
|
+
for (const [index, change] of batch.changes.entries()) {
|
|
82
|
+
const mapped = operationOf(batch, index, handle, written);
|
|
83
|
+
if (mapped === null)
|
|
84
|
+
continue;
|
|
97
85
|
if ('rule' in mapped)
|
|
98
86
|
return { kind: 'unmapped', path: change.path, rule: mapped.rule };
|
|
99
|
-
|
|
87
|
+
const { operation } = mapped;
|
|
88
|
+
const from = departure(batch.changes, index);
|
|
89
|
+
if (change.kind === 'move' && !moves.has(from))
|
|
90
|
+
moves.set(from, changes.length);
|
|
91
|
+
const moved = moves.get(from);
|
|
92
|
+
if (change.kind !== 'move' &&
|
|
93
|
+
moved !== undefined &&
|
|
94
|
+
operation.op === 'write' &&
|
|
95
|
+
'base' in operation) {
|
|
96
|
+
before.set(moved, { ...operation, path: nativePath(from, handle) });
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
changes.push(operation);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
kind: 'changes',
|
|
103
|
+
changes: changes.flatMap((operation, at) => {
|
|
104
|
+
const written = before.get(at);
|
|
105
|
+
return written === undefined ? [operation] : [written, operation];
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function houseMove(batch, source, destination) {
|
|
110
|
+
const changes = [];
|
|
111
|
+
for (const { path, to } of batch.between?.moves ?? []) {
|
|
112
|
+
const existence = priorExistence(batch, path);
|
|
113
|
+
if (existence === undefined)
|
|
114
|
+
return { kind: 'unmapped', path, rule: 'precondition-missing' };
|
|
115
|
+
if (!('base' in existence)) {
|
|
116
|
+
return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
|
|
117
|
+
}
|
|
118
|
+
changes.push({
|
|
119
|
+
op: 'move',
|
|
120
|
+
path: nativePath(path, source),
|
|
121
|
+
to: nativePath(to, destination),
|
|
122
|
+
base: existence.base,
|
|
123
|
+
});
|
|
100
124
|
}
|
|
101
125
|
return { kind: 'changes', changes };
|
|
102
126
|
}
|
|
103
127
|
export function operationHead(batch) {
|
|
104
128
|
const writer = batch.writtenBy;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
: { operation_id: batch.id, app_ref: writer.app, release: writer.release };
|
|
129
|
+
const head = { operation_id: batch.id };
|
|
130
|
+
return writer === undefined ? head : { ...head, app_ref: writer.app, release: writer.release };
|
|
108
131
|
}
|
|
109
132
|
export function batchPaths(changes) {
|
|
110
133
|
return [
|
|
111
|
-
...new Set(changes.flatMap((change) => change.op === '
|
|
112
|
-
]
|
|
134
|
+
...new Set(changes.flatMap((change) => change.op === 'move' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
135
|
+
];
|
|
113
136
|
}
|
|
114
137
|
export function deltaBody(changes) {
|
|
115
138
|
return JSON.stringify({ changes });
|
|
@@ -124,20 +147,29 @@ export function uploadable(inline, bytes, bounds) {
|
|
|
124
147
|
export function deltaDigest(delta) {
|
|
125
148
|
return sha256Hex(delta);
|
|
126
149
|
}
|
|
127
|
-
function material(value, handle) {
|
|
150
|
+
function* material(value, handle, within = () => true) {
|
|
128
151
|
if (!Array.isArray(value))
|
|
129
152
|
return null;
|
|
130
153
|
const held = [];
|
|
131
154
|
for (const entry of value) {
|
|
155
|
+
yield ROW_WEIGHT;
|
|
132
156
|
if (typeof entry !== 'object' || entry === null)
|
|
133
157
|
return null;
|
|
134
158
|
const file = entry;
|
|
135
159
|
if (typeof file.path !== 'string')
|
|
136
160
|
return null;
|
|
161
|
+
if (!within(file.path))
|
|
162
|
+
continue;
|
|
137
163
|
if (file.content !== null && typeof file.content !== 'string')
|
|
138
164
|
return null;
|
|
139
165
|
if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
|
|
140
166
|
return null;
|
|
167
|
+
const binary = attachmentOf(file);
|
|
168
|
+
if (binary === null)
|
|
169
|
+
return null;
|
|
170
|
+
const head = headChange(file);
|
|
171
|
+
if (head === null)
|
|
172
|
+
return null;
|
|
141
173
|
let path;
|
|
142
174
|
try {
|
|
143
175
|
path = roomLocalPath(file.path, handle);
|
|
@@ -149,79 +181,122 @@ function material(value, handle) {
|
|
|
149
181
|
path,
|
|
150
182
|
content: file.content,
|
|
151
183
|
revision: typeof file.revision === 'string' ? file.revision : null,
|
|
184
|
+
...(binary === undefined ? {} : { binary }),
|
|
185
|
+
...(head === undefined ? {} : { head }),
|
|
152
186
|
});
|
|
153
187
|
}
|
|
154
188
|
return held;
|
|
155
189
|
}
|
|
156
|
-
function affectedOf(held) {
|
|
190
|
+
function* affectedOf(held) {
|
|
157
191
|
const affected = {};
|
|
158
192
|
for (const entry of held) {
|
|
159
193
|
if (entry.content !== null)
|
|
160
194
|
affected[entry.path] = entry.content;
|
|
195
|
+
yield ROW_WEIGHT;
|
|
161
196
|
}
|
|
162
197
|
return affected;
|
|
163
198
|
}
|
|
164
|
-
|
|
199
|
+
function* acceptedOf(at, contents) {
|
|
200
|
+
const answer = answering();
|
|
201
|
+
for (const entry of contents) {
|
|
202
|
+
yield ROW_WEIGHT + (entry.content?.length ?? 0);
|
|
203
|
+
if (entry.revision === null) {
|
|
204
|
+
answer.removals.add(entry.path);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (entry.content !== null)
|
|
208
|
+
answer.documents.set(entry.path, entry.content);
|
|
209
|
+
if (entry.binary !== undefined)
|
|
210
|
+
answer.attachments.set(entry.path, entry.binary);
|
|
211
|
+
revised(answer, entry.path, entry.revision);
|
|
212
|
+
if (entry.head !== undefined)
|
|
213
|
+
answer.changes.set(entry.path, entry.head);
|
|
214
|
+
}
|
|
215
|
+
const unbinaried = answer.attachments.size === 0;
|
|
216
|
+
const { attachments, facts: _facts, ...room } = yield* answered(answer);
|
|
217
|
+
return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { attachments }) };
|
|
218
|
+
}
|
|
219
|
+
function* movedOutcome(held, move) {
|
|
220
|
+
const authorities = Array.isArray(held.authorities) ? held.authorities : [];
|
|
221
|
+
const at = (authority) => {
|
|
222
|
+
const entry = authorities.find((one) => typeof one === 'object' &&
|
|
223
|
+
one !== null &&
|
|
224
|
+
one.authority === authority);
|
|
225
|
+
return entry === undefined ? null : readPosition(entry);
|
|
226
|
+
};
|
|
227
|
+
const left = at(move.source.authority);
|
|
228
|
+
const arrived = at(move.destination.authority);
|
|
229
|
+
if (left === null || arrived === null)
|
|
230
|
+
return unusable();
|
|
231
|
+
const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
|
|
232
|
+
const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
|
|
233
|
+
const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
|
|
234
|
+
if (leaving === null || arriving === null)
|
|
235
|
+
return unusable();
|
|
236
|
+
return {
|
|
237
|
+
kind: 'accepted',
|
|
238
|
+
...(yield* acceptedOf(left, leaving)),
|
|
239
|
+
destination: yield* acceptedOf(arrived, arriving),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
export function* mutationOutcome(status, body, locator, handle, move) {
|
|
165
243
|
const refusal = doorRefusal(body);
|
|
166
244
|
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
167
245
|
return { kind: 'write-halted' };
|
|
168
246
|
}
|
|
169
|
-
if (refusal !== null && refusal.code === 'expired')
|
|
170
|
-
return { kind: 'expired' };
|
|
171
247
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
172
248
|
const { current, ...fields } = refusal.fields;
|
|
173
|
-
const held = material(current, handle) ?? [];
|
|
174
|
-
return {
|
|
249
|
+
const held = (yield* material(current, handle)) ?? [];
|
|
250
|
+
return {
|
|
251
|
+
kind: 'conflicted',
|
|
252
|
+
affected: yield* affectedOf(held),
|
|
253
|
+
code: refusal.code,
|
|
254
|
+
fields,
|
|
255
|
+
retryable: refusal.retryable,
|
|
256
|
+
};
|
|
175
257
|
}
|
|
176
258
|
if (refusal !== null && status === 404) {
|
|
177
259
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
178
260
|
}
|
|
179
261
|
const classified = classifyDoor(status, body, locator);
|
|
180
|
-
const reset = refusal
|
|
181
|
-
if (refusal?.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
262
|
+
const reset = resetOf(refusal);
|
|
263
|
+
if (refusal !== null && reset !== undefined && classified?.kind === 'transport-uncertainty') {
|
|
264
|
+
return {
|
|
265
|
+
kind: 'retryable-refusal',
|
|
266
|
+
code: refusal.code,
|
|
267
|
+
fields: refusal.fields,
|
|
268
|
+
retryable: true,
|
|
269
|
+
reset,
|
|
270
|
+
};
|
|
185
271
|
}
|
|
186
272
|
if (classified !== null && classified.kind !== 'scoped-refusal')
|
|
187
273
|
return classified;
|
|
188
|
-
if (classified !== null && status === 403)
|
|
274
|
+
if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
|
|
189
275
|
return classified;
|
|
190
|
-
if (refusal !== null && status >= 400) {
|
|
191
|
-
return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
|
|
192
276
|
}
|
|
193
|
-
if (
|
|
194
|
-
return {
|
|
277
|
+
if (refusal !== null && status >= 400) {
|
|
278
|
+
return {
|
|
279
|
+
kind: 'rejected',
|
|
280
|
+
affected: {},
|
|
281
|
+
code: refusal.code,
|
|
282
|
+
fields: refusal.fields,
|
|
283
|
+
retryable: refusal.retryable,
|
|
284
|
+
};
|
|
195
285
|
}
|
|
286
|
+
if (status !== 200)
|
|
287
|
+
return answeredFailure(status, body);
|
|
288
|
+
if (typeof body !== 'object' || body === null)
|
|
289
|
+
return unusable();
|
|
196
290
|
const held = body;
|
|
291
|
+
if (move !== undefined)
|
|
292
|
+
return yield* movedOutcome(held, move);
|
|
197
293
|
const at = readPosition(held);
|
|
198
294
|
if (at === null)
|
|
199
|
-
return
|
|
200
|
-
const contents = material(held.contents, handle);
|
|
295
|
+
return unusable();
|
|
296
|
+
const contents = yield* material(held.contents, handle);
|
|
201
297
|
if (contents === null)
|
|
202
|
-
return
|
|
203
|
-
|
|
204
|
-
if (originals === null)
|
|
205
|
-
return { kind: 'transport-uncertainty' };
|
|
206
|
-
const documents = {};
|
|
207
|
-
const revisions = {};
|
|
208
|
-
const removals = [];
|
|
209
|
-
for (const entry of contents) {
|
|
210
|
-
if (entry.content === null || entry.revision === null) {
|
|
211
|
-
removals.push(entry.path);
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
documents[entry.path] = entry.content;
|
|
215
|
-
revisions[entry.path] = entry.revision;
|
|
216
|
-
}
|
|
217
|
-
return {
|
|
218
|
-
kind: 'accepted',
|
|
219
|
-
roomVersion: roomVersion(at),
|
|
220
|
-
documents,
|
|
221
|
-
revisions,
|
|
222
|
-
removals: removals.sort(),
|
|
223
|
-
originals,
|
|
224
|
-
};
|
|
298
|
+
return unusable();
|
|
299
|
+
return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
|
|
225
300
|
}
|
|
226
301
|
export function rejectedMapping(mapping) {
|
|
227
302
|
return {
|
|
@@ -229,6 +304,7 @@ export function rejectedMapping(mapping) {
|
|
|
229
304
|
affected: {},
|
|
230
305
|
code: mapping.rule,
|
|
231
306
|
fields: { path: mapping.path },
|
|
307
|
+
retryable: false,
|
|
232
308
|
};
|
|
233
309
|
}
|
|
234
310
|
export function revisionBody(input) {
|
|
@@ -240,13 +316,26 @@ export function revisionBody(input) {
|
|
|
240
316
|
}
|
|
241
317
|
function revisionAuthor(entry) {
|
|
242
318
|
const user = entry.author_user;
|
|
319
|
+
const userName = entry.author_user_name;
|
|
243
320
|
const site = entry.author_site;
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
321
|
+
const siteName = entry.author_site_name;
|
|
322
|
+
const inbox = entry.author_inbox;
|
|
323
|
+
const inboxName = entry.author_inbox_name;
|
|
324
|
+
const app = entry.author_app;
|
|
325
|
+
const appName = entry.author_app_name;
|
|
326
|
+
const named = [site, siteName, inbox, inboxName, app, appName].filter((held) => held !== undefined);
|
|
327
|
+
if (typeof user === 'string' && typeof userName === 'string' && named.length === 0)
|
|
328
|
+
return { kind: 'user', id: user, name: userName };
|
|
329
|
+
if (user !== null || userName !== undefined || named.length !== 2)
|
|
330
|
+
return null;
|
|
331
|
+
if (typeof site === 'string' && typeof siteName === 'string') {
|
|
332
|
+
return { kind: 'site', id: site, name: siteName };
|
|
333
|
+
}
|
|
334
|
+
if (typeof inbox === 'string' && typeof inboxName === 'string') {
|
|
335
|
+
return { kind: 'inbox', id: inbox, name: inboxName };
|
|
247
336
|
}
|
|
248
|
-
if (
|
|
249
|
-
return { kind: '
|
|
337
|
+
if (typeof app === 'string' && typeof appName === 'string') {
|
|
338
|
+
return { kind: 'app', id: app, name: appName };
|
|
250
339
|
}
|
|
251
340
|
return null;
|
|
252
341
|
}
|
|
@@ -255,32 +344,23 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
255
344
|
if (classified !== null)
|
|
256
345
|
return classified;
|
|
257
346
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
258
|
-
return
|
|
347
|
+
return unusable();
|
|
259
348
|
}
|
|
260
349
|
const held = body;
|
|
261
350
|
if (!Array.isArray(held.revisions))
|
|
262
|
-
return
|
|
351
|
+
return unusable();
|
|
263
352
|
const entries = [];
|
|
264
353
|
for (const entry of held.revisions) {
|
|
265
354
|
if (typeof entry !== 'object' || entry === null)
|
|
266
|
-
return
|
|
355
|
+
return unusable();
|
|
267
356
|
entries.push(entry);
|
|
268
357
|
}
|
|
269
|
-
|
|
270
|
-
|
|
358
|
+
const named = entries[0];
|
|
359
|
+
if (request.revision !== undefined && typeof named?.media_type !== 'string') {
|
|
271
360
|
if (named === undefined)
|
|
272
361
|
return { kind: 'no-history' };
|
|
273
|
-
if (named.unavailable === true) {
|
|
274
|
-
return {
|
|
275
|
-
kind: 'scoped-refusal',
|
|
276
|
-
locator,
|
|
277
|
-
scope: 'content',
|
|
278
|
-
code: 'retained_history_unavailable',
|
|
279
|
-
fields: { path: request.path, revision: request.revision },
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
362
|
if (typeof named.content !== 'string')
|
|
283
|
-
return
|
|
363
|
+
return unusable();
|
|
284
364
|
return { kind: 'revision', content: named.content };
|
|
285
365
|
}
|
|
286
366
|
if (entries.length === 0)
|
|
@@ -291,14 +371,23 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
291
371
|
if (typeof entry.revision !== 'string' ||
|
|
292
372
|
author === null ||
|
|
293
373
|
typeof entry.created_at !== 'string') {
|
|
294
|
-
return
|
|
374
|
+
return unusable();
|
|
295
375
|
}
|
|
296
|
-
|
|
376
|
+
const attachment = attachmentOf(entry);
|
|
377
|
+
if (attachment === null)
|
|
378
|
+
return unusable();
|
|
379
|
+
revisions.push({
|
|
380
|
+
revision: entry.revision,
|
|
381
|
+
author,
|
|
382
|
+
time: entry.created_at,
|
|
383
|
+
...(attachment === undefined ? {} : { attachment }),
|
|
384
|
+
});
|
|
297
385
|
}
|
|
298
386
|
const next = held.next_before;
|
|
299
387
|
return {
|
|
300
388
|
kind: 'history',
|
|
301
389
|
revisions,
|
|
302
390
|
...(typeof next === 'number' ? { pageToken: String(next) } : {}),
|
|
391
|
+
...(held.deleted === true ? { deleted: true } : {}),
|
|
303
392
|
};
|
|
304
393
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-c38cdd8a6d962",
|
|
4
3
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
4
|
"license": "MIT",
|
|
6
5
|
"type": "module",
|
|
@@ -9,23 +8,28 @@
|
|
|
9
8
|
"access": "public"
|
|
10
9
|
},
|
|
11
10
|
"engines": {
|
|
12
|
-
"node": ">=24.
|
|
11
|
+
"node": ">=24.22.1"
|
|
13
12
|
},
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
16
15
|
"types": "./dist/index.d.ts",
|
|
17
|
-
"
|
|
16
|
+
"default": "./dist/index.js"
|
|
18
17
|
},
|
|
19
18
|
"./package.json": "./package.json"
|
|
20
19
|
},
|
|
21
20
|
"files": [
|
|
22
21
|
"dist",
|
|
23
|
-
"AGENTS.md",
|
|
24
22
|
"README.md",
|
|
25
23
|
"LICENSE"
|
|
26
24
|
],
|
|
27
25
|
"dependencies": {
|
|
28
|
-
"@agentshouse/mdmodel": "0.1.0-
|
|
29
|
-
"@agentshouse/mdruntime": "0.1.0-
|
|
30
|
-
}
|
|
26
|
+
"@agentshouse/mdmodel": "0.1.0-cd6857b056d76",
|
|
27
|
+
"@agentshouse/mdruntime": "0.1.0-c6ecdbdce0a2c"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/agentshouse/core.git",
|
|
32
|
+
"directory": "mdruntime/packages/mdruntime-adapter"
|
|
33
|
+
},
|
|
34
|
+
"version": "0.1.0-c38f28dbe538b"
|
|
31
35
|
}
|