@agentshouse/mdruntime 0.1.0-cacb4c3f6734e → 0.1.0-cb0eb0d87ff49
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 +164 -99
- package/README.md +13 -3
- package/dist/adapter.d.ts +72 -16
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +15 -2
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +17 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +109 -37
- package/dist/change-set.d.ts +2 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +48 -16
- package/dist/change.d.ts +15 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- package/dist/chat/acts.d.ts +33 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +60 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +26 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +62 -0
- package/dist/chat/markdown.d.ts +20 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +188 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +21 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +151 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +620 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +33 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +20 -11
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +66 -16
- package/dist/collection.d.ts +21 -12
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +271 -23
- package/dist/connection.d.ts +29 -14
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1262 -377
- package/dist/conversation.d.ts +23 -10
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +304 -136
- package/dist/entry.d.ts +17 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +156 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/host.d.ts +4 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +17 -12
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +19 -1
- package/dist/index.d.ts +12 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/memory.d.ts +5 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +70 -21
- package/dist/model.d.ts +11 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +11 -0
- package/dist/observation.d.ts +5 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +22 -11
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +32 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +42 -1
- package/dist/overlay.d.ts +15 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +94 -77
- package/dist/query.d.ts +32 -3
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +5 -31
- package/dist/reach.d.ts +2 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +45 -21
- package/dist/react.d.ts +26 -17
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +8 -6
- package/dist/read-side.d.ts +13 -6
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +291 -85
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +197 -0
- package/dist/refresh.d.ts +10 -0
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +43 -38
- package/dist/replica.d.ts +9 -6
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +116 -68
- package/dist/room-draft.d.ts +26 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +132 -23
- package/dist/rows.d.ts +8 -13
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +12 -14
- package/dist/save.d.ts +31 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +376 -45
- package/dist/search.d.ts +31 -8
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +109 -44
- package/dist/shared.d.ts +11 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +368 -0
- package/dist/status.d.ts +2 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +66 -17
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +506 -196
- package/dist/turn.d.ts +7 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +45 -0
- package/dist/wire.d.ts +7 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +15 -2
- package/package.json +26 -14
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/overlay.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { apply, parse, serialize } from '@agentshouse/mdmodel';
|
|
2
|
+
import { differing, drafted, patched, settled } from './shared.js';
|
|
3
|
+
export function acceptedBinaries(files) {
|
|
4
|
+
return Object.fromEntries(Object.entries(files).map(([path, file]) => [path, { state: 'accepted', ...file }]));
|
|
5
|
+
}
|
|
6
|
+
export function sameBinary(left, right) {
|
|
7
|
+
if (left === undefined || right === undefined)
|
|
8
|
+
return left === right;
|
|
9
|
+
return (left.state === right.state &&
|
|
10
|
+
left.byteLength === right.byteLength &&
|
|
11
|
+
left.mediaType === right.mediaType &&
|
|
12
|
+
left.sha256 === right.sha256 &&
|
|
13
|
+
(left.state === 'accepted'
|
|
14
|
+
? right.state === 'accepted' && left.fileRef === right.fileRef
|
|
15
|
+
: right.state === 'pending' && left.localId === right.localId));
|
|
16
|
+
}
|
|
2
17
|
export function sameChange(left, right) {
|
|
3
18
|
if (left === undefined || right === undefined)
|
|
4
19
|
return left === right;
|
|
@@ -76,13 +91,15 @@ function edited(document, change, priors) {
|
|
|
76
91
|
function edit(staged, change, priors) {
|
|
77
92
|
const text = staged.documents[change.path];
|
|
78
93
|
if (text === undefined)
|
|
79
|
-
return;
|
|
94
|
+
return false;
|
|
80
95
|
const parsed = parse(text, change.path);
|
|
81
96
|
if (!parsed.ok)
|
|
82
|
-
return;
|
|
97
|
+
return false;
|
|
83
98
|
const next = edited(parsed.document, change, priors);
|
|
84
|
-
if (next?.outcome
|
|
85
|
-
|
|
99
|
+
if (next?.outcome !== 'applied')
|
|
100
|
+
return false;
|
|
101
|
+
staged.documents[change.path] = serialize(next.document);
|
|
102
|
+
return true;
|
|
86
103
|
}
|
|
87
104
|
function relocate(staged, from, to) {
|
|
88
105
|
const text = staged.documents[from];
|
|
@@ -90,13 +107,15 @@ function relocate(staged, from, to) {
|
|
|
90
107
|
delete staged.documents[from];
|
|
91
108
|
staged.documents[to] = text;
|
|
92
109
|
}
|
|
93
|
-
else if (staged.
|
|
94
|
-
staged.
|
|
110
|
+
else if (staged.binaries[from] !== undefined) {
|
|
111
|
+
staged.binaries[to] = staged.binaries[from];
|
|
112
|
+
delete staged.binaries[from];
|
|
95
113
|
}
|
|
96
114
|
else {
|
|
97
|
-
return;
|
|
115
|
+
return false;
|
|
98
116
|
}
|
|
99
117
|
moveHead(staged, from, to);
|
|
118
|
+
return true;
|
|
100
119
|
}
|
|
101
120
|
function moveHead(heads, from, to) {
|
|
102
121
|
const revision = heads.revisions[from];
|
|
@@ -113,62 +132,84 @@ function erase(staged, path) {
|
|
|
113
132
|
delete staged.documents[path];
|
|
114
133
|
delete staged.revisions[path];
|
|
115
134
|
delete staged.changes[path];
|
|
116
|
-
staged.
|
|
135
|
+
delete staged.binaries[path];
|
|
117
136
|
}
|
|
118
137
|
function stage(staged, change, priors) {
|
|
119
138
|
if (change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble') {
|
|
120
|
-
|
|
121
|
-
return;
|
|
139
|
+
delete staged.revisions[change.path];
|
|
140
|
+
return edit(staged, change, priors);
|
|
122
141
|
}
|
|
123
142
|
if (change.kind === 'create') {
|
|
124
143
|
staged.documents[change.path] =
|
|
125
144
|
'content' in change ? change.content : compose(change.fields, change.sections);
|
|
126
145
|
delete staged.changes[change.path];
|
|
127
|
-
return;
|
|
146
|
+
return true;
|
|
128
147
|
}
|
|
129
148
|
if (change.kind === 'replace') {
|
|
149
|
+
delete staged.revisions[change.path];
|
|
130
150
|
if (staged.documents[change.path] === undefined)
|
|
131
|
-
return;
|
|
151
|
+
return false;
|
|
132
152
|
staged.documents[change.path] = change.content;
|
|
133
|
-
return;
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
if (change.kind === 'binary') {
|
|
156
|
+
if (staged.documents[change.path] !== undefined)
|
|
157
|
+
return false;
|
|
158
|
+
staged.binaries[change.path] = {
|
|
159
|
+
state: 'pending',
|
|
160
|
+
localId: change.localId,
|
|
161
|
+
byteLength: change.byteLength,
|
|
162
|
+
mediaType: change.mediaType,
|
|
163
|
+
sha256: change.sha256,
|
|
164
|
+
};
|
|
165
|
+
delete staged.revisions[change.path];
|
|
166
|
+
delete staged.changes[change.path];
|
|
167
|
+
return true;
|
|
134
168
|
}
|
|
135
169
|
if (change.kind === 'move') {
|
|
136
|
-
relocate(staged, change.path, change.to);
|
|
137
|
-
return;
|
|
170
|
+
return relocate(staged, change.path, change.to);
|
|
138
171
|
}
|
|
139
172
|
erase(staged, change.path);
|
|
173
|
+
return true;
|
|
140
174
|
}
|
|
141
|
-
export function overlay(base, queue) {
|
|
175
|
+
export function overlay(base, queue, unapplied) {
|
|
142
176
|
const staged = {
|
|
143
|
-
documents:
|
|
144
|
-
|
|
145
|
-
revisions:
|
|
146
|
-
changes:
|
|
177
|
+
documents: drafted(base.documents),
|
|
178
|
+
binaries: drafted(base.binaries),
|
|
179
|
+
revisions: drafted(base.revisions),
|
|
180
|
+
changes: drafted(base.changes),
|
|
147
181
|
};
|
|
148
182
|
for (const batch of queue) {
|
|
149
183
|
const priors = priorsOf(batch.preconditions);
|
|
150
|
-
for (const change of batch.changes)
|
|
151
|
-
stage(staged, change, priors)
|
|
184
|
+
for (const change of batch.changes) {
|
|
185
|
+
if (!stage(staged, change, priors))
|
|
186
|
+
unapplied?.();
|
|
187
|
+
}
|
|
152
188
|
}
|
|
153
189
|
return {
|
|
154
|
-
documents: staged.documents,
|
|
155
|
-
|
|
156
|
-
revisions: staged.revisions,
|
|
157
|
-
changes: staged.changes,
|
|
190
|
+
documents: settled(staged.documents),
|
|
191
|
+
binaries: settled(staged.binaries),
|
|
192
|
+
revisions: settled(staged.revisions),
|
|
193
|
+
changes: settled(staged.changes),
|
|
158
194
|
};
|
|
159
195
|
}
|
|
160
196
|
function pathsOf(batch) {
|
|
161
197
|
return batch.changes.flatMap((change) => change.kind === 'move' ? [change.path, change.to] : [change.path]);
|
|
162
198
|
}
|
|
163
199
|
export function sameLayerText(left, right) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
200
|
+
return (differing(left.documents, right.documents).size === 0 &&
|
|
201
|
+
differing(left.binaries, right.binaries, sameBinary).size === 0);
|
|
202
|
+
}
|
|
203
|
+
export function changedPaths(left, right) {
|
|
204
|
+
return new Set([
|
|
205
|
+
...differing(left.documents, right.documents),
|
|
206
|
+
...differing(left.revisions, right.revisions),
|
|
207
|
+
...differing(left.changes, right.changes, sameChange),
|
|
208
|
+
...differing(left.binaries, right.binaries, sameBinary),
|
|
209
|
+
]);
|
|
169
210
|
}
|
|
170
211
|
function replayHeads(base, queue) {
|
|
171
|
-
const heads = { revisions:
|
|
212
|
+
const heads = { revisions: drafted(base.revisions), changes: drafted(base.changes) };
|
|
172
213
|
for (const batch of queue) {
|
|
173
214
|
for (const change of batch.changes) {
|
|
174
215
|
if (change.kind === 'remove') {
|
|
@@ -178,12 +219,22 @@ function replayHeads(base, queue) {
|
|
|
178
219
|
else if (change.kind === 'create') {
|
|
179
220
|
delete heads.changes[change.path];
|
|
180
221
|
}
|
|
222
|
+
else if (change.kind === 'replace' ||
|
|
223
|
+
change.kind === 'field' ||
|
|
224
|
+
change.kind === 'section' ||
|
|
225
|
+
change.kind === 'preamble') {
|
|
226
|
+
delete heads.revisions[change.path];
|
|
227
|
+
}
|
|
228
|
+
else if (change.kind === 'binary') {
|
|
229
|
+
delete heads.revisions[change.path];
|
|
230
|
+
delete heads.changes[change.path];
|
|
231
|
+
}
|
|
181
232
|
else if (change.kind === 'move') {
|
|
182
233
|
moveHead(heads, change.path, change.to);
|
|
183
234
|
}
|
|
184
235
|
}
|
|
185
236
|
}
|
|
186
|
-
return heads;
|
|
237
|
+
return { revisions: settled(heads.revisions), changes: settled(heads.changes) };
|
|
187
238
|
}
|
|
188
239
|
export function overlayChanged(base, queue, previousBase, previousQueue, previousVisible) {
|
|
189
240
|
const before = previousQueue.map((batch) => JSON.stringify(batch));
|
|
@@ -193,28 +244,11 @@ export function overlayChanged(base, queue, previousBase, previousQueue, previou
|
|
|
193
244
|
sameLayerText(base, previousBase)) {
|
|
194
245
|
return {
|
|
195
246
|
documents: previousVisible.documents,
|
|
196
|
-
|
|
247
|
+
binaries: previousVisible.binaries,
|
|
197
248
|
...replayHeads(base, queue),
|
|
198
249
|
};
|
|
199
250
|
}
|
|
200
|
-
const affected = new Set();
|
|
201
|
-
const paths = new Set([
|
|
202
|
-
...Object.keys(base.documents),
|
|
203
|
-
...Object.keys(previousBase.documents),
|
|
204
|
-
...Object.keys(base.revisions),
|
|
205
|
-
...Object.keys(previousBase.revisions),
|
|
206
|
-
...Object.keys(base.changes),
|
|
207
|
-
...Object.keys(previousBase.changes),
|
|
208
|
-
...base.binaryTargets,
|
|
209
|
-
...previousBase.binaryTargets,
|
|
210
|
-
]);
|
|
211
|
-
for (const path of paths) {
|
|
212
|
-
if (base.documents[path] !== previousBase.documents[path] ||
|
|
213
|
-
base.revisions[path] !== previousBase.revisions[path] ||
|
|
214
|
-
!sameChange(base.changes[path], previousBase.changes[path]) ||
|
|
215
|
-
base.binaryTargets.includes(path) !== previousBase.binaryTargets.includes(path))
|
|
216
|
-
affected.add(path);
|
|
217
|
-
}
|
|
251
|
+
const affected = new Set(changedPaths(base, previousBase));
|
|
218
252
|
const oldIds = new Set(before);
|
|
219
253
|
const newIds = new Set(after);
|
|
220
254
|
for (const batch of previousQueue) {
|
|
@@ -245,6 +279,7 @@ export function overlayChanged(base, queue, previousBase, previousQueue, previou
|
|
|
245
279
|
const documents = {};
|
|
246
280
|
const revisions = {};
|
|
247
281
|
const changes = {};
|
|
282
|
+
const binaries = {};
|
|
248
283
|
for (const path of affected) {
|
|
249
284
|
if (base.documents[path] !== undefined)
|
|
250
285
|
documents[path] = base.documents[path];
|
|
@@ -252,32 +287,14 @@ export function overlayChanged(base, queue, previousBase, previousQueue, previou
|
|
|
252
287
|
revisions[path] = base.revisions[path];
|
|
253
288
|
if (base.changes[path] !== undefined)
|
|
254
289
|
changes[path] = base.changes[path];
|
|
290
|
+
if (base.binaries[path] !== undefined)
|
|
291
|
+
binaries[path] = base.binaries[path];
|
|
255
292
|
}
|
|
256
|
-
const staged = overlay({
|
|
257
|
-
documents,
|
|
258
|
-
revisions,
|
|
259
|
-
changes,
|
|
260
|
-
binaryTargets: base.binaryTargets.filter((path) => affected.has(path)),
|
|
261
|
-
}, queue.filter((batch) => pathsOf(batch).some((path) => affected.has(path))));
|
|
262
|
-
const mergedDocuments = { ...previousVisible.documents };
|
|
263
|
-
const mergedRevisions = { ...previousVisible.revisions };
|
|
264
|
-
const mergedChanges = { ...previousVisible.changes };
|
|
265
|
-
const mergedTargets = new Set(previousVisible.binaryTargets);
|
|
266
|
-
for (const path of affected) {
|
|
267
|
-
delete mergedDocuments[path];
|
|
268
|
-
delete mergedRevisions[path];
|
|
269
|
-
delete mergedChanges[path];
|
|
270
|
-
mergedTargets.delete(path);
|
|
271
|
-
}
|
|
272
|
-
Object.assign(mergedDocuments, staged.documents);
|
|
273
|
-
Object.assign(mergedRevisions, staged.revisions);
|
|
274
|
-
Object.assign(mergedChanges, staged.changes);
|
|
275
|
-
for (const path of staged.binaryTargets)
|
|
276
|
-
mergedTargets.add(path);
|
|
293
|
+
const staged = overlay({ documents, revisions, changes, binaries }, queue.filter((batch) => pathsOf(batch).some((path) => affected.has(path))));
|
|
277
294
|
return {
|
|
278
|
-
documents:
|
|
279
|
-
revisions:
|
|
280
|
-
changes:
|
|
281
|
-
|
|
295
|
+
documents: patched(previousVisible.documents, Object.entries(staged.documents), affected),
|
|
296
|
+
revisions: patched(previousVisible.revisions, Object.entries(staged.revisions), affected),
|
|
297
|
+
changes: patched(previousVisible.changes, Object.entries(staged.changes), affected),
|
|
298
|
+
binaries: patched(previousVisible.binaries, Object.entries(staged.binaries), affected),
|
|
282
299
|
};
|
|
283
300
|
}
|
package/dist/query.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Definition } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { HeadChange } from './adapter.js';
|
|
3
|
+
import type { BinaryFileRecord } from './binary.js';
|
|
3
4
|
export type Value = string | number | boolean | null;
|
|
4
5
|
export type Predicate = Value | {
|
|
5
6
|
$eq: Value;
|
|
@@ -93,18 +94,44 @@ export type QueryDocument = {
|
|
|
93
94
|
markdown?: string;
|
|
94
95
|
backlinks?: readonly Backlink[];
|
|
95
96
|
change?: HeadChange | null;
|
|
97
|
+
binaryFile?: BinaryFileRecord;
|
|
96
98
|
};
|
|
97
99
|
export type QueryGroup = {
|
|
98
100
|
key: readonly unknown[];
|
|
99
101
|
count: number;
|
|
100
102
|
};
|
|
101
|
-
export type
|
|
103
|
+
export type CoveredRoom = {
|
|
104
|
+
room: string;
|
|
105
|
+
generation: string;
|
|
106
|
+
current: boolean;
|
|
107
|
+
};
|
|
108
|
+
export type QueryCoverage = {
|
|
109
|
+
rooms: readonly CoveredRoom[];
|
|
110
|
+
indexes: readonly string[];
|
|
111
|
+
overlay: readonly string[];
|
|
112
|
+
};
|
|
113
|
+
export type Awaits = 'acquisition' | 'preparation' | 'index';
|
|
114
|
+
export type PendingRoom = {
|
|
115
|
+
room: string;
|
|
116
|
+
awaits: Awaits;
|
|
117
|
+
};
|
|
118
|
+
export type PendingResult = {
|
|
119
|
+
pending: readonly PendingRoom[];
|
|
120
|
+
};
|
|
121
|
+
export type DocumentRows = {
|
|
102
122
|
documents: readonly QueryDocument[];
|
|
103
123
|
};
|
|
104
|
-
export type
|
|
124
|
+
export type GroupRows = {
|
|
105
125
|
groups: readonly QueryGroup[];
|
|
106
126
|
};
|
|
107
|
-
export type
|
|
127
|
+
export type QueryRows = DocumentRows | GroupRows;
|
|
128
|
+
export type DocumentResult = DocumentRows & {
|
|
129
|
+
coverage: QueryCoverage;
|
|
130
|
+
};
|
|
131
|
+
export type GroupResult = GroupRows & {
|
|
132
|
+
coverage: QueryCoverage;
|
|
133
|
+
};
|
|
134
|
+
export type QueryResult = DocumentResult | GroupResult | PendingResult;
|
|
108
135
|
export type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';
|
|
109
136
|
export type RoomFacts = {
|
|
110
137
|
locator: string;
|
|
@@ -204,6 +231,8 @@ export type Plan = {
|
|
|
204
231
|
limit: number | null;
|
|
205
232
|
};
|
|
206
233
|
export declare class QueryError extends Error {
|
|
234
|
+
readonly code: QueryErrorCode;
|
|
235
|
+
readonly retryable = false;
|
|
207
236
|
constructor(code: QueryErrorCode, at: string, problem: string);
|
|
208
237
|
}
|
|
209
238
|
type Entries = Readonly<Record<string, unknown>>;
|
package/dist/query.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAGhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAIpD,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAErD,MAAM,MAAM,SAAS,GACjB,KAAK,GACL;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,GACd;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,GACd;IAAE,GAAG,EAAE,SAAS,KAAK,EAAE,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,SAAS,KAAK,EAAE,CAAA;CAAE,GAC1B;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IAAC,GAAG,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,SAAS,KAAK,EAAE,CAAA;CAAE,GAC1B;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACjB;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzB,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IACxB,GAAG,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IACvB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,KAAK,EAAE,GAAG,SAAS,CAAC;CAC3D,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IAAE,KAAK,CAAC,EAAE,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G,IAAI,CAMrD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,GAAE,SAAS,GAAG,IAAW,GAAG,IAAI,CAI/F;AAaD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C"}
|
package/dist/query.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pointerFacts, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { referenceField } from './model.js';
|
|
3
3
|
import { normalize } from './paths.js';
|
|
4
4
|
export class QueryError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
retryable = false;
|
|
5
7
|
constructor(code, at, problem) {
|
|
6
8
|
super(`${code} at ${at}: ${problem}`);
|
|
9
|
+
this.code = code;
|
|
7
10
|
}
|
|
8
11
|
}
|
|
9
12
|
const RANGE = ['$gt', '$gte', '$lt', '$lte'];
|
|
@@ -117,39 +120,10 @@ function pointer(input, at) {
|
|
|
117
120
|
}
|
|
118
121
|
return input;
|
|
119
122
|
}
|
|
120
|
-
function stepped({ facts, through, conditional }, token) {
|
|
121
|
-
if (facts.type === 'array' && ARRAY_INDEX.test(token)) {
|
|
122
|
-
const item = itemFacts(facts, Number(token));
|
|
123
|
-
return item === undefined ? undefined : { facts: item, through, conditional };
|
|
124
|
-
}
|
|
125
|
-
let reached = facts;
|
|
126
|
-
let across = through;
|
|
127
|
-
while (reached?.type === 'array') {
|
|
128
|
-
reached = reached.items;
|
|
129
|
-
across = true;
|
|
130
|
-
}
|
|
131
|
-
const member = reached === undefined ? undefined : memberFacts(reached, token);
|
|
132
|
-
return member === undefined
|
|
133
|
-
? undefined
|
|
134
|
-
: { facts: member, through: across, conditional: conditional || member.conditional === true };
|
|
135
|
-
}
|
|
136
|
-
function specAt(type, field) {
|
|
137
|
-
let spec = {
|
|
138
|
-
facts: { ...type.frontmatter, properties: type.fields },
|
|
139
|
-
through: false,
|
|
140
|
-
conditional: false,
|
|
141
|
-
};
|
|
142
|
-
for (const token of pointerSegments(field)) {
|
|
143
|
-
if (spec === undefined)
|
|
144
|
-
return undefined;
|
|
145
|
-
spec = stepped(spec, token);
|
|
146
|
-
}
|
|
147
|
-
return spec;
|
|
148
|
-
}
|
|
149
123
|
function specs(typed, input, at) {
|
|
150
124
|
const field = pointer(input, at);
|
|
151
125
|
const declared = typed.types.flatMap((type) => {
|
|
152
|
-
const spec =
|
|
126
|
+
const spec = pointerFacts(type, field);
|
|
153
127
|
return spec === undefined ? [] : [spec];
|
|
154
128
|
});
|
|
155
129
|
if (declared.length === 0 && !typed.untyped) {
|
package/dist/reach.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReferrerScope } from './adapter.js';
|
|
1
2
|
import type { MdRuntime, RuntimeTopic } from './connection.js';
|
|
2
3
|
import type { Plan, PlanReach, QueryResult } from './query.js';
|
|
3
4
|
import type { SearchResult } from './search.js';
|
|
@@ -24,6 +25,7 @@ export type Reachable = RuntimeView & {
|
|
|
24
25
|
query(plan: Plan): Promise<QueryResult>;
|
|
25
26
|
watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
|
|
26
27
|
search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
|
28
|
+
referrerScope(referrer: unknown): ReferrerScope | null;
|
|
27
29
|
};
|
|
28
30
|
export declare function holds(reach: PortReach | null, room: string): boolean;
|
|
29
31
|
export declare function governs(reach: PortReach | null, room: {
|
package/dist/reach.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,SAAS,EAAe,YAAY,EAAc,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc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,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACvE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACvE,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAAC;CACxD,CAAC;AAyBF,wBAAgB,KAAK,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAMpE;AAMD,wBAAgB,OAAO,CACrB,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,IAAI,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,cAAc,EAAE;QAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,GAC/F;IAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAU/D;AA2BD,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CASnE;AA8ED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,YAAY,CA4KlF"}
|
package/dist/reach.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { unheldView } from './conversation.js';
|
|
2
2
|
import { modelTypes, NO_MODEL } from './model.js';
|
|
3
3
|
import { applied, observing } from './observation.js';
|
|
4
|
+
import { runtimeError } from './failure.js';
|
|
5
|
+
import { failure, undeclared, } from './outcome.js';
|
|
4
6
|
import { beneath } from './paths.js';
|
|
5
7
|
import { reconciled } from './read-side.js';
|
|
6
|
-
import { moveTarget, readParts } from './room-draft.js';
|
|
8
|
+
import { moveTarget, readParts, staleWrite, } from './room-draft.js';
|
|
7
9
|
import { documentKey } from './rows.js';
|
|
8
10
|
const UNHELD_TYPES = { collection: modelTypes(NO_MODEL), typedSelection: null };
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return Promise.resolve(UNDECLARED);
|
|
11
|
+
function unconversed(name) {
|
|
12
|
+
return () => Promise.resolve(undeclared(name));
|
|
12
13
|
}
|
|
13
14
|
const NO_CONVERSATION = {
|
|
14
15
|
list: () => Promise.resolve([]),
|
|
15
16
|
read: (conversation) => Promise.resolve(unheldView(conversation)),
|
|
16
|
-
create:
|
|
17
|
-
send:
|
|
18
|
-
answer:
|
|
19
|
-
interrupt:
|
|
20
|
-
kill:
|
|
21
|
-
cancel:
|
|
22
|
-
delete:
|
|
17
|
+
create: unconversed('conversation.create'),
|
|
18
|
+
send: unconversed('conversation.send'),
|
|
19
|
+
answer: unconversed('conversation.answer'),
|
|
20
|
+
interrupt: unconversed('conversation.interrupt'),
|
|
21
|
+
kill: unconversed('conversation.kill'),
|
|
22
|
+
cancel: unconversed('conversation.cancel'),
|
|
23
|
+
delete: unconversed('conversation.delete'),
|
|
23
24
|
};
|
|
24
25
|
const NO_CHAT_DRAFT = {
|
|
25
26
|
write: () => Promise.resolve(),
|
|
@@ -51,6 +52,20 @@ function covers(reach, room, path) {
|
|
|
51
52
|
function conversing(reach) {
|
|
52
53
|
return reach === null || reach.conversations;
|
|
53
54
|
}
|
|
55
|
+
function refers(reach, scope) {
|
|
56
|
+
if (reach === null)
|
|
57
|
+
return true;
|
|
58
|
+
if (scope === null)
|
|
59
|
+
return false;
|
|
60
|
+
if (scope.kind === 'conversations')
|
|
61
|
+
return reach.conversations;
|
|
62
|
+
return scope.path === undefined
|
|
63
|
+
? wholly(reach, scope.locator)
|
|
64
|
+
: covers(reach, scope.locator, scope.path);
|
|
65
|
+
}
|
|
66
|
+
function unreachedReference(fileRef) {
|
|
67
|
+
return { kind: 'absent', code: 'binary-file-absent', fields: { fileRef }, retryable: false };
|
|
68
|
+
}
|
|
54
69
|
export function planReach(reach) {
|
|
55
70
|
return reach === null
|
|
56
71
|
? null
|
|
@@ -88,7 +103,7 @@ function shownDraft(reach, draft) {
|
|
|
88
103
|
function writeWithin(reach, write) {
|
|
89
104
|
return write.outcome === 'written'
|
|
90
105
|
? { outcome: 'written', roomDraft: shownDraft(reach, write.roomDraft) }
|
|
91
|
-
:
|
|
106
|
+
: staleWrite(shownDraft(reach, write.current));
|
|
92
107
|
}
|
|
93
108
|
function savedWithin(reach, room, result) {
|
|
94
109
|
if (reach === null || result.outcome === 'saved')
|
|
@@ -115,7 +130,7 @@ function queueWithin(reach, room, entries) {
|
|
|
115
130
|
(change.kind !== 'move' || covers(reach, room, change.to))));
|
|
116
131
|
}
|
|
117
132
|
function unreached(room) {
|
|
118
|
-
return
|
|
133
|
+
return runtimeError('room-not-held', `No Local Replica for ${room}`);
|
|
119
134
|
}
|
|
120
135
|
export function narrowed(runtime, given) {
|
|
121
136
|
const { md, watch } = runtime;
|
|
@@ -174,7 +189,7 @@ export function narrowed(runtime, given) {
|
|
|
174
189
|
if (next === null)
|
|
175
190
|
return;
|
|
176
191
|
held = next.keyed;
|
|
177
|
-
deliver(next.
|
|
192
|
+
deliver(next.message);
|
|
178
193
|
});
|
|
179
194
|
});
|
|
180
195
|
}
|
|
@@ -186,7 +201,7 @@ export function narrowed(runtime, given) {
|
|
|
186
201
|
return () => { };
|
|
187
202
|
});
|
|
188
203
|
}
|
|
189
|
-
if (topic === 'conversations') {
|
|
204
|
+
if (topic === 'conversations' || topic === 'agents') {
|
|
190
205
|
return following(() => {
|
|
191
206
|
if (conversing(reach))
|
|
192
207
|
return watch(topic, input, deliver);
|
|
@@ -216,13 +231,22 @@ export function narrowed(runtime, given) {
|
|
|
216
231
|
throw unreached(room);
|
|
217
232
|
const outside = roomDrafts.find(({ path }) => !covers(reach, room, path) ||
|
|
218
233
|
!moves(reach, room, md.roomDraft.read(room, path)?.parts.move));
|
|
219
|
-
if (outside !== undefined)
|
|
220
|
-
return { outcome: 'refused',
|
|
234
|
+
if (outside !== undefined) {
|
|
235
|
+
return { outcome: 'refused', code: 'stale', retryable: false, file: outside.path };
|
|
236
|
+
}
|
|
221
237
|
return savedWithin(reach, room, await md.save(room, roomDrafts, writtenBy));
|
|
222
238
|
},
|
|
223
239
|
history: (room, path, query) => covers(reach, room, path)
|
|
224
240
|
? md.history(room, path, query)
|
|
225
|
-
: Promise.resolve({ kind: 'room-not-readable', locator: room }),
|
|
241
|
+
: Promise.resolve(failure({ kind: 'room-not-readable', locator: room })),
|
|
242
|
+
binaryFile: {
|
|
243
|
+
read: (room, path, revision) => covers(reach, room, path)
|
|
244
|
+
? md.binaryFile.read(room, path, revision)
|
|
245
|
+
: Promise.resolve(failure({ kind: 'room-not-readable', locator: room })),
|
|
246
|
+
readReference: (reference) => refers(reach, runtime.referrerScope(reference.referrer))
|
|
247
|
+
? md.binaryFile.readReference(reference)
|
|
248
|
+
: Promise.resolve(unreachedReference(reference.fileRef)),
|
|
249
|
+
},
|
|
226
250
|
reached: (room, roomVersion, path) => (path === undefined ? wholly(reach, room) : covers(reach, room, path)) &&
|
|
227
251
|
md.reached(room, roomVersion, path),
|
|
228
252
|
log: () => (reach === null ? md.log() : ''),
|
|
@@ -237,7 +261,7 @@ export function narrowed(runtime, given) {
|
|
|
237
261
|
},
|
|
238
262
|
async discard(room, path, revision) {
|
|
239
263
|
if (!covers(reach, room, path))
|
|
240
|
-
return
|
|
264
|
+
return staleWrite(null);
|
|
241
265
|
return writeWithin(reach, await md.roomDraft.discard(room, path, revision));
|
|
242
266
|
},
|
|
243
267
|
},
|
|
@@ -245,7 +269,7 @@ export function narrowed(runtime, given) {
|
|
|
245
269
|
list: () => conversation().list(),
|
|
246
270
|
read: (id, options) => conversation().read(id, options),
|
|
247
271
|
create: (input) => conversation().create(input),
|
|
248
|
-
send: (id) => conversation().send(id),
|
|
272
|
+
send: (id, operation, draft) => conversation().send(id, operation, draft),
|
|
249
273
|
answer: (id, answer) => conversation().answer(id, answer),
|
|
250
274
|
interrupt: (id) => conversation().interrupt(id),
|
|
251
275
|
kill: (id) => conversation().kill(id),
|
|
@@ -253,7 +277,7 @@ export function narrowed(runtime, given) {
|
|
|
253
277
|
delete: (id) => conversation().delete(id),
|
|
254
278
|
},
|
|
255
279
|
chatDraft: {
|
|
256
|
-
write: (id, draft) => chatDraft().write(id, draft),
|
|
280
|
+
write: (id, draft, revision) => chatDraft().write(id, draft, revision),
|
|
257
281
|
discard: (id) => chatDraft().discard(id),
|
|
258
282
|
},
|
|
259
283
|
observe: observing(within),
|
package/dist/react.d.ts
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
import type { MdRuntimeClient } from './client.js';
|
|
2
2
|
import type { AppRoom, ConnectionRefusal, SaveResult } from './connection.js';
|
|
3
|
-
import type { ServiceMode } from './adapter.js';
|
|
4
|
-
import type { ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
|
|
3
|
+
import type { Member, ServiceMode } from './adapter.js';
|
|
4
|
+
import type { ConversationAgent, ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
|
|
5
|
+
import { type RuntimeError } from './failure.js';
|
|
5
6
|
import type { QueueEntry } from './outcome.js';
|
|
6
|
-
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult } from './query.js';
|
|
7
|
+
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
|
|
7
8
|
import type { RoomDraft, RoomDraftParts } from './room-draft.js';
|
|
8
9
|
import type { SyncStatus } from './status.js';
|
|
9
10
|
type Client = MdRuntimeClient | null;
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export declare function useObserve(client: Client, topic: '
|
|
17
|
-
export declare function useObserve(client: Client, topic: '
|
|
18
|
-
export declare function useObserve(client: Client, topic: '
|
|
19
|
-
export declare function useObserve(client: Client, topic: '
|
|
20
|
-
export declare function useObserve(client: Client, topic: '
|
|
21
|
-
export declare function useObserve(client: Client, topic: '
|
|
22
|
-
export declare function useObserve(client: Client, topic: '
|
|
11
|
+
export type Observed<T> = {
|
|
12
|
+
readonly state: 'loading';
|
|
13
|
+
} | {
|
|
14
|
+
readonly state: 'ready';
|
|
15
|
+
readonly value: T;
|
|
16
|
+
};
|
|
17
|
+
export declare function useObserve(client: Client, topic: 'deployment-facts'): Observed<unknown>;
|
|
18
|
+
export declare function useObserve(client: Client, topic: 'rooms'): Observed<readonly AppRoom[]>;
|
|
19
|
+
export declare function useObserve(client: Client, topic: 'connection-refusal'): Observed<ConnectionRefusal | null>;
|
|
20
|
+
export declare function useObserve(client: Client, topic: 'storage-loss'): Observed<string | null>;
|
|
21
|
+
export declare function useObserve(client: Client, topic: 'sync-status'): Observed<SyncStatus>;
|
|
22
|
+
export declare function useObserve(client: Client, topic: 'service-mode'): Observed<ServiceMode>;
|
|
23
|
+
export declare function useObserve(client: Client, topic: 'member'): Observed<Member | null>;
|
|
24
|
+
export declare function useObserve(client: Client, topic: 'query', query: DocumentQuery): Observed<DocumentResult | PendingResult>;
|
|
25
|
+
export declare function useObserve(client: Client, topic: 'query', query: GroupQuery): Observed<GroupResult | PendingResult>;
|
|
26
|
+
export declare function useObserve(client: Client, topic: 'queue', locator: string): Observed<readonly QueueEntry[]>;
|
|
27
|
+
export declare function useObserve(client: Client, topic: 'room-drafts'): Observed<readonly RoomDraft[]>;
|
|
28
|
+
export declare function useObserve(client: Client, topic: 'presentation'): Observed<unknown>;
|
|
29
|
+
export declare function useObserve(client: Client, topic: 'conversation', conversation: string, options: ConversationOptions): Observed<ConversationView>;
|
|
30
|
+
export declare function useObserve(client: Client, topic: 'conversations'): Observed<readonly ConversationEntry[]>;
|
|
31
|
+
export declare function useObserve(client: Client, topic: 'agents'): Observed<readonly ConversationAgent[]>;
|
|
23
32
|
export type Saving = {
|
|
24
33
|
readonly busy: boolean;
|
|
25
34
|
readonly outcome: SaveResult | null;
|
|
26
|
-
readonly failure:
|
|
35
|
+
readonly failure: RuntimeError | null;
|
|
27
36
|
save(room: string, roomDrafts: ReadonlyMap<string, RoomDraftParts>): Promise<SaveResult>;
|
|
28
37
|
};
|
|
29
38
|
export declare function saveRoomDrafts(client: MdRuntimeClient, room: string, roomDrafts: ReadonlyMap<string, RoomDraftParts>): Promise<SaveResult>;
|