@dsh-agentic-roleplay/core 0.3.5 → 0.3.6

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 (32) hide show
  1. package/lib/authoring.js +5 -5
  2. package/lib/client.js +1735 -459
  3. package/lib/client.js.map +1 -1
  4. package/lib/{deliver-Cl6bjp7g.js → deliver-BBgciEEK.js} +2 -2
  5. package/lib/doctor.js +3 -3
  6. package/lib/{hooks-DdO_tNhu.js → hooks-DkwFGtNH.js} +3 -3
  7. package/lib/index.js +394 -28
  8. package/lib/{load-Clkl0T7C.js → load-CVwJjIJ5.js} +7 -7
  9. package/lib/lorebook-author-tools-Bj31z1cu.js +619 -0
  10. package/lib/lorebook-authoring.js +67 -0
  11. package/lib/orchestration.js +6 -6
  12. package/lib/{pack-jail-ClMpVc__.js → pack-jail-2XztyYAX.js} +6 -5
  13. package/lib/{packs-BC2A3geF.js → packs-xHRCcGdb.js} +2 -2
  14. package/lib/preset-D0FMSeZ9.js +59 -0
  15. package/lib/{preset-author-tools-Dibp-LY9.js → preset-author-tools-BxycmoAr.js} +22 -16
  16. package/lib/preset-authoring.js +3 -3
  17. package/lib/{presets-DNjNxQL5.js → presets-gkBWAiVb.js} +44 -5
  18. package/lib/{reflection-Bju_LPFn.js → reflection-q0UpwXlx.js} +5 -5
  19. package/lib/{preset-ClQm7KPQ.js → tools-Dy1fgP6B.js} +424 -247
  20. package/package.json +3 -2
  21. package/prompts/en/import/lorebook.md +7 -0
  22. package/prompts/en/lorebook/persona.md +1 -0
  23. package/prompts/en/lorebook/procedure.md +1 -0
  24. package/prompts/en/lorebook/welcome.md +1 -0
  25. package/prompts/en/preset/persona.md +1 -1
  26. package/prompts/en/preset/procedure.md +1 -1
  27. package/prompts/zh/import/lorebook.md +7 -0
  28. package/prompts/zh/lorebook/persona.md +1 -0
  29. package/prompts/zh/lorebook/procedure.md +1 -0
  30. package/prompts/zh/lorebook/welcome.md +1 -0
  31. package/prompts/zh/preset/persona.md +1 -1
  32. package/prompts/zh/preset/procedure.md +1 -1
package/lib/index.js CHANGED
@@ -1,17 +1,19 @@
1
1
  import { n as chatSessionId, r as roleplaySessionOf } from "./access-EbNdZFbk.js";
2
- import { A as parseDiceFile, C as populateTriggers, Ct as isPng, Dt as DICE_READINGS, E as TRIGGERS_FILE_NAME, Et as DICE_COMPARISONS, H as CHARACTERS_DIR, J as loadVariables, L as loadLocations, M as loadCalendar, N as parseCalendarFile, O as DICE_FILE_NAME, Ot as DICE_RESULTS, S as populateRoutines, St as ImportCardError, T as routineProblems, Tt as readCard, U as loadCharacters, W as subfolders, X as variableProblems, Y as parseVariablesFile, _ as populateFactions, _t as parseLoreEdit, at as CHARACTER_FILE_NAME, b as populateLocations, bt as parseThingEdit, ct as ImportNotFoundError, d as vetUrl, dt as WORLD_FILE_NAME, f as loadValidatedWorld, ft as parseWorldFile, g as populateDice, gt as parseFactionEdit, h as populateClock, ht as parseCharacterEdit, j as CALENDAR_FILE_NAME, k as loadDice, l as markReady, lt as ImportStore, m as populateCharacters, mt as InvalidEditProblems, ot as parseCharacterFile, p as populateCalendar, pt as parseWorldInfoEdit, q as VARIABLES_FILE_NAME, s as authoringChatSessionId, st as IMPORT_FOLDER, t as readPreset, u as guardedLookup, ut as parseChoices, v as populateItems, vt as parsePlaceEdit, w as populateVariables, wt as pictureOf, x as populateLore, xt as IMPORT_COMMAND, y as populateKnowledge, yt as parseRelationEdit, z as loadItems } from "./preset-ClQm7KPQ.js";
3
- import { _ as writeWorldPrompt, a as listPresets, f as updatePresetInfo, g as readWorldPrompt, h as listWorldPrompts, i as isPresetName, l as reservePreset, m as deleteWorldPrompt, n as createPresetFromShipped, o as loadPreset, p as PROSE_PROMPTS, r as deletePreset, s as presetDirectory, t as PRESET_FILE, u as savePresetFromWorld } from "./presets-DNjNxQL5.js";
4
- import { c as copyPreset, d as switchPreset, f as readTimeline, i as reflectionStatus, l as presetStatus, m as defaultBoundaries, o as TimelineError, p as pathTo, u as recordPreset } from "./reflection-Bju_LPFn.js";
2
+ import { A as parseDiceFile, At as parseFactionEdit, B as CHARACTERS_DIR, Bt as LORE_KINDS, C as populateTriggers, Dt as subfolders, E as TRIGGERS_FILE_NAME, F as loadLocations, Ft as IMPORT_COMMAND, Ht as DICE_COMPARISONS, It as ImportCardError, J as parseVariablesFile, K as VARIABLES_FILE_NAME, L as loadItems, Lt as isPng, M as loadCalendar, Mt as parsePlaceEdit, N as parseCalendarFile, Nt as parseRelationEdit, O as DICE_FILE_NAME, Ot as InvalidEditProblems, Pt as parseThingEdit, Rt as pictureOf, S as populateRoutines, St as writeLorebookEntry, T as routineProblems, Ut as DICE_READINGS, V as loadCharacters, Vt as LORE_SCOPES, Wt as DICE_RESULTS, Y as variableProblems, _ as populateFactions, _t as loadLorebook, at as ImportNotFoundError, b as populateLocations, bt as reserveLorebook, c as markReady, ct as WORLD_FILE_NAME, d as loadValidatedWorld, dt as createLorebook, f as knowsCharacter, ft as deleteLorebook, g as populateDice, gt as listLorebooks, h as populateClock, ht as isLorebookName, it as IMPORT_FOLDER, j as CALENDAR_FILE_NAME, jt as parseLoreEdit, k as loadDice, kt as parseCharacterEdit, l as guardedLookup, lt as parseWorldFile, m as populateCharacters, mt as entriesOf, nt as CHARACTER_FILE_NAME, o as authoringChatSessionId, ot as ImportStore, p as populateCalendar, pt as deleteLorebookEntry, q as loadVariables, rt as parseCharacterFile, st as parseChoices, u as vetUrl, ut as parseWorldInfoEdit, v as populateItems, vt as lorebookDirectory, w as populateVariables, x as populateLore, xt as updateLorebookInfo, y as populateKnowledge, zt as readCard } from "./tools-Dy1fgP6B.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-gkBWAiVb.js";
4
+ import { c as copyPreset, d as switchPreset, f as readTimeline, i as reflectionStatus, l as presetStatus, m as defaultBoundaries, o as TimelineError, p as pathTo, u as recordPreset } from "./reflection-q0UpwXlx.js";
5
5
  import { a as WORLD_RULES_KEY, c as VARIABLE_SUBJECTS, i as parseSwitchboard, l as VARIABLE_VISIBILITIES, n as SETTINGS_SPEC, r as parseSettings, s as VARIABLE_KINDS, t as DEFAULT_SETTINGS } from "./settings-CA6icLL_.js";
6
- import { C as ReflectionRefusedError, E as WorldNotFoundError, S as InvalidWorldError, T as SessionNotFoundError, a as readDocument$1, b as AgentUnavailableError, c as formatIssue, d as PromptLibrary, f as copyWorldPrompts, i as plotReferenceProblems, m as languageOf, o as errorMessage, r as parsePlotsFile, w as SessionArchivedError, x as InvalidStartError } from "./load-Clkl0T7C.js";
7
- import { A as observeAsPlayer, D as notesOfSession, T as addToNote, b as populatePlots, c as readRunDetail, d as externalTools, h as PLOTS_METADATA_KEY, i as readUsage, k as readNotes, n as readWithdrawn, s as readActivity, y as plotProgressOf, z as zoneOf } from "./deliver-Cl6bjp7g.js";
6
+ import { C as ReflectionRefusedError, E as WorldNotFoundError, S as InvalidWorldError, T as SessionNotFoundError, a as readDocument$1, b as AgentUnavailableError, c as errorMessage, d as PromptLibrary, f as copyWorldPrompts, i as plotReferenceProblems, m as languageOf, r as parsePlotsFile, s as formatIssue, w as SessionArchivedError, x as InvalidStartError } from "./load-CVwJjIJ5.js";
7
+ import { A as observeAsPlayer, D as notesOfSession, T as addToNote, b as populatePlots, c as readRunDetail, d as externalTools, h as PLOTS_METADATA_KEY, i as readUsage, k as readNotes, n as readWithdrawn, s as readActivity, y as plotProgressOf, z as zoneOf } from "./deliver-BBgciEEK.js";
8
8
  import { a as liveSettings, c as writeSettings, i as InvalidSettingsError, n as encodeOutput, o as readSettings, s as useChildReasoning } from "./narration-DK2kiIjE.js";
9
9
  import { r as childSamplingOf } from "./child-CFjnaTZt.js";
10
10
  import { a as inheritImages, b as slug, c as referenceImagePath, l as sceneImagePath, t as addToLibrary, x as uniqueKey } from "./library-9JB9zw5a.js";
11
- import { A as worldEntityImageFile, C as readWorldEditor, D as uploadWorldCharacterPortrait, E as replaceFile$1, F as loadWorldParts, H as readWorldDocuments, I as PRESET_FILE$1, L as presetMessage, O as uploadWorldEntityImage, S as generateWorldEntityImage, T as removeWorldTrigger, V as languageOfDocuments, _ 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 translateMessage } from "./pack-jail-ClMpVc__.js";
12
- import { a as presetChatSessionId, n as narrationImportMessage } from "./preset-author-tools-Dibp-LY9.js";
11
+ import { A as worldEntityImageFile, C as readWorldEditor, D as uploadWorldCharacterPortrait, E as replaceFile$1, F as loadWorldParts, H as readWorldDocuments, I as PRESET_FILE$1, L as presetMessage, O as uploadWorldEntityImage, S as generateWorldEntityImage, T as removeWorldTrigger, V as languageOfDocuments, _ 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 translateMessage } from "./pack-jail-2XztyYAX.js";
12
+ import { t as readPreset } from "./preset-D0FMSeZ9.js";
13
+ import { a as presetChatSessionId, n as narrationImportMessage } from "./preset-author-tools-BxycmoAr.js";
14
+ import { a as lorebookImportMessage, c as lorebookChatSessionId, s as readLorebook, t as LOREBOOK_UPLOAD } from "./lorebook-author-tools-Bj31z1cu.js";
13
15
  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-BC2A3geF.js";
16
+ 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-xHRCcGdb.js";
15
17
  import { a as uploadReferenceImage, t as generateReferenceImage } from "./generator-DJ48HxPI.js";
16
18
  import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-DIEgETzU.js";
17
19
  import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from "node:path";
@@ -626,6 +628,138 @@ var PresetAuthoringSessions = class {
626
628
  }
627
629
  };
628
630
  //#endregion
631
+ //#region src/host/agent/lorebook-authoring-sessions.ts
632
+ const LOREBOOK_AUTHORING_PROJECT_TITLE = "Lorebook Authoring";
633
+ const LOREBOOK_AUTHORING_PRESET = "lorebook-authoring";
634
+ /** Creates or reopens the dedicated authoring chat of a library lorebook, and speaks in it for the person when asked to. */
635
+ var LorebookAuthoringSessions = class {
636
+ services;
637
+ roleplayRoot;
638
+ prompts;
639
+ languages;
640
+ constructor(services, roleplayRoot, prompts, languages) {
641
+ this.services = services;
642
+ this.roleplayRoot = roleplayRoot;
643
+ this.prompts = prompts;
644
+ this.languages = languages;
645
+ }
646
+ async ensure(name, title, language) {
647
+ this.languages.set(`lorebook:${name}`, language);
648
+ const services = this.services();
649
+ const projectPath = join(this.roleplayRoot(), "lorebooks");
650
+ const project = await services.registry.create(projectPath, LOREBOOK_AUTHORING_PROJECT_TITLE);
651
+ const sessionId = lorebookChatSessionId(name);
652
+ const stored = !project.sessionIds.includes(sessionId) && await isStored(services.persistence, sessionId);
653
+ if (!project.sessionIds.includes(sessionId) && !stored) {
654
+ if (services.persistence === void 0) throw new AgentUnavailableError("this DSH profile cannot store the opening of an authoring chat");
655
+ await storeAuthoringOpening(services.persistence, {
656
+ id: sessionId,
657
+ cwd: project.path,
658
+ agentPreset: LOREBOOK_AUTHORING_PRESET
659
+ }, this.prompts.text("lorebook/welcome", this.languages.get(`lorebook:${name}`), { lorebook: title }));
660
+ }
661
+ return await ensureAgentChat(services, {
662
+ projectPath,
663
+ projectTitle: LOREBOOK_AUTHORING_PROJECT_TITLE,
664
+ sessionId,
665
+ agentPreset: LOREBOOK_AUTHORING_PRESET,
666
+ title: `Lorebook ${title}`,
667
+ renameExisting: true
668
+ }, project);
669
+ }
670
+ async send(sessionId, text) {
671
+ await this.services().controller.prompt({
672
+ requestId: randomUUID(),
673
+ sessionId,
674
+ mode: "queue",
675
+ content: [{
676
+ type: "text",
677
+ text
678
+ }]
679
+ }, new AbortController().signal);
680
+ }
681
+ };
682
+ //#endregion
683
+ //#region src/host/lorebooks/service.ts
684
+ /** The lorebook library. Refusals are plain `Error`s with the reason. */
685
+ var Lorebooks = class {
686
+ deps;
687
+ constructor(deps) {
688
+ this.deps = deps;
689
+ }
690
+ get maxUploadBytes() {
691
+ return this.deps.maxUploadBytes;
692
+ }
693
+ async list() {
694
+ return (await listLorebooks(this.deps.root())).map((book) => book.summary);
695
+ }
696
+ async read(name) {
697
+ const book = await loadLorebook(this.deps.root(), name);
698
+ return {
699
+ summary: book.summary,
700
+ entries: entriesOf(book)
701
+ };
702
+ }
703
+ async create(request) {
704
+ return (await createLorebook(this.deps.root(), request)).summary;
705
+ }
706
+ async updateInfo(name, change) {
707
+ return (await updateLorebookInfo(this.deps.root(), name, change)).summary;
708
+ }
709
+ async writeEntry(name, entry) {
710
+ return (await writeLorebookEntry(this.deps.root(), name, entry)).summary;
711
+ }
712
+ async removeEntry(name, id) {
713
+ return (await deleteLorebookEntry(this.deps.root(), name, id)).summary;
714
+ }
715
+ async remove(name) {
716
+ await deleteLorebook(this.deps.root(), name);
717
+ }
718
+ /** Opens the authoring chat of a lorebook. */
719
+ async author(name, language) {
720
+ const loaded = await loadLorebook(this.deps.root(), name);
721
+ return { chatSessionId: await this.deps.authoring.ensure(name, loaded.summary.title, language) };
722
+ }
723
+ /** Like `importFile`, under a name made from the title that is not yet taken. */
724
+ async importTitled(title, file, language) {
725
+ const base = title.normalize("NFKD").replace(/[^A-Za-z0-9_-]+/g, "-").replace(/^[-_]+|[-_]+$/g, "").slice(0, 56) || "lorebook";
726
+ const taken = new Set((await listLorebooks(this.deps.root())).map((book) => book.summary.name));
727
+ let name = base;
728
+ for (let index = 2; taken.has(name); index += 1) name = `${base}-${index}`;
729
+ return await this.importFile(name, file, language, title.trim() === "" ? void 0 : title.trim().slice(0, 300));
730
+ }
731
+ /** Keeps an uploaded SillyTavern lorebook in a new library lorebook and has its authoring chat turn it into entries. @throws {ImportCardError} when the file is not a lorebook. */
732
+ async importFile(name, file, language, title) {
733
+ if (!isLorebookName(name)) throw new Error(`"${name}" is not a usable lorebook name (letters, digits, "-" and "_", up to 64)`);
734
+ const uploaded = readLorebook(file, name);
735
+ const root = this.deps.root();
736
+ const directory = await reserveLorebook(root, name, title ?? uploaded.name);
737
+ try {
738
+ await mkdir(join(directory, IMPORT_FOLDER), { recursive: true });
739
+ await writeFile(join(directory, LOREBOOK_UPLOAD), file);
740
+ } catch (error) {
741
+ await rm(lorebookDirectory(root, name), {
742
+ recursive: true,
743
+ force: true
744
+ });
745
+ throw error;
746
+ }
747
+ const chatSessionId = await this.deps.authoring.ensure(name, title ?? uploaded.name, language);
748
+ let failure;
749
+ try {
750
+ await this.deps.authoring.send(chatSessionId, this.deps.importMessage());
751
+ } catch (problem) {
752
+ failure = problem instanceof Error ? problem.message : String(problem);
753
+ }
754
+ return {
755
+ name,
756
+ chatSessionId,
757
+ started: failure === void 0,
758
+ ...failure === void 0 ? {} : { failure }
759
+ };
760
+ }
761
+ };
762
+ //#endregion
629
763
  //#region src/host/agent/doctor-sessions.ts
630
764
  const DOCTOR_PROJECT_TITLE = "Session Doctor";
631
765
  const DOCTOR_AGENT_PRESET = "session-doctor";
@@ -1167,7 +1301,7 @@ var Presets = class {
1167
1301
  async writePrompt(name, language, id, text) {
1168
1302
  const directory = presetDirectory(this.deps.root(), name);
1169
1303
  if (!existsSync(directory)) throw new Error(`there is no preset "${name}"`);
1170
- if (!PROSE_PROMPTS.includes(id)) throw new Error(`a preset carries only ${PROSE_PROMPTS.join(", ")}`);
1304
+ if (!id.startsWith("roleplay/")) throw new Error(`"${id}" is not a prompt of the story`);
1171
1305
  if (text === void 0) await deleteWorldPrompt(directory, language, id);
1172
1306
  else await writeWorldPrompt(directory, language, id, text);
1173
1307
  return loadPreset(this.deps.root(), name).summary;
@@ -1232,7 +1366,7 @@ var Presets = class {
1232
1366
  //#endregion
1233
1367
  //#region src/host/presets/routes.ts
1234
1368
  /** Not found is 404 and a request the library refuses is 422 with its reason; anything else is a fault. */
1235
- function failure(res, error) {
1369
+ function failure$1(res, error) {
1236
1370
  if (error instanceof SessionNotFoundError || error instanceof WorldNotFoundError) return sendError(res, 404, error.message);
1237
1371
  if (error instanceof PresetBusyError) return sendError(res, 409, error.message);
1238
1372
  if (error instanceof Error) return sendError(res, 422, error.message);
@@ -1255,7 +1389,7 @@ function presetRoutes(api) {
1255
1389
  try {
1256
1390
  sendJson(res, 200, api.list());
1257
1391
  } catch (error) {
1258
- failure(res, error);
1392
+ failure$1(res, error);
1259
1393
  }
1260
1394
  },
1261
1395
  POST: async (req, res) => {
@@ -1274,7 +1408,7 @@ function presetRoutes(api) {
1274
1408
  sampling: given
1275
1409
  }));
1276
1410
  } catch (error) {
1277
- failure(res, error);
1411
+ failure$1(res, error);
1278
1412
  }
1279
1413
  }
1280
1414
  },
@@ -1283,7 +1417,7 @@ function presetRoutes(api) {
1283
1417
  try {
1284
1418
  sendJson(res, 200, api.read(url.searchParams.get("name") ?? ""));
1285
1419
  } catch (error) {
1286
- failure(res, error);
1420
+ failure$1(res, error);
1287
1421
  }
1288
1422
  },
1289
1423
  PUT: async (req, res, url) => {
@@ -1298,7 +1432,7 @@ function presetRoutes(api) {
1298
1432
  ...given === void 0 ? {} : { sampling: given }
1299
1433
  }));
1300
1434
  } catch (error) {
1301
- failure(res, error);
1435
+ failure$1(res, error);
1302
1436
  }
1303
1437
  },
1304
1438
  DELETE: async (_req, res, url) => {
@@ -1307,7 +1441,7 @@ function presetRoutes(api) {
1307
1441
  res.statusCode = 204;
1308
1442
  res.end();
1309
1443
  } catch (error) {
1310
- failure(res, error);
1444
+ failure$1(res, error);
1311
1445
  }
1312
1446
  }
1313
1447
  },
@@ -1318,14 +1452,14 @@ function presetRoutes(api) {
1318
1452
  try {
1319
1453
  sendJson(res, 200, await api.writePrompt(url.searchParams.get("name") ?? "", languageOf(url.searchParams.get("language") ?? ""), url.searchParams.get("id") ?? "", text));
1320
1454
  } catch (error) {
1321
- failure(res, error);
1455
+ failure$1(res, error);
1322
1456
  }
1323
1457
  },
1324
1458
  DELETE: async (_req, res, url) => {
1325
1459
  try {
1326
1460
  sendJson(res, 200, await api.writePrompt(url.searchParams.get("name") ?? "", languageOf(url.searchParams.get("language") ?? ""), url.searchParams.get("id") ?? "", void 0));
1327
1461
  } catch (error) {
1328
- failure(res, error);
1462
+ failure$1(res, error);
1329
1463
  }
1330
1464
  }
1331
1465
  },
@@ -1335,7 +1469,7 @@ function presetRoutes(api) {
1335
1469
  try {
1336
1470
  sendJson(res, 200, await api.author(url.searchParams.get("name") ?? "", language === void 0 ? void 0 : languageOf(language)));
1337
1471
  } catch (error) {
1338
- failure(res, error);
1472
+ failure$1(res, error);
1339
1473
  }
1340
1474
  } },
1341
1475
  "/presets/import": { POST: async (req, res, url) => {
@@ -1343,7 +1477,7 @@ function presetRoutes(api) {
1343
1477
  try {
1344
1478
  sendJson(res, 200, await api.importFile(url.searchParams.get("name") ?? "", await readBinaryBody(req, api.maxUploadBytes), language === null ? void 0 : languageOf(language)));
1345
1479
  } catch (error) {
1346
- failure(res, error);
1480
+ failure$1(res, error);
1347
1481
  }
1348
1482
  } },
1349
1483
  "/sessions/preset": {
@@ -1351,7 +1485,7 @@ function presetRoutes(api) {
1351
1485
  try {
1352
1486
  sendJson(res, 200, api.status(url.searchParams.get("id") ?? ""));
1353
1487
  } catch (error) {
1354
- failure(res, error);
1488
+ failure$1(res, error);
1355
1489
  }
1356
1490
  },
1357
1491
  POST: async (req, res, url) => {
@@ -1360,12 +1494,132 @@ function presetRoutes(api) {
1360
1494
  try {
1361
1495
  sendJson(res, 200, api.apply(url.searchParams.get("id") ?? "", typeof name === "string" ? name : void 0));
1362
1496
  } catch (error) {
1363
- failure(res, error);
1497
+ failure$1(res, error);
1364
1498
  }
1365
1499
  }
1366
1500
  }
1367
1501
  };
1368
1502
  }
1503
+ //#endregion
1504
+ //#region src/host/lorebooks/routes.ts
1505
+ /** A request the library refuses is 422 with its reason; anything else is a fault. */
1506
+ function failure(res, error) {
1507
+ if (error instanceof Error) return sendError(res, 422, error.message);
1508
+ throw error;
1509
+ }
1510
+ const texts = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
1511
+ /** Reads the body of an entry, or says what is wrong with it. */
1512
+ function entryOf(id, body) {
1513
+ const { title, kind, scope, knownBy, summary, body: text, related } = body;
1514
+ if (typeof title !== "string") return "\"title\" must be text";
1515
+ if (typeof kind !== "string" || !LORE_KINDS.includes(kind)) return `"kind" must be one of ${LORE_KINDS.join(", ")}`;
1516
+ if (typeof scope !== "string" || !LORE_SCOPES.includes(scope)) return `"scope" must be one of ${LORE_SCOPES.join(", ")}`;
1517
+ if (knownBy !== void 0 && !texts(knownBy)) return "\"knownBy\" must be a list of text";
1518
+ if (related !== void 0 && !texts(related)) return "\"related\" must be a list of text";
1519
+ if (summary !== void 0 && typeof summary !== "string" || text !== void 0 && typeof text !== "string") return "\"summary\" and \"body\" must be text";
1520
+ return {
1521
+ id,
1522
+ title,
1523
+ kind,
1524
+ scope,
1525
+ knownBy: knownBy?.map((entry) => entry.trim()).filter((entry) => entry !== "") ?? [],
1526
+ summary: summary ?? "",
1527
+ body: text ?? "",
1528
+ related: related ?? []
1529
+ };
1530
+ }
1531
+ function lorebookRoutes(api) {
1532
+ return {
1533
+ "/lorebooks": {
1534
+ GET: async (_req, res) => {
1535
+ try {
1536
+ sendJson(res, 200, await api.list());
1537
+ } catch (error) {
1538
+ failure(res, error);
1539
+ }
1540
+ },
1541
+ POST: async (req, res) => {
1542
+ const { name, title, description } = await readJsonBody(req);
1543
+ if (typeof name !== "string" || name === "") return sendError(res, 400, "\"name\" is required");
1544
+ if (title !== void 0 && typeof title !== "string" || description !== void 0 && typeof description !== "string") return sendError(res, 400, "\"title\" and \"description\" must be text");
1545
+ try {
1546
+ sendJson(res, 201, await api.create({
1547
+ name,
1548
+ ...title === void 0 ? {} : { title },
1549
+ ...description === void 0 ? {} : { description }
1550
+ }));
1551
+ } catch (error) {
1552
+ failure(res, error);
1553
+ }
1554
+ }
1555
+ },
1556
+ "/lorebooks/item": {
1557
+ GET: async (_req, res, url) => {
1558
+ try {
1559
+ sendJson(res, 200, await api.read(url.searchParams.get("name") ?? ""));
1560
+ } catch (error) {
1561
+ failure(res, error);
1562
+ }
1563
+ },
1564
+ PUT: async (req, res, url) => {
1565
+ const { title, description } = await readJsonBody(req);
1566
+ if (title !== void 0 && typeof title !== "string" || description !== void 0 && typeof description !== "string") return sendError(res, 400, "\"title\" and \"description\" must be text");
1567
+ try {
1568
+ sendJson(res, 200, await api.updateInfo(url.searchParams.get("name") ?? "", {
1569
+ ...title === void 0 ? {} : { title },
1570
+ ...description === void 0 ? {} : { description }
1571
+ }));
1572
+ } catch (error) {
1573
+ failure(res, error);
1574
+ }
1575
+ },
1576
+ DELETE: async (_req, res, url) => {
1577
+ try {
1578
+ await api.remove(url.searchParams.get("name") ?? "");
1579
+ res.statusCode = 204;
1580
+ res.end();
1581
+ } catch (error) {
1582
+ failure(res, error);
1583
+ }
1584
+ }
1585
+ },
1586
+ "/lorebooks/entry": {
1587
+ PUT: async (req, res, url) => {
1588
+ const entry = entryOf(url.searchParams.get("id") ?? "", await readJsonBody(req));
1589
+ if (typeof entry === "string") return sendError(res, 400, entry);
1590
+ try {
1591
+ sendJson(res, 200, await api.writeEntry(url.searchParams.get("name") ?? "", entry));
1592
+ } catch (error) {
1593
+ failure(res, error);
1594
+ }
1595
+ },
1596
+ DELETE: async (_req, res, url) => {
1597
+ try {
1598
+ sendJson(res, 200, await api.removeEntry(url.searchParams.get("name") ?? "", url.searchParams.get("id") ?? ""));
1599
+ } catch (error) {
1600
+ failure(res, error);
1601
+ }
1602
+ }
1603
+ },
1604
+ "/lorebooks/authoring": { POST: async (req, res, url) => {
1605
+ const { language } = await readJsonBody(req);
1606
+ if (language !== void 0 && typeof language !== "string") return sendError(res, 400, "\"language\" must be text");
1607
+ try {
1608
+ sendJson(res, 200, await api.author(url.searchParams.get("name") ?? "", language === void 0 ? void 0 : languageOf(language)));
1609
+ } catch (error) {
1610
+ failure(res, error);
1611
+ }
1612
+ } },
1613
+ "/lorebooks/import": { POST: async (req, res, url) => {
1614
+ const language = url.searchParams.get("language");
1615
+ try {
1616
+ sendJson(res, 200, await api.importFile(url.searchParams.get("name") ?? "", await readBinaryBody(req, api.maxUploadBytes), language === null ? void 0 : languageOf(language)));
1617
+ } catch (error) {
1618
+ failure(res, error);
1619
+ }
1620
+ } }
1621
+ };
1622
+ }
1369
1623
  /** The headers of every file of a pack. */
1370
1624
  const PACK_HEADERS = {
1371
1625
  "content-security-policy": [
@@ -2163,7 +2417,7 @@ function languageField(value) {
2163
2417
  throw new InvalidEditProblems([error instanceof Error ? error.message : String(error)]);
2164
2418
  }
2165
2419
  }
2166
- function createApiHandler({ catalogue, worlds, createWorld, starter, authorWorld, translation, worldCharacters, importer, avatars, worldFiles, worldEditor, sessions, packs, presets, connection, speech, externalTools }) {
2420
+ function createApiHandler({ catalogue, worlds, createWorld, starter, authorWorld, translation, worldCharacters, importer, avatars, worldFiles, worldEditor, sessions, packs, presets, lorebooks, connection, speech, externalTools }) {
2167
2421
  const routes = {
2168
2422
  "/speech/capabilities": { GET: async (_req, res) => {
2169
2423
  sendJson(res, 200, { streaming: speech.streaming() });
@@ -2214,7 +2468,11 @@ function createApiHandler({ catalogue, worlds, createWorld, starter, authorWorld
2214
2468
  const sort = url.searchParams.get("sort") === "popular" ? "popular" : "recent";
2215
2469
  try {
2216
2470
  sendJson(res, 200, await catalogue.worlds(url.searchParams.get("source") ?? "", {
2217
- kind: ["card", "preset"].find((entry) => entry === url.searchParams.get("kind")) ?? "world",
2471
+ kind: [
2472
+ "card",
2473
+ "preset",
2474
+ "lorebook"
2475
+ ].find((entry) => entry === url.searchParams.get("kind")) ?? "world",
2218
2476
  search: url.searchParams.get("search") ?? "",
2219
2477
  offset: Number.isFinite(offset) ? offset : 0,
2220
2478
  sort
@@ -2297,6 +2555,22 @@ function createApiHandler({ catalogue, worlds, createWorld, starter, authorWorld
2297
2555
  return error instanceof CatalogueError ? catalogueFailure(res, error) : importFailure(res, error);
2298
2556
  }
2299
2557
  } },
2558
+ "/catalogue/convert/lorebook": { POST: async (req, res) => {
2559
+ const body = await readJsonBody(req);
2560
+ if (typeof body.source !== "string" || typeof body.versionId !== "string") return sendError(res, 400, "source and versionId must be text");
2561
+ if (body.title !== void 0 && typeof body.title !== "string") return sendError(res, 400, "title must be text");
2562
+ try {
2563
+ const language = languageField(body.language);
2564
+ sendJson(res, 201, await catalogue.convertLorebook({
2565
+ source: body.source,
2566
+ versionId: body.versionId,
2567
+ ...body.title === void 0 ? {} : { title: body.title },
2568
+ ...language === void 0 ? {} : { language }
2569
+ }));
2570
+ } catch (error) {
2571
+ return error instanceof CatalogueError ? catalogueFailure(res, error) : importFailure(res, error);
2572
+ }
2573
+ } },
2300
2574
  "/worlds/starter": {
2301
2575
  GET: async (_req, res) => {
2302
2576
  sendJson(res, 200, await starter.list());
@@ -2952,7 +3226,7 @@ function createApiHandler({ catalogue, worlds, createWorld, starter, authorWorld
2952
3226
  sendJson(res, 200, sessions.list());
2953
3227
  },
2954
3228
  POST: async (req, res) => {
2955
- const { worldId, playerCharacterId, playerAvatar, avatars: brought, name, settings, opening, startingTime, preset } = await readJsonBody(req);
3229
+ const { worldId, playerCharacterId, playerAvatar, avatars: brought, name, settings, opening, startingTime, preset, lorebooks } = await readJsonBody(req);
2956
3230
  if (typeof worldId !== "string" || worldId.trim() === "") return sendError(res, 400, "\"worldId\" is required");
2957
3231
  if (playerCharacterId === void 0 && playerAvatar === void 0) return sendError(res, 400, "\"playerCharacterId\" or \"playerAvatar\" is required");
2958
3232
  if (playerCharacterId !== void 0 && (typeof playerCharacterId !== "string" || playerCharacterId.trim() === "")) return sendError(res, 400, "\"playerCharacterId\" must be text");
@@ -2962,9 +3236,11 @@ function createApiHandler({ catalogue, worlds, createWorld, starter, authorWorld
2962
3236
  if (opening !== void 0 && (typeof opening !== "number" || !Number.isInteger(opening))) return sendError(res, 400, "\"opening\" must be a whole number");
2963
3237
  if (startingTime !== void 0 && typeof startingTime !== "string") return sendError(res, 400, "\"startingTime\" must be text");
2964
3238
  if (preset !== void 0 && typeof preset !== "string") return sendError(res, 400, "\"preset\" must be text");
3239
+ if (lorebooks !== void 0 && (!Array.isArray(lorebooks) || !lorebooks.every((entry) => typeof entry === "string"))) return sendError(res, 400, "\"lorebooks\" must be a list of lorebook names");
2965
3240
  try {
2966
3241
  sendJson(res, 201, await sessions.start({
2967
3242
  ...preset === void 0 || preset === "" ? {} : { preset },
3243
+ ...lorebooks === void 0 ? {} : { lorebooks },
2968
3244
  ...opening === void 0 ? {} : { opening },
2969
3245
  ...startingTime === void 0 ? {} : { startingTime },
2970
3246
  worldId,
@@ -3352,6 +3628,7 @@ function createApiHandler({ catalogue, worlds, createWorld, starter, authorWorld
3352
3628
  } },
3353
3629
  ...interfaceRoutes(packs),
3354
3630
  ...presetRoutes(presets),
3631
+ ...lorebookRoutes(lorebooks),
3355
3632
  "/worlds/cover": { GET: async (_req, res, url) => {
3356
3633
  const cover = await worlds.cover(url.searchParams.get("id") ?? "");
3357
3634
  if (cover === void 0) return sendError(res, 404, "no cover");
@@ -4642,6 +4919,7 @@ function infoOf(document) {
4642
4919
  timeZone: textOf(document["time_zone"]),
4643
4920
  startingTime: textOf(document["starting_time"]),
4644
4921
  preset: textOf(document["preset"]),
4922
+ lorebooks: Array.isArray(document["lorebooks"]) ? document["lorebooks"].filter((name) => typeof name === "string") : [],
4645
4923
  version: typeof document["version"] === "number" ? String(document["version"]) : textOf(document["version"]),
4646
4924
  tools: toolsOf(document["tools"]),
4647
4925
  alternateOpenings: Array.isArray(document["alternate_openings"]) ? document["alternate_openings"].flatMap((entry) => typeof entry === "object" && entry !== null && typeof entry["text"] === "string" ? [{
@@ -4701,6 +4979,10 @@ async function editWorldInfo(directory, edit) {
4701
4979
  if (edit.startingTime !== void 0) setOrRemove(document, "starting_time", edit.startingTime);
4702
4980
  if (edit.version !== void 0) setOrRemove(document, "version", edit.version);
4703
4981
  if (edit.preset !== void 0) setOrRemove(document, "preset", edit.preset);
4982
+ if (edit.lorebooks !== void 0) {
4983
+ if (edit.lorebooks.length === 0) delete document["lorebooks"];
4984
+ else document["lorebooks"] = edit.lorebooks;
4985
+ }
4704
4986
  if (edit.alternateOpenings !== void 0) {
4705
4987
  if (edit.alternateOpenings.length === 0) delete document["alternate_openings"];
4706
4988
  else document["alternate_openings"] = edit.alternateOpenings.map((entry) => ({
@@ -4719,6 +5001,55 @@ async function editWorldInfo(directory, edit) {
4719
5001
  await replaceFile(join(directory, WORLD_FILE_NAME), next);
4720
5002
  return infoOf(document);
4721
5003
  }
5004
+ //#endregion
5005
+ //#region src/host/lorebooks/apply.ts
5006
+ /** Which lorebooks a story was started with: kept in the story's own metadata, because the library may change afterwards. */
5007
+ const LOREBOOKS_KEY = "roleplay.lorebooks";
5008
+ /** The id an entry has in a story, so that books and the world's own lore never clash. */
5009
+ const bookEntryId = (book, id) => `${book}:${id}`;
5010
+ /**
5011
+ * The entries of the named books as a story takes them. A book that cannot be used is refused when the person chose it and told about when only the world suggested it,
5012
+ * because the world may come from someone whose library differs. Characters an entry names that this story does not have are left out, and it is told.
5013
+ * @throws {Error} when a chosen book cannot be used.
5014
+ */
5015
+ async function lorebookLore(root, names, chosen, characters, taken) {
5016
+ const result = {
5017
+ definitions: [],
5018
+ applied: [],
5019
+ notes: []
5020
+ };
5021
+ const used = new Set(taken);
5022
+ for (const name of [...new Set(names)]) {
5023
+ let book;
5024
+ try {
5025
+ book = await loadLorebook(root, name);
5026
+ if (book.summary.problems.length > 0) throw new Error(`it has problems: ${book.summary.problems.join("; ")}`);
5027
+ } catch (error) {
5028
+ const reason = error instanceof Error ? error.message : String(error);
5029
+ if (chosen) throw new Error(`the lorebook "${name}" cannot be used: ${reason}`);
5030
+ result.notes.push(`The world suggests the lorebook "${name}", which cannot be used here (${reason}), so the story starts without it.`);
5031
+ continue;
5032
+ }
5033
+ for (const entry of book.entries) {
5034
+ const id = bookEntryId(name, entry.id);
5035
+ if (used.has(id)) throw new Error(`the lorebook "${name}" has the entry "${entry.id}", whose id the story already has`);
5036
+ used.add(id);
5037
+ const knownBy = entry.scope === "listed" ? entry.knownBy.filter((reference) => knowsCharacter(characters, reference)) : [];
5038
+ for (const reference of entry.scope === "listed" ? entry.knownBy : []) if (!knownBy.includes(reference)) result.notes.push(`The lorebook "${name}" says "${entry.title}" is known to "${reference}", who is not in this story.`);
5039
+ result.definitions.push({
5040
+ ...entry,
5041
+ id,
5042
+ knownBy,
5043
+ related: entry.related.map((other) => bookEntryId(name, other))
5044
+ });
5045
+ }
5046
+ result.applied.push({
5047
+ name,
5048
+ entries: book.entries.length
5049
+ });
5050
+ }
5051
+ return result;
5052
+ }
4722
5053
  /**
4723
5054
  * Start a new session for a world: create its folder and database and fill it
4724
5055
  * from the world. Either the whole session exists afterwards or nothing does.
@@ -4784,6 +5115,22 @@ async function startSession(deps, request) {
4784
5115
  tools
4785
5116
  };
4786
5117
  const { preset, unavailable } = presetFor(deps, request.preset, world.preset);
5118
+ const asked = request.lorebooks !== void 0;
5119
+ const wanted = request.lorebooks ?? world.lorebooks ?? [];
5120
+ let books = {
5121
+ definitions: [],
5122
+ applied: [],
5123
+ notes: []
5124
+ };
5125
+ if (wanted.length > 0) {
5126
+ if (deps.root === void 0) throw new InvalidStartError("the lorebook library is not available");
5127
+ try {
5128
+ books = await lorebookLore(deps.root(), wanted, asked, characters, new Set(authoredLore.lore.map((entry) => entry.id)));
5129
+ } catch (error) {
5130
+ throw new InvalidStartError(error instanceof Error ? error.message : String(error));
5131
+ }
5132
+ unavailable.push(...books.notes);
5133
+ }
4787
5134
  if (preset !== void 0) {
4788
5135
  const given = request.settings?.sampling ?? {};
4789
5136
  settings = {
@@ -4824,7 +5171,8 @@ async function startSession(deps, request) {
4824
5171
  populateDice(session, checks);
4825
5172
  populateRoutines(session, characters);
4826
5173
  populateItems(session, items, slots, locations);
4827
- populateLore(session, authoredLore.lore);
5174
+ populateLore(session, [...authoredLore.lore, ...books.definitions]);
5175
+ if (books.applied.length > 0) session.metadata.setValue(LOREBOOKS_KEY, books.applied);
4828
5176
  populateKnowledge(session, characters);
4829
5177
  populateVariables(session, declared.defs, {
4830
5178
  characters,
@@ -5248,6 +5596,7 @@ async function worldCharacters(worlds, worldId) {
5248
5596
  startingTime: world.clock?.startingTime === void 0 ? "" : localInstant(world.clock.startingTime, world.clock.timeZone ?? "UTC"),
5249
5597
  timeZone: world.clock?.timeZone ?? "",
5250
5598
  ...world.preset === void 0 ? {} : { preset: world.preset },
5599
+ ...world.lorebooks === void 0 ? {} : { lorebooks: world.lorebooks },
5251
5600
  problems
5252
5601
  };
5253
5602
  }
@@ -5421,7 +5770,8 @@ async function loadWorld(folder, dir, file, problems) {
5421
5770
  ...world.rules === void 0 ? {} : { rules: world.rules },
5422
5771
  ...world.tools === void 0 ? {} : { tools: world.tools },
5423
5772
  ...world.narrationVoice === void 0 ? {} : { narrationVoice: world.narrationVoice },
5424
- ...world.preset === void 0 ? {} : { preset: world.preset }
5773
+ ...world.preset === void 0 ? {} : { preset: world.preset },
5774
+ ...world.lorebooks === void 0 ? {} : { lorebooks: world.lorebooks }
5425
5775
  };
5426
5776
  if (world.coverMediaId !== void 0) try {
5427
5777
  record.cover = await resolveCover(dir, world.coverMediaId);
@@ -5552,6 +5902,7 @@ var WorldCatalog = class extends Service {
5552
5902
  //#region src/shared/catalogue.ts
5553
5903
  const CATALOGUE_CARD_TYPE = "sillytavern/character";
5554
5904
  const CATALOGUE_PRESET_TYPE = "sillytavern/preset";
5905
+ const CATALOGUE_LOREBOOK_TYPE = "sillytavern/lorebook";
5555
5906
  const CATALOGUE_WORLD_TYPE = "dsh-agentic-roleplay/world";
5556
5907
  //#endregion
5557
5908
  //#region src/host/catalogue/origin.ts
@@ -6014,11 +6365,12 @@ const object = (value, what) => {
6014
6365
  };
6015
6366
  const text = (value) => typeof value === "string" ? value : "";
6016
6367
  const count = (value) => typeof value === "number" && Number.isFinite(value) ? value : 0;
6017
- const kindOf = (type) => type === "sillytavern/character" ? "card" : type === "sillytavern/preset" ? "preset" : "world";
6368
+ const kindOf = (type) => type === "sillytavern/character" ? "card" : type === "sillytavern/preset" ? "preset" : type === "sillytavern/lorebook" ? "lorebook" : "world";
6018
6369
  const TYPES = {
6019
6370
  world: CATALOGUE_WORLD_TYPE,
6020
6371
  card: CATALOGUE_CARD_TYPE,
6021
- preset: CATALOGUE_PRESET_TYPE
6372
+ preset: CATALOGUE_PRESET_TYPE,
6373
+ lorebook: CATALOGUE_LOREBOOK_TYPE
6022
6374
  };
6023
6375
  function worldOf(value) {
6024
6376
  const item = object(value, "a world entry");
@@ -6248,6 +6600,11 @@ var Catalogue = class {
6248
6600
  });
6249
6601
  return converted;
6250
6602
  }
6603
+ /** Turns a SillyTavern lorebook of a catalogue into a new library lorebook, which its authoring chat fills with entries. Like a card it is never an update of an earlier one. */
6604
+ async convertLorebook(request) {
6605
+ const release = await this.download(this.deps.sources.get(request.source), request.versionId, CATALOGUE_LOREBOOK_TYPE, "a lorebook");
6606
+ return await this.deps.importLorebook(release.body, request.title ?? "", request.language);
6607
+ }
6251
6608
  /** Turns a SillyTavern preset of a catalogue into a new library preset, which its authoring chat fills with prompts. Like a card it is never an update of an earlier one. */
6252
6609
  async convertPreset(request) {
6253
6610
  const release = await this.download(this.deps.sources.get(request.source), request.versionId, CATALOGUE_PRESET_TYPE, "a preset");
@@ -6538,6 +6895,7 @@ function apply(ctx, config) {
6538
6895
  const agent = new AgentSessions(agentServicesOf(ctx), () => root.path);
6539
6896
  const authoring = new AuthoringSessions(agentServicesOf(ctx), () => root.path, prompts, languages);
6540
6897
  const presetAuthoring = new PresetAuthoringSessions(agentServicesOf(ctx), () => root.path, prompts, languages);
6898
+ const lorebookAuthoring = new LorebookAuthoringSessions(agentServicesOf(ctx), () => root.path, prompts, languages);
6541
6899
  const doctors = new DoctorSessions(agentServicesOf(ctx), () => root.path, prompts);
6542
6900
  const imports = new ImportStore(() => root.path);
6543
6901
  new RoleplayImport(ctx, {
@@ -6575,6 +6933,12 @@ function apply(ctx, config) {
6575
6933
  maxUploadBytes: config.importMaxUploadBytes,
6576
6934
  playing: (id) => ctx.roleplayOrchestration.playing(chatSessionId(id))
6577
6935
  });
6936
+ const lorebookLibrary = new Lorebooks({
6937
+ root: () => root.path,
6938
+ authoring: lorebookAuthoring,
6939
+ importMessage: lorebookImportMessage,
6940
+ maxUploadBytes: config.importMaxUploadBytes
6941
+ });
6578
6942
  const catalogue = new Catalogue({
6579
6943
  sources: new Sources(() => config.catalogues.get()),
6580
6944
  worlds,
@@ -6585,6 +6949,7 @@ function apply(ctx, config) {
6585
6949
  ctx.logger.warn(message);
6586
6950
  },
6587
6951
  importPreset: async (file, title, language) => await presetLibrary.importTitled(title, file, language),
6952
+ importLorebook: async (file, title, language) => await lorebookLibrary.importTitled(title, file, language),
6588
6953
  importCard: async (file, name, language) => {
6589
6954
  const preview = await imports.create(readCard(file, name), isPng(file) ? pictureOf(file) : void 0);
6590
6955
  return await startImport({
@@ -6599,6 +6964,7 @@ function apply(ctx, config) {
6599
6964
  registerApi(ctx, {
6600
6965
  catalogue,
6601
6966
  presets: presetLibrary,
6967
+ lorebooks: lorebookLibrary,
6602
6968
  packs: new InterfaceService({
6603
6969
  open: (id) => ctx.roleplayState.openSession(deps.sessionsDir(), id),
6604
6970
  root: () => root.path,