@agentshouse/mdruntime-adapter 0.1.0-c2b8b021403fc → 0.1.0-c2c0ec6c1f436
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/dist/actions.d.ts +0 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -7
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +26 -17
- package/dist/authored-path.d.ts +0 -5
- package/dist/authored-path.d.ts.map +1 -1
- package/dist/authored-path.js +2 -2
- package/dist/discovery.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/read.d.ts +2 -2
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +3 -3
- 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 +7 -2
- 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 +16 -21
- package/dist/session-content/turn.d.ts +53 -43
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +11 -3
- package/dist/stream.d.ts +2 -1
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +72 -3
- package/dist/transport.d.ts +34 -6
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +10 -8
- package/dist/write.d.ts +3 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +61 -79
- package/package.json +4 -4
package/dist/write.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { departure,
|
|
1
|
+
import { departure, isPart, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
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) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-c2b8b021403fc",
|
|
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-c9834b5077312"
|
|
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-c2c0ec6c1f436"
|
|
35
35
|
}
|