@agentshouse/mdruntime-adapter 0.1.0-ce7ce34e4ced0 → 0.1.0-ce861e3fb788a
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 +1 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +27 -5
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +35 -53
- package/dist/authored-path.d.ts +54 -2
- package/dist/authored-path.d.ts.map +1 -1
- package/dist/authored-path.js +142 -10
- package/dist/chunks.js +1 -1
- package/dist/discovery.js +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/read.d.ts +6 -6
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +9 -9
- 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.map +1 -1
- package/dist/room-query.js +24 -9
- package/dist/session-content/check.d.ts +4 -1
- package/dist/session-content/index.d.ts +1 -1
- package/dist/session-content/parts.d.ts +5 -5
- package/dist/session-content/state.d.ts +18 -18
- package/dist/session-content/turn.d.ts +55 -40
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +12 -4
- package/dist/stream.d.ts +2 -1
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +72 -4
- package/dist/transport.d.ts +36 -8
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +16 -13
- package/dist/upload.d.ts +4 -0
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +41 -0
- package/dist/write.d.ts +3 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +70 -88
- package/package.json +4 -4
package/dist/write.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { departure,
|
|
2
|
-
import { answered, answering,
|
|
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
5
|
import { answeredFailure, classifyDoor, doorRefusal, resetOf, scopedRefusal } from './refusal.js';
|
|
6
6
|
import { readPosition, roomVersion } from './version.js';
|
|
7
7
|
import { unusable } from './uncertain.js';
|
|
8
|
-
function
|
|
9
|
-
return batch.preconditions.find((
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return batch.preconditions.find((precondition) => precondition.kind === 'section' && precondition.path === path && precondition.name === name);
|
|
13
|
-
}
|
|
14
|
-
function priorPreamble(batch, path) {
|
|
15
|
-
return batch.preconditions.find((precondition) => precondition.kind === 'preamble' && precondition.path === path);
|
|
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)));
|
|
16
12
|
}
|
|
17
13
|
function priorAbsence(batch, path) {
|
|
18
14
|
return batch.preconditions.find((precondition) => precondition.kind === 'absent' && precondition.path === path);
|
|
@@ -23,60 +19,30 @@ function priorExistence(batch, path) {
|
|
|
23
19
|
return undefined;
|
|
24
20
|
return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };
|
|
25
21
|
}
|
|
26
|
-
function
|
|
27
|
-
if (
|
|
28
|
-
return {
|
|
29
|
-
|
|
30
|
-
|
|
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)
|
|
31
30
|
return null;
|
|
32
|
-
|
|
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 } };
|
|
33
38
|
}
|
|
34
|
-
function operationOf(batch,
|
|
39
|
+
function operationOf(batch, index, handle, written) {
|
|
40
|
+
const change = batch.changes[index];
|
|
35
41
|
const path = nativePath(change.path, handle);
|
|
36
|
-
if (change.kind === '
|
|
37
|
-
|
|
38
|
-
if (prior === undefined)
|
|
39
|
-
return { rule: 'precondition-missing' };
|
|
40
|
-
return {
|
|
41
|
-
operation: {
|
|
42
|
-
op: 'set_field',
|
|
43
|
-
path,
|
|
44
|
-
field: change.name,
|
|
45
|
-
value: change.value,
|
|
46
|
-
...(prior.value === undefined ? {} : { base: prior.value }),
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (change.kind === 'section') {
|
|
51
|
-
const prior = priorSection(batch, change.path, change.name);
|
|
52
|
-
if (prior === undefined)
|
|
53
|
-
return { rule: 'precondition-missing' };
|
|
54
|
-
return {
|
|
55
|
-
operation: {
|
|
56
|
-
op: 'replace_section',
|
|
57
|
-
path,
|
|
58
|
-
section: change.name,
|
|
59
|
-
base: prior.value,
|
|
60
|
-
content: change.value,
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (change.kind === 'preamble') {
|
|
65
|
-
const prior = priorPreamble(batch, change.path);
|
|
66
|
-
if (prior === undefined)
|
|
67
|
-
return { rule: 'precondition-missing' };
|
|
68
|
-
return {
|
|
69
|
-
operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
if (change.kind === 'create') {
|
|
73
|
-
if (priorAbsence(batch, change.path) === undefined)
|
|
74
|
-
return { rule: 'precondition-missing' };
|
|
75
|
-
const operation = created(change, path);
|
|
76
|
-
return operation === null ? { rule: 'type-missing' } : { operation };
|
|
77
|
-
}
|
|
42
|
+
if (isPart(change) || change.kind === 'create' || change.kind === 'replace')
|
|
43
|
+
return textOf(batch, change, path, written[index]);
|
|
78
44
|
if (change.kind === 'binary') {
|
|
79
|
-
const
|
|
45
|
+
const uploaded = {
|
|
80
46
|
op: 'upload',
|
|
81
47
|
path,
|
|
82
48
|
local_id: change.localId,
|
|
@@ -84,45 +50,61 @@ function operationOf(batch, change, handle) {
|
|
|
84
50
|
sha256: change.sha256,
|
|
85
51
|
media_type: change.mediaType,
|
|
86
52
|
};
|
|
87
|
-
const from = departure(batch.changes,
|
|
53
|
+
const from = departure(batch.changes, index);
|
|
88
54
|
if (from === change.path && priorAbsence(batch, change.path) !== undefined)
|
|
89
|
-
return { operation:
|
|
55
|
+
return { operation: uploaded };
|
|
90
56
|
const replaced = priorExistence(batch, from);
|
|
91
57
|
if (replaced === undefined)
|
|
92
58
|
return { rule: 'precondition-missing' };
|
|
93
59
|
if (!('base' in replaced))
|
|
94
60
|
return { rule: 'presence-base-unrepresentable' };
|
|
95
|
-
return { operation: { ...
|
|
61
|
+
return { operation: { ...uploaded, base: replaced.base } };
|
|
96
62
|
}
|
|
97
63
|
const existence = priorExistence(batch, change.path);
|
|
98
64
|
if (existence === undefined)
|
|
99
65
|
return { rule: 'precondition-missing' };
|
|
100
66
|
if (!('base' in existence))
|
|
101
67
|
return { rule: 'presence-base-unrepresentable' };
|
|
102
|
-
if (change.kind === 'replace') {
|
|
103
|
-
return { operation: { op: 'replace', path, base: existence.base, content: change.content } };
|
|
104
|
-
}
|
|
105
68
|
if (change.kind === 'move') {
|
|
106
69
|
if (priorAbsence(batch, change.to) === undefined)
|
|
107
70
|
return { rule: 'precondition-missing' };
|
|
108
71
|
return {
|
|
109
|
-
operation: { op: '
|
|
72
|
+
operation: { op: 'move', path, to: nativePath(change.to, handle), base: existence.base },
|
|
110
73
|
};
|
|
111
74
|
}
|
|
112
|
-
return { operation: { op: '
|
|
75
|
+
return { operation: { op: 'delete', path, base: existence.base } };
|
|
113
76
|
}
|
|
114
|
-
export function houseChanges(batch, handle) {
|
|
77
|
+
export function houseChanges(batch, handle, written) {
|
|
115
78
|
const changes = [];
|
|
116
|
-
|
|
117
|
-
|
|
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;
|
|
118
85
|
if ('rule' in mapped)
|
|
119
86
|
return { kind: 'unmapped', path: change.path, rule: mapped.rule };
|
|
120
|
-
|
|
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);
|
|
121
100
|
}
|
|
122
|
-
return {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
+
};
|
|
126
108
|
}
|
|
127
109
|
export function houseMove(batch, source, destination) {
|
|
128
110
|
const changes = [];
|
|
@@ -134,7 +116,7 @@ export function houseMove(batch, source, destination) {
|
|
|
134
116
|
return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
|
|
135
117
|
}
|
|
136
118
|
changes.push({
|
|
137
|
-
op: '
|
|
119
|
+
op: 'move',
|
|
138
120
|
path: nativePath(path, source),
|
|
139
121
|
to: nativePath(to, destination),
|
|
140
122
|
base: existence.base,
|
|
@@ -142,14 +124,14 @@ export function houseMove(batch, source, destination) {
|
|
|
142
124
|
}
|
|
143
125
|
return { kind: 'changes', changes };
|
|
144
126
|
}
|
|
145
|
-
export function operationHead(batch
|
|
127
|
+
export function operationHead(batch) {
|
|
146
128
|
const writer = batch.writtenBy;
|
|
147
|
-
const head = { operation_id: batch.id
|
|
129
|
+
const head = { operation_id: batch.id };
|
|
148
130
|
return writer === undefined ? head : { ...head, app_ref: writer.app, release: writer.release };
|
|
149
131
|
}
|
|
150
132
|
export function batchPaths(changes) {
|
|
151
133
|
return [
|
|
152
|
-
...new Set(changes.flatMap((change) => change.op === '
|
|
134
|
+
...new Set(changes.flatMap((change) => change.op === 'move' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
153
135
|
];
|
|
154
136
|
}
|
|
155
137
|
export function deltaBody(changes) {
|
|
@@ -182,7 +164,7 @@ function* material(value, handle, within = () => true) {
|
|
|
182
164
|
return null;
|
|
183
165
|
if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
|
|
184
166
|
return null;
|
|
185
|
-
const binary =
|
|
167
|
+
const binary = attachmentOf(file);
|
|
186
168
|
if (binary === null)
|
|
187
169
|
return null;
|
|
188
170
|
const head = headChange(file);
|
|
@@ -225,14 +207,14 @@ function* acceptedOf(at, contents) {
|
|
|
225
207
|
if (entry.content !== null)
|
|
226
208
|
answer.documents.set(entry.path, entry.content);
|
|
227
209
|
if (entry.binary !== undefined)
|
|
228
|
-
answer.
|
|
210
|
+
answer.attachments.set(entry.path, entry.binary);
|
|
229
211
|
revised(answer, entry.path, entry.revision);
|
|
230
212
|
if (entry.head !== undefined)
|
|
231
213
|
answer.changes.set(entry.path, entry.head);
|
|
232
214
|
}
|
|
233
|
-
const unbinaried = answer.
|
|
234
|
-
const {
|
|
235
|
-
return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : {
|
|
215
|
+
const unbinaried = answer.attachments.size === 0;
|
|
216
|
+
const { attachments, facts: _facts, ...room } = yield* answered(answer);
|
|
217
|
+
return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { attachments }) };
|
|
236
218
|
}
|
|
237
219
|
function* movedOutcome(held, move) {
|
|
238
220
|
const authorities = Array.isArray(held.authorities) ? held.authorities : [];
|
|
@@ -391,14 +373,14 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
391
373
|
typeof entry.created_at !== 'string') {
|
|
392
374
|
return unusable();
|
|
393
375
|
}
|
|
394
|
-
const
|
|
395
|
-
if (
|
|
376
|
+
const attachment = attachmentOf(entry);
|
|
377
|
+
if (attachment === null)
|
|
396
378
|
return unusable();
|
|
397
379
|
revisions.push({
|
|
398
380
|
revision: entry.revision,
|
|
399
381
|
author,
|
|
400
382
|
time: entry.created_at,
|
|
401
|
-
...(
|
|
383
|
+
...(attachment === undefined ? {} : { attachment }),
|
|
402
384
|
});
|
|
403
385
|
}
|
|
404
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-ce7ce34e4ced0",
|
|
4
3
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
4
|
"license": "MIT",
|
|
6
5
|
"type": "module",
|
|
@@ -24,12 +23,13 @@
|
|
|
24
23
|
"LICENSE"
|
|
25
24
|
],
|
|
26
25
|
"dependencies": {
|
|
27
|
-
"@agentshouse/mdmodel": "0.1.0-
|
|
28
|
-
"@agentshouse/mdruntime": "0.1.0-
|
|
26
|
+
"@agentshouse/mdmodel": "0.1.0-c4c6dbb0dc160",
|
|
27
|
+
"@agentshouse/mdruntime": "0.1.0-c0f755c73b599"
|
|
29
28
|
},
|
|
30
29
|
"repository": {
|
|
31
30
|
"type": "git",
|
|
32
31
|
"url": "git+https://github.com/agentshouse/core.git",
|
|
33
32
|
"directory": "mdruntime/packages/mdruntime-adapter"
|
|
34
|
-
}
|
|
33
|
+
},
|
|
34
|
+
"version": "0.1.0-ce861e3fb788a"
|
|
35
35
|
}
|