@agentshouse/mdruntime 0.1.0-cf1e7fdb9c600 → 0.1.0-cf26dc076c1a3
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 +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +328 -0
- 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 +26 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +341 -0
- package/dist/adapter.d.ts +211 -95
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -11
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +20 -60
- 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 +347 -0
- package/dist/bootstrap.d.ts +9 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +204 -86
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -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-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +7 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +11 -0
- package/dist/client.d.ts +45 -24
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +58 -68
- package/dist/collection.d.ts +27 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +34 -10
- 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 +9 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +286 -120
- package/dist/connection.d.ts +6 -142
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +115 -5283
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +150 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +260 -0
- package/dist/conversation-row.d.ts +40 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +66 -0
- package/dist/conversation.d.ts +72 -47
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1004 -901
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +12 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -0
- 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 +20 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +25 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +111 -33
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +8 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +199 -0
- 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 +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +25 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +119 -36
- 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 -2
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -4
- package/dist/index.d.ts +43 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -7
- package/dist/install.d.ts +60 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +292 -0
- package/dist/listing.d.ts +60 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +168 -0
- package/dist/live.d.ts +22 -6
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +130 -34
- 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 +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +34 -0
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +49 -0
- package/dist/media.d.ts +20 -4
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +184 -37
- package/dist/memory.d.ts +12 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +141 -41
- package/dist/messages.d.ts +38 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +105 -25
- 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 +11 -15
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -11
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -0
- 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 +217 -85
- 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 +7 -7
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +71 -0
- package/dist/outcome.d.ts +37 -14
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +39 -6
- package/dist/overlay.d.ts +24 -8
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +143 -48
- 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 +6 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +36 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/preparation.d.ts +46 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +344 -0
- 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 +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +330 -0
- package/dist/query.d.ts +12 -4
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +30 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +117 -0
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +20 -9
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +346 -127
- package/dist/react.d.ts +24 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +23 -5
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +39 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +189 -0
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +40 -9
- package/dist/reference-forms.d.ts +4 -0
- package/dist/reference-forms.d.ts.map +1 -0
- package/dist/reference-forms.js +74 -0
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +14 -26
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +11 -22
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +68 -38
- 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 +33 -10
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +282 -72
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +222 -0
- 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 +24 -6
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +65 -60
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +94 -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 +90 -0
- package/dist/runtime.d.ts +37 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +43 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +332 -228
- package/dist/saves.d.ts +34 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +463 -0
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shared.d.ts +1 -6
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -95
- package/dist/shown.d.ts +35 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +326 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +28 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +103 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/session.d.ts +41 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +26 -0
- package/dist/socket.d.ts +70 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +172 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +95 -0
- package/dist/status.d.ts +0 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +40 -0
- package/dist/store/readiness.d.ts +11 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +68 -0
- package/dist/store/records.d.ts +234 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +474 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- 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/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +116 -152
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +174 -395
- package/dist/stored.d.ts +89 -70
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +438 -174
- package/dist/surface.d.ts +100 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +258 -0
- package/dist/sync.d.ts +21 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +557 -0
- package/dist/tables.d.ts +135 -87
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +216 -283
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +128 -0
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +53 -13
- package/dist/wire.d.ts +87 -12
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +37 -14
- package/package.json +4 -3
- 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/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/job.d.ts +0 -14
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -28
- package/dist/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { plain } from '@agentshouse/mdmodel';
|
|
2
|
+
import { changeSet } from './change-set.js';
|
|
3
|
+
import { collectionOf } from './collection.js';
|
|
4
|
+
import { runtimeError, uncaught } from './failure.js';
|
|
5
|
+
import { roomDraftRevision } from './identity.js';
|
|
6
|
+
import { normalize } from './paths.js';
|
|
7
|
+
import { slicing } from './replica.js';
|
|
8
|
+
import { attachmentBase, gatheredParts, held, heldFile, heldMarks, readParts, staleWrite, underneath, } from './room-draft.js';
|
|
9
|
+
import { stepped } from './turn.js';
|
|
10
|
+
const ROOM_DRAFTS = 'room-drafts';
|
|
11
|
+
const presentationTopic = (app) => `presentation\u0000${app}`;
|
|
12
|
+
export async function visibleOf(store, locator, paths) {
|
|
13
|
+
const kept = await store.record(locator);
|
|
14
|
+
if (kept === undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
const local = await store.open();
|
|
17
|
+
const slice = await stepped(slicing(await local.entries(kept.key, 'visible', paths), paths));
|
|
18
|
+
return { ...slice, collection: collectionOf(slice.documents, store.composed(kept)) };
|
|
19
|
+
}
|
|
20
|
+
function roomDraftOf(record, visible) {
|
|
21
|
+
return structuredClone({
|
|
22
|
+
room: record.locator,
|
|
23
|
+
path: record.path,
|
|
24
|
+
revision: record.revision,
|
|
25
|
+
parts: record.parts,
|
|
26
|
+
changedUnderneath: underneath(record.parts, record.path, visible),
|
|
27
|
+
marks: record.marks,
|
|
28
|
+
returned: record.returned,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function roomDraftsOf(store, records) {
|
|
32
|
+
const rooms = new Map();
|
|
33
|
+
for (const record of records) {
|
|
34
|
+
const paths = rooms.get(record.locator) ?? [];
|
|
35
|
+
paths.push(record.path);
|
|
36
|
+
rooms.set(record.locator, paths);
|
|
37
|
+
}
|
|
38
|
+
const layers = new Map();
|
|
39
|
+
for (const [locator, paths] of rooms) {
|
|
40
|
+
layers.set(locator, await visibleOf(store, locator, paths));
|
|
41
|
+
}
|
|
42
|
+
return records.map((record) => roomDraftOf(record, layers.get(record.locator)));
|
|
43
|
+
}
|
|
44
|
+
function inOrder(records) {
|
|
45
|
+
return [...records].sort((left, right) => {
|
|
46
|
+
if (left.locator !== right.locator)
|
|
47
|
+
return left.locator < right.locator ? -1 : 1;
|
|
48
|
+
if (left.path !== right.path)
|
|
49
|
+
return left.path < right.path ? -1 : 1;
|
|
50
|
+
return 0;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async function snapshotRoomDrafts(store) {
|
|
54
|
+
return roomDraftsOf(store, inOrder(await store.drafts()));
|
|
55
|
+
}
|
|
56
|
+
export function publishRoomDrafts({ store, socket }, waitingOnly, touched = null) {
|
|
57
|
+
const unwatched = () => socket.closed() || store.watching(ROOM_DRAFTS).length === 0;
|
|
58
|
+
if (unwatched())
|
|
59
|
+
return Promise.resolve();
|
|
60
|
+
return store.publication(async () => {
|
|
61
|
+
if (unwatched())
|
|
62
|
+
return;
|
|
63
|
+
const records = await store.drafts();
|
|
64
|
+
if (socket.closed())
|
|
65
|
+
return;
|
|
66
|
+
if (touched !== null &&
|
|
67
|
+
!records.some((record) => touched.some(({ locator, path }) => locator === record.locator && (path === null || path === record.path)))) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const value = await roomDraftsOf(store, inOrder(records));
|
|
71
|
+
if (socket.closed())
|
|
72
|
+
return;
|
|
73
|
+
const answered = store.watching(ROOM_DRAFTS, waitingOnly ? 'waiting' : 'all');
|
|
74
|
+
for (const watcher of answered)
|
|
75
|
+
watcher.answer(value);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async function presentationOf(store, app) {
|
|
79
|
+
const value = await (await store.open()).presentation(app);
|
|
80
|
+
return value === undefined ? null : structuredClone(value);
|
|
81
|
+
}
|
|
82
|
+
export function emitPresentation({ store, socket }, app) {
|
|
83
|
+
const topic = presentationTopic(app);
|
|
84
|
+
const listening = () => store.watching(topic, 'ready');
|
|
85
|
+
if (socket.closed() || listening().length === 0)
|
|
86
|
+
return Promise.resolve();
|
|
87
|
+
return store.publication(async () => {
|
|
88
|
+
if (socket.closed() || listening().length === 0)
|
|
89
|
+
return;
|
|
90
|
+
const value = await presentationOf(store, app);
|
|
91
|
+
if (socket.closed())
|
|
92
|
+
return;
|
|
93
|
+
for (const watcher of listening())
|
|
94
|
+
watcher.answer(value);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async function writtenRoomDraft({ store }, room, path, revision, input, next) {
|
|
98
|
+
const parts = readParts(input, path);
|
|
99
|
+
if (path === '' || normalize(path) !== path)
|
|
100
|
+
throw runtimeError('room-draft-malformed', `room-draft-malformed at ${path}: a path inside the Room, such as notes/a.md`);
|
|
101
|
+
const local = await store.open();
|
|
102
|
+
const current = await store.draft(room, path);
|
|
103
|
+
if ((current?.revision ?? null) !== revision) {
|
|
104
|
+
return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
|
|
105
|
+
}
|
|
106
|
+
const file = parts.file === undefined
|
|
107
|
+
? undefined
|
|
108
|
+
: await heldFile(parts.file.blob, parts.file.base === undefined
|
|
109
|
+
? attachmentBase(await visibleOf(store, room, [path]), path)
|
|
110
|
+
: parts.file.base);
|
|
111
|
+
const kept = held(current?.parts, parts, file);
|
|
112
|
+
const record = {
|
|
113
|
+
locator: room,
|
|
114
|
+
path,
|
|
115
|
+
revision: next,
|
|
116
|
+
parts: kept,
|
|
117
|
+
marks: heldMarks(current?.marks ?? {}, kept),
|
|
118
|
+
returned: current?.returned ?? null,
|
|
119
|
+
};
|
|
120
|
+
await local.keepRoomDraft(record, parts.file === undefined || file === undefined
|
|
121
|
+
? []
|
|
122
|
+
: [{ key: file.localId, blob: parts.file.blob }]);
|
|
123
|
+
await store.changed(changeSet(room, { drafts: [path] }));
|
|
124
|
+
return { outcome: 'written', roomDraft: (await roomDraftsOf(store, [record]))[0] };
|
|
125
|
+
}
|
|
126
|
+
async function keptPresentation({ store }, app, value) {
|
|
127
|
+
await (await store.open()).present({ app, value });
|
|
128
|
+
await store.changed(changeSet('', { presentation: app }));
|
|
129
|
+
}
|
|
130
|
+
export function roomDraftSurface(runtime) {
|
|
131
|
+
const { store } = runtime;
|
|
132
|
+
return {
|
|
133
|
+
list() {
|
|
134
|
+
return store
|
|
135
|
+
.exclusive(async () => {
|
|
136
|
+
await store.open();
|
|
137
|
+
return snapshotRoomDrafts(store);
|
|
138
|
+
})
|
|
139
|
+
.then((listed) => {
|
|
140
|
+
publishRoomDrafts(runtime, true);
|
|
141
|
+
return listed;
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
async read(room, written) {
|
|
145
|
+
const record = await store.draft(room, written.normalize('NFC'));
|
|
146
|
+
return record === undefined ? null : (await roomDraftsOf(store, [record]))[0];
|
|
147
|
+
},
|
|
148
|
+
write(room, written, revision, input, next = roomDraftRevision()) {
|
|
149
|
+
const path = written.normalize('NFC');
|
|
150
|
+
if (typeof next !== 'string' || next === '')
|
|
151
|
+
return Promise.reject(runtimeError('room-draft-malformed'));
|
|
152
|
+
return store.gathered(`room-draft\u0000${room}\u0000${path}`, { revision, input, next }, (earlier, later) => {
|
|
153
|
+
if (later.revision !== earlier.next)
|
|
154
|
+
return null;
|
|
155
|
+
const parts = gatheredParts(earlier.input, later.input);
|
|
156
|
+
return parts === null
|
|
157
|
+
? null
|
|
158
|
+
: { revision: earlier.revision, input: parts, next: later.next };
|
|
159
|
+
}, (written) => writtenRoomDraft(runtime, room, path, written.revision, written.input, written.next));
|
|
160
|
+
},
|
|
161
|
+
discard(room, written, revision) {
|
|
162
|
+
const path = written.normalize('NFC');
|
|
163
|
+
return store.exclusive(async () => {
|
|
164
|
+
const local = await store.open();
|
|
165
|
+
const current = await store.draft(room, path);
|
|
166
|
+
if (current === undefined || current.revision !== revision) {
|
|
167
|
+
return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
|
|
168
|
+
}
|
|
169
|
+
await local.discardRoomDraft(room, path);
|
|
170
|
+
await store.changed(changeSet(room, { drafts: [path] }));
|
|
171
|
+
return { outcome: 'written', roomDraft: null };
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
export function presentationSurface(runtime) {
|
|
177
|
+
const { store } = runtime;
|
|
178
|
+
return {
|
|
179
|
+
read(app) {
|
|
180
|
+
return store.exclusive(() => presentationOf(store, app));
|
|
181
|
+
},
|
|
182
|
+
write(app, value) {
|
|
183
|
+
return store.exclusive(() => keptPresentation(runtime, app, structuredClone(value)));
|
|
184
|
+
},
|
|
185
|
+
edit(app, members) {
|
|
186
|
+
return store.gathered(`presentation\u0000${app}`, structuredClone(members), (earlier, later) => ({ ...earlier, ...later }), async (edited) => {
|
|
187
|
+
const kept = await (await store.open()).presentation(app);
|
|
188
|
+
await keptPresentation(runtime, app, Object.fromEntries([
|
|
189
|
+
...Object.entries(plain(kept) ? kept : {}).filter(([member]) => !Object.hasOwn(edited, member)),
|
|
190
|
+
...Object.entries(edited).filter(([, value]) => value !== null),
|
|
191
|
+
]));
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export function watchRoomDrafts({ store, socket }, deliver) {
|
|
197
|
+
const watcher = store.watch(ROOM_DRAFTS, deliver);
|
|
198
|
+
const unwatched = () => socket.closed() || !watcher.held();
|
|
199
|
+
void store
|
|
200
|
+
.exclusive(async () => {
|
|
201
|
+
await store.open();
|
|
202
|
+
})
|
|
203
|
+
.then(() => store.publication(async () => {
|
|
204
|
+
if (unwatched())
|
|
205
|
+
return;
|
|
206
|
+
const value = await snapshotRoomDrafts(store);
|
|
207
|
+
if (!unwatched())
|
|
208
|
+
watcher.answer(value);
|
|
209
|
+
}), uncaught);
|
|
210
|
+
return watcher.stop;
|
|
211
|
+
}
|
|
212
|
+
export function watchPresentation({ store, socket }, app, deliver) {
|
|
213
|
+
const watcher = store.watch(presentationTopic(app), deliver);
|
|
214
|
+
void store
|
|
215
|
+
.exclusive(async () => {
|
|
216
|
+
const value = await presentationOf(store, app);
|
|
217
|
+
if (!socket.closed() && watcher.held())
|
|
218
|
+
watcher.answer(value);
|
|
219
|
+
})
|
|
220
|
+
.catch(uncaught);
|
|
221
|
+
return watcher.stop;
|
|
222
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuthorityChange, RoomList } from './adapter.js';
|
|
2
|
+
import type { Runtime } from './runtime.js';
|
|
3
|
+
import type { Deliver } from './reach.js';
|
|
4
|
+
export declare const ROOM_LIST_TOPIC = "room-list";
|
|
5
|
+
type RoomListChange = NonNullable<AuthorityChange['roomList']>;
|
|
6
|
+
export declare function roomsListed(runtime: Runtime, list: RoomList | undefined): Promise<void>;
|
|
7
|
+
export declare function roomListChanged(runtime: Runtime, change: RoomListChange | undefined): Promise<void>;
|
|
8
|
+
export declare function watchRoomList(runtime: Runtime, deliver: Deliver): () => void;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=room-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-list.d.ts","sourceRoot":"","sources":["../src/room-list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C,eAAO,MAAM,eAAe,cAAc,CAAC;AAE3C,KAAK,cAAc,GAAG,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;AA2B/D,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvF;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,cAAc,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,IAAI,CAU5E"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { uncaught } from './failure.js';
|
|
2
|
+
import { runsListed } from './runs.js';
|
|
3
|
+
export const ROOM_LIST_TOPIC = 'room-list';
|
|
4
|
+
async function kept(runtime, next) {
|
|
5
|
+
const local = await runtime.store.open();
|
|
6
|
+
const { roomList } = await local.facts(['roomList']);
|
|
7
|
+
const listed = next(roomList);
|
|
8
|
+
if (listed === null || JSON.stringify(listed) === JSON.stringify(roomList))
|
|
9
|
+
return;
|
|
10
|
+
await local.fact('roomList', listed);
|
|
11
|
+
runtime.store.tell(ROOM_LIST_TOPIC, listed);
|
|
12
|
+
await runsListed(runtime, local, listed);
|
|
13
|
+
}
|
|
14
|
+
function changed(held, change) {
|
|
15
|
+
const named = new Map(change.rooms.map((room) => [room.room_ref, room]));
|
|
16
|
+
const left = new Set(change.left);
|
|
17
|
+
const known = new Set(held.rooms.map((room) => room.room_ref));
|
|
18
|
+
return {
|
|
19
|
+
rooms: [
|
|
20
|
+
...held.rooms.flatMap((room) => left.has(room.room_ref) ? [] : [named.get(room.room_ref) ?? room]),
|
|
21
|
+
...change.rooms.filter((room) => !known.has(room.room_ref)),
|
|
22
|
+
],
|
|
23
|
+
spaces: change.spaces,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function roomsListed(runtime, list) {
|
|
27
|
+
if (list === undefined)
|
|
28
|
+
return Promise.resolve();
|
|
29
|
+
return kept(runtime, () => list).catch(uncaught);
|
|
30
|
+
}
|
|
31
|
+
export function roomListChanged(runtime, change) {
|
|
32
|
+
if (change === undefined)
|
|
33
|
+
return Promise.resolve();
|
|
34
|
+
return kept(runtime, (held) => (held === null ? null : changed(held, change))).catch(uncaught);
|
|
35
|
+
}
|
|
36
|
+
export function watchRoomList(runtime, deliver) {
|
|
37
|
+
const { store } = runtime;
|
|
38
|
+
const watcher = store.watch(ROOM_LIST_TOPIC, deliver);
|
|
39
|
+
void store
|
|
40
|
+
.open()
|
|
41
|
+
.then((local) => local.facts(['roomList']))
|
|
42
|
+
.then(({ roomList }) => {
|
|
43
|
+
if (watcher.held())
|
|
44
|
+
deliver(roomList);
|
|
45
|
+
}, uncaught);
|
|
46
|
+
return watcher.stop;
|
|
47
|
+
}
|
package/dist/rows.d.ts
CHANGED
|
@@ -1,30 +1,48 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Definition, type HeldValue } from '@agentshouse/mdmodel';
|
|
2
|
+
import type { SavedFacts } from './adapter.js';
|
|
2
3
|
import { type Composition } from './collection.js';
|
|
3
|
-
type
|
|
4
|
+
import type { PlanReach } from './query.js';
|
|
5
|
+
type LinkKind = 'field' | 'link';
|
|
4
6
|
type HeldLink = {
|
|
5
7
|
readonly kind: LinkKind;
|
|
6
8
|
readonly keys: string;
|
|
7
9
|
readonly places: string;
|
|
10
|
+
readonly handle: string | null;
|
|
8
11
|
readonly target: string;
|
|
9
12
|
readonly field: string;
|
|
10
13
|
};
|
|
11
14
|
export type Described = {
|
|
12
15
|
readonly type: string | null;
|
|
13
16
|
readonly declared: string | null;
|
|
14
|
-
readonly queried: boolean;
|
|
15
17
|
readonly folder: string;
|
|
16
18
|
readonly fields: string | null;
|
|
19
|
+
readonly links: string | null;
|
|
17
20
|
};
|
|
18
|
-
export type
|
|
21
|
+
export type Held = {
|
|
22
|
+
readonly type: string | null;
|
|
23
|
+
readonly fields: Readonly<Record<string, unknown>> | null;
|
|
24
|
+
readonly links: readonly string[];
|
|
25
|
+
};
|
|
26
|
+
export type Sought = {
|
|
27
|
+
readonly type: string;
|
|
28
|
+
readonly field: string;
|
|
29
|
+
readonly value: string;
|
|
30
|
+
};
|
|
31
|
+
export type Derived = {
|
|
19
32
|
readonly values: readonly HeldValue[];
|
|
20
33
|
readonly links: readonly HeldLink[];
|
|
34
|
+
readonly unique: readonly Sought[];
|
|
21
35
|
};
|
|
22
36
|
export declare function documentKey(room: string, path: string): string;
|
|
23
37
|
export declare function roomOfKey(key: string): string;
|
|
38
|
+
export declare function roomsOfReach(reach: PlanReach): ReadonlySet<string>;
|
|
24
39
|
export declare function pathOfKey(key: string): string;
|
|
25
40
|
export declare function markdownPath(path: string): boolean;
|
|
26
41
|
export declare function folderOf(path: string): string;
|
|
27
|
-
export declare function
|
|
28
|
-
export declare function
|
|
42
|
+
export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
|
|
43
|
+
export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
|
|
44
|
+
export declare function heldOf(path: string, content: string | null, facts: SavedFacts | null): Held;
|
|
45
|
+
export declare function uniqueValues(type: string, fields: Readonly<Record<string, unknown>>, definition: Definition | undefined): Sought[];
|
|
46
|
+
export declare function derived(path: string, held: Held, composition: Composition): Derived;
|
|
29
47
|
export {};
|
|
30
48
|
//# sourceMappingURL=rows.d.ts.map
|
package/dist/rows.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"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"}
|
package/dist/rows.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { governing } from './collection.js';
|
|
3
|
-
import { definitionOf } from './model.js';
|
|
1
|
+
import { byCodePoint, documentFacts, fieldKey, indexed, parse, } from '@agentshouse/mdmodel';
|
|
2
|
+
import { definitionsAt, governing } from './collection.js';
|
|
4
3
|
function keyOf(...parts) {
|
|
5
4
|
return `${parts.join('\u0000')}\u0000`;
|
|
6
5
|
}
|
|
@@ -10,77 +9,83 @@ export function documentKey(room, path) {
|
|
|
10
9
|
export function roomOfKey(key) {
|
|
11
10
|
return key.split('\u0000')[1];
|
|
12
11
|
}
|
|
12
|
+
export function roomsOfReach(reach) {
|
|
13
|
+
return new Set([...reach.rooms, ...reach.documents.map(roomOfKey)]);
|
|
14
|
+
}
|
|
13
15
|
export function pathOfKey(key) {
|
|
14
16
|
return key.split('\u0000')[2];
|
|
15
17
|
}
|
|
18
|
+
const MARKDOWN = /\.md$/iu;
|
|
16
19
|
export function markdownPath(path) {
|
|
17
|
-
return
|
|
20
|
+
return MARKDOWN.test(path);
|
|
18
21
|
}
|
|
19
22
|
export function folderOf(path) {
|
|
20
23
|
return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
|
|
21
24
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
25
|
+
function byKey(_key, value) {
|
|
26
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
27
|
+
return value;
|
|
28
|
+
return Object.fromEntries(Object.entries(value).sort(([one], [other]) => byCodePoint(one, other)));
|
|
29
|
+
}
|
|
30
|
+
function fieldsText(fields) {
|
|
31
|
+
return JSON.stringify(fields, byKey);
|
|
24
32
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
continue;
|
|
34
|
-
sectioned.add(reached);
|
|
35
|
-
links.push({ kind: 'section', keys: '', places: '', target: reached, field: '' });
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return { values, links: [...links, ...body] };
|
|
33
|
+
export function writtenFacts(path, content, composition) {
|
|
34
|
+
const model = governing(composition, path);
|
|
35
|
+
const facts = documentFacts(path, parse(content, path, definitionsAt(composition, path)), {
|
|
36
|
+
types: model.status === 'unavailable' ? {} : model.types,
|
|
37
|
+
});
|
|
38
|
+
return facts === null
|
|
39
|
+
? null
|
|
40
|
+
: { ...facts, fields: JSON.parse(fieldsText(facts.fields)) };
|
|
39
41
|
}
|
|
40
|
-
function
|
|
42
|
+
export function described(path, content, facts) {
|
|
41
43
|
const folder = folderOf(path);
|
|
42
|
-
const unread = {
|
|
43
|
-
if (
|
|
44
|
-
return {
|
|
45
|
-
|
|
44
|
+
const unread = { type: null, fields: null, links: null, folder };
|
|
45
|
+
if (content === null || facts === null)
|
|
46
|
+
return { ...unread, declared: null };
|
|
47
|
+
const links = JSON.stringify(facts.links);
|
|
48
|
+
if (!markdownPath(path))
|
|
49
|
+
return { ...unread, declared: facts.type, links };
|
|
46
50
|
return {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
fields: JSON.stringify(document.fields),
|
|
53
|
-
},
|
|
54
|
-
document,
|
|
51
|
+
type: facts.type,
|
|
52
|
+
declared: facts.type,
|
|
53
|
+
folder,
|
|
54
|
+
fields: fieldsText(facts.fields),
|
|
55
|
+
links,
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
folder: folderOf(path),
|
|
64
|
-
type: null,
|
|
65
|
-
declared: null,
|
|
66
|
-
queried: true,
|
|
67
|
-
},
|
|
68
|
-
document: null,
|
|
69
|
-
links: [],
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const type = held.type === null || held.type === 'any' ? undefined : held.type;
|
|
73
|
-
const document = held.fields === null ? null : { type, fields: held.fields };
|
|
74
|
-
return { ...readOf(path, held.type, document), links: held.links };
|
|
58
|
+
export function heldOf(path, content, facts) {
|
|
59
|
+
if (content === null || facts === null)
|
|
60
|
+
return { type: null, fields: null, links: [] };
|
|
61
|
+
return markdownPath(path)
|
|
62
|
+
? { type: facts.type, fields: facts.fields, links: facts.links }
|
|
63
|
+
: { type: null, fields: null, links: facts.links };
|
|
75
64
|
}
|
|
76
|
-
export function
|
|
77
|
-
|
|
65
|
+
export function uniqueValues(type, fields, definition) {
|
|
66
|
+
if (definition === undefined)
|
|
67
|
+
return [];
|
|
68
|
+
return (definition.unique ?? []).flatMap((field) => {
|
|
69
|
+
const { key, unique } = fieldKey(definition, fields, field);
|
|
70
|
+
return unique ? [{ type, field, value: key }] : [];
|
|
71
|
+
});
|
|
78
72
|
}
|
|
79
|
-
export function derived(path,
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
export function derived(path, held, composition) {
|
|
74
|
+
const stored = held.links.map((target) => ({
|
|
75
|
+
kind: 'link',
|
|
76
|
+
keys: '',
|
|
77
|
+
places: '',
|
|
78
|
+
handle: null,
|
|
79
|
+
target,
|
|
80
|
+
field: '',
|
|
81
|
+
}));
|
|
82
|
+
if (held.type === null || held.fields === null)
|
|
83
|
+
return { values: [], links: stored, unique: [] };
|
|
84
|
+
const definition = definitionsAt(composition, path)(held.type);
|
|
85
|
+
const { values, links: fields } = indexed(path, held.fields, definition);
|
|
86
|
+
return {
|
|
87
|
+
values,
|
|
88
|
+
links: [...fields, ...stored],
|
|
89
|
+
unique: uniqueValues(held.type, held.fields, definition),
|
|
90
|
+
};
|
|
86
91
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RunEvent, RunMarks } from './adapter.js';
|
|
2
|
+
import type { Connection } from './tables.js';
|
|
3
|
+
export declare const RUN_TABLES: readonly string[];
|
|
4
|
+
export type RunsAsked = {
|
|
5
|
+
readonly room: string;
|
|
6
|
+
} | {
|
|
7
|
+
readonly sent: true;
|
|
8
|
+
};
|
|
9
|
+
export type RunSight = {
|
|
10
|
+
readonly held: readonly string[];
|
|
11
|
+
readonly searched: readonly string[];
|
|
12
|
+
readonly starter: string | null;
|
|
13
|
+
};
|
|
14
|
+
export type HeldRun = {
|
|
15
|
+
readonly room: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly document: string;
|
|
18
|
+
readonly current: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare function runMarks(connection: Connection): RunMarks;
|
|
21
|
+
export declare function keptRuns(connection: Connection, event: RunEvent): RunMarks | null;
|
|
22
|
+
export declare function heldRuns(connection: Connection, asked: RunsAsked, sight: RunSight): HeldRun[] | null;
|
|
23
|
+
export declare function runsLeft(connection: Connection, sight: RunSight): RunMarks;
|
|
24
|
+
export declare function forgottenRuns(connection: Connection): void;
|
|
25
|
+
//# sourceMappingURL=run-tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-tables.d.ts","sourceRoot":"","sources":["../src/run-tables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAO,MAAM,UAAU,EAAE,SAAS,MAAM,EAKvC,CAAC;AAMF,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC;AAE5E,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAmBF,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,CAWzD;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,GAAG,QAAQ,GAAG,IAAI,CA4BjF;AAOD,wBAAgB,QAAQ,CACtB,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,QAAQ,GACd,OAAO,EAAE,GAAG,IAAI,CAuBlB;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAc1E;AAED,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAE1D"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { count, text } from './column.js';
|
|
2
|
+
import { tablesOf } from './stored.js';
|
|
3
|
+
export const RUN_TABLES = [
|
|
4
|
+
'CREATE TABLE runs (name TEXT PRIMARY KEY, room TEXT NOT NULL, starter TEXT, current INTEGER NOT NULL, sent INTEGER NOT NULL, stale INTEGER NOT NULL, document TEXT NOT NULL) WITHOUT ROWID',
|
|
5
|
+
'CREATE INDEX runs_room ON runs (room, name)',
|
|
6
|
+
'CREATE INDEX runs_starter ON runs (starter, name)',
|
|
7
|
+
'CREATE TABLE run_marks (listing TEXT PRIMARY KEY, mark TEXT, relisting TEXT) WITHOUT ROWID',
|
|
8
|
+
];
|
|
9
|
+
const SENT_LISTING = '';
|
|
10
|
+
const IN_LIST = 'SELECT value FROM json_each(?)';
|
|
11
|
+
function kept(connection, run, sent, listed) {
|
|
12
|
+
connection.run(`INSERT INTO runs (name, room, starter, current, sent, stale, document) VALUES (?, ?, ?, ?, ?, 0, ?)
|
|
13
|
+
ON CONFLICT (name) DO UPDATE SET room = excluded.room, starter = excluded.starter,
|
|
14
|
+
current = excluded.current, stale = 0, document = excluded.document${listed ? ', sent = excluded.sent' : ''}`, [run.name, run.room, run.starter, run.current ? 1 : 0, sent ? 1 : 0, run.document]);
|
|
15
|
+
}
|
|
16
|
+
function ofListing(listing) {
|
|
17
|
+
return listing === null ? 'sent = 1' : 'room = ?';
|
|
18
|
+
}
|
|
19
|
+
function listingBound(listing) {
|
|
20
|
+
return listing === null ? [] : [listing];
|
|
21
|
+
}
|
|
22
|
+
export function runMarks(connection) {
|
|
23
|
+
const rooms = {};
|
|
24
|
+
let sent = null;
|
|
25
|
+
for (const row of connection.rows('SELECT listing, mark FROM run_marks WHERE mark IS NOT NULL ORDER BY listing')) {
|
|
26
|
+
const listing = text(row.listing);
|
|
27
|
+
if (listing === SENT_LISTING)
|
|
28
|
+
sent = text(row.mark);
|
|
29
|
+
else
|
|
30
|
+
rooms[listing] = text(row.mark);
|
|
31
|
+
}
|
|
32
|
+
return { rooms, sent };
|
|
33
|
+
}
|
|
34
|
+
export function keptRuns(connection, event) {
|
|
35
|
+
if (event.kind === 'run') {
|
|
36
|
+
kept(connection, event.run, event.listing === null, false);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const { listing, runs, whole, more, mark } = event;
|
|
40
|
+
const key = listing ?? SENT_LISTING;
|
|
41
|
+
const [held] = connection.rows('SELECT mark, relisting FROM run_marks WHERE listing = ?', [key]);
|
|
42
|
+
if (whole && (held === undefined || held.relisting !== mark)) {
|
|
43
|
+
connection.run(`UPDATE runs SET stale = 1 WHERE ${ofListing(listing)}`, listingBound(listing));
|
|
44
|
+
connection.run('INSERT INTO run_marks (listing, mark, relisting) VALUES (?, NULL, ?) ON CONFLICT (listing) DO UPDATE SET relisting = excluded.relisting', [key, mark]);
|
|
45
|
+
}
|
|
46
|
+
for (const run of runs)
|
|
47
|
+
kept(connection, run, listing === null, true);
|
|
48
|
+
if (more)
|
|
49
|
+
return null;
|
|
50
|
+
if (whole) {
|
|
51
|
+
connection.run(`DELETE FROM runs WHERE ${ofListing(listing)} AND stale = 1`, listingBound(listing));
|
|
52
|
+
}
|
|
53
|
+
connection.run('INSERT INTO run_marks (listing, mark, relisting) VALUES (?, ?, NULL) ON CONFLICT (listing) DO UPDATE SET mark = excluded.mark, relisting = NULL', [key, mark]);
|
|
54
|
+
return runMarks(connection);
|
|
55
|
+
}
|
|
56
|
+
function listingOf(asked, sight) {
|
|
57
|
+
if ('sent' in asked || sight.searched.includes(asked.room))
|
|
58
|
+
return SENT_LISTING;
|
|
59
|
+
return sight.held.includes(asked.room) ? asked.room : null;
|
|
60
|
+
}
|
|
61
|
+
export function heldRuns(connection, asked, sight) {
|
|
62
|
+
const listing = listingOf(asked, sight);
|
|
63
|
+
if (listing !== null &&
|
|
64
|
+
connection.rows('SELECT 1 FROM run_marks WHERE listing = ? AND mark IS NOT NULL', [listing])
|
|
65
|
+
.length === 0)
|
|
66
|
+
return null;
|
|
67
|
+
const [scope, bound] = 'sent' in asked ? ['starter = ?', sight.starter] : ['room = ?', asked.room];
|
|
68
|
+
return connection
|
|
69
|
+
.rows(`SELECT room, name, current, document FROM runs
|
|
70
|
+
WHERE ${scope} AND (room IN (${IN_LIST}) OR (starter = ? AND room IN (${IN_LIST})))
|
|
71
|
+
ORDER BY name`, [bound, JSON.stringify(sight.held), sight.starter, JSON.stringify(sight.searched)])
|
|
72
|
+
.map((row) => ({
|
|
73
|
+
room: text(row.room),
|
|
74
|
+
name: text(row.name),
|
|
75
|
+
document: text(row.document),
|
|
76
|
+
current: count(row.current) === 1,
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
export function runsLeft(connection, sight) {
|
|
80
|
+
const held = JSON.stringify(sight.held);
|
|
81
|
+
const searched = JSON.stringify(sight.searched);
|
|
82
|
+
connection.run(`DELETE FROM runs WHERE room NOT IN (${IN_LIST})
|
|
83
|
+
AND NOT (coalesce(starter = ?, 0) AND room IN (${IN_LIST}))`, [held, sight.starter, searched]);
|
|
84
|
+
connection.run(`UPDATE runs SET sent = 1 WHERE room IN (${IN_LIST})`, [searched]);
|
|
85
|
+
connection.run(`DELETE FROM run_marks WHERE listing <> ? AND listing NOT IN (${IN_LIST})`, [
|
|
86
|
+
SENT_LISTING,
|
|
87
|
+
held,
|
|
88
|
+
]);
|
|
89
|
+
return runMarks(connection);
|
|
90
|
+
}
|
|
91
|
+
export function forgottenRuns(connection) {
|
|
92
|
+
for (const table of tablesOf(RUN_TABLES))
|
|
93
|
+
connection.run(`DELETE FROM ${table}`);
|
|
94
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"running.d.ts","sourceRoot":"","sources":["../src/running.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEjE,KAAK,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAU/C,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,MAAM,EAAE,CAE3E"}
|
package/dist/running.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const NOUNS = {
|
|
2
|
+
subagent: ['sub-agent', 'sub-agents'],
|
|
3
|
+
shell: ['command', 'commands'],
|
|
4
|
+
task: ['task', 'tasks'],
|
|
5
|
+
monitor: ['monitor', 'monitors'],
|
|
6
|
+
schedule: ['schedule', 'schedules'],
|
|
7
|
+
};
|
|
8
|
+
export function runningWords(running) {
|
|
9
|
+
return running.map(({ kind, count }) => `${count} ${NOUNS[kind][count === 1 ? 0 : 1]}`);
|
|
10
|
+
}
|