@dsh-agentic-roleplay/core 0.3.5 → 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 -5
- package/lib/client.js +1735 -459
- package/lib/client.js.map +1 -1
- package/lib/{deliver-Cl6bjp7g.js → deliver-BBgciEEK.js} +2 -2
- package/lib/doctor.js +3 -3
- package/lib/{hooks-DdO_tNhu.js → hooks-DkwFGtNH.js} +3 -3
- package/lib/index.js +394 -28
- package/lib/{load-Clkl0T7C.js → load-CVwJjIJ5.js} +7 -7
- package/lib/lorebook-author-tools-Bj31z1cu.js +619 -0
- package/lib/lorebook-authoring.js +67 -0
- package/lib/orchestration.js +6 -6
- package/lib/{pack-jail-ClMpVc__.js → pack-jail-2XztyYAX.js} +6 -5
- package/lib/{packs-BC2A3geF.js → packs-xHRCcGdb.js} +2 -2
- package/lib/preset-D0FMSeZ9.js +59 -0
- package/lib/{preset-author-tools-Dibp-LY9.js → preset-author-tools-BxycmoAr.js} +22 -16
- package/lib/preset-authoring.js +3 -3
- package/lib/{presets-DNjNxQL5.js → presets-gkBWAiVb.js} +44 -5
- package/lib/{reflection-Bju_LPFn.js → reflection-q0UpwXlx.js} +5 -5
- package/lib/{preset-ClQm7KPQ.js → tools-Dy1fgP6B.js} +424 -247
- package/package.json +3 -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 -1
- package/prompts/en/preset/procedure.md +1 -1
- 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 -1
- package/prompts/zh/preset/procedure.md +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { vt as lorebookDirectory } from "./tools-Dy1fgP6B.js";
|
|
2
|
+
import "./load-CVwJjIJ5.js";
|
|
3
|
+
import { i as lorebookAuthorTools, l as lorebookOfChat, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-Bj31z1cu.js";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
6
|
+
//#region src/lorebook-authoring.ts
|
|
7
|
+
const name = "@dsh-agentic-roleplay/core/lorebook-authoring";
|
|
8
|
+
const inject = [
|
|
9
|
+
"roleplayRoot",
|
|
10
|
+
"roleplayImport",
|
|
11
|
+
"roleplayPrompts",
|
|
12
|
+
"roleplayAuthoringLanguages",
|
|
13
|
+
"tools",
|
|
14
|
+
"systemPrompt"
|
|
15
|
+
];
|
|
16
|
+
/** The lorebook authoring chat: reads and writes the entries of one library lorebook, each write approved by the person. */
|
|
17
|
+
function apply(ctx) {
|
|
18
|
+
const library = () => ctx.roleplayRoot.path;
|
|
19
|
+
const reader = new LorebookReader(library);
|
|
20
|
+
const prompting = {
|
|
21
|
+
prompts: () => ctx.roleplayPrompts,
|
|
22
|
+
languages: () => ctx.roleplayAuthoringLanguages
|
|
23
|
+
};
|
|
24
|
+
for (const tool of lorebookAuthorTools(reader, () => ctx.roleplayImport.settings, prompting)) ctx.tools.register(tool);
|
|
25
|
+
const directoryOf = (chat) => {
|
|
26
|
+
const book = lorebookOfChat(chat);
|
|
27
|
+
return book === void 0 ? void 0 : lorebookDirectory(library(), book);
|
|
28
|
+
};
|
|
29
|
+
const carries = (chat) => {
|
|
30
|
+
const directory = directoryOf(chat);
|
|
31
|
+
return directory !== void 0 && existsSync(join(directory, "lore")) && readdirSync(join(directory, "lore")).length > 0;
|
|
32
|
+
};
|
|
33
|
+
const waiting = (chat) => {
|
|
34
|
+
const directory = directoryOf(chat);
|
|
35
|
+
return directory === void 0 ? {
|
|
36
|
+
ids: [],
|
|
37
|
+
rules: false
|
|
38
|
+
} : pendingTargets(directory);
|
|
39
|
+
};
|
|
40
|
+
ctx.on("tools/pre-execute", (exec, next) => lorebookApproval(exec, next, {
|
|
41
|
+
carries,
|
|
42
|
+
waiting
|
|
43
|
+
}));
|
|
44
|
+
const languageOf = (context) => {
|
|
45
|
+
const chat = context.agent?.session.id;
|
|
46
|
+
const book = chat === void 0 ? void 0 : lorebookOfChat(chat);
|
|
47
|
+
return book === void 0 ? "en" : ctx.roleplayAuthoringLanguages.get(`lorebook:${book}`);
|
|
48
|
+
};
|
|
49
|
+
for (const [section, order, id] of [[
|
|
50
|
+
"LOREBOOK_AUTHORING_PERSONA",
|
|
51
|
+
ctx.systemPrompt.getSectionOrder("DEPLOYMENT_PERSONA_PREFIX"),
|
|
52
|
+
"lorebook/persona"
|
|
53
|
+
], [
|
|
54
|
+
"LOREBOOK_AUTHORING_PROCEDURE",
|
|
55
|
+
ctx.systemPrompt.getSectionOrder("DEPLOYMENT_PERSONA_SUFFIX"),
|
|
56
|
+
"lorebook/procedure"
|
|
57
|
+
]]) ctx.systemPrompt.section({
|
|
58
|
+
name: section,
|
|
59
|
+
order,
|
|
60
|
+
interpolate: false,
|
|
61
|
+
text: (context) => ctx.roleplayPrompts.text(id, languageOf(context))
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { apply, inject, name };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=lorebook-authoring.js.map
|
package/lib/orchestration.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { n as chatSessionId, r as roleplaySessionOf, t as promptFor } from "./access-EbNdZFbk.js";
|
|
2
|
-
import {
|
|
3
|
-
import { a as whereabouts, g as referent, h as sameWords, n as memoryReflector, r as recordFailure, s as Timelines, t as dueReflection } from "./reflection-
|
|
2
|
+
import { b as INTENT_STATUSES } from "./presets-gkBWAiVb.js";
|
|
3
|
+
import { a as whereabouts, g as referent, h as sameWords, n as memoryReflector, r as recordFailure, s as Timelines, t as dueReflection } from "./reflection-q0UpwXlx.js";
|
|
4
4
|
import "./settings-CA6icLL_.js";
|
|
5
|
-
import { C as ReflectionRefusedError } from "./load-
|
|
6
|
-
import { B as RESULTS, F as describeWhen, H as languageOf, M as ClockError, S as MAX_OOC_ANSWER, U as translator, m as createTools$1, p as PREVIEW_TOOL, u as externalGiven, w as toolEnabled, x as AUTHORING_NEEDS, z as zoneOf } from "./deliver-
|
|
5
|
+
import { C as ReflectionRefusedError } from "./load-CVwJjIJ5.js";
|
|
6
|
+
import { B as RESULTS, F as describeWhen, H as languageOf, M as ClockError, S as MAX_OOC_ANSWER, U as translator, m as createTools$1, p as PREVIEW_TOOL, u as externalGiven, w as toolEnabled, x as AUTHORING_NEEDS, z as zoneOf } from "./deliver-BBgciEEK.js";
|
|
7
7
|
import { a as liveSettings } from "./narration-DK2kiIjE.js";
|
|
8
8
|
import { a as runChild, d as tokensOf, i as childTrace, l as currentTurn, n as childSampling, t as childModel, u as estimateAnswer } from "./child-CFjnaTZt.js";
|
|
9
9
|
import { b as slug, t as addToLibrary, x as uniqueKey } from "./library-9JB9zw5a.js";
|
|
10
10
|
import { a as wrongLanguage } from "./language-BgyxtB2h.js";
|
|
11
|
-
import { _ as API_PREFIX } from "./packs-
|
|
11
|
+
import { _ as API_PREFIX } from "./packs-xHRCcGdb.js";
|
|
12
12
|
import { i as updateImage, r as listGallery, t as describeGalleryImage } from "./gallery-DIEgETzU.js";
|
|
13
|
-
import { a as writeVerdicts, i as readVerdicts, n as installHooks, r as storesOf } from "./hooks-
|
|
13
|
+
import { a as writeVerdicts, i as readVerdicts, n as installHooks, r as storesOf } from "./hooks-DkwFGtNH.js";
|
|
14
14
|
import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-DnNEG_Mn.js";
|
|
15
15
|
import { join } from "node:path";
|
|
16
16
|
import { existsSync } from "node:fs";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import {
|
|
3
|
-
import { S as InvalidWorldError, _ as shippedLanguages,
|
|
1
|
+
import { $ as parseItemFile, B as CHARACTERS_DIR, Ct as LORE_DIR, D as loadTriggers, Dt as subfolders, E as TRIGGERS_FILE_NAME, Et as parseLoreFile, F as loadLocations, G as withPlayer, H as extractStyleFrom, I as ITEMS_DIR, L as loadItems, M as loadCalendar, Ot as InvalidEditProblems, P as LOCATIONS_DIR, Q as ITEM_FILE_NAME, R as FACTIONS_DIR, Tt as LORE_FILE_NAME, V as loadCharacters, X as LOCATION_FILE_NAME, Z as parseLocationFile, a as authoredWorldOf, b as populateLocations, d as loadValidatedWorld, et as FACTION_FILE_NAME, i as worldOf, it as IMPORT_FOLDER, m as populateCharacters, nt as CHARACTER_FILE_NAME, q as loadVariables, rt as parseCharacterFile, t as contextOf, tt as parseFactionFile, v as populateItems, w as populateVariables, wt as loadLore, z as loadFactions } from "./tools-Dy1fgP6B.js";
|
|
2
|
+
import { v as writeWorldPrompt } from "./presets-gkBWAiVb.js";
|
|
3
|
+
import { S as InvalidWorldError, _ as shippedLanguages, i as plotReferenceProblems, n as loadPlots, r as parsePlotsFile, s as formatIssue, t as PLOTS_FILE_NAME, u as PROMPTS_FOLDER } from "./load-CVwJjIJ5.js";
|
|
4
4
|
import { c as referenceImagePath, v as mapLimit } from "./library-9JB9zw5a.js";
|
|
5
5
|
import { i as textLanguage, n as STORY_LANGUAGES, r as isStoryLanguage, t as LANGUAGE_NAMES } from "./language-BgyxtB2h.js";
|
|
6
|
-
import {
|
|
6
|
+
import { t as readPreset } from "./preset-D0FMSeZ9.js";
|
|
7
|
+
import { _ as API_PREFIX, a as packIds, d as packPath, f as readPack, h as PACK_MEDIA_TYPES, l as isPackId } from "./packs-xHRCcGdb.js";
|
|
7
8
|
import { a as uploadReferenceImage, t as generateReferenceImage } from "./generator-DJ48HxPI.js";
|
|
8
9
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
9
10
|
import { existsSync, lstatSync, statSync } from "node:fs";
|
|
@@ -1976,4 +1977,4 @@ function registerPackJail(ctx, deps) {
|
|
|
1976
1977
|
//#endregion
|
|
1977
1978
|
export { worldEntityImageFile as A, translateTools as B, readWorldEditor as C, uploadWorldCharacterPortrait as D, replaceFile$1 as E, loadWorldParts as F, readWorldDocuments as H, PRESET_FILE as I, presetMessage as L, deleteTriggerDocument as M, readTriggerDocuments as N, uploadWorldEntityImage as O, writeTriggerDocument as P, presetTools as R, generateWorldEntityImage as S, removeWorldTrigger as T, languageOfDocuments as V, editWorldPlots as _, deleteWorldPackFile as a, entityFolder as b, createAuthoredEntity as c, replaceAuthoredEntity as d, editWorldCharacter as f, editWorldPlace as g, editWorldNarrationVoice as h, checkWorldPack as i, writeWorldTrigger as j, worldCharacterPortraitFile as k, deleteAuthoredEntity as l, editWorldLore as m, packFileProblem as n, listWorldPacks as o, editWorldFaction as p, registerPackJail as r, AUTHORED_ENTITY_KINDS as s, MAX_PACK_TEXT as t, readAuthoredEntityDocument as u, editWorldRelation as v, readWorldTrigger as w, generateWorldCharacterPortrait as x, editWorldThing as y, translateMessage as z };
|
|
1978
1979
|
|
|
1979
|
-
//# sourceMappingURL=pack-jail-
|
|
1980
|
+
//# sourceMappingURL=pack-jail-2XztyYAX.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
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";
|
|
@@ -837,4 +837,4 @@ function anyTab(bases) {
|
|
|
837
837
|
//#endregion
|
|
838
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 };
|
|
839
839
|
|
|
840
|
-
//# sourceMappingURL=packs-
|
|
840
|
+
//# sourceMappingURL=packs-xHRCcGdb.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
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { G as
|
|
2
|
-
import { _ as
|
|
3
|
-
import { _ as shippedLanguages, m as languageOf,
|
|
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";
|
|
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",
|
|
@@ -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-BxycmoAr.js.map
|
package/lib/preset-authoring.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./load-
|
|
3
|
-
import { i as presetAuthorTools, o as presetOfChat, r as presetApproval, t as PresetReader } from "./preset-author-tools-
|
|
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
4
|
import { join } from "node:path";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
//#region src/preset-authoring.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as shippedLanguages, g as promptProblem, h as listFiles, l as LANGUAGE_FOLDER, m as languageOf, u as PROMPTS_FOLDER, v as shippedPromptsDirectory } from "./load-
|
|
1
|
+
import { _ as shippedLanguages, g as promptProblem, h as listFiles, l as LANGUAGE_FOLDER, m as languageOf, u as PROMPTS_FOLDER, v as shippedPromptsDirectory } from "./load-CVwJjIJ5.js";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
@@ -175,20 +175,22 @@ function readPreset(directory, name, shipped = shippedPromptsDirectory()) {
|
|
|
175
175
|
for (const id of listFiles(join(base, entry.name))) {
|
|
176
176
|
const path = `${entry.name}/${id}.md`;
|
|
177
177
|
const text = readFileSync(join(base, path), "utf8");
|
|
178
|
-
const problem =
|
|
178
|
+
const problem = id.startsWith("roleplay/") ? promptProblem(entry.name, id, text, shipped) : `"${id}" is not a prompt of the story`;
|
|
179
179
|
if (problem !== void 0) problems.push(`prompts/${path}: ${problem}`);
|
|
180
180
|
else files.set(path, text);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
if (files.size === 0 && problems.length === 0) problems.push("the preset carries no prompts");
|
|
184
184
|
const paths = [...files.keys()];
|
|
185
|
+
const ids = [...new Set(paths.map((path) => path.slice(path.indexOf("/") + 1, -3)))].sort();
|
|
185
186
|
return {
|
|
186
187
|
summary: {
|
|
187
188
|
name,
|
|
188
189
|
title: header.title ?? name,
|
|
189
190
|
description: header.description ?? "",
|
|
190
191
|
languages: [...new Set(paths.map((path) => path.split("/")[0]))].sort(),
|
|
191
|
-
prompts:
|
|
192
|
+
prompts: ids,
|
|
193
|
+
rules: ids.filter((id) => !PROSE_PROMPTS.includes(id)),
|
|
192
194
|
sampling: header.sampling,
|
|
193
195
|
problems
|
|
194
196
|
},
|
|
@@ -329,7 +331,44 @@ async function reservePreset(root, name, title) {
|
|
|
329
331
|
await writeHeader(target, headerFile(title.trim().slice(0, MAX_TEXT) || void 0, void 0, {}));
|
|
330
332
|
return target;
|
|
331
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* 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
|
|
336
|
+
* the prompt keeps naming the tools and values it needs. The guidance is the importer's, in the language it was written in.
|
|
337
|
+
* @throws {Error} when the name is taken, there is no guidance, or a prompt would not be acceptable; nothing is made then.
|
|
338
|
+
*/
|
|
339
|
+
async function createPresetFromGuidance(root, request, guidance, shipped = shippedPromptsDirectory()) {
|
|
340
|
+
const target = presetDirectory(root, request.name);
|
|
341
|
+
if (existsSync(target)) throw new Error(`there is already a preset "${request.name}"`);
|
|
342
|
+
const ids = Object.keys(guidance).filter((id) => (guidance[id]?.length ?? 0) > 0);
|
|
343
|
+
if (ids.length === 0) throw new Error("there is no guidance to make a preset of");
|
|
344
|
+
const problems = [];
|
|
345
|
+
const header = parseHeader({
|
|
346
|
+
title: request.title?.trim(),
|
|
347
|
+
description: request.description?.trim()
|
|
348
|
+
}, problems);
|
|
349
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
350
|
+
const staging = join(root, ".install", `preset-${request.name}-${Date.now()}`);
|
|
351
|
+
try {
|
|
352
|
+
for (const language of shippedLanguages(shipped)) for (const id of ids) {
|
|
353
|
+
const base = readWorldPrompt(join(staging, "none"), language, id, shipped).text.trimEnd();
|
|
354
|
+
const to = join(staging, PROMPTS_FOLDER, language, `${id}.md`);
|
|
355
|
+
await mkdir(dirname(to), { recursive: true });
|
|
356
|
+
await writeFile(to, `${base}\n\n${(guidance[id] ?? []).join("\n")}\n`);
|
|
357
|
+
}
|
|
358
|
+
await writeHeader(staging, headerFile(header.title, header.description, {}));
|
|
359
|
+
const loaded = readPreset(staging, request.name);
|
|
360
|
+
if (loaded.summary.problems.length > 0) throw new Error(`the preset would have problems: ${loaded.summary.problems.join("; ")}`);
|
|
361
|
+
await mkdir(presetsDirectory(root), { recursive: true });
|
|
362
|
+
await rename(staging, target);
|
|
363
|
+
return readPreset(target, request.name);
|
|
364
|
+
} finally {
|
|
365
|
+
await rm(staging, {
|
|
366
|
+
recursive: true,
|
|
367
|
+
force: true
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
332
371
|
//#endregion
|
|
333
|
-
export {
|
|
372
|
+
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
373
|
|
|
335
|
-
//# sourceMappingURL=presets-
|
|
374
|
+
//# sourceMappingURL=presets-gkBWAiVb.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { r as roleplaySessionOf, t as promptFor } from "./access-EbNdZFbk.js";
|
|
2
|
-
import {
|
|
2
|
+
import { f as sha, o as listPresets, s as loadPreset } from "./presets-gkBWAiVb.js";
|
|
3
3
|
import "./settings-CA6icLL_.js";
|
|
4
|
-
import { p as inheritPrompts, u as PROMPTS_FOLDER } from "./load-
|
|
5
|
-
import { F as describeWhen, H as languageOf, P as describeTime, U as translator, V as answerLimits } from "./deliver-
|
|
4
|
+
import { p as inheritPrompts, u as PROMPTS_FOLDER } from "./load-CVwJjIJ5.js";
|
|
5
|
+
import { F as describeWhen, H as languageOf, P as describeTime, U as translator, V as answerLimits } from "./deliver-BBgciEEK.js";
|
|
6
6
|
import { a as runChild, i as childTrace, n as childSampling, t as childModel, u as estimateAnswer } from "./child-CFjnaTZt.js";
|
|
7
7
|
import { a as inheritImages } from "./library-9JB9zw5a.js";
|
|
8
8
|
import { a as wrongLanguage } from "./language-BgyxtB2h.js";
|
|
9
|
-
import { i as inheritPacks } from "./packs-
|
|
9
|
+
import { i as inheritPacks } from "./packs-xHRCcGdb.js";
|
|
10
10
|
import { dirname, join } from "node:path";
|
|
11
11
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
12
12
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
@@ -1962,4 +1962,4 @@ function memoryReflector(deps) {
|
|
|
1962
1962
|
//#endregion
|
|
1963
1963
|
export { whereabouts as a, copyPreset as c, switchPreset as d, readTimeline as f, referent as g, sameWords as h, reflectionStatus as i, presetStatus as l, defaultBoundaries as m, memoryReflector as n, TimelineError as o, pathTo as p, recordFailure as r, Timelines as s, dueReflection as t, recordPreset as u };
|
|
1964
1964
|
|
|
1965
|
-
//# sourceMappingURL=reflection-
|
|
1965
|
+
//# sourceMappingURL=reflection-q0UpwXlx.js.map
|