@agentshouse/mdruntime 0.1.0-c1db74d14e5fa → 0.1.0-c24132a516ded
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 +246 -242
- package/README.md +9 -8
- package/dist/adapter.d.ts +53 -23
- 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/bootstrap.d.ts +2 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +62 -27
- package/dist/change-set.d.ts +5 -2
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +10 -8
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- 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 +3 -1
- package/dist/chat/list.d.ts.map +1 -1
- package/dist/chat/list.js +47 -6
- package/dist/chat/markdown.d.ts +1 -0
- package/dist/chat/markdown.d.ts.map +1 -1
- package/dist/chat/markdown.js +78 -20
- package/dist/chat/message.d.ts +1 -0
- package/dist/chat/message.d.ts.map +1 -1
- package/dist/chat/message.js +55 -10
- 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 +104 -105
- 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 +7 -5
- 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 +67 -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 +5 -1
- 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 +11 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +19 -5
- package/dist/collection.d.ts +6 -5
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +166 -85
- package/dist/connection.d.ts +17 -5
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1212 -368
- package/dist/conversation.d.ts +15 -2
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +278 -74
- package/dist/digest.d.ts +2 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +100 -0
- package/dist/durability.d.ts +1 -1
- package/dist/entry.d.ts +2 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +5 -4
- 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 +9 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +67 -14
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +33 -16
- package/dist/model.d.ts +3 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +1 -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 +2 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +9 -3
- package/dist/outcome.d.ts +27 -2
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +25 -0
- package/dist/overlay.d.ts +6 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +223 -134
- package/dist/query.d.ts +30 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +37 -7
- package/dist/reach.d.ts +6 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +156 -38
- package/dist/react.d.ts +3 -3
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +7 -17
- package/dist/read-side.d.ts +6 -4
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +755 -215
- package/dist/readiness.d.ts +1 -1
- package/dist/readiness.d.ts.map +1 -1
- 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 +2 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +8 -7
- package/dist/refresh.d.ts +4 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +41 -16
- package/dist/replica.d.ts +12 -7
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +133 -74
- 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 +3 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +8 -1
- package/dist/save.d.ts +47 -9
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +501 -165
- package/dist/search.d.ts +29 -8
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +150 -17
- 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 +9 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +134 -41
- package/dist/store.d.ts +30 -17
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +489 -430
- package/dist/tables.d.ts +181 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +309 -0
- package/dist/turn.d.ts +5 -3
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +35 -13
- 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 +159 -33
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +53 -32
- package/package.json +6 -2
- package/dist/acquisition.d.ts +0 -14
- package/dist/acquisition.d.ts.map +0 -1
- package/dist/acquisition.js +0 -24
package/dist/replica.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
2
|
import { immutable, landing } from './change.js';
|
|
3
|
-
import { changedCleanly,
|
|
4
|
-
import { acceptedBinaries,
|
|
5
|
-
import {
|
|
6
|
-
import { drafted, patched,
|
|
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';
|
|
7
8
|
export function compositionOf(record) {
|
|
8
9
|
return {
|
|
9
10
|
model: record.model,
|
|
@@ -12,74 +13,90 @@ export function compositionOf(record) {
|
|
|
12
13
|
: { roots: record.typedSelection.roots, model: record.selectionModel },
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
const documents =
|
|
17
|
-
const binaries =
|
|
18
|
-
const revisions =
|
|
19
|
-
const
|
|
20
|
-
const
|
|
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);
|
|
21
23
|
return documents === record.documents &&
|
|
22
24
|
binaries === record.binaries &&
|
|
23
25
|
revisions === record.revisions &&
|
|
26
|
+
fileIds === record.fileIds &&
|
|
24
27
|
changes === record.changes &&
|
|
25
28
|
written === record.written
|
|
26
29
|
? record
|
|
27
|
-
: { ...record, documents, binaries, revisions, changes, written };
|
|
30
|
+
: { ...record, documents, binaries, revisions, fileIds, changes, written };
|
|
28
31
|
}
|
|
29
32
|
export function confirmedOf(record, previous) {
|
|
30
|
-
|
|
33
|
+
return stepped(confirming(record, previous));
|
|
34
|
+
}
|
|
35
|
+
function* confirming(record, previous) {
|
|
36
|
+
const kept = yield* holding(record);
|
|
31
37
|
return {
|
|
32
38
|
record: kept,
|
|
33
|
-
collection:
|
|
39
|
+
collection: yield* collecting(kept.documents, compositionOf(kept), previous?.collection),
|
|
34
40
|
};
|
|
35
41
|
}
|
|
36
42
|
export function sameMembership(record, other) {
|
|
37
43
|
return (JSON.stringify(record.typedSelection?.roots ?? null) ===
|
|
38
44
|
JSON.stringify(other.typedSelection?.roots ?? null));
|
|
39
45
|
}
|
|
40
|
-
function cleanly(record, previous) {
|
|
46
|
+
function* cleanly(record, previous) {
|
|
41
47
|
if (previous === undefined)
|
|
42
48
|
return false;
|
|
43
49
|
const before = previous.record;
|
|
44
|
-
return changedCleanly({ text: record.documents, binaries: record.binaries }, { text: before.documents, binaries: before.binaries, composition: compositionOf(before) }, compositionOf(record));
|
|
50
|
+
return yield* changedCleanly({ text: record.documents, binaries: record.binaries }, { text: before.documents, binaries: before.binaries, composition: compositionOf(before) }, compositionOf(record));
|
|
45
51
|
}
|
|
46
|
-
|
|
47
|
-
const record =
|
|
48
|
-
const textChanged = previous === undefined || !
|
|
52
|
+
function* staging(staged, previous) {
|
|
53
|
+
const record = yield* holding(staged);
|
|
54
|
+
const textChanged = previous === undefined || !(yield* sameText(record, previous.record));
|
|
49
55
|
const modeled = record.model.status !== 'unavailable' || record.selectionModel.status !== 'unavailable';
|
|
50
56
|
if (modeled &&
|
|
51
57
|
(textChanged ||
|
|
52
58
|
record.model !== previous?.record.model ||
|
|
53
59
|
record.selectionModel !== previous?.record.selectionModel) &&
|
|
54
|
-
!cleanly(record, previous)) {
|
|
55
|
-
const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
60
|
+
!(yield* cleanly(record, previous))) {
|
|
61
|
+
const verdict = yield* validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
56
62
|
if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
|
|
57
63
|
return { kind: 'refused', refusal: verdict };
|
|
58
64
|
}
|
|
59
65
|
if (verdict.verdict === 'refuse') {
|
|
60
|
-
const refused = unreadable(record.documents, previous?.record.documents);
|
|
66
|
+
const refused = yield* unreadable(record.documents, previous?.record.documents);
|
|
61
67
|
if (refused !== null)
|
|
62
68
|
return refused;
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
else if (textChanged) {
|
|
66
|
-
const refused = unreadable(record.documents, previous?.record.documents);
|
|
72
|
+
const refused = yield* unreadable(record.documents, previous?.record.documents);
|
|
67
73
|
if (refused !== null)
|
|
68
74
|
return refused;
|
|
69
75
|
}
|
|
70
|
-
return { kind: 'staged', confirmed:
|
|
76
|
+
return { kind: 'staged', confirmed: yield* confirming(record, previous) };
|
|
71
77
|
}
|
|
72
|
-
export function
|
|
73
|
-
|
|
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));
|
|
74
83
|
if (verdict.verdict !== 'refuse')
|
|
75
|
-
return { kind: 'staged', confirmed:
|
|
84
|
+
return { kind: 'staged', confirmed: yield* confirming(record, previous) };
|
|
76
85
|
return verdict.rule === 'model-unavailable'
|
|
77
86
|
? { kind: 'deferred' }
|
|
78
87
|
: { kind: 'refused', refusal: verdict };
|
|
79
88
|
}
|
|
80
|
-
function
|
|
89
|
+
export function readReclassified(record, previous) {
|
|
90
|
+
return stepped(reclassifying(record, previous));
|
|
91
|
+
}
|
|
92
|
+
function* returnedBinaries(held, submitted, accepted) {
|
|
81
93
|
const binaries = drafted(held);
|
|
82
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
|
+
}
|
|
83
100
|
if (change.kind !== 'move')
|
|
84
101
|
continue;
|
|
85
102
|
const moved = binaries[change.path];
|
|
@@ -88,53 +105,78 @@ function returnedBinaries(held, submitted, accepted) {
|
|
|
88
105
|
binaries[change.to] = moved;
|
|
89
106
|
delete binaries[change.path];
|
|
90
107
|
}
|
|
91
|
-
|
|
92
|
-
|
|
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) {
|
|
93
113
|
delete binaries[path];
|
|
94
|
-
|
|
114
|
+
yield ROW_WEIGHT;
|
|
115
|
+
}
|
|
116
|
+
return yield* settling(binaries);
|
|
95
117
|
}
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
delete nextChanges[path];
|
|
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;
|
|
109
130
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
delete
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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;
|
|
116
137
|
}
|
|
117
|
-
|
|
118
|
-
|
|
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,
|
|
119
156
|
roomVersion,
|
|
120
|
-
documents:
|
|
121
|
-
revisions:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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),
|
|
125
163
|
}, confirmed);
|
|
126
164
|
}
|
|
127
|
-
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) {
|
|
128
169
|
const composition = compositionOf(confirmed.record);
|
|
170
|
+
const locator = confirmed.record.locator;
|
|
129
171
|
let layer = confirmed.record;
|
|
130
172
|
const replay = [];
|
|
131
173
|
const prior = new Map(previous?.replay.map((step) => [step.id, step]) ?? []);
|
|
132
174
|
for (const batch of batches) {
|
|
133
175
|
const before = layer;
|
|
134
176
|
const old = prior.get(batch.id);
|
|
135
|
-
const hasMove = batch
|
|
177
|
+
const hasMove = rewriting(batch, locator);
|
|
136
178
|
const reuseRewrite = old?.collection !== undefined &&
|
|
137
|
-
|
|
179
|
+
(yield* sameText(before, old.before)) &&
|
|
138
180
|
old.collection.composition.model === composition.model &&
|
|
139
181
|
old.collection.composition.selection?.model === composition.selection?.model &&
|
|
140
182
|
JSON.stringify(old.collection.composition.selection?.roots) ===
|
|
@@ -142,17 +184,17 @@ function predicted(confirmed, batches, previous) {
|
|
|
142
184
|
const collection = hasMove
|
|
143
185
|
? reuseRewrite
|
|
144
186
|
? old.collection
|
|
145
|
-
:
|
|
187
|
+
: yield* collecting(before.documents, composition, old?.collection ?? confirmed.collection)
|
|
146
188
|
: undefined;
|
|
147
189
|
const effective = collection === undefined
|
|
148
190
|
? batch
|
|
149
191
|
: reuseRewrite
|
|
150
192
|
? old.effective
|
|
151
|
-
:
|
|
193
|
+
: yield* effectiveIn(batch, locator, { ...before, collection });
|
|
152
194
|
layer =
|
|
153
195
|
old === undefined
|
|
154
|
-
?
|
|
155
|
-
: overlayChanged(before,
|
|
196
|
+
? yield* overlaying(before, [effective])
|
|
197
|
+
: yield* overlayChanged(before, effective, old.before, old.effective, old.after);
|
|
156
198
|
replay.push({
|
|
157
199
|
id: batch.id,
|
|
158
200
|
before,
|
|
@@ -163,7 +205,7 @@ function predicted(confirmed, batches, previous) {
|
|
|
163
205
|
}
|
|
164
206
|
return { layer, replay };
|
|
165
207
|
}
|
|
166
|
-
export function
|
|
208
|
+
export function* replicating(confirmed, queue, previous) {
|
|
167
209
|
const batches = Object.freeze(queue.map(immutable));
|
|
168
210
|
if (batches.length === 0) {
|
|
169
211
|
return {
|
|
@@ -173,20 +215,21 @@ export function replicaOf(confirmed, queue, previous) {
|
|
|
173
215
|
documents: confirmed.record.documents,
|
|
174
216
|
binaries: confirmed.record.binaries,
|
|
175
217
|
revisions: confirmed.record.revisions,
|
|
218
|
+
fileIds: confirmed.record.fileIds,
|
|
176
219
|
changes: confirmed.record.changes,
|
|
177
220
|
collection: confirmed.collection,
|
|
178
221
|
},
|
|
179
222
|
replay: [],
|
|
180
223
|
};
|
|
181
224
|
}
|
|
182
|
-
const { layer, replay } =
|
|
225
|
+
const { layer, replay } = yield* predicting(confirmed, batches, previous);
|
|
183
226
|
return {
|
|
184
227
|
confirmed,
|
|
185
228
|
queue: batches,
|
|
186
229
|
replay,
|
|
187
230
|
visible: {
|
|
188
231
|
...layer,
|
|
189
|
-
collection:
|
|
232
|
+
collection: yield* collecting(layer.documents, compositionOf(confirmed.record), previous?.visible.collection ?? confirmed.collection),
|
|
190
233
|
},
|
|
191
234
|
};
|
|
192
235
|
}
|
|
@@ -258,7 +301,7 @@ function effects(change) {
|
|
|
258
301
|
{ kind: 'present', path: change.to },
|
|
259
302
|
];
|
|
260
303
|
}
|
|
261
|
-
if (change.kind === 'binary')
|
|
304
|
+
if (change.kind === 'binary' || change.kind === 'arrival')
|
|
262
305
|
return [{ kind: 'present', path }];
|
|
263
306
|
return [{ kind: 'absent', path }];
|
|
264
307
|
}
|
|
@@ -284,32 +327,48 @@ export function landed(batch, confirmed, current = {}) {
|
|
|
284
327
|
});
|
|
285
328
|
});
|
|
286
329
|
}
|
|
287
|
-
|
|
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) {
|
|
288
345
|
if (!queue.some(withdrawable))
|
|
289
|
-
return [];
|
|
346
|
+
return { withdrawn: [], kept: queue };
|
|
290
347
|
const composition = compositionOf(confirmed.record);
|
|
291
348
|
let layer = confirmed.record;
|
|
292
349
|
const withdrawn = [];
|
|
350
|
+
const kept = [];
|
|
293
351
|
for (const batch of queue) {
|
|
294
352
|
if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
|
|
295
353
|
withdrawn.push(batch);
|
|
296
354
|
continue;
|
|
297
355
|
}
|
|
298
|
-
const effective = batch.
|
|
299
|
-
?
|
|
356
|
+
const effective = rewriting(batch, confirmed.record.locator)
|
|
357
|
+
? yield* effectiveIn(batch, confirmed.record.locator, {
|
|
300
358
|
...layer,
|
|
301
|
-
collection:
|
|
359
|
+
collection: yield* collecting(layer.documents, composition),
|
|
302
360
|
})
|
|
303
361
|
: batch;
|
|
304
362
|
let unapplied = false;
|
|
305
|
-
const next =
|
|
363
|
+
const next = yield* overlaying(layer, [effective], () => {
|
|
306
364
|
unapplied = true;
|
|
307
365
|
});
|
|
308
366
|
if (local && unapplied) {
|
|
309
367
|
withdrawn.push(batch);
|
|
310
368
|
continue;
|
|
311
369
|
}
|
|
370
|
+
kept.push(local || !withdrawable(batch) ? batch : founded(batch, layer));
|
|
312
371
|
layer = next;
|
|
313
372
|
}
|
|
314
|
-
return withdrawn;
|
|
373
|
+
return { withdrawn, kept };
|
|
315
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-draft.d.ts","sourceRoot":"","sources":["../src/room-draft.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"room-draft.d.ts","sourceRoot":"","sources":["../src/room-draft.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OA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,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC,CAAC;IACxE,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IACzE,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAChD,CAAC;AAEF,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,CASrE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,SAAS,CA2B5F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAGhE;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS,GACf;IAAE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAA;CAAE,CA2ChE;AAkBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAkBzF;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,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
|
@@ -13,8 +13,10 @@ export type DocumentRow = {
|
|
|
13
13
|
values: Fields;
|
|
14
14
|
reached: Readonly<Record<string, readonly unknown[]>>;
|
|
15
15
|
directories: readonly string[];
|
|
16
|
+
folder: string;
|
|
16
17
|
text: string | null;
|
|
17
18
|
change: HeadChange | null;
|
|
19
|
+
fileId: string | null;
|
|
18
20
|
binary: BinaryFileRecord | null;
|
|
19
21
|
};
|
|
20
22
|
export type ReferenceRow = {
|
|
@@ -32,6 +34,6 @@ export type Row = DocumentRow | ReferenceRow;
|
|
|
32
34
|
export declare function documentKey(room: string, path: string): string;
|
|
33
35
|
export declare function roomOfKey(key: string): string;
|
|
34
36
|
export declare function markdownPath(path: string): boolean;
|
|
35
|
-
export declare function rowsOf(room: string, path: string, document: Frontmatter | null, composition: Composition, change: HeadChange | null, binary: BinaryFileRecord | null): readonly Row[];
|
|
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[];
|
|
36
38
|
export {};
|
|
37
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,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,KAAK,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,CAAC;IACtD,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAA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,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG,WAAW,GAAG,YAAY,CAAC;AAM7C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAuFD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,WAAW,GAAG,IAAI,EAC5B,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,MAAM,EAAE,gBAAgB,GAAG,IAAI,GAC9B,SAAS,GAAG,EAAE,CAmEhB"}
|
package/dist/rows.js
CHANGED
|
@@ -64,6 +64,9 @@ function walk(reading, node, forms, exact) {
|
|
|
64
64
|
: [{ text: `${form.text}/${segment}`, through: form.through, pending: false }]), `${exact}/${segment}`);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
function folderOf(path) {
|
|
68
|
+
return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
|
|
69
|
+
}
|
|
67
70
|
function directoriesOf(path) {
|
|
68
71
|
const parts = path.split('/').slice(0, -1);
|
|
69
72
|
return ['', ...parts.map((_, index) => parts.slice(0, index + 1).join('/'))];
|
|
@@ -71,7 +74,7 @@ function directoriesOf(path) {
|
|
|
71
74
|
export function markdownPath(path) {
|
|
72
75
|
return path.endsWith('.md');
|
|
73
76
|
}
|
|
74
|
-
export function rowsOf(room, path, document, composition, change, binary) {
|
|
77
|
+
export function rowsOf(room, path, document, composition, change, fileId, binary) {
|
|
75
78
|
const key = documentKey(room, path);
|
|
76
79
|
if (document === null || !markdownPath(path)) {
|
|
77
80
|
return [
|
|
@@ -85,8 +88,10 @@ export function rowsOf(room, path, document, composition, change, binary) {
|
|
|
85
88
|
values: {},
|
|
86
89
|
reached: {},
|
|
87
90
|
directories: directoriesOf(path),
|
|
91
|
+
folder: folderOf(path),
|
|
88
92
|
text: null,
|
|
89
93
|
change,
|
|
94
|
+
fileId,
|
|
90
95
|
binary,
|
|
91
96
|
},
|
|
92
97
|
];
|
|
@@ -116,8 +121,10 @@ export function rowsOf(room, path, document, composition, change, binary) {
|
|
|
116
121
|
values,
|
|
117
122
|
reached,
|
|
118
123
|
directories: directoriesOf(path),
|
|
124
|
+
folder: folderOf(path),
|
|
119
125
|
text: document.content,
|
|
120
126
|
change,
|
|
127
|
+
fileId,
|
|
121
128
|
binary,
|
|
122
129
|
},
|
|
123
130
|
...[...reading.targets.values()].map(({ field, target: found, forms }) => ({
|