@dsh-agentic-roleplay/core 0.12.0 → 0.12.2
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/cordis.patch.yml +108 -0
- package/lib/{access-DAw54-NI.js → access-Csp80TFX.js} +2 -2
- package/lib/{authoring-tools-4NgDhIJV.js → authoring-tools-BZr4bgBy.js} +25 -771
- package/lib/authoring.js +136 -12
- package/lib/{child-D3QUNb3m.js → child-DTdY14S9.js} +54 -6
- package/lib/client.js +16457 -1938
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +3 -3
- package/lib/dev-context-Cgv_wZbG.js +50 -0
- package/lib/doctor.js +6 -3
- package/lib/{gallery-Ct6nm4UQ.js → gallery-BNg0rPTp.js} +3 -3
- package/lib/{generator-CI8fOnXy.js → generator-9-5at9cZ.js} +2 -2
- package/lib/helper.js +5 -9
- package/lib/{hooks-BNeoGMHZ.js → hooks-Dtq5KZQX.js} +47 -16
- package/lib/images.js +4 -4
- package/lib/index.js +152 -476
- package/lib/{jail-BIF79PJO.js → jail-DVbPSC0R.js} +2 -2
- package/lib/{library-BF9ZMSFz.js → library-DTxakw0z.js} +2 -2
- package/lib/{lorebook-author-tools-DBk-V0hp.js → lorebook-author-tools-BjcEUo22.js} +19 -6
- package/lib/lorebook-authoring.js +13 -5
- package/lib/{narration-xvErE2yp.js → narration--K2XVIHI.js} +2 -2
- package/lib/orchestration.js +33 -12
- package/lib/{pack-jail-C8EyX9Ix.js → pack-jail-Dt0VTsu0.js} +558 -23
- package/lib/{packs-S0SzrVv-.js → packs-DWfR2Ted.js} +2 -2
- package/lib/{presenter-agent-Bc478nTA.js → presenter-agent-vFOxIuWv.js} +9 -9
- package/lib/{preset-SJZyw0kt.js → preset-Dv5YF2qj.js} +4 -4
- package/lib/{preset-author-tools-CzogjK42.js → preset-author-tools-BUzO9mTW.js} +8 -7
- package/lib/preset-authoring.js +12 -6
- package/lib/{reflection-buQiSdvq.js → reflection-Dd3pEiZB.js} +14 -15
- package/lib/{presets-DQ5rioMh.js → serial-BUaJGwVy.js} +1241 -390
- package/lib/{turn-guard-BSAba8sp.js → turn-guard-87NE-Cnp.js} +3 -3
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +34 -34
- package/prompts/en/import/style.md +2 -1
- package/prompts/en/world/procedure.md +1 -1
- package/prompts/zh/import/style.md +2 -1
- package/prompts/zh/world/procedure.md +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { m as parseSampling } from "./child-
|
|
2
|
-
import "./narration
|
|
3
|
-
import { a as VARIABLE_KINDS, n as atomicWrite, o as VARIABLE_SUBJECTS, s as VARIABLE_VISIBILITIES } from "./access-
|
|
4
|
-
import { G as readDocument, J as errorMessage, K as Reader, X as
|
|
1
|
+
import { m as parseSampling } from "./child-DTdY14S9.js";
|
|
2
|
+
import { f as parseSwitchboard } from "./narration--K2XVIHI.js";
|
|
3
|
+
import { a as VARIABLE_KINDS, n as atomicWrite, o as VARIABLE_SUBJECTS, s as VARIABLE_VISIBILITIES } from "./access-Csp80TFX.js";
|
|
4
|
+
import { G as readDocument, J as errorMessage, K as Reader, X as LANGUAGE_TAG, Y as LANGUAGE_FOLDER, Z as PROMPTS_FOLDER, at as shippedPromptsDirectory, it as shippedLanguages, nt as listFiles, q as formatIssue, rt as promptProblem, tt as languageOf } from "./hooks-Dtq5KZQX.js";
|
|
5
5
|
import { i as translator, r as languageOf$1 } from "./text-Dfv8S8eq.js";
|
|
6
|
-
import { C as slug, S as norm, T as uniqueKey, w as trOf, x as mapLimit } from "./library-
|
|
6
|
+
import { C as slug, S as norm, T as uniqueKey, w as trOf, x as mapLimit } from "./library-DTxakw0z.js";
|
|
7
7
|
import { dirname, join } from "node:path";
|
|
8
|
-
import { MAX_ROUTINE_WINDOWS, createSessionStore, dayTokenProblems, valueIssue } from "@dsh-agentic-roleplay/state";
|
|
8
|
+
import { MAX_ROUTINE_WINDOWS, createSessionStore, dayTokenProblems, isTimeZone, parseInstant, valueIssue } from "@dsh-agentic-roleplay/state";
|
|
9
9
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
10
10
|
import { createHash, randomUUID } from "node:crypto";
|
|
11
11
|
import { cp, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
@@ -702,6 +702,19 @@ function parseRelationEdit(value) {
|
|
|
702
702
|
if (problems.length > 0) throw new InvalidEditProblems(problems);
|
|
703
703
|
return input;
|
|
704
704
|
}
|
|
705
|
+
// src/host/folders.ts
|
|
706
|
+
/**
|
|
707
|
+
* Names of the subfolders of `dir`, sorted. Symbolic links are not followed
|
|
708
|
+
* and a missing directory has none; any other failure is thrown.
|
|
709
|
+
*/
|
|
710
|
+
async function subfolders(dir) {
|
|
711
|
+
try {
|
|
712
|
+
return (await readdir(dir, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
713
|
+
} catch (error) {
|
|
714
|
+
if (error.code === "ENOENT") return [];
|
|
715
|
+
throw error;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
705
718
|
/**
|
|
706
719
|
* Read an `id` field. Ids are opaque strings, unique within their scope, that
|
|
707
720
|
* stay the same when the file is copied or edited.
|
|
@@ -1367,6 +1380,53 @@ function parseLoreFile(text, fallbackId) {
|
|
|
1367
1380
|
issues
|
|
1368
1381
|
};
|
|
1369
1382
|
}
|
|
1383
|
+
// src/host/lore/load.ts
|
|
1384
|
+
const LORE_DIR = "lore";
|
|
1385
|
+
async function loadLore(worldDir) {
|
|
1386
|
+
const dir = join(worldDir, LORE_DIR);
|
|
1387
|
+
const result = {
|
|
1388
|
+
lore: [],
|
|
1389
|
+
problems: []
|
|
1390
|
+
};
|
|
1391
|
+
let folders;
|
|
1392
|
+
try {
|
|
1393
|
+
folders = await subfolders(dir);
|
|
1394
|
+
} catch (error) {
|
|
1395
|
+
if (error.code !== "ENOENT") result.problems.push({
|
|
1396
|
+
path: dir,
|
|
1397
|
+
message: errorMessage(error)
|
|
1398
|
+
});
|
|
1399
|
+
return result;
|
|
1400
|
+
}
|
|
1401
|
+
const owners = /* @__PURE__ */ new Map();
|
|
1402
|
+
for (const folder of folders) {
|
|
1403
|
+
const file = join(dir, folder, LORE_FILE_NAME);
|
|
1404
|
+
try {
|
|
1405
|
+
const entry = await readDocument(file, (text) => parseLoreFile(text, folder), result.problems);
|
|
1406
|
+
if (entry === void 0) continue;
|
|
1407
|
+
const owner = owners.get(entry.id);
|
|
1408
|
+
if (owner !== void 0) {
|
|
1409
|
+
result.problems.push({
|
|
1410
|
+
path: file,
|
|
1411
|
+
message: `id "${entry.id}" is already used by ${owner}`
|
|
1412
|
+
});
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
owners.set(entry.id, folder);
|
|
1416
|
+
result.lore.push(entry);
|
|
1417
|
+
} catch (error) {
|
|
1418
|
+
if (error.code !== "ENOENT") result.problems.push({
|
|
1419
|
+
path: file,
|
|
1420
|
+
message: errorMessage(error)
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
if (result.lore.length > 500) result.problems.push({
|
|
1425
|
+
path: dir,
|
|
1426
|
+
message: `a world has at most 500 lore entries`
|
|
1427
|
+
});
|
|
1428
|
+
return result;
|
|
1429
|
+
}
|
|
1370
1430
|
// src/host/variables/load.ts
|
|
1371
1431
|
const VARIABLES_FILE_NAME = "variables.json";
|
|
1372
1432
|
function readDefinition(reader) {
|
|
@@ -2077,6 +2137,227 @@ function playerWord(text, name) {
|
|
|
2077
2137
|
function withPlayer(text, name) {
|
|
2078
2138
|
return text.replace(/\[PLAYER\]|\{\{\s*user\s*\}\}/g, playerWord(text, name));
|
|
2079
2139
|
}
|
|
2140
|
+
// src/host/lorebooks/lorebooks.ts
|
|
2141
|
+
const LOREBOOKS_FOLDER = "lorebooks";
|
|
2142
|
+
const LOREBOOK_FILE = "lorebook.json";
|
|
2143
|
+
const NAME$1 = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
2144
|
+
const ENTRY_ID = /^[\p{L}\p{N}][\p{L}\p{N}_-]{0,79}$/u;
|
|
2145
|
+
const MAX_TEXT$1 = 300;
|
|
2146
|
+
const isLorebookName = (name) => NAME$1.test(name);
|
|
2147
|
+
const isEntryId = (id) => ENTRY_ID.test(id);
|
|
2148
|
+
const lorebooksDirectory = (root) => join(root, LOREBOOKS_FOLDER);
|
|
2149
|
+
function lorebookDirectory(root, name) {
|
|
2150
|
+
if (!isLorebookName(name)) throw new Error(`"${name}" is not a usable lorebook name (letters, digits, "-" and "_", up to 64)`);
|
|
2151
|
+
return join(lorebooksDirectory(root), name);
|
|
2152
|
+
}
|
|
2153
|
+
const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2154
|
+
function parseHeader$1(value, problems) {
|
|
2155
|
+
if (!isRecord$1(value)) {
|
|
2156
|
+
problems.push(`${LOREBOOK_FILE} must be an object`);
|
|
2157
|
+
return {};
|
|
2158
|
+
}
|
|
2159
|
+
const text = (key) => {
|
|
2160
|
+
const field = value[key];
|
|
2161
|
+
if (field === void 0 || field === null) return void 0;
|
|
2162
|
+
if (typeof field !== "string" || field.length > MAX_TEXT$1) {
|
|
2163
|
+
problems.push(`${LOREBOOK_FILE}: "${key}" must be text of at most ${MAX_TEXT$1} characters`);
|
|
2164
|
+
return;
|
|
2165
|
+
}
|
|
2166
|
+
return field.trim() || void 0;
|
|
2167
|
+
};
|
|
2168
|
+
const title = text("title");
|
|
2169
|
+
const description = text("description");
|
|
2170
|
+
return {
|
|
2171
|
+
...title === void 0 ? {} : { title },
|
|
2172
|
+
...description === void 0 ? {} : { description }
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
function readHeader$1(directory, problems) {
|
|
2176
|
+
const file = join(directory, LOREBOOK_FILE);
|
|
2177
|
+
if (!existsSync(file)) return {};
|
|
2178
|
+
let value;
|
|
2179
|
+
try {
|
|
2180
|
+
value = JSON.parse(readFileSync(file, "utf8"));
|
|
2181
|
+
} catch {
|
|
2182
|
+
problems.push(`${LOREBOOK_FILE} is not valid JSON`);
|
|
2183
|
+
return {};
|
|
2184
|
+
}
|
|
2185
|
+
return parseHeader$1(value, problems);
|
|
2186
|
+
}
|
|
2187
|
+
/** What is wrong with the entries of a book as a whole: an entry about a character or place of some world, or relating to one that is not there. */
|
|
2188
|
+
function bookProblems(entries) {
|
|
2189
|
+
const ids = new Set(entries.map((entry) => entry.id));
|
|
2190
|
+
return entries.flatMap((entry) => [...entry.subjects.length > 0 ? [`${entry.id}: a lorebook does not belong to a world, so its entries have no subjects`] : [], ...entry.related.flatMap((other) => other === entry.id ? [`${entry.id}: related: an entry cannot relate to itself`] : ids.has(other) ? [] : [`${entry.id}: related: "${other}" is not an entry of this book`])]);
|
|
2191
|
+
}
|
|
2192
|
+
/** Reads one lorebook folder, collecting every problem instead of stopping at the first. @throws {Error} when the folder does not exist. */
|
|
2193
|
+
async function readLorebook(directory, name) {
|
|
2194
|
+
if (!existsSync(directory)) throw new Error(`there is no lorebook "${name}"`);
|
|
2195
|
+
const problems = [];
|
|
2196
|
+
const header = readHeader$1(directory, problems);
|
|
2197
|
+
const { lore, problems: found } = await loadLore(directory);
|
|
2198
|
+
for (const problem of found) problems.push(`${problem.path.slice(directory.length + 1)}: ${problem.message}`);
|
|
2199
|
+
problems.push(...bookProblems(lore));
|
|
2200
|
+
if (lore.length === 0 && problems.length === 0) problems.push("the lorebook has no entries");
|
|
2201
|
+
return {
|
|
2202
|
+
summary: {
|
|
2203
|
+
name,
|
|
2204
|
+
title: header.title ?? name,
|
|
2205
|
+
description: header.description ?? "",
|
|
2206
|
+
entries: lore.length,
|
|
2207
|
+
common: lore.filter((entry) => entry.scope === "everyone").length,
|
|
2208
|
+
problems
|
|
2209
|
+
},
|
|
2210
|
+
entries: lore.sort((a, b) => a.title.localeCompare(b.title))
|
|
2211
|
+
};
|
|
2212
|
+
}
|
|
2213
|
+
async function listLorebooks(root) {
|
|
2214
|
+
const folder = lorebooksDirectory(root);
|
|
2215
|
+
if (!existsSync(folder)) return [];
|
|
2216
|
+
const found = (await readdir(folder, { withFileTypes: true })).filter((entry) => entry.isDirectory() && isLorebookName(entry.name));
|
|
2217
|
+
return (await Promise.all(found.map((entry) => readLorebook(join(folder, entry.name), entry.name)))).sort((a, b) => a.summary.name.localeCompare(b.summary.name));
|
|
2218
|
+
}
|
|
2219
|
+
async function loadLorebook(root, name) {
|
|
2220
|
+
return await readLorebook(lorebookDirectory(root, name), name);
|
|
2221
|
+
}
|
|
2222
|
+
const toEntry = (definition) => ({
|
|
2223
|
+
id: definition.id,
|
|
2224
|
+
title: definition.title,
|
|
2225
|
+
kind: definition.kind,
|
|
2226
|
+
scope: definition.scope,
|
|
2227
|
+
knownBy: definition.knownBy,
|
|
2228
|
+
summary: definition.summary,
|
|
2229
|
+
body: definition.body,
|
|
2230
|
+
related: definition.related
|
|
2231
|
+
});
|
|
2232
|
+
const entriesOf = (book) => book.entries.map(toEntry);
|
|
2233
|
+
function headerFile$1(header) {
|
|
2234
|
+
return `${JSON.stringify(header, null, 2)}\n`;
|
|
2235
|
+
}
|
|
2236
|
+
async function writeAtomic(file, text) {
|
|
2237
|
+
await mkdir(dirname(file), { recursive: true });
|
|
2238
|
+
await writeFile(`${file}.tmp`, text);
|
|
2239
|
+
await rename(`${file}.tmp`, file);
|
|
2240
|
+
}
|
|
2241
|
+
/** Makes an empty lorebook. @throws {Error} when the name is taken or the information is not acceptable. */
|
|
2242
|
+
async function createLorebook(root, request) {
|
|
2243
|
+
const target = lorebookDirectory(root, request.name);
|
|
2244
|
+
if (existsSync(target)) throw new Error(`there is already a lorebook "${request.name}"`);
|
|
2245
|
+
const problems = [];
|
|
2246
|
+
const header = parseHeader$1({
|
|
2247
|
+
title: request.title?.trim(),
|
|
2248
|
+
description: request.description?.trim()
|
|
2249
|
+
}, problems);
|
|
2250
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
2251
|
+
await writeAtomic(join(target, LOREBOOK_FILE), headerFile$1(header));
|
|
2252
|
+
return await readLorebook(target, request.name);
|
|
2253
|
+
}
|
|
2254
|
+
/** Makes an empty folder that an import is about to fill; it has no entries yet, so it reads as having problems until it does. */
|
|
2255
|
+
async function reserveLorebook(root, name, title) {
|
|
2256
|
+
const target = lorebookDirectory(root, name);
|
|
2257
|
+
if (existsSync(target)) throw new Error(`there is already a lorebook "${name}"`);
|
|
2258
|
+
await writeAtomic(join(target, LOREBOOK_FILE), headerFile$1({ title: title.trim().slice(0, MAX_TEXT$1) || name }));
|
|
2259
|
+
return target;
|
|
2260
|
+
}
|
|
2261
|
+
/** Changes what a lorebook says about itself. @throws {Error} when the lorebook does not exist or the change is not acceptable; nothing is written then. */
|
|
2262
|
+
async function updateLorebookInfo(root, name, change) {
|
|
2263
|
+
const directory = lorebookDirectory(root, name);
|
|
2264
|
+
if (!existsSync(directory)) throw new Error(`there is no lorebook "${name}"`);
|
|
2265
|
+
const current = readHeader$1(directory, []);
|
|
2266
|
+
const problems = [];
|
|
2267
|
+
const next = parseHeader$1({
|
|
2268
|
+
title: change.title ?? current.title,
|
|
2269
|
+
description: change.description ?? current.description
|
|
2270
|
+
}, problems);
|
|
2271
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
2272
|
+
await writeAtomic(join(directory, LOREBOOK_FILE), headerFile$1(next));
|
|
2273
|
+
return await readLorebook(directory, name);
|
|
2274
|
+
}
|
|
2275
|
+
/** The file of an entry: written in the format of a world's own lore, with its scope always said. */
|
|
2276
|
+
function entryFile(entry) {
|
|
2277
|
+
return `${JSON.stringify({
|
|
2278
|
+
title: entry.title,
|
|
2279
|
+
kind: entry.kind,
|
|
2280
|
+
scope: entry.scope,
|
|
2281
|
+
...entry.scope === "listed" && entry.knownBy.length > 0 ? { known_by: entry.knownBy } : {},
|
|
2282
|
+
summary: entry.summary,
|
|
2283
|
+
body: entry.body,
|
|
2284
|
+
...entry.related.length > 0 ? { related: entry.related } : {}
|
|
2285
|
+
}, null, 2)}\n`;
|
|
2286
|
+
}
|
|
2287
|
+
/** Checks an entry the way a story start would, before anything is written. @returns why it cannot be used, or nothing. */
|
|
2288
|
+
function entryProblem(entry) {
|
|
2289
|
+
if (!isEntryId(entry.id)) return `"${entry.id}" is not a usable entry id (letters, digits, "-" and "_", up to 80)`;
|
|
2290
|
+
if (!LORE_KINDS.includes(entry.kind)) return `kind must be one of ${LORE_KINDS.join(", ")}`;
|
|
2291
|
+
if (!LORE_SCOPES.includes(entry.scope)) return `scope must be one of ${LORE_SCOPES.join(", ")}`;
|
|
2292
|
+
if (entry.title.trim() === "") return "the entry needs a title";
|
|
2293
|
+
if (entry.body.trim() === "" && entry.summary.trim() === "") return "the entry needs a summary or a body";
|
|
2294
|
+
const parsed = parseLoreFile(entryFile({
|
|
2295
|
+
...entry,
|
|
2296
|
+
title: entry.title.trim()
|
|
2297
|
+
}), entry.id);
|
|
2298
|
+
return parsed.ok ? void 0 : parsed.issues.map((issue) => `${issue.path}: ${issue.message}`).join("; ");
|
|
2299
|
+
}
|
|
2300
|
+
/**
|
|
2301
|
+
* Creates several new entries of a lorebook at once, each checked as `writeLorebookEntry` checks one; none is written when any is not acceptable.
|
|
2302
|
+
* @throws {Error} when the lorebook does not exist, an id is taken or an entry is not acceptable, or the book would have more entries than a world may.
|
|
2303
|
+
*/
|
|
2304
|
+
async function addLorebookEntries(root, name, entries) {
|
|
2305
|
+
const directory = lorebookDirectory(root, name);
|
|
2306
|
+
if (!existsSync(directory)) throw new Error(`there is no lorebook "${name}"`);
|
|
2307
|
+
const book = await readLorebook(directory, name);
|
|
2308
|
+
if (book.entries.length + entries.length > 500) throw new Error(`a lorebook has at most 500 entries`);
|
|
2309
|
+
const ids = new Set(book.entries.map((entry) => entry.id));
|
|
2310
|
+
for (const entry of entries) {
|
|
2311
|
+
const problem = entryProblem(entry);
|
|
2312
|
+
if (problem !== void 0) throw new Error(`entry "${entry.title}": ${problem}`);
|
|
2313
|
+
if (ids.has(entry.id)) throw new Error(`there is already an entry "${entry.id}"`);
|
|
2314
|
+
ids.add(entry.id);
|
|
2315
|
+
}
|
|
2316
|
+
for (const entry of entries) await writeAtomic(join(directory, LORE_DIR, entry.id, LORE_FILE_NAME), entryFile({
|
|
2317
|
+
...entry,
|
|
2318
|
+
title: entry.title.trim()
|
|
2319
|
+
}));
|
|
2320
|
+
return await readLorebook(directory, name);
|
|
2321
|
+
}
|
|
2322
|
+
/** Creates or replaces one entry. @throws {Error} when the lorebook does not exist, the entry is not acceptable or the book would have more entries than a world may. */
|
|
2323
|
+
async function writeLorebookEntry(root, name, entry) {
|
|
2324
|
+
const directory = lorebookDirectory(root, name);
|
|
2325
|
+
if (!existsSync(directory)) throw new Error(`there is no lorebook "${name}"`);
|
|
2326
|
+
const problem = entryProblem(entry);
|
|
2327
|
+
if (problem !== void 0) throw new Error(problem);
|
|
2328
|
+
const file = join(directory, LORE_DIR, entry.id, LORE_FILE_NAME);
|
|
2329
|
+
const book = await readLorebook(directory, name);
|
|
2330
|
+
if (!existsSync(file) && book.entries.length >= 500) throw new Error(`a lorebook has at most 500 entries`);
|
|
2331
|
+
const others = book.entries.filter((other) => other.id !== entry.id);
|
|
2332
|
+
const missing = entry.related.filter((id) => id === entry.id || !others.some((other) => other.id === id));
|
|
2333
|
+
if (missing.length > 0) throw new Error(`related: ${missing.map((id) => `"${id}"`).join(", ")} ${missing.length === 1 ? "is" : "are"} not (other) entries of this book`);
|
|
2334
|
+
await writeAtomic(file, entryFile({
|
|
2335
|
+
...entry,
|
|
2336
|
+
title: entry.title.trim()
|
|
2337
|
+
}));
|
|
2338
|
+
return await readLorebook(directory, name);
|
|
2339
|
+
}
|
|
2340
|
+
/** Moves an entry into the book's `.trash`. @throws {Error} when it does not exist or other entries relate to it. */
|
|
2341
|
+
async function deleteLorebookEntry(root, name, id, now = Date.now) {
|
|
2342
|
+
const directory = lorebookDirectory(root, name);
|
|
2343
|
+
const folder = join(directory, LORE_DIR, id);
|
|
2344
|
+
if (!isEntryId(id) || !existsSync(join(folder, "lore.json"))) throw new Error(`the lorebook "${name}" has no entry "${id}"`);
|
|
2345
|
+
const citing = (await readLorebook(directory, name)).entries.filter((entry) => entry.id !== id && entry.related.includes(id)).map((entry) => entry.id);
|
|
2346
|
+
if (citing.length > 0) throw new Error(`the entries ${citing.join(", ")} relate to "${id}"; change them first`);
|
|
2347
|
+
const aside = join(directory, ".trash", LORE_DIR, `${id}-${now()}`);
|
|
2348
|
+
await mkdir(dirname(aside), { recursive: true });
|
|
2349
|
+
await rename(folder, aside);
|
|
2350
|
+
return await readLorebook(directory, name);
|
|
2351
|
+
}
|
|
2352
|
+
/** Moves a lorebook out of the library into `<root>/.trash/lorebooks/`. @returns where it went. */
|
|
2353
|
+
async function deleteLorebook(root, name, now = Date.now) {
|
|
2354
|
+
const directory = lorebookDirectory(root, name);
|
|
2355
|
+
if (!existsSync(directory)) throw new Error(`there is no lorebook "${name}"`);
|
|
2356
|
+
const aside = join(root, ".trash", LOREBOOKS_FOLDER, `${name}-${now()}`);
|
|
2357
|
+
await mkdir(dirname(aside), { recursive: true });
|
|
2358
|
+
await rename(directory, aside);
|
|
2359
|
+
return aside;
|
|
2360
|
+
}
|
|
2080
2361
|
// src/host/prompts/world-prompts.ts
|
|
2081
2362
|
/** The prompts that decide how the story is written and who the models are (prose and persona); every other prompt holds rules of the game. */
|
|
2082
2363
|
const PROSE_PROMPTS = [
|
|
@@ -2142,140 +2423,868 @@ async function deleteWorldPrompt(directory, language, id, shipped = shippedPromp
|
|
|
2142
2423
|
await rm(dirname(file), { recursive: false }).catch(() => void 0);
|
|
2143
2424
|
return aside;
|
|
2144
2425
|
}
|
|
2145
|
-
// src/host/
|
|
2146
|
-
|
|
2147
|
-
const
|
|
2148
|
-
|
|
2149
|
-
const
|
|
2150
|
-
const
|
|
2151
|
-
const
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
escalated: 0,
|
|
2156
|
-
fallbacks: 0,
|
|
2157
|
-
agreed: 0,
|
|
2158
|
-
disagreed: 0,
|
|
2159
|
-
decisionMs: 0,
|
|
2160
|
-
llmMs: 0,
|
|
2161
|
-
samples: []
|
|
2162
|
-
});
|
|
2163
|
-
async function timed(run) {
|
|
2164
|
-
const started = performance.now();
|
|
2165
|
-
return {
|
|
2166
|
-
value: await run(),
|
|
2167
|
-
ms: Math.round(performance.now() - started)
|
|
2168
|
-
};
|
|
2426
|
+
// src/host/presets/presets.ts
|
|
2427
|
+
const PRESETS_FOLDER = "presets";
|
|
2428
|
+
const PRESET_FILE = "preset.json";
|
|
2429
|
+
const NAME = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
2430
|
+
const MAX_TEXT = 300;
|
|
2431
|
+
const isPresetName = (name) => NAME.test(name);
|
|
2432
|
+
const presetsDirectory = (root) => join(root, PRESETS_FOLDER);
|
|
2433
|
+
function presetDirectory(root, name) {
|
|
2434
|
+
if (!isPresetName(name)) throw new Error(`"${name}" is not a usable preset name (letters, digits, "-" and "_", up to 64)`);
|
|
2435
|
+
return join(presetsDirectory(root), name);
|
|
2169
2436
|
}
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
const
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
report
|
|
2182
|
-
};
|
|
2183
|
-
const viaLlm = async (subset) => {
|
|
2184
|
-
const { value, ms } = await timed(() => route.llm(subset));
|
|
2185
|
-
report.llmMs += ms;
|
|
2186
|
-
for (const [key, verdict] of value) verdicts.set(key, verdict);
|
|
2187
|
-
};
|
|
2188
|
-
const viaDecision = async () => {
|
|
2189
|
-
try {
|
|
2190
|
-
const { value, ms } = await timed(() => route.probabilities(keys));
|
|
2191
|
-
report.decisionMs += ms;
|
|
2192
|
-
return value;
|
|
2193
|
-
} catch (error) {
|
|
2194
|
-
if (signal.aborted) throw error;
|
|
2195
|
-
report.problem = error instanceof Error ? error.message : String(error);
|
|
2437
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2438
|
+
function parseHeader(value, problems) {
|
|
2439
|
+
if (!isRecord(value)) {
|
|
2440
|
+
problems.push(`${PRESET_FILE} must be an object`);
|
|
2441
|
+
return { sampling: {} };
|
|
2442
|
+
}
|
|
2443
|
+
const text = (key) => {
|
|
2444
|
+
const field = value[key];
|
|
2445
|
+
if (field === void 0 || field === null) return void 0;
|
|
2446
|
+
if (typeof field !== "string" || field.length > MAX_TEXT) {
|
|
2447
|
+
problems.push(`${PRESET_FILE}: "${key}" must be text of at most ${MAX_TEXT} characters`);
|
|
2196
2448
|
return;
|
|
2197
2449
|
}
|
|
2450
|
+
return field.trim() || void 0;
|
|
2198
2451
|
};
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
verdicts,
|
|
2203
|
-
report
|
|
2204
|
-
};
|
|
2205
|
-
}
|
|
2206
|
-
if (mode === "shadow") {
|
|
2207
|
-
const [decided] = await Promise.all([viaDecision(), viaLlm(keys)]);
|
|
2208
|
-
if (decided === void 0) return {
|
|
2209
|
-
verdicts,
|
|
2210
|
-
report
|
|
2211
|
-
};
|
|
2212
|
-
for (const key of keys) {
|
|
2213
|
-
const probability = decided.get(key);
|
|
2214
|
-
const llm = verdicts.get(key);
|
|
2215
|
-
if (probability === void 0 || llm === void 0) continue;
|
|
2216
|
-
const decision = probability >= route.yesAt;
|
|
2217
|
-
if (decision === llm) report.agreed += 1;
|
|
2218
|
-
else {
|
|
2219
|
-
report.disagreed += 1;
|
|
2220
|
-
if (report.samples.length < 20) report.samples.push({
|
|
2221
|
-
turn: route.turn,
|
|
2222
|
-
what: clip(route.what(key)),
|
|
2223
|
-
probability: Math.round(probability * 1e3) / 1e3,
|
|
2224
|
-
decision,
|
|
2225
|
-
llm
|
|
2226
|
-
});
|
|
2227
|
-
}
|
|
2228
|
-
}
|
|
2229
|
-
return {
|
|
2230
|
-
verdicts,
|
|
2231
|
-
report
|
|
2232
|
-
};
|
|
2233
|
-
}
|
|
2234
|
-
const decided = await viaDecision();
|
|
2235
|
-
if (decided === void 0) {
|
|
2236
|
-
report.fallbacks = keys.length;
|
|
2237
|
-
await viaLlm(keys);
|
|
2238
|
-
return {
|
|
2239
|
-
verdicts,
|
|
2240
|
-
report
|
|
2241
|
-
};
|
|
2242
|
-
}
|
|
2243
|
-
const unsure = [];
|
|
2244
|
-
for (const key of keys) {
|
|
2245
|
-
const probability = decided.get(key);
|
|
2246
|
-
if (probability === void 0) {
|
|
2247
|
-
unsure.push(key);
|
|
2248
|
-
continue;
|
|
2249
|
-
}
|
|
2250
|
-
if (mode === "hybrid" && probability > route.noAt && probability < route.yesAt) unsure.push(key);
|
|
2251
|
-
else verdicts.set(key, probability >= route.yesAt);
|
|
2252
|
-
}
|
|
2253
|
-
report.decided = keys.length - unsure.length;
|
|
2254
|
-
report.escalated = unsure.length;
|
|
2255
|
-
if (unsure.length > 0) await viaLlm(unsure);
|
|
2452
|
+
const sampling = parseSampling(value["sampling"], `${PRESET_FILE}: sampling`, problems);
|
|
2453
|
+
const title = text("title");
|
|
2454
|
+
const description = text("description");
|
|
2256
2455
|
return {
|
|
2257
|
-
|
|
2258
|
-
|
|
2456
|
+
...title === void 0 ? {} : { title },
|
|
2457
|
+
...description === void 0 ? {} : { description },
|
|
2458
|
+
sampling
|
|
2259
2459
|
};
|
|
2260
2460
|
}
|
|
2261
|
-
|
|
2262
|
-
const
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
*/
|
|
2461
|
+
function readHeader(directory, problems) {
|
|
2462
|
+
const file = join(directory, PRESET_FILE);
|
|
2463
|
+
if (!existsSync(file)) return { sampling: {} };
|
|
2464
|
+
let value;
|
|
2465
|
+
try {
|
|
2466
|
+
value = JSON.parse(readFileSync(file, "utf8"));
|
|
2467
|
+
} catch {
|
|
2468
|
+
problems.push(`${PRESET_FILE} is not valid JSON`);
|
|
2469
|
+
return { sampling: {} };
|
|
2470
|
+
}
|
|
2471
|
+
return parseHeader(value, problems);
|
|
2472
|
+
}
|
|
2473
|
+
/** Reads one preset folder, collecting every problem instead of stopping at the first. @throws {Error} when the folder does not exist. */
|
|
2474
|
+
function readPreset(directory, name, shipped = shippedPromptsDirectory()) {
|
|
2475
|
+
if (!existsSync(directory)) throw new Error(`there is no preset "${name}"`);
|
|
2476
|
+
const problems = [];
|
|
2477
|
+
const header = readHeader(directory, problems);
|
|
2478
|
+
const files = /* @__PURE__ */ new Map();
|
|
2479
|
+
const base = join(directory, PROMPTS_FOLDER);
|
|
2480
|
+
if (existsSync(base)) for (const entry of readdirSync(base, { withFileTypes: true })) {
|
|
2481
|
+
if (!entry.isDirectory() || !LANGUAGE_FOLDER.test(entry.name)) {
|
|
2482
|
+
problems.push(`prompts/${entry.name}: prompts are kept in a folder named by the language, such as en or zh`);
|
|
2483
|
+
continue;
|
|
2484
|
+
}
|
|
2485
|
+
for (const id of listFiles(join(base, entry.name))) {
|
|
2486
|
+
const path = `${entry.name}/${id}.md`;
|
|
2487
|
+
const text = readFileSync(join(base, path), "utf8");
|
|
2488
|
+
const problem = id.startsWith("roleplay/") ? promptProblem(entry.name, id, text, shipped) : `"${id}" is not a prompt of the story`;
|
|
2489
|
+
if (problem !== void 0) problems.push(`prompts/${path}: ${problem}`);
|
|
2490
|
+
else files.set(path, text);
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
if (files.size === 0 && problems.length === 0) problems.push("the preset carries no prompts");
|
|
2494
|
+
const paths = [...files.keys()];
|
|
2495
|
+
const ids = [...new Set(paths.map((path) => path.slice(path.indexOf("/") + 1, -3)))].sort((a, b) => a.localeCompare(b));
|
|
2496
|
+
return {
|
|
2497
|
+
summary: {
|
|
2498
|
+
name,
|
|
2499
|
+
title: header.title ?? name,
|
|
2500
|
+
description: header.description ?? "",
|
|
2501
|
+
languages: [...new Set(paths.map((path) => path.split("/")[0]))].sort((a, b) => a.localeCompare(b)),
|
|
2502
|
+
prompts: ids,
|
|
2503
|
+
rules: ids.filter((id) => !PROSE_PROMPTS.includes(id)),
|
|
2504
|
+
sampling: header.sampling,
|
|
2505
|
+
problems
|
|
2506
|
+
},
|
|
2507
|
+
files
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
/** Every preset in the library; one that cannot be read is listed with its problems. */
|
|
2511
|
+
function listPresets(root) {
|
|
2512
|
+
const folder = presetsDirectory(root);
|
|
2513
|
+
if (!existsSync(folder)) return [];
|
|
2514
|
+
return readdirSync(folder, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isPresetName(entry.name)).map((entry) => readPreset(join(folder, entry.name), entry.name)).sort((a, b) => a.summary.name.localeCompare(b.summary.name));
|
|
2515
|
+
}
|
|
2516
|
+
function loadPreset(root, name) {
|
|
2517
|
+
return readPreset(presetDirectory(root, name), name);
|
|
2518
|
+
}
|
|
2519
|
+
const sha = (text) => createHash("sha256").update(text).digest("hex");
|
|
2520
|
+
/**
|
|
2521
|
+
* Makes a preset of the prose prompts a world carries. Nothing is overwritten.
|
|
2522
|
+
* @throws {Error} when the name is taken, the world carries no prose prompt, or what it carries is not acceptable.
|
|
2523
|
+
*/
|
|
2524
|
+
async function savePresetFromWorld(root, worldDirectory, request) {
|
|
2525
|
+
const target = presetDirectory(root, request.name);
|
|
2526
|
+
if (existsSync(target)) throw new Error(`there is already a preset "${request.name}"`);
|
|
2527
|
+
const source = join(worldDirectory, PROMPTS_FOLDER);
|
|
2528
|
+
const found = [];
|
|
2529
|
+
if (existsSync(source)) {
|
|
2530
|
+
for (const entry of readdirSync(source, { withFileTypes: true })) if (entry.isDirectory() && LANGUAGE_FOLDER.test(entry.name)) {
|
|
2531
|
+
for (const id of listFiles(join(source, entry.name))) if (PROSE_PROMPTS.includes(id)) found.push({
|
|
2532
|
+
language: entry.name,
|
|
2533
|
+
id
|
|
2534
|
+
});
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
if (found.length === 0) throw new Error("the world carries no prose prompts to make a preset of");
|
|
2538
|
+
const staging = join(root, ".install", `preset-${request.name}-${Date.now()}`);
|
|
2539
|
+
try {
|
|
2540
|
+
for (const { language, id } of found) {
|
|
2541
|
+
const to = join(staging, PROMPTS_FOLDER, language, `${id}.md`);
|
|
2542
|
+
await mkdir(dirname(to), { recursive: true });
|
|
2543
|
+
await writeFile(to, readFileSync(join(source, language, `${id}.md`), "utf8"));
|
|
2544
|
+
}
|
|
2545
|
+
const header = {
|
|
2546
|
+
...request.title === void 0 || request.title.trim() === "" ? {} : { title: request.title.trim() },
|
|
2547
|
+
...request.description === void 0 || request.description.trim() === "" ? {} : { description: request.description.trim() },
|
|
2548
|
+
...request.sampling === void 0 || Object.keys(request.sampling).length === 0 ? {} : { sampling: request.sampling }
|
|
2549
|
+
};
|
|
2550
|
+
await writeFile(join(staging, PRESET_FILE), JSON.stringify(header, null, 2));
|
|
2551
|
+
const loaded = readPreset(staging, request.name);
|
|
2552
|
+
if (loaded.summary.problems.length > 0) throw new Error(`the preset would have problems: ${loaded.summary.problems.join("; ")}`);
|
|
2553
|
+
await mkdir(presetsDirectory(root), { recursive: true });
|
|
2554
|
+
await rename(staging, target);
|
|
2555
|
+
return readPreset(target, request.name);
|
|
2556
|
+
} finally {
|
|
2557
|
+
await rm(staging, {
|
|
2558
|
+
recursive: true,
|
|
2559
|
+
force: true
|
|
2560
|
+
});
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
/** Moves a preset out of the library into `<root>/.trash/presets/`. @returns where it went. */
|
|
2564
|
+
async function deletePreset(root, name, now = Date.now) {
|
|
2565
|
+
const directory = presetDirectory(root, name);
|
|
2566
|
+
if (!existsSync(directory)) throw new Error(`there is no preset "${name}"`);
|
|
2567
|
+
const aside = join(root, ".trash", PRESETS_FOLDER, `${name}-${now()}`);
|
|
2568
|
+
await mkdir(dirname(aside), { recursive: true });
|
|
2569
|
+
await rename(directory, aside);
|
|
2570
|
+
return aside;
|
|
2571
|
+
}
|
|
2572
|
+
function headerFile(title, description, sampling) {
|
|
2573
|
+
return `${JSON.stringify({
|
|
2574
|
+
...title === void 0 ? {} : { title },
|
|
2575
|
+
...description === void 0 ? {} : { description },
|
|
2576
|
+
...Object.keys(sampling).length === 0 ? {} : { sampling }
|
|
2577
|
+
}, null, 2)}\n`;
|
|
2578
|
+
}
|
|
2579
|
+
async function writeHeader(directory, text) {
|
|
2580
|
+
const file = join(directory, PRESET_FILE);
|
|
2581
|
+
await writeFile(`${file}.tmp`, text);
|
|
2582
|
+
await rename(`${file}.tmp`, file);
|
|
2583
|
+
}
|
|
2584
|
+
/** Changes what a preset says about itself. @throws {Error} when the preset does not exist or the change is not acceptable; nothing is written then. */
|
|
2585
|
+
async function updatePresetInfo(root, name, change) {
|
|
2586
|
+
const directory = presetDirectory(root, name);
|
|
2587
|
+
if (!existsSync(directory)) throw new Error(`there is no preset "${name}"`);
|
|
2588
|
+
const current = readHeader(directory, []);
|
|
2589
|
+
const problems = [];
|
|
2590
|
+
const next = parseHeader({
|
|
2591
|
+
title: change.title ?? current.title,
|
|
2592
|
+
description: change.description ?? current.description,
|
|
2593
|
+
sampling: change.sampling ?? current.sampling
|
|
2594
|
+
}, problems);
|
|
2595
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
2596
|
+
await writeHeader(directory, headerFile(next.title, next.description, next.sampling));
|
|
2597
|
+
return readPreset(directory, name);
|
|
2598
|
+
}
|
|
2599
|
+
/**
|
|
2600
|
+
* Makes a preset holding the shipped prose prompts of every language, as a starting point to edit. Nothing is overwritten.
|
|
2601
|
+
* @throws {Error} when the name is taken or the information is not acceptable.
|
|
2602
|
+
*/
|
|
2603
|
+
async function createPresetFromShipped(root, request, shipped = shippedPromptsDirectory()) {
|
|
2604
|
+
const target = presetDirectory(root, request.name);
|
|
2605
|
+
if (existsSync(target)) throw new Error(`there is already a preset "${request.name}"`);
|
|
2606
|
+
const problems = [];
|
|
2607
|
+
const header = parseHeader({
|
|
2608
|
+
title: request.title?.trim(),
|
|
2609
|
+
description: request.description?.trim(),
|
|
2610
|
+
sampling: request.sampling
|
|
2611
|
+
}, problems);
|
|
2612
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
2613
|
+
const staging = join(root, ".install", `preset-${request.name}-${Date.now()}`);
|
|
2614
|
+
try {
|
|
2615
|
+
for (const language of shippedLanguages(shipped)) for (const id of PROSE_PROMPTS) {
|
|
2616
|
+
const from = join(shipped, language, `${id}.md`);
|
|
2617
|
+
if (!existsSync(from)) continue;
|
|
2618
|
+
const to = join(staging, PROMPTS_FOLDER, language, `${id}.md`);
|
|
2619
|
+
await mkdir(dirname(to), { recursive: true });
|
|
2620
|
+
await writeFile(to, readFileSync(from, "utf8"));
|
|
2621
|
+
}
|
|
2622
|
+
await mkdir(staging, { recursive: true });
|
|
2623
|
+
await writeHeader(staging, headerFile(header.title, header.description, header.sampling));
|
|
2624
|
+
const loaded = readPreset(staging, request.name);
|
|
2625
|
+
if (loaded.summary.problems.length > 0) throw new Error(`the preset would have problems: ${loaded.summary.problems.join("; ")}`);
|
|
2626
|
+
await mkdir(presetsDirectory(root), { recursive: true });
|
|
2627
|
+
await rename(staging, target);
|
|
2628
|
+
return readPreset(target, request.name);
|
|
2629
|
+
} finally {
|
|
2630
|
+
await rm(staging, {
|
|
2631
|
+
recursive: true,
|
|
2632
|
+
force: true
|
|
2633
|
+
});
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
/** Makes an empty preset folder that the import is about to fill; it has no prompts yet, so it reads as having problems until it does. */
|
|
2637
|
+
async function reservePreset(root, name, title, sampling = {}) {
|
|
2638
|
+
const target = presetDirectory(root, name);
|
|
2639
|
+
if (existsSync(target)) throw new Error(`there is already a preset "${name}"`);
|
|
2640
|
+
await mkdir(target, { recursive: true });
|
|
2641
|
+
await writeHeader(target, headerFile(title.trim().slice(0, MAX_TEXT) || void 0, void 0, sampling));
|
|
2642
|
+
return target;
|
|
2643
|
+
}
|
|
2644
|
+
/**
|
|
2645
|
+
* Makes a preset that adds guidance to the shipped prompts, in every language the program ships: each prompt keeps its shipped text and the guidance follows it, so that
|
|
2646
|
+
* the prompt keeps naming the tools and values it needs. The guidance is the importer's, in the language it was written in.
|
|
2647
|
+
* @throws {Error} when the name is taken, there is no guidance, or a prompt would not be acceptable; nothing is made then.
|
|
2648
|
+
*/
|
|
2649
|
+
async function createPresetFromGuidance(root, request, guidance, shipped = shippedPromptsDirectory()) {
|
|
2650
|
+
const target = presetDirectory(root, request.name);
|
|
2651
|
+
if (existsSync(target)) throw new Error(`there is already a preset "${request.name}"`);
|
|
2652
|
+
const ids = Object.keys(guidance).filter((id) => (guidance[id]?.length ?? 0) > 0);
|
|
2653
|
+
if (ids.length === 0) throw new Error("there is no guidance to make a preset of");
|
|
2654
|
+
const problems = [];
|
|
2655
|
+
const header = parseHeader({
|
|
2656
|
+
title: request.title?.trim(),
|
|
2657
|
+
description: request.description?.trim()
|
|
2658
|
+
}, problems);
|
|
2659
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
2660
|
+
const staging = join(root, ".install", `preset-${request.name}-${Date.now()}`);
|
|
2661
|
+
try {
|
|
2662
|
+
for (const language of shippedLanguages(shipped)) for (const id of ids) {
|
|
2663
|
+
const base = readWorldPrompt(join(staging, "none"), language, id, shipped).text.trimEnd();
|
|
2664
|
+
const to = join(staging, PROMPTS_FOLDER, language, `${id}.md`);
|
|
2665
|
+
await mkdir(dirname(to), { recursive: true });
|
|
2666
|
+
await writeFile(to, `${base}\n\n${(guidance[id] ?? []).join("\n")}\n`);
|
|
2667
|
+
}
|
|
2668
|
+
await writeHeader(staging, headerFile(header.title, header.description, {}));
|
|
2669
|
+
const loaded = readPreset(staging, request.name);
|
|
2670
|
+
if (loaded.summary.problems.length > 0) throw new Error(`the preset would have problems: ${loaded.summary.problems.join("; ")}`);
|
|
2671
|
+
await mkdir(presetsDirectory(root), { recursive: true });
|
|
2672
|
+
await rename(staging, target);
|
|
2673
|
+
return readPreset(target, request.name);
|
|
2674
|
+
} finally {
|
|
2675
|
+
await rm(staging, {
|
|
2676
|
+
recursive: true,
|
|
2677
|
+
force: true
|
|
2678
|
+
});
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
// src/shared/start-questions.ts
|
|
2682
|
+
const START_PLOT_STATUSES = ["dormant", "available"];
|
|
2683
|
+
const questionView = (question) => ({
|
|
2684
|
+
id: question.id,
|
|
2685
|
+
text: question.text,
|
|
2686
|
+
options: question.options.map(({ id, label, description }) => ({
|
|
2687
|
+
id,
|
|
2688
|
+
label,
|
|
2689
|
+
...description === void 0 ? {} : { description }
|
|
2690
|
+
}))
|
|
2691
|
+
});
|
|
2692
|
+
/** What the answers add up to, or why they cannot be combined. A question left unanswered changes nothing. */
|
|
2693
|
+
function combineAnswers(questions, answers) {
|
|
2694
|
+
const problems = [];
|
|
2695
|
+
const effect = {};
|
|
2696
|
+
for (const id of Object.keys(answers)) if (!questions.some((question) => question.id === id)) problems.push(`the world asks no question "${id}"`);
|
|
2697
|
+
const set = (key, value, question) => {
|
|
2698
|
+
if (value === void 0) return;
|
|
2699
|
+
if (effect[key] !== void 0 && effect[key] !== value) problems.push(`the answers disagree about the ${key === "startingTime" ? "starting time" : key === "clockMode" ? "clock" : key}; "${question}" changes it again`);
|
|
2700
|
+
else effect[key] = value;
|
|
2701
|
+
};
|
|
2702
|
+
for (const question of questions) {
|
|
2703
|
+
const answer = answers[question.id];
|
|
2704
|
+
if (answer === void 0) continue;
|
|
2705
|
+
const option = question.options.find((entry) => entry.id === answer);
|
|
2706
|
+
if (option === void 0) {
|
|
2707
|
+
problems.push(`"${answer}" is not an answer to "${question.id}"`);
|
|
2708
|
+
continue;
|
|
2709
|
+
}
|
|
2710
|
+
const found = option.effect;
|
|
2711
|
+
if (found.rules !== void 0) effect.rules = [...effect.rules ?? [], ...found.rules];
|
|
2712
|
+
set("opening", found.opening, question.id);
|
|
2713
|
+
set("startingTime", found.startingTime, question.id);
|
|
2714
|
+
set("clockMode", found.clockMode, question.id);
|
|
2715
|
+
for (const [agent, switches] of Object.entries(found.tools ?? {})) {
|
|
2716
|
+
const merged = { ...effect.tools?.[agent] };
|
|
2717
|
+
for (const [tool, value] of Object.entries(switches)) {
|
|
2718
|
+
if (merged[tool] !== void 0 && merged[tool] !== value) problems.push(`the answers disagree about the tool "${tool}"; "${question.id}" changes it again`);
|
|
2719
|
+
merged[tool] = value;
|
|
2720
|
+
}
|
|
2721
|
+
effect.tools = {
|
|
2722
|
+
...effect.tools,
|
|
2723
|
+
[agent]: merged
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
for (const [plot, status] of Object.entries(found.plots ?? {})) {
|
|
2727
|
+
if (effect.plots?.[plot] !== void 0 && effect.plots[plot] !== status) problems.push(`the answers disagree about the plot "${plot}"; "${question.id}" changes it again`);
|
|
2728
|
+
effect.plots = {
|
|
2729
|
+
...effect.plots,
|
|
2730
|
+
[plot]: status
|
|
2731
|
+
};
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
return {
|
|
2735
|
+
effect,
|
|
2736
|
+
problems
|
|
2737
|
+
};
|
|
2738
|
+
}
|
|
2739
|
+
/** The questions as `world.json` writes them: snake_case keys, and only what an answer sets. */
|
|
2740
|
+
function startQuestionsToFile(questions) {
|
|
2741
|
+
return questions.map((question) => ({
|
|
2742
|
+
id: question.id,
|
|
2743
|
+
text: question.text,
|
|
2744
|
+
options: question.options.map((option) => ({
|
|
2745
|
+
id: option.id,
|
|
2746
|
+
label: option.label,
|
|
2747
|
+
...option.description === void 0 || option.description === "" ? {} : { description: option.description },
|
|
2748
|
+
effect: {
|
|
2749
|
+
...option.effect.rules === void 0 || option.effect.rules.length === 0 ? {} : { rules: option.effect.rules },
|
|
2750
|
+
...option.effect.opening === void 0 ? {} : { opening: option.effect.opening },
|
|
2751
|
+
...option.effect.startingTime === void 0 || option.effect.startingTime === "" ? {} : { starting_time: option.effect.startingTime },
|
|
2752
|
+
...option.effect.clockMode === void 0 ? {} : { clock_mode: option.effect.clockMode },
|
|
2753
|
+
...option.effect.tools === void 0 ? {} : { tools: option.effect.tools },
|
|
2754
|
+
...option.effect.plots === void 0 ? {} : { plots: option.effect.plots }
|
|
2755
|
+
}
|
|
2756
|
+
}))
|
|
2757
|
+
}));
|
|
2758
|
+
}
|
|
2759
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2760
|
+
/** Reads questions sent by the editor: the shape only, since the world file's own reader judges every value when the change is written. */
|
|
2761
|
+
function parseStartQuestionsEdit(value, problems) {
|
|
2762
|
+
if (!Array.isArray(value)) {
|
|
2763
|
+
problems.push("startQuestions must be a list");
|
|
2764
|
+
return;
|
|
2765
|
+
}
|
|
2766
|
+
const questions = [];
|
|
2767
|
+
for (const entry of value) {
|
|
2768
|
+
if (!isObject(entry) || typeof entry["id"] !== "string" || typeof entry["text"] !== "string" || !Array.isArray(entry["options"])) {
|
|
2769
|
+
problems.push("a start question needs an id, a text and a list of options");
|
|
2770
|
+
return;
|
|
2771
|
+
}
|
|
2772
|
+
const options = [];
|
|
2773
|
+
for (const option of entry["options"]) {
|
|
2774
|
+
if (!isObject(option) || typeof option["id"] !== "string" || typeof option["label"] !== "string" || !isObject(option["effect"]) || option["description"] !== void 0 && typeof option["description"] !== "string") {
|
|
2775
|
+
problems.push("an answer needs an id, a label and an effect object, such as {\"id\": \"morning\", \"label\": \"Morning\", \"effect\": {\"startingTime\": \"07:00\"}} (the effect may hold rules, opening, startingTime, clockMode, tools, plots; {} changes nothing)");
|
|
2776
|
+
return;
|
|
2777
|
+
}
|
|
2778
|
+
const effect = option["effect"];
|
|
2779
|
+
const known = {};
|
|
2780
|
+
if (Array.isArray(effect["rules"])) known.rules = effect["rules"].filter((rule) => typeof rule === "string");
|
|
2781
|
+
if (typeof effect["opening"] === "number") known.opening = effect["opening"];
|
|
2782
|
+
if (typeof effect["startingTime"] === "string") known.startingTime = effect["startingTime"];
|
|
2783
|
+
if (effect["clockMode"] === "simulated" || effect["clockMode"] === "real") known.clockMode = effect["clockMode"];
|
|
2784
|
+
if (isObject(effect["tools"])) known.tools = effect["tools"];
|
|
2785
|
+
if (isObject(effect["plots"])) known.plots = effect["plots"];
|
|
2786
|
+
options.push({
|
|
2787
|
+
id: option["id"].trim(),
|
|
2788
|
+
label: option["label"].trim(),
|
|
2789
|
+
...typeof option["description"] === "string" && option["description"].trim() !== "" ? { description: option["description"].trim() } : {},
|
|
2790
|
+
effect: known
|
|
2791
|
+
});
|
|
2792
|
+
}
|
|
2793
|
+
questions.push({
|
|
2794
|
+
id: entry["id"].trim(),
|
|
2795
|
+
text: entry["text"].trim(),
|
|
2796
|
+
options
|
|
2797
|
+
});
|
|
2798
|
+
}
|
|
2799
|
+
return questions;
|
|
2800
|
+
}
|
|
2801
|
+
const MAX_OPENING_CHARS = 2e4;
|
|
2802
|
+
const TEXT_FIELDS = [
|
|
2803
|
+
"name",
|
|
2804
|
+
"description",
|
|
2805
|
+
"opening",
|
|
2806
|
+
"authorName",
|
|
2807
|
+
"authorUrl",
|
|
2808
|
+
"timeZone",
|
|
2809
|
+
"startingTime",
|
|
2810
|
+
"version",
|
|
2811
|
+
"language",
|
|
2812
|
+
"preset"
|
|
2813
|
+
];
|
|
2814
|
+
const LIST_FIELDS = [
|
|
2815
|
+
"tags",
|
|
2816
|
+
"rules",
|
|
2817
|
+
"lorebooks"
|
|
2818
|
+
];
|
|
2819
|
+
/** Reads a body that came from the browser; every field is checked and each problem is reported. */
|
|
2820
|
+
function parseWorldInfoEdit(value) {
|
|
2821
|
+
const problems = [];
|
|
2822
|
+
const input = typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
2823
|
+
if (input === void 0) throw new InvalidEditProblems(["the changes must be an object"]);
|
|
2824
|
+
const edit = {};
|
|
2825
|
+
for (const key of Object.keys(input)) if (!TEXT_FIELDS.includes(key) && !LIST_FIELDS.includes(key) && key !== "alternateOpenings" && key !== "startQuestions" && key !== "tools" && key !== "sampling" && key !== "autonomy") problems.push(`there is no field "${key}"`);
|
|
2826
|
+
for (const key of TEXT_FIELDS) {
|
|
2827
|
+
if (input[key] === void 0) continue;
|
|
2828
|
+
if (typeof input[key] === "string") edit[key] = input[key].trim();
|
|
2829
|
+
else problems.push(`${key} must be text`);
|
|
2830
|
+
}
|
|
2831
|
+
for (const key of LIST_FIELDS) {
|
|
2832
|
+
if (input[key] === void 0) continue;
|
|
2833
|
+
if (Array.isArray(input[key]) && input[key].every((entry) => typeof entry === "string")) edit[key] = input[key].map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
2834
|
+
else problems.push(`${key} must be a list of text`);
|
|
2835
|
+
}
|
|
2836
|
+
if (input["alternateOpenings"] !== void 0) {
|
|
2837
|
+
const list = input["alternateOpenings"];
|
|
2838
|
+
const entries = Array.isArray(list) ? list.map((entry) => typeof entry === "object" && entry !== null ? entry : void 0) : void 0;
|
|
2839
|
+
if (entries === void 0 || entries.some((entry) => entry === void 0 || typeof entry["text"] !== "string" || entry["title"] !== void 0 && typeof entry["title"] !== "string" || entry["character"] !== void 0 && typeof entry["character"] !== "string")) problems.push("alternateOpenings must be a list of { title, text, character? }");
|
|
2840
|
+
else {
|
|
2841
|
+
const kept = entries.map((entry) => ({
|
|
2842
|
+
title: String(entry["title"] ?? "").trim(),
|
|
2843
|
+
text: String(entry["text"]).trim(),
|
|
2844
|
+
...String(entry["character"] ?? "").trim() === "" ? {} : { character: String(entry["character"]).trim() }
|
|
2845
|
+
})).filter((entry) => entry.text !== "");
|
|
2846
|
+
if (kept.length > 30) problems.push(`there are more than 30 alternate openings`);
|
|
2847
|
+
if (kept.some((entry) => entry.text.length > 2e4)) problems.push(`an alternate opening is longer than ${MAX_OPENING_CHARS} characters`);
|
|
2848
|
+
edit["alternateOpenings"] = kept;
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
if (input["startQuestions"] !== void 0) {
|
|
2852
|
+
const questions = parseStartQuestionsEdit(input["startQuestions"], problems);
|
|
2853
|
+
if (questions !== void 0) edit["startQuestions"] = questions;
|
|
2854
|
+
}
|
|
2855
|
+
if (input["tools"] !== void 0) {
|
|
2856
|
+
const board = parseSwitchboard(input["tools"], "tools");
|
|
2857
|
+
if (typeof board === "string") problems.push(board);
|
|
2858
|
+
else edit["tools"] = board;
|
|
2859
|
+
}
|
|
2860
|
+
if (input["autonomy"] !== void 0) {
|
|
2861
|
+
if (typeof input["autonomy"] === "boolean") edit["autonomy"] = input["autonomy"];
|
|
2862
|
+
else problems.push("autonomy must be true or false");
|
|
2863
|
+
}
|
|
2864
|
+
if (input["sampling"] !== void 0) edit["sampling"] = parseSampling(input["sampling"], "sampling", problems);
|
|
2865
|
+
if (typeof edit["version"] === "string" && edit["version"].length > 40) problems.push(`the version is longer than 40 characters`);
|
|
2866
|
+
if (edit["name"] === "") problems.push("the world needs a name");
|
|
2867
|
+
if (typeof edit["name"] === "string" && edit["name"].length > 200) problems.push(`the name is longer than 200 characters`);
|
|
2868
|
+
if (problems.length > 0) throw new InvalidEditProblems(problems);
|
|
2869
|
+
return edit;
|
|
2870
|
+
}
|
|
2871
|
+
// src/host/worlds/world-file.ts
|
|
2872
|
+
const WORLD_FILE_NAME = "world.json";
|
|
2873
|
+
/** `alternate_openings` is a list of `{ title, text, character? }`: other first messages the player may start with, each for any character or for one playable character. */
|
|
2874
|
+
function readAlternateOpenings(reader) {
|
|
2875
|
+
const value = reader.raw("alternate_openings");
|
|
2876
|
+
if (value === void 0 || value === null) return void 0;
|
|
2877
|
+
if (!Array.isArray(value)) {
|
|
2878
|
+
reader.fail("alternate_openings", "must be a list");
|
|
2879
|
+
return;
|
|
2880
|
+
}
|
|
2881
|
+
if (value.length > 30) reader.fail("alternate_openings", `has more than 30 openings`);
|
|
2882
|
+
const openings = [];
|
|
2883
|
+
for (const entry of reader.objects("alternate_openings")) {
|
|
2884
|
+
const text = entry.string("text", { required: true })?.trim();
|
|
2885
|
+
if (text === void 0 || text === "") continue;
|
|
2886
|
+
if (text.length > 2e4) entry.fail("text", `is longer than ${MAX_OPENING_CHARS} characters`);
|
|
2887
|
+
const character = entry.string("character")?.trim();
|
|
2888
|
+
openings.push({
|
|
2889
|
+
title: entry.string("title")?.trim() || text.slice(0, 40),
|
|
2890
|
+
text,
|
|
2891
|
+
...character === void 0 || character === "" ? {} : { character }
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
return openings.length === 0 ? void 0 : openings;
|
|
2895
|
+
}
|
|
2896
|
+
const EFFECT_KEYS = [
|
|
2897
|
+
"rules",
|
|
2898
|
+
"opening",
|
|
2899
|
+
"starting_time",
|
|
2900
|
+
"clock_mode",
|
|
2901
|
+
"tools",
|
|
2902
|
+
"plots"
|
|
2903
|
+
];
|
|
2904
|
+
/** One answer's `effect`: only the allow-listed keys, each checked; an unknown key is refused so an answer can never reach a setting it was not meant to. */
|
|
2905
|
+
function readEffect(entry, openings) {
|
|
2906
|
+
const raw = entry.raw("effect");
|
|
2907
|
+
const effect = {};
|
|
2908
|
+
if (raw === void 0 || raw === null) return effect;
|
|
2909
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
2910
|
+
entry.fail("effect", "must be an object");
|
|
2911
|
+
return effect;
|
|
2912
|
+
}
|
|
2913
|
+
const body = raw;
|
|
2914
|
+
for (const key of Object.keys(body)) if (!EFFECT_KEYS.includes(key)) entry.fail(`effect.${key}`, `is not something an answer can change (${EFFECT_KEYS.join(", ")})`);
|
|
2915
|
+
if (body["rules"] !== void 0) {
|
|
2916
|
+
const rules = Array.isArray(body["rules"]) && body["rules"].every((rule) => typeof rule === "string") ? body["rules"].map((rule) => rule.trim()).filter((rule) => rule !== "") : void 0;
|
|
2917
|
+
if (rules === void 0) entry.fail("effect.rules", "must be a list of rules");
|
|
2918
|
+
else if (rules.some((rule) => rule.length > 300)) entry.fail("effect.rules", `has a rule longer than 300 characters`);
|
|
2919
|
+
else if (rules.length > 0) effect.rules = rules;
|
|
2920
|
+
}
|
|
2921
|
+
if (body["opening"] !== void 0) {
|
|
2922
|
+
if (typeof body["opening"] !== "number" || !Number.isInteger(body["opening"]) || body["opening"] < 0 || body["opening"] >= openings) entry.fail("effect.opening", `must be the position of one of the ${openings} alternate openings`);
|
|
2923
|
+
else effect.opening = body["opening"];
|
|
2924
|
+
}
|
|
2925
|
+
if (body["starting_time"] !== void 0) {
|
|
2926
|
+
if (typeof body["starting_time"] !== "string" || body["starting_time"].trim() === "") entry.fail("effect.starting_time", "must be a local time like 1912-04-14T23:40:00");
|
|
2927
|
+
else effect.startingTime = body["starting_time"].trim();
|
|
2928
|
+
}
|
|
2929
|
+
if (body["clock_mode"] !== void 0) {
|
|
2930
|
+
if (body["clock_mode"] !== "simulated" && body["clock_mode"] !== "real") entry.fail("effect.clock_mode", "must be \"simulated\" or \"real\"");
|
|
2931
|
+
else effect.clockMode = body["clock_mode"];
|
|
2932
|
+
}
|
|
2933
|
+
if (body["tools"] !== void 0) {
|
|
2934
|
+
const board = parseSwitchboard(body["tools"], "tools");
|
|
2935
|
+
if (typeof board === "string") entry.fail("effect.tools", board.replace(/^"tools"\s*/, ""));
|
|
2936
|
+
else if (Object.keys(board).length > 0) effect.tools = board;
|
|
2937
|
+
}
|
|
2938
|
+
if (body["plots"] !== void 0) {
|
|
2939
|
+
const plots = body["plots"];
|
|
2940
|
+
if (typeof plots !== "object" || plots === null || Array.isArray(plots)) entry.fail("effect.plots", "must map plot ids to \"dormant\" or \"available\"");
|
|
2941
|
+
else {
|
|
2942
|
+
const kept = {};
|
|
2943
|
+
for (const [id, status] of Object.entries(plots)) if (status !== "dormant" && status !== "available") entry.fail(`effect.plots.${id}`, `must be one of ${START_PLOT_STATUSES.join(", ")}`);
|
|
2944
|
+
else kept[id] = status;
|
|
2945
|
+
if (Object.keys(kept).length > 0) effect.plots = kept;
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
return effect;
|
|
2949
|
+
}
|
|
2950
|
+
/** `start_questions`: `{ id, text, options: [{ id, label, description?, effect }] }`, asked in the start dialog. */
|
|
2951
|
+
function readStartQuestions(reader, openings) {
|
|
2952
|
+
const value = reader.raw("start_questions");
|
|
2953
|
+
if (value === void 0 || value === null) return void 0;
|
|
2954
|
+
if (!Array.isArray(value)) {
|
|
2955
|
+
reader.fail("start_questions", "must be a list");
|
|
2956
|
+
return;
|
|
2957
|
+
}
|
|
2958
|
+
if (value.length > 8) reader.fail("start_questions", `has more than 8 questions`);
|
|
2959
|
+
const questions = [];
|
|
2960
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2961
|
+
for (const entry of reader.objects("start_questions")) {
|
|
2962
|
+
const id = entry.string("id", { required: true })?.trim();
|
|
2963
|
+
const text = entry.string("text", { required: true })?.trim();
|
|
2964
|
+
if (id === void 0 || text === void 0 || id === "" || text === "") continue;
|
|
2965
|
+
if (seen.has(id)) entry.fail("id", `repeats the question "${id}"`);
|
|
2966
|
+
seen.add(id);
|
|
2967
|
+
if (text.length > 200) entry.fail("text", `is longer than 200 characters`);
|
|
2968
|
+
const raw = entry.raw("options");
|
|
2969
|
+
if (!Array.isArray(raw) || raw.length < 2 || raw.length > 8) {
|
|
2970
|
+
entry.fail("options", `must list 2 to 8 answers`);
|
|
2971
|
+
continue;
|
|
2972
|
+
}
|
|
2973
|
+
const options = [];
|
|
2974
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2975
|
+
for (const option of entry.objects("options")) {
|
|
2976
|
+
const optionId = option.string("id", { required: true })?.trim();
|
|
2977
|
+
const label = option.string("label", { required: true })?.trim();
|
|
2978
|
+
if (optionId === void 0 || label === void 0 || optionId === "" || label === "") continue;
|
|
2979
|
+
if (ids.has(optionId)) option.fail("id", `repeats the answer "${optionId}"`);
|
|
2980
|
+
ids.add(optionId);
|
|
2981
|
+
if (label.length > 200) option.fail("label", `is longer than 200 characters`);
|
|
2982
|
+
const description = option.string("description")?.trim();
|
|
2983
|
+
options.push({
|
|
2984
|
+
id: optionId,
|
|
2985
|
+
label,
|
|
2986
|
+
...description === void 0 || description === "" ? {} : { description },
|
|
2987
|
+
effect: readEffect(option, openings)
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
questions.push({
|
|
2991
|
+
id,
|
|
2992
|
+
text,
|
|
2993
|
+
options
|
|
2994
|
+
});
|
|
2995
|
+
}
|
|
2996
|
+
return questions.length === 0 ? void 0 : questions;
|
|
2997
|
+
}
|
|
2998
|
+
/** `tools`: switches by kind of agent and tool name; a world carried from a version with other tools still loads. */
|
|
2999
|
+
function readTools(reader) {
|
|
3000
|
+
const value = reader.raw("tools");
|
|
3001
|
+
if (value === void 0) return void 0;
|
|
3002
|
+
const board = parseSwitchboard(value, "tools");
|
|
3003
|
+
if (typeof board === "string") {
|
|
3004
|
+
reader.fail("tools", board.replace(/^"tools"\s*/, ""));
|
|
3005
|
+
return;
|
|
3006
|
+
}
|
|
3007
|
+
return Object.keys(board).length === 0 ? void 0 : board;
|
|
3008
|
+
}
|
|
3009
|
+
/** `sampling` is an object of the controls a story's requests may carry (see `StorySampling`). */
|
|
3010
|
+
function readSampling(reader) {
|
|
3011
|
+
const problems = [];
|
|
3012
|
+
const sampling = parseSampling(reader.raw("sampling"), "sampling", problems);
|
|
3013
|
+
for (const problem of problems) reader.fail("sampling", problem.replace(/^sampling\.?/, ""));
|
|
3014
|
+
return Object.keys(sampling).length === 0 ? void 0 : sampling;
|
|
3015
|
+
}
|
|
3016
|
+
/** `rules` is one rule as text, or a list of them; blank ones are left out. */
|
|
3017
|
+
function readRules(reader) {
|
|
3018
|
+
const value = reader.raw("rules");
|
|
3019
|
+
if (value === void 0 || value === null) return void 0;
|
|
3020
|
+
const kept = (typeof value === "string" ? [value] : reader.strings("rules")).map((rule) => rule.trim()).filter((rule) => rule !== "");
|
|
3021
|
+
if (kept.length > 30) reader.fail("rules", `has more than 30 rules`);
|
|
3022
|
+
const long = kept.findIndex((rule) => rule.length > 300);
|
|
3023
|
+
if (long >= 0) reader.fail("rules", `rule ${long + 1} is longer than 300 characters: keep rules short`);
|
|
3024
|
+
return kept.length === 0 ? void 0 : kept;
|
|
3025
|
+
}
|
|
3026
|
+
/** `opening_message` is plain text (one narration), or a list of parts in the order the player reads them. */
|
|
3027
|
+
function readOpening(reader) {
|
|
3028
|
+
const value = reader.raw("opening_message");
|
|
3029
|
+
if (value === void 0 || value === null) return void 0;
|
|
3030
|
+
if (typeof value === "string") return value.trim() === "" ? void 0 : [{
|
|
3031
|
+
type: "narration",
|
|
3032
|
+
text: value.trim()
|
|
3033
|
+
}];
|
|
3034
|
+
if (!Array.isArray(value)) {
|
|
3035
|
+
reader.fail("opening_message", "must be text or a list of parts");
|
|
3036
|
+
return;
|
|
3037
|
+
}
|
|
3038
|
+
const parts = [];
|
|
3039
|
+
for (const part of reader.objects("opening_message")) {
|
|
3040
|
+
const type = part.oneOf("type", ["narration", "utterance"], "narration");
|
|
3041
|
+
const text = part.string("text", { required: true })?.trim();
|
|
3042
|
+
if (text === void 0 || text === "") continue;
|
|
3043
|
+
if (type === "narration") {
|
|
3044
|
+
parts.push({
|
|
3045
|
+
type,
|
|
3046
|
+
text
|
|
3047
|
+
});
|
|
3048
|
+
continue;
|
|
3049
|
+
}
|
|
3050
|
+
const character = part.string("character", { required: true });
|
|
3051
|
+
if (character !== void 0) parts.push({
|
|
3052
|
+
type,
|
|
3053
|
+
character,
|
|
3054
|
+
text
|
|
3055
|
+
});
|
|
3056
|
+
}
|
|
3057
|
+
return parts.length === 0 ? void 0 : parts;
|
|
3058
|
+
}
|
|
3059
|
+
/** `time_zone` (an IANA name) and `starting_time` (an ISO 8601 date and time, in `time_zone` unless it carries an offset). */
|
|
3060
|
+
function readClock(reader) {
|
|
3061
|
+
const timeZone = reader.string("time_zone");
|
|
3062
|
+
if (timeZone !== void 0 && !isTimeZone(timeZone)) {
|
|
3063
|
+
reader.fail("time_zone", `"${timeZone}" is not a time zone: write it like Europe/London or UTC`);
|
|
3064
|
+
return;
|
|
3065
|
+
}
|
|
3066
|
+
const text = reader.string("starting_time");
|
|
3067
|
+
let startingTime;
|
|
3068
|
+
if (text !== void 0) try {
|
|
3069
|
+
startingTime = parseInstant(text, timeZone ?? "UTC");
|
|
3070
|
+
} catch (error) {
|
|
3071
|
+
reader.fail("starting_time", error instanceof Error ? error.message : String(error));
|
|
3072
|
+
return;
|
|
3073
|
+
}
|
|
3074
|
+
return timeZone === void 0 && startingTime === void 0 ? void 0 : {
|
|
3075
|
+
...startingTime === void 0 ? {} : { startingTime },
|
|
3076
|
+
...timeZone === void 0 ? {} : { timeZone }
|
|
3077
|
+
};
|
|
3078
|
+
}
|
|
3079
|
+
function readAuthor(reader) {
|
|
3080
|
+
if (reader === void 0) return void 0;
|
|
3081
|
+
const name = reader.string("name", { required: true });
|
|
3082
|
+
const url = reader.string("url");
|
|
3083
|
+
return name === void 0 ? void 0 : {
|
|
3084
|
+
name,
|
|
3085
|
+
...url === void 0 ? {} : { url }
|
|
3086
|
+
};
|
|
3087
|
+
}
|
|
3088
|
+
function parseWorldFile(text) {
|
|
3089
|
+
const issues = [];
|
|
3090
|
+
const reader = Reader.fromJson(text, issues);
|
|
3091
|
+
if (reader === void 0) return {
|
|
3092
|
+
ok: false,
|
|
3093
|
+
issues
|
|
3094
|
+
};
|
|
3095
|
+
const id = readIdentifier(reader);
|
|
3096
|
+
const name = reader.string("name", { required: true });
|
|
3097
|
+
const description = reader.text("description");
|
|
3098
|
+
const tags = reader.object("metadata")?.strings("tags") ?? [];
|
|
3099
|
+
const author = readAuthor(reader.object("author"));
|
|
3100
|
+
const rawVersion = reader.raw("version");
|
|
3101
|
+
if (rawVersion !== void 0 && rawVersion !== null && typeof rawVersion !== "string" && typeof rawVersion !== "number") reader.fail("version", "must be text or a number");
|
|
3102
|
+
const version = (typeof rawVersion === "string" || typeof rawVersion === "number" ? String(rawVersion).trim() : "") || void 0;
|
|
3103
|
+
if (version !== void 0 && version.length > 40) reader.fail("version", `is longer than 40 characters`);
|
|
3104
|
+
const coverMediaId = reader.string("cover_media_id");
|
|
3105
|
+
const opening = readOpening(reader);
|
|
3106
|
+
const clock = readClock(reader);
|
|
3107
|
+
const variables = readVariableValues(reader);
|
|
3108
|
+
const rules = readRules(reader);
|
|
3109
|
+
const tools = readTools(reader);
|
|
3110
|
+
const autonomyValue = reader.raw("autonomy");
|
|
3111
|
+
if (autonomyValue !== void 0 && autonomyValue !== null && typeof autonomyValue !== "boolean") reader.fail("autonomy", "must be true or false");
|
|
3112
|
+
const autonomy = autonomyValue === true ? true : void 0;
|
|
3113
|
+
const alternateOpenings = readAlternateOpenings(reader);
|
|
3114
|
+
const startQuestions = readStartQuestions(reader, alternateOpenings?.length ?? 0);
|
|
3115
|
+
const narrationVoice = reader.string("narration_voice")?.trim() || void 0;
|
|
3116
|
+
const sampling = readSampling(reader);
|
|
3117
|
+
const languageText = reader.string("language")?.trim() || void 0;
|
|
3118
|
+
if (languageText !== void 0 && !LANGUAGE_TAG.test(languageText)) reader.fail("language", "must be a language tag such as \"en\", \"zh\", \"ja\" or \"pt-BR\"");
|
|
3119
|
+
const language = languageText !== void 0 && LANGUAGE_TAG.test(languageText) ? languageOf(languageText) : void 0;
|
|
3120
|
+
const preset = reader.string("preset")?.trim() || void 0;
|
|
3121
|
+
if (preset !== void 0 && !isPresetName(preset)) reader.fail("preset", "must be the name of a preset: letters, digits, \"-\" and \"_\"");
|
|
3122
|
+
const lorebooks = reader.strings("lorebooks").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
3123
|
+
for (const [index, entry] of lorebooks.entries()) if (!isLorebookName(entry)) reader.fail(`lorebooks[${index}]`, "must be the name of a lorebook: letters, digits, \"-\" and \"_\"");
|
|
3124
|
+
if (name === void 0 || issues.length > 0) return {
|
|
3125
|
+
ok: false,
|
|
3126
|
+
issues
|
|
3127
|
+
};
|
|
3128
|
+
return {
|
|
3129
|
+
ok: true,
|
|
3130
|
+
value: {
|
|
3131
|
+
...id === void 0 ? {} : { id },
|
|
3132
|
+
name,
|
|
3133
|
+
description,
|
|
3134
|
+
tags,
|
|
3135
|
+
...author === void 0 ? {} : { author },
|
|
3136
|
+
...version === void 0 ? {} : { version },
|
|
3137
|
+
...coverMediaId === void 0 ? {} : { coverMediaId },
|
|
3138
|
+
...opening === void 0 ? {} : { opening },
|
|
3139
|
+
...clock === void 0 ? {} : { clock },
|
|
3140
|
+
...variables === void 0 ? {} : { variables },
|
|
3141
|
+
...rules === void 0 ? {} : { rules },
|
|
3142
|
+
...tools === void 0 ? {} : { tools },
|
|
3143
|
+
...autonomy === void 0 ? {} : { autonomy },
|
|
3144
|
+
...alternateOpenings === void 0 ? {} : { alternateOpenings },
|
|
3145
|
+
...startQuestions === void 0 ? {} : { startQuestions },
|
|
3146
|
+
...narrationVoice === void 0 ? {} : { narrationVoice },
|
|
3147
|
+
...sampling === void 0 ? {} : { sampling },
|
|
3148
|
+
...language === void 0 ? {} : { language },
|
|
3149
|
+
...preset === void 0 ? {} : { preset },
|
|
3150
|
+
...lorebooks.length === 0 ? {} : { lorebooks: [...new Set(lorebooks)] }
|
|
3151
|
+
}
|
|
3152
|
+
};
|
|
3153
|
+
}
|
|
3154
|
+
// src/host/decisions/route.ts
|
|
3155
|
+
/** The probability from which a yes is taken as a yes, for the confidence a chat asks. */
|
|
3156
|
+
const yesAt = (confidence) => (1 + confidence) / 2;
|
|
3157
|
+
/** The probability up to which a no is taken as a no. */
|
|
3158
|
+
const noAt = (confidence) => (1 - confidence) / 2;
|
|
3159
|
+
const clip = (text) => text.length > 120 ? `${text.slice(0, 119)}…` : text;
|
|
3160
|
+
const reportOf = (mode, items) => ({
|
|
3161
|
+
mode,
|
|
3162
|
+
items,
|
|
3163
|
+
decided: 0,
|
|
3164
|
+
escalated: 0,
|
|
3165
|
+
fallbacks: 0,
|
|
3166
|
+
agreed: 0,
|
|
3167
|
+
disagreed: 0,
|
|
3168
|
+
decisionMs: 0,
|
|
3169
|
+
llmMs: 0,
|
|
3170
|
+
samples: []
|
|
3171
|
+
});
|
|
3172
|
+
async function timed(run) {
|
|
3173
|
+
const started = performance.now();
|
|
3174
|
+
return {
|
|
3175
|
+
value: await run(),
|
|
3176
|
+
ms: Math.round(performance.now() - started)
|
|
3177
|
+
};
|
|
3178
|
+
}
|
|
3179
|
+
/**
|
|
3180
|
+
* Gives each key a verdict the way its site is set to: from the language model, from the decision model, from the decision model where it
|
|
3181
|
+
* is confident and the language model elsewhere, or from the language model while comparing it with the decision model. A decision model
|
|
3182
|
+
* that cannot be used never stops a story: its keys go to the language model and the report says why.
|
|
3183
|
+
*/
|
|
3184
|
+
async function routeVerdicts(route, signal) {
|
|
3185
|
+
const { mode, keys } = route;
|
|
3186
|
+
const report = reportOf(mode, keys.length);
|
|
3187
|
+
const verdicts = /* @__PURE__ */ new Map();
|
|
3188
|
+
if (keys.length === 0) return {
|
|
3189
|
+
verdicts,
|
|
3190
|
+
report
|
|
3191
|
+
};
|
|
3192
|
+
const viaLlm = async (subset) => {
|
|
3193
|
+
const { value, ms } = await timed(() => route.llm(subset));
|
|
3194
|
+
report.llmMs += ms;
|
|
3195
|
+
for (const [key, verdict] of value) verdicts.set(key, verdict);
|
|
3196
|
+
};
|
|
3197
|
+
const viaDecision = async () => {
|
|
3198
|
+
try {
|
|
3199
|
+
const { value, ms } = await timed(() => route.probabilities(keys));
|
|
3200
|
+
report.decisionMs += ms;
|
|
3201
|
+
return value;
|
|
3202
|
+
} catch (error) {
|
|
3203
|
+
if (signal.aborted) throw error;
|
|
3204
|
+
report.problem = error instanceof Error ? error.message : String(error);
|
|
3205
|
+
return;
|
|
3206
|
+
}
|
|
3207
|
+
};
|
|
3208
|
+
if (mode === "llm") {
|
|
3209
|
+
await viaLlm(keys);
|
|
3210
|
+
return {
|
|
3211
|
+
verdicts,
|
|
3212
|
+
report
|
|
3213
|
+
};
|
|
3214
|
+
}
|
|
3215
|
+
if (mode === "shadow") {
|
|
3216
|
+
const [decided] = await Promise.all([viaDecision(), viaLlm(keys)]);
|
|
3217
|
+
if (decided === void 0) return {
|
|
3218
|
+
verdicts,
|
|
3219
|
+
report
|
|
3220
|
+
};
|
|
3221
|
+
for (const key of keys) {
|
|
3222
|
+
const probability = decided.get(key);
|
|
3223
|
+
const llm = verdicts.get(key);
|
|
3224
|
+
if (probability === void 0 || llm === void 0) continue;
|
|
3225
|
+
const decision = probability >= route.yesAt;
|
|
3226
|
+
if (decision === llm) report.agreed += 1;
|
|
3227
|
+
else {
|
|
3228
|
+
report.disagreed += 1;
|
|
3229
|
+
if (report.samples.length < 20) report.samples.push({
|
|
3230
|
+
turn: route.turn,
|
|
3231
|
+
what: clip(route.what(key)),
|
|
3232
|
+
probability: Math.round(probability * 1e3) / 1e3,
|
|
3233
|
+
decision,
|
|
3234
|
+
llm
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
return {
|
|
3239
|
+
verdicts,
|
|
3240
|
+
report
|
|
3241
|
+
};
|
|
3242
|
+
}
|
|
3243
|
+
const decided = await viaDecision();
|
|
3244
|
+
if (decided === void 0) {
|
|
3245
|
+
report.fallbacks = keys.length;
|
|
3246
|
+
await viaLlm(keys);
|
|
3247
|
+
return {
|
|
3248
|
+
verdicts,
|
|
3249
|
+
report
|
|
3250
|
+
};
|
|
3251
|
+
}
|
|
3252
|
+
const unsure = [];
|
|
3253
|
+
for (const key of keys) {
|
|
3254
|
+
const probability = decided.get(key);
|
|
3255
|
+
if (probability === void 0) {
|
|
3256
|
+
unsure.push(key);
|
|
3257
|
+
continue;
|
|
3258
|
+
}
|
|
3259
|
+
if (mode === "hybrid" && probability > route.noAt && probability < route.yesAt) unsure.push(key);
|
|
3260
|
+
else verdicts.set(key, probability >= route.yesAt);
|
|
3261
|
+
}
|
|
3262
|
+
report.decided = keys.length - unsure.length;
|
|
3263
|
+
report.escalated = unsure.length;
|
|
3264
|
+
if (unsure.length > 0) await viaLlm(unsure);
|
|
3265
|
+
return {
|
|
3266
|
+
verdicts,
|
|
3267
|
+
report
|
|
3268
|
+
};
|
|
3269
|
+
}
|
|
3270
|
+
/** `hybrid` is a default that only does something where a decision model is set up: with none it is the language model alone, and nothing is said, because nothing is wrong. */
|
|
3271
|
+
const modeFor = (mode, service) => mode === "hybrid" && service === void 0 ? "llm" : mode;
|
|
3272
|
+
/** Asks the decision model one yes-or-no question for each key about one state, in a single request; the answers are probabilities of yes. */
|
|
3273
|
+
async function askYesNo(service, state, asks, signal) {
|
|
3274
|
+
const questions = Object.fromEntries(asks.map(({ key, instructions }) => [key, {
|
|
3275
|
+
type: "noul",
|
|
3276
|
+
instructions
|
|
3277
|
+
}]));
|
|
3278
|
+
const { answers } = await service.decide(state, questions, {
|
|
3279
|
+
priority: "background",
|
|
3280
|
+
signal
|
|
3281
|
+
});
|
|
3282
|
+
return new Map(asks.map(({ key }) => [key, answers[key].probability]));
|
|
3283
|
+
}
|
|
3284
|
+
/**
|
|
3285
|
+
* Says once, through `say`, why a site's decision model could not be used, and again only when the reason changes, so that a story
|
|
3286
|
+
* played on without the service does not fill the log.
|
|
3287
|
+
*/
|
|
2279
3288
|
function announceProblem(seen, key, report, say) {
|
|
2280
3289
|
if (report.problem === void 0) {
|
|
2281
3290
|
seen.delete(key);
|
|
@@ -2766,6 +3775,7 @@ const emptyExtracted = () => ({
|
|
|
2766
3775
|
items: [],
|
|
2767
3776
|
lore: [],
|
|
2768
3777
|
prompts: [],
|
|
3778
|
+
rules: [],
|
|
2769
3779
|
variables: [],
|
|
2770
3780
|
casting: [],
|
|
2771
3781
|
commands: [],
|
|
@@ -2955,6 +3965,9 @@ const CHARACTER_SCHEMA = {
|
|
|
2955
3965
|
};
|
|
2956
3966
|
/** The most things one character is given from what the text says it carries. */
|
|
2957
3967
|
const MAX_CARRIED = 12;
|
|
3968
|
+
const unplacedNote = (character, place) => `${character}: the place "${place}" is not one of the world's places, so the character starts nowhere`;
|
|
3969
|
+
/** Maximum inferred starting places created during one import. */
|
|
3970
|
+
const MAX_STARTING_PLACES = 3;
|
|
2958
3971
|
/** The document of a character file from what the call answered; names of places and characters become the keys they have in the roster. */
|
|
2959
3972
|
function characterDocument(entity, answer, roster) {
|
|
2960
3973
|
const notes = [];
|
|
@@ -2992,7 +4005,8 @@ function characterDocument(entity, answer, roster) {
|
|
|
2992
4005
|
["activity", "activity"]
|
|
2993
4006
|
]) put(start, to, text(given[from]));
|
|
2994
4007
|
const place = text(given["location"]) === "" ? void 0 : findEntity(roster, text(given["location"]), "place");
|
|
2995
|
-
|
|
4008
|
+
const unplaced = text(given["location"]) !== "" && place === void 0 ? text(given["location"]) : void 0;
|
|
4009
|
+
if (unplaced !== void 0) notes.push(unplacedNote(entity.name, unplaced));
|
|
2996
4010
|
if (place !== void 0) {
|
|
2997
4011
|
start["location"] = place.key;
|
|
2998
4012
|
put(start, "position", text(given["position"]));
|
|
@@ -3053,6 +4067,7 @@ function characterDocument(entity, answer, roster) {
|
|
|
3053
4067
|
return {
|
|
3054
4068
|
document,
|
|
3055
4069
|
notes,
|
|
4070
|
+
...unplaced === void 0 ? {} : { unplaced },
|
|
3056
4071
|
...carried.length === 0 ? {} : { carried }
|
|
3057
4072
|
};
|
|
3058
4073
|
}
|
|
@@ -3584,6 +4599,55 @@ function jobFor(text, tr, entity, sources, roster, card) {
|
|
|
3584
4599
|
}
|
|
3585
4600
|
};
|
|
3586
4601
|
}
|
|
4602
|
+
/** Creates missing places named by character starting locations. */
|
|
4603
|
+
async function startingPlaces(ctx, card, items, classified, roster, results) {
|
|
4604
|
+
const wanted = /* @__PURE__ */ new Map();
|
|
4605
|
+
for (const { built } of results) {
|
|
4606
|
+
const name = built?.unplaced;
|
|
4607
|
+
if (name === void 0 || /[[\]{}]/.test(name) || name.length > 100 || roster.some((other) => other.kind === "character" && norm(other.name) === norm(name))) continue;
|
|
4608
|
+
const found = wanted.get(norm(name)) ?? {
|
|
4609
|
+
name,
|
|
4610
|
+
who: []
|
|
4611
|
+
};
|
|
4612
|
+
found.who.push(built);
|
|
4613
|
+
wanted.set(norm(name), found);
|
|
4614
|
+
}
|
|
4615
|
+
const made = [];
|
|
4616
|
+
const keys = new Set(roster.map((other) => other.key));
|
|
4617
|
+
for (const { name, who } of [...wanted.values()].slice(0, MAX_STARTING_PLACES)) {
|
|
4618
|
+
const entity = {
|
|
4619
|
+
kind: "place",
|
|
4620
|
+
key: uniqueKey(slug(name, "place"), keys),
|
|
4621
|
+
name,
|
|
4622
|
+
aliases: [],
|
|
4623
|
+
player: false
|
|
4624
|
+
};
|
|
4625
|
+
keys.add(entity.key);
|
|
4626
|
+
const known = [
|
|
4627
|
+
...roster,
|
|
4628
|
+
...made.map((each) => each.entity),
|
|
4629
|
+
entity
|
|
4630
|
+
];
|
|
4631
|
+
ctx.say(`writing place: ${name}`);
|
|
4632
|
+
try {
|
|
4633
|
+
const answer = await ctx.run(jobFor(ctx.text, trOf(ctx), entity, sourcesFor(entity, items, classified), known, card));
|
|
4634
|
+
made.push({
|
|
4635
|
+
entity,
|
|
4636
|
+
built: placeDocument(entity, answer, known)
|
|
4637
|
+
});
|
|
4638
|
+
} catch (error) {
|
|
4639
|
+
for (const character of who) character.notes.push(`${name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
4640
|
+
continue;
|
|
4641
|
+
}
|
|
4642
|
+
for (const character of who) {
|
|
4643
|
+
const start = character.document["start"];
|
|
4644
|
+
start["location"] = entity.key;
|
|
4645
|
+
const at = character.notes.indexOf(unplacedNote(String(character.document["name"]), name));
|
|
4646
|
+
if (at >= 0) character.notes.splice(at, 1);
|
|
4647
|
+
}
|
|
4648
|
+
}
|
|
4649
|
+
return made;
|
|
4650
|
+
}
|
|
3587
4651
|
/** Makes the documents of every entity of the roster, and the lore from the pieces about the world. */
|
|
3588
4652
|
async function extractEntities(ctx, card, items, classified, roster) {
|
|
3589
4653
|
const result = emptyExtracted();
|
|
@@ -3608,6 +4672,7 @@ async function extractEntities(ctx, card, items, classified, roster) {
|
|
|
3608
4672
|
};
|
|
3609
4673
|
}
|
|
3610
4674
|
});
|
|
4675
|
+
entityResults.push(...await startingPlaces(ctx, card, items, classified, roster, entityResults));
|
|
3611
4676
|
for (const { entity, built, failure } of entityResults) {
|
|
3612
4677
|
if (failure !== void 0 || built === void 0) {
|
|
3613
4678
|
result.notes.push(failure ?? `${entity.name}: nothing was written`);
|
|
@@ -3756,7 +4821,12 @@ const STYLE_SCHEMA = {
|
|
|
3756
4821
|
left_out: {
|
|
3757
4822
|
type: "array",
|
|
3758
4823
|
items: { type: "string" },
|
|
3759
|
-
description: "What the instructions contained that is not prose or behaviour guidance (rules of the game, formats, panels, scripts), one short phrase each."
|
|
4824
|
+
description: "What the instructions contained that is not prose or behaviour guidance (rules of the game, formats, panels, scripts), one short phrase each."
|
|
4825
|
+
},
|
|
4826
|
+
world_rules: {
|
|
4827
|
+
type: "array",
|
|
4828
|
+
items: { type: "string" },
|
|
4829
|
+
description: "The rules of the world the instructions lay down: what exists, does not exist or may not happen in the story (for example \"there are no firearms\"), one short sentence each, in the language of the instructions, as faithfully as they say it. Not style, not formats, not anything about the player or tools. Empty when there are none."
|
|
3760
4830
|
},
|
|
3761
4831
|
persona_names: {
|
|
3762
4832
|
type: "array",
|
|
@@ -3767,6 +4837,7 @@ const STYLE_SCHEMA = {
|
|
|
3767
4837
|
required: [
|
|
3768
4838
|
"narration",
|
|
3769
4839
|
"characters",
|
|
4840
|
+
"world_rules",
|
|
3770
4841
|
"left_out",
|
|
3771
4842
|
"persona_names"
|
|
3772
4843
|
]
|
|
@@ -3778,6 +4849,11 @@ function instructionPieces(card, items, classified) {
|
|
|
3778
4849
|
const pieces = items.filter((item) => mainRole(classified[item.id] ?? { roles: [] }) === "instruction").map((item) => item.text);
|
|
3779
4850
|
return [...fields, ...pieces];
|
|
3780
4851
|
}
|
|
4852
|
+
function ruleProblem(rules) {
|
|
4853
|
+
if (rules.length > 30) return `world_rules has ${rules.length} rules; keep the 30 that matter most`;
|
|
4854
|
+
const long = rules.find((rule) => rule.length > 300);
|
|
4855
|
+
return long === void 0 ? void 0 : `a world rule is ${long.length} characters long; each is one sentence of at most 300`;
|
|
4856
|
+
}
|
|
3781
4857
|
function styleProblem(id, value, personas = []) {
|
|
3782
4858
|
const named = personas.find((name) => name.trim() !== "" && value.toLowerCase().includes(name.trim().toLowerCase()));
|
|
3783
4859
|
if (named !== void 0) return `${id} uses the persona name "${named}"; say "the character" or "the narrator" instead`;
|
|
@@ -3791,17 +4867,22 @@ async function extractStyle(ctx, card, items, classified) {
|
|
|
3791
4867
|
const pieces = piecesOfTexts(card, items, texts);
|
|
3792
4868
|
return {
|
|
3793
4869
|
...made,
|
|
3794
|
-
derived: made.prompts.map((prompt) => ({
|
|
4870
|
+
derived: [...made.prompts.map((prompt) => ({
|
|
3795
4871
|
kind: "prompt",
|
|
3796
4872
|
name: prompt.id,
|
|
3797
4873
|
pieces
|
|
3798
|
-
}))
|
|
4874
|
+
})), ...made.rules.length === 0 ? [] : [{
|
|
4875
|
+
kind: "rules",
|
|
4876
|
+
name: "world rules",
|
|
4877
|
+
pieces
|
|
4878
|
+
}]]
|
|
3799
4879
|
};
|
|
3800
4880
|
}
|
|
3801
4881
|
/** The prose prompts that instruction texts become, and what was left out of them. */
|
|
3802
4882
|
async function extractStyleFrom(ctx, name, pieces) {
|
|
3803
4883
|
if (pieces.length === 0) return {
|
|
3804
4884
|
prompts: [],
|
|
4885
|
+
rules: [],
|
|
3805
4886
|
notes: []
|
|
3806
4887
|
};
|
|
3807
4888
|
ctx.say("writing the style prompts");
|
|
@@ -3813,7 +4894,7 @@ async function extractStyleFrom(ctx, name, pieces) {
|
|
|
3813
4894
|
maxTokens: 8e3,
|
|
3814
4895
|
prompt,
|
|
3815
4896
|
result: STYLE_SCHEMA,
|
|
3816
|
-
check: (value) => styleProblem("roleplay/style", text(value.narration), list(value.persona_names)) ?? styleProblem("roleplay/character-style", text(value.characters), list(value.persona_names))
|
|
4897
|
+
check: (value) => styleProblem("roleplay/style", text(value.narration), list(value.persona_names)) ?? styleProblem("roleplay/character-style", text(value.characters), list(value.persona_names)) ?? ruleProblem(list(value.world_rules))
|
|
3817
4898
|
});
|
|
3818
4899
|
const leftOut = list(answer.left_out);
|
|
3819
4900
|
const prompts = [["roleplay/style", withoutLeftOut(text(answer.narration), leftOut)], ["roleplay/character-style", withoutLeftOut(text(answer.characters), leftOut)]].flatMap(([id, body]) => body === "" ? [] : [{
|
|
@@ -3823,11 +4904,13 @@ async function extractStyleFrom(ctx, name, pieces) {
|
|
|
3823
4904
|
if (!prompts.every((entry) => PROSE_PROMPTS.includes(entry.id))) throw new Error("only prose prompts can be made");
|
|
3824
4905
|
return {
|
|
3825
4906
|
prompts,
|
|
4907
|
+
rules: list(answer.world_rules).map(withoutOutputMarkup).filter((rule) => rule.trim() !== ""),
|
|
3826
4908
|
notes: list(answer.left_out).map((entry) => `instructions left out on purpose: ${entry}`)
|
|
3827
4909
|
};
|
|
3828
4910
|
} catch (error) {
|
|
3829
4911
|
return {
|
|
3830
4912
|
prompts: [],
|
|
4913
|
+
rules: [],
|
|
3831
4914
|
notes: [`the instructions of the card were not carried over: ${error instanceof Error ? error.message : String(error)}`]
|
|
3832
4915
|
};
|
|
3833
4916
|
}
|
|
@@ -4092,261 +5175,29 @@ async function extractVariables(ctx, card, items, classified, roster) {
|
|
|
4092
5175
|
derived
|
|
4093
5176
|
};
|
|
4094
5177
|
}
|
|
4095
|
-
// src/host/
|
|
4096
|
-
const PRESETS_FOLDER = "presets";
|
|
4097
|
-
const PRESET_FILE = "preset.json";
|
|
4098
|
-
const NAME = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
4099
|
-
const MAX_TEXT = 300;
|
|
4100
|
-
const isPresetName = (name) => NAME.test(name);
|
|
4101
|
-
const presetsDirectory = (root) => join(root, PRESETS_FOLDER);
|
|
4102
|
-
function presetDirectory(root, name) {
|
|
4103
|
-
if (!isPresetName(name)) throw new Error(`"${name}" is not a usable preset name (letters, digits, "-" and "_", up to 64)`);
|
|
4104
|
-
return join(presetsDirectory(root), name);
|
|
4105
|
-
}
|
|
4106
|
-
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4107
|
-
function parseHeader(value, problems) {
|
|
4108
|
-
if (!isRecord(value)) {
|
|
4109
|
-
problems.push(`${PRESET_FILE} must be an object`);
|
|
4110
|
-
return { sampling: {} };
|
|
4111
|
-
}
|
|
4112
|
-
const text = (key) => {
|
|
4113
|
-
const field = value[key];
|
|
4114
|
-
if (field === void 0 || field === null) return void 0;
|
|
4115
|
-
if (typeof field !== "string" || field.length > MAX_TEXT) {
|
|
4116
|
-
problems.push(`${PRESET_FILE}: "${key}" must be text of at most ${MAX_TEXT} characters`);
|
|
4117
|
-
return;
|
|
4118
|
-
}
|
|
4119
|
-
return field.trim() || void 0;
|
|
4120
|
-
};
|
|
4121
|
-
const sampling = parseSampling(value["sampling"], `${PRESET_FILE}: sampling`, problems);
|
|
4122
|
-
const title = text("title");
|
|
4123
|
-
const description = text("description");
|
|
4124
|
-
return {
|
|
4125
|
-
...title === void 0 ? {} : { title },
|
|
4126
|
-
...description === void 0 ? {} : { description },
|
|
4127
|
-
sampling
|
|
4128
|
-
};
|
|
4129
|
-
}
|
|
4130
|
-
function readHeader(directory, problems) {
|
|
4131
|
-
const file = join(directory, PRESET_FILE);
|
|
4132
|
-
if (!existsSync(file)) return { sampling: {} };
|
|
4133
|
-
let value;
|
|
4134
|
-
try {
|
|
4135
|
-
value = JSON.parse(readFileSync(file, "utf8"));
|
|
4136
|
-
} catch {
|
|
4137
|
-
problems.push(`${PRESET_FILE} is not valid JSON`);
|
|
4138
|
-
return { sampling: {} };
|
|
4139
|
-
}
|
|
4140
|
-
return parseHeader(value, problems);
|
|
4141
|
-
}
|
|
4142
|
-
/** Reads one preset folder, collecting every problem instead of stopping at the first. @throws {Error} when the folder does not exist. */
|
|
4143
|
-
function readPreset(directory, name, shipped = shippedPromptsDirectory()) {
|
|
4144
|
-
if (!existsSync(directory)) throw new Error(`there is no preset "${name}"`);
|
|
4145
|
-
const problems = [];
|
|
4146
|
-
const header = readHeader(directory, problems);
|
|
4147
|
-
const files = /* @__PURE__ */ new Map();
|
|
4148
|
-
const base = join(directory, PROMPTS_FOLDER);
|
|
4149
|
-
if (existsSync(base)) for (const entry of readdirSync(base, { withFileTypes: true })) {
|
|
4150
|
-
if (!entry.isDirectory() || !LANGUAGE_FOLDER.test(entry.name)) {
|
|
4151
|
-
problems.push(`prompts/${entry.name}: prompts are kept in a folder named by the language, such as en or zh`);
|
|
4152
|
-
continue;
|
|
4153
|
-
}
|
|
4154
|
-
for (const id of listFiles(join(base, entry.name))) {
|
|
4155
|
-
const path = `${entry.name}/${id}.md`;
|
|
4156
|
-
const text = readFileSync(join(base, path), "utf8");
|
|
4157
|
-
const problem = id.startsWith("roleplay/") ? promptProblem(entry.name, id, text, shipped) : `"${id}" is not a prompt of the story`;
|
|
4158
|
-
if (problem !== void 0) problems.push(`prompts/${path}: ${problem}`);
|
|
4159
|
-
else files.set(path, text);
|
|
4160
|
-
}
|
|
4161
|
-
}
|
|
4162
|
-
if (files.size === 0 && problems.length === 0) problems.push("the preset carries no prompts");
|
|
4163
|
-
const paths = [...files.keys()];
|
|
4164
|
-
const ids = [...new Set(paths.map((path) => path.slice(path.indexOf("/") + 1, -3)))].sort((a, b) => a.localeCompare(b));
|
|
4165
|
-
return {
|
|
4166
|
-
summary: {
|
|
4167
|
-
name,
|
|
4168
|
-
title: header.title ?? name,
|
|
4169
|
-
description: header.description ?? "",
|
|
4170
|
-
languages: [...new Set(paths.map((path) => path.split("/")[0]))].sort((a, b) => a.localeCompare(b)),
|
|
4171
|
-
prompts: ids,
|
|
4172
|
-
rules: ids.filter((id) => !PROSE_PROMPTS.includes(id)),
|
|
4173
|
-
sampling: header.sampling,
|
|
4174
|
-
problems
|
|
4175
|
-
},
|
|
4176
|
-
files
|
|
4177
|
-
};
|
|
4178
|
-
}
|
|
4179
|
-
/** Every preset in the library; one that cannot be read is listed with its problems. */
|
|
4180
|
-
function listPresets(root) {
|
|
4181
|
-
const folder = presetsDirectory(root);
|
|
4182
|
-
if (!existsSync(folder)) return [];
|
|
4183
|
-
return readdirSync(folder, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isPresetName(entry.name)).map((entry) => readPreset(join(folder, entry.name), entry.name)).sort((a, b) => a.summary.name.localeCompare(b.summary.name));
|
|
4184
|
-
}
|
|
4185
|
-
function loadPreset(root, name) {
|
|
4186
|
-
return readPreset(presetDirectory(root, name), name);
|
|
4187
|
-
}
|
|
4188
|
-
const sha = (text) => createHash("sha256").update(text).digest("hex");
|
|
4189
|
-
/**
|
|
4190
|
-
* Makes a preset of the prose prompts a world carries. Nothing is overwritten.
|
|
4191
|
-
* @throws {Error} when the name is taken, the world carries no prose prompt, or what it carries is not acceptable.
|
|
4192
|
-
*/
|
|
4193
|
-
async function savePresetFromWorld(root, worldDirectory, request) {
|
|
4194
|
-
const target = presetDirectory(root, request.name);
|
|
4195
|
-
if (existsSync(target)) throw new Error(`there is already a preset "${request.name}"`);
|
|
4196
|
-
const source = join(worldDirectory, PROMPTS_FOLDER);
|
|
4197
|
-
const found = [];
|
|
4198
|
-
if (existsSync(source)) {
|
|
4199
|
-
for (const entry of readdirSync(source, { withFileTypes: true })) if (entry.isDirectory() && LANGUAGE_FOLDER.test(entry.name)) {
|
|
4200
|
-
for (const id of listFiles(join(source, entry.name))) if (PROSE_PROMPTS.includes(id)) found.push({
|
|
4201
|
-
language: entry.name,
|
|
4202
|
-
id
|
|
4203
|
-
});
|
|
4204
|
-
}
|
|
4205
|
-
}
|
|
4206
|
-
if (found.length === 0) throw new Error("the world carries no prose prompts to make a preset of");
|
|
4207
|
-
const staging = join(root, ".install", `preset-${request.name}-${Date.now()}`);
|
|
4208
|
-
try {
|
|
4209
|
-
for (const { language, id } of found) {
|
|
4210
|
-
const to = join(staging, PROMPTS_FOLDER, language, `${id}.md`);
|
|
4211
|
-
await mkdir(dirname(to), { recursive: true });
|
|
4212
|
-
await writeFile(to, readFileSync(join(source, language, `${id}.md`), "utf8"));
|
|
4213
|
-
}
|
|
4214
|
-
const header = {
|
|
4215
|
-
...request.title === void 0 || request.title.trim() === "" ? {} : { title: request.title.trim() },
|
|
4216
|
-
...request.description === void 0 || request.description.trim() === "" ? {} : { description: request.description.trim() },
|
|
4217
|
-
...request.sampling === void 0 || Object.keys(request.sampling).length === 0 ? {} : { sampling: request.sampling }
|
|
4218
|
-
};
|
|
4219
|
-
await writeFile(join(staging, PRESET_FILE), JSON.stringify(header, null, 2));
|
|
4220
|
-
const loaded = readPreset(staging, request.name);
|
|
4221
|
-
if (loaded.summary.problems.length > 0) throw new Error(`the preset would have problems: ${loaded.summary.problems.join("; ")}`);
|
|
4222
|
-
await mkdir(presetsDirectory(root), { recursive: true });
|
|
4223
|
-
await rename(staging, target);
|
|
4224
|
-
return readPreset(target, request.name);
|
|
4225
|
-
} finally {
|
|
4226
|
-
await rm(staging, {
|
|
4227
|
-
recursive: true,
|
|
4228
|
-
force: true
|
|
4229
|
-
});
|
|
4230
|
-
}
|
|
4231
|
-
}
|
|
4232
|
-
/** Moves a preset out of the library into `<root>/.trash/presets/`. @returns where it went. */
|
|
4233
|
-
async function deletePreset(root, name, now = Date.now) {
|
|
4234
|
-
const directory = presetDirectory(root, name);
|
|
4235
|
-
if (!existsSync(directory)) throw new Error(`there is no preset "${name}"`);
|
|
4236
|
-
const aside = join(root, ".trash", PRESETS_FOLDER, `${name}-${now()}`);
|
|
4237
|
-
await mkdir(dirname(aside), { recursive: true });
|
|
4238
|
-
await rename(directory, aside);
|
|
4239
|
-
return aside;
|
|
4240
|
-
}
|
|
4241
|
-
function headerFile(title, description, sampling) {
|
|
4242
|
-
return `${JSON.stringify({
|
|
4243
|
-
...title === void 0 ? {} : { title },
|
|
4244
|
-
...description === void 0 ? {} : { description },
|
|
4245
|
-
...Object.keys(sampling).length === 0 ? {} : { sampling }
|
|
4246
|
-
}, null, 2)}\n`;
|
|
4247
|
-
}
|
|
4248
|
-
async function writeHeader(directory, text) {
|
|
4249
|
-
const file = join(directory, PRESET_FILE);
|
|
4250
|
-
await writeFile(`${file}.tmp`, text);
|
|
4251
|
-
await rename(`${file}.tmp`, file);
|
|
4252
|
-
}
|
|
4253
|
-
/** Changes what a preset says about itself. @throws {Error} when the preset does not exist or the change is not acceptable; nothing is written then. */
|
|
4254
|
-
async function updatePresetInfo(root, name, change) {
|
|
4255
|
-
const directory = presetDirectory(root, name);
|
|
4256
|
-
if (!existsSync(directory)) throw new Error(`there is no preset "${name}"`);
|
|
4257
|
-
const current = readHeader(directory, []);
|
|
4258
|
-
const problems = [];
|
|
4259
|
-
const next = parseHeader({
|
|
4260
|
-
title: change.title ?? current.title,
|
|
4261
|
-
description: change.description ?? current.description,
|
|
4262
|
-
sampling: change.sampling ?? current.sampling
|
|
4263
|
-
}, problems);
|
|
4264
|
-
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
4265
|
-
await writeHeader(directory, headerFile(next.title, next.description, next.sampling));
|
|
4266
|
-
return readPreset(directory, name);
|
|
4267
|
-
}
|
|
5178
|
+
// src/host/serial.ts
|
|
4268
5179
|
/**
|
|
4269
|
-
*
|
|
4270
|
-
*
|
|
5180
|
+
* One job at a time per key. Everything asked for a key runs after what was asked before it, and a failure does not stop
|
|
5181
|
+
* the work that follows: the next caller is told about its own failure, not the previous one. The key is forgotten once
|
|
5182
|
+
* nothing is waiting, so a host that has seen many sessions does not keep them all.
|
|
4271
5183
|
*/
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
4282
|
-
const staging = join(root, ".install", `preset-${request.name}-${Date.now()}`);
|
|
4283
|
-
try {
|
|
4284
|
-
for (const language of shippedLanguages(shipped)) for (const id of PROSE_PROMPTS) {
|
|
4285
|
-
const from = join(shipped, language, `${id}.md`);
|
|
4286
|
-
if (!existsSync(from)) continue;
|
|
4287
|
-
const to = join(staging, PROMPTS_FOLDER, language, `${id}.md`);
|
|
4288
|
-
await mkdir(dirname(to), { recursive: true });
|
|
4289
|
-
await writeFile(to, readFileSync(from, "utf8"));
|
|
4290
|
-
}
|
|
4291
|
-
await mkdir(staging, { recursive: true });
|
|
4292
|
-
await writeHeader(staging, headerFile(header.title, header.description, header.sampling));
|
|
4293
|
-
const loaded = readPreset(staging, request.name);
|
|
4294
|
-
if (loaded.summary.problems.length > 0) throw new Error(`the preset would have problems: ${loaded.summary.problems.join("; ")}`);
|
|
4295
|
-
await mkdir(presetsDirectory(root), { recursive: true });
|
|
4296
|
-
await rename(staging, target);
|
|
4297
|
-
return readPreset(target, request.name);
|
|
4298
|
-
} finally {
|
|
4299
|
-
await rm(staging, {
|
|
4300
|
-
recursive: true,
|
|
4301
|
-
force: true
|
|
5184
|
+
var SerialQueue = class {
|
|
5185
|
+
tails = /* @__PURE__ */ new Map();
|
|
5186
|
+
/** Runs `work` after the work asked for `key` before it, and resolves with its result. */
|
|
5187
|
+
run(key, work) {
|
|
5188
|
+
const run = (this.tails.get(key) ?? Promise.resolve()).then(work, work);
|
|
5189
|
+
const tail = run.then(() => void 0, () => void 0);
|
|
5190
|
+
this.tails.set(key, tail);
|
|
5191
|
+
tail.then(() => {
|
|
5192
|
+
if (this.tails.get(key) === tail) this.tails.delete(key);
|
|
4302
5193
|
});
|
|
5194
|
+
return run;
|
|
4303
5195
|
}
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
const target = presetDirectory(root, name);
|
|
4308
|
-
if (existsSync(target)) throw new Error(`there is already a preset "${name}"`);
|
|
4309
|
-
await mkdir(target, { recursive: true });
|
|
4310
|
-
await writeHeader(target, headerFile(title.trim().slice(0, MAX_TEXT) || void 0, void 0, sampling));
|
|
4311
|
-
return target;
|
|
4312
|
-
}
|
|
4313
|
-
/**
|
|
4314
|
-
* Makes a preset that adds guidance to the shipped prompts, in every language the program ships: each prompt keeps its shipped text and the guidance follows it, so that
|
|
4315
|
-
* the prompt keeps naming the tools and values it needs. The guidance is the importer's, in the language it was written in.
|
|
4316
|
-
* @throws {Error} when the name is taken, there is no guidance, or a prompt would not be acceptable; nothing is made then.
|
|
4317
|
-
*/
|
|
4318
|
-
async function createPresetFromGuidance(root, request, guidance, shipped = shippedPromptsDirectory()) {
|
|
4319
|
-
const target = presetDirectory(root, request.name);
|
|
4320
|
-
if (existsSync(target)) throw new Error(`there is already a preset "${request.name}"`);
|
|
4321
|
-
const ids = Object.keys(guidance).filter((id) => (guidance[id]?.length ?? 0) > 0);
|
|
4322
|
-
if (ids.length === 0) throw new Error("there is no guidance to make a preset of");
|
|
4323
|
-
const problems = [];
|
|
4324
|
-
const header = parseHeader({
|
|
4325
|
-
title: request.title?.trim(),
|
|
4326
|
-
description: request.description?.trim()
|
|
4327
|
-
}, problems);
|
|
4328
|
-
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
4329
|
-
const staging = join(root, ".install", `preset-${request.name}-${Date.now()}`);
|
|
4330
|
-
try {
|
|
4331
|
-
for (const language of shippedLanguages(shipped)) for (const id of ids) {
|
|
4332
|
-
const base = readWorldPrompt(join(staging, "none"), language, id, shipped).text.trimEnd();
|
|
4333
|
-
const to = join(staging, PROMPTS_FOLDER, language, `${id}.md`);
|
|
4334
|
-
await mkdir(dirname(to), { recursive: true });
|
|
4335
|
-
await writeFile(to, `${base}\n\n${(guidance[id] ?? []).join("\n")}\n`);
|
|
4336
|
-
}
|
|
4337
|
-
await writeHeader(staging, headerFile(header.title, header.description, {}));
|
|
4338
|
-
const loaded = readPreset(staging, request.name);
|
|
4339
|
-
if (loaded.summary.problems.length > 0) throw new Error(`the preset would have problems: ${loaded.summary.problems.join("; ")}`);
|
|
4340
|
-
await mkdir(presetsDirectory(root), { recursive: true });
|
|
4341
|
-
await rename(staging, target);
|
|
4342
|
-
return readPreset(target, request.name);
|
|
4343
|
-
} finally {
|
|
4344
|
-
await rm(staging, {
|
|
4345
|
-
recursive: true,
|
|
4346
|
-
force: true
|
|
4347
|
-
});
|
|
5196
|
+
/** How many keys have work waiting or running; for tests and diagnostics. */
|
|
5197
|
+
get pending() {
|
|
5198
|
+
return this.tails.size;
|
|
4348
5199
|
}
|
|
4349
|
-
}
|
|
4350
|
-
export {
|
|
5200
|
+
};
|
|
5201
|
+
export { deleteWorldPrompt as $, subfolders as $t, routeVerdicts as A, parseAuthoringCommand as At, createPresetFromGuidance as B, loadLore as Bt, ROLE_TABLE as C, PICTURE_FILE as Ct, mergeReports as D, writeChoices as Dt, askYesNo as E, readImportFolder as Et, parseWorldInfoEdit as F, VARIABLES_FILE_NAME as Ft, loadPreset as G, ITEM_FILE_NAME as Gt, deletePreset as H, parseLoreFile as Ht, combineAnswers as I, loadVariables as It, reservePreset as J, parseSlotsFile as Jt, presetDirectory as K, SLOTS_FILE_NAME as Kt, questionView as L, parseVariablesFile as Lt, WORLD_FILE_NAME as M, splitPanels as Mt, parseWorldFile as N, dialectOf as Nt, modeFor as O, IMPORT_COMMAND as Ot, MAX_OPENING_CHARS as P, sourceSummary as Pt, PROSE_PROMPTS as Q, parseCharacterFile as Qt, startQuestionsToFile as R, variableProblems as Rt, ROLES as S, ImportStore as St, announceProblem as T, parseChoices as Tt, isPresetName as U, LOCATION_FILE_NAME as Ut, createPresetFromShipped as V, LORE_FILE_NAME as Vt, listPresets as W, parseLocationFile as Wt, sha as X, parseFactionFile as Xt, savePresetFromWorld as Y, FACTION_FILE_NAME as Yt, updatePresetInfo as Z, CHARACTER_FILE_NAME as Zt, pruneRelationships as _, itemise as _t, characterDocument as a, parseRelationEdit as an, deleteLorebook as at, classifyItems as b, IMPORT_FOLDER as bt, extractStyle as c, LORE_KINDS as cn, isLorebookName as ct, inert as d, DEFAULT_SLOTS as dn, lorebookDirectory as dt, InvalidEditProblems as en, listWorldPrompts as et, loreDocuments as f, INTENT_STATUSES as fn, readLorebook as ft, pruneMembers as g, cleanText as gt, pruneLoreSubjects as h, writeLorebookEntry as ht, asWritten as i, parsePlaceEdit as in, createLorebook as it, yesAt as j, findPanel as jt, noAt as k, parseImportCommand as kt, extractStyleFrom as l, LORE_SCOPES as ln, listLorebooks as lt, pruneLinks as m, updateLorebookInfo as mt, STANDING_PROMPT as n, parseFactionEdit as nn, writeWorldPrompt as nt, emptyExtracted as o, parseThingEdit as on, deleteLorebookEntry as ot, pruneKnowledge as p, reserveLorebook as pt, readPreset as q, parseItemFile as qt, addLore as r, parseLoreEdit as rn, addLorebookEntries as rt, extractEntities as s, guarded as sn, entriesOf as st, SerialQueue as t, parseCharacterEdit as tn, readWorldPrompt as tt, extractVariables as u, WEEKDAY_NAMES as un, loadLorebook as ut, sourcesFor as v, partsOf as vt, isLeftOut as w, openingText as wt, findEntity as x, ImportNotFoundError as xt, buildRoster as y, withPlayer as yt, PRESET_FILE as z, LORE_DIR as zt };
|
|
4351
5202
|
|
|
4352
|
-
//# sourceMappingURL=
|
|
5203
|
+
//# sourceMappingURL=serial-BUaJGwVy.js.map
|