@agentshouse/mdruntime-adapter 0.1.0-cf6a7cf003c4b → 0.1.0-cf768be36486a
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 +12 -43
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +135 -292
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +302 -250
- 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 -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 -7
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +30 -50
- package/dist/read.d.ts +54 -52
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +210 -249
- package/dist/refusal.d.ts +6 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +27 -10
- 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 +153 -107
- 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 +280 -154
- package/dist/transport.d.ts +132 -28
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +91 -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 +14 -12
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +197 -134
- package/package.json +10 -6
- package/AGENTS.md +0 -269
- 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
|
-
},
|
|
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,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,32 +181,75 @@ 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) ?? [];
|
|
249
|
+
const held = (yield* material(current, handle)) ?? [];
|
|
178
250
|
return {
|
|
179
251
|
kind: 'conflicted',
|
|
180
|
-
affected: affectedOf(held),
|
|
252
|
+
affected: yield* affectedOf(held),
|
|
181
253
|
code: refusal.code,
|
|
182
254
|
fields,
|
|
183
255
|
retryable: refusal.retryable,
|
|
@@ -187,10 +259,8 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
187
259
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
188
260
|
}
|
|
189
261
|
const classified = classifyDoor(status, body, locator);
|
|
190
|
-
const reset = refusal
|
|
191
|
-
if (refusal?.
|
|
192
|
-
typeof reset === 'string' &&
|
|
193
|
-
classified?.kind === 'transport-uncertainty') {
|
|
262
|
+
const reset = resetOf(refusal);
|
|
263
|
+
if (refusal !== null && reset !== undefined && classified?.kind === 'transport-uncertainty') {
|
|
194
264
|
return {
|
|
195
265
|
kind: 'retryable-refusal',
|
|
196
266
|
code: refusal.code,
|
|
@@ -201,8 +271,9 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
201
271
|
}
|
|
202
272
|
if (classified !== null && classified.kind !== 'scoped-refusal')
|
|
203
273
|
return classified;
|
|
204
|
-
if (classified !== null && status === 403)
|
|
274
|
+
if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
|
|
205
275
|
return classified;
|
|
276
|
+
}
|
|
206
277
|
if (refusal !== null && status >= 400) {
|
|
207
278
|
return {
|
|
208
279
|
kind: 'rejected',
|
|
@@ -212,39 +283,20 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
212
283
|
retryable: refusal.retryable,
|
|
213
284
|
};
|
|
214
285
|
}
|
|
215
|
-
if (status !== 200
|
|
216
|
-
return
|
|
217
|
-
|
|
286
|
+
if (status !== 200)
|
|
287
|
+
return answeredFailure(status, body);
|
|
288
|
+
if (typeof body !== 'object' || body === null)
|
|
289
|
+
return unusable();
|
|
218
290
|
const held = body;
|
|
291
|
+
if (move !== undefined)
|
|
292
|
+
return yield* movedOutcome(held, move);
|
|
219
293
|
const at = readPosition(held);
|
|
220
294
|
if (at === null)
|
|
221
|
-
return
|
|
222
|
-
const contents = material(held.contents, handle);
|
|
295
|
+
return unusable();
|
|
296
|
+
const contents = yield* material(held.contents, handle);
|
|
223
297
|
if (contents === null)
|
|
224
|
-
return
|
|
225
|
-
|
|
226
|
-
const revisions = {};
|
|
227
|
-
const changes = {};
|
|
228
|
-
const removals = [];
|
|
229
|
-
for (const entry of contents) {
|
|
230
|
-
if (entry.content === null || entry.revision === null) {
|
|
231
|
-
removals.push(entry.path);
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
documents[entry.path] = entry.content;
|
|
235
|
-
revisions[entry.path] = entry.revision;
|
|
236
|
-
if (entry.head !== undefined)
|
|
237
|
-
changes[entry.path] = entry.head;
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
kind: 'accepted',
|
|
241
|
-
roomVersion: roomVersion(at),
|
|
242
|
-
documents,
|
|
243
|
-
revisions,
|
|
244
|
-
changes,
|
|
245
|
-
removals: removals.sort(),
|
|
246
|
-
originals: [],
|
|
247
|
-
};
|
|
298
|
+
return unusable();
|
|
299
|
+
return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
|
|
248
300
|
}
|
|
249
301
|
export function rejectedMapping(mapping) {
|
|
250
302
|
return {
|
|
@@ -264,13 +316,26 @@ export function revisionBody(input) {
|
|
|
264
316
|
}
|
|
265
317
|
function revisionAuthor(entry) {
|
|
266
318
|
const user = entry.author_user;
|
|
319
|
+
const userName = entry.author_user_name;
|
|
267
320
|
const site = entry.author_site;
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
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 };
|
|
271
333
|
}
|
|
272
|
-
if (
|
|
273
|
-
return { kind: '
|
|
334
|
+
if (typeof inbox === 'string' && typeof inboxName === 'string') {
|
|
335
|
+
return { kind: 'inbox', id: inbox, name: inboxName };
|
|
336
|
+
}
|
|
337
|
+
if (typeof app === 'string' && typeof appName === 'string') {
|
|
338
|
+
return { kind: 'app', id: app, name: appName };
|
|
274
339
|
}
|
|
275
340
|
return null;
|
|
276
341
|
}
|
|
@@ -279,33 +344,23 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
279
344
|
if (classified !== null)
|
|
280
345
|
return classified;
|
|
281
346
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
282
|
-
return
|
|
347
|
+
return unusable();
|
|
283
348
|
}
|
|
284
349
|
const held = body;
|
|
285
350
|
if (!Array.isArray(held.revisions))
|
|
286
|
-
return
|
|
351
|
+
return unusable();
|
|
287
352
|
const entries = [];
|
|
288
353
|
for (const entry of held.revisions) {
|
|
289
354
|
if (typeof entry !== 'object' || entry === null)
|
|
290
|
-
return
|
|
355
|
+
return unusable();
|
|
291
356
|
entries.push(entry);
|
|
292
357
|
}
|
|
293
|
-
|
|
294
|
-
|
|
358
|
+
const named = entries[0];
|
|
359
|
+
if (request.revision !== undefined && typeof named?.media_type !== 'string') {
|
|
295
360
|
if (named === undefined)
|
|
296
361
|
return { kind: 'no-history' };
|
|
297
|
-
if (named.unavailable === true) {
|
|
298
|
-
return {
|
|
299
|
-
kind: 'scoped-refusal',
|
|
300
|
-
locator,
|
|
301
|
-
scope: 'content',
|
|
302
|
-
code: 'retained_history_unavailable',
|
|
303
|
-
fields: { path: request.path, revision: request.revision },
|
|
304
|
-
retryable: false,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
362
|
if (typeof named.content !== 'string')
|
|
308
|
-
return
|
|
363
|
+
return unusable();
|
|
309
364
|
return { kind: 'revision', content: named.content };
|
|
310
365
|
}
|
|
311
366
|
if (entries.length === 0)
|
|
@@ -316,9 +371,17 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
316
371
|
if (typeof entry.revision !== 'string' ||
|
|
317
372
|
author === null ||
|
|
318
373
|
typeof entry.created_at !== 'string') {
|
|
319
|
-
return
|
|
374
|
+
return unusable();
|
|
320
375
|
}
|
|
321
|
-
|
|
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
|
+
});
|
|
322
385
|
}
|
|
323
386
|
const next = held.next_before;
|
|
324
387
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-cf6a7cf003c4b",
|
|
4
3
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
4
|
"license": "MIT",
|
|
6
5
|
"type": "module",
|
|
@@ -9,7 +8,7 @@
|
|
|
9
8
|
"access": "public"
|
|
10
9
|
},
|
|
11
10
|
"engines": {
|
|
12
|
-
"node": ">=24.
|
|
11
|
+
"node": ">=24.22.1"
|
|
13
12
|
},
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
@@ -20,12 +19,17 @@
|
|
|
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-c9ac98184dfa8",
|
|
27
|
+
"@agentshouse/mdruntime": "0.1.0-c5d560f15bf2d"
|
|
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-cf768be36486a"
|
|
31
35
|
}
|