@agentshouse/mdruntime 0.1.0-c2aaa9c0e3ca4 → 0.1.0-c2c52158b7381
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/AGENTS.md +285 -276
- package/README.md +9 -8
- package/dist/adapter.d.ts +80 -21
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +4 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +13 -3
- package/dist/attempt.d.ts.map +1 -1
- package/dist/attempt.js +14 -1
- package/dist/bootstrap.d.ts +3 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +83 -26
- package/dist/change-set.d.ts +7 -2
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +37 -10
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/chat/acts.d.ts +3 -4
- package/dist/chat/acts.d.ts.map +1 -1
- package/dist/chat/acts.js +10 -10
- package/dist/chat/earlier.d.ts +10 -0
- package/dist/chat/earlier.d.ts.map +1 -0
- package/dist/chat/earlier.js +54 -0
- package/dist/chat/house.d.ts +25 -0
- package/dist/chat/house.d.ts.map +1 -0
- package/dist/chat/house.js +38 -0
- package/dist/chat/input.d.ts +3 -1
- package/dist/chat/input.d.ts.map +1 -1
- package/dist/chat/input.js +11 -18
- package/dist/chat/kit.d.ts +2 -1
- package/dist/chat/kit.d.ts.map +1 -1
- package/dist/chat/kit.js +3 -3
- package/dist/chat/list.d.ts +9 -1
- package/dist/chat/list.d.ts.map +1 -1
- package/dist/chat/list.js +53 -9
- package/dist/chat/markdown.d.ts +3 -1
- package/dist/chat/markdown.d.ts.map +1 -1
- package/dist/chat/markdown.js +85 -26
- package/dist/chat/message.d.ts +1 -0
- package/dist/chat/message.d.ts.map +1 -1
- package/dist/chat/message.js +57 -12
- package/dist/chat/messages.d.ts +9 -1
- package/dist/chat/messages.d.ts.map +1 -1
- package/dist/chat/messages.js +67 -28
- package/dist/chat/name.d.ts +1 -0
- package/dist/chat/name.d.ts.map +1 -1
- package/dist/chat/name.js +1 -1
- package/dist/chat/opened.d.ts +1 -0
- package/dist/chat/opened.d.ts.map +1 -1
- package/dist/chat/opened.js +2 -0
- package/dist/chat/overlay.d.ts +1 -0
- package/dist/chat/overlay.d.ts.map +1 -1
- package/dist/chat/overlay.js +11 -5
- package/dist/chat/parts.d.ts +1 -0
- package/dist/chat/parts.d.ts.map +1 -1
- package/dist/chat/parts.js +3 -2
- package/dist/chat/pieces.d.ts +62 -0
- package/dist/chat/pieces.d.ts.map +1 -0
- package/dist/chat/pieces.js +1110 -0
- package/dist/chat/provider.d.ts +7 -2
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +129 -155
- package/dist/chat/question.d.ts +1 -1
- package/dist/chat/question.d.ts.map +1 -1
- package/dist/chat/question.js +7 -18
- package/dist/chat/ready.d.ts +5 -1
- package/dist/chat/ready.d.ts.map +1 -1
- package/dist/chat/ready.js +9 -7
- package/dist/chat/room-file.d.ts +8 -0
- package/dist/chat/room-file.d.ts.map +1 -0
- package/dist/chat/room-file.js +72 -0
- package/dist/chat/steady.d.ts +3 -0
- package/dist/chat/steady.d.ts.map +1 -0
- package/dist/chat/steady.js +26 -0
- package/dist/chat/style.d.ts.map +1 -1
- package/dist/chat/style.js +8 -4
- package/dist/chat.d.ts +3 -2
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +2 -2
- package/dist/client.d.ts +21 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +47 -8
- package/dist/collection.d.ts +21 -6
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +332 -40
- package/dist/connection.d.ts +39 -11
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2294 -492
- package/dist/conversation.d.ts +28 -9
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +500 -165
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +8 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +18 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +157 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/file.d.ts +2 -10
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -120
- package/dist/host.d.ts +15 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +103 -13
- package/dist/identity.d.ts +2 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +6 -0
- package/dist/index.d.ts +15 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/memory.d.ts +8 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +43 -12
- package/dist/model.d.ts +4 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +10 -1
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +7 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +29 -12
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +39 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +29 -0
- package/dist/overlay.d.ts +6 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +229 -161
- package/dist/query.d.ts +57 -4
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +37 -7
- package/dist/reach.d.ts +11 -4
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +192 -41
- package/dist/react.d.ts +8 -6
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +7 -17
- package/dist/read-side.d.ts +18 -9
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +894 -155
- package/dist/readiness.d.ts +53 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +33 -0
- package/dist/reads.d.ts +11 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +98 -0
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +198 -0
- package/dist/refresh.d.ts +4 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +46 -20
- package/dist/replica.d.ts +12 -7
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +151 -64
- package/dist/room-draft.d.ts +16 -2
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +32 -25
- package/dist/rows.d.ts +6 -13
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +10 -13
- package/dist/save.d.ts +52 -10
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +519 -159
- package/dist/search.d.ts +49 -6
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +242 -46
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +19 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +461 -0
- package/dist/status.d.ts +4 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/store.d.ts +61 -17
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +581 -310
- package/dist/tables.d.ts +242 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +406 -0
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +67 -0
- package/dist/windows.d.ts +21 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +84 -0
- package/dist/wire.d.ts +168 -32
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +56 -31
- package/package.json +10 -2
package/dist/replica.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
2
|
import { immutable, landing } from './change.js';
|
|
3
|
-
import {
|
|
4
|
-
import { acceptedBinaries,
|
|
5
|
-
import {
|
|
3
|
+
import { changedCleanly, collecting, unreadable, validateCollection, } from './collection.js';
|
|
4
|
+
import { acceptedBinaries, overlayChanged, overlaying, sameText, } from './overlay.js';
|
|
5
|
+
import { effectiveIn, rewriting } from './save.js';
|
|
6
|
+
import { drafted, entriesIn, patched, settling, sharing } from './shared.js';
|
|
7
|
+
import { ROW_WEIGHT, stepped } from './turn.js';
|
|
6
8
|
export function compositionOf(record) {
|
|
7
9
|
return {
|
|
8
10
|
model: record.model,
|
|
@@ -11,51 +13,90 @@ export function compositionOf(record) {
|
|
|
11
13
|
: { roots: record.typedSelection.roots, model: record.selectionModel },
|
|
12
14
|
};
|
|
13
15
|
}
|
|
16
|
+
function* holding(record) {
|
|
17
|
+
const documents = yield* sharing(record.documents);
|
|
18
|
+
const binaries = yield* sharing(record.binaries);
|
|
19
|
+
const revisions = yield* sharing(record.revisions);
|
|
20
|
+
const fileIds = yield* sharing(record.fileIds);
|
|
21
|
+
const changes = yield* sharing(record.changes);
|
|
22
|
+
const written = yield* sharing(record.written);
|
|
23
|
+
return documents === record.documents &&
|
|
24
|
+
binaries === record.binaries &&
|
|
25
|
+
revisions === record.revisions &&
|
|
26
|
+
fileIds === record.fileIds &&
|
|
27
|
+
changes === record.changes &&
|
|
28
|
+
written === record.written
|
|
29
|
+
? record
|
|
30
|
+
: { ...record, documents, binaries, revisions, fileIds, changes, written };
|
|
31
|
+
}
|
|
14
32
|
export function confirmedOf(record, previous) {
|
|
33
|
+
return stepped(confirming(record, previous));
|
|
34
|
+
}
|
|
35
|
+
function* confirming(record, previous) {
|
|
36
|
+
const kept = yield* holding(record);
|
|
15
37
|
return {
|
|
16
|
-
record,
|
|
17
|
-
collection:
|
|
38
|
+
record: kept,
|
|
39
|
+
collection: yield* collecting(kept.documents, compositionOf(kept), previous?.collection),
|
|
18
40
|
};
|
|
19
41
|
}
|
|
20
42
|
export function sameMembership(record, other) {
|
|
21
43
|
return (JSON.stringify(record.typedSelection?.roots ?? null) ===
|
|
22
44
|
JSON.stringify(other.typedSelection?.roots ?? null));
|
|
23
45
|
}
|
|
24
|
-
|
|
25
|
-
|
|
46
|
+
function* cleanly(record, previous) {
|
|
47
|
+
if (previous === undefined)
|
|
48
|
+
return false;
|
|
49
|
+
const before = previous.record;
|
|
50
|
+
return yield* changedCleanly({ text: record.documents, binaries: record.binaries }, { text: before.documents, binaries: before.binaries, composition: compositionOf(before) }, compositionOf(record));
|
|
51
|
+
}
|
|
52
|
+
function* staging(staged, previous) {
|
|
53
|
+
const record = yield* holding(staged);
|
|
54
|
+
const textChanged = previous === undefined || !(yield* sameText(record, previous.record));
|
|
26
55
|
const modeled = record.model.status !== 'unavailable' || record.selectionModel.status !== 'unavailable';
|
|
27
56
|
if (modeled &&
|
|
28
57
|
(textChanged ||
|
|
29
58
|
record.model !== previous?.record.model ||
|
|
30
|
-
record.selectionModel !== previous?.record.selectionModel)
|
|
31
|
-
|
|
59
|
+
record.selectionModel !== previous?.record.selectionModel) &&
|
|
60
|
+
!(yield* cleanly(record, previous))) {
|
|
61
|
+
const verdict = yield* validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
32
62
|
if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
|
|
33
63
|
return { kind: 'refused', refusal: verdict };
|
|
34
64
|
}
|
|
35
65
|
if (verdict.verdict === 'refuse') {
|
|
36
|
-
const refused = unreadable(record.documents, previous?.record.documents);
|
|
66
|
+
const refused = yield* unreadable(record.documents, previous?.record.documents);
|
|
37
67
|
if (refused !== null)
|
|
38
68
|
return refused;
|
|
39
69
|
}
|
|
40
70
|
}
|
|
41
71
|
else if (textChanged) {
|
|
42
|
-
const refused = unreadable(record.documents, previous?.record.documents);
|
|
72
|
+
const refused = yield* unreadable(record.documents, previous?.record.documents);
|
|
43
73
|
if (refused !== null)
|
|
44
74
|
return refused;
|
|
45
75
|
}
|
|
46
|
-
return { kind: 'staged', confirmed:
|
|
76
|
+
return { kind: 'staged', confirmed: yield* confirming(record, previous) };
|
|
47
77
|
}
|
|
48
|
-
export function
|
|
49
|
-
|
|
78
|
+
export function readStaged(staged, previous) {
|
|
79
|
+
return stepped(staging(staged, previous));
|
|
80
|
+
}
|
|
81
|
+
function* reclassifying(record, previous) {
|
|
82
|
+
const verdict = yield* validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
50
83
|
if (verdict.verdict !== 'refuse')
|
|
51
|
-
return { kind: 'staged', confirmed:
|
|
84
|
+
return { kind: 'staged', confirmed: yield* confirming(record, previous) };
|
|
52
85
|
return verdict.rule === 'model-unavailable'
|
|
53
86
|
? { kind: 'deferred' }
|
|
54
87
|
: { kind: 'refused', refusal: verdict };
|
|
55
88
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
89
|
+
export function readReclassified(record, previous) {
|
|
90
|
+
return stepped(reclassifying(record, previous));
|
|
91
|
+
}
|
|
92
|
+
function* returnedBinaries(held, submitted, accepted) {
|
|
93
|
+
const binaries = drafted(held);
|
|
58
94
|
for (const change of submitted.changes) {
|
|
95
|
+
if (change.kind === 'arrival' && 'binary' in change) {
|
|
96
|
+
if (accepted.revisions[change.path] !== undefined)
|
|
97
|
+
binaries[change.path] = { state: 'accepted', ...change.binary };
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
59
100
|
if (change.kind !== 'move')
|
|
60
101
|
continue;
|
|
61
102
|
const moved = binaries[change.path];
|
|
@@ -64,52 +105,78 @@ function returnedBinaries(held, submitted, accepted) {
|
|
|
64
105
|
binaries[change.to] = moved;
|
|
65
106
|
delete binaries[change.path];
|
|
66
107
|
}
|
|
67
|
-
|
|
68
|
-
|
|
108
|
+
for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {})) {
|
|
109
|
+
binaries[path] = binary;
|
|
110
|
+
yield ROW_WEIGHT;
|
|
111
|
+
}
|
|
112
|
+
for (const path of accepted.removals) {
|
|
69
113
|
delete binaries[path];
|
|
70
|
-
|
|
114
|
+
yield ROW_WEIGHT;
|
|
115
|
+
}
|
|
116
|
+
return yield* settling(binaries);
|
|
71
117
|
}
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
118
|
+
function* returning(confirmed, submitted, accepted, roomVersion, writtenAt) {
|
|
119
|
+
const held = confirmed.record;
|
|
120
|
+
const documents = drafted(held.documents);
|
|
121
|
+
const revisions = drafted(held.revisions);
|
|
122
|
+
const fileIds = drafted(held.fileIds);
|
|
123
|
+
const changes = drafted(held.changes);
|
|
124
|
+
const written = drafted(held.written);
|
|
125
|
+
for (const [path, content] of entriesIn(accepted.documents)) {
|
|
126
|
+
documents[path] = content;
|
|
127
|
+
delete fileIds[path];
|
|
128
|
+
written[path] = writtenAt;
|
|
129
|
+
yield ROW_WEIGHT + content.length;
|
|
84
130
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
delete
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
131
|
+
for (const [path, revision] of entriesIn(accepted.revisions)) {
|
|
132
|
+
revisions[path] = revision;
|
|
133
|
+
delete fileIds[path];
|
|
134
|
+
if (held.revisions[path] !== revision)
|
|
135
|
+
delete changes[path];
|
|
136
|
+
yield ROW_WEIGHT;
|
|
91
137
|
}
|
|
92
|
-
|
|
93
|
-
|
|
138
|
+
for (const [path, fileId] of entriesIn(accepted.fileIds ?? {})) {
|
|
139
|
+
fileIds[path] = fileId;
|
|
140
|
+
yield ROW_WEIGHT;
|
|
141
|
+
}
|
|
142
|
+
for (const [path, change] of entriesIn(accepted.changes)) {
|
|
143
|
+
changes[path] = change;
|
|
144
|
+
yield ROW_WEIGHT;
|
|
145
|
+
}
|
|
146
|
+
for (const path of accepted.removals) {
|
|
147
|
+
delete documents[path];
|
|
148
|
+
delete revisions[path];
|
|
149
|
+
delete fileIds[path];
|
|
150
|
+
delete changes[path];
|
|
151
|
+
delete written[path];
|
|
152
|
+
yield ROW_WEIGHT;
|
|
153
|
+
}
|
|
154
|
+
return yield* staging({
|
|
155
|
+
...held,
|
|
94
156
|
roomVersion,
|
|
95
|
-
documents:
|
|
96
|
-
revisions:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
157
|
+
documents: yield* settling(documents),
|
|
158
|
+
revisions: yield* settling(revisions),
|
|
159
|
+
fileIds: yield* settling(fileIds),
|
|
160
|
+
changes: yield* settling(changes),
|
|
161
|
+
written: yield* settling(written),
|
|
162
|
+
binaries: yield* returnedBinaries(held.binaries, submitted, accepted),
|
|
100
163
|
}, confirmed);
|
|
101
164
|
}
|
|
102
|
-
function
|
|
165
|
+
export function applyReturned(confirmed, submitted, accepted, roomVersion, writtenAt) {
|
|
166
|
+
return stepped(returning(confirmed, submitted, accepted, roomVersion, writtenAt));
|
|
167
|
+
}
|
|
168
|
+
function* predicting(confirmed, batches, previous) {
|
|
103
169
|
const composition = compositionOf(confirmed.record);
|
|
170
|
+
const locator = confirmed.record.locator;
|
|
104
171
|
let layer = confirmed.record;
|
|
105
172
|
const replay = [];
|
|
106
173
|
const prior = new Map(previous?.replay.map((step) => [step.id, step]) ?? []);
|
|
107
174
|
for (const batch of batches) {
|
|
108
175
|
const before = layer;
|
|
109
176
|
const old = prior.get(batch.id);
|
|
110
|
-
const hasMove = batch
|
|
177
|
+
const hasMove = rewriting(batch, locator);
|
|
111
178
|
const reuseRewrite = old?.collection !== undefined &&
|
|
112
|
-
|
|
179
|
+
(yield* sameText(before, old.before)) &&
|
|
113
180
|
old.collection.composition.model === composition.model &&
|
|
114
181
|
old.collection.composition.selection?.model === composition.selection?.model &&
|
|
115
182
|
JSON.stringify(old.collection.composition.selection?.roots) ===
|
|
@@ -117,17 +184,17 @@ function predicted(confirmed, batches, previous) {
|
|
|
117
184
|
const collection = hasMove
|
|
118
185
|
? reuseRewrite
|
|
119
186
|
? old.collection
|
|
120
|
-
:
|
|
187
|
+
: yield* collecting(before.documents, composition, old?.collection ?? confirmed.collection)
|
|
121
188
|
: undefined;
|
|
122
189
|
const effective = collection === undefined
|
|
123
190
|
? batch
|
|
124
191
|
: reuseRewrite
|
|
125
192
|
? old.effective
|
|
126
|
-
:
|
|
193
|
+
: yield* effectiveIn(batch, locator, { ...before, collection });
|
|
127
194
|
layer =
|
|
128
195
|
old === undefined
|
|
129
|
-
?
|
|
130
|
-
: overlayChanged(before,
|
|
196
|
+
? yield* overlaying(before, [effective])
|
|
197
|
+
: yield* overlayChanged(before, effective, old.before, old.effective, old.after);
|
|
131
198
|
replay.push({
|
|
132
199
|
id: batch.id,
|
|
133
200
|
before,
|
|
@@ -138,7 +205,7 @@ function predicted(confirmed, batches, previous) {
|
|
|
138
205
|
}
|
|
139
206
|
return { layer, replay };
|
|
140
207
|
}
|
|
141
|
-
export function
|
|
208
|
+
export function* replicating(confirmed, queue, previous) {
|
|
142
209
|
const batches = Object.freeze(queue.map(immutable));
|
|
143
210
|
if (batches.length === 0) {
|
|
144
211
|
return {
|
|
@@ -148,20 +215,21 @@ export function replicaOf(confirmed, queue, previous) {
|
|
|
148
215
|
documents: confirmed.record.documents,
|
|
149
216
|
binaries: confirmed.record.binaries,
|
|
150
217
|
revisions: confirmed.record.revisions,
|
|
218
|
+
fileIds: confirmed.record.fileIds,
|
|
151
219
|
changes: confirmed.record.changes,
|
|
152
220
|
collection: confirmed.collection,
|
|
153
221
|
},
|
|
154
222
|
replay: [],
|
|
155
223
|
};
|
|
156
224
|
}
|
|
157
|
-
const { layer, replay } =
|
|
225
|
+
const { layer, replay } = yield* predicting(confirmed, batches, previous);
|
|
158
226
|
return {
|
|
159
227
|
confirmed,
|
|
160
228
|
queue: batches,
|
|
161
229
|
replay,
|
|
162
230
|
visible: {
|
|
163
231
|
...layer,
|
|
164
|
-
collection:
|
|
232
|
+
collection: yield* collecting(layer.documents, compositionOf(confirmed.record), previous?.visible.collection ?? confirmed.collection),
|
|
165
233
|
},
|
|
166
234
|
};
|
|
167
235
|
}
|
|
@@ -233,12 +301,15 @@ function effects(change) {
|
|
|
233
301
|
{ kind: 'present', path: change.to },
|
|
234
302
|
];
|
|
235
303
|
}
|
|
236
|
-
if (change.kind === 'binary')
|
|
304
|
+
if (change.kind === 'binary' || change.kind === 'arrival')
|
|
237
305
|
return [{ kind: 'present', path }];
|
|
238
306
|
return [{ kind: 'absent', path }];
|
|
239
307
|
}
|
|
240
308
|
export function landed(batch, confirmed, current = {}) {
|
|
241
|
-
const layer = {
|
|
309
|
+
const layer = {
|
|
310
|
+
...confirmed.record,
|
|
311
|
+
documents: patched(confirmed.record.documents, Object.entries(current)),
|
|
312
|
+
};
|
|
242
313
|
return batch.changes.every((change, index) => {
|
|
243
314
|
if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
|
|
244
315
|
const at = landing(batch.changes, index, change.path);
|
|
@@ -256,32 +327,48 @@ export function landed(batch, confirmed, current = {}) {
|
|
|
256
327
|
});
|
|
257
328
|
});
|
|
258
329
|
}
|
|
259
|
-
|
|
330
|
+
function founded(batch, layer) {
|
|
331
|
+
let changed = false;
|
|
332
|
+
const preconditions = batch.preconditions.map((precondition) => {
|
|
333
|
+
if (precondition.kind !== 'content')
|
|
334
|
+
return precondition;
|
|
335
|
+
const revision = layer.revisions[precondition.path];
|
|
336
|
+
if (revision === undefined || layer.documents[precondition.path] !== precondition.content) {
|
|
337
|
+
return precondition;
|
|
338
|
+
}
|
|
339
|
+
changed = true;
|
|
340
|
+
return { kind: 'revision', path: precondition.path, revision };
|
|
341
|
+
});
|
|
342
|
+
return changed ? immutable({ ...batch, preconditions }) : batch;
|
|
343
|
+
}
|
|
344
|
+
export function* standing(confirmed, queue, withdrawable, local) {
|
|
260
345
|
if (!queue.some(withdrawable))
|
|
261
|
-
return [];
|
|
346
|
+
return { withdrawn: [], kept: queue };
|
|
262
347
|
const composition = compositionOf(confirmed.record);
|
|
263
348
|
let layer = confirmed.record;
|
|
264
349
|
const withdrawn = [];
|
|
350
|
+
const kept = [];
|
|
265
351
|
for (const batch of queue) {
|
|
266
352
|
if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
|
|
267
353
|
withdrawn.push(batch);
|
|
268
354
|
continue;
|
|
269
355
|
}
|
|
270
|
-
const effective = batch.
|
|
271
|
-
?
|
|
356
|
+
const effective = rewriting(batch, confirmed.record.locator)
|
|
357
|
+
? yield* effectiveIn(batch, confirmed.record.locator, {
|
|
272
358
|
...layer,
|
|
273
|
-
collection:
|
|
359
|
+
collection: yield* collecting(layer.documents, composition),
|
|
274
360
|
})
|
|
275
361
|
: batch;
|
|
276
362
|
let unapplied = false;
|
|
277
|
-
const next =
|
|
363
|
+
const next = yield* overlaying(layer, [effective], () => {
|
|
278
364
|
unapplied = true;
|
|
279
365
|
});
|
|
280
366
|
if (local && unapplied) {
|
|
281
367
|
withdrawn.push(batch);
|
|
282
368
|
continue;
|
|
283
369
|
}
|
|
370
|
+
kept.push(local || !withdrawable(batch) ? batch : founded(batch, layer));
|
|
284
371
|
layer = next;
|
|
285
372
|
}
|
|
286
|
-
return withdrawn;
|
|
373
|
+
return { withdrawn, kept };
|
|
287
374
|
}
|
package/dist/room-draft.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export type RoomDraftParts = {
|
|
|
32
32
|
readonly creation?: RoomDraftCreation;
|
|
33
33
|
readonly move?: {
|
|
34
34
|
readonly to: string;
|
|
35
|
+
readonly room?: string;
|
|
35
36
|
readonly base?: string | null;
|
|
36
37
|
};
|
|
37
38
|
readonly removal?: {
|
|
@@ -42,8 +43,8 @@ export type RoomDraftParts = {
|
|
|
42
43
|
};
|
|
43
44
|
};
|
|
44
45
|
export type HeldFile = {
|
|
45
|
-
readonly blob: Blob;
|
|
46
46
|
readonly localId: string;
|
|
47
|
+
readonly name?: string;
|
|
47
48
|
readonly byteLength: number;
|
|
48
49
|
readonly mediaType: string;
|
|
49
50
|
readonly sha256: string;
|
|
@@ -69,6 +70,7 @@ type HeldParts = {
|
|
|
69
70
|
readonly creation?: RoomDraftCreation;
|
|
70
71
|
readonly move?: {
|
|
71
72
|
readonly to: string;
|
|
73
|
+
readonly room?: string;
|
|
72
74
|
readonly base: string | null;
|
|
73
75
|
};
|
|
74
76
|
readonly removal?: {
|
|
@@ -87,7 +89,7 @@ type ChangedUnderneath = {
|
|
|
87
89
|
readonly file?: string | null;
|
|
88
90
|
};
|
|
89
91
|
export type ReturnReason = ProviderRefusal & {
|
|
90
|
-
readonly kind: 'conflicted' | 'rejected' | 'expired' | 'withdrawn'
|
|
92
|
+
readonly kind: Open<'conflicted' | 'rejected' | 'expired' | 'withdrawn'>;
|
|
91
93
|
};
|
|
92
94
|
export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
|
|
93
95
|
export type RoomDraft = {
|
|
@@ -130,6 +132,18 @@ export declare function underneath(parts: HeldParts, path: string, visible: Visi
|
|
|
130
132
|
export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
|
|
131
133
|
export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
|
|
132
134
|
export declare function changedParts(path: string, report: ChangedUnderneath): readonly ChangedPart[];
|
|
135
|
+
export type TextParts = {
|
|
136
|
+
readonly fields?: Readonly<Record<string, {
|
|
137
|
+
readonly value: unknown;
|
|
138
|
+
}>>;
|
|
139
|
+
readonly sections?: Readonly<Record<string, {
|
|
140
|
+
readonly value: string;
|
|
141
|
+
}>>;
|
|
142
|
+
readonly preamble?: {
|
|
143
|
+
readonly value: string;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
export declare function partsAfter(markdown: string, parts: TextParts): string;
|
|
133
147
|
export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
|
|
134
148
|
export declare function moveTarget(move: {
|
|
135
149
|
readonly to: string;
|
package/dist/room-draft.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room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,SAAS,UAAU,EAAE,CAqBvB"}
|
package/dist/room-draft.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { apply, equalValue, frontmatterValue, parse, serialize } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, equalValue, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { runtimeError } from './failure.js';
|
|
3
|
-
import {
|
|
3
|
+
import { sha256 } from './digest.js';
|
|
4
4
|
import { binaryLocalId } from './identity.js';
|
|
5
5
|
import { normalize } from './paths.js';
|
|
6
6
|
export function returnedBy(kind) {
|
|
@@ -90,7 +90,12 @@ export function readParts(value) {
|
|
|
90
90
|
if (!plain(value.move))
|
|
91
91
|
malformed();
|
|
92
92
|
const base = markdownBase(value.move.base);
|
|
93
|
-
|
|
93
|
+
const room = optionalText(value.move.room);
|
|
94
|
+
parts.move = {
|
|
95
|
+
to: text(value.move.to),
|
|
96
|
+
...(room === undefined ? {} : { room }),
|
|
97
|
+
...(base === undefined ? {} : { base }),
|
|
98
|
+
};
|
|
94
99
|
}
|
|
95
100
|
if (value.removal !== undefined) {
|
|
96
101
|
if (!plain(value.removal))
|
|
@@ -120,6 +125,13 @@ function kept(prior, base) {
|
|
|
120
125
|
throw runtimeError('room-draft-base-missing');
|
|
121
126
|
return base;
|
|
122
127
|
}
|
|
128
|
+
function movePart(current, move) {
|
|
129
|
+
return {
|
|
130
|
+
to: move.to,
|
|
131
|
+
...(move.room === undefined ? {} : { room: move.room }),
|
|
132
|
+
base: kept(current, move.base),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
123
135
|
function editsText(parts) {
|
|
124
136
|
return (parts.preamble !== undefined ||
|
|
125
137
|
named(parts.fields).length > 0 ||
|
|
@@ -144,9 +156,7 @@ export function held(current, parts, file) {
|
|
|
144
156
|
}
|
|
145
157
|
return {
|
|
146
158
|
file: current.file,
|
|
147
|
-
...(parts.move === undefined
|
|
148
|
-
? {}
|
|
149
|
-
: { move: { to: parts.move.to, base: kept(current.move, parts.move.base) } }),
|
|
159
|
+
...(parts.move === undefined ? {} : { move: movePart(current.move, parts.move) }),
|
|
150
160
|
...(parts.removal === undefined
|
|
151
161
|
? {}
|
|
152
162
|
: { removal: { base: kept(current.removal, parts.removal.base) } }),
|
|
@@ -181,9 +191,8 @@ export function held(current, parts, file) {
|
|
|
181
191
|
}
|
|
182
192
|
if (parts.creation !== undefined)
|
|
183
193
|
next.creation = parts.creation;
|
|
184
|
-
if (parts.move !== undefined)
|
|
185
|
-
next.move =
|
|
186
|
-
}
|
|
194
|
+
if (parts.move !== undefined)
|
|
195
|
+
next.move = movePart(current?.move, parts.move);
|
|
187
196
|
if (parts.removal !== undefined) {
|
|
188
197
|
next.removal = { base: kept(current?.removal, parts.removal.base) };
|
|
189
198
|
}
|
|
@@ -240,13 +249,12 @@ export function underneath(parts, path, visible) {
|
|
|
240
249
|
}
|
|
241
250
|
const UNTYPED_MEDIA_TYPE = 'application/octet-stream';
|
|
242
251
|
export async function heldFile(blob, base) {
|
|
243
|
-
const bytes = await blob.arrayBuffer();
|
|
244
252
|
return {
|
|
245
|
-
blob,
|
|
246
253
|
localId: binaryLocalId(),
|
|
247
|
-
|
|
254
|
+
...(blob instanceof File ? { name: blob.name } : {}),
|
|
255
|
+
byteLength: blob.size,
|
|
248
256
|
mediaType: blob.type === '' ? UNTYPED_MEDIA_TYPE : blob.type,
|
|
249
|
-
sha256:
|
|
257
|
+
sha256: await sha256(blob),
|
|
250
258
|
base,
|
|
251
259
|
};
|
|
252
260
|
}
|
|
@@ -279,16 +287,15 @@ function frontmatterOf(fields) {
|
|
|
279
287
|
const opened = parse('---\n---\n');
|
|
280
288
|
if (!opened.ok)
|
|
281
289
|
return malformed();
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
function concatenated(markdown, parts) {
|
|
290
|
+
const next = apply(opened.document, fields.map(([name, part]) => ({
|
|
291
|
+
kind: 'field',
|
|
292
|
+
name,
|
|
293
|
+
value: part.value,
|
|
294
|
+
prior: undefined,
|
|
295
|
+
})));
|
|
296
|
+
return next.outcome === 'applied' ? serialize(next.document) : malformed();
|
|
297
|
+
}
|
|
298
|
+
export function partsAfter(markdown, parts) {
|
|
292
299
|
const fields = named(parts.fields);
|
|
293
300
|
const pieces = [
|
|
294
301
|
...(fields.length === 0 ? [] : [frontmatterOf(fields)]),
|
|
@@ -319,7 +326,7 @@ export function returnedInto(existing, returned) {
|
|
|
319
326
|
delete next.fields;
|
|
320
327
|
delete next.sections;
|
|
321
328
|
delete next.preamble;
|
|
322
|
-
const value =
|
|
329
|
+
const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned);
|
|
323
330
|
next.markdown = { value, base: whole.base };
|
|
324
331
|
}
|
|
325
332
|
const creation = existing.creation ?? returned.creation;
|
|
@@ -370,7 +377,7 @@ export function changesOf(path, parts) {
|
|
|
370
377
|
changes.push({ kind: 'replace', path, content: parts.markdown.value });
|
|
371
378
|
}
|
|
372
379
|
if (parts.file !== undefined && parts.removal === undefined) {
|
|
373
|
-
const { base, ...file } = parts.file;
|
|
380
|
+
const { base, name: _name, ...file } = parts.file;
|
|
374
381
|
const at = parts.move === undefined ? path : moveTarget(parts.move);
|
|
375
382
|
if (base !== null && at !== path)
|
|
376
383
|
changes.push({ kind: 'move', path, to: at });
|
package/dist/rows.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Frontmatter } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { HeadChange } from './adapter.js';
|
|
3
3
|
import type { BinaryFileRecord } from './binary.js';
|
|
4
4
|
import { type Composition } from './collection.js';
|
|
@@ -13,19 +13,12 @@ export type DocumentRow = {
|
|
|
13
13
|
values: Fields;
|
|
14
14
|
reached: Readonly<Record<string, readonly unknown[]>>;
|
|
15
15
|
directories: readonly string[];
|
|
16
|
-
|
|
16
|
+
folder: string;
|
|
17
|
+
text: string | null;
|
|
17
18
|
change: HeadChange | null;
|
|
19
|
+
fileId: string | null;
|
|
18
20
|
binary: BinaryFileRecord | null;
|
|
19
21
|
};
|
|
20
|
-
export type BodyRow = {
|
|
21
|
-
key: string;
|
|
22
|
-
kind: 'body';
|
|
23
|
-
room: string;
|
|
24
|
-
path: string;
|
|
25
|
-
preamble: string;
|
|
26
|
-
sections: Readonly<Record<string, string>>;
|
|
27
|
-
markdown: string;
|
|
28
|
-
};
|
|
29
22
|
export type ReferenceRow = {
|
|
30
23
|
key: string;
|
|
31
24
|
kind: 'reference';
|
|
@@ -37,10 +30,10 @@ export type ReferenceRow = {
|
|
|
37
30
|
path: string;
|
|
38
31
|
type: string;
|
|
39
32
|
};
|
|
40
|
-
export type Row = DocumentRow |
|
|
33
|
+
export type Row = DocumentRow | ReferenceRow;
|
|
41
34
|
export declare function documentKey(room: string, path: string): string;
|
|
42
35
|
export declare function roomOfKey(key: string): string;
|
|
43
36
|
export declare function markdownPath(path: string): boolean;
|
|
44
|
-
export declare function rowsOf(room: string, path: string, document:
|
|
37
|
+
export declare function rowsOf(room: string, path: string, document: Frontmatter | null, composition: Composition, change: HeadChange | null, fileId: string | null, binary: BinaryFileRecord | null): readonly Row[];
|
|
45
38
|
export {};
|
|
46
39
|
//# sourceMappingURL=rows.d.ts.map
|
package/dist/rows.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAA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