@dsh-agentic-roleplay/core 0.4.1 → 0.6.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/{authoring-tools-C2BHkEFP.js → authoring-tools-BGzzW6O5.js} +7 -6
- package/lib/authoring.js +5 -5
- package/lib/{child-DsixtqTw.js → child-D5SVNk4O.js} +58 -71
- package/lib/client.js +747 -316
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +18 -23
- package/lib/doctor.js +2 -2
- package/lib/{gallery-CDYKJf_O.js → gallery-C7VOJ3xH.js} +2 -2
- package/lib/{generator-BR1ugzln.js → generator-CO8usAjE.js} +2 -2
- package/lib/helper.js +26 -0
- package/lib/{hooks-CHmUksFS.js → hooks-BLperIIB.js} +70 -7
- package/lib/images.js +4 -4
- package/lib/index.js +64 -22
- package/lib/{library-COIktKBa.js → library-DsDc6fQa.js} +2 -2
- package/lib/{lorebook-author-tools-CaT74Q7v.js → lorebook-author-tools-C-cFiE6E.js} +6 -6
- package/lib/lorebook-authoring.js +3 -3
- package/lib/{narration-DstnwrvX.js → narration-_dA9oIt2.js} +57 -2
- package/lib/orchestration.js +372 -48
- package/lib/{pack-jail-CEDDI4Xw.js → pack-jail-BKFmbYP8.js} +10 -10
- package/lib/{packs-DB_9xiCp.js → packs-ZTG7fWut.js} +2 -2
- package/lib/{presenter-agent-Gu34bZwd.js → presenter-agent-BHSbyWwZ.js} +5 -5
- package/lib/{preset-BL1d40oG.js → preset-CJLW8Mp0.js} +3 -3
- package/lib/{preset-author-tools-B2wZXKZo.js → preset-author-tools-1RstgEZs.js} +5 -5
- package/lib/preset-authoring.js +4 -4
- package/lib/{presets-Dc15L6OU.js → presets-DcPCnn8O.js} +3 -3
- package/lib/{reflection-BWMVdHhR.js → reflection-6qfOC5OT.js} +236 -32
- package/lib/text-CT1re6XT.js +18 -0
- package/package.json +38 -41
- package/prompts/en/roleplay/check-rule.md +3 -0
- package/prompts/en/roleplay/decide-reflection.md +3 -0
- package/prompts/en/roleplay/decide-trigger.md +3 -0
- package/prompts/en/roleplay/gate-agency.md +1 -0
- package/prompts/en/roleplay/gate-refusal.md +1 -0
- package/prompts/en/roleplay/gate-secret.md +3 -0
- package/prompts/zh/roleplay/check-rule.md +3 -0
- package/prompts/zh/roleplay/decide-reflection.md +3 -0
- package/prompts/zh/roleplay/decide-trigger.md +3 -0
- package/prompts/zh/roleplay/gate-agency.md +1 -0
- package/prompts/zh/roleplay/gate-refusal.md +1 -0
- package/prompts/zh/roleplay/gate-secret.md +3 -0
package/lib/compaction.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { r as roleplaySessionOf, t as promptFor } from "./access-EbNdZFbk.js";
|
|
2
|
-
import { a as liveSettings, t as decodeOutput } from "./narration-
|
|
2
|
+
import { a as liveSettings, t as decodeOutput } from "./narration-_dA9oIt2.js";
|
|
3
|
+
import { h as tokensOf, n as childSampling, o as runChild, t as childModel } from "./child-D5SVNk4O.js";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
5
6
|
import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
|
|
@@ -137,30 +138,23 @@ const SUMMARY_SCHEMA = {
|
|
|
137
138
|
required: ["summary"],
|
|
138
139
|
additionalProperties: false
|
|
139
140
|
};
|
|
140
|
-
/** Writes each passage with a one-shot
|
|
141
|
-
function
|
|
141
|
+
/** Writes each passage with a one-shot child of the game master that has the chronicler's persona and no tools of its own. */
|
|
142
|
+
function childChronicler(parent, settings) {
|
|
143
|
+
const language = settings.prompts.language;
|
|
142
144
|
return { async write({ task, material, words }, signal) {
|
|
143
|
-
const
|
|
145
|
+
const estimate = tokensOf(words * (language.toLowerCase().startsWith("zh") ? 1 : 6), language) + 8;
|
|
146
|
+
return (await runChild({
|
|
144
147
|
parent,
|
|
145
148
|
signal,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
text: `${task}\n\nWrite at most ${words} words.\n\n${material}`
|
|
150
|
-
}],
|
|
149
|
+
reasoningEffort: settings.reasoning.children,
|
|
150
|
+
sampling: childSampling(settings, "records", estimate),
|
|
151
|
+
...childModel(settings, "records"),
|
|
151
152
|
persona: promptFor(parent, "roleplay/chronicler", language),
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (result.stopReason !== "completed") throw new Error(`the chronicler did not finish (${result.stopReason})`);
|
|
158
|
-
const text = result.structured?.summary;
|
|
159
|
-
if (typeof text !== "string" || text.trim() === "") throw new Error("the chronicler wrote nothing");
|
|
160
|
-
return text;
|
|
161
|
-
} finally {
|
|
162
|
-
await run.dispose();
|
|
163
|
-
}
|
|
153
|
+
prompt: `${task}\n\nWrite at most ${words} words.\n\n${material}`,
|
|
154
|
+
result: SUMMARY_SCHEMA,
|
|
155
|
+
beforeSubmit: (value) => value.summary?.trim() === "" ? "the passage is empty: write it" : void 0,
|
|
156
|
+
maxCalls: 3
|
|
157
|
+
})).summary;
|
|
164
158
|
} };
|
|
165
159
|
}
|
|
166
160
|
//#endregion
|
|
@@ -299,8 +293,9 @@ var RoleplayCompaction = class extends BasicCompactionEngine {
|
|
|
299
293
|
const fold = this.folds.get(agent.session.id);
|
|
300
294
|
if (fold === void 0) return super.summarize(input, agent, signal);
|
|
301
295
|
const story = this.ctx.roleplayState.openSession(this.sessionsDir(), fold.id);
|
|
302
|
-
const
|
|
303
|
-
const
|
|
296
|
+
const settings = liveSettings(fold.folder);
|
|
297
|
+
const { context, prompts } = settings;
|
|
298
|
+
const chronicler = childChronicler(agent, settings);
|
|
304
299
|
const { playerInputs, transcript } = readFolded(input.messages);
|
|
305
300
|
await foldSummaries({
|
|
306
301
|
story,
|
package/lib/doctor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as chatSessionId } from "./access-EbNdZFbk.js";
|
|
2
|
-
import { a as liveSettings } from "./narration-
|
|
3
|
-
import { i as externalTools, t as externalToolLimit } from "./hooks-
|
|
2
|
+
import { a as liveSettings } from "./narration-_dA9oIt2.js";
|
|
3
|
+
import { i as externalTools, t as externalToolLimit } from "./hooks-BLperIIB.js";
|
|
4
4
|
import { n as doctorSessionOf } from "./doctor-chat-ByDfCMeo.js";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { existsSync } from "node:fs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as mediaTypeOf, h as writeImageFileMetadata, m as sidecarOf, p as readImageFileMetadata, r as LIBRARY_FOLDER, v as mapLimit } from "./library-
|
|
1
|
+
import { f as mediaTypeOf, h as writeImageFileMetadata, m as sidecarOf, p as readImageFileMetadata, r as LIBRARY_FOLDER, v as mapLimit } from "./library-DsDc6fQa.js";
|
|
2
2
|
import { join, sep } from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { lstat, mkdir, readFile, readdir, realpath, rename, stat, writeFile } from "node:fs/promises";
|
|
@@ -192,4 +192,4 @@ async function updateImage(sessionFolder, path, update) {
|
|
|
192
192
|
//#endregion
|
|
193
193
|
export { updateImage as i, galleryFile as n, listGallery as r, describeGalleryImage as t };
|
|
194
194
|
|
|
195
|
-
//# sourceMappingURL=gallery-
|
|
195
|
+
//# sourceMappingURL=gallery-C7VOJ3xH.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as referenceImagePath, l as sceneImagePath, u as writeImage } from "./library-
|
|
1
|
+
import { c as referenceImagePath, l as sceneImagePath, u as writeImage } from "./library-DsDc6fQa.js";
|
|
2
2
|
//#region src/host/images/generator.ts
|
|
3
3
|
const unique = (values) => [...new Set(values.map((value) => value.trim()).filter((value) => value !== ""))];
|
|
4
4
|
/** What a reference image shows: the subject and its stable look. */
|
|
@@ -142,4 +142,4 @@ async function generateTransientImage(service, request) {
|
|
|
142
142
|
//#endregion
|
|
143
143
|
export { uploadReferenceImage as a, transientPrompt as i, generateTransientImage as n, referencePrompt as r, generateReferenceImage as t };
|
|
144
144
|
|
|
145
|
-
//# sourceMappingURL=generator-
|
|
145
|
+
//# sourceMappingURL=generator-CO8usAjE.js.map
|
package/lib/helper.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { a as helpers } from "./child-D5SVNk4O.js";
|
|
2
|
+
//#region src/helper.ts
|
|
3
|
+
const name = "@dsh-agentic-roleplay/core/helper";
|
|
4
|
+
const inject = ["tools", "systemPrompt"];
|
|
5
|
+
/**
|
|
6
|
+
* The preset every helper agent (a character, the record keeper, the author, the chronicler) runs under. The preset is shared by all of them, so what is
|
|
7
|
+
* one child's is found by its session id: its persona, and the equipment its caller set up for it when it was created.
|
|
8
|
+
*/
|
|
9
|
+
function apply(ctx) {
|
|
10
|
+
ctx.systemPrompt.section({
|
|
11
|
+
name: "ROLEPLAY_HELPER_PERSONA",
|
|
12
|
+
order: ctx.systemPrompt.getSectionOrder("DEPLOYMENT_PERSONA_PREFIX"),
|
|
13
|
+
interpolate: false,
|
|
14
|
+
text: (context) => {
|
|
15
|
+
const agent = context.agent;
|
|
16
|
+
return agent === void 0 ? "" : helpers.get(agent.session.id)?.persona ?? "";
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
ctx.on("agent/created", ({ agent }) => {
|
|
20
|
+
helpers.get(agent.session.id)?.setup(agent);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { apply, inject, name };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { r as roleplaySessionOf, t as promptFor } from "./access-EbNdZFbk.js";
|
|
2
|
-
import { a as liveSettings, m as rulesOf, n as encodeOutput, p as WORLD_RULES_KEY, r as encodePreview } from "./narration-
|
|
3
|
-
import {
|
|
2
|
+
import { _ as emptyStats, a as liveSettings, h as DECISION_SITES, m as rulesOf, n as encodeOutput, p as WORLD_RULES_KEY, r as encodePreview } from "./narration-_dA9oIt2.js";
|
|
3
|
+
import { t as trimCharacters } from "./text-CT1re6XT.js";
|
|
4
|
+
import { d as NO_TOKENS, f as addTokens, i as childTrace, m as estimateAnswer, n as childSampling, o as runChild, t as childModel, u as tokensOf } from "./child-D5SVNk4O.js";
|
|
4
5
|
import { dirname, join } from "node:path";
|
|
5
6
|
import { copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
7
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
@@ -1462,6 +1463,61 @@ function forgetRunDetails(folder, dropped) {
|
|
|
1462
1463
|
for (const entry of dropped) if (entry.run !== void 0) rmSync(runFile(folder, entry.run), { force: true });
|
|
1463
1464
|
}
|
|
1464
1465
|
//#endregion
|
|
1466
|
+
//#region src/host/decisions/stats.ts
|
|
1467
|
+
const DECISIONS_FILE = "decisions.json";
|
|
1468
|
+
const isSite = (value) => typeof value === "object" && value !== null && [
|
|
1469
|
+
"runs",
|
|
1470
|
+
"items",
|
|
1471
|
+
"decided",
|
|
1472
|
+
"escalated",
|
|
1473
|
+
"fallbacks",
|
|
1474
|
+
"agreed",
|
|
1475
|
+
"disagreed",
|
|
1476
|
+
"decisionMs",
|
|
1477
|
+
"llmMs"
|
|
1478
|
+
].every((field) => typeof value[field] === "number") && Array.isArray(value.samples);
|
|
1479
|
+
/**
|
|
1480
|
+
* What was kept about the story's decisions. The file only holds measurements, so one that cannot be read is
|
|
1481
|
+
* started again, not a reason to stop the story.
|
|
1482
|
+
*/
|
|
1483
|
+
function readDecisionStats(folder, now = () => /* @__PURE__ */ new Date()) {
|
|
1484
|
+
let value;
|
|
1485
|
+
try {
|
|
1486
|
+
value = JSON.parse(readFileSync(join(folder, DECISIONS_FILE), "utf8"));
|
|
1487
|
+
} catch {
|
|
1488
|
+
return emptyStats(now().toISOString());
|
|
1489
|
+
}
|
|
1490
|
+
const given = value;
|
|
1491
|
+
const fresh = emptyStats(typeof given?.since === "string" ? given.since : now().toISOString());
|
|
1492
|
+
for (const site of DECISION_SITES) {
|
|
1493
|
+
const entry = given?.sites?.[site];
|
|
1494
|
+
if (isSite(entry)) fresh.sites[site] = entry;
|
|
1495
|
+
}
|
|
1496
|
+
return fresh;
|
|
1497
|
+
}
|
|
1498
|
+
/** Adds one run of a site to what is kept; the file is written aside and renamed, and stays beside the database, so putting the story back does not change it. */
|
|
1499
|
+
function recordDecisions(folder, site, report, now = () => /* @__PURE__ */ new Date()) {
|
|
1500
|
+
const stats = readDecisionStats(folder, now);
|
|
1501
|
+
const kept = stats.sites[site];
|
|
1502
|
+
stats.sites[site] = {
|
|
1503
|
+
runs: kept.runs + 1,
|
|
1504
|
+
items: kept.items + report.items,
|
|
1505
|
+
decided: kept.decided + report.decided,
|
|
1506
|
+
escalated: kept.escalated + report.escalated,
|
|
1507
|
+
fallbacks: kept.fallbacks + report.fallbacks,
|
|
1508
|
+
agreed: kept.agreed + report.agreed,
|
|
1509
|
+
disagreed: kept.disagreed + report.disagreed,
|
|
1510
|
+
decisionMs: kept.decisionMs + report.decisionMs,
|
|
1511
|
+
llmMs: kept.llmMs + report.llmMs,
|
|
1512
|
+
samples: [...kept.samples, ...report.samples].slice(-20),
|
|
1513
|
+
...report.problem === void 0 ? {} : { problem: report.problem }
|
|
1514
|
+
};
|
|
1515
|
+
const target = join(folder, DECISIONS_FILE);
|
|
1516
|
+
const aside = `${target}.writing`;
|
|
1517
|
+
writeFileSync(aside, JSON.stringify(stats, null, 2));
|
|
1518
|
+
renameSync(aside, target);
|
|
1519
|
+
}
|
|
1520
|
+
//#endregion
|
|
1465
1521
|
//#region src/host/sessions/usage.ts
|
|
1466
1522
|
const KEY = "usage";
|
|
1467
1523
|
const isCount = (value) => typeof value === "object" && value !== null && [
|
|
@@ -2197,6 +2253,9 @@ function storeOf(session, folder, problem, queryVector, wall, prompt) {
|
|
|
2197
2253
|
forgetRunDetails(folder, recordActivity(session, entry));
|
|
2198
2254
|
if (entry.turn !== void 0 && entry.tokens !== void 0) addUsage(session, entry.turn, "helper", entry.tokens);
|
|
2199
2255
|
},
|
|
2256
|
+
recordDecisions: (site, report) => {
|
|
2257
|
+
recordDecisions(folder, site, report);
|
|
2258
|
+
},
|
|
2200
2259
|
recordUsage: (turn, tokens) => {
|
|
2201
2260
|
addUsage(session, turn, "master", tokens);
|
|
2202
2261
|
},
|
|
@@ -3410,9 +3469,10 @@ function createTools$1(deps) {
|
|
|
3410
3469
|
}]
|
|
3411
3470
|
},
|
|
3412
3471
|
isConcurrencySafe: () => false,
|
|
3413
|
-
execute(args, exec) {
|
|
3472
|
+
async execute(args, exec) {
|
|
3414
3473
|
const { owner } = ownerOf(exec.agent);
|
|
3415
|
-
|
|
3474
|
+
await deps.engine.checkRules(owner, args.allowed);
|
|
3475
|
+
return record(deps.engine.judge(owner, args.allowed, args.reason, args.at, args.uncertain));
|
|
3416
3476
|
}
|
|
3417
3477
|
}),
|
|
3418
3478
|
preview,
|
|
@@ -3606,7 +3666,10 @@ function installHooks(ctx, deps) {
|
|
|
3606
3666
|
cast
|
|
3607
3667
|
}) : { ok: true };
|
|
3608
3668
|
if (ooc !== void 0 && ooc.request !== "") engine.beginOoc(owner, ooc.request, ooc.question);
|
|
3609
|
-
else if (ooc === void 0)
|
|
3669
|
+
else if (ooc === void 0) {
|
|
3670
|
+
engine.expectJudgement(owner);
|
|
3671
|
+
engine.noteInput(owner, text);
|
|
3672
|
+
}
|
|
3610
3673
|
const queryVector = await store.queryVector(ooc?.request ?? text);
|
|
3611
3674
|
store.clearNotes();
|
|
3612
3675
|
store.lapseNotes(payload.turn);
|
|
@@ -3689,6 +3752,6 @@ function installHooks(ctx, deps) {
|
|
|
3689
3752
|
});
|
|
3690
3753
|
}
|
|
3691
3754
|
//#endregion
|
|
3692
|
-
export {
|
|
3755
|
+
export { listFiles as $, answerLimits as A, loadPlots as B, readNotes as C, describeWhen as D, describeTime as E, STORY_LANGUAGES as F, formatIssue as G, plotReferenceProblems as H, isStoryLanguage as I, PROMPTS_FOLDER as J, errorMessage as K, textLanguage as L, plotProgressOf as M, populatePlots as N, zoneOf as O, LANGUAGE_NAMES as P, languageOf as Q, wrongLanguage as R, notesOfSession as S, ClockError as T, readDocument as U, parsePlotsFile as V, Reader as W, copyWorldPrompts as X, PromptLibrary as Y, inheritPrompts as Z, readRunDetail as _, externalWithheld as a, InvalidWorldError as at, readWithdrawn as b, record as c, SessionNotFoundError as ct, toolEnabled as d, translator as dt, promptProblem as et, MAX_OOC_ANSWER as f, readActivity as g, readDecisionStats as h, externalTools as i, InvalidStartError as it, PLOTS_METADATA_KEY as j, RESULTS as k, AUTHORING_NEEDS as l, WorldNotFoundError as lt, readUsage as m, installHooks as n, shippedPromptsDirectory as nt, PREVIEW_TOOL as o, ReflectionRefusedError as ot, storesOf as p, LANGUAGE_FOLDER as q, externalGiven as r, AgentUnavailableError as rt, createTools$1 as s, SessionArchivedError as st, externalToolLimit as t, shippedLanguages as tt, characterRunner as u, languageOf$1 as ut, readVerdicts as v, observeAsPlayer as w, addToNote as x, writeVerdicts as y, PLOTS_FILE_NAME as z };
|
|
3693
3756
|
|
|
3694
|
-
//# sourceMappingURL=hooks-
|
|
3757
|
+
//# sourceMappingURL=hooks-BLperIIB.js.map
|
package/lib/images.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as withPngMetadata, a as inheritImages, c as referenceImagePath, g as readPngMetadata, i as entityImageDirectory, l as sceneImagePath, o as nextSceneSerial, s as readImageMetadata, t as addToLibrary } from "./library-
|
|
2
|
-
import { i as transientPrompt, n as generateTransientImage, r as referencePrompt, t as generateReferenceImage } from "./generator-
|
|
3
|
-
import { i as updateImage, r as listGallery } from "./gallery-
|
|
4
|
-
import { a as tokensOf, i as searchImages, n as interpretImage, o as present, r as imageTools, s as presentedFor, t as runImagePresenter } from "./presenter-agent-
|
|
1
|
+
import { _ as withPngMetadata, a as inheritImages, c as referenceImagePath, g as readPngMetadata, i as entityImageDirectory, l as sceneImagePath, o as nextSceneSerial, s as readImageMetadata, t as addToLibrary } from "./library-DsDc6fQa.js";
|
|
2
|
+
import { i as transientPrompt, n as generateTransientImage, r as referencePrompt, t as generateReferenceImage } from "./generator-CO8usAjE.js";
|
|
3
|
+
import { i as updateImage, r as listGallery } from "./gallery-C7VOJ3xH.js";
|
|
4
|
+
import { a as tokensOf, i as searchImages, n as interpretImage, o as present, r as imageTools, s as presentedFor, t as runImagePresenter } from "./presenter-agent-BHSbyWwZ.js";
|
|
5
5
|
export { addToLibrary, entityImageDirectory, generateReferenceImage, generateTransientImage, imageTools, inheritImages, interpretImage, listGallery, nextSceneSerial, present, presentedFor, readImageMetadata, readPngMetadata, referenceImagePath, referencePrompt, runImagePresenter, sceneImagePath, searchImages, tokensOf, transientPrompt, updateImage, withPngMetadata };
|
package/lib/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { n as chatSessionId, r as roleplaySessionOf } from "./access-EbNdZFbk.js";
|
|
2
|
-
import { B as loadItems, Bt as ImportCardError, C as populateLocations, D as populateVariables, E as populateTriggers, Et as writeLorebookEntry, F as loadCalendar, Ft as parseLoreEdit, Gt as LORE_SCOPES, Ht as pictureOf, I as parseCalendarFile, It as parsePlaceEdit, J as withPlayer, Jt as DICE_RESULTS, Kt as DICE_COMPARISONS, Lt as parseRelationEdit, M as loadDice, Mt as InvalidEditProblems, N as parseDiceFile, Nt as parseCharacterEdit, O as routineProblems, P as CALENDAR_FILE_NAME, Pt as parseFactionEdit, Q as variableProblems, R as loadLocations, Rt as parseThingEdit, S as populateKnowledge, St as lorebookDirectory, T as populateRoutines, Tt as updateLorebookInfo, U as CHARACTERS_DIR, Ut as readCard, Vt as isPng, W as loadCharacters, Wt as LORE_KINDS, X as loadVariables, Y as VARIABLES_FILE_NAME, Z as parseVariablesFile, _ as populateCharacters, _t as deleteLorebookEntry, at as CHARACTER_FILE_NAME, b as populateFactions, bt as listLorebooks, ct as ImportNotFoundError, d as markReady, dt as WORLD_FILE_NAME, f as guardedLookup, ft as parseWorldFile, g as populateCalendar, gt as deleteLorebook, h as knowsCharacter, ht as createLorebook, j as DICE_FILE_NAME, jt as subfolders, k as TRIGGERS_FILE_NAME, l as authoringChatSessionId, lt as ImportStore, m as loadValidatedWorld, mt as addLorebookEntries, ot as parseCharacterFile, p as vetUrl, pt as parseWorldInfoEdit, q as partsOf, qt as DICE_READINGS, st as IMPORT_FOLDER, t as AuthoringTools, ut as parseChoices, v as populateClock, vt as entriesOf, w as populateLore, wt as reserveLorebook, x as populateItems, xt as loadLorebook, y as populateDice, yt as isLorebookName, zt as IMPORT_COMMAND } from "./authoring-tools-
|
|
3
|
-
import { _ as readWorldPrompt, a as isPresetName, c as presetDirectory, d as savePresetFromWorld, g as listWorldPrompts, h as deleteWorldPrompt, i as deletePreset, o as listPresets, p as updatePresetInfo, r as createPresetFromShipped, s as loadPreset, t as PRESET_FILE, u as reservePreset, v as writeWorldPrompt } from "./presets-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { n as
|
|
11
|
-
import {
|
|
12
|
-
import { a as
|
|
2
|
+
import { B as loadItems, Bt as ImportCardError, C as populateLocations, D as populateVariables, E as populateTriggers, Et as writeLorebookEntry, F as loadCalendar, Ft as parseLoreEdit, Gt as LORE_SCOPES, Ht as pictureOf, I as parseCalendarFile, It as parsePlaceEdit, J as withPlayer, Jt as DICE_RESULTS, Kt as DICE_COMPARISONS, Lt as parseRelationEdit, M as loadDice, Mt as InvalidEditProblems, N as parseDiceFile, Nt as parseCharacterEdit, O as routineProblems, P as CALENDAR_FILE_NAME, Pt as parseFactionEdit, Q as variableProblems, R as loadLocations, Rt as parseThingEdit, S as populateKnowledge, St as lorebookDirectory, T as populateRoutines, Tt as updateLorebookInfo, U as CHARACTERS_DIR, Ut as readCard, Vt as isPng, W as loadCharacters, Wt as LORE_KINDS, X as loadVariables, Y as VARIABLES_FILE_NAME, Z as parseVariablesFile, _ as populateCharacters, _t as deleteLorebookEntry, at as CHARACTER_FILE_NAME, b as populateFactions, bt as listLorebooks, ct as ImportNotFoundError, d as markReady, dt as WORLD_FILE_NAME, f as guardedLookup, ft as parseWorldFile, g as populateCalendar, gt as deleteLorebook, h as knowsCharacter, ht as createLorebook, j as DICE_FILE_NAME, jt as subfolders, k as TRIGGERS_FILE_NAME, l as authoringChatSessionId, lt as ImportStore, m as loadValidatedWorld, mt as addLorebookEntries, ot as parseCharacterFile, p as vetUrl, pt as parseWorldInfoEdit, q as partsOf, qt as DICE_READINGS, st as IMPORT_FOLDER, t as AuthoringTools, ut as parseChoices, v as populateClock, vt as entriesOf, w as populateLore, wt as reserveLorebook, x as populateItems, xt as loadLorebook, y as populateDice, yt as isLorebookName, zt as IMPORT_COMMAND } from "./authoring-tools-BGzzW6O5.js";
|
|
3
|
+
import { _ as readWorldPrompt, a as isPresetName, c as presetDirectory, d as savePresetFromWorld, g as listWorldPrompts, h as deleteWorldPrompt, i as deletePreset, o as listPresets, p as updatePresetInfo, r as createPresetFromShipped, s as loadPreset, t as PRESET_FILE, u as reservePreset, v as writeWorldPrompt } from "./presets-DcPCnn8O.js";
|
|
4
|
+
import { _ as readTimeline, d as TimelineError, g as switchPreset, h as recordPreset, i as reflectionStatus, m as presetStatus, p as copyPreset, v as pathTo, y as defaultBoundaries } from "./reflection-6qfOC5OT.js";
|
|
5
|
+
import { a as liveSettings, b as VARIABLE_VISIBILITIES, c as writeSettings, d as parseSettings, i as InvalidSettingsError, l as DEFAULT_SETTINGS, n as encodeOutput, o as readSettings, p as WORLD_RULES_KEY, s as useChildReasoning, u as SETTINGS_SPEC, v as VARIABLE_KINDS, y as VARIABLE_SUBJECTS } from "./narration-_dA9oIt2.js";
|
|
6
|
+
import { C as readNotes, G as formatIssue, H as plotReferenceProblems, K as errorMessage, M as plotProgressOf, N as populatePlots, O as zoneOf, Q as languageOf, S as notesOfSession, U as readDocument, V as parsePlotsFile, X as copyWorldPrompts, Y as PromptLibrary, _ as readRunDetail, at as InvalidWorldError, b as readWithdrawn, ct as SessionNotFoundError, g as readActivity, h as readDecisionStats, i as externalTools, it as InvalidStartError, j as PLOTS_METADATA_KEY, lt as WorldNotFoundError, m as readUsage, ot as ReflectionRefusedError, rt as AgentUnavailableError, st as SessionArchivedError, tt as shippedLanguages, w as observeAsPlayer, x as addToNote } from "./hooks-BLperIIB.js";
|
|
7
|
+
import { t as trimCharacters } from "./text-CT1re6XT.js";
|
|
8
|
+
import { c as parseSampling, l as sharedSamplingOf, r as childSamplingOf } from "./child-D5SVNk4O.js";
|
|
9
|
+
import { a as inheritImages, b as slug, c as referenceImagePath, l as sceneImagePath, t as addToLibrary, x as uniqueKey } from "./library-DsDc6fQa.js";
|
|
10
|
+
import { A as worldEntityImageFile, B as readWorldInfo, C as readWorldEditor, D as uploadWorldCharacterPortrait, E as replaceFile, F as loadWorldParts, I as PRESET_FILE$1, L as presetMessage, O as uploadWorldEntityImage, S as generateWorldEntityImage, T as removeWorldTrigger, U as languageOfDocuments, V as translateMessage, W as readWorldDocuments, _ as editWorldPlots$1, a as deleteWorldPackFile, b as entityFolder, c as createAuthoredEntity, f as editWorldCharacter$1, g as editWorldPlace$1, h as editWorldNarrationVoice, j as writeWorldTrigger, k as worldCharacterPortraitFile, l as deleteAuthoredEntity, m as editWorldLore$1, n as packFileProblem, p as editWorldFaction$1, t as MAX_PACK_TEXT, u as readAuthoredEntityDocument, v as editWorldRelation$1, w as readWorldTrigger, x as generateWorldCharacterPortrait, y as editWorldThing$1, z as editWorldInfo } from "./pack-jail-BKFmbYP8.js";
|
|
11
|
+
import { n as readPreset, r as selectPrompts, t as previewPreset } from "./preset-CJLW8Mp0.js";
|
|
12
|
+
import { a as lorebookImportMessage, d as selectEntries, l as previewLorebook, s as lorebookChatSessionId, t as LOREBOOK_UPLOAD, u as readLorebook } from "./lorebook-author-tools-C-cFiE6E.js";
|
|
13
|
+
import { a as presetChatSessionId, n as narrationImportMessage } from "./preset-author-tools-1RstgEZs.js";
|
|
13
14
|
import { t as doctorChatSessionId } from "./doctor-chat-ByDfCMeo.js";
|
|
14
|
-
import { _ as API_PREFIX, a as packIds, c as describePack, d as packPath, f as readPack, l as isPackId, m as PACK_LIMITS, n as anyTab, o as syncWorldPacks, r as copyWorldPacks, s as worldPackStates, t as activePack, u as packFile } from "./packs-
|
|
15
|
-
import { a as uploadReferenceImage, t as generateReferenceImage } from "./generator-
|
|
16
|
-
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-
|
|
15
|
+
import { _ as API_PREFIX, a as packIds, c as describePack, d as packPath, f as readPack, l as isPackId, m as PACK_LIMITS, n as anyTab, o as syncWorldPacks, r as copyWorldPacks, s as worldPackStates, t as activePack, u as packFile } from "./packs-ZTG7fWut.js";
|
|
16
|
+
import { a as uploadReferenceImage, t as generateReferenceImage } from "./generator-CO8usAjE.js";
|
|
17
|
+
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-C7VOJ3xH.js";
|
|
17
18
|
import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from "node:path";
|
|
18
19
|
import { cpSync, createReadStream, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
19
20
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
@@ -215,20 +216,30 @@ const AGENT_PRESET = "roleplay";
|
|
|
215
216
|
async function isStored(persistence, sessionId) {
|
|
216
217
|
return persistence?.stat !== void 0 && await persistence.stat(SessionId(sessionId)) !== void 0;
|
|
217
218
|
}
|
|
218
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* Make sure one named preset chat belongs to its project, and only name it on first creation. DSH's `create` reuses a stored chat only while
|
|
221
|
+
* it has no turn and mints another id otherwise, so a chat that exists is never created again: one that is stored (it holds an opening) is
|
|
222
|
+
* attached to the project, and only a chat that does not exist is created.
|
|
223
|
+
*/
|
|
219
224
|
async function ensureAgentChat(services, request, knownProject) {
|
|
220
225
|
const project = knownProject ?? await services.registry.create(request.projectPath, request.projectTitle);
|
|
221
226
|
const existed = project.sessionIds.includes(request.sessionId);
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
if (!existed) {
|
|
228
|
+
if (await isStored(services.persistence, request.sessionId)) await project.attachSession(request.sessionId);
|
|
229
|
+
else {
|
|
230
|
+
const { sessionId } = await services.controller.create({
|
|
231
|
+
workspaceId: project.id,
|
|
232
|
+
sessionId: request.sessionId,
|
|
233
|
+
agentPreset: request.agentPreset
|
|
234
|
+
});
|
|
235
|
+
if (sessionId !== request.sessionId) throw new Error(`DSH made the chat "${sessionId}" instead of "${request.sessionId}", so the chat cannot be found again`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
227
238
|
if (!existed || request.renameExisting === true) await services.controller.rename({
|
|
228
|
-
sessionId,
|
|
239
|
+
sessionId: request.sessionId,
|
|
229
240
|
title: request.title
|
|
230
241
|
});
|
|
231
|
-
return sessionId;
|
|
242
|
+
return request.sessionId;
|
|
232
243
|
}
|
|
233
244
|
/** Looks the services up on first use: profiles without the web app do not have them. */
|
|
234
245
|
function agentServicesOf(ctx) {
|
|
@@ -3884,6 +3895,14 @@ function createApiHandler({ catalogue, worlds, createWorld, starter, authorWorld
|
|
|
3884
3895
|
throw error;
|
|
3885
3896
|
}
|
|
3886
3897
|
} },
|
|
3898
|
+
"/sessions/decisions": { GET: async (_req, res, url) => {
|
|
3899
|
+
try {
|
|
3900
|
+
sendJson(res, 200, sessions.decisions(url.searchParams.get("id") ?? ""));
|
|
3901
|
+
} catch (error) {
|
|
3902
|
+
if (error instanceof SessionNotFoundError) return sendError(res, 404, error.message);
|
|
3903
|
+
throw error;
|
|
3904
|
+
}
|
|
3905
|
+
} },
|
|
3887
3906
|
"/sessions/notes": { GET: async (_req, res, url) => {
|
|
3888
3907
|
try {
|
|
3889
3908
|
sendJson(res, 200, sessions.notes(url.searchParams.get("id") ?? ""));
|
|
@@ -5931,6 +5950,25 @@ function readInterventions(session) {
|
|
|
5931
5950
|
});
|
|
5932
5951
|
}
|
|
5933
5952
|
//#endregion
|
|
5953
|
+
//#region src/host/decisions/status.ts
|
|
5954
|
+
/**
|
|
5955
|
+
* Whether a decision service is there, which one, and what was kept about how the story's decisions went.
|
|
5956
|
+
* @throws {SessionNotFoundError} for an id that names no session.
|
|
5957
|
+
*/
|
|
5958
|
+
function decisionsOfSession(deps, id) {
|
|
5959
|
+
const sessions = deps.sessionsDir();
|
|
5960
|
+
if (!isSessionId(id) || !existsSync(sessionDatabase(sessions, id))) throw new SessionNotFoundError(`no session "${id}"`);
|
|
5961
|
+
const service = deps.service();
|
|
5962
|
+
return {
|
|
5963
|
+
available: service !== void 0,
|
|
5964
|
+
...service === void 0 ? {} : {
|
|
5965
|
+
provider: service.provider,
|
|
5966
|
+
model: service.model
|
|
5967
|
+
},
|
|
5968
|
+
stats: readDecisionStats(sessionFolder(sessions, id))
|
|
5969
|
+
};
|
|
5970
|
+
}
|
|
5971
|
+
//#endregion
|
|
5934
5972
|
//#region src/host/sessions/open-session.ts
|
|
5935
5973
|
/** Make sure a session has its DSH chat, so that it can be opened. */
|
|
5936
5974
|
async function openSession(deps, id) {
|
|
@@ -7792,6 +7830,10 @@ function apply(ctx, config) {
|
|
|
7792
7830
|
if (!isSessionId(id) || !existsSync(sessionDatabase(sessions, id))) throw new SessionNotFoundError(`no session "${id}"`);
|
|
7793
7831
|
resetVectors(ctx.roleplayState.openSession(sessions, id));
|
|
7794
7832
|
},
|
|
7833
|
+
decisions: (id) => decisionsOfSession({
|
|
7834
|
+
sessionsDir: deps.sessionsDir,
|
|
7835
|
+
service: () => ctx.get("decisions")
|
|
7836
|
+
}, id),
|
|
7795
7837
|
notes: (id) => notesOfSession({
|
|
7796
7838
|
sessionsDir: deps.sessionsDir,
|
|
7797
7839
|
open: (sessionId) => ctx.roleplayState.openSession(deps.sessionsDir(), sessionId)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as withoutExtension, t as trimCharacters } from "./text-CT1re6XT.js";
|
|
2
2
|
import { dirname, extname, join } from "node:path";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
@@ -332,4 +332,4 @@ async function addToLibrary(sessionFolder, bytes, originalName) {
|
|
|
332
332
|
//#endregion
|
|
333
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 };
|
|
334
334
|
|
|
335
|
-
//# sourceMappingURL=library-
|
|
335
|
+
//# sourceMappingURL=library-DsDc6fQa.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
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-
|
|
2
|
-
import { n as createPresetFromGuidance } from "./presets-
|
|
3
|
-
import "./narration-
|
|
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-BGzzW6O5.js";
|
|
2
|
+
import { n as createPresetFromGuidance } from "./presets-DcPCnn8O.js";
|
|
3
|
+
import "./narration-_dA9oIt2.js";
|
|
4
|
+
import { nt as shippedPromptsDirectory } from "./hooks-BLperIIB.js";
|
|
5
|
+
import { b as slug, v as mapLimit, x as uniqueKey } from "./library-DsDc6fQa.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";
|
|
@@ -691,4 +691,4 @@ async function lorebookApproval(exec, next, state) {
|
|
|
691
691
|
//#endregion
|
|
692
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 };
|
|
693
693
|
|
|
694
|
-
//# sourceMappingURL=lorebook-author-tools-
|
|
694
|
+
//# sourceMappingURL=lorebook-author-tools-C-cFiE6E.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { St as lorebookDirectory, n as limitAuthoringAgents } from "./authoring-tools-
|
|
2
|
-
import "./hooks-
|
|
3
|
-
import { c as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-
|
|
1
|
+
import { St as lorebookDirectory, n as limitAuthoringAgents } from "./authoring-tools-BGzzW6O5.js";
|
|
2
|
+
import "./hooks-BLperIIB.js";
|
|
3
|
+
import { c as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-C-cFiE6E.js";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { existsSync, readdirSync } from "node:fs";
|
|
6
6
|
//#region src/lorebook-authoring.ts
|
|
@@ -132,6 +132,51 @@ const VARIABLE_VISIBILITIES = [
|
|
|
132
132
|
builtin: true
|
|
133
133
|
}));
|
|
134
134
|
//#endregion
|
|
135
|
+
//#region src/shared/decisions.ts
|
|
136
|
+
/** The places where a language model's closed-choice judgement can be given to a decision model instead, or, for the gates, a check can be made at all. */
|
|
137
|
+
const DECISION_SITES = [
|
|
138
|
+
"triggers",
|
|
139
|
+
"reflection",
|
|
140
|
+
"agency",
|
|
141
|
+
"refusal",
|
|
142
|
+
"rules",
|
|
143
|
+
"secrets"
|
|
144
|
+
];
|
|
145
|
+
/** The sites that check what the game master delivers to the player. They are off unless a chat turns one on: a check costs a request, or at least a call, in every turn. */
|
|
146
|
+
const GATE_SITES = ["agency", "refusal"];
|
|
147
|
+
const EXTRA_MODES = ["off", "on"];
|
|
148
|
+
/**
|
|
149
|
+
* Who makes a site's judgements.
|
|
150
|
+
* - `llm`: the language model, as before.
|
|
151
|
+
* - `decision`: the decision model alone; a judgement it is not confident of counts as "no".
|
|
152
|
+
* - `hybrid`: the decision model where it is confident, the language model for the rest.
|
|
153
|
+
* - `shadow`: both, acting on the language model's answer and recording whether the decision model agreed.
|
|
154
|
+
*/
|
|
155
|
+
const DECISION_MODES = [
|
|
156
|
+
"llm",
|
|
157
|
+
"decision",
|
|
158
|
+
"hybrid",
|
|
159
|
+
"shadow"
|
|
160
|
+
];
|
|
161
|
+
/** What a gate can be set to: the modes of any site, or off. */
|
|
162
|
+
const GATE_MODES = ["off", ...DECISION_MODES];
|
|
163
|
+
const emptySiteStats = () => ({
|
|
164
|
+
runs: 0,
|
|
165
|
+
items: 0,
|
|
166
|
+
decided: 0,
|
|
167
|
+
escalated: 0,
|
|
168
|
+
fallbacks: 0,
|
|
169
|
+
agreed: 0,
|
|
170
|
+
disagreed: 0,
|
|
171
|
+
decisionMs: 0,
|
|
172
|
+
llmMs: 0,
|
|
173
|
+
samples: []
|
|
174
|
+
});
|
|
175
|
+
const emptyStats = (since) => ({
|
|
176
|
+
since,
|
|
177
|
+
sites: Object.fromEntries(DECISION_SITES.map((site) => [site, emptySiteStats()]))
|
|
178
|
+
});
|
|
179
|
+
//#endregion
|
|
135
180
|
//#region src/shared/rules.ts
|
|
136
181
|
/** The key under which a session keeps the rules of its world, which it copies at the start so that it stays whole without the world's files. */
|
|
137
182
|
const WORLD_RULES_KEY = "rules";
|
|
@@ -262,6 +307,16 @@ const SETTINGS_SPEC = {
|
|
|
262
307
|
cueTurns: integer(1, 20, 2),
|
|
263
308
|
judgedPerTurn: integer(0, 5, 2)
|
|
264
309
|
},
|
|
310
|
+
decisions: {
|
|
311
|
+
triggers: choice(DECISION_MODES, "llm"),
|
|
312
|
+
reflection: choice(DECISION_MODES, "llm"),
|
|
313
|
+
agency: choice(GATE_MODES, "off"),
|
|
314
|
+
refusal: choice(GATE_MODES, "off"),
|
|
315
|
+
rules: choice(EXTRA_MODES, "off"),
|
|
316
|
+
secrets: choice(EXTRA_MODES, "off"),
|
|
317
|
+
gateThreshold: ratio(.1, .95, .5),
|
|
318
|
+
confidence: ratio(0, 1, .7)
|
|
319
|
+
},
|
|
265
320
|
interface: { pack: text(60, "") },
|
|
266
321
|
rewind: { keepSnapshots: integer(0, 500, 30) },
|
|
267
322
|
rules: { own: text(MAX_OWN_RULES, "") },
|
|
@@ -524,6 +579,6 @@ function decodeOutput(text) {
|
|
|
524
579
|
}
|
|
525
580
|
}
|
|
526
581
|
//#endregion
|
|
527
|
-
export {
|
|
582
|
+
export { emptyStats as _, liveSettings as a, VARIABLE_VISIBILITIES as b, writeSettings as c, parseSettings as d, parseSwitchboard as f, GATE_SITES as g, DECISION_SITES 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, VARIABLE_KINDS as v, VARIABLE_SUBJECTS as y };
|
|
528
583
|
|
|
529
|
-
//# sourceMappingURL=narration-
|
|
584
|
+
//# sourceMappingURL=narration-_dA9oIt2.js.map
|