@dsh-agentic-roleplay/core 0.3.4 → 0.3.6
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/authoring.js +5 -3
- package/lib/client.js +3260 -493
- package/lib/client.js.map +1 -1
- package/lib/{deliver-CpZOxBX5.js → deliver-BBgciEEK.js} +3 -2
- package/lib/doctor.js +3 -3
- package/lib/{gallery-CtFDL22W.js → gallery-DIEgETzU.js} +2 -2
- package/lib/generator-DJ48HxPI.js +145 -0
- package/lib/{hooks-KTCR3fNJ.js → hooks-DkwFGtNH.js} +3 -3
- package/lib/images.js +4 -3
- package/lib/index.js +889 -52
- package/lib/language-BgyxtB2h.js +38 -0
- package/lib/{generator-B6FxlKOV.js → library-9JB9zw5a.js} +2 -143
- package/lib/{language-DWVwi1R7.js → load-CVwJjIJ5.js} +11 -45
- package/lib/lorebook-author-tools-Bj31z1cu.js +619 -0
- package/lib/lorebook-authoring.js +67 -0
- package/lib/orchestration.js +22 -14
- package/lib/pack-jail-2XztyYAX.js +1980 -0
- package/lib/{packs-BYjrAen6.js → packs-xHRCcGdb.js} +3 -29
- package/lib/{presenter-agent-CiEVKcjJ.js → presenter-agent-DnNEG_Mn.js} +4 -3
- package/lib/preset-D0FMSeZ9.js +59 -0
- package/lib/preset-author-tools-BxycmoAr.js +276 -0
- package/lib/preset-authoring.js +53 -0
- package/lib/presets-gkBWAiVb.js +374 -0
- package/lib/{reflection-waxFg1x-.js → reflection-q0UpwXlx.js} +130 -8
- package/lib/{pack-jail-CybSNzxr.js → tools-Dy1fgP6B.js} +454 -2303
- package/package.json +4 -2
- package/prompts/en/import/lorebook.md +7 -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 -0
- package/prompts/en/preset/procedure.md +1 -0
- package/prompts/en/preset/welcome.md +1 -0
- package/prompts/zh/import/lorebook.md +7 -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 -0
- package/prompts/zh/preset/procedure.md +1 -0
- package/prompts/zh/preset/welcome.md +1 -0
|
@@ -1,33 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as Reader } from "./load-CVwJjIJ5.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";
|
|
5
|
-
//#region ../dsh-roleplay-model/src/intent.ts
|
|
6
|
-
const INTENT_TYPES = [
|
|
7
|
-
"need",
|
|
8
|
-
"obligation",
|
|
9
|
-
"quest",
|
|
10
|
-
"agenda",
|
|
11
|
-
"aspiration",
|
|
12
|
-
"relationship",
|
|
13
|
-
"habit",
|
|
14
|
-
"reaction"
|
|
15
|
-
];
|
|
16
|
-
const INTENT_STATUSES = [
|
|
17
|
-
"active",
|
|
18
|
-
"paused",
|
|
19
|
-
"completed",
|
|
20
|
-
"failed",
|
|
21
|
-
"abandoned"
|
|
22
|
-
];
|
|
23
|
-
const INTENT_HORIZONS = [
|
|
24
|
-
"immediate",
|
|
25
|
-
"short",
|
|
26
|
-
"day",
|
|
27
|
-
"long",
|
|
28
|
-
"open_ended"
|
|
29
|
-
];
|
|
30
|
-
//#endregion
|
|
31
5
|
//#region src/shared/worlds.ts
|
|
32
6
|
/** Path prefix of the plugin's HTTP API. Relative, so a mounted deployment resolves it against the page. */
|
|
33
7
|
const API_PREFIX = "roleplay-api";
|
|
@@ -861,6 +835,6 @@ function anyTab(bases) {
|
|
|
861
835
|
}));
|
|
862
836
|
}
|
|
863
837
|
//#endregion
|
|
864
|
-
export { API_PREFIX as _, packIds as a,
|
|
838
|
+
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 };
|
|
865
839
|
|
|
866
|
-
//# sourceMappingURL=packs-
|
|
840
|
+
//# sourceMappingURL=packs-xHRCcGdb.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { t as promptFor } from "./access-EbNdZFbk.js";
|
|
2
2
|
import { a as runChild } from "./child-CFjnaTZt.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { c as referenceImagePath, o as nextSceneSerial } from "./library-9JB9zw5a.js";
|
|
4
|
+
import { n as generateTransientImage, t as generateReferenceImage } from "./generator-DJ48HxPI.js";
|
|
5
|
+
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-DIEgETzU.js";
|
|
5
6
|
import { dirname, join, relative } from "node:path";
|
|
6
7
|
import { existsSync } from "node:fs";
|
|
7
8
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -851,4 +852,4 @@ async function runImagePresenter(job) {
|
|
|
851
852
|
//#endregion
|
|
852
853
|
export { tokensOf as a, searchImages as i, interpretImage as n, present as o, imageTools as r, presentedFor as s, runImagePresenter as t };
|
|
853
854
|
|
|
854
|
-
//# sourceMappingURL=presenter-agent-
|
|
855
|
+
//# sourceMappingURL=presenter-agent-DnNEG_Mn.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { It as ImportCardError } from "./tools-Dy1fgP6B.js";
|
|
2
|
+
//#region src/host/import/preset.ts
|
|
3
|
+
/** The older preset layout keeps its texts under fixed keys. */
|
|
4
|
+
const LEGACY_KEYS = [
|
|
5
|
+
"main_prompt",
|
|
6
|
+
"nsfw_prompt",
|
|
7
|
+
"jailbreak_prompt",
|
|
8
|
+
"impersonation_prompt",
|
|
9
|
+
"new_chat_prompt",
|
|
10
|
+
"new_group_chat_prompt",
|
|
11
|
+
"new_example_chat_prompt"
|
|
12
|
+
];
|
|
13
|
+
const MAX_PIECES = 60;
|
|
14
|
+
const MAX_PIECE_CHARS = 8e3;
|
|
15
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16
|
+
const text = (value) => typeof value === "string" ? value.trim() : "";
|
|
17
|
+
/** The order the preset sends its prompts in: the longest list it gives, with what each entry says about being on. */
|
|
18
|
+
function orderOf(root) {
|
|
19
|
+
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" ? [{
|
|
20
|
+
identifier: entry["identifier"],
|
|
21
|
+
enabled: entry["enabled"] !== false
|
|
22
|
+
}] : []);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Reads a preset file. Markers (places where chat history or the card's fields are inserted), switched-off prompts and empty ones are left out.
|
|
26
|
+
* @throws {ImportCardError} when the file is not a preset, with why.
|
|
27
|
+
*/
|
|
28
|
+
function readPreset(file, name) {
|
|
29
|
+
let root;
|
|
30
|
+
try {
|
|
31
|
+
root = JSON.parse(file.toString("utf8").replace(/^/, ""));
|
|
32
|
+
} catch {
|
|
33
|
+
throw new ImportCardError("the file is not JSON: a preset is the .json file SillyTavern exports");
|
|
34
|
+
}
|
|
35
|
+
if (!isObject(root)) throw new ImportCardError("the file is not a preset: it must be a JSON object");
|
|
36
|
+
const pieces = [];
|
|
37
|
+
const prompts = Array.isArray(root["prompts"]) ? root["prompts"].filter(isObject) : [];
|
|
38
|
+
if (prompts.length > 0) {
|
|
39
|
+
const byId = new Map(prompts.flatMap((prompt) => typeof prompt["identifier"] === "string" ? [[prompt["identifier"], prompt]] : []));
|
|
40
|
+
const ordered = orderOf(root);
|
|
41
|
+
const chosen = ordered.length > 0 ? ordered.flatMap((entry) => entry.enabled && byId.has(entry.identifier) ? [byId.get(entry.identifier)] : []) : prompts.filter((prompt) => prompt["enabled"] !== false);
|
|
42
|
+
for (const prompt of chosen) {
|
|
43
|
+
const content = text(prompt["content"]);
|
|
44
|
+
if (prompt["marker"] === true || content === "") continue;
|
|
45
|
+
const title = text(prompt["name"]);
|
|
46
|
+
pieces.push(`${title === "" ? "" : `[${title}]\n`}${content.slice(0, MAX_PIECE_CHARS)}`);
|
|
47
|
+
}
|
|
48
|
+
} else for (const key of LEGACY_KEYS) if (text(root[key]) !== "") pieces.push(`[${key}]\n${text(root[key]).slice(0, MAX_PIECE_CHARS)}`);
|
|
49
|
+
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");
|
|
50
|
+
const title = text(root["name"]) || text(root["preset_name"]);
|
|
51
|
+
return {
|
|
52
|
+
name: title === "" ? name.replace(/\.json$/i, "") : title,
|
|
53
|
+
pieces: pieces.slice(0, MAX_PIECES)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { readPreset as t };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=preset-D0FMSeZ9.js.map
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { G as withPlayer, H as extractStyleFrom, it as IMPORT_FOLDER, t as contextOf } from "./tools-Dy1fgP6B.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-gkBWAiVb.js";
|
|
3
|
+
import { _ as shippedLanguages, m as languageOf, v as shippedPromptsDirectory } from "./load-CVwJjIJ5.js";
|
|
4
|
+
import { t as readPreset$1 } from "./preset-D0FMSeZ9.js";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
8
|
+
import { readFile, rm } from "node:fs/promises";
|
|
9
|
+
//#region src/shared/preset-chat.ts
|
|
10
|
+
const PREFIX = "preset-author-";
|
|
11
|
+
/** Stable DSH chat identity for the authoring conversation of one library preset. */
|
|
12
|
+
function presetChatSessionId(name) {
|
|
13
|
+
if (name === "") throw new TypeError("preset name cannot be empty");
|
|
14
|
+
return `${PREFIX}${encodeURIComponent(name)}`;
|
|
15
|
+
}
|
|
16
|
+
/** The library preset named by a dedicated preset authoring chat. */
|
|
17
|
+
function presetOfChat(chatSessionId) {
|
|
18
|
+
if (!chatSessionId.startsWith(PREFIX)) return void 0;
|
|
19
|
+
try {
|
|
20
|
+
const name = decodeURIComponent(chatSessionId.slice(14));
|
|
21
|
+
return name === "" ? void 0 : name;
|
|
22
|
+
} catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/host/authoring/preset-author-tools.ts
|
|
28
|
+
const PRESET_MUTATION_TOOLS = [
|
|
29
|
+
"write_preset_prompt",
|
|
30
|
+
"delete_preset_prompt",
|
|
31
|
+
"write_preset_info",
|
|
32
|
+
"import_narration_preset"
|
|
33
|
+
];
|
|
34
|
+
const NARRATION_IMPORT_TOOL = "import_narration_preset";
|
|
35
|
+
const UPLOAD_PATH = `${IMPORT_FOLDER}/${PRESET_FILE}`;
|
|
36
|
+
/** The command that has a preset's authoring chat turn an uploaded SillyTavern preset into prompts. */
|
|
37
|
+
const narrationImportMessage = () => `Turn the SillyTavern preset I uploaded into this preset's prompts: call ${NARRATION_IMPORT_TOOL} with file ${UPLOAD_PATH}.`;
|
|
38
|
+
const output = (value) => [{
|
|
39
|
+
type: "text",
|
|
40
|
+
text: JSON.stringify(value, null, 2)
|
|
41
|
+
}];
|
|
42
|
+
const jsonOutput = {
|
|
43
|
+
schema: { type: "json" },
|
|
44
|
+
render: (_args, value) => output(value)
|
|
45
|
+
};
|
|
46
|
+
const json = (value) => JSON.parse(JSON.stringify(value));
|
|
47
|
+
const idParameter = {
|
|
48
|
+
type: "string",
|
|
49
|
+
required: true,
|
|
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
|
+
};
|
|
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);
|
|
54
|
+
const languageParameter = {
|
|
55
|
+
type: "string",
|
|
56
|
+
required: true,
|
|
57
|
+
description: "The language folder, such as en or zh."
|
|
58
|
+
};
|
|
59
|
+
/** Resolves every call from its preset authoring chat, so a tool can only reach the preset the chat is about. */
|
|
60
|
+
var PresetReader = class {
|
|
61
|
+
root;
|
|
62
|
+
constructor(root) {
|
|
63
|
+
this.root = root;
|
|
64
|
+
}
|
|
65
|
+
directory(exec) {
|
|
66
|
+
const chat = exec.agent?.session.id;
|
|
67
|
+
const name = chat === void 0 ? void 0 : presetOfChat(chat);
|
|
68
|
+
if (name === void 0) throw new Error("this tool is available only in a preset authoring chat");
|
|
69
|
+
const directory = presetDirectory(this.root(), name);
|
|
70
|
+
if (!existsSync(directory)) throw new Error(`the preset "${name}" no longer exists`);
|
|
71
|
+
return {
|
|
72
|
+
name,
|
|
73
|
+
directory
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
get library() {
|
|
77
|
+
return this.root();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
/** Read and write the prompts and the information of the preset the chat is about. The files are those a story start copies, so they are checked as it checks them. */
|
|
81
|
+
function presetAuthorTools(reader, settings, prompting, shipped = shippedPromptsDirectory()) {
|
|
82
|
+
return [
|
|
83
|
+
defineTool({
|
|
84
|
+
name: "read_preset_info",
|
|
85
|
+
description: "Read the preset's title, description, suggested temperatures, the languages it has prompts in and any problems it has.",
|
|
86
|
+
parameters: {},
|
|
87
|
+
output: jsonOutput,
|
|
88
|
+
isConcurrencySafe: () => true,
|
|
89
|
+
async execute(_args, exec) {
|
|
90
|
+
const { name, directory } = reader.directory(exec);
|
|
91
|
+
return json(readPreset(directory, name, shipped).summary);
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
defineTool({
|
|
95
|
+
name: "list_preset_prompts",
|
|
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.",
|
|
97
|
+
parameters: { language: languageParameter },
|
|
98
|
+
output: jsonOutput,
|
|
99
|
+
isConcurrencySafe: () => true,
|
|
100
|
+
async execute(args, exec) {
|
|
101
|
+
const { directory } = reader.directory(exec);
|
|
102
|
+
return json(listWorldPrompts(directory, args.language, shipped));
|
|
103
|
+
}
|
|
104
|
+
}),
|
|
105
|
+
defineTool({
|
|
106
|
+
name: "read_preset_prompt",
|
|
107
|
+
description: "Read a prompt of the preset. When the preset does not carry it in that language, the shipped text is returned (carried: false), which is what a story would use and a good starting point. ${name} marks a value the program fills in.",
|
|
108
|
+
parameters: {
|
|
109
|
+
id: idParameter,
|
|
110
|
+
language: languageParameter
|
|
111
|
+
},
|
|
112
|
+
output: jsonOutput,
|
|
113
|
+
isConcurrencySafe: () => true,
|
|
114
|
+
async execute(args, exec) {
|
|
115
|
+
const { directory } = reader.directory(exec);
|
|
116
|
+
return json(readWorldPrompt(directory, args.language, args.id, shipped));
|
|
117
|
+
}
|
|
118
|
+
}),
|
|
119
|
+
defineTool({
|
|
120
|
+
name: "write_preset_prompt",
|
|
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.",
|
|
122
|
+
parameters: {
|
|
123
|
+
id: idParameter,
|
|
124
|
+
language: languageParameter,
|
|
125
|
+
text: {
|
|
126
|
+
type: "string",
|
|
127
|
+
required: true,
|
|
128
|
+
description: "The complete prompt text."
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
output: jsonOutput,
|
|
132
|
+
async execute(args, exec) {
|
|
133
|
+
const { directory } = reader.directory(exec);
|
|
134
|
+
if (!args.id.startsWith("roleplay/")) throw new Error(`"${args.id}" is not a prompt of the story`);
|
|
135
|
+
await writeWorldPrompt(directory, args.language, args.id, args.text, shipped);
|
|
136
|
+
return json({
|
|
137
|
+
action: "written",
|
|
138
|
+
id: args.id,
|
|
139
|
+
language: languageOf(args.language)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}),
|
|
143
|
+
defineTool({
|
|
144
|
+
name: "delete_preset_prompt",
|
|
145
|
+
description: "Remove the preset's version of a prompt in a language; stories started with the preset then use the shipped one. The file is moved into the preset's .trash. Requires user approval.",
|
|
146
|
+
parameters: {
|
|
147
|
+
id: idParameter,
|
|
148
|
+
language: languageParameter
|
|
149
|
+
},
|
|
150
|
+
output: jsonOutput,
|
|
151
|
+
async execute(args, exec) {
|
|
152
|
+
const { directory } = reader.directory(exec);
|
|
153
|
+
const trashPath = await deleteWorldPrompt(directory, args.language, args.id, shipped);
|
|
154
|
+
return json({
|
|
155
|
+
action: "deleted",
|
|
156
|
+
id: args.id,
|
|
157
|
+
language: languageOf(args.language),
|
|
158
|
+
trashPath
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}),
|
|
162
|
+
defineTool({
|
|
163
|
+
name: "write_preset_info",
|
|
164
|
+
description: "Change the preset's title, description (up to 300 characters each) and suggested temperatures. Give only what changes; sampling replaces the suggested temperatures as a whole ({} suggests none) and has only master (the narrator) and characters, each from 0 to 2. Requires user approval.",
|
|
165
|
+
parameters: {
|
|
166
|
+
title: {
|
|
167
|
+
type: "string",
|
|
168
|
+
description: "A short name to show; empty to clear."
|
|
169
|
+
},
|
|
170
|
+
description: {
|
|
171
|
+
type: "string",
|
|
172
|
+
description: "What the preset is for; empty to clear."
|
|
173
|
+
},
|
|
174
|
+
sampling: {
|
|
175
|
+
type: "json",
|
|
176
|
+
description: "For example {\"master\": 0.9, \"characters\": 0.85}."
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
output: jsonOutput,
|
|
180
|
+
async execute(args, exec) {
|
|
181
|
+
const { name } = reader.directory(exec);
|
|
182
|
+
const sampling = args.sampling;
|
|
183
|
+
if (sampling !== void 0 && (typeof sampling !== "object" || sampling === null || Array.isArray(sampling))) throw new Error("\"sampling\" must be an object");
|
|
184
|
+
const loaded = await updatePresetInfo(reader.library, name, {
|
|
185
|
+
...args.title === void 0 ? {} : { title: args.title },
|
|
186
|
+
...args.description === void 0 ? {} : { description: args.description },
|
|
187
|
+
...sampling === void 0 ? {} : { sampling }
|
|
188
|
+
});
|
|
189
|
+
return json({
|
|
190
|
+
action: "written",
|
|
191
|
+
summary: loaded.summary
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}),
|
|
195
|
+
defineTool({
|
|
196
|
+
name: NARRATION_IMPORT_TOOL,
|
|
197
|
+
description: `Turn the SillyTavern preset the person uploaded (${UPLOAD_PATH}) into this preset's prose prompts, in every language the program ships. Rules of the game, formats and scripts in the uploaded preset are not carried. It replaces this preset's versions of those prompts, so the person is asked first unless the preset has none yet.`,
|
|
198
|
+
parameters: { file: {
|
|
199
|
+
type: "string",
|
|
200
|
+
required: true,
|
|
201
|
+
description: `The uploaded preset: ${UPLOAD_PATH}.`
|
|
202
|
+
} },
|
|
203
|
+
output: jsonOutput,
|
|
204
|
+
isConcurrencySafe: () => false,
|
|
205
|
+
async execute(args, exec) {
|
|
206
|
+
if (args.file.trim() !== UPLOAD_PATH) throw new Error(`the uploaded preset is ${UPLOAD_PATH}`);
|
|
207
|
+
const { name, directory } = reader.directory(exec);
|
|
208
|
+
const file = join(directory, IMPORT_FOLDER, PRESET_FILE);
|
|
209
|
+
const uploaded = readPreset$1(await readFile(file).catch(() => {
|
|
210
|
+
throw new Error("no preset was uploaded here");
|
|
211
|
+
}), name);
|
|
212
|
+
const language = prompting.languages().get(`preset:${name}`);
|
|
213
|
+
const text = (id, variables) => prompting.prompts().text(id, language, variables);
|
|
214
|
+
const made = await extractStyleFrom(contextOf(exec, settings(), text), uploaded.name, uploaded.pieces);
|
|
215
|
+
for (const { id, text: body } of made.prompts) for (const tag of shippedLanguages(shipped)) await writeWorldPrompt(directory, tag, id, withPlayer(body), shipped);
|
|
216
|
+
await rm(join(directory, IMPORT_FOLDER), {
|
|
217
|
+
recursive: true,
|
|
218
|
+
force: true
|
|
219
|
+
});
|
|
220
|
+
const written = made.prompts.map((entry) => entry.id);
|
|
221
|
+
return json({
|
|
222
|
+
written,
|
|
223
|
+
notes: made.notes,
|
|
224
|
+
next: written.length === 0 ? "Nothing in the uploaded preset was about how to write the story, so no prompt was written: tell the person." : "Tell the person which prompts were written (they can read and edit them here or in the Presets page) and what was not carried over."
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
];
|
|
229
|
+
}
|
|
230
|
+
/** Every change to a preset is put to the person; the first import into an empty preset only fills it, so it is not. */
|
|
231
|
+
async function presetApproval(exec, next, carries) {
|
|
232
|
+
if (!PRESET_MUTATION_TOOLS.includes(exec.name) || exec.agent === void 0 || presetOfChat(exec.agent.session.id) === void 0) return await next();
|
|
233
|
+
const args = exec.arguments;
|
|
234
|
+
const chat = exec.agent.session.id;
|
|
235
|
+
if (exec.name === "import_narration_preset") {
|
|
236
|
+
if (!carries(chat)) return await next();
|
|
237
|
+
return {
|
|
238
|
+
kind: "ask",
|
|
239
|
+
reason: "replace the preset's prompts with ones made from the uploaded preset",
|
|
240
|
+
displayReason: {
|
|
241
|
+
en: "Replace this preset's prompts with ones made from the uploaded preset?",
|
|
242
|
+
zh: "用上传的预设生成的提示词,替换此预设的提示词?"
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
if (exec.name === "write_preset_info") return {
|
|
247
|
+
kind: "ask",
|
|
248
|
+
reason: "change the preset's title, description or suggested temperatures",
|
|
249
|
+
displayReason: {
|
|
250
|
+
en: "Change the preset's title, description or temperatures?",
|
|
251
|
+
zh: "修改预设的标题、描述或建议温度?"
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
const target = `prompt “${String(args["language"])}/${String(args["id"])}”`;
|
|
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
|
+
};
|
|
264
|
+
return {
|
|
265
|
+
kind: "ask",
|
|
266
|
+
reason: `${remove ? "delete" : "write"} preset ${target}`,
|
|
267
|
+
displayReason: {
|
|
268
|
+
en: `${remove ? "Delete" : "Write"} ${target} in the preset?`,
|
|
269
|
+
zh: `${remove ? "删除" : "写入"}预设中的${target}?`
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
export { presetChatSessionId as a, presetAuthorTools as i, narrationImportMessage as n, presetOfChat as o, presetApproval as r, PresetReader as t };
|
|
275
|
+
|
|
276
|
+
//# sourceMappingURL=preset-author-tools-BxycmoAr.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { c as presetDirectory } from "./presets-gkBWAiVb.js";
|
|
2
|
+
import "./load-CVwJjIJ5.js";
|
|
3
|
+
import { i as presetAuthorTools, o as presetOfChat, r as presetApproval, t as PresetReader } from "./preset-author-tools-BxycmoAr.js";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
//#region src/preset-authoring.ts
|
|
7
|
+
const name = "@dsh-agentic-roleplay/core/preset-authoring";
|
|
8
|
+
const inject = [
|
|
9
|
+
"roleplayRoot",
|
|
10
|
+
"roleplayImport",
|
|
11
|
+
"roleplayPrompts",
|
|
12
|
+
"roleplayAuthoringLanguages",
|
|
13
|
+
"tools",
|
|
14
|
+
"systemPrompt"
|
|
15
|
+
];
|
|
16
|
+
/** The preset authoring chat: reads and writes the prose prompts of one library preset, each write approved by the person. */
|
|
17
|
+
function apply(ctx) {
|
|
18
|
+
const library = () => ctx.roleplayRoot.path;
|
|
19
|
+
const reader = new PresetReader(library);
|
|
20
|
+
const prompting = {
|
|
21
|
+
prompts: () => ctx.roleplayPrompts,
|
|
22
|
+
languages: () => ctx.roleplayAuthoringLanguages
|
|
23
|
+
};
|
|
24
|
+
for (const tool of presetAuthorTools(reader, () => ctx.roleplayImport.settings, prompting)) ctx.tools.register(tool);
|
|
25
|
+
const carries = (chat) => {
|
|
26
|
+
const preset = presetOfChat(chat);
|
|
27
|
+
return preset !== void 0 && existsSync(join(presetDirectory(library(), preset), "prompts"));
|
|
28
|
+
};
|
|
29
|
+
ctx.on("tools/pre-execute", (exec, next) => presetApproval(exec, next, carries));
|
|
30
|
+
const languageOf = (context) => {
|
|
31
|
+
const chat = context.agent?.session.id;
|
|
32
|
+
const preset = chat === void 0 ? void 0 : presetOfChat(chat);
|
|
33
|
+
return preset === void 0 ? "en" : ctx.roleplayAuthoringLanguages.get(`preset:${preset}`);
|
|
34
|
+
};
|
|
35
|
+
for (const [section, order, id] of [[
|
|
36
|
+
"PRESET_AUTHORING_PERSONA",
|
|
37
|
+
ctx.systemPrompt.getSectionOrder("DEPLOYMENT_PERSONA_PREFIX"),
|
|
38
|
+
"preset/persona"
|
|
39
|
+
], [
|
|
40
|
+
"PRESET_AUTHORING_PROCEDURE",
|
|
41
|
+
ctx.systemPrompt.getSectionOrder("DEPLOYMENT_PERSONA_SUFFIX"),
|
|
42
|
+
"preset/procedure"
|
|
43
|
+
]]) ctx.systemPrompt.section({
|
|
44
|
+
name: section,
|
|
45
|
+
order,
|
|
46
|
+
interpolate: false,
|
|
47
|
+
text: (context) => ctx.roleplayPrompts.text(id, languageOf(context))
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { apply, inject, name };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=preset-authoring.js.map
|