@agentshouse/mdruntime-adapter 0.1.0-c86eddcb309ff → 0.1.0-c87013e8a4dd8
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 -44
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +124 -332
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +295 -318
- 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 -53
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +198 -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 +149 -134
- 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 -161
- package/dist/transport.d.ts +124 -32
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +90 -11
- 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 -5
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +177 -163
- package/package.json +10 -6
- package/AGENTS.md +0 -299
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -45
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -38
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -35
package/dist/write.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { departure, } from '@agentshouse/mdruntime';
|
|
2
|
-
import {
|
|
1
|
+
import { departure, isPart, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { answered, answering, attachmentOf, headChange, revised } from './read.js';
|
|
3
3
|
import { sha256Hex, textBytes } from './digest.js';
|
|
4
4
|
import { nativePath, roomLocalPath } from './map.js';
|
|
5
|
-
import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
|
|
5
|
+
import { answeredFailure, classifyDoor, doorRefusal, resetOf, scopedRefusal } from './refusal.js';
|
|
6
6
|
import { readPosition, roomVersion } from './version.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
function priorPreamble(batch, path) {
|
|
14
|
-
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)));
|
|
15
12
|
}
|
|
16
13
|
function priorAbsence(batch, path) {
|
|
17
14
|
return batch.preconditions.find((precondition) => precondition.kind === 'absent' && precondition.path === path);
|
|
@@ -22,60 +19,30 @@ function priorExistence(batch, path) {
|
|
|
22
19
|
return undefined;
|
|
23
20
|
return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };
|
|
24
21
|
}
|
|
25
|
-
function
|
|
26
|
-
if (
|
|
27
|
-
return {
|
|
28
|
-
|
|
29
|
-
|
|
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)
|
|
30
30
|
return null;
|
|
31
|
-
|
|
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 } };
|
|
32
38
|
}
|
|
33
|
-
function operationOf(batch,
|
|
39
|
+
function operationOf(batch, index, handle, written) {
|
|
40
|
+
const change = batch.changes[index];
|
|
34
41
|
const path = nativePath(change.path, handle);
|
|
35
|
-
if (change.kind === '
|
|
36
|
-
|
|
37
|
-
if (prior === undefined)
|
|
38
|
-
return { rule: 'precondition-missing' };
|
|
39
|
-
return {
|
|
40
|
-
operation: {
|
|
41
|
-
op: 'set_field',
|
|
42
|
-
path,
|
|
43
|
-
field: change.name,
|
|
44
|
-
value: change.value,
|
|
45
|
-
...(prior.value === undefined ? {} : { base: prior.value }),
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
if (change.kind === 'section') {
|
|
50
|
-
const prior = priorSection(batch, change.path, change.name);
|
|
51
|
-
if (prior === undefined)
|
|
52
|
-
return { rule: 'precondition-missing' };
|
|
53
|
-
return {
|
|
54
|
-
operation: {
|
|
55
|
-
op: 'replace_section',
|
|
56
|
-
path,
|
|
57
|
-
section: change.name,
|
|
58
|
-
base: prior.value,
|
|
59
|
-
content: change.value,
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
if (change.kind === 'preamble') {
|
|
64
|
-
const prior = priorPreamble(batch, change.path);
|
|
65
|
-
if (prior === undefined)
|
|
66
|
-
return { rule: 'precondition-missing' };
|
|
67
|
-
return {
|
|
68
|
-
operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
if (change.kind === 'create') {
|
|
72
|
-
if (priorAbsence(batch, change.path) === undefined)
|
|
73
|
-
return { rule: 'precondition-missing' };
|
|
74
|
-
const operation = created(change, path);
|
|
75
|
-
return operation === null ? { rule: 'type-missing' } : { operation };
|
|
76
|
-
}
|
|
42
|
+
if (isPart(change) || change.kind === 'create' || change.kind === 'replace')
|
|
43
|
+
return textOf(batch, change, path, written[index]);
|
|
77
44
|
if (change.kind === 'binary') {
|
|
78
|
-
const
|
|
45
|
+
const uploaded = {
|
|
79
46
|
op: 'upload',
|
|
80
47
|
path,
|
|
81
48
|
local_id: change.localId,
|
|
@@ -83,53 +50,89 @@ function operationOf(batch, change, handle) {
|
|
|
83
50
|
sha256: change.sha256,
|
|
84
51
|
media_type: change.mediaType,
|
|
85
52
|
};
|
|
86
|
-
const from = departure(batch.changes,
|
|
53
|
+
const from = departure(batch.changes, index);
|
|
87
54
|
if (from === change.path && priorAbsence(batch, change.path) !== undefined)
|
|
88
|
-
return { operation:
|
|
55
|
+
return { operation: uploaded };
|
|
89
56
|
const replaced = priorExistence(batch, from);
|
|
90
57
|
if (replaced === undefined)
|
|
91
58
|
return { rule: 'precondition-missing' };
|
|
92
59
|
if (!('base' in replaced))
|
|
93
60
|
return { rule: 'presence-base-unrepresentable' };
|
|
94
|
-
return { operation: { ...
|
|
61
|
+
return { operation: { ...uploaded, base: replaced.base } };
|
|
95
62
|
}
|
|
96
63
|
const existence = priorExistence(batch, change.path);
|
|
97
64
|
if (existence === undefined)
|
|
98
65
|
return { rule: 'precondition-missing' };
|
|
99
66
|
if (!('base' in existence))
|
|
100
67
|
return { rule: 'presence-base-unrepresentable' };
|
|
101
|
-
if (change.kind === 'replace') {
|
|
102
|
-
return { operation: { op: 'replace', path, base: existence.base, content: change.content } };
|
|
103
|
-
}
|
|
104
68
|
if (change.kind === 'move') {
|
|
105
69
|
if (priorAbsence(batch, change.to) === undefined)
|
|
106
70
|
return { rule: 'precondition-missing' };
|
|
107
71
|
return {
|
|
108
|
-
operation: { op: '
|
|
72
|
+
operation: { op: 'move', path, to: nativePath(change.to, handle), base: existence.base },
|
|
109
73
|
};
|
|
110
74
|
}
|
|
111
|
-
return { operation: { op: '
|
|
75
|
+
return { operation: { op: 'delete', path, base: existence.base } };
|
|
112
76
|
}
|
|
113
|
-
export function houseChanges(batch, handle) {
|
|
77
|
+
export function houseChanges(batch, handle, written) {
|
|
114
78
|
const changes = [];
|
|
115
|
-
|
|
116
|
-
|
|
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;
|
|
117
85
|
if ('rule' in mapped)
|
|
118
86
|
return { kind: 'unmapped', path: change.path, rule: mapped.rule };
|
|
119
|
-
|
|
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
|
+
});
|
|
120
124
|
}
|
|
121
125
|
return { kind: 'changes', changes };
|
|
122
126
|
}
|
|
123
127
|
export function operationHead(batch) {
|
|
124
128
|
const writer = batch.writtenBy;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
: { 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 };
|
|
128
131
|
}
|
|
129
132
|
export function batchPaths(changes) {
|
|
130
133
|
return [
|
|
131
|
-
...new Set(changes.flatMap((change) => change.op === '
|
|
132
|
-
]
|
|
134
|
+
...new Set(changes.flatMap((change) => change.op === 'move' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
135
|
+
];
|
|
133
136
|
}
|
|
134
137
|
export function deltaBody(changes) {
|
|
135
138
|
return JSON.stringify({ changes });
|
|
@@ -144,21 +147,24 @@ export function uploadable(inline, bytes, bounds) {
|
|
|
144
147
|
export function deltaDigest(delta) {
|
|
145
148
|
return sha256Hex(delta);
|
|
146
149
|
}
|
|
147
|
-
function material(value, handle) {
|
|
150
|
+
function* material(value, handle, within = () => true) {
|
|
148
151
|
if (!Array.isArray(value))
|
|
149
152
|
return null;
|
|
150
153
|
const held = [];
|
|
151
154
|
for (const entry of value) {
|
|
155
|
+
yield ROW_WEIGHT;
|
|
152
156
|
if (typeof entry !== 'object' || entry === null)
|
|
153
157
|
return null;
|
|
154
158
|
const file = entry;
|
|
155
159
|
if (typeof file.path !== 'string')
|
|
156
160
|
return null;
|
|
161
|
+
if (!within(file.path))
|
|
162
|
+
continue;
|
|
157
163
|
if (file.content !== null && typeof file.content !== 'string')
|
|
158
164
|
return null;
|
|
159
165
|
if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
|
|
160
166
|
return null;
|
|
161
|
-
const binary =
|
|
167
|
+
const binary = attachmentOf(file);
|
|
162
168
|
if (binary === null)
|
|
163
169
|
return null;
|
|
164
170
|
const head = headChange(file);
|
|
@@ -181,27 +187,69 @@ function material(value, handle) {
|
|
|
181
187
|
}
|
|
182
188
|
return held;
|
|
183
189
|
}
|
|
184
|
-
function affectedOf(held) {
|
|
190
|
+
function* affectedOf(held) {
|
|
185
191
|
const affected = {};
|
|
186
192
|
for (const entry of held) {
|
|
187
193
|
if (entry.content !== null)
|
|
188
194
|
affected[entry.path] = entry.content;
|
|
195
|
+
yield ROW_WEIGHT;
|
|
189
196
|
}
|
|
190
197
|
return affected;
|
|
191
198
|
}
|
|
192
|
-
|
|
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) {
|
|
193
243
|
const refusal = doorRefusal(body);
|
|
194
244
|
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
195
245
|
return { kind: 'write-halted' };
|
|
196
246
|
}
|
|
197
|
-
if (refusal !== null && refusal.code === 'expired')
|
|
198
|
-
return { kind: 'expired' };
|
|
199
247
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
200
248
|
const { current, ...fields } = refusal.fields;
|
|
201
|
-
const held = material(current, handle) ?? [];
|
|
249
|
+
const held = (yield* material(current, handle)) ?? [];
|
|
202
250
|
return {
|
|
203
251
|
kind: 'conflicted',
|
|
204
|
-
affected: affectedOf(held),
|
|
252
|
+
affected: yield* affectedOf(held),
|
|
205
253
|
code: refusal.code,
|
|
206
254
|
fields,
|
|
207
255
|
retryable: refusal.retryable,
|
|
@@ -211,10 +259,8 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
211
259
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
212
260
|
}
|
|
213
261
|
const classified = classifyDoor(status, body, locator);
|
|
214
|
-
const reset = refusal
|
|
215
|
-
if (refusal?.
|
|
216
|
-
typeof reset === 'string' &&
|
|
217
|
-
classified?.kind === 'transport-uncertainty') {
|
|
262
|
+
const reset = resetOf(refusal);
|
|
263
|
+
if (refusal !== null && reset !== undefined && classified?.kind === 'transport-uncertainty') {
|
|
218
264
|
return {
|
|
219
265
|
kind: 'retryable-refusal',
|
|
220
266
|
code: refusal.code,
|
|
@@ -225,8 +271,9 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
225
271
|
}
|
|
226
272
|
if (classified !== null && classified.kind !== 'scoped-refusal')
|
|
227
273
|
return classified;
|
|
228
|
-
if (classified !== null && status === 403)
|
|
274
|
+
if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
|
|
229
275
|
return classified;
|
|
276
|
+
}
|
|
230
277
|
if (refusal !== null && status >= 400) {
|
|
231
278
|
return {
|
|
232
279
|
kind: 'rejected',
|
|
@@ -236,43 +283,20 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
236
283
|
retryable: refusal.retryable,
|
|
237
284
|
};
|
|
238
285
|
}
|
|
239
|
-
if (status !== 200
|
|
240
|
-
return
|
|
241
|
-
|
|
286
|
+
if (status !== 200)
|
|
287
|
+
return answeredFailure(status, body);
|
|
288
|
+
if (typeof body !== 'object' || body === null)
|
|
289
|
+
return unusable();
|
|
242
290
|
const held = body;
|
|
291
|
+
if (move !== undefined)
|
|
292
|
+
return yield* movedOutcome(held, move);
|
|
243
293
|
const at = readPosition(held);
|
|
244
294
|
if (at === null)
|
|
245
|
-
return
|
|
246
|
-
const contents = material(held.contents, handle);
|
|
295
|
+
return unusable();
|
|
296
|
+
const contents = yield* material(held.contents, handle);
|
|
247
297
|
if (contents === null)
|
|
248
|
-
return
|
|
249
|
-
|
|
250
|
-
const revisions = {};
|
|
251
|
-
const changes = {};
|
|
252
|
-
const binaryFiles = {};
|
|
253
|
-
const removals = [];
|
|
254
|
-
for (const entry of contents) {
|
|
255
|
-
if (entry.revision === null) {
|
|
256
|
-
removals.push(entry.path);
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
if (entry.content !== null)
|
|
260
|
-
documents[entry.path] = entry.content;
|
|
261
|
-
if (entry.binary !== undefined)
|
|
262
|
-
binaryFiles[entry.path] = entry.binary;
|
|
263
|
-
revisions[entry.path] = entry.revision;
|
|
264
|
-
if (entry.head !== undefined)
|
|
265
|
-
changes[entry.path] = entry.head;
|
|
266
|
-
}
|
|
267
|
-
return {
|
|
268
|
-
kind: 'accepted',
|
|
269
|
-
roomVersion: roomVersion(at),
|
|
270
|
-
documents,
|
|
271
|
-
revisions,
|
|
272
|
-
changes,
|
|
273
|
-
removals: removals.sort(),
|
|
274
|
-
...(Object.keys(binaryFiles).length === 0 ? {} : { binaryFiles }),
|
|
275
|
-
};
|
|
298
|
+
return unusable();
|
|
299
|
+
return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
|
|
276
300
|
}
|
|
277
301
|
export function rejectedMapping(mapping) {
|
|
278
302
|
return {
|
|
@@ -292,61 +316,51 @@ export function revisionBody(input) {
|
|
|
292
316
|
}
|
|
293
317
|
function revisionAuthor(entry) {
|
|
294
318
|
const user = entry.author_user;
|
|
319
|
+
const userName = entry.author_user_name;
|
|
295
320
|
const site = entry.author_site;
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
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 };
|
|
299
333
|
}
|
|
300
|
-
if (
|
|
301
|
-
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 };
|
|
302
339
|
}
|
|
303
340
|
return null;
|
|
304
341
|
}
|
|
305
|
-
function historyBinary(entry) {
|
|
306
|
-
if (entry.file === undefined)
|
|
307
|
-
return undefined;
|
|
308
|
-
const { file, bytes, media_type: mediaType, sha256 } = entry;
|
|
309
|
-
if (typeof file !== 'string' ||
|
|
310
|
-
typeof bytes !== 'number' ||
|
|
311
|
-
typeof mediaType !== 'string' ||
|
|
312
|
-
typeof sha256 !== 'string')
|
|
313
|
-
return null;
|
|
314
|
-
return { fileRef: file, byteLength: bytes, mediaType, sha256 };
|
|
315
|
-
}
|
|
316
342
|
export function historyOutcome(status, body, locator, request) {
|
|
317
343
|
const classified = classifyDoor(status, body, locator);
|
|
318
344
|
if (classified !== null)
|
|
319
345
|
return classified;
|
|
320
346
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
321
|
-
return
|
|
347
|
+
return unusable();
|
|
322
348
|
}
|
|
323
349
|
const held = body;
|
|
324
350
|
if (!Array.isArray(held.revisions))
|
|
325
|
-
return
|
|
351
|
+
return unusable();
|
|
326
352
|
const entries = [];
|
|
327
353
|
for (const entry of held.revisions) {
|
|
328
354
|
if (typeof entry !== 'object' || entry === null)
|
|
329
|
-
return
|
|
355
|
+
return unusable();
|
|
330
356
|
entries.push(entry);
|
|
331
357
|
}
|
|
332
|
-
|
|
333
|
-
|
|
358
|
+
const named = entries[0];
|
|
359
|
+
if (request.revision !== undefined && typeof named?.media_type !== 'string') {
|
|
334
360
|
if (named === undefined)
|
|
335
361
|
return { kind: 'no-history' };
|
|
336
|
-
if (named.unavailable === true) {
|
|
337
|
-
return {
|
|
338
|
-
kind: 'scoped-refusal',
|
|
339
|
-
locator,
|
|
340
|
-
scope: 'content',
|
|
341
|
-
code: 'retained_history_unavailable',
|
|
342
|
-
fields: { path: request.path, revision: request.revision },
|
|
343
|
-
retryable: false,
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
if (typeof named.file === 'string')
|
|
347
|
-
return { kind: 'no-history' };
|
|
348
362
|
if (typeof named.content !== 'string')
|
|
349
|
-
return
|
|
363
|
+
return unusable();
|
|
350
364
|
return { kind: 'revision', content: named.content };
|
|
351
365
|
}
|
|
352
366
|
if (entries.length === 0)
|
|
@@ -357,16 +371,16 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
357
371
|
if (typeof entry.revision !== 'string' ||
|
|
358
372
|
author === null ||
|
|
359
373
|
typeof entry.created_at !== 'string') {
|
|
360
|
-
return
|
|
374
|
+
return unusable();
|
|
361
375
|
}
|
|
362
|
-
const
|
|
363
|
-
if (
|
|
364
|
-
return
|
|
376
|
+
const attachment = attachmentOf(entry);
|
|
377
|
+
if (attachment === null)
|
|
378
|
+
return unusable();
|
|
365
379
|
revisions.push({
|
|
366
380
|
revision: entry.revision,
|
|
367
381
|
author,
|
|
368
382
|
time: entry.created_at,
|
|
369
|
-
...(
|
|
383
|
+
...(attachment === undefined ? {} : { attachment }),
|
|
370
384
|
});
|
|
371
385
|
}
|
|
372
386
|
const next = held.next_before;
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-c86eddcb309ff",
|
|
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-c248d240eb2f6",
|
|
27
|
+
"@agentshouse/mdruntime": "0.1.0-c04c556aa5c93"
|
|
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-c87013e8a4dd8"
|
|
31
35
|
}
|