@dsh-agentic-roleplay/core 0.10.1 → 0.10.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/icon.svg +13 -0
- package/lib/{authoring-tools-C6Hzy8jU.js → authoring-tools-C9cmcUbD.js} +424 -31
- package/lib/authoring.js +6 -6
- package/lib/{child-C8r8AFpm.js → child-C9nPIy9j.js} +7 -3
- package/lib/client.js +2196 -728
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +1 -1
- package/lib/doctor.js +2 -2
- package/lib/helper.js +8 -1
- package/lib/{hooks-BuQ61nvQ.js → hooks-BpLN_hhT.js} +180 -153
- package/lib/images.js +1 -1
- package/lib/index.js +456 -61
- package/lib/{lorebook-author-tools-B6_Jj8oe.js → lorebook-author-tools-Cg7QQemi.js} +4 -4
- package/lib/lorebook-authoring.js +4 -4
- package/lib/orchestration.js +65 -15
- package/lib/{pack-jail-OZSgU85i.js → pack-jail-D5j5mIq6.js} +12 -8
- package/lib/{packs-B88bxt8E.js → packs-Cc05FrId.js} +2 -2
- package/lib/{presenter-agent-D-WNs626.js → presenter-agent-UKbKYXMO.js} +3 -3
- package/lib/{preset-DNuqvMan.js → preset-Be4lz6vB.js} +4 -4
- package/lib/{preset-author-tools-CDwavcTb.js → preset-author-tools-C3s0iSfv.js} +5 -5
- package/lib/preset-authoring.js +5 -5
- package/lib/{presets-9_MNxwaw.js → presets-Cl9sU3Qs.js} +52 -10
- package/lib/{reflection-BvM0w1R4.js → reflection-I9z-PvFK.js} +8 -6
- package/lib/{turn-guard-Ygdww1Wt.js → turn-guard-B9pGCeir.js} +3 -3
- package/package.json +4 -2
- package/prompts/en/checks/decide-opening.md +7 -1
- package/prompts/en/roleplay/record-keeper.md +2 -1
- package/prompts/zh/checks/decide-opening.md +7 -1
- package/prompts/zh/roleplay/record-keeper.md +2 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { n as atomicWrite, r as atomicWriteJson } from "./access-CXtaZNbx.js";
|
|
2
|
-
import { $ as IMPORT_FOLDER, A as sourcesFor, At as InvalidEditProblems, Bt as DEFAULT_SLOTS, C as inert, Ct as parseSlotsFile, D as pruneLoreSubjects, Dt as parseCharacterFile, E as pruneLinks, Et as CHARACTER_FILE_NAME, F as ROLE_TABLE, I as isLeftOut, Lt as LORE_KINDS, M as classifyItems, N as findEntity, O as pruneMembers, Ot as readVariableValues, P as ROLES, Q as withPlayer, R as askYesNo, Rt as LORE_SCOPES, S as extractVariables, St as parseItemFile, T as pruneKnowledge, Tt as parseFactionFile, U as yesAt, V as noAt, X as itemise, Y as cleanText, _ as characterDocument, _t as parseLoreFile, a as isPresetName, at as readImportFolder, b as extractStyle, bt as ITEM_FILE_NAME, ft as VARIABLES_FILE_NAME, g as asWritten, gt as LORE_FILE_NAME, h as addLore, ht as variableProblems, j as buildRoster, k as pruneRelationships, kt as readIdentifier, nt as PICTURE_FILE, pt as loadVariables, rt as openingText, st as dialectOf, ut as parseImportCommand, v as emptyExtracted, vt as LOCATION_FILE_NAME, w as loreDocuments, wt as FACTION_FILE_NAME, xt as SLOTS_FILE_NAME, y as extractEntities, yt as parseLocationFile, zt as WEEKDAY_NAMES } from "./presets-
|
|
2
|
+
import { $ as IMPORT_FOLDER, A as sourcesFor, At as InvalidEditProblems, Bt as DEFAULT_SLOTS, C as inert, Ct as parseSlotsFile, D as pruneLoreSubjects, Dt as parseCharacterFile, E as pruneLinks, Et as CHARACTER_FILE_NAME, F as ROLE_TABLE, I as isLeftOut, Lt as LORE_KINDS, M as classifyItems, N as findEntity, O as pruneMembers, Ot as readVariableValues, P as ROLES, Q as withPlayer, R as askYesNo, Rt as LORE_SCOPES, S as extractVariables, St as parseItemFile, T as pruneKnowledge, Tt as parseFactionFile, U as yesAt, V as noAt, X as itemise, Y as cleanText, _ as characterDocument, _t as parseLoreFile, a as isPresetName, at as readImportFolder, b as extractStyle, bt as ITEM_FILE_NAME, ft as VARIABLES_FILE_NAME, g as asWritten, gt as LORE_FILE_NAME, h as addLore, ht as variableProblems, j as buildRoster, k as pruneRelationships, kt as readIdentifier, nt as PICTURE_FILE, pt as loadVariables, rt as openingText, st as dialectOf, ut as parseImportCommand, v as emptyExtracted, vt as LOCATION_FILE_NAME, w as loreDocuments, wt as FACTION_FILE_NAME, xt as SLOTS_FILE_NAME, y as extractEntities, yt as parseLocationFile, zt as WEEKDAY_NAMES } from "./presets-Cl9sU3Qs.js";
|
|
3
3
|
import { f as parseSwitchboard } from "./narration-B0hConSw.js";
|
|
4
|
-
import {
|
|
4
|
+
import { $ as listFiles, G as formatIssue, J as PROMPTS_FOLDER, K as errorMessage, L as loadPlots, U as readDocument$1, V as commandFlagKey, W as Reader, X as copyWorldPrompts, a as externalWithheld, et as promptProblem, gt as COMPARISONS, ot as InvalidWorldError, r as externalGiven, rt as shippedText, t as externalToolLimit, tt as shippedLanguages, z as plotReferenceProblems } from "./hooks-BpLN_hhT.js";
|
|
5
5
|
import { t as trimCharacters } from "./text-CzqhC8sT.js";
|
|
6
|
-
import {
|
|
6
|
+
import { S as currentTurn, c as namedModel, d as parseSampling, l as runChild, t as ChildTimeoutError } from "./child-C9nPIy9j.js";
|
|
7
7
|
import { C as slug, S as norm, T as uniqueKey, _ as writeImageFileMetadata, b as NoEmbeddingService, i as libraryHashes, n as addToLibraryOnce, p as MEDIA_TYPES, r as imageExtensionOf, u as referenceImagePath, w as trOf, x as mapLimit } from "./library-CH-ahlm0.js";
|
|
8
8
|
import { dirname, join, relative } from "node:path";
|
|
9
|
+
import { MINUTE, MONTH_NAMES, SEASONS, checkProblems, createSessionStore, dayTokenProblems, isTimeZone, lintWorld, parseInstant, parseTimeOfDay, readTriggerDefinition, triggerReferenceProblems, writeCalendar } from "@dsh-agentic-roleplay/state";
|
|
9
10
|
import { existsSync, readFileSync } from "node:fs";
|
|
10
11
|
import { createHash } from "node:crypto";
|
|
11
12
|
import { mkdir, mkdtemp, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
@@ -13,7 +14,6 @@ import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
|
13
14
|
import { inflateSync } from "node:zlib";
|
|
14
15
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
15
16
|
import { Service } from "@deepseek-ai/cordis";
|
|
16
|
-
import { MINUTE, MONTH_NAMES, SEASONS, checkProblems, createSessionStore, dayTokenProblems, isTimeZone, lintWorld, parseInstant, parseTimeOfDay, readTriggerDefinition, triggerReferenceProblems, writeCalendar } from "@dsh-agentic-roleplay/state";
|
|
17
17
|
import { lookup } from "node:dns";
|
|
18
18
|
import { request } from "node:http";
|
|
19
19
|
import { request as request$1 } from "node:https";
|
|
@@ -76,6 +76,7 @@ const TEXT_CHUNKS = /* @__PURE__ */ new Set([
|
|
|
76
76
|
const CARD_KEYWORDS = ["ccv3", "chara"];
|
|
77
77
|
function chunksOf(file) {
|
|
78
78
|
const chunks = [];
|
|
79
|
+
if (file.length < PNG_SIGNATURE.length + 12 || file.toString("latin1", PNG_SIGNATURE.length + 4, PNG_SIGNATURE.length + 8) !== "IHDR") throw new ImportCardError("the PNG file is damaged: it does not start with a picture header");
|
|
79
80
|
let at = PNG_SIGNATURE.length;
|
|
80
81
|
while (at + 12 <= file.length) {
|
|
81
82
|
const length = file.readUInt32BE(at);
|
|
@@ -118,8 +119,40 @@ function textOf$1(chunk) {
|
|
|
118
119
|
function pictureOf(file) {
|
|
119
120
|
return Buffer.concat([PNG_SIGNATURE, ...chunksOf(file).filter((chunk) => !TEXT_CHUNKS.has(chunk.type)).map((chunk) => chunk.raw)]);
|
|
120
121
|
}
|
|
122
|
+
const BYTE_ORDER_MARK = [
|
|
123
|
+
239,
|
|
124
|
+
187,
|
|
125
|
+
191
|
|
126
|
+
];
|
|
127
|
+
const BLANKS = /* @__PURE__ */ new Set([
|
|
128
|
+
32,
|
|
129
|
+
9,
|
|
130
|
+
10,
|
|
131
|
+
13
|
|
132
|
+
]);
|
|
133
|
+
const startOfText = (file) => {
|
|
134
|
+
let at = BYTE_ORDER_MARK.every((byte, index) => file[index] === byte) ? BYTE_ORDER_MARK.length : 0;
|
|
135
|
+
while (at < file.length && BLANKS.has(file[at])) at += 1;
|
|
136
|
+
return at;
|
|
137
|
+
};
|
|
138
|
+
/** What a file is by its first bytes: never by its name or by the type a sender claimed. A card is a PNG picture or a JSON object. */
|
|
139
|
+
function cardFormat(file) {
|
|
140
|
+
if (isPng(file)) return "png";
|
|
141
|
+
return file[startOfText(file)] === 123 ? "json" : void 0;
|
|
142
|
+
}
|
|
143
|
+
/** A few kinds of file people mistake for a card, named by their first bytes, so the refusal can say what arrived. */
|
|
144
|
+
function kindOf(file) {
|
|
145
|
+
const start = file.toString("latin1", startOfText(file), startOfText(file) + 15).toLowerCase();
|
|
146
|
+
if (start.startsWith("<!doctype") || start.startsWith("<html") || start.startsWith("<?xml") || start.startsWith("<")) return "a web page";
|
|
147
|
+
if (file.subarray(0, 2).toString("latin1") === "PK") return "a ZIP archive";
|
|
148
|
+
if (file[0] === 255 && file[1] === 216 && file[2] === 255) return "a JPEG picture";
|
|
149
|
+
if (file.toString("latin1", 0, 4) === "GIF8") return "a GIF picture";
|
|
150
|
+
if (file.toString("latin1", 0, 4) === "RIFF" && file.toString("latin1", 8, 12) === "WEBP") return "a WebP picture";
|
|
151
|
+
}
|
|
121
152
|
function jsonOf(file, name) {
|
|
122
|
-
|
|
153
|
+
const format = cardFormat(file);
|
|
154
|
+
if (format === void 0) throw new ImportCardError(`${name} is ${file.length === 0 ? "empty" : `${kindOf(file) ?? "neither a PNG picture nor a JSON file"}`}: a character card is a PNG picture with the card in it, or a JSON file`);
|
|
155
|
+
if (format === "png") {
|
|
123
156
|
const found = /* @__PURE__ */ new Map();
|
|
124
157
|
for (const chunk of chunksOf(file)) {
|
|
125
158
|
if (!TEXT_CHUNKS.has(chunk.type)) continue;
|
|
@@ -137,7 +170,7 @@ function jsonOf(file, name) {
|
|
|
137
170
|
try {
|
|
138
171
|
return JSON.parse(file.toString("utf8").replace(/^/, ""));
|
|
139
172
|
} catch {
|
|
140
|
-
throw new ImportCardError(`${name}
|
|
173
|
+
throw new ImportCardError(`${name} looks like JSON but cannot be read as JSON`);
|
|
141
174
|
}
|
|
142
175
|
}
|
|
143
176
|
const URL_PATTERN = /https?:\/\/[^\s"'`<>()[\]{}\\|^]+/gi;
|
|
@@ -1969,6 +2002,126 @@ async function deleteLorebook(root, name, now = Date.now) {
|
|
|
1969
2002
|
await rename(directory, aside);
|
|
1970
2003
|
return aside;
|
|
1971
2004
|
}
|
|
2005
|
+
// src/shared/start-questions.ts
|
|
2006
|
+
const START_PLOT_STATUSES = ["dormant", "available"];
|
|
2007
|
+
const questionView = (question) => ({
|
|
2008
|
+
id: question.id,
|
|
2009
|
+
text: question.text,
|
|
2010
|
+
options: question.options.map(({ id, label, description }) => ({
|
|
2011
|
+
id,
|
|
2012
|
+
label,
|
|
2013
|
+
...description === void 0 ? {} : { description }
|
|
2014
|
+
}))
|
|
2015
|
+
});
|
|
2016
|
+
/** What the answers add up to, or why they cannot be combined. A question left unanswered changes nothing. */
|
|
2017
|
+
function combineAnswers(questions, answers) {
|
|
2018
|
+
const problems = [];
|
|
2019
|
+
const effect = {};
|
|
2020
|
+
for (const id of Object.keys(answers)) if (!questions.some((question) => question.id === id)) problems.push(`the world asks no question "${id}"`);
|
|
2021
|
+
const set = (key, value, question) => {
|
|
2022
|
+
if (value === void 0) return;
|
|
2023
|
+
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`);
|
|
2024
|
+
else effect[key] = value;
|
|
2025
|
+
};
|
|
2026
|
+
for (const question of questions) {
|
|
2027
|
+
const answer = answers[question.id];
|
|
2028
|
+
if (answer === void 0) continue;
|
|
2029
|
+
const option = question.options.find((entry) => entry.id === answer);
|
|
2030
|
+
if (option === void 0) {
|
|
2031
|
+
problems.push(`"${answer}" is not an answer to "${question.id}"`);
|
|
2032
|
+
continue;
|
|
2033
|
+
}
|
|
2034
|
+
const found = option.effect;
|
|
2035
|
+
if (found.rules !== void 0) effect.rules = [...effect.rules ?? [], ...found.rules];
|
|
2036
|
+
set("opening", found.opening, question.id);
|
|
2037
|
+
set("startingTime", found.startingTime, question.id);
|
|
2038
|
+
set("clockMode", found.clockMode, question.id);
|
|
2039
|
+
for (const [agent, switches] of Object.entries(found.tools ?? {})) {
|
|
2040
|
+
const merged = { ...effect.tools?.[agent] };
|
|
2041
|
+
for (const [tool, value] of Object.entries(switches)) {
|
|
2042
|
+
if (merged[tool] !== void 0 && merged[tool] !== value) problems.push(`the answers disagree about the tool "${tool}"; "${question.id}" changes it again`);
|
|
2043
|
+
merged[tool] = value;
|
|
2044
|
+
}
|
|
2045
|
+
effect.tools = {
|
|
2046
|
+
...effect.tools,
|
|
2047
|
+
[agent]: merged
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
for (const [plot, status] of Object.entries(found.plots ?? {})) {
|
|
2051
|
+
if (effect.plots?.[plot] !== void 0 && effect.plots[plot] !== status) problems.push(`the answers disagree about the plot "${plot}"; "${question.id}" changes it again`);
|
|
2052
|
+
effect.plots = {
|
|
2053
|
+
...effect.plots,
|
|
2054
|
+
[plot]: status
|
|
2055
|
+
};
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
return {
|
|
2059
|
+
effect,
|
|
2060
|
+
problems
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
/** The questions as `world.json` writes them: snake_case keys, and only what an answer sets. */
|
|
2064
|
+
function startQuestionsToFile(questions) {
|
|
2065
|
+
return questions.map((question) => ({
|
|
2066
|
+
id: question.id,
|
|
2067
|
+
text: question.text,
|
|
2068
|
+
options: question.options.map((option) => ({
|
|
2069
|
+
id: option.id,
|
|
2070
|
+
label: option.label,
|
|
2071
|
+
...option.description === void 0 || option.description === "" ? {} : { description: option.description },
|
|
2072
|
+
effect: {
|
|
2073
|
+
...option.effect.rules === void 0 || option.effect.rules.length === 0 ? {} : { rules: option.effect.rules },
|
|
2074
|
+
...option.effect.opening === void 0 ? {} : { opening: option.effect.opening },
|
|
2075
|
+
...option.effect.startingTime === void 0 || option.effect.startingTime === "" ? {} : { starting_time: option.effect.startingTime },
|
|
2076
|
+
...option.effect.clockMode === void 0 ? {} : { clock_mode: option.effect.clockMode },
|
|
2077
|
+
...option.effect.tools === void 0 ? {} : { tools: option.effect.tools },
|
|
2078
|
+
...option.effect.plots === void 0 ? {} : { plots: option.effect.plots }
|
|
2079
|
+
}
|
|
2080
|
+
}))
|
|
2081
|
+
}));
|
|
2082
|
+
}
|
|
2083
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2084
|
+
/** Reads questions sent by the editor: the shape only, since the world file's own reader judges every value when the change is written. */
|
|
2085
|
+
function parseStartQuestionsEdit(value, problems) {
|
|
2086
|
+
if (!Array.isArray(value)) {
|
|
2087
|
+
problems.push("startQuestions must be a list");
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
const questions = [];
|
|
2091
|
+
for (const entry of value) {
|
|
2092
|
+
if (!isObject(entry) || typeof entry["id"] !== "string" || typeof entry["text"] !== "string" || !Array.isArray(entry["options"])) {
|
|
2093
|
+
problems.push("a start question needs an id, a text and a list of options");
|
|
2094
|
+
return;
|
|
2095
|
+
}
|
|
2096
|
+
const options = [];
|
|
2097
|
+
for (const option of entry["options"]) {
|
|
2098
|
+
if (!isObject(option) || typeof option["id"] !== "string" || typeof option["label"] !== "string" || !isObject(option["effect"]) || option["description"] !== void 0 && typeof option["description"] !== "string") {
|
|
2099
|
+
problems.push("an answer needs an id, a label and an effect");
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
2102
|
+
const effect = option["effect"];
|
|
2103
|
+
const known = {};
|
|
2104
|
+
if (Array.isArray(effect["rules"])) known.rules = effect["rules"].filter((rule) => typeof rule === "string");
|
|
2105
|
+
if (typeof effect["opening"] === "number") known.opening = effect["opening"];
|
|
2106
|
+
if (typeof effect["startingTime"] === "string") known.startingTime = effect["startingTime"];
|
|
2107
|
+
if (effect["clockMode"] === "simulated" || effect["clockMode"] === "real") known.clockMode = effect["clockMode"];
|
|
2108
|
+
if (isObject(effect["tools"])) known.tools = effect["tools"];
|
|
2109
|
+
if (isObject(effect["plots"])) known.plots = effect["plots"];
|
|
2110
|
+
options.push({
|
|
2111
|
+
id: option["id"].trim(),
|
|
2112
|
+
label: option["label"].trim(),
|
|
2113
|
+
...typeof option["description"] === "string" && option["description"].trim() !== "" ? { description: option["description"].trim() } : {},
|
|
2114
|
+
effect: known
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
questions.push({
|
|
2118
|
+
id: entry["id"].trim(),
|
|
2119
|
+
text: entry["text"].trim(),
|
|
2120
|
+
options
|
|
2121
|
+
});
|
|
2122
|
+
}
|
|
2123
|
+
return questions;
|
|
2124
|
+
}
|
|
1972
2125
|
const MAX_OPENING_CHARS = 2e4;
|
|
1973
2126
|
const TEXT_FIELDS = [
|
|
1974
2127
|
"name",
|
|
@@ -1992,7 +2145,7 @@ function parseWorldInfoEdit(value) {
|
|
|
1992
2145
|
const input = typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1993
2146
|
if (input === void 0) throw new InvalidEditProblems(["the changes must be an object"]);
|
|
1994
2147
|
const edit = {};
|
|
1995
|
-
for (const key of Object.keys(input)) if (!TEXT_FIELDS.includes(key) && !LIST_FIELDS.includes(key) && key !== "alternateOpenings" && key !== "tools" && key !== "sampling") problems.push(`there is no field "${key}"`);
|
|
2148
|
+
for (const key of Object.keys(input)) if (!TEXT_FIELDS.includes(key) && !LIST_FIELDS.includes(key) && key !== "alternateOpenings" && key !== "startQuestions" && key !== "tools" && key !== "sampling") problems.push(`there is no field "${key}"`);
|
|
1996
2149
|
for (const key of TEXT_FIELDS) {
|
|
1997
2150
|
if (input[key] === void 0) continue;
|
|
1998
2151
|
if (typeof input[key] === "string") edit[key] = input[key].trim();
|
|
@@ -2018,6 +2171,10 @@ function parseWorldInfoEdit(value) {
|
|
|
2018
2171
|
edit["alternateOpenings"] = kept;
|
|
2019
2172
|
}
|
|
2020
2173
|
}
|
|
2174
|
+
if (input["startQuestions"] !== void 0) {
|
|
2175
|
+
const questions = parseStartQuestionsEdit(input["startQuestions"], problems);
|
|
2176
|
+
if (questions !== void 0) edit["startQuestions"] = questions;
|
|
2177
|
+
}
|
|
2021
2178
|
if (input["tools"] !== void 0) {
|
|
2022
2179
|
const board = parseSwitchboard(input["tools"], "tools");
|
|
2023
2180
|
if (typeof board === "string") problems.push(board);
|
|
@@ -2055,6 +2212,108 @@ function readAlternateOpenings(reader) {
|
|
|
2055
2212
|
}
|
|
2056
2213
|
return openings.length === 0 ? void 0 : openings;
|
|
2057
2214
|
}
|
|
2215
|
+
const EFFECT_KEYS = [
|
|
2216
|
+
"rules",
|
|
2217
|
+
"opening",
|
|
2218
|
+
"starting_time",
|
|
2219
|
+
"clock_mode",
|
|
2220
|
+
"tools",
|
|
2221
|
+
"plots"
|
|
2222
|
+
];
|
|
2223
|
+
/** 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. */
|
|
2224
|
+
function readEffect(entry, openings) {
|
|
2225
|
+
const raw = entry.raw("effect");
|
|
2226
|
+
const effect = {};
|
|
2227
|
+
if (raw === void 0 || raw === null) return effect;
|
|
2228
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
2229
|
+
entry.fail("effect", "must be an object");
|
|
2230
|
+
return effect;
|
|
2231
|
+
}
|
|
2232
|
+
const body = raw;
|
|
2233
|
+
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(", ")})`);
|
|
2234
|
+
if (body["rules"] !== void 0) {
|
|
2235
|
+
const rules = Array.isArray(body["rules"]) && body["rules"].every((rule) => typeof rule === "string") ? body["rules"].map((rule) => rule.trim()).filter((rule) => rule !== "") : void 0;
|
|
2236
|
+
if (rules === void 0) entry.fail("effect.rules", "must be a list of rules");
|
|
2237
|
+
else if (rules.some((rule) => rule.length > 300)) entry.fail("effect.rules", `has a rule longer than 300 characters`);
|
|
2238
|
+
else if (rules.length > 0) effect.rules = rules;
|
|
2239
|
+
}
|
|
2240
|
+
if (body["opening"] !== void 0) {
|
|
2241
|
+
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`);
|
|
2242
|
+
else effect.opening = body["opening"];
|
|
2243
|
+
}
|
|
2244
|
+
if (body["starting_time"] !== void 0) {
|
|
2245
|
+
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");
|
|
2246
|
+
else effect.startingTime = body["starting_time"].trim();
|
|
2247
|
+
}
|
|
2248
|
+
if (body["clock_mode"] !== void 0) {
|
|
2249
|
+
if (body["clock_mode"] !== "simulated" && body["clock_mode"] !== "real") entry.fail("effect.clock_mode", "must be \"simulated\" or \"real\"");
|
|
2250
|
+
else effect.clockMode = body["clock_mode"];
|
|
2251
|
+
}
|
|
2252
|
+
if (body["tools"] !== void 0) {
|
|
2253
|
+
const board = parseSwitchboard(body["tools"], "tools");
|
|
2254
|
+
if (typeof board === "string") entry.fail("effect.tools", board.replace(/^"tools"\s*/, ""));
|
|
2255
|
+
else if (Object.keys(board).length > 0) effect.tools = board;
|
|
2256
|
+
}
|
|
2257
|
+
if (body["plots"] !== void 0) {
|
|
2258
|
+
const plots = body["plots"];
|
|
2259
|
+
if (typeof plots !== "object" || plots === null || Array.isArray(plots)) entry.fail("effect.plots", "must map plot ids to \"dormant\" or \"available\"");
|
|
2260
|
+
else {
|
|
2261
|
+
const kept = {};
|
|
2262
|
+
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(", ")}`);
|
|
2263
|
+
else kept[id] = status;
|
|
2264
|
+
if (Object.keys(kept).length > 0) effect.plots = kept;
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
return effect;
|
|
2268
|
+
}
|
|
2269
|
+
/** `start_questions`: `{ id, text, options: [{ id, label, description?, effect }] }`, asked in the start dialog. */
|
|
2270
|
+
function readStartQuestions(reader, openings) {
|
|
2271
|
+
const value = reader.raw("start_questions");
|
|
2272
|
+
if (value === void 0 || value === null) return void 0;
|
|
2273
|
+
if (!Array.isArray(value)) {
|
|
2274
|
+
reader.fail("start_questions", "must be a list");
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2277
|
+
if (value.length > 8) reader.fail("start_questions", `has more than 8 questions`);
|
|
2278
|
+
const questions = [];
|
|
2279
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2280
|
+
for (const entry of reader.objects("start_questions")) {
|
|
2281
|
+
const id = entry.string("id", { required: true })?.trim();
|
|
2282
|
+
const text = entry.string("text", { required: true })?.trim();
|
|
2283
|
+
if (id === void 0 || text === void 0 || id === "" || text === "") continue;
|
|
2284
|
+
if (seen.has(id)) entry.fail("id", `repeats the question "${id}"`);
|
|
2285
|
+
seen.add(id);
|
|
2286
|
+
if (text.length > 200) entry.fail("text", `is longer than 200 characters`);
|
|
2287
|
+
const raw = entry.raw("options");
|
|
2288
|
+
if (!Array.isArray(raw) || raw.length < 2 || raw.length > 8) {
|
|
2289
|
+
entry.fail("options", `must list 2 to 8 answers`);
|
|
2290
|
+
continue;
|
|
2291
|
+
}
|
|
2292
|
+
const options = [];
|
|
2293
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2294
|
+
for (const option of entry.objects("options")) {
|
|
2295
|
+
const optionId = option.string("id", { required: true })?.trim();
|
|
2296
|
+
const label = option.string("label", { required: true })?.trim();
|
|
2297
|
+
if (optionId === void 0 || label === void 0 || optionId === "" || label === "") continue;
|
|
2298
|
+
if (ids.has(optionId)) option.fail("id", `repeats the answer "${optionId}"`);
|
|
2299
|
+
ids.add(optionId);
|
|
2300
|
+
if (label.length > 200) option.fail("label", `is longer than 200 characters`);
|
|
2301
|
+
const description = option.string("description")?.trim();
|
|
2302
|
+
options.push({
|
|
2303
|
+
id: optionId,
|
|
2304
|
+
label,
|
|
2305
|
+
...description === void 0 || description === "" ? {} : { description },
|
|
2306
|
+
effect: readEffect(option, openings)
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
questions.push({
|
|
2310
|
+
id,
|
|
2311
|
+
text,
|
|
2312
|
+
options
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
return questions.length === 0 ? void 0 : questions;
|
|
2316
|
+
}
|
|
2058
2317
|
/** `tools`: switches by kind of agent and tool name; a world carried from a version with other tools still loads. */
|
|
2059
2318
|
function readTools(reader) {
|
|
2060
2319
|
const value = reader.raw("tools");
|
|
@@ -2168,6 +2427,7 @@ function parseWorldFile(text) {
|
|
|
2168
2427
|
const rules = readRules(reader);
|
|
2169
2428
|
const tools = readTools(reader);
|
|
2170
2429
|
const alternateOpenings = readAlternateOpenings(reader);
|
|
2430
|
+
const startQuestions = readStartQuestions(reader, alternateOpenings?.length ?? 0);
|
|
2171
2431
|
const narrationVoice = reader.string("narration_voice")?.trim() || void 0;
|
|
2172
2432
|
const sampling = readSampling(reader);
|
|
2173
2433
|
const preset = reader.string("preset")?.trim() || void 0;
|
|
@@ -2194,6 +2454,7 @@ function parseWorldFile(text) {
|
|
|
2194
2454
|
...rules === void 0 ? {} : { rules },
|
|
2195
2455
|
...tools === void 0 ? {} : { tools },
|
|
2196
2456
|
...alternateOpenings === void 0 ? {} : { alternateOpenings },
|
|
2457
|
+
...startQuestions === void 0 ? {} : { startQuestions },
|
|
2197
2458
|
...narrationVoice === void 0 ? {} : { narrationVoice },
|
|
2198
2459
|
...sampling === void 0 ? {} : { sampling },
|
|
2199
2460
|
...preset === void 0 ? {} : { preset },
|
|
@@ -2215,9 +2476,15 @@ const OUTCOMES = [
|
|
|
2215
2476
|
"awaiting"
|
|
2216
2477
|
];
|
|
2217
2478
|
const rolesOf$1 = (source, id) => [...new Set(Object.entries(source.records.classified ?? {}).filter(([key]) => baseId(key) === id).flatMap(([, entry]) => entry.roles))];
|
|
2218
|
-
|
|
2479
|
+
const MECHANICS = [
|
|
2480
|
+
"variable",
|
|
2481
|
+
"rules",
|
|
2482
|
+
"command",
|
|
2483
|
+
"trigger"
|
|
2484
|
+
];
|
|
2485
|
+
function outcomeOf(source, piece, made, mechanics, finished) {
|
|
2219
2486
|
const { choices, card } = source;
|
|
2220
|
-
const reported = source.records.report !== void 0;
|
|
2487
|
+
const reported = source.records.report !== void 0 || finished;
|
|
2221
2488
|
if (piece.id === "field:creator-notes") return {
|
|
2222
2489
|
outcome: "omitted",
|
|
2223
2490
|
because: "notes to people, not part of the world"
|
|
@@ -2250,26 +2517,41 @@ function outcomeOf(source, piece, made) {
|
|
|
2250
2517
|
outcome: "awaiting",
|
|
2251
2518
|
because: "the import did not classify it"
|
|
2252
2519
|
};
|
|
2253
|
-
if (roles.every((role) => ROLE_TABLE[role].leftOut))
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2520
|
+
if (roles.every((role) => ROLE_TABLE[role].leftOut)) {
|
|
2521
|
+
if (mechanics) return {
|
|
2522
|
+
outcome: "converted",
|
|
2523
|
+
because: "its rules became tracked values, rules or triggers"
|
|
2524
|
+
};
|
|
2525
|
+
return roles.includes("instruction") ? {
|
|
2526
|
+
outcome: "guidance",
|
|
2527
|
+
because: "how to run a story, not facts of this one"
|
|
2528
|
+
} : {
|
|
2529
|
+
outcome: "omitted",
|
|
2530
|
+
because: roles.includes("template") ? "a template or format of the source tool" : "nothing to do with the story"
|
|
2531
|
+
};
|
|
2532
|
+
}
|
|
2533
|
+
if (made.length > 0 || mechanics) return {
|
|
2534
|
+
outcome: "converted",
|
|
2535
|
+
...made.length === 0 ? { because: "its rules became tracked values, rules or triggers" } : {}
|
|
2259
2536
|
};
|
|
2260
|
-
return
|
|
2537
|
+
return {
|
|
2261
2538
|
outcome: "read",
|
|
2262
|
-
because: "no character, place or
|
|
2539
|
+
because: "no character, place, thing or rule is made from it: its words survive only as background"
|
|
2263
2540
|
};
|
|
2264
2541
|
}
|
|
2265
2542
|
/** What became of every piece of the card, from the import's records; `made` is `entitiesByPiece` of the same source. */
|
|
2266
|
-
function pieceOutcomes(source, made) {
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2543
|
+
function pieceOutcomes(source, made, options = {}) {
|
|
2544
|
+
const derived = options.derived ?? source.records.report?.derived ?? [];
|
|
2545
|
+
return source.pieces.map((piece) => {
|
|
2546
|
+
const from = derived.filter((entry) => entry.pieces.includes(piece.id));
|
|
2547
|
+
const labels = from.map((entry) => `${entry.kind}: ${entry.name}`);
|
|
2548
|
+
return {
|
|
2549
|
+
piece: piece.id,
|
|
2550
|
+
label: piece.label,
|
|
2551
|
+
...outcomeOf(source, piece, made.get(piece.id) ?? [], from.some((entry) => MECHANICS.includes(entry.kind)), options.finished === true),
|
|
2552
|
+
madeInto: [...made.get(piece.id) ?? [], ...labels]
|
|
2553
|
+
};
|
|
2554
|
+
});
|
|
2273
2555
|
}
|
|
2274
2556
|
const outcomeCounts = (outcomes) => Object.fromEntries(OUTCOMES.map((outcome) => [outcome, outcomes.filter((entry) => entry.outcome === outcome).length]));
|
|
2275
2557
|
// src/host/import/card-tools.ts
|
|
@@ -2651,6 +2933,71 @@ function originOf(card, choices, pieces, records, name, items = itemise(card, ch
|
|
|
2651
2933
|
}];
|
|
2652
2934
|
});
|
|
2653
2935
|
}
|
|
2936
|
+
// src/host/import/repair.ts
|
|
2937
|
+
const ENTITY_FILE = /^(characters|locations|factions|items|lore)\/[^/]+\/(character|location|faction|item|lore)\.json$/;
|
|
2938
|
+
/** Fields a document cannot do without, and fields that tie it to others: never dropped, whatever the problem says. */
|
|
2939
|
+
const KEPT = /* @__PURE__ */ new Set([
|
|
2940
|
+
"id",
|
|
2941
|
+
"name",
|
|
2942
|
+
"role",
|
|
2943
|
+
"kind",
|
|
2944
|
+
"tier",
|
|
2945
|
+
"from",
|
|
2946
|
+
"to",
|
|
2947
|
+
"parent",
|
|
2948
|
+
"summary"
|
|
2949
|
+
]);
|
|
2950
|
+
const ABOUT_VALUE = /^(must be|is longer than|has more than|is not one of|must not|cannot be)/;
|
|
2951
|
+
const STEP = /([^.[\]]+)|\[(\d+)\]/g;
|
|
2952
|
+
const stepsOf = (field) => [...field.matchAll(STEP)].map((match) => match[2] === void 0 ? match[1] : Number(match[2]));
|
|
2953
|
+
/** Removes what `steps` names; false when it is not there. */
|
|
2954
|
+
function remove(root, steps) {
|
|
2955
|
+
let at = root;
|
|
2956
|
+
for (const step of steps.slice(0, -1)) {
|
|
2957
|
+
at = at?.[step];
|
|
2958
|
+
if (typeof at !== "object" || at === null) return void 0;
|
|
2959
|
+
}
|
|
2960
|
+
const last = steps.at(-1);
|
|
2961
|
+
if (typeof at !== "object" || at === null || !(last in at)) return void 0;
|
|
2962
|
+
const value = at[last];
|
|
2963
|
+
if (Array.isArray(at) && typeof last === "number") at.splice(last, 1);
|
|
2964
|
+
else delete at[last];
|
|
2965
|
+
return { value };
|
|
2966
|
+
}
|
|
2967
|
+
/**
|
|
2968
|
+
* Mends what the world check refused, one field at a time and only where that is safe: an optional field of an entity whose value cannot be used (wrong type, too long, not one of the
|
|
2969
|
+
* allowed words) is dropped. A missing required field, a name, an id or a link to another entity is never touched: those stay problems for a person or the assistant. Returns what was dropped, with the values.
|
|
2970
|
+
*/
|
|
2971
|
+
async function repairFields(directory, problems) {
|
|
2972
|
+
const repairs = [];
|
|
2973
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
2974
|
+
for (const problem of problems) {
|
|
2975
|
+
if (!ENTITY_FILE.test(problem.where)) continue;
|
|
2976
|
+
const split = problem.message.indexOf(": ");
|
|
2977
|
+
if (split < 0) continue;
|
|
2978
|
+
const field = problem.message.slice(0, split);
|
|
2979
|
+
const because = problem.message.slice(split + 2);
|
|
2980
|
+
if (!/^[\w.[\]]+$/.test(field) || !ABOUT_VALUE.test(because) || KEPT.has(stepsOf(field)[0])) continue;
|
|
2981
|
+
byFile.set(problem.where, [...byFile.get(problem.where) ?? [], {
|
|
2982
|
+
field,
|
|
2983
|
+
because
|
|
2984
|
+
}]);
|
|
2985
|
+
}
|
|
2986
|
+
for (const [file, fields] of byFile) {
|
|
2987
|
+
const document = JSON.parse(await readFile(join(directory, file), "utf8"));
|
|
2988
|
+
for (const { field, because } of fields.sort((a, b) => b.field.localeCompare(a.field, void 0, { numeric: true }))) {
|
|
2989
|
+
const dropped = remove(document, stepsOf(field));
|
|
2990
|
+
if (dropped !== void 0) repairs.push({
|
|
2991
|
+
file,
|
|
2992
|
+
field,
|
|
2993
|
+
value: dropped.value,
|
|
2994
|
+
because
|
|
2995
|
+
});
|
|
2996
|
+
}
|
|
2997
|
+
if (repairs.some((repair) => repair.file === file)) await atomicWrite(join(directory, file), `${JSON.stringify(document, null, 2)}\n`);
|
|
2998
|
+
}
|
|
2999
|
+
return repairs;
|
|
3000
|
+
}
|
|
2654
3001
|
// src/host/worlds/world-file-io.ts
|
|
2655
3002
|
const queues = /* @__PURE__ */ new Map();
|
|
2656
3003
|
/**
|
|
@@ -2906,6 +3253,8 @@ async function hasEntities(world) {
|
|
|
2906
3253
|
return false;
|
|
2907
3254
|
}
|
|
2908
3255
|
const writeAtomically = (file, text) => atomicWrite(file, text, { createDirectory: true });
|
|
3256
|
+
/** The world as it is after the import: every document written into it, or nothing changed and the problems found. */
|
|
3257
|
+
const MAX_REPAIR_ROUNDS = 4;
|
|
2909
3258
|
/**
|
|
2910
3259
|
* Writes what was extracted into the world, all at once. The documents are first written to a staging folder and read back as the world will
|
|
2911
3260
|
* read them when a session starts; only when every part of the world is valid are they moved in. The world's own file gets its description, tags, opening and cover.
|
|
@@ -2976,10 +3325,24 @@ async function finishImport(ctx, input) {
|
|
|
2976
3325
|
force: true
|
|
2977
3326
|
});
|
|
2978
3327
|
}
|
|
2979
|
-
|
|
3328
|
+
let check = await checkWorld({
|
|
2980
3329
|
directory,
|
|
2981
3330
|
summary: { name: choices.name }
|
|
2982
3331
|
});
|
|
3332
|
+
const repairs = [];
|
|
3333
|
+
for (let round = 0; round < MAX_REPAIR_ROUNDS && !check.ok; round += 1) {
|
|
3334
|
+
const made = await repairFields(directory, check.problems);
|
|
3335
|
+
if (made.length === 0) break;
|
|
3336
|
+
repairs.push(...made);
|
|
3337
|
+
check = await checkWorld({
|
|
3338
|
+
directory,
|
|
3339
|
+
summary: { name: choices.name }
|
|
3340
|
+
});
|
|
3341
|
+
}
|
|
3342
|
+
if (repairs.length > 0) {
|
|
3343
|
+
await writeAtomically(join(directory, IMPORT_FOLDER, "repairs.json"), JSON.stringify(repairs, null, 2));
|
|
3344
|
+
notes.push(`${repairs.length} field(s) were dropped because their value could not be used (${repairs.slice(0, 5).map((repair) => `${repair.file}: ${repair.field}`).join("; ")}${repairs.length > 5 ? "; ..." : ""}); the values are kept in ${IMPORT_FOLDER}/repairs.json`);
|
|
3345
|
+
}
|
|
2983
3346
|
if (!check.ok) notes.push(`the world was written as a draft: it would not start yet (${check.problems.length + check.more} problem(s) in ${check.summary ?? "the world"})`);
|
|
2984
3347
|
const player = extracted.characters.find((document) => document["role"] === "playable");
|
|
2985
3348
|
for (const { id, text } of extracted.prompts) for (const language of shippedLanguages()) await writeAtomically(join(directory, PROMPTS_FOLDER, language, `${id}.md`), `${withPlayer(text, player === void 0 ? void 0 : String(player["name"]))}\n`);
|
|
@@ -3019,6 +3382,7 @@ async function finishImport(ctx, input) {
|
|
|
3019
3382
|
const classification = classified[item.id];
|
|
3020
3383
|
return classification !== void 0 && isLeftOut(classification) && classification.roles[0] === role;
|
|
3021
3384
|
}).length;
|
|
3385
|
+
const derived = extracted.derived ?? [];
|
|
3022
3386
|
const sourceOf = {
|
|
3023
3387
|
card,
|
|
3024
3388
|
choices,
|
|
@@ -3054,7 +3418,11 @@ async function finishImport(ctx, input) {
|
|
|
3054
3418
|
found: 0,
|
|
3055
3419
|
added: 0
|
|
3056
3420
|
},
|
|
3057
|
-
|
|
3421
|
+
...derived.length === 0 ? {} : { derived },
|
|
3422
|
+
pieces: outcomeCounts(pieceOutcomes(sourceOf, entitiesByPiece(sourceOf), {
|
|
3423
|
+
derived,
|
|
3424
|
+
finished: true
|
|
3425
|
+
})),
|
|
3058
3426
|
notes
|
|
3059
3427
|
};
|
|
3060
3428
|
await writeAtomically(join(directory, IMPORT_FOLDER, "report.json"), JSON.stringify(report, null, 2));
|
|
@@ -3747,7 +4115,7 @@ const toolsOf = (value) => {
|
|
|
3747
4115
|
const board = value === void 0 ? {} : parseSwitchboard(value, "tools");
|
|
3748
4116
|
return typeof board === "string" ? {} : board;
|
|
3749
4117
|
};
|
|
3750
|
-
function infoOf(document) {
|
|
4118
|
+
function infoOf(document, startQuestions = []) {
|
|
3751
4119
|
const opening = document["opening_message"];
|
|
3752
4120
|
const parts = Array.isArray(opening) && opening.some((part) => typeof part === "object" && part !== null && part["type"] === "utterance");
|
|
3753
4121
|
const plain = typeof opening === "string" ? opening : Array.isArray(opening) ? opening.map((part) => textOf(part?.["text"])).filter((text) => text !== "").join("\n\n") : "";
|
|
@@ -3770,6 +4138,7 @@ function infoOf(document) {
|
|
|
3770
4138
|
version: typeof document["version"] === "number" ? String(document["version"]) : textOf(document["version"]),
|
|
3771
4139
|
sampling: parseSampling(document["sampling"], "sampling", []),
|
|
3772
4140
|
tools: toolsOf(document["tools"]),
|
|
4141
|
+
startQuestions,
|
|
3773
4142
|
alternateOpenings: Array.isArray(document["alternate_openings"]) ? document["alternate_openings"].flatMap((entry) => typeof entry === "object" && entry !== null && typeof entry["text"] === "string" ? [{
|
|
3774
4143
|
title: textOf(entry["title"]),
|
|
3775
4144
|
text: entry["text"],
|
|
@@ -3784,8 +4153,14 @@ async function readDocument(directory) {
|
|
|
3784
4153
|
document: JSON.parse(text.replace(/^/, ""))
|
|
3785
4154
|
};
|
|
3786
4155
|
}
|
|
4156
|
+
/** The questions the file asks, as its own reader understands them; none when the file does not parse (its problems are reported elsewhere). */
|
|
4157
|
+
function questionsOf(text) {
|
|
4158
|
+
const parsed = parseWorldFile(text);
|
|
4159
|
+
return parsed.ok ? parsed.value.startQuestions ?? [] : [];
|
|
4160
|
+
}
|
|
3787
4161
|
async function readWorldInfo(directory) {
|
|
3788
|
-
|
|
4162
|
+
const { text, document } = await readDocument(directory);
|
|
4163
|
+
return infoOf(document, questionsOf(text));
|
|
3789
4164
|
}
|
|
3790
4165
|
function setOrRemove(document, key, value) {
|
|
3791
4166
|
if (value === "") delete document[key];
|
|
@@ -3802,6 +4177,10 @@ function editWorldInfo(directory, edit) {
|
|
|
3802
4177
|
async function changeWorldInfo(directory, edit) {
|
|
3803
4178
|
const { text, document } = await readDocument(directory);
|
|
3804
4179
|
const before = infoOf(document);
|
|
4180
|
+
if (edit.startQuestions !== void 0) {
|
|
4181
|
+
if (edit.startQuestions.length === 0) delete document["start_questions"];
|
|
4182
|
+
else document["start_questions"] = startQuestionsToFile(edit.startQuestions);
|
|
4183
|
+
}
|
|
3805
4184
|
if (edit.opening !== void 0 && before.openingParts && edit.opening !== before.opening) throw new InvalidEditProblems(["the opening has lines spoken by characters: change it in the file, or ask the authoring assistant"]);
|
|
3806
4185
|
if (edit.name !== void 0) document["name"] = edit.name;
|
|
3807
4186
|
if (edit.description !== void 0) document["description"] = edit.description;
|
|
@@ -3854,7 +4233,7 @@ async function changeWorldInfo(directory, edit) {
|
|
|
3854
4233
|
const parsed = parseWorldFile(next);
|
|
3855
4234
|
if (!parsed.ok) throw new InvalidEditProblems(parsed.issues.map(formatIssue));
|
|
3856
4235
|
await atomicWrite(join(directory, WORLD_FILE_NAME), next);
|
|
3857
|
-
return infoOf(document);
|
|
4236
|
+
return infoOf(document, questionsOf(next));
|
|
3858
4237
|
}
|
|
3859
4238
|
// src/host/checks/world-text.ts
|
|
3860
4239
|
/** Every string a document holds, joined: what the world says in it, without the structure around it. */
|
|
@@ -5979,13 +6358,27 @@ async function build(ctx, world) {
|
|
|
5979
6358
|
const style = await extractStyle(ctx, card, items, classified);
|
|
5980
6359
|
extracted.prompts.push(...style.prompts);
|
|
5981
6360
|
extracted.notes.push(...style.notes);
|
|
6361
|
+
extracted.derived.push(...style.derived);
|
|
5982
6362
|
const tracked = await extractVariables(ctx, card, items, classified, roster);
|
|
5983
6363
|
extracted.variables.push(...tracked.variables);
|
|
5984
6364
|
extracted.notes.push(...tracked.notes);
|
|
6365
|
+
extracted.derived.push(...tracked.derived);
|
|
5985
6366
|
const cast = await extractCasting(ctx, card, extracted.casting);
|
|
5986
6367
|
extracted.commands.push(...cast.commands);
|
|
5987
6368
|
extracted.triggers.push(...cast.triggers);
|
|
5988
6369
|
extracted.notes.push(...cast.notes);
|
|
6370
|
+
const castFrom = extracted.derived.filter((entry) => entry.kind === "command" && entry.name === "").flatMap((entry) => entry.pieces);
|
|
6371
|
+
extracted.derived = extracted.derived.filter((entry) => !(entry.kind === "command" && entry.name === ""));
|
|
6372
|
+
const named = (document) => typeof document["name"] === "string" && document["name"] !== "" ? document["name"] : typeof document["id"] === "string" ? document["id"] : typeof document["key"] === "string" ? document["key"] : "unnamed";
|
|
6373
|
+
extracted.derived.push(...cast.commands.map((document) => ({
|
|
6374
|
+
kind: "command",
|
|
6375
|
+
name: named(document),
|
|
6376
|
+
pieces: castFrom
|
|
6377
|
+
})), ...cast.triggers.map((document) => ({
|
|
6378
|
+
kind: "trigger",
|
|
6379
|
+
name: named(document),
|
|
6380
|
+
pieces: castFrom
|
|
6381
|
+
})));
|
|
5989
6382
|
if (ctx.cancelled?.() === true) throw new Error("the build was stopped before it was done, so what it made is not kept");
|
|
5990
6383
|
await rename(join(folder(world), EXTRACTED), join(folder(world), PREVIOUS_EXTRACTED)).catch((error) => {
|
|
5991
6384
|
if (error.code !== "ENOENT") throw error;
|
|
@@ -6471,6 +6864,6 @@ function limitAuthoringAgents(ctx, kindOf) {
|
|
|
6471
6864
|
return await next();
|
|
6472
6865
|
});
|
|
6473
6866
|
}
|
|
6474
|
-
export { readSource as $,
|
|
6867
|
+
export { readSource as $, subfolders as $t, editsSince as A, populateLore as At, addressesToFetch as B, loadLocations as Bt, worldFieldChanges as C, populateCharacters as Ct, loadCardEvidence as D, populateItems as Dt, loadWorldParts as E, populateFactions as Et, localChanges as F, TRIGGERS_FILE_NAME as Ft, vetUrl as G, DICE_FILE_NAME as Gt, fetchPictures as H, loadItems as Ht, readOrigin as I, loadTriggers as It, UPDATE_FOLDER as J, CALENDAR_FILE_NAME as Jt, cardCharacter as K, loadDice as Kt, writeOrigin as L, LORE_DIR as Lt, describeChanges as M, populateTriggers as Mt, hashWorld as N, populateVariables as Nt, CHECK_COMMANDS as O, populateKnowledge as Ot, isUnchanged as P, routineProblems as Pt, entitiesByPiece as Q, loadCharacters as Qt, CatalogueError as R, loadLore as Rt, pictureChange as S, populateCalendar as St, readWorldInfo as T, populateDice as Tt, guardedLookup as U, FACTIONS_DIR as Ut, candidateUrls as V, ITEMS_DIR as Vt, mergeReports as W, loadFactions as Wt, cardPieces as X, parseCalendarFile as Xt, baseId as Y, loadCalendar as Yt, cardTools as Z, CHARACTERS_DIR as Zt, runChecks as _, writeLorebookEntry as _t, importHooks as a, readCard as an, addLorebookEntries as at, diffText as b, withScratchStory as bt, importPhase as c, DICE_RESULTS as cn, deleteLorebookEntry as ct, markReady as d, listLorebooks as dt, knownOutputCeiling as en, WORLD_FILE_NAME as et, settleDraft as f, loadLorebook as ft, CHECKS as g, updateLorebookInfo as gt, presentReport as h, reserveLorebook as ht, contextOf as i, pictureOf as in, questionView as it, writeSnapshot as j, populateRoutines as jt, recordProvenance as k, populateLocations as kt, isReviewing as l, authoredWorldOf as ln, entriesOf as lt, checkImported as m, readLorebook as mt, limitAuthoringAgents as n, cardFormat as nn, parseWorldInfoEdit as nt, importTools as o, DICE_COMPARISONS as on, createLorebook as ot, structureImport as p, lorebookDirectory as pt, writePortrait as q, parseDiceFile as qt, MAX_PREVIEW_TEXT as r, isPng as rn, combineAnswers as rt, worldOf as s, DICE_READINGS as sn, deleteLorebook as st, AuthoringTools as t, ImportCardError as tn, parseWorldFile as tt, keepDraft as u, authoringChatSessionId as un, isLorebookName as ut, addressChanges as v, checkWorld as vt, editWorldInfo as w, populateClock as wt, matchPieces as x, knowsCharacter as xt, cardChanges as y, loadValidatedWorld as yt, addressKey as z, LOCATIONS_DIR as zt };
|
|
6475
6868
|
|
|
6476
|
-
//# sourceMappingURL=authoring-tools-
|
|
6869
|
+
//# sourceMappingURL=authoring-tools-C9cmcUbD.js.map
|