@agentshouse/mdruntime 0.1.0-cf08ada271a7f → 0.1.0-cf08df9b663d8
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 +21 -19
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +57 -38
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +173 -83
- package/dist/adapter.d.ts +210 -30
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -7
- 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.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +2 -4
- package/dist/client.d.ts +29 -24
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +49 -64
- 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 +4 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +88 -44
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +32 -17
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +26 -11
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +24 -11
- 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 +45 -11
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +337 -203
- 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 +46 -48
- 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 +6 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- package/dist/expectation.d.ts +25 -14
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +51 -20
- package/dist/failure.d.ts +2 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -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 +3 -2
- package/dist/holdings.d.ts.map +1 -1
- package/dist/holdings.js +5 -3
- package/dist/host.d.ts +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +94 -30
- 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 +27 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -9
- package/dist/install.d.ts +10 -5
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +49 -55
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +74 -51
- 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 +27 -20
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +68 -69
- 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 +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +10 -38
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +8 -20
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +181 -34
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +99 -37
- package/dist/messages.d.ts +21 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +48 -16
- 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 +18 -35
- 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 +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +206 -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 +6 -6
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +4 -4
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +22 -10
- package/dist/outcome.d.ts +33 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +36 -6
- package/dist/overlay.d.ts +21 -7
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +112 -39
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +5 -9
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -15
- 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 +207 -96
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +137 -79
- package/dist/query.d.ts +2 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -8
- package/dist/queue.d.ts +2 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +76 -49
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +196 -37
- package/dist/react.d.ts +17 -5
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +28 -5
- package/dist/readiness.d.ts +23 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +5 -3
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +26 -14
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +2 -4
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -5
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +31 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +262 -36
- 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 +11 -5
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +120 -135
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +116 -65
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -4
- 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 +8 -5
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +95 -67
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- 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 +9 -6
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +17 -16
- package/dist/source.d.ts +42 -7
- 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 +31 -7
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +70 -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 +24 -14
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +49 -17
- package/dist/stored.d.ts +41 -16
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +215 -57
- package/dist/surface.d.ts +20 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +66 -32
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +109 -82
- package/dist/tables.d.ts +40 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +109 -326
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +3 -4
- 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 +68 -8
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +28 -11
- package/package.json +4 -4
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- package/dist/job.d.ts +0 -5
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -7
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/socket/rooms.d.ts +0 -41
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
package/dist/save.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { apply, ARRAY_INDEX, ATTACHMENT, create, links, parse, pointerSegments, references, relative, relativize, retarget, roomReferences, serialize, target, } from '@agentshouse/mdmodel';
|
|
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
|
-
import { overlaying } from './overlay.js';
|
|
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
|
-
function refuse(code, file, location) {
|
|
11
|
+
function refuse(code, file, location, line) {
|
|
12
12
|
return {
|
|
13
13
|
kind: 'refused',
|
|
14
14
|
refusal: {
|
|
@@ -16,9 +16,13 @@ function refuse(code, file, location) {
|
|
|
16
16
|
retryable: false,
|
|
17
17
|
...(file === undefined ? {} : { file }),
|
|
18
18
|
...(location === undefined ? {} : { location }),
|
|
19
|
+
...(line === undefined ? {} : { line }),
|
|
19
20
|
},
|
|
20
21
|
};
|
|
21
22
|
}
|
|
23
|
+
function refusedBy(refusal, file) {
|
|
24
|
+
return refuse(refusal.rule, file, refusal.location, refusal.line);
|
|
25
|
+
}
|
|
22
26
|
function repointed(document, definition, from, to, moves, settled) {
|
|
23
27
|
const changes = [];
|
|
24
28
|
const names = new Set();
|
|
@@ -48,36 +52,6 @@ function repointed(document, definition, from, to, moves, settled) {
|
|
|
48
52
|
const next = applied.document;
|
|
49
53
|
return [...names].map((name) => ({ kind: 'field', path: from, name, value: next.fields[name] }));
|
|
50
54
|
}
|
|
51
|
-
function edited(document, changes, definition) {
|
|
52
|
-
const parts = new Map();
|
|
53
|
-
for (const change of changes) {
|
|
54
|
-
if (change.kind === 'preamble')
|
|
55
|
-
parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
56
|
-
if (change.kind === 'section')
|
|
57
|
-
parts.set(`section ${change.name}`, {
|
|
58
|
-
kind: 'section',
|
|
59
|
-
name: change.name,
|
|
60
|
-
value: change.value,
|
|
61
|
-
prior: document.sections[change.name] ?? '',
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
if (parts.size === 0)
|
|
65
|
-
return document;
|
|
66
|
-
const applied = apply(document, [...parts.values()], definition);
|
|
67
|
-
return applied.outcome === 'applied' ? applied.document : document;
|
|
68
|
-
}
|
|
69
|
-
function bodies(path, before, after) {
|
|
70
|
-
const changes = [];
|
|
71
|
-
if (after.preamble !== before.preamble) {
|
|
72
|
-
changes.push({ kind: 'preamble', path, value: after.preamble });
|
|
73
|
-
}
|
|
74
|
-
for (const [name, value] of Object.entries(after.sections)) {
|
|
75
|
-
if (before.sections[name] === value)
|
|
76
|
-
continue;
|
|
77
|
-
changes.push({ kind: 'section', path, name, value });
|
|
78
|
-
}
|
|
79
|
-
return changes;
|
|
80
|
-
}
|
|
81
55
|
function relinks(path, moved, before, moves, definition) {
|
|
82
56
|
const changes = [];
|
|
83
57
|
for (const link of links(before, path)) {
|
|
@@ -92,27 +66,20 @@ function relinks(path, moved, before, moves, definition) {
|
|
|
92
66
|
if (changes.length === 0)
|
|
93
67
|
return { kind: 'changes', changes: [] };
|
|
94
68
|
const applied = apply(before, changes, definition);
|
|
95
|
-
if (applied.outcome === 'refuse')
|
|
96
|
-
return
|
|
97
|
-
kind: 'refused',
|
|
98
|
-
refusal: {
|
|
99
|
-
code: applied.refusal.rule,
|
|
100
|
-
retryable: false,
|
|
101
|
-
file: path,
|
|
102
|
-
...(applied.refusal.location === undefined ? {} : { location: applied.refusal.location }),
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
69
|
+
if (applied.outcome === 'refuse')
|
|
70
|
+
return refusedBy(applied.refusal, path);
|
|
106
71
|
const after = applied.document;
|
|
107
72
|
if (after === before)
|
|
108
73
|
return { kind: 'changes', changes: [] };
|
|
109
74
|
if (before.type === undefined) {
|
|
110
75
|
return { kind: 'changes', changes: [{ kind: 'replace', path, content: serialize(after) }] };
|
|
111
76
|
}
|
|
112
|
-
return { kind: 'changes', changes:
|
|
77
|
+
return { kind: 'changes', changes: partsBetween(path, before, after) };
|
|
113
78
|
}
|
|
114
79
|
function partKey(change) {
|
|
115
|
-
return change.kind === 'section'
|
|
80
|
+
return change.kind === 'section' || change.kind === 'field'
|
|
81
|
+
? `${change.kind} ${change.name}`
|
|
82
|
+
: change.kind;
|
|
116
83
|
}
|
|
117
84
|
const NAMES_A_SKIP_TESTS = 64;
|
|
118
85
|
const ENCODED = /[%&\\]/u;
|
|
@@ -159,9 +126,10 @@ function* rewrites(changes, visible) {
|
|
|
159
126
|
const repointing = repointed(document, definition, path, moved, moves, settled);
|
|
160
127
|
added.push(...repointing);
|
|
161
128
|
const own = parts.get(path) ?? [];
|
|
129
|
+
const edited = applyParts(document, own.map((index) => merged[index]), definition);
|
|
162
130
|
const relinked = moved === path && own.length === 0 && cannotLink(document.content, names)
|
|
163
131
|
? { kind: 'changes', changes: [] }
|
|
164
|
-
: relinks(path, moved, edited
|
|
132
|
+
: relinks(path, moved, edited.outcome === 'applied' ? edited.document : document, moves, definition);
|
|
165
133
|
if (relinked.kind === 'refused')
|
|
166
134
|
return relinked;
|
|
167
135
|
const keyed = new Map();
|
|
@@ -174,7 +142,7 @@ function* rewrites(changes, visible) {
|
|
|
174
142
|
if (change.kind === 'replace') {
|
|
175
143
|
for (const index of own) {
|
|
176
144
|
const kind = merged[index]?.kind;
|
|
177
|
-
if (kind === 'section' || kind === 'preamble')
|
|
145
|
+
if (kind === 'field' || kind === 'section' || kind === 'preamble')
|
|
178
146
|
merged[index] = null;
|
|
179
147
|
}
|
|
180
148
|
added.push(change);
|
|
@@ -239,26 +207,24 @@ function rewritten(path, document, changes, definition) {
|
|
|
239
207
|
const after = applied.document;
|
|
240
208
|
if (document.type === undefined)
|
|
241
209
|
return [{ kind: 'replace', path, content: serialize(after) }];
|
|
242
|
-
|
|
243
|
-
return [
|
|
244
|
-
...[...names].map((name) => ({ kind: 'field', path, name, value: after.fields[name] })),
|
|
245
|
-
...bodies(path, document, after),
|
|
246
|
-
];
|
|
247
|
-
}
|
|
248
|
-
function roomPathOf(handle, path) {
|
|
249
|
-
return `/rooms/${handle}/${path}`;
|
|
210
|
+
return partsBetween(path, document, after);
|
|
250
211
|
}
|
|
251
212
|
function* leavingRewritten(batch, visible) {
|
|
252
213
|
const between = batch.between;
|
|
253
214
|
if (between === undefined)
|
|
254
215
|
return batch;
|
|
255
|
-
const
|
|
216
|
+
const { handle } = between.destination;
|
|
217
|
+
const moved = new Map(between.moves.map(({ path, to }) => [path, to]));
|
|
256
218
|
const derived = [];
|
|
257
219
|
for (const [path, document] of yield* documentsOf(visible.collection)) {
|
|
258
220
|
if (moved.has(path))
|
|
259
221
|
continue;
|
|
260
222
|
const definition = definitionsAt(visible.collection.composition, path)(document.type);
|
|
261
|
-
|
|
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));
|
|
262
228
|
yield ROW_WEIGHT + visible.collection.text[path].length;
|
|
263
229
|
}
|
|
264
230
|
if (derived.length === 0)
|
|
@@ -453,7 +419,7 @@ function* preconditionsOf(changes, visible, bases) {
|
|
|
453
419
|
};
|
|
454
420
|
for (const change of changes) {
|
|
455
421
|
yield ROW_WEIGHT;
|
|
456
|
-
if (change
|
|
422
|
+
if (isPart(change)) {
|
|
457
423
|
const based = bases.find((base) => sameTarget(base, change));
|
|
458
424
|
if (based !== undefined) {
|
|
459
425
|
add(based);
|
|
@@ -542,7 +508,7 @@ function* exceeding(limits, changes, effective, resulting) {
|
|
|
542
508
|
return null;
|
|
543
509
|
}
|
|
544
510
|
function shellRelative(text, path, handle, definition) {
|
|
545
|
-
if (!text
|
|
511
|
+
if (!relativizable(text, handle))
|
|
546
512
|
return null;
|
|
547
513
|
const parsed = parse(text, path, definition);
|
|
548
514
|
if (!parsed.ok)
|
|
@@ -551,7 +517,7 @@ function shellRelative(text, path, handle, definition) {
|
|
|
551
517
|
return result.outcome === 'applied' && result.document.content !== text ? result.document : null;
|
|
552
518
|
}
|
|
553
519
|
function relativeField(path, name, value, handle, definition) {
|
|
554
|
-
if (definition === undefined || !JSON.stringify(value ?? null)
|
|
520
|
+
if (definition === undefined || !relativizable(JSON.stringify(value ?? null), handle))
|
|
555
521
|
return value;
|
|
556
522
|
const held = apply(create(definition.name, definition), [{ kind: 'field', name, value, prior: undefined }], definition);
|
|
557
523
|
if (held.outcome !== 'applied')
|
|
@@ -560,71 +526,81 @@ function relativeField(path, name, value, handle, definition) {
|
|
|
560
526
|
return result.outcome === 'applied' ? result.document.fields[name] : value;
|
|
561
527
|
}
|
|
562
528
|
function relativeChanges(input) {
|
|
529
|
+
const changes = [];
|
|
530
|
+
for (const change of input.changes) {
|
|
531
|
+
const next = relativeChange(change, input);
|
|
532
|
+
if ('refusal' in next)
|
|
533
|
+
return next;
|
|
534
|
+
changes.push(next.change);
|
|
535
|
+
}
|
|
536
|
+
return { kind: 'changes', changes };
|
|
537
|
+
}
|
|
538
|
+
function relativeChange(change, input) {
|
|
563
539
|
const { handle, composition, visible } = input;
|
|
564
|
-
const typed = (path) => definitionsAt(composition, path);
|
|
565
540
|
const body = (path, text) => shellRelative(text, path, handle, () => undefined)?.content ?? text;
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
541
|
+
const definition = definitionsAt(composition, change.path);
|
|
542
|
+
if (change.kind === 'field') {
|
|
543
|
+
const type = visible.collection.document(change.path)?.type;
|
|
544
|
+
const value = relativeField(change.path, change.name, change.value, handle, definition(type));
|
|
545
|
+
return { change: value === change.value ? change : { ...change, value } };
|
|
546
|
+
}
|
|
547
|
+
if (change.kind === 'section' || change.kind === 'preamble') {
|
|
548
|
+
const value = body(change.path, change.value);
|
|
549
|
+
return { change: value === change.value ? change : { ...change, value } };
|
|
550
|
+
}
|
|
551
|
+
if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
|
|
552
|
+
const content = shellRelative(change.content, change.path, handle, definition)?.content ?? change.content;
|
|
553
|
+
return { change: content === change.content ? change : { ...change, content } };
|
|
554
|
+
}
|
|
555
|
+
if (change.kind !== 'create')
|
|
556
|
+
return { change };
|
|
557
|
+
const type = typeof change.fields.type === 'string' ? change.fields.type : undefined;
|
|
558
|
+
const fields = Object.fromEntries(Object.entries(change.fields).map(([name, value]) => [
|
|
559
|
+
name,
|
|
560
|
+
relativeField(change.path, name, value, handle, definition(type)),
|
|
561
|
+
]));
|
|
562
|
+
const sections = Object.fromEntries(Object.entries(change.sections).map(([name, value]) => [name, body(change.path, value)]));
|
|
563
|
+
const written = composed(change.path, fields, sections, composition);
|
|
564
|
+
if (written.outcome === 'refuse')
|
|
565
|
+
return refusedBy(written.refusal, change.path);
|
|
566
|
+
if (written.outcome === 'stale')
|
|
567
|
+
throw new Error(`the creation of ${change.path} is stale`);
|
|
568
|
+
if (Object.keys(sections).length === 0)
|
|
569
|
+
return { change: { ...change, fields, sections } };
|
|
570
|
+
return {
|
|
571
|
+
change: { kind: 'create', path: change.path, content: serialize(written.document) },
|
|
572
|
+
};
|
|
591
573
|
}
|
|
592
574
|
function unqueueable(file) {
|
|
593
575
|
return refuse('unknown-revision', file);
|
|
594
576
|
}
|
|
595
|
-
function isPart(change) {
|
|
596
|
-
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
597
|
-
}
|
|
598
577
|
function touched(change) {
|
|
599
578
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
600
579
|
}
|
|
601
580
|
function partsApplied(content, path, changes, composition) {
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const
|
|
607
|
-
const parts = new Map();
|
|
581
|
+
const applied = partsResult(content, path, changes, composition);
|
|
582
|
+
return applied?.outcome === 'applied' ? serialize(applied.document) : null;
|
|
583
|
+
}
|
|
584
|
+
function unapplied(changes, visible, composition) {
|
|
585
|
+
const parted = new Map();
|
|
608
586
|
for (const change of changes) {
|
|
609
|
-
if (change
|
|
610
|
-
|
|
611
|
-
kind: 'field',
|
|
612
|
-
name: change.name,
|
|
613
|
-
value: change.value,
|
|
614
|
-
prior: document.fields[change.name],
|
|
615
|
-
});
|
|
616
|
-
else if (change.kind === 'section')
|
|
617
|
-
parts.set(`section ${change.name}`, {
|
|
618
|
-
kind: 'section',
|
|
619
|
-
name: change.name,
|
|
620
|
-
value: change.value,
|
|
621
|
-
prior: document.sections[change.name] ?? '',
|
|
622
|
-
});
|
|
623
|
-
else
|
|
624
|
-
parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
587
|
+
if (isPart(change))
|
|
588
|
+
parted.set(change.path, [...(parted.get(change.path) ?? []), change]);
|
|
625
589
|
}
|
|
626
|
-
const
|
|
627
|
-
|
|
590
|
+
for (const [path, parts] of parted) {
|
|
591
|
+
const content = visible.documents[path];
|
|
592
|
+
if (content === undefined)
|
|
593
|
+
continue;
|
|
594
|
+
const applied = partsResult(content, path, parts, composition);
|
|
595
|
+
if (applied?.outcome === 'refuse')
|
|
596
|
+
return refusedBy(applied.refusal, path);
|
|
597
|
+
}
|
|
598
|
+
return null;
|
|
599
|
+
}
|
|
600
|
+
function partsResult(content, path, changes, composition) {
|
|
601
|
+
const definitions = definitionsAt(composition, path);
|
|
602
|
+
const parsed = parse(content, path, definitions);
|
|
603
|
+
return parsed.ok ? applyParts(parsed.document, changes, definitions(parsed.document.type)) : null;
|
|
628
604
|
}
|
|
629
605
|
function settledParts(changes, deferred, composition) {
|
|
630
606
|
for (const [held, parts] of deferred) {
|
|
@@ -843,11 +819,8 @@ function* limiting(queue, batch, limits, state) {
|
|
|
843
819
|
const limited = yield* exceeding(limits, batch.changes, rewritten.changes, yield* state(queue.slice(0, at + 1)));
|
|
844
820
|
return limited?.refusal ?? null;
|
|
845
821
|
}
|
|
846
|
-
function
|
|
847
|
-
|
|
848
|
-
return false;
|
|
849
|
-
const parsed = parse(content);
|
|
850
|
-
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);
|
|
851
824
|
}
|
|
852
825
|
function touchedLibrary(resulting, touched, composition) {
|
|
853
826
|
const entries = touched
|
|
@@ -867,9 +840,9 @@ function touchedLibrary(resulting, touched, composition) {
|
|
|
867
840
|
if (binaries.has(path))
|
|
868
841
|
known.set(path, { type: undefined, binary: true });
|
|
869
842
|
else if (content !== undefined && content !== null) {
|
|
870
|
-
const
|
|
871
|
-
if (
|
|
872
|
-
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 });
|
|
873
846
|
await pace(content.length + ROW_WEIGHT);
|
|
874
847
|
}
|
|
875
848
|
}
|
|
@@ -887,7 +860,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
887
860
|
for (const path of touched) {
|
|
888
861
|
const before = visible.documents[path];
|
|
889
862
|
const after = resulting.documents[path];
|
|
890
|
-
if (
|
|
863
|
+
if (typedContent(composition, path, before) || typedContent(composition, path, after))
|
|
891
864
|
typedPaths.push(path);
|
|
892
865
|
await pace((before?.length ?? 0) + (after?.length ?? 0) + ROW_WEIGHT);
|
|
893
866
|
}
|
|
@@ -905,6 +878,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
905
878
|
retryable: false,
|
|
906
879
|
file: verdict.file,
|
|
907
880
|
...(verdict.location === undefined ? {} : { location: verdict.location }),
|
|
881
|
+
...(verdict.line === undefined ? {} : { line: verdict.line }),
|
|
908
882
|
...(verdict.referrers === undefined ? {} : { referrers: verdict.referrers }),
|
|
909
883
|
},
|
|
910
884
|
};
|
|
@@ -917,11 +891,9 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
917
891
|
};
|
|
918
892
|
}
|
|
919
893
|
function placed(reference) {
|
|
920
|
-
const key =
|
|
894
|
+
const key = writeRoomPath(reference);
|
|
921
895
|
if (reference.kind === 'link')
|
|
922
896
|
return `link ${key}`;
|
|
923
|
-
if (reference.kind === 'item')
|
|
924
|
-
return `section ${reference.section} ${key}`;
|
|
925
897
|
const pointer = reference.pointer
|
|
926
898
|
.split('/')
|
|
927
899
|
.map((segment) => (ARRAY_INDEX.test(segment) ? '-' : segment))
|
|
@@ -935,7 +907,7 @@ function roomReferencesIn(path, content, composition) {
|
|
|
935
907
|
const parsed = parse(content, path, definitions);
|
|
936
908
|
if (!parsed.ok)
|
|
937
909
|
return [];
|
|
938
|
-
return roomReferences(parsed.document, definitions(parsed.document.type));
|
|
910
|
+
return roomReferences(parsed.document, { path }, definitions(parsed.document.type));
|
|
939
911
|
}
|
|
940
912
|
function* admittedRooms(changes, visible, resulting, composition) {
|
|
941
913
|
const from = new Map();
|
|
@@ -953,7 +925,7 @@ function* admittedRooms(changes, visible, resulting, composition) {
|
|
|
953
925
|
continue;
|
|
954
926
|
if (held.has(placed(reference)))
|
|
955
927
|
continue;
|
|
956
|
-
return refuse('unresolved-reference', path, reference.
|
|
928
|
+
return refuse('unresolved-reference', path, reference.pointer);
|
|
957
929
|
}
|
|
958
930
|
yield ROW_WEIGHT + now.length;
|
|
959
931
|
}
|
|
@@ -971,7 +943,10 @@ function validationOf(validated) {
|
|
|
971
943
|
};
|
|
972
944
|
}
|
|
973
945
|
async function batching(input) {
|
|
974
|
-
const
|
|
946
|
+
const relative = relativeChanges(input);
|
|
947
|
+
if (relative.kind === 'refused')
|
|
948
|
+
return relative;
|
|
949
|
+
const { changes } = relative;
|
|
975
950
|
const structural = changes.find((change) => change.kind === 'move' || change.kind === 'remove');
|
|
976
951
|
if (structural !== undefined && input.unmodeled) {
|
|
977
952
|
return refuse('model-unavailable', structural.path);
|
|
@@ -981,7 +956,7 @@ async function batching(input) {
|
|
|
981
956
|
const rewritten = await stepped(rewrites(changes, input.visible));
|
|
982
957
|
if (rewritten.kind === 'refused')
|
|
983
958
|
return rewritten;
|
|
984
|
-
const refusal = guard(changes, input, WRITE);
|
|
959
|
+
const refusal = guard(changes, input, WRITE) ?? unapplied(changes, input.visible, input.composition);
|
|
985
960
|
if (refusal !== null)
|
|
986
961
|
return refusal;
|
|
987
962
|
const preconditions = await stepped(preconditionsOf(changes, input.visible, input.bases));
|
|
@@ -1022,7 +997,9 @@ function arrivingText(path, to, source, moved) {
|
|
|
1022
997
|
const at = moved.get(named);
|
|
1023
998
|
if (at !== undefined)
|
|
1024
999
|
return target(to, href) === at ? undefined : relative(to, at);
|
|
1025
|
-
return heldAt(source.visible, named)
|
|
1000
|
+
return heldAt(source.visible, named)
|
|
1001
|
+
? relativePath({ path: to }, { handle: source.handle, path: named })
|
|
1002
|
+
: undefined;
|
|
1026
1003
|
});
|
|
1027
1004
|
if (changes.length === 0)
|
|
1028
1005
|
return content;
|
|
@@ -1120,6 +1097,14 @@ async function moving(input) {
|
|
|
1120
1097
|
return limited;
|
|
1121
1098
|
return { kind: 'moved', leaving: immutable(leavingBatch), arriving: immutable(arrivingBatch) };
|
|
1122
1099
|
}
|
|
1100
|
+
function unreadable(saved, visible, composition) {
|
|
1101
|
+
const path = saved.find(({ path: at, parts }) => (parts.fields !== undefined ||
|
|
1102
|
+
parts.sections !== undefined ||
|
|
1103
|
+
parts.preamble !== undefined) &&
|
|
1104
|
+
typedContent(composition, at, visible.documents[at]) &&
|
|
1105
|
+
governing(composition, at).status === 'unavailable')?.path;
|
|
1106
|
+
return path === undefined ? null : refuse('model-unavailable', path);
|
|
1107
|
+
}
|
|
1123
1108
|
function changedUnderneath(saved, visible) {
|
|
1124
1109
|
const parts = saved.flatMap(({ path, parts: held }) => changedParts(path, held, visible));
|
|
1125
1110
|
return parts.length === 0
|
|
@@ -1201,7 +1186,7 @@ async function plannedMove(ask, source, into) {
|
|
|
1201
1186
|
async function plannedWithin(ask, room) {
|
|
1202
1187
|
const { record } = room;
|
|
1203
1188
|
const visible = await stepped(room.replay(room.queue));
|
|
1204
|
-
const changed = changedUnderneath(ask.saved, visible);
|
|
1189
|
+
const changed = unreadable(ask.saved, visible, room.composition) ?? changedUnderneath(ask.saved, visible);
|
|
1205
1190
|
if (changed !== null)
|
|
1206
1191
|
return changed;
|
|
1207
1192
|
const parts = ask.saved.map(({ path, parts: held }) => changesOf(path, held));
|
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"}
|