@dsh-agentic-roleplay/core 0.3.5 → 0.4.0
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/lib/{preset-ClQm7KPQ.js → authoring-tools-C_8ClUkP.js} +542 -261
- package/lib/authoring.js +7 -5
- package/lib/{child-CFjnaTZt.js → child-DsixtqTw.js} +94 -2
- package/lib/client.js +16938 -14212
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +1 -1
- package/lib/doctor.js +2 -4
- package/lib/{gallery-DIEgETzU.js → gallery-CDYKJf_O.js} +2 -2
- package/lib/{generator-DJ48HxPI.js → generator-BR1ugzln.js} +2 -2
- package/lib/{deliver-Cl6bjp7g.js → hooks-B2EhBS_-.js} +1884 -236
- package/lib/images.js +4 -4
- package/lib/index.js +1200 -242
- package/lib/{library-9JB9zw5a.js → library-COIktKBa.js} +4 -3
- package/lib/lorebook-author-tools-C-o0t4dL.js +694 -0
- package/lib/lorebook-authoring.js +69 -0
- package/lib/{settings-CA6icLL_.js → narration-BT9uvQry.js} +145 -2
- package/lib/orchestration.js +34 -21
- package/lib/{pack-jail-ClMpVc__.js → pack-jail-soI-In96.js} +170 -12
- package/lib/{packs-BC2A3geF.js → packs-CJPSe5LI.js} +7 -4
- package/lib/{presenter-agent-DnNEG_Mn.js → presenter-agent-Gu34bZwd.js} +6 -6
- package/lib/preset-3zn8xme7.js +242 -0
- package/lib/{preset-author-tools-Dibp-LY9.js → preset-author-tools-C-X8G40s.js} +24 -18
- package/lib/preset-authoring.js +6 -3
- package/lib/{presets-DNjNxQL5.js → presets-C3mhqqfz.js} +50 -28
- package/lib/{reflection-Bju_LPFn.js → reflection-Btsj0ZLh.js} +51 -17
- package/package.json +3 -2
- package/packs/scene/map.html +1 -0
- package/packs/scene/strip.html +1 -0
- package/prompts/en/import/lorebook.md +8 -0
- package/prompts/en/import/style.md +1 -0
- package/prompts/en/lorebook/persona.md +1 -0
- package/prompts/en/lorebook/procedure.md +1 -0
- package/prompts/en/lorebook/welcome.md +1 -0
- package/prompts/en/preset/persona.md +1 -1
- package/prompts/en/preset/procedure.md +1 -1
- package/prompts/en/roleplay/character-lookup.md +1 -0
- package/prompts/en/roleplay/game-master.md +1 -1
- package/prompts/en/world/procedure.md +1 -1
- package/prompts/zh/import/lorebook.md +8 -0
- package/prompts/zh/import/style.md +1 -0
- package/prompts/zh/lorebook/persona.md +1 -0
- package/prompts/zh/lorebook/procedure.md +1 -0
- package/prompts/zh/lorebook/welcome.md +1 -0
- package/prompts/zh/preset/persona.md +1 -1
- package/prompts/zh/preset/procedure.md +1 -1
- package/prompts/zh/roleplay/character-lookup.md +1 -0
- package/prompts/zh/roleplay/game-master.md +1 -1
- package/prompts/zh/world/procedure.md +1 -1
- package/lib/hooks-DdO_tNhu.js +0 -1060
- package/lib/language-BgyxtB2h.js +0 -38
- package/lib/load-Clkl0T7C.js +0 -486
- package/lib/narration-DK2kiIjE.js +0 -141
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { V as Reader } from "./hooks-B2EhBS_-.js";
|
|
2
2
|
import { dirname, extname, join, posix, sep } from "node:path";
|
|
3
3
|
import { copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync } from "node:fs";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
@@ -228,8 +228,11 @@ function declarationProblem(body, url) {
|
|
|
228
228
|
problem: "@import is not allowed"
|
|
229
229
|
};
|
|
230
230
|
let problem;
|
|
231
|
-
const css = body.replace(/url\(
|
|
232
|
-
const
|
|
231
|
+
const css = body.replace(/url\(([^)]*)\)/gi, (match, raw) => {
|
|
232
|
+
const value = raw.trim();
|
|
233
|
+
const quoted = value.startsWith("\"") && value.endsWith("\"") || value.startsWith("'") && value.endsWith("'");
|
|
234
|
+
if (!quoted && /\s/u.test(value)) return match;
|
|
235
|
+
const path = quoted ? value.slice(1, -1) : value;
|
|
233
236
|
if (path === "" || /^[a-z][a-z0-9+.-]*:/i.test(path) || path.startsWith("/") || path.startsWith("#")) {
|
|
234
237
|
problem ??= `url(${path}) must be a path inside the pack`;
|
|
235
238
|
return match;
|
|
@@ -837,4 +840,4 @@ function anyTab(bases) {
|
|
|
837
840
|
//#endregion
|
|
838
841
|
export { API_PREFIX as _, packIds as a, describePack as c, packPath as d, readPack as f, SURFACE_NAMES as g, PACK_MEDIA_TYPES as h, inheritPacks as i, isPackId as l, PACK_LIMITS as m, anyTab as n, syncWorldPacks as o, PACK_ACTIONS as p, copyWorldPacks as r, worldPackStates as s, activePack as t, packFile as u };
|
|
839
842
|
|
|
840
|
-
//# sourceMappingURL=packs-
|
|
843
|
+
//# sourceMappingURL=packs-CJPSe5LI.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as promptFor } from "./access-EbNdZFbk.js";
|
|
2
|
-
import { a as runChild } from "./child-
|
|
3
|
-
import { c as referenceImagePath, o as nextSceneSerial } from "./library-
|
|
4
|
-
import { n as generateTransientImage, t as generateReferenceImage } from "./generator-
|
|
5
|
-
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-
|
|
2
|
+
import { a as runChild } from "./child-DsixtqTw.js";
|
|
3
|
+
import { c as referenceImagePath, o as nextSceneSerial } from "./library-COIktKBa.js";
|
|
4
|
+
import { n as generateTransientImage, t as generateReferenceImage } from "./generator-BR1ugzln.js";
|
|
5
|
+
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-CDYKJf_O.js";
|
|
6
6
|
import { dirname, join, relative } from "node:path";
|
|
7
7
|
import { existsSync } from "node:fs";
|
|
8
8
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -125,7 +125,7 @@ const VECTORS_FILE = ".vectors.json";
|
|
|
125
125
|
const MIN_SIMILARITY = .35;
|
|
126
126
|
const FUSION_CONSTANT = 60;
|
|
127
127
|
const DENSE_LIMIT = 10;
|
|
128
|
-
const hashOf = (text) => createHash("
|
|
128
|
+
const hashOf = (text) => createHash("sha256").update(text).digest("hex");
|
|
129
129
|
function cosine(a, b) {
|
|
130
130
|
let dot = 0;
|
|
131
131
|
let x = 0;
|
|
@@ -852,4 +852,4 @@ async function runImagePresenter(job) {
|
|
|
852
852
|
//#endregion
|
|
853
853
|
export { tokensOf as a, searchImages as i, interpretImage as n, present as o, imageTools as r, presentedFor as s, runImagePresenter as t };
|
|
854
854
|
|
|
855
|
-
//# sourceMappingURL=presenter-agent-
|
|
855
|
+
//# sourceMappingURL=presenter-agent-Gu34bZwd.js.map
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { Bt as ImportCardError, K as cleanText, r as MAX_PREVIEW_TEXT } from "./authoring-tools-C_8ClUkP.js";
|
|
2
|
+
import { o as SAMPLING_RANGES } from "./child-DsixtqTw.js";
|
|
3
|
+
//#region src/host/import/preset.ts
|
|
4
|
+
/** The older preset layout keeps its texts under fixed keys. */
|
|
5
|
+
const LEGACY_KEYS = [
|
|
6
|
+
"main_prompt",
|
|
7
|
+
"nsfw_prompt",
|
|
8
|
+
"jailbreak_prompt",
|
|
9
|
+
"impersonation_prompt",
|
|
10
|
+
"new_chat_prompt",
|
|
11
|
+
"new_group_chat_prompt",
|
|
12
|
+
"new_example_chat_prompt"
|
|
13
|
+
];
|
|
14
|
+
const MAX_PIECES = 60;
|
|
15
|
+
const MAX_PIECE_CHARS = 8e3;
|
|
16
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
+
const text = (value) => typeof value === "string" ? value.trim() : "";
|
|
18
|
+
/** Prompts sent as the model's own turn are prefills for one particular model, not instructions. */
|
|
19
|
+
const PREFILL_ROLES = ["assistant", "model"];
|
|
20
|
+
/** The text of the macro that opens at `from` (just after its `{{`), up to its matching `}}`, or undefined when it never closes. */
|
|
21
|
+
function macroEnd(source, from) {
|
|
22
|
+
let depth = 1;
|
|
23
|
+
for (let at = from; at < source.length - 1; at += 1) if (source.startsWith("{{", at)) {
|
|
24
|
+
depth += 1;
|
|
25
|
+
at += 1;
|
|
26
|
+
} else if (source.startsWith("}}", at)) {
|
|
27
|
+
depth -= 1;
|
|
28
|
+
if (depth === 0) return at;
|
|
29
|
+
at += 1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Splits a macro's inside at its `::`, leaving the macros nested in an argument whole. */
|
|
33
|
+
function macroParts(inside) {
|
|
34
|
+
const parts = [];
|
|
35
|
+
let depth = 0;
|
|
36
|
+
let start = 0;
|
|
37
|
+
for (let at = 0; at < inside.length; at += 1) if (inside.startsWith("{{", at)) {
|
|
38
|
+
depth += 1;
|
|
39
|
+
at += 1;
|
|
40
|
+
} else if (inside.startsWith("}}", at)) {
|
|
41
|
+
depth -= 1;
|
|
42
|
+
at += 1;
|
|
43
|
+
} else if (depth === 0 && inside.startsWith("::", at)) {
|
|
44
|
+
parts.push(inside.slice(start, at));
|
|
45
|
+
start = at + 2;
|
|
46
|
+
at += 1;
|
|
47
|
+
}
|
|
48
|
+
return [...parts, inside.slice(start)];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Plays the variable macros of a preset (`setvar`, `addvar`, `getvar`), drops its comments and `trim` markers and shows a `random` as all its choices, so that a text reads as it will to the model.
|
|
52
|
+
* The variables belong to the whole preset: a prompt early in the order may set what a later one reads.
|
|
53
|
+
*/
|
|
54
|
+
function resolveMacros(source, variables) {
|
|
55
|
+
let out = "";
|
|
56
|
+
let at = 0;
|
|
57
|
+
for (;;) {
|
|
58
|
+
const open = source.indexOf("{{", at);
|
|
59
|
+
const close = open === -1 ? void 0 : macroEnd(source, open + 2);
|
|
60
|
+
if (open === -1 || close === void 0) return out + source.slice(at);
|
|
61
|
+
out += source.slice(at, open);
|
|
62
|
+
const parts = macroParts(source.slice(open + 2, close));
|
|
63
|
+
const name = (parts[0] ?? "").trim();
|
|
64
|
+
const args = parts.slice(1).map((part) => resolveMacros(part, variables));
|
|
65
|
+
if (name.startsWith("//") || name.toLowerCase() === "trim") out += "";
|
|
66
|
+
else if (name === "setvar" || name === "setglobalvar") variables.set(args[0] ?? "", args.slice(1).join("::"));
|
|
67
|
+
else if (name === "addvar" || name === "addglobalvar") variables.set(args[0] ?? "", `${variables.get(args[0] ?? "") ?? ""}${args.slice(1).join("::")}`);
|
|
68
|
+
else if (name === "getvar" || name === "getglobalvar") out += variables.get(args[0] ?? "") ?? "";
|
|
69
|
+
else if (name === "random") out += args.join(" / ");
|
|
70
|
+
else out += source.slice(open, close + 2);
|
|
71
|
+
at = close + 2;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** The order the preset sends its prompts in: the longest list it gives, with what each entry says about being on. */
|
|
75
|
+
function orderOf(root) {
|
|
76
|
+
return ((Array.isArray(root["prompt_order"]) ? root["prompt_order"].flatMap((entry) => isObject(entry) && Array.isArray(entry["order"]) ? [entry["order"]] : []) : []).sort((a, b) => b.length - a.length)[0] ?? []).flatMap((entry) => isObject(entry) && typeof entry["identifier"] === "string" ? [{
|
|
77
|
+
identifier: entry["identifier"],
|
|
78
|
+
enabled: entry["enabled"] !== false
|
|
79
|
+
}] : []);
|
|
80
|
+
}
|
|
81
|
+
/** The sampling fields of a preset file and the control of a story each sets; a value that leaves the choice to the server is not carried. */
|
|
82
|
+
const SAMPLING_FIELDS = {
|
|
83
|
+
top_p: "topP",
|
|
84
|
+
top_k: "topK",
|
|
85
|
+
min_p: "minP",
|
|
86
|
+
frequency_penalty: "frequencyPenalty",
|
|
87
|
+
presence_penalty: "presencePenalty",
|
|
88
|
+
repetition_penalty: "repetitionPenalty"
|
|
89
|
+
};
|
|
90
|
+
/** What the file asks of the model's sampling. The one temperature is asked of the narrator and of the characters. */
|
|
91
|
+
function samplingOf(root) {
|
|
92
|
+
const sampling = {};
|
|
93
|
+
const within = (key, value) => {
|
|
94
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
|
|
95
|
+
const { min, max } = SAMPLING_RANGES[key];
|
|
96
|
+
return value < min || value > max ? void 0 : value;
|
|
97
|
+
};
|
|
98
|
+
const temperature = within("master", root["temperature"]);
|
|
99
|
+
if (temperature !== void 0) {
|
|
100
|
+
sampling["master"] = temperature;
|
|
101
|
+
sampling["characters"] = temperature;
|
|
102
|
+
}
|
|
103
|
+
for (const [field, key] of Object.entries(SAMPLING_FIELDS)) {
|
|
104
|
+
const value = within(key, root[field]);
|
|
105
|
+
if (value !== void 0 && value !== SAMPLING_RANGES[key].neutral) sampling[key] = value;
|
|
106
|
+
}
|
|
107
|
+
return sampling;
|
|
108
|
+
}
|
|
109
|
+
function parseRoot(file) {
|
|
110
|
+
let root;
|
|
111
|
+
try {
|
|
112
|
+
root = JSON.parse(file.toString("utf8").replace(/^\uFEFF/, ""));
|
|
113
|
+
} catch {
|
|
114
|
+
throw new ImportCardError("the file is not JSON: a preset is the .json file SillyTavern exports");
|
|
115
|
+
}
|
|
116
|
+
if (!isObject(root)) throw new ImportCardError("the file is not a preset: it must be a JSON object");
|
|
117
|
+
return root;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The prompts of a preset in the order it sends them, those it has switched off included, without the markers that stand for chat history or a card's fields.
|
|
121
|
+
* Prompts the order never names are not sent by the tool that wrote it and are not offered.
|
|
122
|
+
*/
|
|
123
|
+
function promptsOf(root) {
|
|
124
|
+
const prompts = Array.isArray(root["prompts"]) ? root["prompts"].filter(isObject) : [];
|
|
125
|
+
const found = [];
|
|
126
|
+
const add = (prompt, on) => {
|
|
127
|
+
const id = text(prompt["identifier"]);
|
|
128
|
+
if (id === "" || prompt["marker"] === true || text(prompt["content"]) === "" || found.some((entry) => entry.id === id)) return;
|
|
129
|
+
found.push({
|
|
130
|
+
id,
|
|
131
|
+
title: text(prompt["name"]),
|
|
132
|
+
role: text(prompt["role"]),
|
|
133
|
+
content: text(prompt["content"]),
|
|
134
|
+
on,
|
|
135
|
+
raw: prompt
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
if (prompts.length === 0) {
|
|
139
|
+
for (const key of LEGACY_KEYS) if (text(root[key]) !== "") add({
|
|
140
|
+
identifier: key,
|
|
141
|
+
name: key,
|
|
142
|
+
role: "system",
|
|
143
|
+
content: root[key]
|
|
144
|
+
}, true);
|
|
145
|
+
return found;
|
|
146
|
+
}
|
|
147
|
+
const byId = new Map(prompts.flatMap((prompt) => typeof prompt["identifier"] === "string" ? [[prompt["identifier"], prompt]] : []));
|
|
148
|
+
const ordered = orderOf(root);
|
|
149
|
+
if (ordered.length === 0) {
|
|
150
|
+
for (const prompt of prompts) add(prompt, prompt["enabled"] !== false);
|
|
151
|
+
return found;
|
|
152
|
+
}
|
|
153
|
+
for (const entry of ordered) {
|
|
154
|
+
const prompt = byId.get(entry.identifier);
|
|
155
|
+
if (prompt !== void 0) add(prompt, entry.enabled);
|
|
156
|
+
}
|
|
157
|
+
return found;
|
|
158
|
+
}
|
|
159
|
+
const isPrefill = (prompt) => PREFILL_ROLES.includes(prompt.role);
|
|
160
|
+
/**
|
|
161
|
+
* Reads a preset file. Markers (places where chat history or the card's fields are inserted), switched-off prompts, prefills and empty ones are left out; the macros of the tool that wrote it are played, so that a text holds what it will say.
|
|
162
|
+
* @throws {ImportCardError} when the file is not a preset, with why.
|
|
163
|
+
*/
|
|
164
|
+
function readPreset(file, name) {
|
|
165
|
+
const root = parseRoot(file);
|
|
166
|
+
const pieces = [];
|
|
167
|
+
const variables = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const prompt of promptsOf(root)) {
|
|
169
|
+
if (!prompt.on || isPrefill(prompt)) continue;
|
|
170
|
+
const content = cleanText(resolveMacros(prompt.content, variables), "the character");
|
|
171
|
+
if (content === "") continue;
|
|
172
|
+
pieces.push(`${prompt.title === "" ? "" : `[${prompt.title}]\n`}${content.slice(0, MAX_PIECE_CHARS)}`);
|
|
173
|
+
}
|
|
174
|
+
if (pieces.length === 0) throw new ImportCardError("the file holds no instructions this importer can read: a preset has a \"prompts\" list with texts in it");
|
|
175
|
+
const title = text(root["name"]) || text(root["preset_name"]);
|
|
176
|
+
return {
|
|
177
|
+
name: title === "" ? name.replace(/\.json$/i, "") : title,
|
|
178
|
+
pieces: pieces.slice(0, MAX_PIECES),
|
|
179
|
+
sampling: samplingOf(root)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** The scripts a preset carries for the tool that wrote it (regular expressions run over replies, helper scripts), which nothing here runs. */
|
|
183
|
+
function scriptsOf(root) {
|
|
184
|
+
const extensions = isObject(root["extensions"]) ? root["extensions"] : {};
|
|
185
|
+
const regex = Array.isArray(extensions["regex_scripts"]) ? extensions["regex_scripts"].length : 0;
|
|
186
|
+
const helper = isObject(extensions["tavern_helper"]) && Array.isArray(extensions["tavern_helper"]["scripts"]) ? extensions["tavern_helper"]["scripts"].length : 0;
|
|
187
|
+
return {
|
|
188
|
+
...regex === 0 ? {} : { regexScripts: regex },
|
|
189
|
+
...helper === 0 ? {} : { scripts: helper }
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** What a preset file offers, for the person to choose from. @throws {ImportCardError} when the file is not a preset. */
|
|
193
|
+
function previewPreset(file, name) {
|
|
194
|
+
const root = parseRoot(file);
|
|
195
|
+
const items = promptsOf(root).map((prompt) => ({
|
|
196
|
+
id: prompt.id,
|
|
197
|
+
title: prompt.title === "" ? prompt.id : prompt.title,
|
|
198
|
+
detail: prompt.role,
|
|
199
|
+
text: prompt.content.slice(0, MAX_PREVIEW_TEXT),
|
|
200
|
+
chars: prompt.content.length,
|
|
201
|
+
enabled: prompt.on && !isPrefill(prompt),
|
|
202
|
+
usable: !isPrefill(prompt),
|
|
203
|
+
...isPrefill(prompt) ? { note: "prefill" } : /\{\{\s*(?:set|add)(?:global)?var::/.test(prompt.content) ? { note: "variables" } : {}
|
|
204
|
+
}));
|
|
205
|
+
if (items.length === 0) throw new ImportCardError("the file holds no instructions this importer can read: a preset has a \"prompts\" list with texts in it");
|
|
206
|
+
const title = text(root["name"]) || text(root["preset_name"]);
|
|
207
|
+
return {
|
|
208
|
+
name: title === "" ? name.replace(/\.json$/i, "") : title,
|
|
209
|
+
items,
|
|
210
|
+
sampling: samplingOf(root),
|
|
211
|
+
ignored: scriptsOf(root)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The file with only the chosen prompts in it, in the order the preset sends them, as if the preset never had the others; the sampling stays only when asked.
|
|
216
|
+
* @throws {ImportCardError} when a chosen prompt is not in the file or nothing usable is chosen.
|
|
217
|
+
*/
|
|
218
|
+
function selectPrompts(file, enabled, keepSampling) {
|
|
219
|
+
const root = parseRoot(file);
|
|
220
|
+
const prompts = promptsOf(root);
|
|
221
|
+
const unknown = enabled.filter((id) => !prompts.some((prompt) => prompt.id === id));
|
|
222
|
+
if (unknown.length > 0) throw new ImportCardError(`the preset has no prompt ${unknown.map((id) => `"${id}"`).join(", ")}`);
|
|
223
|
+
const chosen = prompts.filter((prompt) => enabled.includes(prompt.id) && !isPrefill(prompt));
|
|
224
|
+
if (chosen.length === 0) throw new ImportCardError("choose at least one prompt of the preset");
|
|
225
|
+
const kept = { ...typeof root["name"] === "string" ? { name: root["name"] } : typeof root["preset_name"] === "string" ? { preset_name: root["preset_name"] } : {} };
|
|
226
|
+
if (keepSampling) {
|
|
227
|
+
for (const field of ["temperature", ...Object.keys(SAMPLING_FIELDS)]) if (root[field] !== void 0) kept[field] = root[field];
|
|
228
|
+
}
|
|
229
|
+
kept["prompts"] = chosen.map((prompt) => prompt.raw);
|
|
230
|
+
kept["prompt_order"] = [{
|
|
231
|
+
character_id: 100001,
|
|
232
|
+
order: chosen.map((prompt) => ({
|
|
233
|
+
identifier: prompt.id,
|
|
234
|
+
enabled: true
|
|
235
|
+
}))
|
|
236
|
+
}];
|
|
237
|
+
return Buffer.from(JSON.stringify(kept));
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
export { readPreset as n, selectPrompts as r, previewPreset as t };
|
|
241
|
+
|
|
242
|
+
//# sourceMappingURL=preset-3zn8xme7.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { G as extractStyleFrom,
|
|
2
|
-
import { _ as
|
|
3
|
-
import {
|
|
1
|
+
import { G as extractStyleFrom, J as withPlayer, i as contextOf, st as IMPORT_FOLDER } from "./authoring-tools-C_8ClUkP.js";
|
|
2
|
+
import { _ as readWorldPrompt, c as presetDirectory, g as listWorldPrompts, h as deleteWorldPrompt, l as readPreset, m as PROSE_PROMPTS, p as updatePresetInfo, t as PRESET_FILE, v as writeWorldPrompt } from "./presets-C3mhqqfz.js";
|
|
3
|
+
import { $ as shippedPromptsDirectory, Q as shippedLanguages, Y as languageOf } from "./hooks-B2EhBS_-.js";
|
|
4
|
+
import { n as readPreset$1 } from "./preset-3zn8xme7.js";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import { existsSync } from "node:fs";
|
|
6
7
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
@@ -46,9 +47,10 @@ const json = (value) => JSON.parse(JSON.stringify(value));
|
|
|
46
47
|
const idParameter = {
|
|
47
48
|
type: "string",
|
|
48
49
|
required: true,
|
|
49
|
-
|
|
50
|
-
description: "The prompt: roleplay/persona, roleplay/style or roleplay/character-style."
|
|
50
|
+
description: "The prompt, such as roleplay/style. The prose prompts are roleplay/persona, roleplay/style and roleplay/character-style; every other roleplay/ prompt holds rules of the game (see list_preset_prompts)."
|
|
51
51
|
};
|
|
52
|
+
/** Whether a prompt holds rules of the game, which tell the models how to work and not only how the story reads. */
|
|
53
|
+
const isRulesPrompt = (id) => typeof id === "string" && !PROSE_PROMPTS.includes(id);
|
|
52
54
|
const languageParameter = {
|
|
53
55
|
type: "string",
|
|
54
56
|
required: true,
|
|
@@ -86,22 +88,18 @@ function presetAuthorTools(reader, settings, prompting, shipped = shippedPrompts
|
|
|
86
88
|
isConcurrencySafe: () => true,
|
|
87
89
|
async execute(_args, exec) {
|
|
88
90
|
const { name, directory } = reader.directory(exec);
|
|
89
|
-
return json(readPreset
|
|
91
|
+
return json(readPreset(directory, name, shipped).summary);
|
|
90
92
|
}
|
|
91
93
|
}),
|
|
92
94
|
defineTool({
|
|
93
95
|
name: "list_preset_prompts",
|
|
94
|
-
description: "List
|
|
96
|
+
description: "List every prompt of the story, in a language, with its kind (prose, or rules of the game) and whether this preset carries its own version.",
|
|
95
97
|
parameters: { language: languageParameter },
|
|
96
98
|
output: jsonOutput,
|
|
97
99
|
isConcurrencySafe: () => true,
|
|
98
100
|
async execute(args, exec) {
|
|
99
101
|
const { directory } = reader.directory(exec);
|
|
100
|
-
|
|
101
|
-
return json(PROSE_PROMPTS.map((id) => ({
|
|
102
|
-
id,
|
|
103
|
-
carried: existsSync(join(directory, PROMPTS_FOLDER, tag, `${id}.md`))
|
|
104
|
-
})));
|
|
102
|
+
return json(listWorldPrompts(directory, args.language, shipped));
|
|
105
103
|
}
|
|
106
104
|
}),
|
|
107
105
|
defineTool({
|
|
@@ -120,7 +118,7 @@ function presetAuthorTools(reader, settings, prompting, shipped = shippedPrompts
|
|
|
120
118
|
}),
|
|
121
119
|
defineTool({
|
|
122
120
|
name: "write_preset_prompt",
|
|
123
|
-
description: "Create or replace the preset's version of a prompt in a language. It must not be empty and may use only the ${variables} the shipped prompt uses; tool names and field names in it must stay as they are. Read it first and change only what is needed. Requires user approval.",
|
|
121
|
+
description: "Create or replace the preset's version of a prompt in a language. It must not be empty and may use only the ${variables} the shipped prompt uses; tool names and field names in it must stay as they are. Read it first and change only what is needed. Prompts other than the three prose ones hold rules of the game: change them only when the person asked for it, keep the shipped text and add to it rather than replacing it, and know that the person is shown a warning. Requires user approval.",
|
|
124
122
|
parameters: {
|
|
125
123
|
id: idParameter,
|
|
126
124
|
language: languageParameter,
|
|
@@ -133,7 +131,7 @@ function presetAuthorTools(reader, settings, prompting, shipped = shippedPrompts
|
|
|
133
131
|
output: jsonOutput,
|
|
134
132
|
async execute(args, exec) {
|
|
135
133
|
const { directory } = reader.directory(exec);
|
|
136
|
-
if (!
|
|
134
|
+
if (!args.id.startsWith("roleplay/")) throw new Error(`"${args.id}" is not a prompt of the story`);
|
|
137
135
|
await writeWorldPrompt(directory, args.language, args.id, args.text, shipped);
|
|
138
136
|
return json({
|
|
139
137
|
action: "written",
|
|
@@ -163,7 +161,7 @@ function presetAuthorTools(reader, settings, prompting, shipped = shippedPrompts
|
|
|
163
161
|
}),
|
|
164
162
|
defineTool({
|
|
165
163
|
name: "write_preset_info",
|
|
166
|
-
description: "Change the preset's title, description (up to 300 characters each) and suggested
|
|
164
|
+
description: "Change the preset's title, description (up to 300 characters each) and suggested sampling. Give only what changes; sampling replaces the suggested values as a whole ({} suggests none): master and characters are temperatures from 0 to 2; topP and minP 0 to 1, topK 0 to 1000, frequencyPenalty and presencePenalty -2 to 2, repetitionPenalty 0 to 2 apply to both. Requires user approval.",
|
|
167
165
|
parameters: {
|
|
168
166
|
title: {
|
|
169
167
|
type: "string",
|
|
@@ -175,7 +173,7 @@ function presetAuthorTools(reader, settings, prompting, shipped = shippedPrompts
|
|
|
175
173
|
},
|
|
176
174
|
sampling: {
|
|
177
175
|
type: "json",
|
|
178
|
-
description: "For example {\"master\": 0.9, \"characters\": 0.85}."
|
|
176
|
+
description: "For example {\"master\": 0.9, \"characters\": 0.85, \"topP\": 0.95}."
|
|
179
177
|
}
|
|
180
178
|
},
|
|
181
179
|
output: jsonOutput,
|
|
@@ -208,7 +206,7 @@ function presetAuthorTools(reader, settings, prompting, shipped = shippedPrompts
|
|
|
208
206
|
if (args.file.trim() !== UPLOAD_PATH) throw new Error(`the uploaded preset is ${UPLOAD_PATH}`);
|
|
209
207
|
const { name, directory } = reader.directory(exec);
|
|
210
208
|
const file = join(directory, IMPORT_FOLDER, PRESET_FILE);
|
|
211
|
-
const uploaded = readPreset(await readFile(file).catch(() => {
|
|
209
|
+
const uploaded = readPreset$1(await readFile(file).catch(() => {
|
|
212
210
|
throw new Error("no preset was uploaded here");
|
|
213
211
|
}), name);
|
|
214
212
|
const language = prompting.languages().get(`preset:${name}`);
|
|
@@ -255,6 +253,14 @@ async function presetApproval(exec, next, carries) {
|
|
|
255
253
|
};
|
|
256
254
|
const target = `prompt “${String(args["language"])}/${String(args["id"])}”`;
|
|
257
255
|
const remove = exec.name.startsWith("delete");
|
|
256
|
+
if (isRulesPrompt(args["id"])) return {
|
|
257
|
+
kind: "ask",
|
|
258
|
+
reason: `${remove ? "delete" : "write"} preset ${target}, a rules prompt`,
|
|
259
|
+
displayReason: {
|
|
260
|
+
en: `WARNING: ${target} holds rules of the game, not only prose. ${remove ? "Delete" : "Write"} it in the preset? A wrong change can break how the story runs.`,
|
|
261
|
+
zh: `警告:${target}属于游戏规则,而不只是文风。${remove ? "删除" : "写入"}预设中的这条提示词?改错可能会影响故事的运行。`
|
|
262
|
+
}
|
|
263
|
+
};
|
|
258
264
|
return {
|
|
259
265
|
kind: "ask",
|
|
260
266
|
reason: `${remove ? "delete" : "write"} preset ${target}`,
|
|
@@ -267,4 +273,4 @@ async function presetApproval(exec, next, carries) {
|
|
|
267
273
|
//#endregion
|
|
268
274
|
export { presetChatSessionId as a, presetAuthorTools as i, narrationImportMessage as n, presetOfChat as o, presetApproval as r, PresetReader as t };
|
|
269
275
|
|
|
270
|
-
//# sourceMappingURL=preset-author-tools-
|
|
276
|
+
//# sourceMappingURL=preset-author-tools-C-X8G40s.js.map
|
package/lib/preset-authoring.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
3
|
-
import
|
|
1
|
+
import { n as limitAuthoringAgents } from "./authoring-tools-C_8ClUkP.js";
|
|
2
|
+
import { c as presetDirectory } from "./presets-C3mhqqfz.js";
|
|
3
|
+
import "./hooks-B2EhBS_-.js";
|
|
4
|
+
import { i as presetAuthorTools, o as presetOfChat, r as presetApproval, t as PresetReader } from "./preset-author-tools-C-X8G40s.js";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import { existsSync } from "node:fs";
|
|
6
7
|
//#region src/preset-authoring.ts
|
|
@@ -10,6 +11,7 @@ const inject = [
|
|
|
10
11
|
"roleplayImport",
|
|
11
12
|
"roleplayPrompts",
|
|
12
13
|
"roleplayAuthoringLanguages",
|
|
14
|
+
"roleplayAuthoringTools",
|
|
13
15
|
"tools",
|
|
14
16
|
"systemPrompt"
|
|
15
17
|
];
|
|
@@ -26,6 +28,7 @@ function apply(ctx) {
|
|
|
26
28
|
const preset = presetOfChat(chat);
|
|
27
29
|
return preset !== void 0 && existsSync(join(presetDirectory(library(), preset), "prompts"));
|
|
28
30
|
};
|
|
31
|
+
limitAuthoringAgents(ctx, (chat) => presetOfChat(chat) === void 0 ? void 0 : "presetAuthoring");
|
|
29
32
|
ctx.on("tools/pre-execute", (exec, next) => presetApproval(exec, next, carries));
|
|
30
33
|
const languageOf = (context) => {
|
|
31
34
|
const chat = context.agent?.session.id;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as shippedPromptsDirectory, G as PROMPTS_FOLDER, Q as shippedLanguages, W as LANGUAGE_FOLDER, X as listFiles, Y as languageOf, Z as promptProblem } from "./hooks-B2EhBS_-.js";
|
|
2
|
+
import { s as parseSampling } from "./child-DsixtqTw.js";
|
|
2
3
|
import { dirname, join } from "node:path";
|
|
3
4
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
4
5
|
import { createHash } from "node:crypto";
|
|
@@ -48,11 +49,7 @@ function fileOf(directory, language, id, shipped) {
|
|
|
48
49
|
/** Every prompt of the story, in a language, and whether the world carries its own version. */
|
|
49
50
|
function listWorldPrompts(directory, language, shipped = shippedPromptsDirectory()) {
|
|
50
51
|
const tag = languageOf(language);
|
|
51
|
-
return readdirSync(join(shipped, "en"), { withFileTypes: true }).filter((entry) => entry.isDirectory() &&
|
|
52
|
-
"import",
|
|
53
|
-
"world",
|
|
54
|
-
"preset"
|
|
55
|
-
].includes(entry.name)).flatMap((entry) => listFiles(join(shipped, "en", entry.name), `${entry.name}/`)).sort().map((id) => ({
|
|
52
|
+
return readdirSync(join(shipped, "en"), { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name === "roleplay").flatMap((entry) => listFiles(join(shipped, "en", entry.name), `${entry.name}/`)).sort().map((id) => ({
|
|
56
53
|
id,
|
|
57
54
|
kind: PROSE_PROMPTS.includes(id) ? "prose" : "rules",
|
|
58
55
|
carried: existsSync(join(directory, PROMPTS_FOLDER, tag, `${id}.md`))
|
|
@@ -104,7 +101,6 @@ const PRESETS_FOLDER = "presets";
|
|
|
104
101
|
const PRESET_FILE = "preset.json";
|
|
105
102
|
const NAME = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
106
103
|
const MAX_TEXT = 300;
|
|
107
|
-
const SAMPLING_KEYS = ["master", "characters"];
|
|
108
104
|
const isPresetName = (name) => NAME.test(name);
|
|
109
105
|
const presetsDirectory = (root) => join(root, PRESETS_FOLDER);
|
|
110
106
|
function presetDirectory(root, name) {
|
|
@@ -126,20 +122,7 @@ function parseHeader(value, problems) {
|
|
|
126
122
|
}
|
|
127
123
|
return field.trim() || void 0;
|
|
128
124
|
};
|
|
129
|
-
const sampling = {};
|
|
130
|
-
const given = value["sampling"];
|
|
131
|
-
if (given !== void 0 && given !== null) {
|
|
132
|
-
if (!isRecord(given)) problems.push(`${PRESET_FILE}: "sampling" must be an object`);
|
|
133
|
-
else {
|
|
134
|
-
for (const key of Object.keys(given)) if (!SAMPLING_KEYS.includes(key)) problems.push(`${PRESET_FILE}: sampling.${key} is not something a preset sets (${SAMPLING_KEYS.join(", ")})`);
|
|
135
|
-
for (const key of SAMPLING_KEYS) {
|
|
136
|
-
const number = given[key];
|
|
137
|
-
if (number === void 0) continue;
|
|
138
|
-
if (typeof number !== "number" || !Number.isFinite(number) || number < 0 || number > 2) problems.push(`${PRESET_FILE}: sampling.${key} must be a number from 0 to 2`);
|
|
139
|
-
else sampling[key] = number;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
125
|
+
const sampling = parseSampling(value["sampling"], `${PRESET_FILE}: sampling`, problems);
|
|
143
126
|
const title = text("title");
|
|
144
127
|
const description = text("description");
|
|
145
128
|
return {
|
|
@@ -175,20 +158,22 @@ function readPreset(directory, name, shipped = shippedPromptsDirectory()) {
|
|
|
175
158
|
for (const id of listFiles(join(base, entry.name))) {
|
|
176
159
|
const path = `${entry.name}/${id}.md`;
|
|
177
160
|
const text = readFileSync(join(base, path), "utf8");
|
|
178
|
-
const problem =
|
|
161
|
+
const problem = id.startsWith("roleplay/") ? promptProblem(entry.name, id, text, shipped) : `"${id}" is not a prompt of the story`;
|
|
179
162
|
if (problem !== void 0) problems.push(`prompts/${path}: ${problem}`);
|
|
180
163
|
else files.set(path, text);
|
|
181
164
|
}
|
|
182
165
|
}
|
|
183
166
|
if (files.size === 0 && problems.length === 0) problems.push("the preset carries no prompts");
|
|
184
167
|
const paths = [...files.keys()];
|
|
168
|
+
const ids = [...new Set(paths.map((path) => path.slice(path.indexOf("/") + 1, -3)))].sort((a, b) => a.localeCompare(b));
|
|
185
169
|
return {
|
|
186
170
|
summary: {
|
|
187
171
|
name,
|
|
188
172
|
title: header.title ?? name,
|
|
189
173
|
description: header.description ?? "",
|
|
190
|
-
languages: [...new Set(paths.map((path) => path.split("/")[0]))].sort(),
|
|
191
|
-
prompts:
|
|
174
|
+
languages: [...new Set(paths.map((path) => path.split("/")[0]))].sort((a, b) => a.localeCompare(b)),
|
|
175
|
+
prompts: ids,
|
|
176
|
+
rules: ids.filter((id) => !PROSE_PROMPTS.includes(id)),
|
|
192
177
|
sampling: header.sampling,
|
|
193
178
|
problems
|
|
194
179
|
},
|
|
@@ -322,14 +307,51 @@ async function createPresetFromShipped(root, request, shipped = shippedPromptsDi
|
|
|
322
307
|
}
|
|
323
308
|
}
|
|
324
309
|
/** 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. */
|
|
325
|
-
async function reservePreset(root, name, title) {
|
|
310
|
+
async function reservePreset(root, name, title, sampling = {}) {
|
|
326
311
|
const target = presetDirectory(root, name);
|
|
327
312
|
if (existsSync(target)) throw new Error(`there is already a preset "${name}"`);
|
|
328
313
|
await mkdir(target, { recursive: true });
|
|
329
|
-
await writeHeader(target, headerFile(title.trim().slice(0, MAX_TEXT) || void 0, void 0,
|
|
314
|
+
await writeHeader(target, headerFile(title.trim().slice(0, MAX_TEXT) || void 0, void 0, sampling));
|
|
330
315
|
return target;
|
|
331
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* 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
|
|
319
|
+
* the prompt keeps naming the tools and values it needs. The guidance is the importer's, in the language it was written in.
|
|
320
|
+
* @throws {Error} when the name is taken, there is no guidance, or a prompt would not be acceptable; nothing is made then.
|
|
321
|
+
*/
|
|
322
|
+
async function createPresetFromGuidance(root, request, guidance, shipped = shippedPromptsDirectory()) {
|
|
323
|
+
const target = presetDirectory(root, request.name);
|
|
324
|
+
if (existsSync(target)) throw new Error(`there is already a preset "${request.name}"`);
|
|
325
|
+
const ids = Object.keys(guidance).filter((id) => (guidance[id]?.length ?? 0) > 0);
|
|
326
|
+
if (ids.length === 0) throw new Error("there is no guidance to make a preset of");
|
|
327
|
+
const problems = [];
|
|
328
|
+
const header = parseHeader({
|
|
329
|
+
title: request.title?.trim(),
|
|
330
|
+
description: request.description?.trim()
|
|
331
|
+
}, problems);
|
|
332
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
333
|
+
const staging = join(root, ".install", `preset-${request.name}-${Date.now()}`);
|
|
334
|
+
try {
|
|
335
|
+
for (const language of shippedLanguages(shipped)) for (const id of ids) {
|
|
336
|
+
const base = readWorldPrompt(join(staging, "none"), language, id, shipped).text.trimEnd();
|
|
337
|
+
const to = join(staging, PROMPTS_FOLDER, language, `${id}.md`);
|
|
338
|
+
await mkdir(dirname(to), { recursive: true });
|
|
339
|
+
await writeFile(to, `${base}\n\n${(guidance[id] ?? []).join("\n")}\n`);
|
|
340
|
+
}
|
|
341
|
+
await writeHeader(staging, headerFile(header.title, header.description, {}));
|
|
342
|
+
const loaded = readPreset(staging, request.name);
|
|
343
|
+
if (loaded.summary.problems.length > 0) throw new Error(`the preset would have problems: ${loaded.summary.problems.join("; ")}`);
|
|
344
|
+
await mkdir(presetsDirectory(root), { recursive: true });
|
|
345
|
+
await rename(staging, target);
|
|
346
|
+
return readPreset(target, request.name);
|
|
347
|
+
} finally {
|
|
348
|
+
await rm(staging, {
|
|
349
|
+
recursive: true,
|
|
350
|
+
force: true
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
332
354
|
//#endregion
|
|
333
|
-
export {
|
|
355
|
+
export { readWorldPrompt as _, isPresetName as a, INTENT_STATUSES as b, presetDirectory as c, savePresetFromWorld as d, sha as f, listWorldPrompts as g, deleteWorldPrompt as h, deletePreset as i, readPreset as l, PROSE_PROMPTS as m, createPresetFromGuidance as n, listPresets as o, updatePresetInfo as p, createPresetFromShipped as r, loadPreset as s, PRESET_FILE as t, reservePreset as u, writeWorldPrompt as v, INTENT_TYPES as x, INTENT_HORIZONS as y };
|
|
334
356
|
|
|
335
|
-
//# sourceMappingURL=presets-
|
|
357
|
+
//# sourceMappingURL=presets-C3mhqqfz.js.map
|