@dsh-agentic-roleplay/core 0.7.0 → 0.7.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.
Files changed (40) hide show
  1. package/lib/access-DtOxFKBK.js +150 -0
  2. package/lib/{authoring-tools-BWjEr_lF.js → authoring-tools-BKltdiea.js} +160 -74
  3. package/lib/authoring.js +10 -5
  4. package/lib/{child-D5SVNk4O.js → child-CyCViUKa.js} +48 -7
  5. package/lib/client.js +1046 -606
  6. package/lib/client.js.map +1 -1
  7. package/lib/compaction.js +3 -3
  8. package/lib/doctor.js +3 -3
  9. package/lib/{gallery-C7VOJ3xH.js → gallery-BxZGOgMb.js} +2 -2
  10. package/lib/{generator-CO8usAjE.js → generator-BFmSYvR8.js} +2 -2
  11. package/lib/helper.js +1 -1
  12. package/lib/{hooks-DufjUf1p.js → hooks-HnqXO8mM.js} +6 -245
  13. package/lib/images.js +4 -4
  14. package/lib/index.js +129 -103
  15. package/lib/{library-DsDc6fQa.js → library-BGxPKs9a.js} +6 -3
  16. package/lib/{lorebook-author-tools-v-PM8Kbs.js → lorebook-author-tools-BAnUyRtS.js} +31 -28
  17. package/lib/lorebook-authoring.js +8 -3
  18. package/lib/{narration-_dA9oIt2.js → narration-DvFBqmqe.js} +9 -132
  19. package/lib/orchestration.js +11 -10
  20. package/lib/{pack-jail--Ij90LeY.js → pack-jail-DLGguGS3.js} +14 -12
  21. package/lib/{packs-DWKnL4YX.js → packs-jowC-MN_.js} +2 -2
  22. package/lib/{presenter-agent-BHSbyWwZ.js → presenter-agent-DvZtnf0Q.js} +6 -6
  23. package/lib/{preset-CDNyJhfU.js → preset-CXbC0NeU.js} +3 -3
  24. package/lib/{preset-author-tools-D7Azdlaq.js → preset-author-tools-C26kj6t5.js} +11 -10
  25. package/lib/preset-authoring.js +9 -4
  26. package/lib/{reflection-CRCWK2E1.js → reflection-CvOZGjmn.js} +9 -170
  27. package/lib/{presets-D11bxWX0.js → route-DRTJ_vcA.js} +165 -4
  28. package/lib/text-JbWfTHbr.js +295 -0
  29. package/lib/turn-guard-BvCs1VxB.js +53 -0
  30. package/package.json +2 -2
  31. package/prompts/en/import/cut-off.md +1 -0
  32. package/prompts/en/import/finish-failed.md +1 -1
  33. package/prompts/en/roleplay/decide-instruction.md +1 -0
  34. package/prompts/en/roleplay/decide-irrelevant.md +1 -0
  35. package/prompts/zh/import/cut-off.md +1 -0
  36. package/prompts/zh/import/finish-failed.md +1 -1
  37. package/prompts/zh/roleplay/decide-instruction.md +1 -0
  38. package/prompts/zh/roleplay/decide-irrelevant.md +1 -0
  39. package/lib/access-EbNdZFbk.js +0 -25
  40. package/lib/text-CT1re6XT.js +0 -18
package/lib/index.js CHANGED
@@ -1,20 +1,20 @@
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-BWjEr_lF.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-D11bxWX0.js";
4
- import { _ as readTimeline, b as defaultBoundaries, d as TimelineError, g as switchPreset, h as recordPreset, i as reflectionStatus, m as presetStatus, p as copyPreset, v as writeTimeline, y as pathTo } from "./reflection-CRCWK2E1.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, dt as translator, 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, ut as languageOf$1, w as observeAsPlayer, x as addToNote } from "./hooks-DufjUf1p.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--Ij90LeY.js";
11
- import { n as readPreset, r as selectPrompts, t as previewPreset } from "./preset-CDNyJhfU.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-v-PM8Kbs.js";
13
- import { a as presetChatSessionId, n as narrationImportMessage } from "./preset-author-tools-D7Azdlaq.js";
1
+ import { a as chatSessionId, i as VARIABLE_VISIBILITIES, n as VARIABLE_KINDS, o as roleplaySessionOf, r as VARIABLE_SUBJECTS } from "./access-DtOxFKBK.js";
2
+ import { A as loadDice, At as InvalidEditProblems, Bt as pictureOf, C as populateRoutines, Ct as updateLorebookInfo, D as TRIGGERS_FILE_NAME, E as routineProblems, Ft as parseRelationEdit, G as partsOf, Gt as DICE_READINGS, H as loadCharacters, Ht as LORE_KINDS, I as loadLocations, It as parseThingEdit, J as loadVariables, Jt as authoringChatSessionId, K as withPlayer, Kt as DICE_RESULTS, Lt as IMPORT_COMMAND, M as CALENDAR_FILE_NAME, Mt as parseFactionEdit, N as loadCalendar, Nt as parseLoreEdit, P as parseCalendarFile, Pt as parsePlaceEdit, R as loadItems, Rt as ImportCardError, S as populateLore, St as reserveLorebook, T as populateVariables, Ut as LORE_SCOPES, V as CHARACTERS_DIR, Vt as readCard, Wt as DICE_COMPARISONS, X as variableProblems, Y as parseVariablesFile, _ as populateDice, _t as isLorebookName, at as IMPORT_FOLDER, b as populateKnowledge, bt as lorebookDirectory, ct as parseChoices, d as vetUrl, dt as parseWorldInfoEdit, f as loadValidatedWorld, ft as addLorebookEntries, g as populateClock, gt as entriesOf, h as populateCharacters, ht as deleteLorebookEntry, it as parseCharacterFile, j as parseDiceFile, jt as parseCharacterEdit, k as DICE_FILE_NAME, kt as subfolders, l as markReady, lt as WORLD_FILE_NAME, m as populateCalendar, mt as deleteLorebook, ot as ImportNotFoundError, p as knowsCharacter, pt as createLorebook, q as VARIABLES_FILE_NAME, qt as authoredWorldOf, rt as CHARACTER_FILE_NAME, st as ImportStore, t as AuthoringTools, u as guardedLookup, ut as parseWorldFile, v as populateFactions, vt as listLorebooks, w as populateTriggers, wt as writeLorebookEntry, x as populateLocations, y as populateItems, yt as loadLorebook, zt as isPng } from "./authoring-tools-BKltdiea.js";
3
+ import { a as lorebookImportMessage, c as readLorebook, d as lorebookOfChat, l as selectEntries, s as previewLorebook, t as LOREBOOK_UPLOAD, u as lorebookChatSessionId } from "./lorebook-author-tools-BAnUyRtS.js";
4
+ import { a as presetChatSessionId, n as narrationImportMessage, o as presetOfChat } from "./preset-author-tools-C26kj6t5.js";
5
+ import { C as readWorldPrompt, S as listWorldPrompts, _ as savePresetFromWorld, d as isPresetName, f as listPresets, g as reservePreset, l as createPresetFromShipped, m as presetDirectory, p as loadPreset, s as PRESET_FILE, u as deletePreset, w as writeWorldPrompt, x as deleteWorldPrompt, y as updatePresetInfo } from "./route-DRTJ_vcA.js";
6
+ import { c as copyPreset, d as switchPreset, f as readTimeline, h as defaultBoundaries, i as reflectionStatus, l as presetStatus, m as pathTo, o as TimelineError, p as writeTimeline, u as recordPreset } from "./reflection-CvOZGjmn.js";
7
+ import { a as liveSettings, 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 } from "./narration-DvFBqmqe.js";
8
+ 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-HnqXO8mM.js";
9
+ import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-JbWfTHbr.js";
10
+ import { d as sharedSamplingOf, i as childSamplingOf, u as parseSampling } from "./child-CyCViUKa.js";
11
+ import { S as uniqueKey, a as inheritImages, b as slug, c as referenceImagePath, l as sceneImagePath, t as addToLibrary } from "./library-BGxPKs9a.js";
12
+ 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-DLGguGS3.js";
13
+ import { n as readPreset, r as selectPrompts, t as previewPreset } from "./preset-CXbC0NeU.js";
14
14
  import { t as doctorChatSessionId } from "./doctor-chat-ByDfCMeo.js";
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-DWKnL4YX.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";
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-jowC-MN_.js";
16
+ import { a as uploadReferenceImage, t as generateReferenceImage } from "./generator-BFmSYvR8.js";
17
+ import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-BxZGOgMb.js";
18
18
  import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from "node:path";
19
19
  import { cpSync, createReadStream, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from "node:fs";
20
20
  import { createHash, randomBytes, randomUUID } from "node:crypto";
@@ -445,10 +445,73 @@ var AuthoringLanguages = class extends Service {
445
445
  //#region src/host/import/service.ts
446
446
  /** What an import is configured to do, for the parts of the plugin that run in other scopes (the authoring chat's tools). */
447
447
  var RoleplayImport = class extends Service {
448
- settings;
449
- constructor(ctx, settings) {
448
+ read;
449
+ constructor(ctx, read) {
450
450
  super(ctx, "roleplayImport");
451
- this.settings = settings;
451
+ this.read = read;
452
+ }
453
+ /** The settings as they stand now: they are edited while the plugin runs. */
454
+ get settings() {
455
+ return this.read();
456
+ }
457
+ };
458
+ //#endregion
459
+ //#region src/host/agent/authoring-sessions.ts
460
+ const AUTHORING_PROJECT_TITLE = "World Authoring";
461
+ const AUTHORING_AGENT_PRESET = "world-authoring";
462
+ /** The title of a world's authoring chat, in the language of the person who opened it. */
463
+ function authoringTitle(worldName, language) {
464
+ return translator(languageOf$1(language))("Authoring {name}", { name: worldName });
465
+ }
466
+ /** Creates or reopens the dedicated authoring chat of an authored world, and speaks in it for the person when asked to. */
467
+ var AuthoringSessions = class {
468
+ services;
469
+ roleplayRoot;
470
+ prompts;
471
+ languages;
472
+ constructor(services, roleplayRoot, prompts, languages) {
473
+ this.services = services;
474
+ this.roleplayRoot = roleplayRoot;
475
+ this.prompts = prompts;
476
+ this.languages = languages;
477
+ }
478
+ async ensure(worldId, worldName, title, language) {
479
+ const chatTitle = title ?? authoringTitle(worldName, language);
480
+ this.languages.set(worldId, language);
481
+ const services = this.services();
482
+ const projectPath = join(this.roleplayRoot(), "worlds");
483
+ const project = await services.registry.create(projectPath, AUTHORING_PROJECT_TITLE);
484
+ const sessionId = authoringChatSessionId(worldId);
485
+ const existed = project.sessionIds.includes(sessionId);
486
+ const stored = !existed && await isStored(services.persistence, sessionId);
487
+ if (!existed && !stored) {
488
+ if (services.persistence === void 0) throw new AgentUnavailableError("this DSH profile cannot store the opening of an authoring chat");
489
+ await storeAuthoringOpening(services.persistence, {
490
+ id: sessionId,
491
+ cwd: project.path,
492
+ agentPreset: AUTHORING_AGENT_PRESET
493
+ }, this.prompts.text("world/welcome", this.languages.get(worldId), { world: worldName }));
494
+ }
495
+ return await ensureAgentChat(services, {
496
+ projectPath,
497
+ projectTitle: AUTHORING_PROJECT_TITLE,
498
+ sessionId,
499
+ agentPreset: AUTHORING_AGENT_PRESET,
500
+ title: chatTitle,
501
+ renameExisting: true
502
+ }, project);
503
+ }
504
+ /** Sends a message into a chat as if the person had written it. */
505
+ async send(sessionId, text) {
506
+ await this.services().controller.prompt({
507
+ requestId: randomUUID(),
508
+ sessionId,
509
+ mode: "queue",
510
+ content: [{
511
+ type: "text",
512
+ text
513
+ }]
514
+ }, new AbortController().signal);
452
515
  }
453
516
  };
454
517
  //#endregion
@@ -532,7 +595,7 @@ async function startImport(deps, id, choices, language) {
532
595
  if (record === void 0) throw new WorldNotFoundError(`the world "${world.name}" was made but cannot be found`);
533
596
  await deps.store.adopt(id, record.directory);
534
597
  await markReady(record.directory);
535
- const chatSessionId = await deps.authoring.ensure(world.id, world.name, deps.chatTitle(world.name), language);
598
+ const chatSessionId = await deps.authoring.ensure(world.id, world.name, authoringTitle(world.name, language), language);
536
599
  let failure;
537
600
  try {
538
601
  await deps.authoring.send(chatSessionId, importMessage(language));
@@ -608,7 +671,7 @@ async function uploadPreset(deps, worldId, file, name, language) {
608
671
  const preset = readPreset(file, name);
609
672
  await mkdir(join(world.directory, IMPORT_FOLDER), { recursive: true });
610
673
  await writeFile(join(world.directory, IMPORT_FOLDER, PRESET_FILE$1), file);
611
- const chatSessionId = await deps.authoring.ensure(world.summary.id, world.summary.name, `Authoring ${world.summary.name}`, language);
674
+ const chatSessionId = await deps.authoring.ensure(world.summary.id, world.summary.name, authoringTitle(world.summary.name, language), language);
612
675
  let failure;
613
676
  try {
614
677
  await deps.authoring.send(chatSessionId, presetMessage(language));
@@ -716,60 +779,6 @@ function parseSelectionChoice(body) {
716
779
  };
717
780
  }
718
781
  //#endregion
719
- //#region src/host/agent/authoring-sessions.ts
720
- const AUTHORING_PROJECT_TITLE = "World Authoring";
721
- const AUTHORING_AGENT_PRESET = "world-authoring";
722
- /** Creates or reopens the dedicated authoring chat of an authored world, and speaks in it for the person when asked to. */
723
- var AuthoringSessions = class {
724
- services;
725
- roleplayRoot;
726
- prompts;
727
- languages;
728
- constructor(services, roleplayRoot, prompts, languages) {
729
- this.services = services;
730
- this.roleplayRoot = roleplayRoot;
731
- this.prompts = prompts;
732
- this.languages = languages;
733
- }
734
- async ensure(worldId, worldName, title = `Authoring ${worldName}`, language) {
735
- this.languages.set(worldId, language);
736
- const services = this.services();
737
- const projectPath = join(this.roleplayRoot(), "worlds");
738
- const project = await services.registry.create(projectPath, AUTHORING_PROJECT_TITLE);
739
- const sessionId = authoringChatSessionId(worldId);
740
- const existed = project.sessionIds.includes(sessionId);
741
- const stored = !existed && await isStored(services.persistence, sessionId);
742
- if (!existed && !stored) {
743
- if (services.persistence === void 0) throw new AgentUnavailableError("this DSH profile cannot store the opening of an authoring chat");
744
- await storeAuthoringOpening(services.persistence, {
745
- id: sessionId,
746
- cwd: project.path,
747
- agentPreset: AUTHORING_AGENT_PRESET
748
- }, this.prompts.text("world/welcome", this.languages.get(worldId), { world: worldName }));
749
- }
750
- return await ensureAgentChat(services, {
751
- projectPath,
752
- projectTitle: AUTHORING_PROJECT_TITLE,
753
- sessionId,
754
- agentPreset: AUTHORING_AGENT_PRESET,
755
- title,
756
- renameExisting: true
757
- }, project);
758
- }
759
- /** Sends a message into a chat as if the person had written it. */
760
- async send(sessionId, text) {
761
- await this.services().controller.prompt({
762
- requestId: randomUUID(),
763
- sessionId,
764
- mode: "queue",
765
- content: [{
766
- type: "text",
767
- text
768
- }]
769
- }, new AbortController().signal);
770
- }
771
- };
772
- //#endregion
773
782
  //#region src/host/agent/preset-authoring-sessions.ts
774
783
  const PRESET_AUTHORING_PROJECT_TITLE = "Preset Authoring";
775
784
  const PRESET_AUTHORING_PRESET = "preset-authoring";
@@ -8603,14 +8612,18 @@ const Config = z.object({
8603
8612
  passwordRef: z.string().default(""),
8604
8613
  intervalMinutes: z.number().min(0).default(0)
8605
8614
  }).default({ ...DEFAULT_SYNC }).volatile(),
8606
- catalogueMaxBytes: z.number().min(1024).default(268435456),
8607
- catalogueTrashDays: z.number().min(0).default(30),
8608
- importMaxUploadBytes: z.number().min(1024).default(104857600),
8609
- importConcurrency: z.number().min(1).max(16).default(4),
8610
- importReasoning: z.string().default(""),
8611
- childReasoning: z.string().default(""),
8612
- importMaxTokens: z.number().min(1e3).max(2e5).default(16e3),
8613
- importTemperature: z.number().min(0).max(2).default(.2)
8615
+ catalogueMaxBytes: z.number().min(1024).default(268435456).volatile(),
8616
+ catalogueTrashDays: z.number().min(0).default(30).volatile(),
8617
+ importMaxUploadBytes: z.number().min(1024).default(104857600).volatile(),
8618
+ importConcurrency: z.number().min(1).max(16).default(4).volatile(),
8619
+ importReasoning: z.string().default("").volatile(),
8620
+ childReasoning: z.string().default("").volatile(),
8621
+ importModel: z.string().default("").volatile(),
8622
+ importMaxTokens: z.number().min(1e3).max(2e5).default(16e3).volatile(),
8623
+ importTemperature: z.number().min(0).max(2).default(.2).volatile(),
8624
+ importTimeoutMinutes: z.number().min(0).max(240).default(15).volatile(),
8625
+ importDecisions: z.union([z.const("llm"), z.const("decision")]).default("llm").volatile(),
8626
+ importConfidence: z.number().min(0).max(1).default(.7).volatile()
8614
8627
  });
8615
8628
  //#endregion
8616
8629
  //#region src/index.ts
@@ -8625,6 +8638,10 @@ function apply(ctx, config) {
8625
8638
  const id = String(options.sessionId);
8626
8639
  const helper = childSamplingOf(id);
8627
8640
  if (helper !== void 0) return helper;
8641
+ if (authoredWorldOf(id) !== void 0 || presetOfChat(id) !== void 0 || lorebookOfChat(id) !== void 0) return {
8642
+ maxTokens: config.importMaxTokens.get(),
8643
+ priority: "foreground"
8644
+ };
8628
8645
  const session = roleplaySessionOf(id);
8629
8646
  if (session === void 0) return void 0;
8630
8647
  const { sampling } = liveSettings(sessionFolder(join(root.path, "sessions"), session));
@@ -8636,7 +8653,7 @@ function apply(ctx, config) {
8636
8653
  };
8637
8654
  }), "roleplay: request controls");
8638
8655
  });
8639
- ctx.effect(() => useChildReasoning(config.childReasoning), "roleplay: helper thinking level");
8656
+ ctx.effect(() => useChildReasoning(() => config.childReasoning.get()), "roleplay: helper thinking level");
8640
8657
  const root = new RoleplayRoot(ctx, config.rootPath);
8641
8658
  root.start();
8642
8659
  const orchestration = new RoleplayOrchestration(ctx);
@@ -8654,13 +8671,19 @@ function apply(ctx, config) {
8654
8671
  const lorebookAuthoring = new LorebookAuthoringSessions(agentServicesOf(ctx), () => root.path, prompts, languages);
8655
8672
  const doctors = new DoctorSessions(agentServicesOf(ctx), () => root.path, prompts);
8656
8673
  const imports = new ImportStore(() => root.path);
8657
- const roleplayImport = new RoleplayImport(ctx, {
8658
- maxUploadBytes: config.importMaxUploadBytes,
8659
- concurrency: config.importConcurrency,
8660
- reasoning: config.importReasoning,
8661
- maxTokens: config.importMaxTokens,
8662
- temperature: config.importTemperature
8663
- });
8674
+ const roleplayImport = new RoleplayImport(ctx, () => ({
8675
+ get maxUploadBytes() {
8676
+ return config.importMaxUploadBytes.get();
8677
+ },
8678
+ concurrency: config.importConcurrency.get(),
8679
+ reasoning: config.importReasoning.get() || config.childReasoning.get(),
8680
+ model: config.importModel.get(),
8681
+ maxTokens: config.importMaxTokens.get(),
8682
+ temperature: config.importTemperature.get(),
8683
+ timeoutMinutes: config.importTimeoutMinutes.get(),
8684
+ decisions: config.importDecisions.get() === "decision" ? "decision" : "llm",
8685
+ confidence: config.importConfidence.get()
8686
+ }));
8664
8687
  const settingsDeps = {
8665
8688
  sessionsDir: () => join(root.path, "sessions"),
8666
8689
  pendingRecords: (id) => ctx.roleplayState.openSession(join(root.path, "sessions"), id).pendingCommits.list().length,
@@ -8687,7 +8710,9 @@ function apply(ctx, config) {
8687
8710
  worldDirectory: async (worldId) => (await worlds.find(worldId))?.directory,
8688
8711
  authoring: presetAuthoring,
8689
8712
  importMessage: narrationImportMessage,
8690
- maxUploadBytes: config.importMaxUploadBytes,
8713
+ get maxUploadBytes() {
8714
+ return config.importMaxUploadBytes.get();
8715
+ },
8691
8716
  staging,
8692
8717
  playing: (id) => orchestration.playing(chatSessionId(id))
8693
8718
  });
@@ -8695,7 +8720,9 @@ function apply(ctx, config) {
8695
8720
  root: () => root.path,
8696
8721
  authoring: lorebookAuthoring,
8697
8722
  importMessage: lorebookImportMessage,
8698
- maxUploadBytes: config.importMaxUploadBytes,
8723
+ get maxUploadBytes() {
8724
+ return config.importMaxUploadBytes.get();
8725
+ },
8699
8726
  staging,
8700
8727
  session: (id) => {
8701
8728
  const sessions = join(root.path, "sessions");
@@ -8707,9 +8734,9 @@ function apply(ctx, config) {
8707
8734
  const catalogue = new Catalogue({
8708
8735
  sources: new Sources(() => config.catalogues.get(), () => ctx.get("credentials")),
8709
8736
  worlds,
8710
- maxBytes: () => config.catalogueMaxBytes,
8711
- maxCardBytes: () => config.importMaxUploadBytes,
8712
- trashDays: () => config.catalogueTrashDays,
8737
+ maxBytes: () => config.catalogueMaxBytes.get(),
8738
+ maxCardBytes: () => config.importMaxUploadBytes.get(),
8739
+ trashDays: () => config.catalogueTrashDays.get(),
8713
8740
  problem: (message) => {
8714
8741
  ctx.logger.warn(message);
8715
8742
  },
@@ -8720,16 +8747,14 @@ function apply(ctx, config) {
8720
8747
  startCard: async (id, choices, language) => await startImport({
8721
8748
  store: imports,
8722
8749
  worlds,
8723
- authoring,
8724
- chatTitle: (title) => `Authoring ${title}`
8750
+ authoring
8725
8751
  }, id, choices, language),
8726
8752
  importCard: async (file, name, language) => {
8727
8753
  const preview = await imports.create(readCard(file, name), isPng(file) ? pictureOf(file) : void 0);
8728
8754
  return await startImport({
8729
8755
  store: imports,
8730
8756
  worlds,
8731
- authoring,
8732
- chatTitle: (title) => `Authoring ${title}`
8757
+ authoring
8733
8758
  }, preview.id, preview.choices, language);
8734
8759
  }
8735
8760
  });
@@ -8791,7 +8816,9 @@ function apply(ctx, config) {
8791
8816
  }, id, to, title, language)
8792
8817
  },
8793
8818
  importer: {
8794
- maxUploadBytes: config.importMaxUploadBytes,
8819
+ get maxUploadBytes() {
8820
+ return config.importMaxUploadBytes.get();
8821
+ },
8795
8822
  upload: async (file, name) => {
8796
8823
  const card = readCard(file, name);
8797
8824
  return await imports.create(card, isPng(file) ? pictureOf(file) : void 0);
@@ -8802,8 +8829,7 @@ function apply(ctx, config) {
8802
8829
  start: (id, choices, language) => startImport({
8803
8830
  store: imports,
8804
8831
  worlds,
8805
- authoring,
8806
- chatTitle: (name) => `Authoring ${name}`
8832
+ authoring
8807
8833
  }, id, choices, language),
8808
8834
  picture: (id) => imports.picture(id),
8809
8835
  uploadPreset: (worldId, file, name, language) => uploadPreset({
@@ -1,9 +1,12 @@
1
- import { n as withoutExtension, t as trimCharacters } from "./text-CT1re6XT.js";
1
+ import "./access-DtOxFKBK.js";
2
+ import { i as translator, n as withoutExtension, r as languageOf, t as trimCharacters } from "./text-JbWfTHbr.js";
2
3
  import { dirname, extname, join } from "node:path";
3
4
  import { existsSync } from "node:fs";
4
5
  import { randomUUID } from "node:crypto";
5
6
  import { copyFile, link, mkdir, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
6
7
  //#region src/host/import/run.ts
8
+ /** The labels of a job's prompt, in the language of the import. */
9
+ const trOf = (ctx) => translator(languageOf(ctx.language));
7
10
  /** Runs `work` on every item, at most `limit` at a time, and returns the results in the order of the items. */
8
11
  async function mapLimit(items, limit, work) {
9
12
  const results = new Array(items.length);
@@ -330,6 +333,6 @@ async function addToLibrary(sessionFolder, bytes, originalName) {
330
333
  return `${LIBRARY_FOLDER}/${name}`;
331
334
  }
332
335
  //#endregion
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 };
336
+ export { uniqueKey as S, 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, trOf as x, norm as y };
334
337
 
335
- //# sourceMappingURL=library-DsDc6fQa.js.map
338
+ //# sourceMappingURL=library-BGxPKs9a.js.map
@@ -1,12 +1,31 @@
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-BWjEr_lF.js";
2
- import { n as createPresetFromGuidance } from "./presets-D11bxWX0.js";
3
- import "./narration-_dA9oIt2.js";
4
- import { dt as translator, nt as shippedPromptsDirectory, ut as languageOf } from "./hooks-DufjUf1p.js";
5
- import { b as slug, v as mapLimit, x as uniqueKey } from "./library-DsDc6fQa.js";
1
+ import "./access-DtOxFKBK.js";
2
+ import { Ct as updateLorebookInfo, G as partsOf, Ht as LORE_KINDS, K as withPlayer, Rt as ImportCardError, Ut as LORE_SCOPES, W as cleanText, at as IMPORT_FOLDER, bt as lorebookDirectory, gt as entriesOf, ht as deleteLorebookEntry, i as contextOf, r as MAX_PREVIEW_TEXT, wt as writeLorebookEntry, xt as readLorebook$1, yt as loadLorebook } from "./authoring-tools-BKltdiea.js";
3
+ import { c as createPresetFromGuidance } from "./route-DRTJ_vcA.js";
4
+ import { nt as shippedPromptsDirectory } from "./hooks-HnqXO8mM.js";
5
+ import { i as translator, r as languageOf } from "./text-JbWfTHbr.js";
6
+ import { S as uniqueKey, b as slug, v as mapLimit, x as trOf } from "./library-BGxPKs9a.js";
6
7
  import { join } from "node:path";
7
8
  import { existsSync, readFileSync } from "node:fs";
8
9
  import { defineTool } from "@deepseek-ai/dsh-tools";
9
10
  import { readFile, rm, writeFile } from "node:fs/promises";
11
+ //#region src/shared/lorebook-chat.ts
12
+ const PREFIX = "lorebook-author-";
13
+ /** Stable DSH chat identity for the authoring conversation of one library lorebook. */
14
+ function lorebookChatSessionId(name) {
15
+ if (name === "") throw new TypeError("lorebook name cannot be empty");
16
+ return `${PREFIX}${encodeURIComponent(name)}`;
17
+ }
18
+ /** The library lorebook named by a dedicated lorebook authoring chat. */
19
+ function lorebookOfChat(chatSessionId) {
20
+ if (!chatSessionId.startsWith(PREFIX)) return void 0;
21
+ try {
22
+ const name = decodeURIComponent(chatSessionId.slice(16));
23
+ return name === "" ? void 0 : name;
24
+ } catch {
25
+ return;
26
+ }
27
+ }
28
+ //#endregion
10
29
  //#region src/host/import/lorebook.ts
11
30
  const MAX_ENTRIES = 500;
12
31
  const BATCH_CHARS = 6e3;
@@ -243,18 +262,20 @@ function problemOf(answer, batch) {
243
262
  const missing = batch.filter((entry) => !seen.has(entry.ref)).map((entry) => entry.ref);
244
263
  return missing.length === 0 ? void 0 : `decide every entry: ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} missing`;
245
264
  }
246
- const describe = (entry) => `Entry ${entry.ref}${entry.title === "" ? "" : ` “${entry.title}”`}${entry.keys.length === 0 ? "" : ` (triggers: ${entry.keys.join(", ")})`}:\n${entry.text}`;
265
+ const describe = (entry, tr) => `${tr("Entry {ref}", { ref: entry.ref })}${entry.title === "" ? "" : ` “${entry.title}”`}${entry.keys.length === 0 ? "" : ` ${tr("(triggers: {keys})", { keys: entry.keys.join(", ") })}`}:\n${entry.text}`;
247
266
  /**
248
267
  * Sorts the entries of a lorebook into what the world is (kept word for word as lorebook entries, common knowledge unless an entry clearly says otherwise)
249
268
  * and what is told to the AI (kept as guidance for the prompts). Throws when the model never gives a usable answer, so that nothing half-made is written.
250
269
  */
251
270
  async function classifyEntries(ctx, book) {
252
271
  const batches = batchesOf(book.entries);
272
+ const tr = trOf(ctx);
253
273
  ctx.say(`sorting ${book.entries.length} entries`);
254
274
  const answers = await mapLimit(batches, ctx.concurrency, async (batch) => {
255
275
  return await ctx.run({
256
276
  persona: ctx.text("import/lorebook"),
257
- prompt: `Lorebook: ${book.name}\n\n${batch.map(describe).join("\n\n---\n\n")}`,
277
+ maxTokens: 4e3,
278
+ prompt: `${tr("Lorebook: {name}", { name: book.name })}\n\n${batch.map((entry) => describe(entry, tr)).join("\n\n---\n\n")}`,
258
279
  result: DECISIONS_SCHEMA,
259
280
  check: (value) => problemOf(value, batch)
260
281
  });
@@ -302,24 +323,6 @@ async function classifyEntries(ctx, book) {
302
323
  return result;
303
324
  }
304
325
  //#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
323
326
  //#region src/host/authoring/lorebook-author-tools.ts
324
327
  const LOREBOOK_MUTATION_TOOLS = [
325
328
  "write_lorebook_entry",
@@ -568,7 +571,7 @@ function lorebookAuthorTools(reader, settings, prompting, shipped = shippedPromp
568
571
  }), name);
569
572
  const language = prompting.languages().get(`lorebook:${name}`);
570
573
  const text = (id, variables) => prompting.prompts().text(id, language, variables);
571
- const made = await classifyEntries(contextOf(exec, settings(), text), uploaded);
574
+ const made = await classifyEntries(contextOf(exec, settings(), text, language), uploaded);
572
575
  const taken = new Set((await loadLorebook(reader.library, name)).entries.map((entry) => entry.id));
573
576
  for (const entry of made.entries) {
574
577
  let id = entry.id;
@@ -694,6 +697,6 @@ async function lorebookApproval(exec, next, state) {
694
697
  };
695
698
  }
696
699
  //#endregion
697
- 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 };
700
+ export { lorebookImportMessage as a, readLorebook as c, lorebookOfChat as d, lorebookAuthorTools as i, selectEntries as l, LorebookReader as n, pendingTargets as o, lorebookApproval as r, previewLorebook as s, LOREBOOK_UPLOAD as t, lorebookChatSessionId as u };
698
701
 
699
- //# sourceMappingURL=lorebook-author-tools-v-PM8Kbs.js.map
702
+ //# sourceMappingURL=lorebook-author-tools-BAnUyRtS.js.map
@@ -1,6 +1,7 @@
1
- import { St as lorebookDirectory, n as limitAuthoringAgents } from "./authoring-tools-BWjEr_lF.js";
2
- import "./hooks-DufjUf1p.js";
3
- import { c as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-v-PM8Kbs.js";
1
+ import { bt as lorebookDirectory, n as limitAuthoringAgents } from "./authoring-tools-BKltdiea.js";
2
+ import { d as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-BAnUyRtS.js";
3
+ import "./hooks-HnqXO8mM.js";
4
+ import { t as guardAuthoringTurns } from "./turn-guard-BvCs1VxB.js";
4
5
  import { join } from "node:path";
5
6
  import { existsSync, readdirSync } from "node:fs";
6
7
  //#region src/lorebook-authoring.ts
@@ -39,6 +40,10 @@ function apply(ctx) {
39
40
  } : pendingTargets(directory);
40
41
  };
41
42
  limitAuthoringAgents(ctx, (chat) => lorebookOfChat(chat) === void 0 ? void 0 : "lorebookAuthoring");
43
+ guardAuthoringTurns(ctx, () => ctx.roleplayPrompts, (chat) => {
44
+ const book = lorebookOfChat(chat);
45
+ return book === void 0 ? void 0 : ctx.roleplayAuthoringLanguages.get(`lorebook:${book}`);
46
+ }, () => ctx.roleplayImport.settings.reasoning);
42
47
  ctx.on("tools/pre-execute", (exec, next) => lorebookApproval(exec, next, {
43
48
  carries,
44
49
  waiting