@agentshouse/mdruntime 0.1.0-c80bb5b77602a → 0.1.0-c80f51ef6a574
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/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +31 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +35 -15
- package/dist/adapter.d.ts +100 -14
- package/dist/adapter.d.ts.map +1 -1
- package/dist/{binary.d.ts → attachment.d.ts} +3 -3
- package/dist/attachment.d.ts.map +1 -0
- package/dist/{binary.js → attachment.js} +1 -1
- package/dist/authored.d.ts.map +1 -1
- package/dist/authored.js +0 -2
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/client.d.ts +8 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -3
- package/dist/collection.d.ts +1 -0
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +7 -1
- package/dist/compile.d.ts +2 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +71 -37
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +8 -2
- package/dist/conversation-live.d.ts +1 -0
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +2 -1
- package/dist/conversation-row.d.ts +16 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +17 -1
- package/dist/conversation.d.ts +13 -4
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +45 -36
- package/dist/declaration.js +2 -2
- package/dist/download.d.ts +2 -2
- package/dist/download.d.ts.map +1 -1
- package/dist/download.js +2 -2
- package/dist/durability.d.ts +1 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +12 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +86 -25
- package/dist/figures.d.ts +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +2 -2
- package/dist/holdings.d.ts.map +1 -1
- package/dist/holdings.js +5 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +2 -2
- package/dist/house-query.d.ts +8 -2
- package/dist/house-query.d.ts.map +1 -1
- package/dist/house-query.js +53 -5
- 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 +12 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +2 -0
- 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/live.d.ts +14 -0
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +29 -12
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +16 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +11 -8
- package/dist/messages.d.ts +5 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +14 -3
- package/dist/model.d.ts +6 -5
- package/dist/model.d.ts.map +1 -1
- 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 +2 -0
- package/dist/outcome.d.ts +16 -16
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +4 -4
- package/dist/overlay.d.ts +17 -6
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +108 -37
- package/dist/parts.d.ts +1 -0
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +1 -1
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +56 -13
- package/dist/query.d.ts +1 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/queue.d.ts +1 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +4 -2
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +22 -6
- package/dist/react.d.ts +6 -0
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +4 -1
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +2 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +15 -4
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +2 -2
- package/dist/room-draft.d.ts +1 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +4 -4
- package/dist/room-drafts.js +2 -2
- package/dist/room-list.d.ts.map +1 -1
- package/dist/room-list.js +2 -0
- package/dist/rows.d.ts +9 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +17 -4
- 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/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/runtime.d.ts +4 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +21 -17
- package/dist/saves.d.ts +3 -3
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +53 -46
- 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 +1 -1
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +13 -12
- package/dist/socket.d.ts +3 -1
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +7 -0
- package/dist/source.d.ts +35 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +61 -7
- package/dist/store/records.d.ts +12 -5
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +10 -4
- package/dist/store.d.ts +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/stored.d.ts +9 -2
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +33 -11
- package/dist/surface.d.ts +7 -1
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +3 -0
- package/dist/tables.d.ts +26 -3
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +24 -4
- package/dist/tallies.js +2 -2
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +49 -3
- package/dist/wire.d.ts +2 -1
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +2 -1
- package/package.json +4 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/reference-forms.d.ts +0 -4
- package/dist/reference-forms.d.ts.map +0 -1
- package/dist/reference-forms.js +0 -74
package/dist/room-list.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { uncaught } from './failure.js';
|
|
2
|
+
import { runsListed } from './runs.js';
|
|
2
3
|
export const ROOM_LIST_TOPIC = 'room-list';
|
|
3
4
|
async function kept(runtime, next) {
|
|
4
5
|
const local = await runtime.store.open();
|
|
@@ -8,6 +9,7 @@ async function kept(runtime, next) {
|
|
|
8
9
|
return;
|
|
9
10
|
await local.fact('roomList', listed);
|
|
10
11
|
runtime.store.tell(ROOM_LIST_TOPIC, listed);
|
|
12
|
+
await runsListed(runtime, local, listed);
|
|
11
13
|
}
|
|
12
14
|
function changed(held, change) {
|
|
13
15
|
const named = new Map(change.rooms.map((room) => [room.room_ref, room]));
|
package/dist/rows.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type HeldValue } from '@agentshouse/mdmodel';
|
|
1
|
+
import { type Definition, type HeldValue } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { SavedFacts } from './adapter.js';
|
|
3
3
|
import { type Composition } from './collection.js';
|
|
4
4
|
import type { PlanReach } from './query.js';
|
|
@@ -7,6 +7,7 @@ type HeldLink = {
|
|
|
7
7
|
readonly kind: LinkKind;
|
|
8
8
|
readonly keys: string;
|
|
9
9
|
readonly places: string;
|
|
10
|
+
readonly handle: string | null;
|
|
10
11
|
readonly target: string;
|
|
11
12
|
readonly field: string;
|
|
12
13
|
};
|
|
@@ -22,19 +23,25 @@ export type Held = {
|
|
|
22
23
|
readonly fields: Readonly<Record<string, unknown>> | null;
|
|
23
24
|
readonly links: readonly string[];
|
|
24
25
|
};
|
|
26
|
+
export type Sought = {
|
|
27
|
+
readonly type: string;
|
|
28
|
+
readonly field: string;
|
|
29
|
+
readonly value: string;
|
|
30
|
+
};
|
|
25
31
|
export type Derived = {
|
|
26
32
|
readonly values: readonly HeldValue[];
|
|
27
33
|
readonly links: readonly HeldLink[];
|
|
34
|
+
readonly unique: readonly Sought[];
|
|
28
35
|
};
|
|
29
36
|
export declare function documentKey(room: string, path: string): string;
|
|
30
37
|
export declare function roomOfKey(key: string): string;
|
|
31
38
|
export declare function roomsOfReach(reach: PlanReach): ReadonlySet<string>;
|
|
32
39
|
export declare function pathOfKey(key: string): string;
|
|
33
|
-
export declare function markdownPath(path: string): boolean;
|
|
34
40
|
export declare function folderOf(path: string): string;
|
|
35
41
|
export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
|
|
36
42
|
export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
|
|
37
43
|
export declare function heldOf(path: string, content: string | null, facts: SavedFacts | null): Held;
|
|
44
|
+
export declare function uniqueValues(type: string, fields: Readonly<Record<string, unknown>>, definition: Definition | undefined): Sought[];
|
|
38
45
|
export declare function derived(path: string, held: Held, composition: Composition): Derived;
|
|
39
46
|
export {};
|
|
40
47
|
//# 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":"AAAA,OAAO,EAML,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UA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,EAAE,WAAW,GAAG,OAAO,CAiBnF"}
|
package/dist/rows.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { byCodePoint, documentFacts, indexed, parse } from '@agentshouse/mdmodel';
|
|
1
|
+
import { byCodePoint, documentFacts, fieldKey, indexed, parse, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { definitionsAt, governing } from './collection.js';
|
|
3
3
|
function keyOf(...parts) {
|
|
4
4
|
return `${parts.join('\u0000')}\u0000`;
|
|
@@ -16,7 +16,7 @@ export function pathOfKey(key) {
|
|
|
16
16
|
return key.split('\u0000')[2];
|
|
17
17
|
}
|
|
18
18
|
const MARKDOWN = /\.md$/iu;
|
|
19
|
-
|
|
19
|
+
function markdownPath(path) {
|
|
20
20
|
return MARKDOWN.test(path);
|
|
21
21
|
}
|
|
22
22
|
export function folderOf(path) {
|
|
@@ -62,17 +62,30 @@ export function heldOf(path, content, facts) {
|
|
|
62
62
|
? { type: facts.type, fields: facts.fields, links: facts.links }
|
|
63
63
|
: { type: null, fields: null, links: facts.links };
|
|
64
64
|
}
|
|
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
|
+
});
|
|
72
|
+
}
|
|
65
73
|
export function derived(path, held, composition) {
|
|
66
74
|
const stored = held.links.map((target) => ({
|
|
67
75
|
kind: 'link',
|
|
68
76
|
keys: '',
|
|
69
77
|
places: '',
|
|
78
|
+
handle: null,
|
|
70
79
|
target,
|
|
71
80
|
field: '',
|
|
72
81
|
}));
|
|
73
82
|
if (held.type === null || held.fields === null)
|
|
74
|
-
return { values: [], links: stored };
|
|
83
|
+
return { values: [], links: stored, unique: [] };
|
|
75
84
|
const definition = definitionsAt(composition, path)(held.type);
|
|
76
85
|
const { values, links: fields } = indexed(path, held.fields, definition);
|
|
77
|
-
return {
|
|
86
|
+
return {
|
|
87
|
+
values,
|
|
88
|
+
links: [...fields, ...stored],
|
|
89
|
+
unique: uniqueValues(held.type, held.fields, definition),
|
|
90
|
+
};
|
|
78
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,CAgCjF;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,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
|
+
}
|
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
|
@@ -19,10 +19,13 @@ export type Runtime = {
|
|
|
19
19
|
readonly recovery: Recovery;
|
|
20
20
|
readonly retries: Retries;
|
|
21
21
|
readonly shell: RuntimeShell;
|
|
22
|
-
readonly
|
|
22
|
+
readonly savesLocally: (locator: string) => boolean;
|
|
23
23
|
readonly roomTypes: Parameters<typeof schemaTypes>[1];
|
|
24
24
|
readonly builtIn: ModelState;
|
|
25
25
|
readonly typedPaths: readonly TypedPath[];
|
|
26
|
+
readonly renamedActions: ReadonlyMap<string, string>;
|
|
27
|
+
readonly rewrittenInputs: ReadonlyMap<string, (input: unknown) => unknown>;
|
|
28
|
+
readonly keptInput: (input: unknown) => unknown;
|
|
26
29
|
readonly writeRule: (declaration: RoomDeclaration) => WriteRule;
|
|
27
30
|
readonly build: string;
|
|
28
31
|
readonly conversations: LiveConversations;
|
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,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,MAAM,OAAO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AAI,CAAC,CAAC;CACxD,CAAC"}
|
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,EAwBL,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,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAwB,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAOL,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AAIzB,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC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C,CAAC;AAEF,MAAM,MAAM,QAAQ,GAChB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAA;CAAE,GAC3D;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;CACxC,CAAC;AAmBN,MAAM,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AAsM9F,wBAAiB,iBAAiB,CAChC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,YAAY,GACpB,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,CAOtC;AAsED,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;AA8uCD,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,6 +1,6 @@
|
|
|
1
|
-
import { apply, ARRAY_INDEX, ATTACHMENT, create, links, parse, pointerSegments, references, relative, relativize, retarget, roomReferences, serialize, target, } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, ARRAY_INDEX, ATTACHMENT, create, links, parse, pointerSegments, references, relative, relativePath, relativizable, relativize, retarget, roomReferences, serialize, target, writeRoomPath, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { immutable, isPart, leaving, queuedFile, departure, } from './change.js';
|
|
3
|
-
import { collectionOf, definitionsAt, documentsOf, governing,
|
|
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';
|
|
@@ -209,20 +209,22 @@ function rewritten(path, document, changes, definition) {
|
|
|
209
209
|
return [{ kind: 'replace', path, content: serialize(after) }];
|
|
210
210
|
return partsBetween(path, document, after);
|
|
211
211
|
}
|
|
212
|
-
function roomPathOf(handle, path) {
|
|
213
|
-
return `/rooms/${handle}/${path}`;
|
|
214
|
-
}
|
|
215
212
|
function* leavingRewritten(batch, visible) {
|
|
216
213
|
const between = batch.between;
|
|
217
214
|
if (between === undefined)
|
|
218
215
|
return batch;
|
|
219
|
-
const
|
|
216
|
+
const { handle } = between.destination;
|
|
217
|
+
const moved = new Map(between.moves.map(({ path, to }) => [path, to]));
|
|
220
218
|
const derived = [];
|
|
221
219
|
for (const [path, document] of yield* documentsOf(visible.collection)) {
|
|
222
220
|
if (moved.has(path))
|
|
223
221
|
continue;
|
|
224
222
|
const definition = definitionsAt(visible.collection.composition, path)(document.type);
|
|
225
|
-
|
|
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));
|
|
226
228
|
yield ROW_WEIGHT + visible.collection.text[path].length;
|
|
227
229
|
}
|
|
228
230
|
if (derived.length === 0)
|
|
@@ -506,7 +508,7 @@ function* exceeding(limits, changes, effective, resulting) {
|
|
|
506
508
|
return null;
|
|
507
509
|
}
|
|
508
510
|
function shellRelative(text, path, handle, definition) {
|
|
509
|
-
if (!text
|
|
511
|
+
if (!relativizable(text, handle))
|
|
510
512
|
return null;
|
|
511
513
|
const parsed = parse(text, path, definition);
|
|
512
514
|
if (!parsed.ok)
|
|
@@ -515,7 +517,7 @@ function shellRelative(text, path, handle, definition) {
|
|
|
515
517
|
return result.outcome === 'applied' && result.document.content !== text ? result.document : null;
|
|
516
518
|
}
|
|
517
519
|
function relativeField(path, name, value, handle, definition) {
|
|
518
|
-
if (definition === undefined || !JSON.stringify(value ?? null)
|
|
520
|
+
if (definition === undefined || !relativizable(JSON.stringify(value ?? null), handle))
|
|
519
521
|
return value;
|
|
520
522
|
const held = apply(create(definition.name, definition), [{ kind: 'field', name, value, prior: undefined }], definition);
|
|
521
523
|
if (held.outcome !== 'applied')
|
|
@@ -817,8 +819,8 @@ function* limiting(queue, batch, limits, state) {
|
|
|
817
819
|
const limited = yield* exceeding(limits, batch.changes, rewritten.changes, yield* state(queue.slice(0, at + 1)));
|
|
818
820
|
return limited?.refusal ?? null;
|
|
819
821
|
}
|
|
820
|
-
function typedContent(content) {
|
|
821
|
-
return content !== undefined &&
|
|
822
|
+
function typedContent(composition, path, content) {
|
|
823
|
+
return (content !== undefined && (typeAt(composition, path, parse(content)) ?? UNTYPED) !== UNTYPED);
|
|
822
824
|
}
|
|
823
825
|
function touchedLibrary(resulting, touched, composition) {
|
|
824
826
|
const entries = touched
|
|
@@ -838,7 +840,7 @@ function touchedLibrary(resulting, touched, composition) {
|
|
|
838
840
|
if (binaries.has(path))
|
|
839
841
|
known.set(path, { type: undefined, binary: true });
|
|
840
842
|
else if (content !== undefined && content !== null) {
|
|
841
|
-
const type =
|
|
843
|
+
const type = typeAt(composition, path, parse(content, path, definitionsAt(composition, path)));
|
|
842
844
|
if (type !== undefined)
|
|
843
845
|
known.set(path, { type, binary: false });
|
|
844
846
|
await pace(content.length + ROW_WEIGHT);
|
|
@@ -858,7 +860,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
858
860
|
for (const path of touched) {
|
|
859
861
|
const before = visible.documents[path];
|
|
860
862
|
const after = resulting.documents[path];
|
|
861
|
-
if (typedContent(before) || typedContent(after))
|
|
863
|
+
if (typedContent(composition, path, before) || typedContent(composition, path, after))
|
|
862
864
|
typedPaths.push(path);
|
|
863
865
|
await pace((before?.length ?? 0) + (after?.length ?? 0) + ROW_WEIGHT);
|
|
864
866
|
}
|
|
@@ -889,7 +891,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
889
891
|
};
|
|
890
892
|
}
|
|
891
893
|
function placed(reference) {
|
|
892
|
-
const key =
|
|
894
|
+
const key = writeRoomPath(reference);
|
|
893
895
|
if (reference.kind === 'link')
|
|
894
896
|
return `link ${key}`;
|
|
895
897
|
const pointer = reference.pointer
|
|
@@ -905,7 +907,7 @@ function roomReferencesIn(path, content, composition) {
|
|
|
905
907
|
const parsed = parse(content, path, definitions);
|
|
906
908
|
if (!parsed.ok)
|
|
907
909
|
return [];
|
|
908
|
-
return roomReferences(parsed.document, definitions(parsed.document.type));
|
|
910
|
+
return roomReferences(parsed.document, { path }, definitions(parsed.document.type));
|
|
909
911
|
}
|
|
910
912
|
function* admittedRooms(changes, visible, resulting, composition) {
|
|
911
913
|
const from = new Map();
|
|
@@ -995,7 +997,9 @@ function arrivingText(path, to, source, moved) {
|
|
|
995
997
|
const at = moved.get(named);
|
|
996
998
|
if (at !== undefined)
|
|
997
999
|
return target(to, href) === at ? undefined : relative(to, at);
|
|
998
|
-
return heldAt(source.visible, named)
|
|
1000
|
+
return heldAt(source.visible, named)
|
|
1001
|
+
? relativePath({ path: to }, { handle: source.handle, path: named })
|
|
1002
|
+
: undefined;
|
|
999
1003
|
});
|
|
1000
1004
|
if (changes.length === 0)
|
|
1001
1005
|
return content;
|
|
@@ -1097,7 +1101,7 @@ function unreadable(saved, visible, composition) {
|
|
|
1097
1101
|
const path = saved.find(({ path: at, parts }) => (parts.fields !== undefined ||
|
|
1098
1102
|
parts.sections !== undefined ||
|
|
1099
1103
|
parts.preamble !== undefined) &&
|
|
1100
|
-
typedContent(visible.documents[at]) &&
|
|
1104
|
+
typedContent(composition, at, visible.documents[at]) &&
|
|
1101
1105
|
governing(composition, at).status === 'unavailable')?.path;
|
|
1102
1106
|
return path === undefined ? null : refuse('model-unavailable', path);
|
|
1103
1107
|
}
|
package/dist/saves.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ChangeBatch, type WrittenBy } from './change.js';
|
|
2
2
|
import type { ConversationFiles } from './conversation.js';
|
|
3
|
-
import { type AttachAnswer, type
|
|
3
|
+
import { type AttachAnswer, type AttachmentLinkAnswer, type HeldAttachmentAnswer, type HeldShownAnswer } from './outcome.js';
|
|
4
4
|
import { type RoomDraftParts } from './room-draft.js';
|
|
5
5
|
import type { Runtime } from './runtime.js';
|
|
6
6
|
import { type SaveRefusal } from './save.js';
|
|
@@ -20,8 +20,8 @@ export type SavedParts = {
|
|
|
20
20
|
readonly parts: RoomDraftParts;
|
|
21
21
|
};
|
|
22
22
|
export type AttachmentSurface = {
|
|
23
|
-
read(room: string, path: string, revision?: string): Promise<
|
|
24
|
-
link(room: string, path: string, revision?: string): Promise<
|
|
23
|
+
read(room: string, path: string, revision?: string): Promise<HeldAttachmentAnswer>;
|
|
24
|
+
link(room: string, path: string, revision?: string): Promise<AttachmentLinkAnswer>;
|
|
25
25
|
show(room: string, path: string, revision?: string): Promise<HeldShownAnswer>;
|
|
26
26
|
attach(room: string, file: File): Promise<AttachAnswer>;
|
|
27
27
|
part(file: string, part: number): Promise<Uint8Array | null>;
|
package/dist/saves.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;AAKx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