@dsh-agentic-roleplay/core 0.12.0 → 0.12.1
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/{access-DAw54-NI.js → access-DifaiHrI.js} +2 -2
- package/lib/{authoring-tools-4NgDhIJV.js → authoring-tools-VOaXzr_R.js} +23 -771
- package/lib/authoring.js +135 -12
- package/lib/{child-D3QUNb3m.js → child-DzZ-aI6k.js} +10 -1
- package/lib/client.js +16162 -1902
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +3 -3
- package/lib/dev-context-Bdm-eVer.js +40 -0
- package/lib/doctor.js +5 -3
- package/lib/{gallery-Ct6nm4UQ.js → gallery-Ctz-UoFk.js} +3 -3
- package/lib/{generator-CI8fOnXy.js → generator-Cv6WWmZT.js} +2 -2
- package/lib/helper.js +4 -2
- package/lib/{hooks-BNeoGMHZ.js → hooks-BdR3mBeM.js} +33 -14
- package/lib/images.js +4 -4
- package/lib/index.js +128 -463
- package/lib/{jail-BIF79PJO.js → jail-Cp4zEfip.js} +2 -2
- package/lib/{library-BF9ZMSFz.js → library-BU2A_Dx8.js} +2 -2
- package/lib/{lorebook-author-tools-DBk-V0hp.js → lorebook-author-tools-DUKcQu8P.js} +19 -6
- package/lib/lorebook-authoring.js +12 -5
- package/lib/{narration-xvErE2yp.js → narration-CDsJ5wxH.js} +2 -2
- package/lib/orchestration.js +33 -12
- package/lib/{pack-jail-C8EyX9Ix.js → pack-jail-CzHQu0n3.js} +558 -23
- package/lib/{packs-S0SzrVv-.js → packs-BZ-45J4-.js} +2 -2
- package/lib/{presenter-agent-Bc478nTA.js → presenter-agent-C2ZkoxZu.js} +9 -9
- package/lib/{preset-SJZyw0kt.js → preset-BPnRPW-1.js} +4 -4
- package/lib/{preset-author-tools-CzogjK42.js → preset-author-tools-DBqPwn-o.js} +8 -7
- package/lib/preset-authoring.js +11 -6
- package/lib/{reflection-buQiSdvq.js → reflection-Cuy0YLv0.js} +14 -15
- package/lib/{presets-DQ5rioMh.js → serial-BZNeK57v.js} +1180 -389
- package/lib/{turn-guard-BSAba8sp.js → turn-guard-xaFxYc1T.js} +3 -3
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +33 -33
- package/prompts/en/import/style.md +2 -1
- package/prompts/en/world/procedure.md +1 -1
- package/prompts/zh/import/style.md +2 -1
- package/prompts/zh/world/procedure.md +1 -1
package/lib/compaction.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as liveSettings, t as decodeOutput } from "./narration-
|
|
2
|
-
import { j as roleplaySessionOf, k as tokensOf, l as runChild, n as childModel, r as childSampling } from "./child-
|
|
3
|
-
import { t as promptFor } from "./access-
|
|
1
|
+
import { a as liveSettings, t as decodeOutput } from "./narration-CDsJ5wxH.js";
|
|
2
|
+
import { j as roleplaySessionOf, k as tokensOf, l as runChild, n as childModel, r as childSampling } from "./child-DzZ-aI6k.js";
|
|
3
|
+
import { t as promptFor } from "./access-DifaiHrI.js";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
6
6
|
import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/host/prompts/dev-context.ts
|
|
2
|
+
/**
|
|
3
|
+
* What the Web bundle's `harness-dev-context` plugin says to every agent: where the DSH checkout is, that
|
|
4
|
+
* the harness may be inspected and extended, and what "this page" is. It orients an agent working on DSH
|
|
5
|
+
* itself. A game master, a character, an author or a doctor works on a story: the text is noise in every
|
|
6
|
+
* prompt, it names this machine's paths, and it points at the browser tab instead of the scene.
|
|
7
|
+
*
|
|
8
|
+
* `SystemPrompt` resolves a contribution by name at the nearest scope, so a registration made here — in
|
|
9
|
+
* a preset's scope — shadows the profile's registration for that preset's agents and leaves every other
|
|
10
|
+
* session in the profile as DSH made it. Only the name and order have to match; empty text contributes
|
|
11
|
+
* nothing.
|
|
12
|
+
*/
|
|
13
|
+
const SILENCED = [{
|
|
14
|
+
name: "harness:source",
|
|
15
|
+
section: "HARNESS_SOURCE",
|
|
16
|
+
context: "HARNESS_SOURCE"
|
|
17
|
+
}, {
|
|
18
|
+
name: "app:web-surface",
|
|
19
|
+
section: "WEB_SURFACE",
|
|
20
|
+
context: "WEB_SURFACE"
|
|
21
|
+
}];
|
|
22
|
+
function silenceHarnessDevContext(ctx) {
|
|
23
|
+
for (const entry of SILENCED) {
|
|
24
|
+
ctx.systemPrompt.section({
|
|
25
|
+
name: entry.name,
|
|
26
|
+
order: ctx.systemPrompt.getSectionOrder(entry.section),
|
|
27
|
+
interpolate: false,
|
|
28
|
+
text: ""
|
|
29
|
+
});
|
|
30
|
+
ctx.systemPrompt.context({
|
|
31
|
+
name: entry.name,
|
|
32
|
+
order: ctx.systemPrompt.getContextOrder(entry.context),
|
|
33
|
+
interpolate: false,
|
|
34
|
+
text: ""
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export { silenceHarnessDevContext as t };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=dev-context-Bdm-eVer.js.map
|
package/lib/doctor.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as silenceHarnessDevContext } from "./dev-context-Bdm-eVer.js";
|
|
2
|
+
import { A as chatSessionId } from "./child-DzZ-aI6k.js";
|
|
2
3
|
import { n as doctorSessionOf } from "./doctor-chat-hL1a61hp.js";
|
|
3
|
-
import { o as externalTools, t as externalToolLimit } from "./hooks-
|
|
4
|
-
import { a as liveSettings } from "./narration-
|
|
4
|
+
import { o as externalTools, t as externalToolLimit } from "./hooks-BdR3mBeM.js";
|
|
5
|
+
import { a as liveSettings } from "./narration-CDsJ5wxH.js";
|
|
5
6
|
import { join } from "node:path";
|
|
6
7
|
import { createTools, isSessionId, sessionDatabase, sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
7
8
|
import { existsSync } from "node:fs";
|
|
@@ -77,6 +78,7 @@ function doctorApproval(exec) {
|
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
80
|
function apply(ctx) {
|
|
81
|
+
silenceHarnessDevContext(ctx);
|
|
80
82
|
const sessionsDir = () => join(ctx.roleplayRoot.path, "sessions");
|
|
81
83
|
const resolve = (chat) => {
|
|
82
84
|
const id = doctorSessionOf(chat);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as atomicWrite } from "./access-
|
|
2
|
-
import { _ as writeImageFileMetadata, a as LIBRARY_FOLDER, g as sidecarOf, h as readImageFileMetadata, m as mediaTypeOf, x as mapLimit } from "./library-
|
|
1
|
+
import { n as atomicWrite } from "./access-DifaiHrI.js";
|
|
2
|
+
import { _ as writeImageFileMetadata, a as LIBRARY_FOLDER, g as sidecarOf, h as readImageFileMetadata, m as mediaTypeOf, x as mapLimit } from "./library-BU2A_Dx8.js";
|
|
3
3
|
import { join, sep } from "node:path";
|
|
4
4
|
import { lstat, readFile, readdir, realpath, stat } from "node:fs/promises";
|
|
5
5
|
// src/host/images/gallery.ts
|
|
@@ -187,4 +187,4 @@ async function updateImage(sessionFolder, path, update) {
|
|
|
187
187
|
}
|
|
188
188
|
export { updateImage as i, galleryFile as n, listGallery as r, describeGalleryImage as t };
|
|
189
189
|
|
|
190
|
-
//# sourceMappingURL=gallery-
|
|
190
|
+
//# sourceMappingURL=gallery-Ctz-UoFk.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as sceneImagePath, f as writeImage, u as referenceImagePath } from "./library-
|
|
1
|
+
import { d as sceneImagePath, f as writeImage, u as referenceImagePath } from "./library-BU2A_Dx8.js";
|
|
2
2
|
// 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. */
|
|
@@ -147,4 +147,4 @@ async function generateTransientImage(service, request) {
|
|
|
147
147
|
}
|
|
148
148
|
export { uploadReferenceImage as a, transientPrompt as i, generateTransientImage as n, referencePrompt as r, generateReferenceImage as t };
|
|
149
149
|
|
|
150
|
-
//# sourceMappingURL=generator-
|
|
150
|
+
//# sourceMappingURL=generator-Cv6WWmZT.js.map
|
package/lib/helper.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as silenceHarnessDevContext } from "./dev-context-Bdm-eVer.js";
|
|
2
|
+
import { o as helpers } from "./child-DzZ-aI6k.js";
|
|
2
3
|
import { a as workspaceOf, n as storyRoots } from "./service-mRKwpWjX.js";
|
|
3
|
-
import { t as registerFoldersJail } from "./jail-
|
|
4
|
+
import { t as registerFoldersJail } from "./jail-Cp4zEfip.js";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import { sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
6
7
|
// src/helper.ts
|
|
@@ -11,6 +12,7 @@ const inject = ["tools", "systemPrompt"];
|
|
|
11
12
|
* one child's is found by its session id: its persona, and the equipment its caller set up for it when it was created.
|
|
12
13
|
*/
|
|
13
14
|
function apply(ctx) {
|
|
15
|
+
silenceHarnessDevContext(ctx);
|
|
14
16
|
ctx.systemPrompt.section({
|
|
15
17
|
name: "ROLEPLAY_HELPER_PERSONA",
|
|
16
18
|
order: ctx.systemPrompt.getSectionOrder("DEPLOYMENT_PERSONA_PREFIX"),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as addTokens, D as finishOf, E as cutOff, O as estimateAnswer, S as NO_TOKENS, a as childTrace, b as estimateTokens, f as tracerOf, j as roleplaySessionOf, l as runChild, n as childModel, r as childSampling, u as TurnTraces, v as requestsOf, x as tokensOf, y as blockText } from "./child-
|
|
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-
|
|
3
|
-
import { t as promptFor } from "./access-
|
|
1
|
+
import { C as addTokens, D as finishOf, E as cutOff, O as estimateAnswer, S as NO_TOKENS, a as childTrace, b as estimateTokens, f as tracerOf, j as roleplaySessionOf, l as runChild, n as childModel, r as childSampling, u as TurnTraces, v as requestsOf, x as tokensOf, y as blockText } from "./child-DzZ-aI6k.js";
|
|
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-CDsJ5wxH.js";
|
|
3
|
+
import { t as promptFor } from "./access-DifaiHrI.js";
|
|
4
4
|
import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-Dfv8S8eq.js";
|
|
5
5
|
import { n as storyRoots } from "./service-mRKwpWjX.js";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
@@ -249,9 +249,11 @@ function fill(id, text, given, tag) {
|
|
|
249
249
|
return String(value);
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
+
/** Prompt text as it was written: a checkout that writes CRLF must not change what the models are sent. */
|
|
253
|
+
const textOf$1 = (path) => readFileSync(path, "utf8").replaceAll("\r\n", "\n");
|
|
252
254
|
/** A prompt as the package ships it, without a roleplay root: for code that has none, such as tests. */
|
|
253
255
|
function shippedText(id, language = "en", variables = {}) {
|
|
254
|
-
return fill(id,
|
|
256
|
+
return fill(id, textOf$1(join(shippedPromptsDirectory(), language, `${id}.md`)), variables, language);
|
|
255
257
|
}
|
|
256
258
|
function listFiles(directory, prefix = "") {
|
|
257
259
|
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
@@ -293,7 +295,7 @@ var PromptLibrary = class extends Service {
|
|
|
293
295
|
if (!existsSync(this.directory)) return [];
|
|
294
296
|
return readdirSync(this.directory, { withFileTypes: true }).filter((entry) => entry.isDirectory() && LANGUAGE.test(entry.name)).flatMap((entry) => listFiles(join(this.directory, entry.name)).flatMap((id) => {
|
|
295
297
|
const path = join(this.directory, entry.name, `${id}.md`);
|
|
296
|
-
const text =
|
|
298
|
+
const text = textOf$1(path);
|
|
297
299
|
const message = !ID.test(id) || ![entry.name, "en"].some((name) => existsSync(join(this.shipped, name, `${id}.md`))) ? void 0 : text.includes("{{") ? "holds \"{{\", which DSH reads as a variable of its own" : promptProblem(entry.name, id, text, this.shipped);
|
|
298
300
|
return message === void 0 ? [] : [{
|
|
299
301
|
path,
|
|
@@ -309,7 +311,7 @@ var PromptLibrary = class extends Service {
|
|
|
309
311
|
if (!ID.test(id)) throw new Error(`"${id}" is not a prompt id`);
|
|
310
312
|
const tag = languageOf(language);
|
|
311
313
|
const own = session === void 0 ? void 0 : this.override(id, tag, session);
|
|
312
|
-
return fill(id,
|
|
314
|
+
return fill(id, textOf$1(own ?? this.file(id, tag)), variables, tag);
|
|
313
315
|
}
|
|
314
316
|
override(id, language, session) {
|
|
315
317
|
if (!SESSION_ID.test(session)) throw new Error(`"${session}" is not a session id`);
|
|
@@ -4549,26 +4551,43 @@ function installHooks(ctx, deps) {
|
|
|
4549
4551
|
registerConditionalTools(agent, conditionsOf(agent.session.id));
|
|
4550
4552
|
applyLimit(agent, store);
|
|
4551
4553
|
});
|
|
4554
|
+
/** Where the open turn of each chat began, so its own events can be read back without walking the whole log. */
|
|
4555
|
+
const openTurns = /* @__PURE__ */ new Map();
|
|
4552
4556
|
ctx.on("session/event", (session, event) => {
|
|
4553
|
-
if (
|
|
4557
|
+
if (session.header.origin === "subagent" || roleplaySessionOf(session.id) === void 0) return;
|
|
4558
|
+
if (event.type === "turn/start") {
|
|
4559
|
+
openTurns.set(session.id, {
|
|
4560
|
+
seq: event.seq,
|
|
4561
|
+
time: event.time
|
|
4562
|
+
});
|
|
4563
|
+
return;
|
|
4564
|
+
}
|
|
4565
|
+
if (event.type !== "turn/end") return;
|
|
4554
4566
|
ctx.roleplayOrchestration.recovery.clear(session.id);
|
|
4555
4567
|
turns.end(session.id);
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
const
|
|
4568
|
+
const began = openTurns.get(session.id);
|
|
4569
|
+
openTurns.delete(session.id);
|
|
4570
|
+
timelines.ended(session.id, session, event.seq, began === void 0 ? void 0 : began.seq);
|
|
4571
|
+
const events = session.snapshotEvents(began?.seq ?? 0);
|
|
4572
|
+
const from = began === void 0 ? events.findLastIndex((entry) => entry.type === "turn/start") : 0;
|
|
4573
|
+
if (from === -1) return;
|
|
4574
|
+
const turn = events.slice(from);
|
|
4575
|
+
const start = turn[0];
|
|
4560
4576
|
if (start?.type !== "turn/start") return;
|
|
4561
4577
|
const store = stores(session.id);
|
|
4562
|
-
store?.recordUsage?.(start.data.turn, tokensOf(
|
|
4578
|
+
store?.recordUsage?.(start.data.turn, tokensOf(turn), Math.max(0, event.time - start.time));
|
|
4563
4579
|
try {
|
|
4564
4580
|
store?.recordTrace?.(start.data.turn, {
|
|
4565
|
-
...masterTrace(
|
|
4581
|
+
...masterTrace(turn),
|
|
4566
4582
|
endedAt: event.time
|
|
4567
4583
|
});
|
|
4568
4584
|
} catch (error) {
|
|
4569
4585
|
ctx.logger.warn(`roleplay: the trace of turn ${start.data.turn} could not be kept: ${error instanceof Error ? error.message : String(error)}`);
|
|
4570
4586
|
}
|
|
4571
4587
|
});
|
|
4588
|
+
ctx.on("session/disposed", (session) => {
|
|
4589
|
+
openTurns.delete(session.id);
|
|
4590
|
+
});
|
|
4572
4591
|
ctx.on("agent/created", async ({ agent }) => {
|
|
4573
4592
|
const { header } = agent.session;
|
|
4574
4593
|
if (header.origin === "subagent" || !header.isSeeded || header.parentSession === void 0) return;
|
|
@@ -4820,4 +4839,4 @@ function installHooks(ctx, deps) {
|
|
|
4820
4839
|
}
|
|
4821
4840
|
export { inheritPrompts as $, plotProgressOf as A, parsePlotsFile as B, readNotes as C, referent as D, sameWords as E, textLanguage as F, readDocument as G, COMMANDS_KEY as H, wrongLanguage as I, errorMessage as J, Reader as K, readUsage as L, LANGUAGE_NAMES as M, STORY_LANGUAGES as N, RESULTS as O, isStoryLanguage as P, copyWorldPrompts as Q, PLOTS_FILE_NAME as R, notesOfSession as S, defaultBoundaries as T, commandFlagKey as U, plotReferenceProblems as V, commandsOf as W, PROMPTS_FOLDER as X, LANGUAGE_FOLDER as Y, PromptLibrary as Z, readTraces as _, COMPARISONS as _t, externalGiven as a, shippedText as at, readWithdrawn as b, PREVIEW_TOOL as c, InvalidWorldError as ct, toolEnabled as d, SessionNotFoundError as dt, languageOf as et, MAX_OOC_ANSWER as f, WorldNotFoundError as ft, readRunDetail as g, AUTHORING_NEEDS as gt, readActivity as h, zoneOf as ht, characterRunner as i, shippedPromptsDirectory as it, populatePlots as j, PLOTS_METADATA_KEY as k, createTools$1 as l, ReflectionRefusedError as lt, readDecisionStats as m, describeWhen as mt, installHooks as n, promptProblem as nt, externalTools as o, AgentUnavailableError as ot, storesOf as p, ClockError as pt, formatIssue as q, guardRepeatedCalls as r, shippedLanguages as rt, externalWithheld as s, InvalidStartError as st, externalToolLimit as t, listFiles as tt, record as u, SessionArchivedError as ut, readVerdicts as v, observeAsPlayer as w, addToNote as x, writeVerdicts as y, loadPlots as z };
|
|
4822
4841
|
|
|
4823
|
-
//# sourceMappingURL=hooks-
|
|
4842
|
+
//# sourceMappingURL=hooks-BdR3mBeM.js.map
|
package/lib/images.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as searchImages, c as presentedFor, n as interpretImage, o as tokensOf, r as imageTools, s as present, t as runImagePresenter } from "./presenter-agent-
|
|
2
|
-
import { i as updateImage, r as listGallery } from "./gallery-
|
|
3
|
-
import { c as nextSceneSerial, d as sceneImagePath, l as readImageMetadata, o as entityImageDirectory, s as inheritImages, t as addToLibrary, u as referenceImagePath, v as readPngMetadata, y as withPngMetadata } from "./library-
|
|
4
|
-
import { i as transientPrompt, n as generateTransientImage, r as referencePrompt, t as generateReferenceImage } from "./generator-
|
|
1
|
+
import { a as searchImages, c as presentedFor, n as interpretImage, o as tokensOf, r as imageTools, s as present, t as runImagePresenter } from "./presenter-agent-C2ZkoxZu.js";
|
|
2
|
+
import { i as updateImage, r as listGallery } from "./gallery-Ctz-UoFk.js";
|
|
3
|
+
import { c as nextSceneSerial, d as sceneImagePath, l as readImageMetadata, o as entityImageDirectory, s as inheritImages, t as addToLibrary, u as referenceImagePath, v as readPngMetadata, y as withPngMetadata } from "./library-BU2A_Dx8.js";
|
|
4
|
+
import { i as transientPrompt, n as generateTransientImage, r as referencePrompt, t as generateReferenceImage } from "./generator-Cv6WWmZT.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 };
|