@agentshouse/mdruntime 0.1.0-c9ede0b00364b → 0.1.0-ca10b2b0a3e33
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 +32 -22
- package/dist/act-lanes.d.ts +1 -0
- package/dist/act-lanes.d.ts.map +1 -1
- package/dist/act-lanes.js +53 -5
- package/dist/actions.d.ts +1 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +135 -55
- package/dist/adapter.d.ts +176 -29
- 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 +27 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +29 -57
- 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 +15 -14
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +21 -9
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +19 -8
- package/dist/conversation-row.d.ts +20 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +30 -7
- package/dist/conversation.d.ts +30 -12
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +278 -198
- 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 -8
- 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 -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 -34
- 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 +3 -2
- package/dist/host.d.ts +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +77 -31
- 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 +22 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -6
- package/dist/install.d.ts +9 -3
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +44 -46
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +42 -29
- 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 -3
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +2 -3
- 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 +63 -23
- package/dist/messages.d.ts +21 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +43 -13
- 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 +5 -8
- 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 +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 +22 -10
- package/dist/outcome.d.ts +30 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +21 -6
- 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 -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 +198 -87
- 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 +116 -71
- 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 +1 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +54 -39
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +178 -38
- package/dist/react.d.ts +12 -1
- package/dist/react.d.ts.map +1 -1
- 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 +1 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +17 -6
- 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/refusal.d.ts.map +1 -1
- package/dist/refusal.js +1 -3
- 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 +240 -19
- 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 +5 -4
- 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 +17 -86
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +107 -57
- 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 +5 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +79 -43
- package/dist/socket/lanes.d.ts +10 -3
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +29 -6
- 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 -4
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +10 -9
- package/dist/source.d.ts +22 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +46 -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 +30 -8
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +70 -26
- 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 +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 +62 -27
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +52 -35
- 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 +40 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +22 -14
- package/package.json +4 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
if (event.kind === 'removed') {
|
|
40
|
+
connection.run('DELETE FROM runs WHERE name = ?', [event.name]);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const { listing, runs, whole, more, mark } = event;
|
|
44
|
+
const key = listing ?? SENT_LISTING;
|
|
45
|
+
const [held] = connection.rows('SELECT mark, relisting FROM run_marks WHERE listing = ?', [key]);
|
|
46
|
+
if (whole && (held === undefined || held.relisting !== mark)) {
|
|
47
|
+
connection.run(`UPDATE runs SET stale = 1 WHERE ${ofListing(listing)}`, listingBound(listing));
|
|
48
|
+
connection.run('INSERT INTO run_marks (listing, mark, relisting) VALUES (?, NULL, ?) ON CONFLICT (listing) DO UPDATE SET relisting = excluded.relisting', [key, mark]);
|
|
49
|
+
}
|
|
50
|
+
for (const run of runs)
|
|
51
|
+
kept(connection, run, listing === null, true);
|
|
52
|
+
if (more)
|
|
53
|
+
return null;
|
|
54
|
+
if (whole) {
|
|
55
|
+
connection.run(`DELETE FROM runs WHERE ${ofListing(listing)} AND stale = 1`, listingBound(listing));
|
|
56
|
+
}
|
|
57
|
+
connection.run('INSERT INTO run_marks (listing, mark, relisting) VALUES (?, ?, NULL) ON CONFLICT (listing) DO UPDATE SET mark = excluded.mark, relisting = NULL', [key, mark]);
|
|
58
|
+
return runMarks(connection);
|
|
59
|
+
}
|
|
60
|
+
function listingOf(asked, sight) {
|
|
61
|
+
if ('sent' in asked || sight.searched.includes(asked.room))
|
|
62
|
+
return SENT_LISTING;
|
|
63
|
+
return sight.held.includes(asked.room) ? asked.room : null;
|
|
64
|
+
}
|
|
65
|
+
export function heldRuns(connection, asked, sight) {
|
|
66
|
+
const listing = listingOf(asked, sight);
|
|
67
|
+
if (listing !== null &&
|
|
68
|
+
connection.rows('SELECT 1 FROM run_marks WHERE listing = ? AND mark IS NOT NULL', [listing])
|
|
69
|
+
.length === 0)
|
|
70
|
+
return null;
|
|
71
|
+
const [scope, bound] = 'sent' in asked ? ['starter = ?', sight.starter] : ['room = ?', asked.room];
|
|
72
|
+
return connection
|
|
73
|
+
.rows(`SELECT room, name, current, document FROM runs
|
|
74
|
+
WHERE ${scope} AND (room IN (${IN_LIST}) OR (starter = ? AND room IN (${IN_LIST})))
|
|
75
|
+
ORDER BY name`, [bound, JSON.stringify(sight.held), sight.starter, JSON.stringify(sight.searched)])
|
|
76
|
+
.map((row) => ({
|
|
77
|
+
room: text(row.room),
|
|
78
|
+
name: text(row.name),
|
|
79
|
+
document: text(row.document),
|
|
80
|
+
current: count(row.current) === 1,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
export function runsLeft(connection, sight) {
|
|
84
|
+
const held = JSON.stringify(sight.held);
|
|
85
|
+
const searched = JSON.stringify(sight.searched);
|
|
86
|
+
connection.run(`DELETE FROM runs WHERE room NOT IN (${IN_LIST})
|
|
87
|
+
AND NOT (coalesce(starter = ?, 0) AND room IN (${IN_LIST}))`, [held, sight.starter, searched]);
|
|
88
|
+
connection.run(`UPDATE runs SET sent = 1 WHERE room IN (${IN_LIST})`, [searched]);
|
|
89
|
+
connection.run(`DELETE FROM run_marks WHERE listing <> ? AND listing NOT IN (${IN_LIST})`, [
|
|
90
|
+
SENT_LISTING,
|
|
91
|
+
held,
|
|
92
|
+
]);
|
|
93
|
+
return runMarks(connection);
|
|
94
|
+
}
|
|
95
|
+
export function forgottenRuns(connection) {
|
|
96
|
+
for (const table of tablesOf(RUN_TABLES))
|
|
97
|
+
connection.run(`DELETE FROM ${table}`);
|
|
98
|
+
}
|
|
@@ -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
|
+
}
|
package/dist/runs.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RoomList, RunEvent } from './adapter.js';
|
|
2
|
+
import type { PendingResult } from './query.js';
|
|
3
|
+
import type { RunsAsked } from './run-tables.js';
|
|
4
|
+
import type { Runtime } from './runtime.js';
|
|
5
|
+
import type { RuntimeStore } from './store.js';
|
|
6
|
+
export declare const RUNS_TOPIC = "runs";
|
|
7
|
+
export type RunEntry = {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly document: string;
|
|
10
|
+
};
|
|
11
|
+
export type Runs = {
|
|
12
|
+
readonly current: readonly RunEntry[];
|
|
13
|
+
readonly history: readonly RunEntry[];
|
|
14
|
+
};
|
|
15
|
+
export type HeldRunEntry = RunEntry & {
|
|
16
|
+
readonly room: string;
|
|
17
|
+
};
|
|
18
|
+
export type HeldRuns = {
|
|
19
|
+
readonly current: readonly HeldRunEntry[];
|
|
20
|
+
readonly history: readonly HeldRunEntry[];
|
|
21
|
+
};
|
|
22
|
+
export declare function runsAsked(input: unknown): RunsAsked;
|
|
23
|
+
export declare function watchRuns(runtime: Runtime, input: unknown, deliver: (runs: HeldRuns | PendingResult) => void): () => void;
|
|
24
|
+
export declare function runsOpened(runtime: Runtime): Promise<void>;
|
|
25
|
+
export declare function runHeard(runtime: Runtime, event: RunEvent): void;
|
|
26
|
+
export declare function runsListed(runtime: Runtime, local: RuntimeStore, roomList: RoomList): Promise<void>;
|
|
27
|
+
//# sourceMappingURL=runs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runs.d.ts","sourceRoot":"","sources":["../src/runs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,QAAQ,EAAE,QAAQ,EAAY,MAAM,cAAc,CAAC;AAGzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAW,SAAS,EAAY,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;CAC3C,CAAC;AAaF,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAGnD;AA6CD,wBAAgB,SAAS,CACvB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,aAAa,KAAK,IAAI,GAChD,MAAM,IAAI,CAcZ;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhE;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAMhE;AAED,wBAAsB,UAAU,CAC9B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
package/dist/runs.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { refusedForSpace } from './durability.js';
|
|
2
|
+
import { uncaught } from './failure.js';
|
|
3
|
+
export const RUNS_TOPIC = 'runs';
|
|
4
|
+
function sightOf(roomList, member) {
|
|
5
|
+
const rooms = roomList?.rooms ?? [];
|
|
6
|
+
return {
|
|
7
|
+
held: rooms.filter((room) => room.level !== 'search').map((room) => room.room_ref),
|
|
8
|
+
searched: rooms.filter((room) => room.level === 'search').map((room) => room.room_ref),
|
|
9
|
+
starter: member?.id ?? null,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function runsAsked(input) {
|
|
13
|
+
const asked = input;
|
|
14
|
+
return asked?.sent === true ? { sent: true } : { room: String(asked?.room) };
|
|
15
|
+
}
|
|
16
|
+
function entryOf({ room, name, document }) {
|
|
17
|
+
return { room, name, document };
|
|
18
|
+
}
|
|
19
|
+
function touches(asked, touched) {
|
|
20
|
+
return touched === null || 'sent' in asked || touched.includes(asked.room);
|
|
21
|
+
}
|
|
22
|
+
function touchedBy(event) {
|
|
23
|
+
if (event.kind === 'run')
|
|
24
|
+
return [event.run.room];
|
|
25
|
+
if (event.kind === 'removed')
|
|
26
|
+
return [event.room];
|
|
27
|
+
if (event.listing !== null)
|
|
28
|
+
return [event.listing];
|
|
29
|
+
return event.whole ? null : event.runs.map((run) => run.room);
|
|
30
|
+
}
|
|
31
|
+
function written(runtime, marks, touched) {
|
|
32
|
+
const { store, socket } = runtime;
|
|
33
|
+
if (marks !== null)
|
|
34
|
+
socket.runs()?.hold(marks);
|
|
35
|
+
store.tell(RUNS_TOPIC, touched);
|
|
36
|
+
}
|
|
37
|
+
function unwritten(error) {
|
|
38
|
+
if (!refusedForSpace(error))
|
|
39
|
+
uncaught(error);
|
|
40
|
+
}
|
|
41
|
+
function unheard(asked) {
|
|
42
|
+
return { pending: 'sent' in asked ? [] : [{ room: asked.room, awaits: 'acquisition' }] };
|
|
43
|
+
}
|
|
44
|
+
async function heldRuns(runtime, asked) {
|
|
45
|
+
const { store } = runtime;
|
|
46
|
+
const { roomList, member } = await (await store.open()).facts(['roomList', 'member']);
|
|
47
|
+
const held = roomList === null
|
|
48
|
+
? null
|
|
49
|
+
: await store.ask({ kind: 'run.held', asked, sight: sightOf(roomList, member) });
|
|
50
|
+
if (held === null)
|
|
51
|
+
return unheard(asked);
|
|
52
|
+
return {
|
|
53
|
+
current: held.filter((run) => run.current).map(entryOf),
|
|
54
|
+
history: held.map(entryOf),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function watchRuns(runtime, input, deliver) {
|
|
58
|
+
const { store } = runtime;
|
|
59
|
+
const asked = runsAsked(input);
|
|
60
|
+
const answer = () => store.publication(async () => {
|
|
61
|
+
if (!watcher.held())
|
|
62
|
+
return;
|
|
63
|
+
const runs = await heldRuns(runtime, asked);
|
|
64
|
+
if (watcher.held())
|
|
65
|
+
deliver(runs);
|
|
66
|
+
});
|
|
67
|
+
const watcher = store.watch(RUNS_TOPIC, (touched) => {
|
|
68
|
+
if (touches(asked, touched))
|
|
69
|
+
void answer();
|
|
70
|
+
});
|
|
71
|
+
void answer();
|
|
72
|
+
return watcher.stop;
|
|
73
|
+
}
|
|
74
|
+
export async function runsOpened(runtime) {
|
|
75
|
+
const { store, socket } = runtime;
|
|
76
|
+
socket.runs()?.hold(await store.ask({ kind: 'run.marks' }));
|
|
77
|
+
}
|
|
78
|
+
export function runHeard(runtime, event) {
|
|
79
|
+
const { store, socket } = runtime;
|
|
80
|
+
if (socket.closed())
|
|
81
|
+
return;
|
|
82
|
+
void store
|
|
83
|
+
.exclusive(() => store.ask({ kind: 'run.keep', event }))
|
|
84
|
+
.then((marks) => written(runtime, marks, touchedBy(event)), unwritten);
|
|
85
|
+
}
|
|
86
|
+
export async function runsListed(runtime, local, roomList) {
|
|
87
|
+
const { store } = runtime;
|
|
88
|
+
const { member } = await local.facts(['member']);
|
|
89
|
+
await store
|
|
90
|
+
.exclusive(() => store.ask({ kind: 'run.left', sight: sightOf(roomList, member) }))
|
|
91
|
+
.then((marks) => written(runtime, marks, null), unwritten);
|
|
92
|
+
}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { RoomDeclaration, TypedPath } from './adapter.js';
|
|
1
|
+
import type { Discovery, RoomDeclaration, TypedPath } from './adapter.js';
|
|
2
2
|
import type { RuntimeShell } from './durability.js';
|
|
3
3
|
import type { LiveConversations } from './conversation-live.js';
|
|
4
4
|
import type { WriteRule } from './declaration.js';
|
|
5
5
|
import type { FiguresRead } from './figures.js';
|
|
6
6
|
import type { LiveQueries } from './live.js';
|
|
7
|
-
import type { Log } from './log.js';
|
|
8
7
|
import type { ModelState } from './model.js';
|
|
9
8
|
import type { Presence } from './presence.js';
|
|
10
9
|
import type { ReadAnswers } from './reads.js';
|
|
@@ -17,7 +16,6 @@ export type Runtime = {
|
|
|
17
16
|
readonly store: Store;
|
|
18
17
|
readonly socket: RuntimeSocket;
|
|
19
18
|
readonly presence: Presence;
|
|
20
|
-
readonly journal: Log;
|
|
21
19
|
readonly recovery: Recovery;
|
|
22
20
|
readonly retries: Retries;
|
|
23
21
|
readonly shell: RuntimeShell;
|
|
@@ -25,12 +23,15 @@ export type Runtime = {
|
|
|
25
23
|
readonly roomTypes: Parameters<typeof schemaTypes>[1];
|
|
26
24
|
readonly builtIn: ModelState;
|
|
27
25
|
readonly typedPaths: readonly TypedPath[];
|
|
26
|
+
readonly renamedActions: ReadonlyMap<string, string>;
|
|
27
|
+
readonly rewrittenInputs: ReadonlyMap<string, (input: unknown) => unknown>;
|
|
28
28
|
readonly writeRule: (declaration: RoomDeclaration) => WriteRule;
|
|
29
|
-
readonly usableWhenHeld: readonly string[];
|
|
30
29
|
readonly build: string;
|
|
31
30
|
readonly conversations: LiveConversations;
|
|
32
31
|
readonly liveQueries: LiveQueries<HeldCover>;
|
|
33
32
|
readonly figures: FiguresRead;
|
|
34
33
|
readonly lastAnswers: ReadAnswers;
|
|
34
|
+
readonly discover: () => Promise<void>;
|
|
35
|
+
readonly adopt: (unstored: Discovery) => Promise<void>;
|
|
35
36
|
};
|
|
36
37
|
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA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CAAC,CAAC;IACtD,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrD,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;IAC3E,QAAQ,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,eAAe,KAAK,SAAS,CAAC;IAChE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAC7C,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD,CAAC"}
|
package/dist/save.d.ts
CHANGED
package/dist/save.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"AACA,OAAO,EAqBL,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAOL,KAAK,WAAW,EAIhB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAQL,KAAK,WAAW,EACjB,MAAM,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AE,WAAW,EAClB,OAAO,EAAE,YAAY,GACpB,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,CAOtC;AA4ED,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEtE;AAED,wBAAiB,WAAW,CAC1B,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,YAAY,GACpB,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,CAItC;AA4uCD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,MAAM,GAAG,IAAI,CAKxF;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAE7F"}
|
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, relativize, retarget, roomReferences, serialize, target, } 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,7 +207,7 @@ 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
|
|
210
|
+
return partsBetween(path, document, after);
|
|
252
211
|
}
|
|
253
212
|
function roomPathOf(handle, path) {
|
|
254
213
|
return `/rooms/${handle}/${path}`;
|
|
@@ -458,7 +417,7 @@ function* preconditionsOf(changes, visible, bases) {
|
|
|
458
417
|
};
|
|
459
418
|
for (const change of changes) {
|
|
460
419
|
yield ROW_WEIGHT;
|
|
461
|
-
if (change
|
|
420
|
+
if (isPart(change)) {
|
|
462
421
|
const based = bases.find((base) => sameTarget(base, change));
|
|
463
422
|
if (based !== undefined) {
|
|
464
423
|
add(based);
|
|
@@ -613,9 +572,6 @@ function relativeChange(change, input) {
|
|
|
613
572
|
function unqueueable(file) {
|
|
614
573
|
return refuse('unknown-revision', file);
|
|
615
574
|
}
|
|
616
|
-
function isPart(change) {
|
|
617
|
-
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
618
|
-
}
|
|
619
575
|
function touched(change) {
|
|
620
576
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
621
577
|
}
|
|
@@ -642,29 +598,7 @@ function unapplied(changes, visible, composition) {
|
|
|
642
598
|
function partsResult(content, path, changes, composition) {
|
|
643
599
|
const definitions = definitionsAt(composition, path);
|
|
644
600
|
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));
|
|
601
|
+
return parsed.ok ? applyParts(parsed.document, changes, definitions(parsed.document.type)) : null;
|
|
668
602
|
}
|
|
669
603
|
function settledParts(changes, deferred, composition) {
|
|
670
604
|
for (const [held, parts] of deferred) {
|
|
@@ -883,11 +817,8 @@ function* limiting(queue, batch, limits, state) {
|
|
|
883
817
|
const limited = yield* exceeding(limits, batch.changes, rewritten.changes, yield* state(queue.slice(0, at + 1)));
|
|
884
818
|
return limited?.refusal ?? null;
|
|
885
819
|
}
|
|
886
|
-
function
|
|
887
|
-
|
|
888
|
-
return false;
|
|
889
|
-
const parsed = parse(content);
|
|
890
|
-
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
820
|
+
function typedContent(composition, path, content) {
|
|
821
|
+
return (content !== undefined && (typeAt(composition, path, parse(content)) ?? UNTYPED) !== UNTYPED);
|
|
891
822
|
}
|
|
892
823
|
function touchedLibrary(resulting, touched, composition) {
|
|
893
824
|
const entries = touched
|
|
@@ -907,9 +838,9 @@ function touchedLibrary(resulting, touched, composition) {
|
|
|
907
838
|
if (binaries.has(path))
|
|
908
839
|
known.set(path, { type: undefined, binary: true });
|
|
909
840
|
else if (content !== undefined && content !== null) {
|
|
910
|
-
const
|
|
911
|
-
if (
|
|
912
|
-
known.set(path, { type
|
|
841
|
+
const type = typeAt(composition, path, parse(content, path, definitionsAt(composition, path)));
|
|
842
|
+
if (type !== undefined)
|
|
843
|
+
known.set(path, { type, binary: false });
|
|
913
844
|
await pace(content.length + ROW_WEIGHT);
|
|
914
845
|
}
|
|
915
846
|
}
|
|
@@ -927,7 +858,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
927
858
|
for (const path of touched) {
|
|
928
859
|
const before = visible.documents[path];
|
|
929
860
|
const after = resulting.documents[path];
|
|
930
|
-
if (
|
|
861
|
+
if (typedContent(composition, path, before) || typedContent(composition, path, after))
|
|
931
862
|
typedPaths.push(path);
|
|
932
863
|
await pace((before?.length ?? 0) + (after?.length ?? 0) + ROW_WEIGHT);
|
|
933
864
|
}
|
|
@@ -1166,7 +1097,7 @@ function unreadable(saved, visible, composition) {
|
|
|
1166
1097
|
const path = saved.find(({ path: at, parts }) => (parts.fields !== undefined ||
|
|
1167
1098
|
parts.sections !== undefined ||
|
|
1168
1099
|
parts.preamble !== undefined) &&
|
|
1169
|
-
|
|
1100
|
+
typedContent(composition, at, visible.documents[at]) &&
|
|
1170
1101
|
governing(composition, at).status === 'unavailable')?.path;
|
|
1171
1102
|
return path === undefined ? null : refuse('model-unavailable', path);
|
|
1172
1103
|
}
|
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,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