@agentshouse/mdruntime 0.1.0-c01d4615bfe46 → 0.1.0-c024a9c474f5e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -13
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +32 -3
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +58 -19
- package/dist/adapter.d.ts +183 -21
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -2
- package/dist/{binary.d.ts → attachment.d.ts} +8 -4
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +3 -0
- package/dist/chat-types.js +2 -2
- package/dist/client.d.ts +23 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +25 -54
- package/dist/collection.d.ts +6 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +23 -9
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +2 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +73 -42
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +16 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +8 -5
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +5 -3
- package/dist/conversation-row.d.ts +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +37 -8
- package/dist/conversation.d.ts +20 -9
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +102 -68
- package/dist/declaration.js +3 -3
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +30 -5
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +2 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +3 -0
- package/dist/entry.d.ts +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -1
- package/dist/figures.d.ts +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +6 -4
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +1 -1
- package/dist/holdings.d.ts.map +1 -1
- package/dist/holdings.js +5 -3
- package/dist/host.d.ts +6 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +70 -29
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +20 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/install.d.ts +8 -2
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +40 -33
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +42 -25
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +13 -0
- package/dist/listing.d.ts +24 -12
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +50 -21
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +94 -36
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +4 -2
- package/dist/lost.js +1 -1
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +177 -27
- package/dist/memory.d.ts +4 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +50 -16
- package/dist/messages.d.ts +12 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +28 -6
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +10 -7
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +3 -3
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +26 -10
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +200 -69
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +5 -5
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +2 -2
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +20 -2
- package/dist/outcome.d.ts +27 -14
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +14 -5
- package/dist/overlay.d.ts +20 -9
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +110 -41
- package/dist/parts.d.ts +4 -1
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -7
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +195 -78
- package/dist/presence.d.ts +8 -2
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +24 -13
- package/dist/queries.d.ts +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +115 -67
- package/dist/query.d.ts +2 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -0
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -1
- package/dist/queue.d.ts +1 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +55 -23
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +140 -25
- package/dist/react.d.ts +11 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +22 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +2 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +21 -13
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +2 -1
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -5
- package/dist/room-draft.d.ts +29 -4
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +237 -16
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +12 -7
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +47 -0
- package/dist/rows.d.ts +11 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +25 -11
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +98 -0
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/runtime.d.ts +7 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +31 -96
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +108 -54
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shown.d.ts +4 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +73 -48
- package/dist/socket/session.d.ts +4 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +6 -1
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +14 -2
- package/dist/source.d.ts +42 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +76 -9
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +24 -5
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +59 -24
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store.d.ts +15 -10
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +12 -5
- package/dist/stored.d.ts +40 -16
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +210 -52
- package/dist/surface.d.ts +18 -7
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +52 -16
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +47 -25
- package/dist/tables.d.ts +34 -49
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +84 -325
- package/dist/tallies.js +2 -2
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +50 -10
- package/dist/wire.d.ts +29 -14
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +18 -13
- package/package.json +4 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
package/dist/save.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { apply, ARRAY_INDEX, ATTACHMENT, create,
|
|
2
|
-
import { immutable, leaving, queuedFile, departure, } from './change.js';
|
|
3
|
-
import { collectionOf, definitionsAt, documentsOf, governing, } from './collection.js';
|
|
1
|
+
import { apply, ARRAY_INDEX, ATTACHMENT, create, links, parse, pointerSegments, references, relative, relativePath, relativizable, relativize, retarget, roomReferences, serialize, target, writeRoomPath, } from '@agentshouse/mdmodel';
|
|
2
|
+
import { immutable, isPart, leaving, queuedFile, departure, } from './change.js';
|
|
3
|
+
import { collectionOf, definitionsAt, documentsOf, governing, typeAt, UNTYPED, } from './collection.js';
|
|
4
4
|
import { changeBatchIdentity, roomDraftRevision } from './identity.js';
|
|
5
5
|
import { composed, overlaying } from './overlay.js';
|
|
6
6
|
import { ancestors } from './paths.js';
|
|
7
7
|
import { entriesIn, sorting } from './shared.js';
|
|
8
|
-
import { changedParts, changesOf, moveTarget, withdrawnDrafts, } from './room-draft.js';
|
|
8
|
+
import { applyParts, changedParts, changesOf, moveTarget, partsBetween, withdrawnDrafts, } from './room-draft.js';
|
|
9
9
|
import { paced, ROW_WEIGHT, stepped } from './turn.js';
|
|
10
10
|
import { validatedCollection } from './validation.js';
|
|
11
11
|
function refuse(code, file, location, line) {
|
|
@@ -52,48 +52,6 @@ function repointed(document, definition, from, to, moves, settled) {
|
|
|
52
52
|
const next = applied.document;
|
|
53
53
|
return [...names].map((name) => ({ kind: 'field', path: from, name, value: next.fields[name] }));
|
|
54
54
|
}
|
|
55
|
-
function edited(document, changes, definition) {
|
|
56
|
-
const parts = new Map();
|
|
57
|
-
for (const change of changes) {
|
|
58
|
-
if (change.kind === 'field')
|
|
59
|
-
parts.set(`field ${change.name}`, {
|
|
60
|
-
kind: 'field',
|
|
61
|
-
name: change.name,
|
|
62
|
-
value: change.value,
|
|
63
|
-
prior: document.fields[change.name],
|
|
64
|
-
});
|
|
65
|
-
if (change.kind === 'preamble')
|
|
66
|
-
parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
67
|
-
if (change.kind === 'section')
|
|
68
|
-
parts.set(`section ${change.name}`, {
|
|
69
|
-
kind: 'section',
|
|
70
|
-
name: change.name,
|
|
71
|
-
value: change.value,
|
|
72
|
-
prior: document.sections[change.name] ?? '',
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
if (parts.size === 0)
|
|
76
|
-
return document;
|
|
77
|
-
const applied = apply(document, [...parts.values()], definition);
|
|
78
|
-
return applied.outcome === 'applied' ? applied.document : document;
|
|
79
|
-
}
|
|
80
|
-
function bodies(path, before, after) {
|
|
81
|
-
const changes = [];
|
|
82
|
-
for (const [name, value] of Object.entries(after.fields)) {
|
|
83
|
-
if (equalValue(before.fields[name], value))
|
|
84
|
-
continue;
|
|
85
|
-
changes.push({ kind: 'field', path, name, value });
|
|
86
|
-
}
|
|
87
|
-
if (after.preamble !== before.preamble) {
|
|
88
|
-
changes.push({ kind: 'preamble', path, value: after.preamble });
|
|
89
|
-
}
|
|
90
|
-
for (const [name, value] of Object.entries(after.sections)) {
|
|
91
|
-
if (before.sections[name] === value)
|
|
92
|
-
continue;
|
|
93
|
-
changes.push({ kind: 'section', path, name, value });
|
|
94
|
-
}
|
|
95
|
-
return changes;
|
|
96
|
-
}
|
|
97
55
|
function relinks(path, moved, before, moves, definition) {
|
|
98
56
|
const changes = [];
|
|
99
57
|
for (const link of links(before, path)) {
|
|
@@ -116,7 +74,7 @@ function relinks(path, moved, before, moves, definition) {
|
|
|
116
74
|
if (before.type === undefined) {
|
|
117
75
|
return { kind: 'changes', changes: [{ kind: 'replace', path, content: serialize(after) }] };
|
|
118
76
|
}
|
|
119
|
-
return { kind: 'changes', changes:
|
|
77
|
+
return { kind: 'changes', changes: partsBetween(path, before, after) };
|
|
120
78
|
}
|
|
121
79
|
function partKey(change) {
|
|
122
80
|
return change.kind === 'section' || change.kind === 'field'
|
|
@@ -168,9 +126,10 @@ function* rewrites(changes, visible) {
|
|
|
168
126
|
const repointing = repointed(document, definition, path, moved, moves, settled);
|
|
169
127
|
added.push(...repointing);
|
|
170
128
|
const own = parts.get(path) ?? [];
|
|
129
|
+
const edited = applyParts(document, own.map((index) => merged[index]), definition);
|
|
171
130
|
const relinked = moved === path && own.length === 0 && cannotLink(document.content, names)
|
|
172
131
|
? { kind: 'changes', changes: [] }
|
|
173
|
-
: relinks(path, moved, edited
|
|
132
|
+
: relinks(path, moved, edited.outcome === 'applied' ? edited.document : document, moves, definition);
|
|
174
133
|
if (relinked.kind === 'refused')
|
|
175
134
|
return relinked;
|
|
176
135
|
const keyed = new Map();
|
|
@@ -248,22 +207,24 @@ function rewritten(path, document, changes, definition) {
|
|
|
248
207
|
const after = applied.document;
|
|
249
208
|
if (document.type === undefined)
|
|
250
209
|
return [{ kind: 'replace', path, content: serialize(after) }];
|
|
251
|
-
return
|
|
252
|
-
}
|
|
253
|
-
function roomPathOf(handle, path) {
|
|
254
|
-
return `/rooms/${handle}/${path}`;
|
|
210
|
+
return partsBetween(path, document, after);
|
|
255
211
|
}
|
|
256
212
|
function* leavingRewritten(batch, visible) {
|
|
257
213
|
const between = batch.between;
|
|
258
214
|
if (between === undefined)
|
|
259
215
|
return batch;
|
|
260
|
-
const
|
|
216
|
+
const { handle } = between.destination;
|
|
217
|
+
const moved = new Map(between.moves.map(({ path, to }) => [path, to]));
|
|
261
218
|
const derived = [];
|
|
262
219
|
for (const [path, document] of yield* documentsOf(visible.collection)) {
|
|
263
220
|
if (moved.has(path))
|
|
264
221
|
continue;
|
|
265
222
|
const definition = definitionsAt(visible.collection.composition, path)(document.type);
|
|
266
|
-
|
|
223
|
+
const into = (named) => {
|
|
224
|
+
const to = moved.get(named);
|
|
225
|
+
return to === undefined ? undefined : relativePath({ path }, { handle, path: to });
|
|
226
|
+
};
|
|
227
|
+
derived.push(...rewritten(path, document, crossed(document, definition, path, into), definition));
|
|
267
228
|
yield ROW_WEIGHT + visible.collection.text[path].length;
|
|
268
229
|
}
|
|
269
230
|
if (derived.length === 0)
|
|
@@ -458,7 +419,7 @@ function* preconditionsOf(changes, visible, bases) {
|
|
|
458
419
|
};
|
|
459
420
|
for (const change of changes) {
|
|
460
421
|
yield ROW_WEIGHT;
|
|
461
|
-
if (change
|
|
422
|
+
if (isPart(change)) {
|
|
462
423
|
const based = bases.find((base) => sameTarget(base, change));
|
|
463
424
|
if (based !== undefined) {
|
|
464
425
|
add(based);
|
|
@@ -547,7 +508,7 @@ function* exceeding(limits, changes, effective, resulting) {
|
|
|
547
508
|
return null;
|
|
548
509
|
}
|
|
549
510
|
function shellRelative(text, path, handle, definition) {
|
|
550
|
-
if (!text
|
|
511
|
+
if (!relativizable(text, handle))
|
|
551
512
|
return null;
|
|
552
513
|
const parsed = parse(text, path, definition);
|
|
553
514
|
if (!parsed.ok)
|
|
@@ -556,7 +517,7 @@ function shellRelative(text, path, handle, definition) {
|
|
|
556
517
|
return result.outcome === 'applied' && result.document.content !== text ? result.document : null;
|
|
557
518
|
}
|
|
558
519
|
function relativeField(path, name, value, handle, definition) {
|
|
559
|
-
if (definition === undefined || !JSON.stringify(value ?? null)
|
|
520
|
+
if (definition === undefined || !relativizable(JSON.stringify(value ?? null), handle))
|
|
560
521
|
return value;
|
|
561
522
|
const held = apply(create(definition.name, definition), [{ kind: 'field', name, value, prior: undefined }], definition);
|
|
562
523
|
if (held.outcome !== 'applied')
|
|
@@ -613,9 +574,6 @@ function relativeChange(change, input) {
|
|
|
613
574
|
function unqueueable(file) {
|
|
614
575
|
return refuse('unknown-revision', file);
|
|
615
576
|
}
|
|
616
|
-
function isPart(change) {
|
|
617
|
-
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
618
|
-
}
|
|
619
577
|
function touched(change) {
|
|
620
578
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
621
579
|
}
|
|
@@ -642,29 +600,7 @@ function unapplied(changes, visible, composition) {
|
|
|
642
600
|
function partsResult(content, path, changes, composition) {
|
|
643
601
|
const definitions = definitionsAt(composition, path);
|
|
644
602
|
const parsed = parse(content, path, definitions);
|
|
645
|
-
|
|
646
|
-
return null;
|
|
647
|
-
const document = parsed.document;
|
|
648
|
-
const parts = new Map();
|
|
649
|
-
for (const change of changes) {
|
|
650
|
-
if (change.kind === 'field')
|
|
651
|
-
parts.set(`field ${change.name}`, {
|
|
652
|
-
kind: 'field',
|
|
653
|
-
name: change.name,
|
|
654
|
-
value: change.value,
|
|
655
|
-
prior: document.fields[change.name],
|
|
656
|
-
});
|
|
657
|
-
else if (change.kind === 'section')
|
|
658
|
-
parts.set(`section ${change.name}`, {
|
|
659
|
-
kind: 'section',
|
|
660
|
-
name: change.name,
|
|
661
|
-
value: change.value,
|
|
662
|
-
prior: document.sections[change.name] ?? '',
|
|
663
|
-
});
|
|
664
|
-
else
|
|
665
|
-
parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
666
|
-
}
|
|
667
|
-
return apply(document, [...parts.values()], definitions(document.type));
|
|
603
|
+
return parsed.ok ? applyParts(parsed.document, changes, definitions(parsed.document.type)) : null;
|
|
668
604
|
}
|
|
669
605
|
function settledParts(changes, deferred, composition) {
|
|
670
606
|
for (const [held, parts] of deferred) {
|
|
@@ -883,11 +819,8 @@ function* limiting(queue, batch, limits, state) {
|
|
|
883
819
|
const limited = yield* exceeding(limits, batch.changes, rewritten.changes, yield* state(queue.slice(0, at + 1)));
|
|
884
820
|
return limited?.refusal ?? null;
|
|
885
821
|
}
|
|
886
|
-
function
|
|
887
|
-
|
|
888
|
-
return false;
|
|
889
|
-
const parsed = parse(content);
|
|
890
|
-
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
822
|
+
function typedContent(composition, path, content) {
|
|
823
|
+
return (content !== undefined && (typeAt(composition, path, parse(content)) ?? UNTYPED) !== UNTYPED);
|
|
891
824
|
}
|
|
892
825
|
function touchedLibrary(resulting, touched, composition) {
|
|
893
826
|
const entries = touched
|
|
@@ -907,9 +840,9 @@ function touchedLibrary(resulting, touched, composition) {
|
|
|
907
840
|
if (binaries.has(path))
|
|
908
841
|
known.set(path, { type: undefined, binary: true });
|
|
909
842
|
else if (content !== undefined && content !== null) {
|
|
910
|
-
const
|
|
911
|
-
if (
|
|
912
|
-
known.set(path, { type
|
|
843
|
+
const type = typeAt(composition, path, parse(content, path, definitionsAt(composition, path)));
|
|
844
|
+
if (type !== undefined)
|
|
845
|
+
known.set(path, { type, binary: false });
|
|
913
846
|
await pace(content.length + ROW_WEIGHT);
|
|
914
847
|
}
|
|
915
848
|
}
|
|
@@ -927,7 +860,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
927
860
|
for (const path of touched) {
|
|
928
861
|
const before = visible.documents[path];
|
|
929
862
|
const after = resulting.documents[path];
|
|
930
|
-
if (
|
|
863
|
+
if (typedContent(composition, path, before) || typedContent(composition, path, after))
|
|
931
864
|
typedPaths.push(path);
|
|
932
865
|
await pace((before?.length ?? 0) + (after?.length ?? 0) + ROW_WEIGHT);
|
|
933
866
|
}
|
|
@@ -958,7 +891,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
958
891
|
};
|
|
959
892
|
}
|
|
960
893
|
function placed(reference) {
|
|
961
|
-
const key =
|
|
894
|
+
const key = writeRoomPath(reference);
|
|
962
895
|
if (reference.kind === 'link')
|
|
963
896
|
return `link ${key}`;
|
|
964
897
|
const pointer = reference.pointer
|
|
@@ -974,7 +907,7 @@ function roomReferencesIn(path, content, composition) {
|
|
|
974
907
|
const parsed = parse(content, path, definitions);
|
|
975
908
|
if (!parsed.ok)
|
|
976
909
|
return [];
|
|
977
|
-
return roomReferences(parsed.document, definitions(parsed.document.type));
|
|
910
|
+
return roomReferences(parsed.document, { path }, definitions(parsed.document.type));
|
|
978
911
|
}
|
|
979
912
|
function* admittedRooms(changes, visible, resulting, composition) {
|
|
980
913
|
const from = new Map();
|
|
@@ -1064,7 +997,9 @@ function arrivingText(path, to, source, moved) {
|
|
|
1064
997
|
const at = moved.get(named);
|
|
1065
998
|
if (at !== undefined)
|
|
1066
999
|
return target(to, href) === at ? undefined : relative(to, at);
|
|
1067
|
-
return heldAt(source.visible, named)
|
|
1000
|
+
return heldAt(source.visible, named)
|
|
1001
|
+
? relativePath({ path: to }, { handle: source.handle, path: named })
|
|
1002
|
+
: undefined;
|
|
1068
1003
|
});
|
|
1069
1004
|
if (changes.length === 0)
|
|
1070
1005
|
return content;
|
|
@@ -1166,7 +1101,7 @@ function unreadable(saved, visible, composition) {
|
|
|
1166
1101
|
const path = saved.find(({ path: at, parts }) => (parts.fields !== undefined ||
|
|
1167
1102
|
parts.sections !== undefined ||
|
|
1168
1103
|
parts.preamble !== undefined) &&
|
|
1169
|
-
|
|
1104
|
+
typedContent(composition, at, visible.documents[at]) &&
|
|
1170
1105
|
governing(composition, at).status === 'unavailable')?.path;
|
|
1171
1106
|
return path === undefined ? null : refuse('model-unavailable', path);
|
|
1172
1107
|
}
|
package/dist/saves.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ChangeBatch, type WrittenBy } from './change.js';
|
|
2
|
-
import
|
|
2
|
+
import type { ConversationFiles } from './conversation.js';
|
|
3
|
+
import { type AttachAnswer, type AttachmentLinkAnswer, type HeldAttachmentAnswer, type HeldShownAnswer } from './outcome.js';
|
|
3
4
|
import { type RoomDraftParts } from './room-draft.js';
|
|
4
5
|
import type { Runtime } from './runtime.js';
|
|
5
6
|
import { type SaveRefusal } from './save.js';
|
|
@@ -18,9 +19,9 @@ export type SavedParts = {
|
|
|
18
19
|
readonly path: string;
|
|
19
20
|
readonly parts: RoomDraftParts;
|
|
20
21
|
};
|
|
21
|
-
export type
|
|
22
|
-
read(room: string, path: string, revision?: string): Promise<
|
|
23
|
-
link(room: string, path: string, revision?: string): Promise<
|
|
22
|
+
export type AttachmentSurface = {
|
|
23
|
+
read(room: string, path: string, revision?: string): Promise<HeldAttachmentAnswer>;
|
|
24
|
+
link(room: string, path: string, revision?: string): Promise<AttachmentLinkAnswer>;
|
|
24
25
|
show(room: string, path: string, revision?: string): Promise<HeldShownAnswer>;
|
|
25
26
|
attach(room: string, file: File): Promise<AttachAnswer>;
|
|
26
27
|
part(file: string, part: number): Promise<Uint8Array | null>;
|
|
@@ -28,5 +29,6 @@ export type BinaryFileSurface = {
|
|
|
28
29
|
export declare function saveRoomDrafts(runtime: Runtime, locator: string, named: readonly SavedRoomDraft[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
|
|
29
30
|
export declare function saveParts(runtime: Runtime, locator: string, named: readonly SavedParts[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
|
|
30
31
|
export declare function batchFile(store: Store, batch: ChangeBatch): (localId: string) => Promise<Blob>;
|
|
31
|
-
export declare function
|
|
32
|
+
export declare function conversationFiles(runtime: Runtime): ConversationFiles;
|
|
33
|
+
export declare function attachmentSurface(runtime: Runtime): AttachmentSurface;
|
|
32
34
|
//# sourceMappingURL=saves.d.ts.map
|
package/dist/saves.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"saves.d.ts","sourceRoot":"","sources":["../src/saves.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"saves.d.ts","sourceRoot":"","sources":["../src/saves.ts"],"names":[],"mappings":"AAUA,OAAO,EAA2B,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAKxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,OAAO,EASL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAGzB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AAatB,OAAO,EAQL,KAAK,cAAc,EAGpB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAsB,KAAK,EAAoB,MAAM,YAAY,CAAC;AAK9E,MAAM,MAAM,UAAU,GAClB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACxC,CAAC;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,GAAG,WAAW,CAAC,CAAC;AAE3C,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;CAAE,CAAC;AAEnF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnF,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnF,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACxD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;CAC9D,CAAC;AAYF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,SAAS,EAAE,SAAS,GAAG,SAAS,GAC/B,OAAO,CAAC,UAAU,CAAC,CAsCrB;AAuBD,wBAAgB,SAAS,CACvB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,SAAS,EAAE,SAAS,GAAG,SAAS,GAC/B,OAAO,CAAC,UAAU,CAAC,CAyBrB;AAwOD,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAK9F;AA+RD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAKrE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAQrE"}
|
package/dist/saves.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { isImageType,
|
|
2
|
-
import {
|
|
1
|
+
import { isImageType, parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { attachmentRecord } from './attachment.js';
|
|
3
|
+
import { changeSet } from './change-set.js';
|
|
3
4
|
import { queuedFile } from './change.js';
|
|
4
|
-
import { available } from './collection.js';
|
|
5
|
+
import { available, definitionsAt, typeAt } from './collection.js';
|
|
5
6
|
import { runtimeError } from './failure.js';
|
|
6
7
|
import { attachedFile } from './file.js';
|
|
8
|
+
import { roomDraftRevision } from './identity.js';
|
|
7
9
|
import { compositionFor } from './listing.js';
|
|
8
10
|
import { scoped } from './models.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
+
import { absentAttachment, attachAnswer, attachmentAnswer, attachmentLinkAnswer, failure, linkedAnswer, OFFLINE, UNCERTAIN, } from './outcome.js';
|
|
12
|
+
import { sameAttachment } from './overlay.js';
|
|
11
13
|
import { ancestors } from './paths.js';
|
|
12
14
|
import { connectionNow } from './preparation.js';
|
|
13
15
|
import { append, sliceAt, withdrawable } from './queue.js';
|
|
14
16
|
import { entryAt, replaying, slicing, } from './replica.js';
|
|
15
|
-
import {
|
|
17
|
+
import { attachmentBase, changesOf, held, heldFile, joinedOver, moveTarget, readSavedParts, } from './room-draft.js';
|
|
16
18
|
import { refuse } from './refusal.js';
|
|
17
19
|
import { visibleOf } from './room-drafts.js';
|
|
18
20
|
import { destination, planSave, } from './save.js';
|
|
@@ -43,9 +45,24 @@ export function saveRoomDrafts(runtime, locator, named, writtenBy) {
|
|
|
43
45
|
if (!saved.some((draft) => draft.path === path))
|
|
44
46
|
saved.push({ path, parts: record.parts });
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
const result = await loaded(runtime, locator, replica, saved, new Set(saved.map(({ path }) => path)), [], writtenBy);
|
|
49
|
+
if (result.outcome !== 'refused' || result.code !== 'changed-underneath')
|
|
50
|
+
return result;
|
|
51
|
+
return joinedUnderneath(runtime, locator, saved.map(({ path }) => drafts.get(path)), result);
|
|
47
52
|
});
|
|
48
53
|
}
|
|
54
|
+
async function joinedUnderneath({ store }, locator, records, refused) {
|
|
55
|
+
const visible = (await visibleOf(store, locator, records.map(({ path }) => path)));
|
|
56
|
+
const joined = records.flatMap((record) => {
|
|
57
|
+
const join = joinedOver(record.parts, record.marks, record.path, visible);
|
|
58
|
+
return join === null ? [] : [{ ...record, ...join, revision: roomDraftRevision() }];
|
|
59
|
+
});
|
|
60
|
+
if (joined.length === 0)
|
|
61
|
+
return refused;
|
|
62
|
+
await (await store.open()).commit({ rooms: [], writes: [{ locator, roomDrafts: joined }] });
|
|
63
|
+
await store.changed(changeSet(locator, { drafts: joined.map(({ path }) => path) }));
|
|
64
|
+
return refused;
|
|
65
|
+
}
|
|
49
66
|
export function saveParts(runtime, locator, named, writtenBy) {
|
|
50
67
|
const { store } = runtime;
|
|
51
68
|
return store.exclusive(async () => {
|
|
@@ -60,7 +77,7 @@ export function saveParts(runtime, locator, named, writtenBy) {
|
|
|
60
77
|
for (const { path, parts } of read) {
|
|
61
78
|
const file = parts.file === undefined
|
|
62
79
|
? undefined
|
|
63
|
-
: await heldFile(parts.file.blob, parts.file.base === undefined ?
|
|
80
|
+
: await heldFile(parts.file.blob, parts.file.base === undefined ? attachmentBase(visible, path) : parts.file.base);
|
|
64
81
|
if (parts.file !== undefined && file !== undefined) {
|
|
65
82
|
files.push({ key: file.localId, blob: parts.file.blob });
|
|
66
83
|
}
|
|
@@ -118,7 +135,8 @@ function targetsOf(saved) {
|
|
|
118
135
|
return saved.flatMap(({ parts }) => (parts.move === undefined ? [] : [moveTarget(parts.move)]));
|
|
119
136
|
}
|
|
120
137
|
async function loaded(runtime, locator, replica, saved, consumed, files, writtenBy) {
|
|
121
|
-
const { store
|
|
138
|
+
const { store } = runtime;
|
|
139
|
+
const localSaves = runtime.savesLocally(locator);
|
|
122
140
|
const into = destination(locator, saved);
|
|
123
141
|
const target = into === null ? undefined : await savedRoom(runtime, into);
|
|
124
142
|
const paths = saved.map(({ path }) => path);
|
|
@@ -137,12 +155,12 @@ async function loaded(runtime, locator, replica, saved, consumed, files, written
|
|
|
137
155
|
room.record.locator,
|
|
138
156
|
held,
|
|
139
157
|
])),
|
|
140
|
-
after: () => pendingShown(runtime),
|
|
158
|
+
after: () => pendingShown(runtime, locator),
|
|
141
159
|
});
|
|
142
160
|
}
|
|
143
161
|
function textDiffers(left, right) {
|
|
144
162
|
return ((left?.content ?? undefined) !== (right?.content ?? undefined) ||
|
|
145
|
-
!
|
|
163
|
+
!sameAttachment(left?.binary ?? undefined, right?.binary ?? undefined));
|
|
146
164
|
}
|
|
147
165
|
function textOf(entry) {
|
|
148
166
|
if (entry === null)
|
|
@@ -159,13 +177,16 @@ function lookupOf(local, key, view) {
|
|
|
159
177
|
]));
|
|
160
178
|
};
|
|
161
179
|
}
|
|
162
|
-
function declaredOf(entry) {
|
|
180
|
+
function declaredOf(composition, path, entry) {
|
|
163
181
|
if (entry.binary !== null)
|
|
164
182
|
return { type: undefined, binary: true };
|
|
165
|
-
const
|
|
166
|
-
return {
|
|
183
|
+
const content = entry.content ?? '';
|
|
184
|
+
return {
|
|
185
|
+
type: typeAt(composition, path, parse(content, path, definitionsAt(composition, path))),
|
|
186
|
+
binary: false,
|
|
187
|
+
};
|
|
167
188
|
}
|
|
168
|
-
function overriddenLookup(lookup, overrides) {
|
|
189
|
+
function overriddenLookup(composition, lookup, overrides) {
|
|
169
190
|
return async (paths) => {
|
|
170
191
|
const known = new Map(await lookup(paths.filter((path) => !overrides.has(path))));
|
|
171
192
|
for (const path of paths) {
|
|
@@ -175,7 +196,7 @@ function overriddenLookup(lookup, overrides) {
|
|
|
175
196
|
if (entry === null)
|
|
176
197
|
known.delete(path);
|
|
177
198
|
else
|
|
178
|
-
known.set(path, declaredOf(entry));
|
|
199
|
+
known.set(path, declaredOf(composition, path, entry));
|
|
179
200
|
}
|
|
180
201
|
return known;
|
|
181
202
|
};
|
|
@@ -196,10 +217,12 @@ function validatorOf(runtime, record, confirmedLayer) {
|
|
|
196
217
|
if (textOf(was) !== textOf(now))
|
|
197
218
|
changes.push({ path, was: textOf(was), now: textOf(now) });
|
|
198
219
|
}
|
|
199
|
-
|
|
200
|
-
|
|
220
|
+
const composition = compositionFor(runtime, record);
|
|
221
|
+
return validatedNeighbourhood(changes, composition, {
|
|
222
|
+
lookup: overriddenLookup(composition, lookupOf(local, record.key, 'confirmed'), overrides),
|
|
201
223
|
texts: textsOf(local, record.key, 'confirmed'),
|
|
202
224
|
referrers: referrersOf(local, record.key, 'confirmed'),
|
|
225
|
+
holders: (sought) => local.holders(record.key, 'confirmed', sought),
|
|
203
226
|
});
|
|
204
227
|
};
|
|
205
228
|
}
|
|
@@ -229,7 +252,7 @@ export function batchFile(store, batch) {
|
|
|
229
252
|
return (await store.open()).file(localId, change?.kind === 'binary' ? change.mediaType : '');
|
|
230
253
|
};
|
|
231
254
|
}
|
|
232
|
-
async function
|
|
255
|
+
async function transferAttachment(runtime, request, transfer, answer) {
|
|
233
256
|
const { store, socket, presence } = runtime;
|
|
234
257
|
const { session } = socket;
|
|
235
258
|
if (socket.closed() || session.now().refusal !== null)
|
|
@@ -250,7 +273,7 @@ async function transferBinary(runtime, request, transfer, answer) {
|
|
|
250
273
|
try {
|
|
251
274
|
const result = await transfer(authorization);
|
|
252
275
|
const settled = result;
|
|
253
|
-
if (presence.lostSince(request.locator, since))
|
|
276
|
+
if (request.locator !== null && presence.lostSince(request.locator, since))
|
|
254
277
|
return failure({ kind: 'room-not-readable', locator: request.locator });
|
|
255
278
|
if (settled.kind === 'scoped-refusal') {
|
|
256
279
|
const room = await store.record(settled.locator);
|
|
@@ -265,19 +288,19 @@ async function transferBinary(runtime, request, transfer, answer) {
|
|
|
265
288
|
return UNCERTAIN;
|
|
266
289
|
}
|
|
267
290
|
}
|
|
268
|
-
function
|
|
291
|
+
function fetchAttachment(runtime, request, name) {
|
|
269
292
|
const { store, socket } = runtime;
|
|
270
|
-
return
|
|
293
|
+
return transferAttachment(runtime, request, (authorization) => store.opened.fetch(name, () => socket.binary(authorization, request)), attachmentAnswer);
|
|
271
294
|
}
|
|
272
|
-
async function
|
|
295
|
+
async function readAttachment(runtime, request, name) {
|
|
273
296
|
if (runtime.socket.closed())
|
|
274
297
|
return UNCERTAIN;
|
|
275
298
|
const held = await runtime.store.opened.find(name);
|
|
276
299
|
if (held !== null)
|
|
277
300
|
return held;
|
|
278
|
-
return
|
|
301
|
+
return fetchAttachment(runtime, request, name);
|
|
279
302
|
}
|
|
280
|
-
async function
|
|
303
|
+
async function attachmentPath(store, locator, path, revision) {
|
|
281
304
|
if (revision !== undefined)
|
|
282
305
|
return { kind: 'path', locator, path, revision };
|
|
283
306
|
const replica = await store.replica(locator);
|
|
@@ -290,7 +313,7 @@ async function binaryPath(store, locator, path, revision) {
|
|
|
290
313
|
return null;
|
|
291
314
|
if (held.binary.state === 'pending')
|
|
292
315
|
return { kind: 'pending', localId: held.binary.localId };
|
|
293
|
-
const record =
|
|
316
|
+
const record = attachmentRecord(path, held.binary, held.revision ?? undefined);
|
|
294
317
|
if (record.state !== 'accepted')
|
|
295
318
|
return null;
|
|
296
319
|
const queued = replica.queue.flatMap((batch) => batch.changes);
|
|
@@ -318,17 +341,17 @@ async function binaryPath(store, locator, path, revision) {
|
|
|
318
341
|
revision: record.revision,
|
|
319
342
|
};
|
|
320
343
|
}
|
|
321
|
-
async function
|
|
344
|
+
async function askedAttachment({ store, socket }, locator, path, revision) {
|
|
322
345
|
await socket.ready;
|
|
323
346
|
const drafted = (await store.draft(locator, path))?.parts.file;
|
|
324
347
|
return drafted !== undefined && drafted.localId === revision
|
|
325
348
|
? { kind: 'pending', localId: revision }
|
|
326
|
-
:
|
|
349
|
+
: attachmentPath(store, locator, path, revision);
|
|
327
350
|
}
|
|
328
|
-
async function
|
|
351
|
+
async function pendingAttachment(store, locator, path, localId) {
|
|
329
352
|
const facts = await queuedFacts(store, locator, path, localId);
|
|
330
353
|
return facts === null
|
|
331
|
-
?
|
|
354
|
+
? absentAttachment(path)
|
|
332
355
|
: {
|
|
333
356
|
kind: 'binary',
|
|
334
357
|
file: localId,
|
|
@@ -336,13 +359,13 @@ async function pendingBinary(store, locator, path, localId) {
|
|
|
336
359
|
mediaType: facts.mediaType,
|
|
337
360
|
};
|
|
338
361
|
}
|
|
339
|
-
async function
|
|
340
|
-
const asked = await
|
|
362
|
+
async function readAttachmentPath(runtime, locator, path, revision) {
|
|
363
|
+
const asked = await askedAttachment(runtime, locator, path, revision);
|
|
341
364
|
if (asked === null)
|
|
342
|
-
return
|
|
365
|
+
return absentAttachment(path);
|
|
343
366
|
if (asked.kind === 'pending')
|
|
344
|
-
return
|
|
345
|
-
return
|
|
367
|
+
return pendingAttachment(runtime.store, locator, path, asked.localId);
|
|
368
|
+
return readAttachment(runtime, asked, { locator, path: asked.path, revision: asked.revision });
|
|
346
369
|
}
|
|
347
370
|
async function heldMediaType(store, locator, path) {
|
|
348
371
|
const replica = await store.record(locator);
|
|
@@ -350,23 +373,42 @@ async function heldMediaType(store, locator, path) {
|
|
|
350
373
|
return held === undefined ? store.attached.of(locator, path)?.mediaType : held.binary?.mediaType;
|
|
351
374
|
}
|
|
352
375
|
function linkOf(runtime, asked, held) {
|
|
353
|
-
return
|
|
376
|
+
return transferAttachment(runtime, asked, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result, held));
|
|
354
377
|
}
|
|
355
|
-
async function
|
|
378
|
+
async function linkAttachmentPath(runtime, locator, path, revision) {
|
|
356
379
|
const { store, socket } = runtime;
|
|
357
380
|
await socket.ready;
|
|
358
|
-
const asked = await
|
|
381
|
+
const asked = await attachmentPath(store, locator, path, revision);
|
|
359
382
|
if (asked === null || asked.kind === 'pending')
|
|
360
|
-
return
|
|
383
|
+
return absentAttachment(path);
|
|
361
384
|
return linkOf(runtime, asked, revision === undefined ? await heldMediaType(store, locator, path) : undefined);
|
|
362
385
|
}
|
|
363
|
-
|
|
386
|
+
function shownImage(runtime, asked, name) {
|
|
387
|
+
const { store, socket } = runtime;
|
|
388
|
+
return new Promise((answer) => {
|
|
389
|
+
void transferAttachment(runtime, asked, (authorization) => store.opened.fetch(name, async () => {
|
|
390
|
+
const read = await socket.binary(authorization, asked);
|
|
391
|
+
const copies = read.kind === 'binary' ? (read.copies ?? []) : [];
|
|
392
|
+
if (read.kind === 'binary' && read.url !== undefined && copies.length > 0) {
|
|
393
|
+
answer({
|
|
394
|
+
kind: 'link',
|
|
395
|
+
url: read.url,
|
|
396
|
+
name: asked.path.slice(asked.path.lastIndexOf('/') + 1),
|
|
397
|
+
mediaType: read.mediaType,
|
|
398
|
+
copies,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
return read;
|
|
402
|
+
}), attachmentAnswer).then(answer);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
async function showAttachmentPath(runtime, locator, path, revision) {
|
|
364
406
|
const { store } = runtime;
|
|
365
|
-
const asked = await
|
|
407
|
+
const asked = await askedAttachment(runtime, locator, path, revision);
|
|
366
408
|
if (asked === null)
|
|
367
|
-
return
|
|
409
|
+
return absentAttachment(path);
|
|
368
410
|
if (asked.kind === 'pending')
|
|
369
|
-
return
|
|
411
|
+
return pendingAttachment(store, locator, path, asked.localId);
|
|
370
412
|
if (runtime.socket.closed())
|
|
371
413
|
return UNCERTAIN;
|
|
372
414
|
const name = { locator, path: asked.path, revision: asked.revision };
|
|
@@ -375,10 +417,11 @@ async function showBinaryPath(runtime, locator, path, revision) {
|
|
|
375
417
|
return kept;
|
|
376
418
|
const mediaType = await heldMediaType(store, locator, path);
|
|
377
419
|
if (mediaType !== undefined && isImageType(mediaType))
|
|
378
|
-
return
|
|
379
|
-
|
|
420
|
+
return shownImage(runtime, asked, name);
|
|
421
|
+
const linked = await linkOf(runtime, asked, revision === undefined ? mediaType : undefined);
|
|
422
|
+
return linked.kind === 'link' ? { ...linked, copies: [] } : linked;
|
|
380
423
|
}
|
|
381
|
-
async function
|
|
424
|
+
async function attachFile(runtime, locator, file, answer) {
|
|
382
425
|
const { store, socket } = runtime;
|
|
383
426
|
await socket.ready;
|
|
384
427
|
await socket.firstDiscovery;
|
|
@@ -388,23 +431,34 @@ async function attachBinary(runtime, locator, file) {
|
|
|
388
431
|
socket.session.now().refusal !== null)
|
|
389
432
|
return OFFLINE;
|
|
390
433
|
const request = await attachedFile(locator, file);
|
|
391
|
-
return
|
|
434
|
+
return transferAttachment(runtime, { locator }, async (held) => {
|
|
392
435
|
const result = await socket.attach(held, request);
|
|
393
|
-
if (result.kind === 'attached') {
|
|
436
|
+
if (result.kind === 'attached' && locator !== null) {
|
|
394
437
|
store.attached.hold(locator, result.path, {
|
|
395
438
|
revision: result.revision,
|
|
396
439
|
mediaType: request.mediaType,
|
|
397
440
|
});
|
|
398
441
|
}
|
|
399
442
|
return result;
|
|
400
|
-
},
|
|
443
|
+
}, answer);
|
|
444
|
+
}
|
|
445
|
+
async function keyedAttachment(runtime, link) {
|
|
446
|
+
await runtime.socket.ready;
|
|
447
|
+
const asked = { kind: 'key', link };
|
|
448
|
+
return transferAttachment(runtime, { locator: null }, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result));
|
|
449
|
+
}
|
|
450
|
+
export function conversationFiles(runtime) {
|
|
451
|
+
return {
|
|
452
|
+
attach: (file) => attachFile(runtime, null, file, linkedAnswer),
|
|
453
|
+
attachment: (link) => keyedAttachment(runtime, link),
|
|
454
|
+
};
|
|
401
455
|
}
|
|
402
|
-
export function
|
|
456
|
+
export function attachmentSurface(runtime) {
|
|
403
457
|
return {
|
|
404
458
|
part: runtime.store.part,
|
|
405
|
-
read: (room, path, revision) =>
|
|
406
|
-
link: (room, path, revision) =>
|
|
407
|
-
show: (room, path, revision) =>
|
|
408
|
-
attach: (room, file) =>
|
|
459
|
+
read: (room, path, revision) => readAttachmentPath(runtime, room, path, revision),
|
|
460
|
+
link: (room, path, revision) => linkAttachmentPath(runtime, room, path, revision),
|
|
461
|
+
show: (room, path, revision) => showAttachmentPath(runtime, room, path, revision),
|
|
462
|
+
attach: (room, file) => attachFile(runtime, room, file, attachAnswer),
|
|
409
463
|
};
|
|
410
464
|
}
|
package/dist/seed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAwB,KAAK,WAAW,EAAqB,MAAM,kBAAkB,CAAC;AAC7F,OAAO,KAAK,EAAE,IAAI,EAA4C,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,SAAS;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;KAAE,EAAE,CAAC;CACpF,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAEjG,KAAK,WAAW,GAAG,CACjB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,KAAK,KAAK,EACjD,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAChC,MAAM,IAAI,CAAC;AA0ChB,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAe5D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAmBtD;AA+BD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAOxF;AAYD,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAMlE;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,WAAW,GACjB,MAAM,IAAI,CA4BZ"}
|
package/dist/seed.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { queryKey } from '@agentshouse/mdmodel';
|
|
2
|
-
import { whole } from './observation.js';
|
|
2
|
+
import { pendingChange, whole } from './observation.js';
|
|
3
3
|
import { documentKey } from './rows.js';
|
|
4
4
|
const seedTopic = (key) => `seed\u0000${key}`;
|
|
5
5
|
function plain(value) {
|
|
@@ -130,7 +130,7 @@ export function watchSeeded(runtime, plan, deliver, watch) {
|
|
|
130
130
|
const watcher = store.watch(seedTopic(plan.key), shown);
|
|
131
131
|
const stop = watch((cover, held) => seedBehind(runtime, plan, cover, held), (message) => {
|
|
132
132
|
const answered = message;
|
|
133
|
-
pending = whole(answered)
|
|
133
|
+
pending = whole(answered) ? 'pending' in answered.result : pendingChange(answered);
|
|
134
134
|
if (pending && store.seeds.of(plan.key) !== undefined) {
|
|
135
135
|
shown();
|
|
136
136
|
return;
|