@dsh-agentic-roleplay/core 0.3.4 → 0.3.5

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.
@@ -1,12 +1,14 @@
1
1
  import { r as roleplaySessionOf, t as promptFor } from "./access-EbNdZFbk.js";
2
- import { i as inheritPacks } from "./packs-BYjrAen6.js";
2
+ import { a as listPresets, d as sha, o as loadPreset } from "./presets-DNjNxQL5.js";
3
3
  import "./settings-CA6icLL_.js";
4
- import { _ as inheritPrompts, a as wrongLanguage } from "./language-DWVwi1R7.js";
5
- import { F as describeWhen, H as languageOf, P as describeTime, U as translator, V as answerLimits } from "./deliver-CpZOxBX5.js";
4
+ import { p as inheritPrompts, u as PROMPTS_FOLDER } from "./load-Clkl0T7C.js";
5
+ import { F as describeWhen, H as languageOf, P as describeTime, U as translator, V as answerLimits } from "./deliver-Cl6bjp7g.js";
6
6
  import { a as runChild, i as childTrace, n as childSampling, t as childModel, u as estimateAnswer } from "./child-CFjnaTZt.js";
7
- import { u as inheritImages } from "./generator-B6FxlKOV.js";
8
- import { join } from "node:path";
9
- import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
7
+ import { a as inheritImages } from "./library-9JB9zw5a.js";
8
+ import { a as wrongLanguage } from "./language-BgyxtB2h.js";
9
+ import { i as inheritPacks } from "./packs-BC2A3geF.js";
10
+ import { dirname, join } from "node:path";
11
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
10
12
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
11
13
  import { MINUTE, characterKey, describeDuration, locationKey, mentioned, overlap, sessionDatabase, sessionFolder, tokens } from "@dsh-agentic-roleplay/state";
12
14
  //#region ../dsh-roleplay-model/src/memory.ts
@@ -779,6 +781,125 @@ function planMove(timeline, target, surface) {
779
781
  };
780
782
  }
781
783
  //#endregion
784
+ //#region src/host/presets/apply.ts
785
+ /** Which preset a story's prompts came from, and what each copied file held: kept beside the story's database, so that a story can tell its copies from its own edits. */
786
+ const PRESET_RECORD = "preset.json";
787
+ const promptFile = (folder, path) => join(folder, PROMPTS_FOLDER, ...path.split("/"));
788
+ function readRecord(folder) {
789
+ const file = join(folder, PRESET_RECORD);
790
+ if (!existsSync(file)) return void 0;
791
+ let value;
792
+ try {
793
+ value = JSON.parse(readFileSync(file, "utf8"));
794
+ } catch {
795
+ throw new Error(`${file} is damaged`);
796
+ }
797
+ const { name, files } = value ?? {};
798
+ if (typeof name !== "string" || typeof files !== "object" || files === null || !Object.values(files).every((hash) => typeof hash === "string")) throw new Error(`${file} is damaged`);
799
+ return {
800
+ name,
801
+ files
802
+ };
803
+ }
804
+ function writeRecord(folder, record) {
805
+ const file = join(folder, PRESET_RECORD);
806
+ if (record === void 0) {
807
+ rmSync(file, { force: true });
808
+ return;
809
+ }
810
+ const temporary = `${file}.tmp`;
811
+ writeFileSync(temporary, JSON.stringify(record, null, 2));
812
+ renameSync(temporary, file);
813
+ }
814
+ /** Writes the preset's prompts over the story's own. */
815
+ function copyPreset(preset, folder) {
816
+ for (const [path, text] of preset.files) {
817
+ const to = promptFile(folder, path);
818
+ mkdirSync(dirname(to), { recursive: true });
819
+ writeFileSync(to, text);
820
+ }
821
+ }
822
+ /** Notes that the story's prompts came from the preset: only the files that still hold the preset's text count, because the world's own may have replaced the rest. */
823
+ function recordPreset(folder, preset) {
824
+ const files = {};
825
+ for (const [path, text] of preset.files) {
826
+ const own = promptFile(folder, path);
827
+ if (existsSync(own) && readFileSync(own, "utf8") === text) files[path] = sha(text);
828
+ }
829
+ writeRecord(folder, {
830
+ name: preset.summary.name,
831
+ files
832
+ });
833
+ }
834
+ /** Where the story stands against the library. */
835
+ function presetStatus(root, folder) {
836
+ const available = listPresets(root).map((entry) => entry.summary);
837
+ const record = readRecord(folder);
838
+ if (record === void 0) return { available };
839
+ const paths = Object.keys(record.files);
840
+ const edited = paths.some((path) => {
841
+ const file = promptFile(folder, path);
842
+ return !existsSync(file) || sha(readFileSync(file, "utf8")) !== record.files[path];
843
+ });
844
+ let state = edited ? "edited" : "current";
845
+ try {
846
+ const library = loadPreset(root, record.name);
847
+ if (!edited && (library.files.size !== paths.length || paths.some((path) => {
848
+ const text = library.files.get(path);
849
+ return text === void 0 || sha(text) !== record.files[path];
850
+ }))) state = "changed";
851
+ } catch {
852
+ state = "missing";
853
+ }
854
+ return {
855
+ applied: {
856
+ name: record.name,
857
+ state,
858
+ files: paths
859
+ },
860
+ available
861
+ };
862
+ }
863
+ /**
864
+ * Takes the story's copies of its preset out (to `.trash/prompts/` in the story) and, when a preset is named, puts that one in.
865
+ * Prompts the world carried that a preset had replaced are not brought back.
866
+ * @returns the files that were replaced or taken out.
867
+ * @throws {Error} when the named preset has problems or does not exist; nothing is changed then.
868
+ */
869
+ function switchPreset(root, folder, name, now = Date.now) {
870
+ const next = name === void 0 ? void 0 : loadPreset(root, name);
871
+ if (next !== void 0 && next.summary.problems.length > 0) throw new Error(`the preset "${name}" has problems: ${next.summary.problems.join("; ")}`);
872
+ const record = readRecord(folder);
873
+ const touched = new Set(next === void 0 ? [] : next.files.keys());
874
+ for (const path of Object.keys(record?.files ?? {})) touched.add(path);
875
+ const aside = join(folder, ".trash", PROMPTS_FOLDER, String(now()));
876
+ const moved = [];
877
+ for (const path of touched) {
878
+ const file = promptFile(folder, path);
879
+ if (!existsSync(file)) continue;
880
+ const to = join(aside, ...path.split("/"));
881
+ mkdirSync(dirname(to), { recursive: true });
882
+ copyFileSync(file, to);
883
+ moved.push(path);
884
+ }
885
+ for (const path of Object.keys(record?.files ?? {})) {
886
+ const file = promptFile(folder, path);
887
+ rmSync(file, { force: true });
888
+ }
889
+ if (next === void 0) {
890
+ writeRecord(folder, void 0);
891
+ return moved;
892
+ }
893
+ copyPreset(next, folder);
894
+ recordPreset(folder, next);
895
+ return moved;
896
+ }
897
+ /** A branch plays with the preset of the story it was cut from. */
898
+ function inheritPreset(from, to) {
899
+ const file = join(from, PRESET_RECORD);
900
+ if (existsSync(file)) copyFileSync(file, join(to, PRESET_RECORD));
901
+ }
902
+ //#endregion
782
903
  //#region src/host/timeline/service.ts
783
904
  /** The text of the marker that stands for the turns it replaces: never empty, as a model service may refuse an empty message. */
784
905
  const MARKER_TEXT = "(empty message)";
@@ -982,6 +1103,7 @@ var Timelines = class {
982
1103
  try {
983
1104
  await inheritImages(this.folder(from), this.folder(id), branch.timeline.nodes.map((node) => node.id));
984
1105
  inheritPrompts(this.folder(from), this.folder(id));
1106
+ inheritPreset(this.folder(from), this.folder(id));
985
1107
  inheritPacks(this.folder(from), this.folder(id));
986
1108
  const plan = planMove(branch.timeline, branch.timeline.head, [...agent.session.surface.nodes]);
987
1109
  this.reconcile(agent, plan);
@@ -1838,6 +1960,6 @@ function memoryReflector(deps) {
1838
1960
  } };
1839
1961
  }
1840
1962
  //#endregion
1841
- export { whereabouts as a, readTimeline as c, sameWords as d, referent as f, reflectionStatus as i, pathTo as l, memoryReflector as n, TimelineError as o, recordFailure as r, Timelines as s, dueReflection as t, defaultBoundaries as u };
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 };
1842
1964
 
1843
- //# sourceMappingURL=reflection-waxFg1x-.js.map
1965
+ //# sourceMappingURL=reflection-Bju_LPFn.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-agentic-roleplay/core",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Core plugin of the agentic roleplay bundle for DeepSeek Harness: roleplay UI, orchestration and storage.",
5
5
  "author": {
6
6
  "name": "Firefox2100",
@@ -12,6 +12,7 @@
12
12
  ".": "./lib/index.js",
13
13
  "./orchestration": "./lib/orchestration.js",
14
14
  "./authoring": "./lib/authoring.js",
15
+ "./preset-authoring": "./lib/preset-authoring.js",
15
16
  "./doctor": "./lib/doctor.js",
16
17
  "./compaction": "./lib/compaction.js",
17
18
  "./images": "./lib/images.js",
@@ -75,7 +76,7 @@
75
76
  "@deepseek-ai/schemastery": "^3.18.4"
76
77
  },
77
78
  "dependencies": {
78
- "@dsh-agentic-roleplay/state": "0.3.4",
79
+ "@dsh-agentic-roleplay/state": "0.3.5",
79
80
  "@dsh-ai-providers/core": "^0.1.2"
80
81
  },
81
82
  "devDependencies": {
@@ -0,0 +1 @@
1
+ You are a preset authoring assistant. A preset is reusable writing instructions for interactive roleplay: the narrator's persona, the style of the narration, and the style in which characters speak and act. Help the user shape them. A preset holds only prose, never the rules of the game, the names of tools or the fields the program reads, and nothing specific to one world or character. Read the preset with your tools before relying on its details, and write in the style the user asks for. Every write requires the user's one-time approval. If approval is declined or unavailable, acknowledge that nothing changed and continue discussing revisions instead of retrying automatically.
@@ -0,0 +1 @@
1
+ Use the read tools before making claims or edits. A preset carries up to three prompts in each language: roleplay/persona (who the narrator is), roleplay/style (how the narration is written) and roleplay/character-style (how characters speak and act). Read the one you are changing first (list_preset_prompts shows which the preset already carries; a prompt it does not carry is read as the shipped default, a good starting point), change only what the request needs, keep every placeholder the original uses (a name in braces after a dollar sign), and write it again in the other languages the preset carries when the user wants them to match. Every write asks the user for one-time approval. If approval is rejected, cancelled or unavailable, do not retry it automatically: explain that nothing changed and ask how the user wants to proceed. To turn an uploaded SillyTavern preset into prompts, call import_narration_preset with the file the user's message names. The suggested temperatures (sampling) are for the narrator (master) and the characters only.
@@ -0,0 +1 @@
1
+ Welcome to the authoring room for the preset “${preset}”. A preset is a set of writing instructions that can be put into any story: who the narrator is, how the narration reads, and how the characters speak and behave. I can read and rewrite its prompts in each language, and set its title, description and the temperatures it suggests. I will show you each change for approval before it is written; if you decline, nothing changes and we can revise it together. Tell me how you want the story to read.
@@ -0,0 +1 @@
1
+ 你是一位预设创作助手。预设是互动角色扮演中可复用的写作指令:叙述者的人设、叙述的文风,以及角色说话和行动的风格。帮助用户把它们打磨好。预设只包含行文方面的文字,不包含游戏规则、工具名称或程序读取的字段,也不包含只属于某个世界或某个角色的内容。在依赖任何细节之前,先用工具读取预设,并按用户要求的风格来写。每一次写入都需要用户一次性的批准。如果批准被拒绝或无法获得,请说明没有任何改动,并继续与用户讨论修改方案,不要自动重试。
@@ -0,0 +1 @@
1
+ 在下结论或修改之前,先用读取类工具查看。预设在每种语言下最多带有三个提示词:roleplay/persona(叙述者是谁)、roleplay/style(叙述怎么写)和 roleplay/character-style(角色怎样说话和行动)。先读你要改的那一个(list_preset_prompts 会显示预设已带有哪些;未带有的提示词读到的是内置默认文本,是个不错的起点),只改请求需要改的部分,保留原文用到的每一个占位符(美元符号后花括号里的名称),用户希望各语言保持一致时,也在预设带有的其他语言中重写。每一次写入都会请用户一次性批准。如果批准被拒绝、取消或无法获得,不要自动重试:说明没有任何改动,并询问用户想怎么继续。要把上传的酒馆(SillyTavern)预设变成提示词,请用用户消息中指明的文件调用 import_narration_preset。建议温度(sampling)只涉及叙述者(master)和角色(characters)。
@@ -0,0 +1 @@
1
+ 欢迎来到预设“${preset}”的创作室。预设是一组可以放进任何故事的写作指令:叙述者是谁、叙述读起来如何、角色怎样说话和行事。我可以读取并改写它在各种语言下的提示词,也可以设置它的标题、描述和建议的温度。每一处修改,我都会先给你看,经你批准后才写入;如果你拒绝,不会有任何改动,我们可以一起修改。告诉我你希望故事读起来是什么样子。