@agentshouse/mdruntime-adapter 0.1.0-c7d05e09c73b7 → 0.1.0-c7d4e2f67c325
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 +197 -319
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +306 -252
- 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 +45 -18
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +254 -65
- 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 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -7
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +30 -50
- package/dist/read.d.ts +54 -53
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +209 -278
- package/dist/refusal.d.ts +8 -10
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +31 -18
- 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 -109
- 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 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +281 -154
- package/dist/transport.d.ts +131 -31
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +90 -9
- 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 +218 -138
- package/package.json +11 -7
- package/AGENTS.md +0 -253
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -45
- 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
|
-
},
|
|
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,
|
|
60
52
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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)
|
|
65
58
|
return { rule: 'precondition-missing' };
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
if (change.kind === 'create') {
|
|
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 };
|
|
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,26 @@ 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;
|
|
141
170
|
const head = headChange(file);
|
|
142
171
|
if (head === null)
|
|
143
172
|
return null;
|
|
@@ -152,84 +181,122 @@ function material(value, handle) {
|
|
|
152
181
|
path,
|
|
153
182
|
content: file.content,
|
|
154
183
|
revision: typeof file.revision === 'string' ? file.revision : null,
|
|
184
|
+
...(binary === undefined ? {} : { binary }),
|
|
155
185
|
...(head === undefined ? {} : { head }),
|
|
156
186
|
});
|
|
157
187
|
}
|
|
158
188
|
return held;
|
|
159
189
|
}
|
|
160
|
-
function affectedOf(held) {
|
|
190
|
+
function* affectedOf(held) {
|
|
161
191
|
const affected = {};
|
|
162
192
|
for (const entry of held) {
|
|
163
193
|
if (entry.content !== null)
|
|
164
194
|
affected[entry.path] = entry.content;
|
|
195
|
+
yield ROW_WEIGHT;
|
|
165
196
|
}
|
|
166
197
|
return affected;
|
|
167
198
|
}
|
|
168
|
-
|
|
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) {
|
|
169
243
|
const refusal = doorRefusal(body);
|
|
170
244
|
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
171
245
|
return { kind: 'write-halted' };
|
|
172
246
|
}
|
|
173
|
-
if (refusal !== null && refusal.code === 'expired')
|
|
174
|
-
return { kind: 'expired' };
|
|
175
247
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
176
248
|
const { current, ...fields } = refusal.fields;
|
|
177
|
-
const held = material(current, handle) ?? [];
|
|
178
|
-
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
|
+
};
|
|
179
257
|
}
|
|
180
258
|
if (refusal !== null && status === 404) {
|
|
181
259
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
182
260
|
}
|
|
183
261
|
const classified = classifyDoor(status, body, locator);
|
|
184
|
-
const reset = refusal
|
|
185
|
-
if (refusal?.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
+
};
|
|
189
271
|
}
|
|
190
272
|
if (classified !== null && classified.kind !== 'scoped-refusal')
|
|
191
273
|
return classified;
|
|
192
|
-
if (classified !== null && status === 403)
|
|
274
|
+
if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
|
|
193
275
|
return classified;
|
|
194
|
-
if (refusal !== null && status >= 400) {
|
|
195
|
-
return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
|
|
196
276
|
}
|
|
197
|
-
if (
|
|
198
|
-
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
|
+
};
|
|
199
285
|
}
|
|
286
|
+
if (status !== 200)
|
|
287
|
+
return answeredFailure(status, body);
|
|
288
|
+
if (typeof body !== 'object' || body === null)
|
|
289
|
+
return unusable();
|
|
200
290
|
const held = body;
|
|
291
|
+
if (move !== undefined)
|
|
292
|
+
return yield* movedOutcome(held, move);
|
|
201
293
|
const at = readPosition(held);
|
|
202
294
|
if (at === null)
|
|
203
|
-
return
|
|
204
|
-
const contents = material(held.contents, handle);
|
|
295
|
+
return unusable();
|
|
296
|
+
const contents = yield* material(held.contents, handle);
|
|
205
297
|
if (contents === null)
|
|
206
|
-
return
|
|
207
|
-
|
|
208
|
-
if (originals === null)
|
|
209
|
-
return { kind: 'transport-uncertainty' };
|
|
210
|
-
const documents = {};
|
|
211
|
-
const revisions = {};
|
|
212
|
-
const changes = {};
|
|
213
|
-
const removals = [];
|
|
214
|
-
for (const entry of contents) {
|
|
215
|
-
if (entry.content === null || entry.revision === null) {
|
|
216
|
-
removals.push(entry.path);
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
documents[entry.path] = entry.content;
|
|
220
|
-
revisions[entry.path] = entry.revision;
|
|
221
|
-
if (entry.head !== undefined)
|
|
222
|
-
changes[entry.path] = entry.head;
|
|
223
|
-
}
|
|
224
|
-
return {
|
|
225
|
-
kind: 'accepted',
|
|
226
|
-
roomVersion: roomVersion(at),
|
|
227
|
-
documents,
|
|
228
|
-
revisions,
|
|
229
|
-
changes,
|
|
230
|
-
removals: removals.sort(),
|
|
231
|
-
originals,
|
|
232
|
-
};
|
|
298
|
+
return unusable();
|
|
299
|
+
return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
|
|
233
300
|
}
|
|
234
301
|
export function rejectedMapping(mapping) {
|
|
235
302
|
return {
|
|
@@ -237,6 +304,7 @@ export function rejectedMapping(mapping) {
|
|
|
237
304
|
affected: {},
|
|
238
305
|
code: mapping.rule,
|
|
239
306
|
fields: { path: mapping.path },
|
|
307
|
+
retryable: false,
|
|
240
308
|
};
|
|
241
309
|
}
|
|
242
310
|
export function revisionBody(input) {
|
|
@@ -248,13 +316,26 @@ export function revisionBody(input) {
|
|
|
248
316
|
}
|
|
249
317
|
function revisionAuthor(entry) {
|
|
250
318
|
const user = entry.author_user;
|
|
319
|
+
const userName = entry.author_user_name;
|
|
251
320
|
const site = entry.author_site;
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
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 };
|
|
255
336
|
}
|
|
256
|
-
if (
|
|
257
|
-
return { kind: '
|
|
337
|
+
if (typeof app === 'string' && typeof appName === 'string') {
|
|
338
|
+
return { kind: 'app', id: app, name: appName };
|
|
258
339
|
}
|
|
259
340
|
return null;
|
|
260
341
|
}
|
|
@@ -263,32 +344,23 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
263
344
|
if (classified !== null)
|
|
264
345
|
return classified;
|
|
265
346
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
266
|
-
return
|
|
347
|
+
return unusable();
|
|
267
348
|
}
|
|
268
349
|
const held = body;
|
|
269
350
|
if (!Array.isArray(held.revisions))
|
|
270
|
-
return
|
|
351
|
+
return unusable();
|
|
271
352
|
const entries = [];
|
|
272
353
|
for (const entry of held.revisions) {
|
|
273
354
|
if (typeof entry !== 'object' || entry === null)
|
|
274
|
-
return
|
|
355
|
+
return unusable();
|
|
275
356
|
entries.push(entry);
|
|
276
357
|
}
|
|
277
|
-
|
|
278
|
-
|
|
358
|
+
const named = entries[0];
|
|
359
|
+
if (request.revision !== undefined && typeof named?.media_type !== 'string') {
|
|
279
360
|
if (named === undefined)
|
|
280
361
|
return { kind: 'no-history' };
|
|
281
|
-
if (named.unavailable === true) {
|
|
282
|
-
return {
|
|
283
|
-
kind: 'scoped-refusal',
|
|
284
|
-
locator,
|
|
285
|
-
scope: 'content',
|
|
286
|
-
code: 'retained_history_unavailable',
|
|
287
|
-
fields: { path: request.path, revision: request.revision },
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
362
|
if (typeof named.content !== 'string')
|
|
291
|
-
return
|
|
363
|
+
return unusable();
|
|
292
364
|
return { kind: 'revision', content: named.content };
|
|
293
365
|
}
|
|
294
366
|
if (entries.length === 0)
|
|
@@ -299,9 +371,17 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
299
371
|
if (typeof entry.revision !== 'string' ||
|
|
300
372
|
author === null ||
|
|
301
373
|
typeof entry.created_at !== 'string') {
|
|
302
|
-
return
|
|
374
|
+
return unusable();
|
|
303
375
|
}
|
|
304
|
-
|
|
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
|
+
});
|
|
305
385
|
}
|
|
306
386
|
const next = held.next_before;
|
|
307
387
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-c7d05e09c73b7",
|
|
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-c28f5cb4a11e0",
|
|
27
|
+
"@agentshouse/mdruntime": "0.1.0-c5d06f0aab9c6"
|
|
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-c7d4e2f67c325"
|
|
31
35
|
}
|