narrarium-engine 0.1.9 → 0.1.11
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 +252 -22
- package/dist/ai/budget.d.ts +18 -2
- package/dist/ai/budget.d.ts.map +1 -1
- package/dist/ai/budget.js +9 -2
- package/dist/ai/budget.js.map +1 -1
- package/dist/ai/fetch-client.d.ts +13 -6
- package/dist/ai/fetch-client.d.ts.map +1 -1
- package/dist/ai/fetch-client.js +26 -3
- package/dist/ai/fetch-client.js.map +1 -1
- package/dist/ai/request.d.ts +1 -1
- package/dist/ai/request.d.ts.map +1 -1
- package/dist/ai/request.js +31 -5
- package/dist/ai/request.js.map +1 -1
- package/dist/ai/routing.d.ts.map +1 -1
- package/dist/ai/routing.js +1 -1
- package/dist/ai/routing.js.map +1 -1
- package/dist/ai/types.d.ts +29 -2
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/types.js +5 -2
- package/dist/ai/types.js.map +1 -1
- package/dist/autopilot/chapter-state.d.ts +19 -0
- package/dist/autopilot/chapter-state.d.ts.map +1 -0
- package/dist/autopilot/chapter-state.js +31 -0
- package/dist/autopilot/chapter-state.js.map +1 -0
- package/dist/autopilot/errors.d.ts +2 -1
- package/dist/autopilot/errors.d.ts.map +1 -1
- package/dist/autopilot/errors.js +17 -1
- package/dist/autopilot/errors.js.map +1 -1
- package/dist/autopilot/estimate-math.d.ts +19 -0
- package/dist/autopilot/estimate-math.d.ts.map +1 -0
- package/dist/autopilot/estimate-math.js +74 -0
- package/dist/autopilot/estimate-math.js.map +1 -0
- package/dist/autopilot/estimate-texts.d.ts +40 -0
- package/dist/autopilot/estimate-texts.d.ts.map +1 -0
- package/dist/autopilot/estimate-texts.js +130 -0
- package/dist/autopilot/estimate-texts.js.map +1 -0
- package/dist/autopilot/estimate.d.ts +303 -0
- package/dist/autopilot/estimate.d.ts.map +1 -0
- package/dist/autopilot/estimate.js +887 -0
- package/dist/autopilot/estimate.js.map +1 -0
- package/dist/autopilot/frozen.d.ts +1 -4
- package/dist/autopilot/frozen.d.ts.map +1 -1
- package/dist/autopilot/frozen.js +13 -25
- package/dist/autopilot/frozen.js.map +1 -1
- package/dist/autopilot/outline-change.d.ts +69 -0
- package/dist/autopilot/outline-change.d.ts.map +1 -0
- package/dist/autopilot/outline-change.js +42 -0
- package/dist/autopilot/outline-change.js.map +1 -0
- package/dist/autopilot/outline-check.d.ts +1 -0
- package/dist/autopilot/outline-check.d.ts.map +1 -1
- package/dist/autopilot/outline-check.js +9 -6
- package/dist/autopilot/outline-check.js.map +1 -1
- package/dist/autopilot/outline-compose.d.ts +203 -0
- package/dist/autopilot/outline-compose.d.ts.map +1 -0
- package/dist/autopilot/outline-compose.js +492 -0
- package/dist/autopilot/outline-compose.js.map +1 -0
- package/dist/autopilot/presets.d.ts +36 -0
- package/dist/autopilot/presets.d.ts.map +1 -0
- package/dist/autopilot/presets.js +54 -0
- package/dist/autopilot/presets.js.map +1 -0
- package/dist/autopilot/runner.d.ts +55 -5
- package/dist/autopilot/runner.d.ts.map +1 -1
- package/dist/autopilot/runner.js +252 -20
- package/dist/autopilot/runner.js.map +1 -1
- package/dist/autopilot/session.d.ts +61 -9
- package/dist/autopilot/session.d.ts.map +1 -1
- package/dist/autopilot/session.js +140 -17
- package/dist/autopilot/session.js.map +1 -1
- package/dist/autopilot/speed.d.ts +30 -0
- package/dist/autopilot/speed.d.ts.map +1 -0
- package/dist/autopilot/speed.js +71 -0
- package/dist/autopilot/speed.js.map +1 -0
- package/dist/autopilot/state.d.ts +15 -2
- package/dist/autopilot/state.d.ts.map +1 -1
- package/dist/autopilot/state.js +67 -2
- package/dist/autopilot/state.js.map +1 -1
- package/dist/autopilot/types.d.ts +104 -9
- package/dist/autopilot/types.d.ts.map +1 -1
- package/dist/autopilot/types.js +14 -2
- package/dist/autopilot/types.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/server/client.d.ts +52 -6
- package/dist/server/client.d.ts.map +1 -1
- package/dist/server/client.js +93 -11
- package/dist/server/client.js.map +1 -1
- package/dist/server/protocol.d.ts +125 -1
- package/dist/server/protocol.d.ts.map +1 -1
- package/dist/server/protocol.js +47 -0
- package/dist/server/protocol.js.map +1 -1
- package/dist/util/text.d.ts +6 -0
- package/dist/util/text.d.ts.map +1 -1
- package/dist/util/text.js +21 -0
- package/dist/util/text.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { outlineChanges, parseOutline, readOutlineBook, readOutlineChapter, } from "../book/outline.js";
|
|
2
|
+
import { OUTLINE_BOOK_FILE, outlineChapterPath, parseOutlineChapterPath } from "../book/paths.js";
|
|
3
|
+
import { sha256Hex } from "../util/hash.js";
|
|
4
|
+
/**
|
|
5
|
+
* A series of edits of the outline (the Scaletta) as the files of one commit. One function for every host that makes the author's edits in a row: the web app's Outline
|
|
6
|
+
* page and Copilot, the personal server's MCP tool.
|
|
7
|
+
*
|
|
8
|
+
* The engine makes every edit (`outlineChanges`): the numbering, the format, the author as the writer of every entry it writes. What it leaves to its caller, and this
|
|
9
|
+
* does:
|
|
10
|
+
*
|
|
11
|
+
* - Several edits in a row. Each is made on the outline the one before left (a `number` is the number the chapter has at that point of the series), and the files are
|
|
12
|
+
* written once, with their final text; a file that comes back to what it was is left alone.
|
|
13
|
+
* - The identity of every entry, followed through the renumbering. A client reads an entry and gets the hash of its file; the text of that entry is replaced, or the entry
|
|
14
|
+
* removed, only if the hash is still the file's. In a series the entry is no longer where it was, so the hash that was read is checked against the entry it was of,
|
|
15
|
+
* wherever the edits before have put it (`OutlineSeriesEdit.expectedHash`).
|
|
16
|
+
* - Only the files that are needed. An outline has no maximum, and an insert at its head renames every entry: but an update of one entry reads one file. An entry is known
|
|
17
|
+
* by its path and hash (`OutlineIndex`, from the list of the book's files) and read only when an edit is about to rewrite it.
|
|
18
|
+
* - Limits a caller chooses: how many edits a series has, how many files it may change (checked as the series goes).
|
|
19
|
+
*
|
|
20
|
+
* Pure: nothing is written and no file is read but through `OutlineSource.read`. The files come out as `BookFileChange`s, each expecting the file as it was read, and a commit
|
|
21
|
+
* through a store refuses the lot if any of them changed since.
|
|
22
|
+
*/
|
|
23
|
+
/** Edits one series may make, unless the caller says another number. */
|
|
24
|
+
export const OUTLINE_COMPOSE_MAX_EDITS = 50;
|
|
25
|
+
/** Files one series may change, unless the caller says another number: an insert at the head of a long outline renames all of it, and that is for a place where the author sees it and can undo it. */
|
|
26
|
+
export const OUTLINE_COMPOSE_MAX_FILES = 1000;
|
|
27
|
+
/**
|
|
28
|
+
* Whether an edit replaces what someone must have read: the text of an entry that exists, an entry that is deleted, the description of the book. The rule of a caller that
|
|
29
|
+
* never overwrites what changed meanwhile (`OutlineComposeOptions.requireHash`): a title or a ghostwriter changes no text, and a new entry has no file to compare.
|
|
30
|
+
*/
|
|
31
|
+
export function outlineEditNeedsHash(edit) {
|
|
32
|
+
switch (edit.kind) {
|
|
33
|
+
case "remove":
|
|
34
|
+
return true;
|
|
35
|
+
case "update":
|
|
36
|
+
return edit.entry.body !== undefined;
|
|
37
|
+
case "book":
|
|
38
|
+
return edit.body !== undefined;
|
|
39
|
+
default:
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Where the entry numbered `number` is after `edit`, as the engine places the files; `null` when the edit deletes it. The one rule of the renumbering: the series follows
|
|
45
|
+
* the entries with it, and a page that keeps what the author typed in an entry that moved with it.
|
|
46
|
+
*/
|
|
47
|
+
export function remapOutlineNumber(edit, number) {
|
|
48
|
+
switch (edit.kind) {
|
|
49
|
+
case "insert":
|
|
50
|
+
return number >= edit.at ? number + 1 : number;
|
|
51
|
+
case "move":
|
|
52
|
+
if (number === edit.from)
|
|
53
|
+
return edit.to;
|
|
54
|
+
if (edit.from < edit.to && number > edit.from && number <= edit.to)
|
|
55
|
+
return number - 1;
|
|
56
|
+
if (edit.from > edit.to && number >= edit.to && number < edit.from)
|
|
57
|
+
return number + 1;
|
|
58
|
+
return number;
|
|
59
|
+
case "remove":
|
|
60
|
+
if (number === edit.number)
|
|
61
|
+
return null;
|
|
62
|
+
return edit.renumber && number > edit.number ? number - 1 : number;
|
|
63
|
+
default:
|
|
64
|
+
return number;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A series that cannot be made: nothing was written, for nothing is written here. The `code` is one of `OutlineComposeErrorCode`, and the details say which edit and
|
|
69
|
+
* which file, so that a host words it in its own way (the message is English, and names no tool).
|
|
70
|
+
*/
|
|
71
|
+
export class OutlineComposeError extends Error {
|
|
72
|
+
code;
|
|
73
|
+
constructor(code, message, details = {}) {
|
|
74
|
+
super(message);
|
|
75
|
+
this.code = code;
|
|
76
|
+
this.name = "OutlineComposeError";
|
|
77
|
+
for (const [key, value] of Object.entries(details))
|
|
78
|
+
if (value !== undefined)
|
|
79
|
+
Object.defineProperty(this, key, { value, enumerable: true, writable: false, configurable: true });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// ─── What is known of the outline, and when it is read ─────────────────────
|
|
83
|
+
/** Entries read at once when an edit has to read many. */
|
|
84
|
+
const READ_BATCH = 64;
|
|
85
|
+
const stubEntry = (file) => ({ number: file.number, path: file.path, hash: file.hash, title: "", body: "", origin: "author", contentDigest: "", intact: false, frontmatter: {} });
|
|
86
|
+
const stubBook = (file) => ({ path: file.path, hash: file.hash, title: "", body: "", origin: "author", contentDigest: "", intact: false, frontmatter: {} });
|
|
87
|
+
const isOutlineFile = (path) => path === OUTLINE_BOOK_FILE || parseOutlineChapterPath(path) !== null;
|
|
88
|
+
const goneError = (path, index) => new OutlineComposeError("conflict", `${path} changed since the outline was listed: it is gone now.`, { path, reason: "gone", ...(index === undefined ? {} : { index }) });
|
|
89
|
+
async function load(source) {
|
|
90
|
+
const chapters = new Map(source.index.chapters.map((file) => [file.number, stubEntry(file)]));
|
|
91
|
+
const hashes = new Map(source.index.chapters.map((file) => [file.path, file.hash]));
|
|
92
|
+
if (source.index.book)
|
|
93
|
+
hashes.set(source.index.book.path, source.index.book.hash);
|
|
94
|
+
const listed = source.paths ? [...source.paths].filter(isOutlineFile) : [...source.index.chapters.map((file) => file.path), ...(source.index.book ? [source.index.book.path] : [])];
|
|
95
|
+
const odd = [...listed, ...source.index.chapters.map((file) => file.path)].some((path) => path !== OUTLINE_BOOK_FILE && parseOutlineChapterPath(path)?.canonical === false);
|
|
96
|
+
const loaded = {
|
|
97
|
+
source,
|
|
98
|
+
originals: new Map(chapters),
|
|
99
|
+
chapters,
|
|
100
|
+
book: source.index.book ? stubBook(source.index.book) : null,
|
|
101
|
+
unloaded: new Set(source.index.chapters.map((file) => file.path)),
|
|
102
|
+
bookUnloaded: Boolean(source.index.book),
|
|
103
|
+
hashes,
|
|
104
|
+
contents: new Map(),
|
|
105
|
+
whole: odd,
|
|
106
|
+
files: new Map(),
|
|
107
|
+
};
|
|
108
|
+
if (odd)
|
|
109
|
+
await readWhole(loaded, listed);
|
|
110
|
+
return loaded;
|
|
111
|
+
}
|
|
112
|
+
async function readAll(source, paths, index) {
|
|
113
|
+
const found = [];
|
|
114
|
+
for (let start = 0; start < paths.length; start += READ_BATCH) {
|
|
115
|
+
const batch = paths.slice(start, start + READ_BATCH);
|
|
116
|
+
const reads = await Promise.all(batch.map((path) => source.read(path)));
|
|
117
|
+
reads.forEach((read, position) => {
|
|
118
|
+
if (!read)
|
|
119
|
+
throw goneError(batch[position], index);
|
|
120
|
+
found.push(read);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return found;
|
|
124
|
+
}
|
|
125
|
+
/** The outline read whole, the way the engine reads it: every file, the entries it leaves out because another file has their number too. */
|
|
126
|
+
async function readWhole(loaded, paths) {
|
|
127
|
+
for (const read of await readAll(loaded.source, [...new Set(paths)])) {
|
|
128
|
+
loaded.files.set(read.path, { content: read.content, hash: read.hash });
|
|
129
|
+
loaded.contents.set(read.path, read.content);
|
|
130
|
+
loaded.hashes.set(read.path, read.hash);
|
|
131
|
+
}
|
|
132
|
+
const parsed = await parseOutline([...loaded.files].map(([path, file]) => ({ path, ...file })));
|
|
133
|
+
loaded.chapters = new Map(parsed.chapters.map((entry) => [entry.number, entry]));
|
|
134
|
+
loaded.originals = new Map(loaded.chapters);
|
|
135
|
+
loaded.book = parsed.book;
|
|
136
|
+
loaded.unloaded.clear();
|
|
137
|
+
loaded.bookUnloaded = false;
|
|
138
|
+
}
|
|
139
|
+
/** Read the entries from `from` to `to` that are not read yet: the ones an edit is about to rewrite. */
|
|
140
|
+
async function ensureRange(loaded, from, to, index) {
|
|
141
|
+
if (loaded.whole)
|
|
142
|
+
return;
|
|
143
|
+
const wanted = [...loaded.chapters.values()].filter((entry) => entry.number >= from && entry.number <= to && loaded.unloaded.has(entry.path));
|
|
144
|
+
for (let start = 0; start < wanted.length; start += READ_BATCH) {
|
|
145
|
+
const batch = wanted.slice(start, start + READ_BATCH);
|
|
146
|
+
const reads = await readAll(loaded.source, batch.map((entry) => entry.path), index);
|
|
147
|
+
for (let position = 0; position < batch.length; position += 1) {
|
|
148
|
+
const { number, path } = batch[position];
|
|
149
|
+
const read = reads[position];
|
|
150
|
+
const { entry } = await readOutlineChapter(path, number, read.content, read.hash);
|
|
151
|
+
loaded.chapters.set(number, entry);
|
|
152
|
+
loaded.originals.set(number, entry);
|
|
153
|
+
loaded.contents.set(path, read.content);
|
|
154
|
+
loaded.hashes.set(path, read.hash);
|
|
155
|
+
loaded.unloaded.delete(path);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function ensureBook(loaded, index) {
|
|
160
|
+
if (!loaded.bookUnloaded || !loaded.book)
|
|
161
|
+
return;
|
|
162
|
+
const [read] = await readAll(loaded.source, [loaded.book.path], index);
|
|
163
|
+
const { book } = await readOutlineBook(read.content, read.hash);
|
|
164
|
+
loaded.book = book;
|
|
165
|
+
loaded.contents.set(book.path, read.content);
|
|
166
|
+
loaded.hashes.set(book.path, read.hash);
|
|
167
|
+
loaded.bookUnloaded = false;
|
|
168
|
+
}
|
|
169
|
+
/** Runs of consecutive entries that moved together: `{ from, to, count }` means `count` entries from chapter `from` are now from chapter `to`. */
|
|
170
|
+
function runs(pairs) {
|
|
171
|
+
const found = [];
|
|
172
|
+
for (const [from, to] of [...pairs].sort(([left], [right]) => left - right)) {
|
|
173
|
+
const last = found.at(-1);
|
|
174
|
+
if (last && from === last.from + last.count && to === last.to + last.count)
|
|
175
|
+
last.count += 1;
|
|
176
|
+
else
|
|
177
|
+
found.push({ from, to, count: 1 });
|
|
178
|
+
}
|
|
179
|
+
return found;
|
|
180
|
+
}
|
|
181
|
+
/** The number an entry had when the series began, as a step says it (nothing for an entry the series made). */
|
|
182
|
+
const originOf = (live) => (live && live.origin !== null ? { origin: live.origin } : {});
|
|
183
|
+
const fieldsOfEntry = (entry) => ["title", "body", "ghostwriter"].filter((key) => entry[key] !== undefined);
|
|
184
|
+
/** The chapters from 1 to the last that have no entry, as runs (`2-3,6`): only to tell whether two outlines have the same gaps. */
|
|
185
|
+
function gapsOf(numbers) {
|
|
186
|
+
const runsOfGaps = [];
|
|
187
|
+
let expected = 1;
|
|
188
|
+
for (const number of [...numbers].sort((left, right) => left - right)) {
|
|
189
|
+
if (number > expected)
|
|
190
|
+
runsOfGaps.push(`${expected}-${number - 1}`);
|
|
191
|
+
expected = Math.max(expected, number + 1);
|
|
192
|
+
}
|
|
193
|
+
return runsOfGaps.join(",");
|
|
194
|
+
}
|
|
195
|
+
const byNumber = (left, right) => left.number - right.number;
|
|
196
|
+
const byPath = (left, right) => (left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
|
|
197
|
+
/** What an edit is, for a message: `update chapter 3`, `remove chapter 9`, `move chapter 5 to 7`, `the description of the book`. */
|
|
198
|
+
function describe(edit) {
|
|
199
|
+
switch (edit.kind) {
|
|
200
|
+
case "move":
|
|
201
|
+
return `move chapter ${edit.from} to ${edit.to}`;
|
|
202
|
+
case "remove":
|
|
203
|
+
case "update":
|
|
204
|
+
return `${edit.kind} chapter ${edit.number}`;
|
|
205
|
+
case "book":
|
|
206
|
+
return "update the description of the book";
|
|
207
|
+
case "insert":
|
|
208
|
+
return `insert chapter ${edit.at}`;
|
|
209
|
+
default:
|
|
210
|
+
return edit.kind;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** The edits of a series, looked at before anything is read: each is an object of a kind the engine has, and a hash only where there is a file to compare with. */
|
|
214
|
+
function checkSeries(edits) {
|
|
215
|
+
edits.forEach((edit, index) => {
|
|
216
|
+
if (typeof edit !== "object" || edit === null || Array.isArray(edit))
|
|
217
|
+
throw new OutlineComposeError("invalid_edit", `edits[${index}] must be an object: an edit has a kind and what the kind takes.`, { index, edit });
|
|
218
|
+
const { kind, expectedHash } = edit;
|
|
219
|
+
if (kind !== "append" && kind !== "insert" && kind !== "move" && kind !== "remove" && kind !== "update" && kind !== "book") {
|
|
220
|
+
throw new OutlineComposeError("invalid_edit", `edits[${index}]: ${typeof kind === "string" ? `«${kind.slice(0, 40)}»` : "that"} is not a kind of edit; the kinds are append, insert, move, remove, update and book.`, { index, edit });
|
|
221
|
+
}
|
|
222
|
+
if (expectedHash !== undefined && (kind === "append" || kind === "insert" || kind === "move")) {
|
|
223
|
+
throw new OutlineComposeError("invalid_edit", `edits[${index}] (${kind}): ${kind === "move" ? "a move changes no text" : `${kind === "append" ? "an appended" : "an inserted"} chapter is a new entry, which has no file yet`}, so there is no expectedHash to give.`, { index, edit });
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Make `edits` on the outline `source` describes, in order, and answer the files of one commit. Throws an `OutlineComposeError` for an edit that cannot be made
|
|
229
|
+
* (`not_found`, `invalid_edit`), one whose hash is missing where the caller's rule asks for one (`expected_hash_required`) or is not the entry's (`conflict`), a file that is
|
|
230
|
+
* gone when it is read (`conflict`), and a series that is too long or would change too many files (`too_many_edits`, `too_many_files`). Nothing was written then, for nothing
|
|
231
|
+
* is written here.
|
|
232
|
+
*/
|
|
233
|
+
export async function composeOutlineEdits(source, edits, options = {}) {
|
|
234
|
+
const maxEdits = options.maxEdits ?? OUTLINE_COMPOSE_MAX_EDITS;
|
|
235
|
+
const maxFiles = options.maxFiles ?? OUTLINE_COMPOSE_MAX_FILES;
|
|
236
|
+
const missing = options.missing ?? "throw";
|
|
237
|
+
const ghostwriters = options.ghostwriters;
|
|
238
|
+
if (edits.length > maxEdits)
|
|
239
|
+
throw new OutlineComposeError("too_many_edits", `A series makes at most ${maxEdits} edits: ${edits.length} were given.`, { count: edits.length, limit: maxEdits });
|
|
240
|
+
checkSeries(edits);
|
|
241
|
+
const loaded = await load(source);
|
|
242
|
+
let lives = new Map([...loaded.chapters.keys()].map((number) => [number, { origin: number }]));
|
|
243
|
+
const verified = new Set();
|
|
244
|
+
const finalContent = new Map();
|
|
245
|
+
const removed = [];
|
|
246
|
+
const warnings = new Map();
|
|
247
|
+
const steps = [];
|
|
248
|
+
const bookExisted = loaded.book !== null;
|
|
249
|
+
let bookTouched = false;
|
|
250
|
+
let gap;
|
|
251
|
+
const outline = () => ({ book: loaded.book, chapters: [...loaded.chapters.values()].sort(byNumber), warnings: [] });
|
|
252
|
+
const last = () => Math.max(0, ...loaded.chapters.keys());
|
|
253
|
+
/** The identities after an edit: each entry is where the engine put it, and an entry the edit deleted is gone. */
|
|
254
|
+
const follow = (edit) => {
|
|
255
|
+
lives = new Map([...lives].flatMap(([number, live]) => {
|
|
256
|
+
const now = remapOutlineNumber(edit, number);
|
|
257
|
+
return now === null ? [] : [[now, live]];
|
|
258
|
+
}));
|
|
259
|
+
};
|
|
260
|
+
/** The files the series has changed so far: what it wrote last, leaving alone what came back to what it was and what was made and deleted in the same series. */
|
|
261
|
+
function netChanges() {
|
|
262
|
+
const changes = [];
|
|
263
|
+
for (const [path, content] of finalContent) {
|
|
264
|
+
const known = loaded.hashes.get(path);
|
|
265
|
+
if (content === null) {
|
|
266
|
+
if (known !== undefined)
|
|
267
|
+
changes.push({ path, content: null, expectedHash: known });
|
|
268
|
+
}
|
|
269
|
+
else if (known === undefined || loaded.contents.get(path) !== content) {
|
|
270
|
+
changes.push({ path, content, expectedHash: known ?? null });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return changes.sort(byPath);
|
|
274
|
+
}
|
|
275
|
+
const tooMany = (count, index) => new OutlineComposeError("too_many_files", `The series would change at least ${count} files of the outline, and at most ${maxFiles} may change: nothing was written.`, { count, limit: maxFiles, ...(index === undefined ? {} : { index }) });
|
|
276
|
+
/** The engine makes the edit; the files it writes become the outline the next edit works on. */
|
|
277
|
+
async function make(edit, index, reachesGap = true) {
|
|
278
|
+
const { expectedHash: _hash, ...plain } = edit;
|
|
279
|
+
const result = outlineChanges({ outline: outline(), edit: plain, ghostwriters });
|
|
280
|
+
for (const warning of result.warnings) {
|
|
281
|
+
if (warning.code !== "gap")
|
|
282
|
+
warnings.set(`${warning.code}|${warning.path ?? ""}|${warning.message}`, warning);
|
|
283
|
+
}
|
|
284
|
+
if (reachesGap)
|
|
285
|
+
gap = result.warnings.find((warning) => warning.code === "gap") ?? null;
|
|
286
|
+
for (const change of result.changes)
|
|
287
|
+
finalContent.set(change.path, change.content);
|
|
288
|
+
// A series that has changed more files than it may, at any point of it, is refused there: not after the rest of its edits have rewritten the outline over again.
|
|
289
|
+
if (finalContent.size > maxFiles) {
|
|
290
|
+
const touchedSoFar = netChanges().length;
|
|
291
|
+
if (touchedSoFar > maxFiles)
|
|
292
|
+
throw tooMany(touchedSoFar, index);
|
|
293
|
+
}
|
|
294
|
+
await apply(result.changes);
|
|
295
|
+
}
|
|
296
|
+
async function apply(changes) {
|
|
297
|
+
if (loaded.whole) {
|
|
298
|
+
for (const change of changes) {
|
|
299
|
+
if (change.content === null)
|
|
300
|
+
loaded.files.delete(change.path);
|
|
301
|
+
else
|
|
302
|
+
loaded.files.set(change.path, { content: change.content, hash: await sha256Hex(change.content) });
|
|
303
|
+
}
|
|
304
|
+
const parsed = await parseOutline([...loaded.files].map(([path, file]) => ({ path, ...file })));
|
|
305
|
+
loaded.chapters = new Map(parsed.chapters.map((entry) => [entry.number, entry]));
|
|
306
|
+
loaded.book = parsed.book;
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
for (const change of changes) {
|
|
310
|
+
const hash = change.content === null ? undefined : await sha256Hex(change.content);
|
|
311
|
+
if (change.path === OUTLINE_BOOK_FILE) {
|
|
312
|
+
loaded.book = change.content === null ? null : (await readOutlineBook(change.content, hash)).book;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const number = parseOutlineChapterPath(change.path)?.number;
|
|
316
|
+
if (number === undefined)
|
|
317
|
+
continue;
|
|
318
|
+
if (change.content === null) {
|
|
319
|
+
if (loaded.chapters.get(number)?.path === change.path)
|
|
320
|
+
loaded.chapters.delete(number);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
loaded.chapters.set(number, (await readOutlineChapter(change.path, number, change.content, hash)).entry);
|
|
324
|
+
loaded.unloaded.delete(change.path);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* What a client had to see: the text of an entry is replaced, and an entry removed, by someone who read its file, and a hash that is given is the file's. The entry is
|
|
330
|
+
* followed through the series (`origin`), so the hash is compared with the file the entry had when the series began.
|
|
331
|
+
*/
|
|
332
|
+
function check(index, edit, subject) {
|
|
333
|
+
const expected = edit.expectedHash;
|
|
334
|
+
const where = describe(edit);
|
|
335
|
+
const details = { index, edit, path: subject.path, subject: subject.kind, ...(subject.number === undefined ? {} : { number: subject.number }) };
|
|
336
|
+
if (expected === undefined) {
|
|
337
|
+
if ((options.requireHash?.(edit) ?? false) && subject.exists && !subject.created && !verified.has(subject.key)) {
|
|
338
|
+
throw new OutlineComposeError("expected_hash_required", `edits[${index}] (${where}): replacing the text of an entry, deleting one or replacing the description of the book needs the hash of ${subject.path} as it was read (expectedHash), so that a change made meanwhile is never overwritten.`, details);
|
|
339
|
+
}
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (!subject.exists)
|
|
343
|
+
throw new OutlineComposeError("conflict", `edits[${index}] (${where}): ${subject.path} has no entry now, so the hash given cannot be its: it was removed since it was read.`, { ...details, reason: "removed" });
|
|
344
|
+
if (subject.created)
|
|
345
|
+
throw new OutlineComposeError("conflict", `edits[${index}] (${where}): ${subject.path} is a new entry made by an earlier edit of the series, so the hash given (of an entry that was read) is not its: the numbers of a series count the edits before them.`, { ...details, reason: "made-in-series" });
|
|
346
|
+
if (expected !== subject.hash)
|
|
347
|
+
throw new OutlineComposeError("conflict", `edits[${index}] (${where}): ${subject.path} changed since it was read.`, { ...details, reason: "changed" });
|
|
348
|
+
verified.add(subject.key);
|
|
349
|
+
}
|
|
350
|
+
const notFound = (index, edit, number) => new OutlineComposeError("not_found", `edits[${index}] (${describe(edit)}): the outline has no entry for chapter ${number}.`, { index, edit, number });
|
|
351
|
+
for (const [index, edit] of edits.entries()) {
|
|
352
|
+
switch (edit.kind) {
|
|
353
|
+
case "append": {
|
|
354
|
+
const number = last() + 1;
|
|
355
|
+
steps.push({ kind: "append", number });
|
|
356
|
+
await make(edit, index);
|
|
357
|
+
lives.set(number, { origin: null, touched: "created" });
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
case "insert": {
|
|
361
|
+
await ensureRange(loaded, edit.at, Number.POSITIVE_INFINITY, index);
|
|
362
|
+
steps.push({ kind: "insert", at: edit.at });
|
|
363
|
+
await make(edit, index);
|
|
364
|
+
follow(edit);
|
|
365
|
+
lives.set(edit.at, { origin: null, touched: "created" });
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
case "move": {
|
|
369
|
+
const { from, to } = edit;
|
|
370
|
+
if (!loaded.chapters.has(from)) {
|
|
371
|
+
if (missing === "throw")
|
|
372
|
+
throw notFound(index, edit, from);
|
|
373
|
+
await make(edit, index, false);
|
|
374
|
+
steps.push({ kind: "move", from, to, unchanged: false, missing: true });
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
const origin = originOf(lives.get(from));
|
|
378
|
+
if (from === to) {
|
|
379
|
+
steps.push({ kind: "move", from, to, unchanged: true, ...origin });
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
await ensureRange(loaded, Math.min(from, to), Math.max(from, to), index);
|
|
383
|
+
steps.push({ kind: "move", from, to, unchanged: false, ...origin });
|
|
384
|
+
await make(edit, index);
|
|
385
|
+
follow(edit);
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
case "remove": {
|
|
389
|
+
const { number } = edit;
|
|
390
|
+
const live = lives.get(number);
|
|
391
|
+
if (!live || !loaded.chapters.has(number)) {
|
|
392
|
+
if (missing === "throw")
|
|
393
|
+
throw notFound(index, edit, number);
|
|
394
|
+
await make(edit, index, false);
|
|
395
|
+
steps.push({ kind: "remove", number, renumber: edit.renumber === true, missing: true });
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
check(index, edit, { path: loaded.chapters.get(number)?.path ?? outlineChapterPath(number), number, kind: "chapter", exists: true, created: live.origin === null, hash: live.origin === null ? undefined : loaded.originals.get(live.origin)?.hash, key: live });
|
|
399
|
+
if (edit.renumber === true)
|
|
400
|
+
await ensureRange(loaded, number + 1, Number.POSITIVE_INFINITY, index);
|
|
401
|
+
steps.push({ kind: "remove", number, renumber: edit.renumber === true, ...originOf(live) });
|
|
402
|
+
await make(edit, index);
|
|
403
|
+
if (live.origin !== null)
|
|
404
|
+
removed.push(live.origin);
|
|
405
|
+
follow(edit);
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
case "update": {
|
|
409
|
+
const { number } = edit;
|
|
410
|
+
const exists = loaded.chapters.has(number);
|
|
411
|
+
if (exists)
|
|
412
|
+
await ensureRange(loaded, number, number, index);
|
|
413
|
+
const live = lives.get(number);
|
|
414
|
+
check(index, edit, { path: loaded.chapters.get(number)?.path ?? outlineChapterPath(number), number, kind: "chapter", exists, created: live?.origin === null, hash: live && live.origin !== null ? loaded.originals.get(live.origin)?.hash : undefined, key: live });
|
|
415
|
+
steps.push({ kind: "update", number, created: !exists, fields: fieldsOfEntry(edit.entry), ...originOf(live) });
|
|
416
|
+
await make(edit, index);
|
|
417
|
+
if (!live)
|
|
418
|
+
lives.set(number, { origin: null, touched: "created" });
|
|
419
|
+
else
|
|
420
|
+
live.touched ??= live.origin === null ? "created" : "updated";
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
default: {
|
|
424
|
+
await ensureBook(loaded, index);
|
|
425
|
+
check(index, edit, { path: OUTLINE_BOOK_FILE, kind: "book", exists: loaded.book !== null, created: loaded.book !== null && !bookExisted, hash: loaded.hashes.get(OUTLINE_BOOK_FILE), key: "book" });
|
|
426
|
+
steps.push({ kind: "book", created: loaded.book === null, fields: ["title", "body"].filter((key) => edit[key] !== undefined) });
|
|
427
|
+
await make(edit, index, false);
|
|
428
|
+
bookTouched = true;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
// A gap is told when the series made or changed it, as the outline ends: one that was there before and is still there is no news (a host that reads the outline says it).
|
|
433
|
+
if (gap && gapsOf(loaded.chapters.keys()) !== gapsOf(loaded.originals.keys()))
|
|
434
|
+
warnings.set(`gap|${gap.path ?? ""}|${gap.message}`, gap);
|
|
435
|
+
const changes = netChanges();
|
|
436
|
+
if (changes.length > maxFiles)
|
|
437
|
+
throw tooMany(changes.length);
|
|
438
|
+
const written = new Map(changes.flatMap((change) => (change.content === null ? [] : [[change.path, change.content]])));
|
|
439
|
+
const numbered = (picked) => [...lives].filter(([, live]) => picked(live)).map(([number]) => number).filter((number) => written.has(outlineChapterPath(number))).sort((left, right) => left - right);
|
|
440
|
+
const created = numbered((live) => live.origin === null && live.touched === "created");
|
|
441
|
+
const updated = numbered((live) => live.origin !== null && live.touched === "updated");
|
|
442
|
+
const entries = [];
|
|
443
|
+
for (const number of [...created, ...updated].sort((left, right) => left - right)) {
|
|
444
|
+
const path = outlineChapterPath(number);
|
|
445
|
+
entries.push({ number, path, hash: await sha256Hex(written.get(path)) });
|
|
446
|
+
}
|
|
447
|
+
const bookContent = written.get(OUTLINE_BOOK_FILE);
|
|
448
|
+
const moved = runs([...lives].flatMap(([number, live]) => (live.origin !== null && live.origin !== number ? [[live.origin, number]] : [])));
|
|
449
|
+
const changed = [];
|
|
450
|
+
const gone = [];
|
|
451
|
+
for (const number of [...new Set([...loaded.originals.keys(), ...loaded.chapters.keys()])].sort((left, right) => left - right)) {
|
|
452
|
+
const before = loaded.originals.get(number);
|
|
453
|
+
const after = loaded.chapters.get(number);
|
|
454
|
+
if (before === after)
|
|
455
|
+
continue;
|
|
456
|
+
if (!after)
|
|
457
|
+
gone.push(number);
|
|
458
|
+
else if (!before || before.contentDigest !== after.contentDigest)
|
|
459
|
+
changed.push(number);
|
|
460
|
+
}
|
|
461
|
+
const now = new Map();
|
|
462
|
+
const where = new Map();
|
|
463
|
+
for (const [number, live] of lives) {
|
|
464
|
+
if (live.origin === null)
|
|
465
|
+
continue;
|
|
466
|
+
now.set(live.origin, live);
|
|
467
|
+
where.set(live.origin, number);
|
|
468
|
+
}
|
|
469
|
+
const identities = [];
|
|
470
|
+
for (const [origin, entry] of [...loaded.originals].sort(([left], [right]) => left - right)) {
|
|
471
|
+
const there = where.get(origin) ?? null;
|
|
472
|
+
const touched = now.get(origin)?.touched === "updated";
|
|
473
|
+
if (there !== origin || touched)
|
|
474
|
+
identities.push({ number: origin, hash: loaded.hashes.get(entry.path) ?? entry.hash ?? "", now: there, updated: touched });
|
|
475
|
+
}
|
|
476
|
+
return {
|
|
477
|
+
changes,
|
|
478
|
+
warnings: [...warnings.values()],
|
|
479
|
+
steps,
|
|
480
|
+
created,
|
|
481
|
+
updated,
|
|
482
|
+
removed: removed.sort((left, right) => left - right),
|
|
483
|
+
moved,
|
|
484
|
+
changed,
|
|
485
|
+
gone,
|
|
486
|
+
chapters: loaded.chapters.size,
|
|
487
|
+
entries,
|
|
488
|
+
...(bookTouched && bookContent !== undefined ? { book: { path: OUTLINE_BOOK_FILE, hash: await sha256Hex(bookContent), created: !bookExisted } } : {}),
|
|
489
|
+
identities,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
//# sourceMappingURL=outline-compose.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outline-compose.js","sourceRoot":"","sources":["../../src/autopilot/outline-compose.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,eAAe,EACf,kBAAkB,GAOnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAElG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wEAAwE;AACxE,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,uMAAuM;AACvM,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAW9C;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAuB;IAC1D,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC;QACd,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC;QACvC,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;QACjC;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAiB,EAAE,MAAc;IAClE,QAAQ,IAAI,CAAC,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IAAI;QACJ,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;QAC9B,OAAO;QACP,GAAG,CAAC,WAAW,IAAI,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrJ,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AutopilotBrief, AutopilotOptions } from "./types.js";
|
|
2
|
+
/** The books the interface offers first. Their names and descriptions are the interface's: the engine knows only the numbers. */
|
|
3
|
+
export type AutopilotPresetId = "story" | "novella" | "novel-draft";
|
|
4
|
+
/** The values of a preset: the three of the brief and the four options that change what a run costs, and the rounds of the review the director allows. */
|
|
5
|
+
export interface AutopilotPreset {
|
|
6
|
+
readonly id: AutopilotPresetId;
|
|
7
|
+
readonly brief: Readonly<Pick<AutopilotBrief, "targetChapters" | "scenesPerChapter" | "wordsPerScene">>;
|
|
8
|
+
readonly options: Readonly<Pick<AutopilotOptions, "readers" | "maxReaders" | "readersOnPlan" | "specialists">>;
|
|
9
|
+
/** The most rounds of review a chapter gets (`maxReviewRounds` of the director's profile, from 1 to 3): it changes the cost, and it is not an option of the autopilot. */
|
|
10
|
+
readonly maxReviewRounds: 1 | 2 | 3;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The three starting points, from the shortest book to the longest. Every number is one the engine takes as it is (`normalizeBrief`,
|
|
14
|
+
* `normalizeOptions`), and none is a book of three hundred chapters:
|
|
15
|
+
* - `story`: four short chapters, about 7 000 words, three readers, none on the plan.
|
|
16
|
+
* - `novella`: twelve chapters of three scenes, about 50 000 words: what a new book starts with (`DEFAULT_BRIEF`, `DEFAULT_OPTIONS`).
|
|
17
|
+
* - `novel-draft`: twenty-four chapters, about 108 000 words, with one round of review so that the cost of a long book stays within reach.
|
|
18
|
+
*/
|
|
19
|
+
export declare const AUTOPILOT_PRESETS: readonly AutopilotPreset[];
|
|
20
|
+
export declare const AUTOPILOT_PRESET_IDS: readonly AutopilotPresetId[];
|
|
21
|
+
/** The preset with this id; `undefined` for any other value. */
|
|
22
|
+
export declare function autopilotPreset(id: unknown): AutopilotPreset | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The preset a form matches, or `null` for one that matches none: what the interface calls "custom".
|
|
25
|
+
*
|
|
26
|
+
* The values are compared as the engine takes them (`normalizeBrief`, `normalizeOptions`): what is missing is the default, text that is a number is that
|
|
27
|
+
* number, one past the limits is the limit. Only the values that change what a run costs are compared (the three of the brief, the four options and
|
|
28
|
+
* the rounds): the pauses, the budgets, the outline, the idea and the genre change no preset. The rounds are compared only when they are given: they are
|
|
29
|
+
* not a field of the brief or of the options but of the director's profile, which a form may not have at hand.
|
|
30
|
+
*/
|
|
31
|
+
export declare function matchAutopilotPreset(values?: {
|
|
32
|
+
brief?: unknown;
|
|
33
|
+
options?: unknown;
|
|
34
|
+
maxReviewRounds?: unknown;
|
|
35
|
+
} | null): AutopilotPresetId | null;
|
|
36
|
+
//# sourceMappingURL=presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../src/autopilot/presets.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnE,iIAAiI;AACjI,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,SAAS,GAAG,aAAa,CAAC;AAEpE,0JAA0J;AAC1J,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,cAAc,EAAE,gBAAgB,GAAG,kBAAkB,GAAG,eAAe,CAAC,CAAC,CAAC;IACxG,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,YAAY,GAAG,eAAe,GAAG,aAAa,CAAC,CAAC,CAAC;IAC/G,0KAA0K;IAC1K,QAAQ,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACrC;AAOD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAI1B,CAAC;AAE/B,eAAO,MAAM,oBAAoB,EAAE,SAAS,iBAAiB,EAAyD,CAAC;AAEvH,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,EAAE,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,CAExE;AAQD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,iBAAiB,GAAG,IAAI,CAchJ"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { asNumber, asRecord } from "../util/json.js";
|
|
2
|
+
import { normalizeBrief, normalizeOptions } from "./state.js";
|
|
3
|
+
function freeze(value) {
|
|
4
|
+
for (const inner of Object.values(value))
|
|
5
|
+
if (inner && typeof inner === "object")
|
|
6
|
+
freeze(inner);
|
|
7
|
+
return Object.freeze(value);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The three starting points, from the shortest book to the longest. Every number is one the engine takes as it is (`normalizeBrief`,
|
|
11
|
+
* `normalizeOptions`), and none is a book of three hundred chapters:
|
|
12
|
+
* - `story`: four short chapters, about 7 000 words, three readers, none on the plan.
|
|
13
|
+
* - `novella`: twelve chapters of three scenes, about 50 000 words: what a new book starts with (`DEFAULT_BRIEF`, `DEFAULT_OPTIONS`).
|
|
14
|
+
* - `novel-draft`: twenty-four chapters, about 108 000 words, with one round of review so that the cost of a long book stays within reach.
|
|
15
|
+
*/
|
|
16
|
+
export const AUTOPILOT_PRESETS = freeze([
|
|
17
|
+
{ id: "story", brief: { targetChapters: 4, scenesPerChapter: 2, wordsPerScene: 900 }, options: { readers: true, maxReaders: 3, readersOnPlan: false, specialists: true }, maxReviewRounds: 2 },
|
|
18
|
+
{ id: "novella", brief: { targetChapters: 12, scenesPerChapter: 3, wordsPerScene: 1400 }, options: { readers: true, maxReaders: 5, readersOnPlan: true, specialists: true }, maxReviewRounds: 2 },
|
|
19
|
+
{ id: "novel-draft", brief: { targetChapters: 24, scenesPerChapter: 3, wordsPerScene: 1500 }, options: { readers: true, maxReaders: 3, readersOnPlan: true, specialists: true }, maxReviewRounds: 1 },
|
|
20
|
+
]);
|
|
21
|
+
export const AUTOPILOT_PRESET_IDS = freeze(AUTOPILOT_PRESETS.map((preset) => preset.id));
|
|
22
|
+
/** The preset with this id; `undefined` for any other value. */
|
|
23
|
+
export function autopilotPreset(id) {
|
|
24
|
+
return AUTOPILOT_PRESETS.find((preset) => preset.id === id);
|
|
25
|
+
}
|
|
26
|
+
/** The rounds as the director's profile takes them: a whole number from 1 to 3; `undefined` for a value that is not a number. */
|
|
27
|
+
function roundsOf(value) {
|
|
28
|
+
const rounds = asNumber(value, Number.NaN);
|
|
29
|
+
return Number.isNaN(rounds) ? undefined : Math.min(3, Math.max(1, Math.round(rounds)));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The preset a form matches, or `null` for one that matches none: what the interface calls "custom".
|
|
33
|
+
*
|
|
34
|
+
* The values are compared as the engine takes them (`normalizeBrief`, `normalizeOptions`): what is missing is the default, text that is a number is that
|
|
35
|
+
* number, one past the limits is the limit. Only the values that change what a run costs are compared (the three of the brief, the four options and
|
|
36
|
+
* the rounds): the pauses, the budgets, the outline, the idea and the genre change no preset. The rounds are compared only when they are given: they are
|
|
37
|
+
* not a field of the brief or of the options but of the director's profile, which a form may not have at hand.
|
|
38
|
+
*/
|
|
39
|
+
export function matchAutopilotPreset(values) {
|
|
40
|
+
const source = asRecord(values);
|
|
41
|
+
const brief = normalizeBrief(source.brief);
|
|
42
|
+
const options = normalizeOptions(source.options);
|
|
43
|
+
const rounds = roundsOf(source.maxReviewRounds);
|
|
44
|
+
const found = AUTOPILOT_PRESETS.find((preset) => preset.brief.targetChapters === brief.targetChapters
|
|
45
|
+
&& preset.brief.scenesPerChapter === brief.scenesPerChapter
|
|
46
|
+
&& preset.brief.wordsPerScene === brief.wordsPerScene
|
|
47
|
+
&& preset.options.readers === options.readers
|
|
48
|
+
&& preset.options.maxReaders === options.maxReaders
|
|
49
|
+
&& preset.options.readersOnPlan === options.readersOnPlan
|
|
50
|
+
&& preset.options.specialists === options.specialists
|
|
51
|
+
&& (rounds === undefined || rounds === preset.maxReviewRounds));
|
|
52
|
+
return found?.id ?? null;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=presets.js.map
|