@dsh-agentic-roleplay/core 0.3.6 → 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/{tools-Dy1fgP6B.js → authoring-tools-C_8ClUkP.js} +129 -25
- package/lib/authoring.js +7 -5
- package/lib/{child-CFjnaTZt.js → child-DsixtqTw.js} +94 -2
- package/lib/client.js +3714 -2264
- 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-BBgciEEK.js → hooks-B2EhBS_-.js} +1884 -236
- package/lib/images.js +4 -4
- package/lib/index.js +846 -254
- package/lib/{library-9JB9zw5a.js → library-COIktKBa.js} +4 -3
- package/lib/{lorebook-author-tools-Bj31z1cu.js → lorebook-author-tools-C-o0t4dL.js} +118 -43
- package/lib/lorebook-authoring.js +5 -3
- package/lib/{settings-CA6icLL_.js → narration-BT9uvQry.js} +145 -2
- package/lib/orchestration.js +34 -21
- package/lib/{pack-jail-2XztyYAX.js → pack-jail-soI-In96.js} +170 -13
- package/lib/{packs-xHRCcGdb.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-BxycmoAr.js → preset-author-tools-C-X8G40s.js} +7 -7
- package/lib/preset-authoring.js +6 -3
- package/lib/{presets-gkBWAiVb.js → presets-C3mhqqfz.js} +9 -26
- package/lib/{reflection-q0UpwXlx.js → reflection-Btsj0ZLh.js} +51 -17
- package/package.json +2 -2
- package/packs/scene/map.html +1 -0
- package/packs/scene/strip.html +1 -0
- package/prompts/en/import/lorebook.md +2 -1
- package/prompts/en/import/style.md +1 -0
- package/prompts/en/lorebook/procedure.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 +2 -1
- package/prompts/zh/import/style.md +1 -0
- package/prompts/zh/lorebook/procedure.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-DkwFGtNH.js +0 -1060
- package/lib/language-BgyxtB2h.js +0 -38
- package/lib/load-CVwJjIJ5.js +0 -486
- package/lib/narration-DK2kiIjE.js +0 -141
- package/lib/preset-D0FMSeZ9.js +0 -59
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { g as withoutExtension, h as trimCharacters } from "./child-DsixtqTw.js";
|
|
1
2
|
import { dirname, extname, join } from "node:path";
|
|
2
3
|
import { existsSync } from "node:fs";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
@@ -24,7 +25,7 @@ function norm(name) {
|
|
|
24
25
|
/** A file-safe key from a name: the letters and digits of any script joined by hyphens; `fallback` when nothing is left. */
|
|
25
26
|
/** An id made of the letters and digits of a name, in whatever script it is written; a name with none gets the fallback. */
|
|
26
27
|
function slug(name, fallback) {
|
|
27
|
-
const key = name.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-")
|
|
28
|
+
const key = trimCharacters(trimCharacters(name.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-"), "-").slice(0, 60), "-", "end");
|
|
28
29
|
return key === "" ? fallback : key;
|
|
29
30
|
}
|
|
30
31
|
/** `base`, or `base-2`, `base-3` … the first that `taken` does not hold; the key is added to it. */
|
|
@@ -294,7 +295,7 @@ function imageExtensionOf(bytes) {
|
|
|
294
295
|
}
|
|
295
296
|
/** A file name made of the letters and digits of the name it came with, in any script. */
|
|
296
297
|
function libraryName(original, extension, taken) {
|
|
297
|
-
const stem = original
|
|
298
|
+
const stem = trimCharacters(withoutExtension(original).normalize("NFKC").replace(/[^\p{L}\p{N}]+/gu, "-"), "-").slice(0, 60) || "image";
|
|
298
299
|
for (let n = 1;; n += 1) {
|
|
299
300
|
const name = `${stem}${n === 1 ? "" : `-${n}`}${extension}`;
|
|
300
301
|
if (!taken(name)) return name;
|
|
@@ -331,4 +332,4 @@ async function addToLibrary(sessionFolder, bytes, originalName) {
|
|
|
331
332
|
//#endregion
|
|
332
333
|
export { withPngMetadata as _, inheritImages as a, slug as b, referenceImagePath as c, MEDIA_TYPES as d, mediaTypeOf as f, readPngMetadata as g, writeImageFileMetadata as h, entityImageDirectory as i, sceneImagePath as l, sidecarOf as m, imageExtensionOf as n, nextSceneSerial as o, readImageFileMetadata as p, LIBRARY_FOLDER as r, readImageMetadata as s, addToLibrary as t, writeImage as u, mapLimit as v, uniqueKey as x, norm as y };
|
|
333
334
|
|
|
334
|
-
//# sourceMappingURL=library-
|
|
335
|
+
//# sourceMappingURL=library-COIktKBa.js.map
|
|
@@ -1,82 +1,126 @@
|
|
|
1
|
-
import { Bt as
|
|
2
|
-
import { n as createPresetFromGuidance } from "./presets-
|
|
3
|
-
import "./
|
|
4
|
-
import {
|
|
5
|
-
import { b as slug, v as mapLimit, x as uniqueKey } from "./library-
|
|
1
|
+
import { Bt as ImportCardError, Ct as readLorebook$1, Et as writeLorebookEntry, Gt as LORE_SCOPES, J as withPlayer, K as cleanText, St as lorebookDirectory, Tt as updateLorebookInfo, Wt as LORE_KINDS, _t as deleteLorebookEntry, i as contextOf, q as partsOf, r as MAX_PREVIEW_TEXT, st as IMPORT_FOLDER, vt as entriesOf, xt as loadLorebook } from "./authoring-tools-C_8ClUkP.js";
|
|
2
|
+
import { n as createPresetFromGuidance } from "./presets-C3mhqqfz.js";
|
|
3
|
+
import "./narration-BT9uvQry.js";
|
|
4
|
+
import { $ as shippedPromptsDirectory } from "./hooks-B2EhBS_-.js";
|
|
5
|
+
import { b as slug, v as mapLimit, x as uniqueKey } from "./library-COIktKBa.js";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { existsSync, readFileSync } from "node:fs";
|
|
8
8
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
9
9
|
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
10
|
-
//#region src/shared/lorebook-chat.ts
|
|
11
|
-
const PREFIX = "lorebook-author-";
|
|
12
|
-
/** Stable DSH chat identity for the authoring conversation of one library lorebook. */
|
|
13
|
-
function lorebookChatSessionId(name) {
|
|
14
|
-
if (name === "") throw new TypeError("lorebook name cannot be empty");
|
|
15
|
-
return `${PREFIX}${encodeURIComponent(name)}`;
|
|
16
|
-
}
|
|
17
|
-
/** The library lorebook named by a dedicated lorebook authoring chat. */
|
|
18
|
-
function lorebookOfChat(chatSessionId) {
|
|
19
|
-
if (!chatSessionId.startsWith(PREFIX)) return void 0;
|
|
20
|
-
try {
|
|
21
|
-
const name = decodeURIComponent(chatSessionId.slice(16));
|
|
22
|
-
return name === "" ? void 0 : name;
|
|
23
|
-
} catch {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
10
|
//#region src/host/import/lorebook.ts
|
|
29
11
|
const MAX_ENTRIES = 500;
|
|
30
12
|
const BATCH_CHARS = 6e3;
|
|
31
13
|
const BATCH_ENTRIES = 8;
|
|
14
|
+
/** Instructions are short; an entry longer than this that was called one is most likely a fact the model would otherwise throw away. */
|
|
15
|
+
const MAX_STEERING_SOURCE_CHARS = 2e3;
|
|
16
|
+
/** Guidance that keeps less than this share of its entry's length has not kept what the entry asks for. */
|
|
17
|
+
const MIN_STEERING_SHARE = .15;
|
|
32
18
|
/** The stand-in for the character a card's lorebook speaks of: a lorebook on its own belongs to no character. */
|
|
33
19
|
const CHARACTER_WORD = "the character";
|
|
34
20
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35
21
|
const text = (value) => typeof value === "string" ? value.trim() : "";
|
|
36
22
|
const strings = (value) => Array.isArray(value) ? value.flatMap((entry) => typeof entry === "string" && entry.trim() !== "" ? [entry.trim()] : []) : typeof value === "string" && value.trim() !== "" ? value.split(",").map((entry) => entry.trim()).filter((entry) => entry !== "") : [];
|
|
37
|
-
/** The book of a file: a lorebook export (`entries`), a card (`data.character_book` or `character_book`), or a bare book. */
|
|
23
|
+
/** The book of a file: a lorebook export (`entries`), a wrapped one (`data.entries`, as catalogues serve it), a card (`data.character_book` or `character_book`), or a bare book. */
|
|
38
24
|
function bookOf(root) {
|
|
39
25
|
if (isObject(root["entries"]) || Array.isArray(root["entries"])) return root;
|
|
40
|
-
const
|
|
26
|
+
const data = isObject(root["data"]) ? root["data"] : void 0;
|
|
27
|
+
if (data !== void 0 && (isObject(data["entries"]) || Array.isArray(data["entries"]))) return data;
|
|
28
|
+
const embedded = data?.["character_book"] ?? root["character_book"];
|
|
41
29
|
return isObject(embedded) ? embedded : void 0;
|
|
42
30
|
}
|
|
43
|
-
|
|
44
|
-
* Reads a lorebook file. Entries that are switched off or empty are left out; macros of the tool that wrote them are replaced.
|
|
45
|
-
* @throws {ImportCardError} when the file is not a lorebook, with why.
|
|
46
|
-
*/
|
|
47
|
-
function readLorebook(file, fileName) {
|
|
31
|
+
function parseRoot(file) {
|
|
48
32
|
let root;
|
|
49
33
|
try {
|
|
50
|
-
root = JSON.parse(file.toString("utf8").replace(
|
|
34
|
+
root = JSON.parse(file.toString("utf8").replace(/^\uFEFF/, ""));
|
|
51
35
|
} catch {
|
|
52
36
|
throw new ImportCardError("the file is not JSON: a lorebook is the .json file SillyTavern exports");
|
|
53
37
|
}
|
|
54
38
|
if (!isObject(root)) throw new ImportCardError("the file is not a lorebook: it must be a JSON object");
|
|
39
|
+
return root;
|
|
40
|
+
}
|
|
41
|
+
/** The entries of the file's book as it holds them, in file order. @throws {ImportCardError} when the file holds no book. */
|
|
42
|
+
function rawEntries(root) {
|
|
55
43
|
const book = bookOf(root);
|
|
56
44
|
if (book === void 0) throw new ImportCardError("the file holds no lorebook: it needs an \"entries\" list (or a card with a character book)");
|
|
57
|
-
|
|
45
|
+
return {
|
|
46
|
+
book,
|
|
47
|
+
entries: (Array.isArray(book["entries"]) ? book["entries"] : isObject(book["entries"]) ? Object.values(book["entries"]) : []).filter(isObject)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const switchedOff = (entry) => entry["disable"] === true || entry["enabled"] === false;
|
|
51
|
+
const entryKeys = (entry) => [...strings(entry["keys"]), ...strings(entry["key"])];
|
|
52
|
+
const nameOf = (book, root, fileName) => text(book["name"]) || text(root["name"]) || fileName.replace(/\.json$/i, "");
|
|
53
|
+
/**
|
|
54
|
+
* Reads a lorebook file. Entries that are switched off or empty are left out; macros of the tool that wrote them are replaced.
|
|
55
|
+
* @throws {ImportCardError} when the file is not a lorebook, with why.
|
|
56
|
+
*/
|
|
57
|
+
function readLorebook(file, fileName) {
|
|
58
|
+
const root = parseRoot(file);
|
|
59
|
+
const { book, entries: raw } = rawEntries(root);
|
|
58
60
|
const entries = [];
|
|
59
61
|
for (const entry of raw) {
|
|
60
|
-
if (
|
|
61
|
-
if (entry["disable"] === true || entry["enabled"] === false) continue;
|
|
62
|
+
if (switchedOff(entry)) continue;
|
|
62
63
|
const content = cleanText(text(entry["content"]), CHARACTER_WORD);
|
|
63
64
|
if (content === "") continue;
|
|
64
|
-
const keys = [...strings(entry["keys"]), ...strings(entry["key"])];
|
|
65
65
|
entries.push({
|
|
66
66
|
ref: entries.length,
|
|
67
67
|
title: text(entry["comment"]) || text(entry["name"]),
|
|
68
|
-
keys,
|
|
68
|
+
keys: entryKeys(entry),
|
|
69
69
|
text: content
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
if (entries.length === 0) throw new ImportCardError("the lorebook has no entries that are switched on and hold text");
|
|
73
73
|
if (entries.length > MAX_ENTRIES) throw new ImportCardError(`the lorebook has ${entries.length} entries; this importer takes at most ${MAX_ENTRIES}`);
|
|
74
|
-
const title = text(book["name"]) || text(root["name"]);
|
|
75
74
|
return {
|
|
76
|
-
name:
|
|
75
|
+
name: nameOf(book, root, fileName),
|
|
77
76
|
entries
|
|
78
77
|
};
|
|
79
78
|
}
|
|
79
|
+
/** What a lorebook file offers, for the person to choose from: every entry with text, the ones the file has switched off included. @throws {ImportCardError} when the file is not a lorebook. */
|
|
80
|
+
function previewLorebook(file, fileName) {
|
|
81
|
+
const root = parseRoot(file);
|
|
82
|
+
const { book, entries } = rawEntries(root);
|
|
83
|
+
const items = entries.flatMap((entry, index) => {
|
|
84
|
+
const content = cleanText(text(entry["content"]), CHARACTER_WORD);
|
|
85
|
+
if (content === "") return [];
|
|
86
|
+
const keys = entryKeys(entry);
|
|
87
|
+
return [{
|
|
88
|
+
id: String(index),
|
|
89
|
+
title: text(entry["comment"]) || text(entry["name"]) || `#${index + 1}`,
|
|
90
|
+
detail: keys.join(", "),
|
|
91
|
+
text: content.slice(0, MAX_PREVIEW_TEXT),
|
|
92
|
+
chars: content.length,
|
|
93
|
+
enabled: !switchedOff(entry),
|
|
94
|
+
usable: true,
|
|
95
|
+
...entry["constant"] === true ? { note: "always" } : {}
|
|
96
|
+
}];
|
|
97
|
+
});
|
|
98
|
+
if (items.length === 0) throw new ImportCardError("the lorebook has no entries that hold text");
|
|
99
|
+
return {
|
|
100
|
+
name: nameOf(book, root, fileName),
|
|
101
|
+
items
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The file with only the chosen entries in it, all switched on, as if the book never had the others.
|
|
106
|
+
* @throws {ImportCardError} when a chosen entry is not in the file or nothing is chosen.
|
|
107
|
+
*/
|
|
108
|
+
function selectEntries(file, enabled, fileName) {
|
|
109
|
+
const root = parseRoot(file);
|
|
110
|
+
const { book, entries } = rawEntries(root);
|
|
111
|
+
const unknown = enabled.filter((id) => !/^\d+$/.test(id) || Number(id) >= entries.length);
|
|
112
|
+
if (unknown.length > 0) throw new ImportCardError(`the lorebook has no entry ${unknown.map((id) => `"${id}"`).join(", ")}`);
|
|
113
|
+
const chosen = [...new Set(enabled.map(Number))].sort((a, b) => a - b).map((index) => ({
|
|
114
|
+
...entries[index],
|
|
115
|
+
disable: false,
|
|
116
|
+
enabled: true
|
|
117
|
+
}));
|
|
118
|
+
if (chosen.length === 0) throw new ImportCardError("choose at least one entry of the lorebook");
|
|
119
|
+
return Buffer.from(JSON.stringify({
|
|
120
|
+
name: nameOf(book, root, fileName),
|
|
121
|
+
entries: chosen
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
80
124
|
/** Where a piece of steering text goes: the prose prompts, and the prompts that tell the models how to run the game. */
|
|
81
125
|
const STEERING_TARGETS = {
|
|
82
126
|
style: "roleplay/style",
|
|
@@ -122,6 +166,10 @@ const DECISIONS_SCHEMA = {
|
|
|
122
166
|
type: "string",
|
|
123
167
|
description: "For knowledge: one sentence saying what the entry tells. Empty otherwise."
|
|
124
168
|
},
|
|
169
|
+
has_secrets: {
|
|
170
|
+
type: "boolean",
|
|
171
|
+
description: "For knowledge: true when the entry holds anything that not everyone in the world may know: a hidden identity, a secret, a hidden motive, private thoughts, or anything marked hidden or private. Such an entry is never told to everyone. False otherwise."
|
|
172
|
+
},
|
|
125
173
|
scope: {
|
|
126
174
|
type: "string",
|
|
127
175
|
enum: [...LORE_SCOPES],
|
|
@@ -148,6 +196,7 @@ const DECISIONS_SCHEMA = {
|
|
|
148
196
|
"title",
|
|
149
197
|
"kind",
|
|
150
198
|
"summary",
|
|
199
|
+
"has_secrets",
|
|
151
200
|
"scope",
|
|
152
201
|
"known_by",
|
|
153
202
|
"target",
|
|
@@ -185,8 +234,11 @@ function problemOf(answer, batch) {
|
|
|
185
234
|
if (seen.has(decision.ref)) return `entry ${decision.ref} is decided twice`;
|
|
186
235
|
seen.add(decision.ref);
|
|
187
236
|
if (decision.role === "knowledge" && text(decision.title) === "" && batch.find((entry) => entry.ref === decision.ref)?.title === "") return `entry ${decision.ref} is knowledge and has no title: give it one`;
|
|
188
|
-
if (decision.role === "knowledge" && decision.scope === "listed" && strings(decision.known_by).length === 0) return `entry ${decision.ref} is listed but names nobody who knows it: use everyone, or name them`;
|
|
237
|
+
if (decision.role === "knowledge" && decision.scope === "listed" && decision.has_secrets !== true && strings(decision.known_by).length === 0) return `entry ${decision.ref} is listed but names nobody who knows it: use everyone, or name them`;
|
|
189
238
|
if (decision.role === "steering" && (!isSteeringTarget(text(decision.target)) || text(decision.guidance) === "")) return `entry ${decision.ref} is steering: say where it belongs (${Object.keys(STEERING_TARGETS).join(", ")}) and give the guidance`;
|
|
239
|
+
const source = batch.find((entry) => entry.ref === decision.ref);
|
|
240
|
+
if (decision.role === "steering" && source !== void 0 && source.text.length > MAX_STEERING_SOURCE_CHARS) return `entry ${decision.ref} is ${source.text.length} characters long, too long to be an instruction: an entry that describes a person, a place or history is knowledge, and what is thrown away as steering is lost. Make it knowledge, or skip it if it is neither`;
|
|
241
|
+
if (decision.role === "steering" && source !== void 0 && text(decision.guidance).length < source.text.length * MIN_STEERING_SHARE) return `the guidance for entry ${decision.ref} is much shorter than the entry (${text(decision.guidance).length} of ${source.text.length} characters): keep everything the entry asks for, or, if it is not an instruction, make it knowledge`;
|
|
190
242
|
}
|
|
191
243
|
const missing = batch.filter((entry) => !seen.has(entry.ref)).map((entry) => entry.ref);
|
|
192
244
|
return missing.length === 0 ? void 0 : `decide every entry: ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} missing`;
|
|
@@ -210,6 +262,7 @@ async function classifyEntries(ctx, book) {
|
|
|
210
262
|
const result = {
|
|
211
263
|
entries: [],
|
|
212
264
|
steering: {},
|
|
265
|
+
steeringFrom: {},
|
|
213
266
|
notes: []
|
|
214
267
|
};
|
|
215
268
|
const taken = /* @__PURE__ */ new Set();
|
|
@@ -225,11 +278,13 @@ async function classifyEntries(ctx, book) {
|
|
|
225
278
|
if (decision.role === "steering") {
|
|
226
279
|
const target = text(decision.target);
|
|
227
280
|
(result.steering[target] ??= []).push(withPlayer(text(decision.guidance)));
|
|
281
|
+
(result.steeringFrom[target] ??= []).push(label);
|
|
282
|
+
result.notes.push(`kept aside as instructions for ${STEERING_TARGETS[target]}: ${label}`);
|
|
228
283
|
continue;
|
|
229
284
|
}
|
|
230
285
|
const title = (text(decision.title) || source.title).slice(0, 100);
|
|
231
286
|
const kind = LORE_KINDS.includes(decision.kind) ? decision.kind : "other";
|
|
232
|
-
const listed = decision.scope === "listed" && strings(decision.known_by).length > 0;
|
|
287
|
+
const listed = decision.has_secrets === true || decision.scope === "listed" && strings(decision.known_by).length > 0;
|
|
233
288
|
const also = source.keys.length === 0 ? "" : ` Also: ${source.keys.join(", ")}.`;
|
|
234
289
|
const parts = partsOf(withPlayer(source.text));
|
|
235
290
|
for (const [part, body] of parts.entries()) result.entries.push({
|
|
@@ -247,6 +302,24 @@ async function classifyEntries(ctx, book) {
|
|
|
247
302
|
return result;
|
|
248
303
|
}
|
|
249
304
|
//#endregion
|
|
305
|
+
//#region src/shared/lorebook-chat.ts
|
|
306
|
+
const PREFIX = "lorebook-author-";
|
|
307
|
+
/** Stable DSH chat identity for the authoring conversation of one library lorebook. */
|
|
308
|
+
function lorebookChatSessionId(name) {
|
|
309
|
+
if (name === "") throw new TypeError("lorebook name cannot be empty");
|
|
310
|
+
return `${PREFIX}${encodeURIComponent(name)}`;
|
|
311
|
+
}
|
|
312
|
+
/** The library lorebook named by a dedicated lorebook authoring chat. */
|
|
313
|
+
function lorebookOfChat(chatSessionId) {
|
|
314
|
+
if (!chatSessionId.startsWith(PREFIX)) return void 0;
|
|
315
|
+
try {
|
|
316
|
+
const name = decodeURIComponent(chatSessionId.slice(16));
|
|
317
|
+
return name === "" ? void 0 : name;
|
|
318
|
+
} catch {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
//#endregion
|
|
250
323
|
//#region src/host/authoring/lorebook-author-tools.ts
|
|
251
324
|
const LOREBOOK_MUTATION_TOOLS = [
|
|
252
325
|
"write_lorebook_entry",
|
|
@@ -502,9 +575,11 @@ function lorebookAuthorTools(reader, settings, prompting, shipped = shippedPromp
|
|
|
502
575
|
});
|
|
503
576
|
}
|
|
504
577
|
const guidance = Object.fromEntries(Object.entries(made.steering).map(([target, lines]) => [STEERING_TARGETS[target], lines]));
|
|
578
|
+
const from = Object.fromEntries(Object.entries(made.steeringFrom).map(([target, titles]) => [STEERING_TARGETS[target], titles]));
|
|
505
579
|
if (Object.keys(guidance).length > 0) await writeFile(join(directory, IMPORT_FOLDER, STEERING_FILE), JSON.stringify({
|
|
506
580
|
source: uploaded.name,
|
|
507
|
-
guidance
|
|
581
|
+
guidance,
|
|
582
|
+
from
|
|
508
583
|
}, null, 2));
|
|
509
584
|
await rm(join(directory, IMPORT_FOLDER, "lorebook.json"), { force: true });
|
|
510
585
|
const waiting = Object.keys(guidance);
|
|
@@ -614,6 +689,6 @@ async function lorebookApproval(exec, next, state) {
|
|
|
614
689
|
};
|
|
615
690
|
}
|
|
616
691
|
//#endregion
|
|
617
|
-
export { lorebookImportMessage as a,
|
|
692
|
+
export { lorebookImportMessage as a, lorebookOfChat as c, selectEntries as d, lorebookAuthorTools as i, previewLorebook as l, LorebookReader as n, pendingTargets as o, lorebookApproval as r, lorebookChatSessionId as s, LOREBOOK_UPLOAD as t, readLorebook as u };
|
|
618
693
|
|
|
619
|
-
//# sourceMappingURL=lorebook-author-tools-
|
|
694
|
+
//# sourceMappingURL=lorebook-author-tools-C-o0t4dL.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
3
|
-
import {
|
|
1
|
+
import { St as lorebookDirectory, n as limitAuthoringAgents } from "./authoring-tools-C_8ClUkP.js";
|
|
2
|
+
import "./hooks-B2EhBS_-.js";
|
|
3
|
+
import { c as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-C-o0t4dL.js";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { existsSync, readdirSync } from "node:fs";
|
|
6
6
|
//#region src/lorebook-authoring.ts
|
|
@@ -10,6 +10,7 @@ const inject = [
|
|
|
10
10
|
"roleplayImport",
|
|
11
11
|
"roleplayPrompts",
|
|
12
12
|
"roleplayAuthoringLanguages",
|
|
13
|
+
"roleplayAuthoringTools",
|
|
13
14
|
"tools",
|
|
14
15
|
"systemPrompt"
|
|
15
16
|
];
|
|
@@ -37,6 +38,7 @@ function apply(ctx) {
|
|
|
37
38
|
rules: false
|
|
38
39
|
} : pendingTargets(directory);
|
|
39
40
|
};
|
|
41
|
+
limitAuthoringAgents(ctx, (chat) => lorebookOfChat(chat) === void 0 ? void 0 : "lorebookAuthoring");
|
|
40
42
|
ctx.on("tools/pre-execute", (exec, next) => lorebookApproval(exec, next, {
|
|
41
43
|
carries,
|
|
42
44
|
waiting
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { existsSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
1
3
|
//#region ../dsh-roleplay-model/src/clock.ts
|
|
2
4
|
/**
|
|
3
5
|
* How the story's time passes: `simulated` moves only when the story does (the game master says how
|
|
@@ -214,6 +216,12 @@ const SETTINGS_SPEC = {
|
|
|
214
216
|
sampling: {
|
|
215
217
|
master: ratio(0, 2, .7),
|
|
216
218
|
characters: ratio(0, 2, .8),
|
|
219
|
+
topP: ratio(0, 1, 1),
|
|
220
|
+
topK: integer(0, 1e3, 0),
|
|
221
|
+
minP: ratio(0, 1, 0),
|
|
222
|
+
frequencyPenalty: ratio(-2, 2, 0),
|
|
223
|
+
presencePenalty: ratio(-2, 2, 0),
|
|
224
|
+
repetitionPenalty: ratio(0, 2, 1),
|
|
217
225
|
suggestions: ratio(0, 2, .2),
|
|
218
226
|
authoring: ratio(0, 2, .4),
|
|
219
227
|
records: ratio(0, 2, .1),
|
|
@@ -378,6 +386,141 @@ function parseSettings(value) {
|
|
|
378
386
|
};
|
|
379
387
|
}
|
|
380
388
|
//#endregion
|
|
381
|
-
|
|
389
|
+
//#region src/host/sessions/settings.ts
|
|
390
|
+
const SETTINGS_FILE = "settings.json";
|
|
391
|
+
const known = /* @__PURE__ */ new Map();
|
|
392
|
+
let childReasoning = "";
|
|
393
|
+
/** The thinking level helpers get when a chat's own setting is empty (the profile's choice); returns the function that takes it back. */
|
|
394
|
+
function useChildReasoning(level) {
|
|
395
|
+
childReasoning = level;
|
|
396
|
+
return () => {
|
|
397
|
+
childReasoning = "";
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/** The settings are not acceptable; `problems` say what to fix. */
|
|
401
|
+
var InvalidSettingsError = class extends Error {
|
|
402
|
+
problems;
|
|
403
|
+
constructor(problems) {
|
|
404
|
+
super(`the settings are not acceptable: ${problems.join("; ")}`);
|
|
405
|
+
this.problems = problems;
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* The settings of the session in `folder`; a session that has none yet has the defaults.
|
|
410
|
+
* @throws {InvalidSettingsError} when the file exists and is not valid.
|
|
411
|
+
*/
|
|
412
|
+
function readSettings(folder) {
|
|
413
|
+
const file = join(folder, SETTINGS_FILE);
|
|
414
|
+
if (!existsSync(file)) return { ...DEFAULT_SETTINGS };
|
|
415
|
+
let value;
|
|
416
|
+
try {
|
|
417
|
+
value = JSON.parse(readFileSync(file, "utf8"));
|
|
418
|
+
} catch (error) {
|
|
419
|
+
throw new InvalidSettingsError([`${SETTINGS_FILE} is not valid JSON (${error instanceof Error ? error.message : String(error)})`]);
|
|
420
|
+
}
|
|
421
|
+
const parsed = parseSettings(value);
|
|
422
|
+
if (!parsed.ok) throw new InvalidSettingsError(parsed.problems);
|
|
423
|
+
return parsed.value;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Store the settings of the session in `folder`, replacing what was there.
|
|
427
|
+
* @throws {InvalidSettingsError} when the value is not acceptable; nothing is written then.
|
|
428
|
+
*/
|
|
429
|
+
function writeSettings(folder, value) {
|
|
430
|
+
const parsed = parseSettings(value);
|
|
431
|
+
if (!parsed.ok) throw new InvalidSettingsError(parsed.problems);
|
|
432
|
+
const file = join(folder, SETTINGS_FILE);
|
|
433
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
434
|
+
writeFileSync(temporary, `${JSON.stringify(parsed.value, null, 2)}\n`);
|
|
435
|
+
renameSync(temporary, file);
|
|
436
|
+
known.delete(folder);
|
|
437
|
+
return parsed.value;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* The settings to use right now. Called before each use, so an edit to the file applies at the
|
|
441
|
+
* next round, step or run without a restart; the file is parsed again only when it changed.
|
|
442
|
+
* A file that is not valid is reported once through `problem` and the last good settings
|
|
443
|
+
* (the defaults when there were none) stay in force, so a typo cannot stop a story in the middle.
|
|
444
|
+
*/
|
|
445
|
+
function liveSettings(folder, problem = () => void 0) {
|
|
446
|
+
const value = loadedSettings(folder, problem);
|
|
447
|
+
return value.reasoning.children === "" && childReasoning !== "" ? {
|
|
448
|
+
...value,
|
|
449
|
+
reasoning: {
|
|
450
|
+
...value.reasoning,
|
|
451
|
+
children: childReasoning
|
|
452
|
+
}
|
|
453
|
+
} : value;
|
|
454
|
+
}
|
|
455
|
+
function loadedSettings(folder, problem) {
|
|
456
|
+
let modified = -1;
|
|
457
|
+
try {
|
|
458
|
+
modified = statSync(join(folder, SETTINGS_FILE)).mtimeMs;
|
|
459
|
+
} catch {}
|
|
460
|
+
const last = known.get(folder);
|
|
461
|
+
if (last?.modified === modified) return last.value;
|
|
462
|
+
try {
|
|
463
|
+
const value = readSettings(folder);
|
|
464
|
+
known.set(folder, {
|
|
465
|
+
modified,
|
|
466
|
+
value
|
|
467
|
+
});
|
|
468
|
+
return value;
|
|
469
|
+
} catch (error) {
|
|
470
|
+
if (!(error instanceof InvalidSettingsError)) throw error;
|
|
471
|
+
problem(`${error.message} (the last good settings stay in force)`);
|
|
472
|
+
const value = last?.value ?? { ...DEFAULT_SETTINGS };
|
|
473
|
+
known.set(folder, {
|
|
474
|
+
modified,
|
|
475
|
+
value
|
|
476
|
+
});
|
|
477
|
+
return value;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/shared/narration.ts
|
|
482
|
+
const OPEN = "<roleplay-output>";
|
|
483
|
+
const CLOSE = "</roleplay-output>";
|
|
484
|
+
const PREVIEW_OPEN = "<roleplay-preview>";
|
|
485
|
+
const PREVIEW_CLOSE = "</roleplay-preview>";
|
|
486
|
+
/** What the game master shows the player while the characters are still being asked: a scene-setting opening that the delivered output replaces in the view. */
|
|
487
|
+
function encodePreview(text) {
|
|
488
|
+
return `${PREVIEW_OPEN}${JSON.stringify({ text })}${PREVIEW_CLOSE}`;
|
|
489
|
+
}
|
|
490
|
+
function encodeOutput(output) {
|
|
491
|
+
return `${OPEN}${JSON.stringify(output)}${CLOSE}`;
|
|
492
|
+
}
|
|
493
|
+
function isSegment(value) {
|
|
494
|
+
if (typeof value !== "object" || value === null) return false;
|
|
495
|
+
const segment = value;
|
|
496
|
+
if (segment["type"] === "narration") return typeof segment["text"] === "string";
|
|
497
|
+
return segment["type"] === "utterance" && typeof segment["character"] === "string" && typeof segment["name"] === "string" && typeof segment["text"] === "string";
|
|
498
|
+
}
|
|
499
|
+
/** The output encoded in a tool result's text, or nothing when the text carries none. */
|
|
500
|
+
function decodeOutput(text) {
|
|
501
|
+
const start = text.indexOf(OPEN);
|
|
502
|
+
const end = text.indexOf(CLOSE, start + 17);
|
|
503
|
+
if (start < 0 || end < 0) return void 0;
|
|
504
|
+
try {
|
|
505
|
+
const value = JSON.parse(text.slice(start + 17, end));
|
|
506
|
+
const segments = value["segments"];
|
|
507
|
+
if (!Array.isArray(segments) || !segments.every(isSegment) || typeof value["repaired"] !== "boolean") return void 0;
|
|
508
|
+
const ooc = value["ooc"];
|
|
509
|
+
const ruled = typeof ooc === "object" && ooc !== null && typeof ooc["legal"] === "boolean" && typeof ooc["note"] === "string" ? ooc : void 0;
|
|
510
|
+
const timelineNode = typeof value["timelineNode"] === "string" ? value["timelineNode"] : void 0;
|
|
511
|
+
const rolls = Array.isArray(value["rolls"]) ? value["rolls"].filter((entry) => typeof entry === "object" && entry !== null && typeof entry.id === "number" && typeof entry.text === "string" && (entry.by === "agent" || entry.by === "player")) : [];
|
|
512
|
+
return {
|
|
513
|
+
segments,
|
|
514
|
+
repaired: value["repaired"],
|
|
515
|
+
...ruled === void 0 ? {} : { ooc: ruled },
|
|
516
|
+
...rolls.length === 0 ? {} : { rolls },
|
|
517
|
+
...timelineNode === void 0 ? {} : { timelineNode }
|
|
518
|
+
};
|
|
519
|
+
} catch {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
//#endregion
|
|
524
|
+
export { VARIABLE_VISIBILITIES as _, liveSettings as a, writeSettings as c, parseSettings as d, parseSwitchboard as f, VARIABLE_SUBJECTS as g, VARIABLE_KINDS as h, InvalidSettingsError as i, DEFAULT_SETTINGS as l, rulesOf as m, encodeOutput as n, readSettings as o, WORLD_RULES_KEY as p, encodePreview as r, useChildReasoning as s, decodeOutput as t, SETTINGS_SPEC as u };
|
|
382
525
|
|
|
383
|
-
//# sourceMappingURL=
|
|
526
|
+
//# sourceMappingURL=narration-BT9uvQry.js.map
|
package/lib/orchestration.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { n as chatSessionId, r as roleplaySessionOf, t as promptFor } from "./access-EbNdZFbk.js";
|
|
2
|
-
import { b as INTENT_STATUSES } from "./presets-
|
|
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-
|
|
4
|
-
import "./
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { _ as API_PREFIX } from "./packs-xHRCcGdb.js";
|
|
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-DkwFGtNH.js";
|
|
14
|
-
import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-DnNEG_Mn.js";
|
|
2
|
+
import { b as INTENT_STATUSES } from "./presets-C3mhqqfz.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-Btsj0ZLh.js";
|
|
4
|
+
import { a as liveSettings } from "./narration-BT9uvQry.js";
|
|
5
|
+
import { E as RESULTS, F as wrongLanguage, S as ClockError, T as zoneOf, c as AUTHORING_NEEDS, ct as translator, d as storesOf, g as writeVerdicts, h as readVerdicts, l as toolEnabled, n as installHooks, o as PREVIEW_TOOL, r as externalGiven, rt as ReflectionRefusedError, s as createTools$1, st as languageOf, u as MAX_OOC_ANSWER, w as describeWhen } from "./hooks-B2EhBS_-.js";
|
|
6
|
+
import { a as runChild, f as currentTurn, i as childTrace, m as tokensOf, n as childSampling, p as estimateAnswer, t as childModel } from "./child-DsixtqTw.js";
|
|
7
|
+
import { b as slug, t as addToLibrary, x as uniqueKey } from "./library-COIktKBa.js";
|
|
8
|
+
import { _ as API_PREFIX } from "./packs-CJPSe5LI.js";
|
|
9
|
+
import { i as updateImage, r as listGallery, t as describeGalleryImage } from "./gallery-CDYKJf_O.js";
|
|
10
|
+
import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-Gu34bZwd.js";
|
|
15
11
|
import { join } from "node:path";
|
|
16
12
|
import { existsSync } from "node:fs";
|
|
17
13
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
@@ -25,7 +21,11 @@ const RESOURCE_TOOLS = [
|
|
|
25
21
|
"list_mcp_resource_templates",
|
|
26
22
|
"read_mcp_resource"
|
|
27
23
|
];
|
|
28
|
-
|
|
24
|
+
function serverOf(name) {
|
|
25
|
+
if (!name.startsWith("mcp__")) return [];
|
|
26
|
+
const end = name.indexOf("__", 5);
|
|
27
|
+
return end <= 5 || end + 2 >= name.length ? [] : [name.slice(5, end)];
|
|
28
|
+
}
|
|
29
29
|
/**
|
|
30
30
|
* What an agent is told about MCP resources: nothing unless it can see a resource tool, since the plugin's own paragraph names the tools
|
|
31
31
|
* and servers to every agent whether or not it was given them, and an agent that is told of a tool it lacks goes looking for it. The servers are
|
|
@@ -34,7 +34,7 @@ const NAMESPACED = /^mcp__(.+?)__.+$/;
|
|
|
34
34
|
function resourceHint(visible, registered, tr) {
|
|
35
35
|
const tools = RESOURCE_TOOLS.filter((name) => visible.includes(name));
|
|
36
36
|
if (tools.length === 0) return "";
|
|
37
|
-
const servers = [...new Set(registered.flatMap((
|
|
37
|
+
const servers = [...new Set(registered.flatMap(serverOf))].sort((a, b) => a.localeCompare(b));
|
|
38
38
|
return servers.length === 0 ? tr("## MCP resource servers\n\nUse {tools} with the server argument naming an MCP server.", { tools: tools.join(", ") }) : tr("## MCP resource servers\n\nUse {tools} with one of these names as the server argument: {servers}.", {
|
|
39
39
|
tools: tools.join(", "),
|
|
40
40
|
servers: JSON.stringify(servers)
|
|
@@ -614,6 +614,8 @@ function factionStrategist(deps) {
|
|
|
614
614
|
}
|
|
615
615
|
//#endregion
|
|
616
616
|
//#region src/host/authoring/author-agent.ts
|
|
617
|
+
/** How many calls of the tools of other plugins the author may make on top of its own budget. */
|
|
618
|
+
const EXTERNAL_CALLS = 10;
|
|
617
619
|
/** A made-up thing in one edit: its name, description and the handful of fields a character, place or item carries. */
|
|
618
620
|
const THING_TEXTS = 14;
|
|
619
621
|
const THING_TEXT_CHARS = 300;
|
|
@@ -857,6 +859,7 @@ function worldAuthor(deps) {
|
|
|
857
859
|
if (parent === void 0) throw new Error(`no agent for chat ${chat}`);
|
|
858
860
|
return parent;
|
|
859
861
|
};
|
|
862
|
+
const given = (parent) => deps.external?.(parent) ?? [];
|
|
860
863
|
return {
|
|
861
864
|
async create(job, signal) {
|
|
862
865
|
const parent = parentOf(job.chat);
|
|
@@ -872,6 +875,7 @@ function worldAuthor(deps) {
|
|
|
872
875
|
persona: promptFor(parent, "world/author", job.store.settings().prompts.language),
|
|
873
876
|
prompt: createPrompt(job, authoring.perTurn),
|
|
874
877
|
tools: authorTools(job, work, "create", authoring),
|
|
878
|
+
external: given(parent),
|
|
875
879
|
result: CREATE_RESULT,
|
|
876
880
|
beforeSubmit: (value) => {
|
|
877
881
|
const { outcome } = value;
|
|
@@ -880,7 +884,7 @@ function worldAuthor(deps) {
|
|
|
880
884
|
const errors = errorsAbout(job.store, work);
|
|
881
885
|
return errors.length === 0 ? void 0 : `what you made is not usable yet; fix it with edit_world:\n${describeFindings(errors).join("\n")}`;
|
|
882
886
|
},
|
|
883
|
-
maxCalls: 30
|
|
887
|
+
maxCalls: 30 + (given(parent).length > 0 ? EXTERNAL_CALLS : 0)
|
|
884
888
|
});
|
|
885
889
|
const label = names(job.store);
|
|
886
890
|
const created = work.created.map((entry) => ({
|
|
@@ -915,6 +919,7 @@ function worldAuthor(deps) {
|
|
|
915
919
|
persona: promptFor(parent, "world/consolidate", job.store.settings().prompts.language),
|
|
916
920
|
prompt: consolidationPrompt(job),
|
|
917
921
|
tools: authorTools(job, work, "consolidate", authoring),
|
|
922
|
+
external: given(parent),
|
|
918
923
|
result: CONSOLIDATE_RESULT,
|
|
919
924
|
beforeSubmit: (value) => {
|
|
920
925
|
if (!value.complete) return void 0;
|
|
@@ -923,7 +928,7 @@ function worldAuthor(deps) {
|
|
|
923
928
|
const errors = lintWorld(job.store.story).filter((finding) => finding.severity === "error");
|
|
924
929
|
return errors.length === 0 ? void 0 : `the world still shows errors:\n${describeFindings(errors).join("\n")}`;
|
|
925
930
|
},
|
|
926
|
-
maxCalls: 60
|
|
931
|
+
maxCalls: 60 + (given(parent).length > 0 ? EXTERNAL_CALLS : 0)
|
|
927
932
|
});
|
|
928
933
|
if (!result.complete) throw new Error(`not everything could be fitted in: ${result.notes}`);
|
|
929
934
|
return {
|
|
@@ -939,6 +944,11 @@ const PROTOCOL_SECTION = "roleplay:protocol";
|
|
|
939
944
|
const PERSONA_SECTION = "roleplay:persona";
|
|
940
945
|
//#endregion
|
|
941
946
|
//#region src/host/dice/describe.ts
|
|
947
|
+
const sentenceBody = (value) => {
|
|
948
|
+
let end = value.length;
|
|
949
|
+
while (end > 0 && (value[end - 1] === "." || /\s/u.test(value[end - 1]))) end -= 1;
|
|
950
|
+
return value.slice(0, end);
|
|
951
|
+
};
|
|
942
952
|
/** The checks of a story as the game master is told of them: when each is used, what it rolls and what it needs. The result's bands are told by the roll itself. */
|
|
943
953
|
function describeChecks(checks, tr) {
|
|
944
954
|
if (checks.length === 0) return tr("No checks are defined: use roll_dice only.");
|
|
@@ -952,7 +962,7 @@ function describeChecks(checks, tr) {
|
|
|
952
962
|
return `${tr("- {key} ({name}): {use}", {
|
|
953
963
|
key: check.key,
|
|
954
964
|
name: check.name,
|
|
955
|
-
use: check.use
|
|
965
|
+
use: sentenceBody(check.use)
|
|
956
966
|
})}. ${needs.join(" ")}`;
|
|
957
967
|
});
|
|
958
968
|
return [tr("The checks of this story:"), ...lines].join("\n");
|
|
@@ -1781,7 +1791,7 @@ function asSpoken(segments, spoken) {
|
|
|
1781
1791
|
*/
|
|
1782
1792
|
function checkedOutput(narrationChecker, language, state, segments, silent) {
|
|
1783
1793
|
const problems = [...segments.flatMap((segment, index) => segment.type === "utterance" && segment.character === "" ? [`segment ${index + 1}: an utterance needs the character who says it`] : []), ...narrationChecker.check(segments, state.utterances)];
|
|
1784
|
-
const wording = wrongLanguage(language, { narration: segments.flatMap((segment) => segment.type === "narration" ? [segment.text] : []).join(" ") });
|
|
1794
|
+
const wording = wrongLanguage(language, { narration: segments.flatMap((segment) => segment.type === "narration" ? [segment.text] : []).join(" ") }, { strays: true });
|
|
1785
1795
|
if (problems.length === 0 && wording !== void 0 && !silent && state.refused < 2) {
|
|
1786
1796
|
state.refused += 1;
|
|
1787
1797
|
throw new Error(`the output is not acceptable: ${wording}. Deliver it again with the narration corrected; utterances may not be touched`);
|
|
@@ -2081,7 +2091,7 @@ var TurnEngine = class {
|
|
|
2081
2091
|
});
|
|
2082
2092
|
if (keys.length === 0) throw new Error("there is no character to activate");
|
|
2083
2093
|
if (keys.length > most) throw new Error(`${keys.length} characters were asked, which is more than one round allows (${most}): ask only those the moment actually reaches, and the others in a later round if the story comes to them`);
|
|
2084
|
-
const signature = `${[...keys].sort().join(",")}|${situation.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").trim()}`;
|
|
2094
|
+
const signature = `${[...keys].sort((a, b) => a.localeCompare(b)).join(",")}|${situation.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").trim()}`;
|
|
2085
2095
|
if (repeatsEarlier(signature, state.asked)) throw new Error("the same characters were already asked about the same situation in this message, so nothing new would come of it: say what changed, ask others, or deliver the output with narrate");
|
|
2086
2096
|
state.situation = situation;
|
|
2087
2097
|
state.cast = cast;
|
|
@@ -2895,7 +2905,10 @@ function apply(ctx) {
|
|
|
2895
2905
|
ctx.effect(() => ctx.roleplayOrchestration.replace({ judge: triggerJudge({ agentOf: (chat) => ctx.agents.get(SessionId(chat)) }) }), "roleplay: trigger judge");
|
|
2896
2906
|
ctx.effect(() => ctx.roleplayOrchestration.replace({ strategist: factionStrategist({ agentOf: (chat) => ctx.agents.get(SessionId(chat)) }) }), "roleplay: faction strategist");
|
|
2897
2907
|
ctx.effect(() => ctx.roleplayOrchestration.replace({ reflector: memoryReflector({ agentOf: (chat) => ctx.agents.get(SessionId(chat)) }) }), "roleplay: reflection");
|
|
2898
|
-
ctx.effect(() => ctx.roleplayOrchestration.replace({ author: worldAuthor({
|
|
2908
|
+
ctx.effect(() => ctx.roleplayOrchestration.replace({ author: worldAuthor({
|
|
2909
|
+
agentOf: (chat) => ctx.agents.get(SessionId(chat)),
|
|
2910
|
+
external: (parent) => ctx.get("roleplayAuthoringTools")?.given(parent.ctx.tools, "worldAuthor") ?? []
|
|
2911
|
+
}) }), "roleplay: world author");
|
|
2899
2912
|
ctx.effect(() => ctx.roleplayOrchestration.replace({ suggester: suggestionWriter({ agentOf: (chat) => ctx.agents.get(SessionId(chat)) }) }), "roleplay: suggestions");
|
|
2900
2913
|
ctx.effect(() => ctx.roleplayState.bind((agentSessionId) => {
|
|
2901
2914
|
const id = roleplaySessionOf(agentSessionId);
|