@dsh-agentic-roleplay/core 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{access-CfQWbNZP.js → access-CXtaZNbx.js} +50 -2
- package/lib/{authoring-tools-C_l07RYn.js → authoring-tools-B4mEdKp_.js} +144 -58
- package/lib/authoring.js +7 -7
- package/lib/{child-lYYeOwl2.js → child-Dtv76jNx.js} +116 -11
- package/lib/client.js +2805 -790
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +3 -3
- package/lib/doctor.js +3 -3
- package/lib/{gallery-q7niLtWn.js → gallery-BZJleAeH.js} +5 -9
- package/lib/{generator-BpjPrvHe.js → generator-Cg6CQc5S.js} +2 -2
- package/lib/helper.js +1 -1
- package/lib/{hooks-DNaDzMjW.js → hooks-DTjHWTfx.js} +132 -25
- package/lib/images.js +4 -4
- package/lib/index.js +362 -33
- package/lib/{library-CIkxhf_R.js → library-GIlrkOim.js} +6 -13
- package/lib/{lorebook-author-tools-BiMDmdFi.js → lorebook-author-tools-BCFFJSle.js} +6 -6
- package/lib/lorebook-authoring.js +4 -4
- package/lib/{narration-CjB_KwwY.js → narration-BVzew4-K.js} +7 -52
- package/lib/orchestration.js +155 -10
- package/lib/{pack-jail-B35Vx3hT.js → pack-jail-hsNQNTOf.js} +10 -10
- package/lib/{packs-BajKw7S9.js → packs-UpK_cvI4.js} +2 -2
- package/lib/{presenter-agent-jgtuTwZr.js → presenter-agent-DZOgBOR9.js} +12 -17
- package/lib/{preset-DWgkcPau.js → preset-Cyoj1ZWa.js} +4 -4
- package/lib/{preset-author-tools-BhuYIKms.js → preset-author-tools-RSta6pHK.js} +6 -6
- package/lib/preset-authoring.js +5 -5
- package/lib/{presets-9GzaSELc.js → presets-CvpsW_10.js} +7 -8
- package/lib/{reflection-4L0Plvct.js → reflection-0qTvw2It.js} +53 -26
- package/lib/{turn-guard-sCUXmp-5.js → turn-guard-BzNeGNnc.js} +3 -3
- package/package.json +2 -2
- package/prompts/en/checks/conflict.md +1 -1
- package/prompts/en/checks/decide-conflict.md +1 -1
- package/prompts/en/checks/decide-opening.md +1 -1
- package/prompts/en/checks/decide-same-value.md +1 -1
- package/prompts/en/checks/decide-sheet.md +1 -1
- package/prompts/en/checks/fidelity.md +1 -0
- package/prompts/zh/checks/conflict.md +1 -1
- package/prompts/zh/checks/decide-conflict.md +1 -1
- package/prompts/zh/checks/decide-opening.md +1 -1
- package/prompts/zh/checks/decide-same-value.md +1 -1
- package/prompts/zh/checks/decide-sheet.md +1 -1
- package/prompts/zh/checks/fidelity.md +1 -0
package/lib/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { a as chatSessionId, i as
|
|
2
|
-
import { $ as
|
|
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-
|
|
4
|
-
import { a as presetChatSessionId, n as narrationImportMessage, o as presetOfChat } from "./preset-author-tools-
|
|
5
|
-
import { a as liveSettings, c as writeSettings, d as
|
|
6
|
-
import { $ as DOCTOR_OPENING_SOURCE, A as worldEntityImageFile, B as languageOfDocuments, C as readWorldEditor, D as uploadWorldCharacterPortrait, E as replaceFile, F as PRESET_FILE, G as revertUpdate, H as findTargets, I as presetMessage, J as AuthoringSessions, K as startUpdate, O as uploadWorldEntityImage, Q as agentServicesOf, R as translateMessage, S as generateWorldEntityImage, T as removeWorldTrigger, V as readWorldDocuments, X as ensureAuthoringChat, Y as authoringTitle, Z as AgentSessions, _ as editWorldPlots$1, a as deleteWorldPackFile, b as entityFolder, c as createAuthoredEntity, et as appendEmptyTurn, 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, q as updateStatus, t as MAX_PACK_TEXT, tt as appendNarratedTurn, u as readAuthoredEntityDocument, v as editWorldRelation$1, w as readWorldTrigger, x as generateWorldCharacterPortrait, y as editWorldThing$1 } from "./pack-jail-
|
|
7
|
-
import { d as sharedSamplingOf, i as childSamplingOf, u as parseSampling } from "./child-
|
|
8
|
-
import { $ as
|
|
9
|
-
import { $ as ImportNotFoundError, At as parseLoreEdit, Ct as CHARACTER_FILE_NAME, Dt as InvalidEditProblems, Ft as LORE_SCOPES, G as listWorldPrompts, K as readWorldPrompt, Mt as parseRelationEdit, Nt as parseThingEdit, Ot as parseCharacterEdit, Pt as LORE_KINDS, Q as IMPORT_FOLDER, W as deleteWorldPrompt, X as partsOf, Z as withPlayer, a as isPresetName, c as presetDirectory, d as savePresetFromWorld, dt as parseVariablesFile, et as ImportStore, ft as variableProblems, i as deletePreset, jt as parsePlaceEdit, kt as parseFactionEdit, lt as VARIABLES_FILE_NAME, o as listPresets, ot as IMPORT_COMMAND, p as updatePresetInfo, q as writeWorldPrompt, r as createPresetFromShipped, rt as parseChoices, s as loadPreset, t as PRESET_FILE$1, u as reservePreset, ut as loadVariables, wt as parseCharacterFile } from "./presets-
|
|
1
|
+
import { a as VARIABLE_KINDS, c as chatSessionId, i as atomicWriteSync, l as roleplaySessionOf, n as atomicWrite, o as VARIABLE_SUBJECTS, r as atomicWriteJson, s as VARIABLE_VISIBILITIES } from "./access-CXtaZNbx.js";
|
|
2
|
+
import { $ as parseWorldFile, $t as pictureOf, At as routineProblems, B as readOrigin, C as readWorldInfo, Ct as populateItems, Dt as populateRoutines, Et as populateLore, Gt as loadCalendar, H as CatalogueError, Ht as loadDice, I as describeChanges, It as loadLocations, Jt as loadCharacters, Kt as parseCalendarFile, L as hashWorld, Ot as populateTriggers, Q as WORLD_FILE_NAME, Qt as isPng, R as isUnchanged, Rt as loadItems, S as editWorldInfo, St as populateFactions, Tt as populateLocations, Ut as parseDiceFile, V as writeOrigin, Vt as DICE_FILE_NAME, Wt as CALENDAR_FILE_NAME, Xt as knownOutputCeiling, Y as vetUrl, Yt as subfolders, Zt as ImportCardError, _t as knowsCharacter, at as entriesOf, bt as populateClock, c as importPhase, ct as loadLorebook, d as markReady, dt as reserveLorebook, en as readCard, et as parseWorldInfoEdit, f as settleDraft, ft as updateLorebookInfo, ht as loadValidatedWorld, in as authoredWorldOf, it as deleteLorebookEntry, jt as TRIGGERS_FILE_NAME, kt as populateVariables, lt as lorebookDirectory, mt as checkWorld, nn as DICE_READINGS, nt as createLorebook, ot as isLorebookName, p as structureImport, pt as writeLorebookEntry, q as guardedLookup, qt as CHARACTERS_DIR, rn as DICE_RESULTS, rt as deleteLorebook, st as listLorebooks, t as AuthoringTools, tn as DICE_COMPARISONS, tt as addLorebookEntries, u as keepDraft, vt as populateCalendar, w as loadWorldParts, wt as populateKnowledge, xt as populateDice, yt as populateCharacters, z as localChanges } from "./authoring-tools-B4mEdKp_.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-BCFFJSle.js";
|
|
4
|
+
import { a as presetChatSessionId, n as narrationImportMessage, o as presetOfChat } from "./preset-author-tools-RSta6pHK.js";
|
|
5
|
+
import { a as liveSettings, c as writeSettings, d as parseSettings, i as InvalidSettingsError, l as DEFAULT_SETTINGS, o as readSettings, p as WORLD_RULES_KEY, s as useChildReasoning, u as SETTINGS_SPEC } from "./narration-BVzew4-K.js";
|
|
6
|
+
import { $ as DOCTOR_OPENING_SOURCE, A as worldEntityImageFile, B as languageOfDocuments, C as readWorldEditor, D as uploadWorldCharacterPortrait, E as replaceFile, F as PRESET_FILE, G as revertUpdate, H as findTargets, I as presetMessage, J as AuthoringSessions, K as startUpdate, O as uploadWorldEntityImage, Q as agentServicesOf, R as translateMessage, S as generateWorldEntityImage, T as removeWorldTrigger, V as readWorldDocuments, X as ensureAuthoringChat, Y as authoringTitle, Z as AgentSessions, _ as editWorldPlots$1, a as deleteWorldPackFile, b as entityFolder, c as createAuthoredEntity, et as appendEmptyTurn, 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, q as updateStatus, t as MAX_PACK_TEXT, tt as appendNarratedTurn, u as readAuthoredEntityDocument, v as editWorldRelation$1, w as readWorldTrigger, x as generateWorldCharacterPortrait, y as editWorldThing$1 } from "./pack-jail-hsNQNTOf.js";
|
|
7
|
+
import { d as sharedSamplingOf, i as childSamplingOf, u as parseSampling } from "./child-Dtv76jNx.js";
|
|
8
|
+
import { $ as PromptLibrary, C as notesOfSession, H as parsePlotsFile, M as PLOTS_METADATA_KEY, N as plotProgressOf, P as populatePlots, S as addToNote, T as observeAsPlayer, U as plotReferenceProblems, W as COMMANDS_KEY, X as errorMessage, Y as formatIssue, _ as readRunDetail, at as shippedLanguages, ct as AgentUnavailableError, dt as ReflectionRefusedError, et as copyWorldPrompts, ft as SessionArchivedError, g as readActivity, h as readDecisionStats, i as externalTools, k as zoneOf, lt as InvalidStartError, m as readUsage, mt as WorldNotFoundError, nt as languageOf, pt as SessionNotFoundError, q as readDocument, ut as InvalidWorldError, v as readTraces, w as readNotes, x as readWithdrawn } from "./hooks-DTjHWTfx.js";
|
|
9
|
+
import { $ as ImportNotFoundError, At as parseLoreEdit, Ct as CHARACTER_FILE_NAME, Dt as InvalidEditProblems, Ft as LORE_SCOPES, G as listWorldPrompts, K as readWorldPrompt, Mt as parseRelationEdit, Nt as parseThingEdit, Ot as parseCharacterEdit, Pt as LORE_KINDS, Q as IMPORT_FOLDER, W as deleteWorldPrompt, X as partsOf, Z as withPlayer, a as isPresetName, c as presetDirectory, d as savePresetFromWorld, dt as parseVariablesFile, et as ImportStore, ft as variableProblems, i as deletePreset, jt as parsePlaceEdit, kt as parseFactionEdit, lt as VARIABLES_FILE_NAME, o as listPresets, ot as IMPORT_COMMAND, p as updatePresetInfo, q as writeWorldPrompt, r as createPresetFromShipped, rt as parseChoices, s as loadPreset, t as PRESET_FILE$1, u as reservePreset, ut as loadVariables, wt as parseCharacterFile } from "./presets-CvpsW_10.js";
|
|
10
10
|
import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-CbGQhK1-.js";
|
|
11
|
-
import { n as readPreset, r as selectPrompts, t as previewPreset } from "./preset-
|
|
12
|
-
import { C as slug, T as uniqueKey, d as sceneImagePath, s as inheritImages, t as addToLibrary, u as referenceImagePath } from "./library-
|
|
11
|
+
import { n as readPreset, r as selectPrompts, t as previewPreset } from "./preset-Cyoj1ZWa.js";
|
|
12
|
+
import { C as slug, T as uniqueKey, d as sceneImagePath, s as inheritImages, t as addToLibrary, u as referenceImagePath } from "./library-GIlrkOim.js";
|
|
13
13
|
import { t as doctorChatSessionId } from "./doctor-chat-hL1a61hp.js";
|
|
14
|
-
import { c as readTimeline, d as copyPreset, f as presetStatus, h as defaultBoundaries, i as reflectionStatus, l as writeTimeline, m as switchPreset, o as TimelineError, p as recordPreset, u as pathTo } from "./reflection-
|
|
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-
|
|
16
|
-
import { a as uploadReferenceImage, t as generateReferenceImage } from "./generator-
|
|
17
|
-
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-
|
|
14
|
+
import { c as readTimeline, d as copyPreset, f as presetStatus, h as defaultBoundaries, i as reflectionStatus, l as writeTimeline, m as switchPreset, o as TimelineError, p as recordPreset, u as pathTo } from "./reflection-0qTvw2It.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-UpK_cvI4.js";
|
|
16
|
+
import { a as uploadReferenceImage, t as generateReferenceImage } from "./generator-Cg6CQc5S.js";
|
|
17
|
+
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-BZJleAeH.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";
|
|
@@ -570,7 +570,7 @@ async function lorebookLore(root, names, chosen, knows, taken) {
|
|
|
570
570
|
function lorebooksOf(session) {
|
|
571
571
|
return session.metadata.getValue("roleplay.lorebooks") ?? [];
|
|
572
572
|
}
|
|
573
|
-
const keyOf$
|
|
573
|
+
const keyOf$4 = (entry) => entry.sourceId ?? String(entry.id);
|
|
574
574
|
/**
|
|
575
575
|
* Copies a library lorebook into a story that is already being played. The characters that know an entry learn it at the story's current turn.
|
|
576
576
|
* @throws {Error} when the story already has the book or the book cannot be used.
|
|
@@ -603,12 +603,12 @@ function removeLorebook(session, name) {
|
|
|
603
603
|
const ids = new Set(leaving.map((entry) => entry.id));
|
|
604
604
|
const citing = all.filter((entry) => !ids.has(entry.id) && (entry.related.some((id) => ids.has(id)) || entry.subjects.some((subject) => subject.kind === "lore" && ids.has(subject.id)))).map((entry) => entry.title);
|
|
605
605
|
if (citing.length > 0) throw new Error(`other lore refers to entries of this lorebook: ${citing.join(", ")}`);
|
|
606
|
-
const remaining = all.filter((entry) => !ids.has(entry.id)).map(keyOf$
|
|
606
|
+
const remaining = all.filter((entry) => !ids.has(entry.id)).map(keyOf$4);
|
|
607
607
|
const plots = plotReferenceProblems(plotProgressOf(session.metadata).map((progress) => progress.plot), [
|
|
608
|
-
...session.characters.list().map(keyOf$
|
|
609
|
-
...session.factions.list().map(keyOf$
|
|
610
|
-
...session.locations.list().map(keyOf$
|
|
611
|
-
...session.items.list().map(keyOf$
|
|
608
|
+
...session.characters.list().map(keyOf$4),
|
|
609
|
+
...session.factions.list().map(keyOf$4),
|
|
610
|
+
...session.locations.list().map(keyOf$4),
|
|
611
|
+
...session.items.list().map(keyOf$4),
|
|
612
612
|
...remaining
|
|
613
613
|
]);
|
|
614
614
|
if (plots.length > 0) throw new Error(`a plot refers to entries of this lorebook: ${plots.join("; ")}`);
|
|
@@ -840,6 +840,8 @@ var RoleplayOrchestration = class extends Service {
|
|
|
840
840
|
halt = () => Promise.resolve();
|
|
841
841
|
/** Starts a reflection of a chat's characters on what they have taken in, in the background; there while the orchestration is. */
|
|
842
842
|
reflect = () => Promise.reject(/* @__PURE__ */ new Error("the orchestration is not running"));
|
|
843
|
+
/** What a moment would bring back for the chat's characters, without playing it or changing the story; there while the orchestration is. */
|
|
844
|
+
recallPreview = () => Promise.reject(/* @__PURE__ */ new Error("the orchestration is not running"));
|
|
843
845
|
/** Whether a turn of the chat is being played; there while the orchestration is. */
|
|
844
846
|
playing = () => false;
|
|
845
847
|
/** Whether a reflection of the chat is running; there while the orchestration is. */
|
|
@@ -1650,7 +1652,7 @@ function withBridge(html) {
|
|
|
1650
1652
|
return `${script}${html}`;
|
|
1651
1653
|
}
|
|
1652
1654
|
// src/host/interface/player-view.ts
|
|
1653
|
-
const keyOf$
|
|
1655
|
+
const keyOf$3 = (character) => character.sourceId ?? String(character.id);
|
|
1654
1656
|
/** What a variable shows, in one line of data. */
|
|
1655
1657
|
function shown(subject, entries) {
|
|
1656
1658
|
return entries.map(({ variable, value }) => ({
|
|
@@ -1697,12 +1699,12 @@ function playerViewOf(session, options) {
|
|
|
1697
1699
|
if (player === void 0) return finish(view, session);
|
|
1698
1700
|
const playerState = session.characterStates.get(player.id);
|
|
1699
1701
|
view.player = {
|
|
1700
|
-
key: keyOf$
|
|
1702
|
+
key: keyOf$3(player),
|
|
1701
1703
|
name: player.name,
|
|
1702
1704
|
summary: player.summary,
|
|
1703
1705
|
publicState: playerState?.publicState ?? ""
|
|
1704
1706
|
};
|
|
1705
|
-
view.variables.push(...shown(player.name, shownVariables(session, "character", player.id, keyOf$
|
|
1707
|
+
view.variables.push(...shown(player.name, shownVariables(session, "character", player.id, keyOf$3(player), "others")));
|
|
1706
1708
|
const placement = session.placements.get("character", player.id);
|
|
1707
1709
|
const here = placement === void 0 ? void 0 : session.locations.get(placement.locationId);
|
|
1708
1710
|
const known = new Set(session.knowledge.list(player.id, "location").map((entry) => entry.subjectId));
|
|
@@ -1733,7 +1735,7 @@ function playerViewOf(session, options) {
|
|
|
1733
1735
|
here: session.placements.at(here.id, "character").flatMap((other) => {
|
|
1734
1736
|
const character = other.entityId === player.id ? void 0 : session.characters.get(other.entityId);
|
|
1735
1737
|
return character === void 0 ? [] : [{
|
|
1736
|
-
key: keyOf$
|
|
1738
|
+
key: keyOf$3(character),
|
|
1737
1739
|
name: character.name,
|
|
1738
1740
|
publicState: session.characterStates.get(character.id)?.publicState ?? ""
|
|
1739
1741
|
}];
|
|
@@ -1741,7 +1743,7 @@ function playerViewOf(session, options) {
|
|
|
1741
1743
|
};
|
|
1742
1744
|
view.variables.push(...shown(here.name, shownVariables(session, "location", here.id, locationKey(here), "others")));
|
|
1743
1745
|
for (const other of view.place.here) {
|
|
1744
|
-
const character = session.characters.list().find((candidate) => keyOf$
|
|
1746
|
+
const character = session.characters.list().find((candidate) => keyOf$3(candidate) === other.key);
|
|
1745
1747
|
if (character !== void 0) view.variables.push(...shown(character.name, shownVariables(session, "character", character.id, other.key, "others")));
|
|
1746
1748
|
}
|
|
1747
1749
|
for (const entry of session.items.contents({
|
|
@@ -1847,13 +1849,13 @@ async function previewViewOf(world, wall) {
|
|
|
1847
1849
|
}
|
|
1848
1850
|
}
|
|
1849
1851
|
// src/host/interface/storage.ts
|
|
1850
|
-
const keyOf$
|
|
1852
|
+
const keyOf$2 = (pack) => `roleplay.interface.${pack}`;
|
|
1851
1853
|
function checkedKey(key) {
|
|
1852
1854
|
if (key === "" || key.length > 100) throw new RangeError("a key is 1 to 100 characters");
|
|
1853
1855
|
return key;
|
|
1854
1856
|
}
|
|
1855
1857
|
function read(session, pack) {
|
|
1856
|
-
const stored = session.metadata.getValue(keyOf$
|
|
1858
|
+
const stored = session.metadata.getValue(keyOf$2(pack));
|
|
1857
1859
|
return typeof stored === "object" && stored !== null && !Array.isArray(stored) ? stored : {};
|
|
1858
1860
|
}
|
|
1859
1861
|
/** What a pack keeps in a session: small JSON values by name. */
|
|
@@ -1880,12 +1882,12 @@ var PackStorage = class {
|
|
|
1880
1882
|
throw new RangeError("a stored value must be JSON");
|
|
1881
1883
|
}
|
|
1882
1884
|
if (Buffer.byteLength(json) > PACK_LIMITS.storageBytes) throw new RangeError(`a pack keeps at most ${PACK_LIMITS.storageBytes / 1024} KB in a story`);
|
|
1883
|
-
this.session.metadata.setValue(keyOf$
|
|
1885
|
+
this.session.metadata.setValue(keyOf$2(this.pack), next);
|
|
1884
1886
|
}
|
|
1885
1887
|
remove(key) {
|
|
1886
1888
|
checkedKey(key);
|
|
1887
1889
|
const { [key]: _removed, ...rest } = read(this.session, this.pack);
|
|
1888
|
-
this.session.metadata.setValue(keyOf$
|
|
1890
|
+
this.session.metadata.setValue(keyOf$2(this.pack), rest);
|
|
1889
1891
|
}
|
|
1890
1892
|
};
|
|
1891
1893
|
// src/host/interface/service.ts
|
|
@@ -3690,6 +3692,268 @@ function worldFilesRoutes({ worldFiles, worldEditor, sessions }) {
|
|
|
3690
3692
|
]))
|
|
3691
3693
|
};
|
|
3692
3694
|
}
|
|
3695
|
+
// src/shared/journal.ts
|
|
3696
|
+
/** The most a journal may hold. */
|
|
3697
|
+
const MAX_JOURNAL = 2e4;
|
|
3698
|
+
// src/host/reference/journal.ts
|
|
3699
|
+
const JOURNAL_FILE = "journal.json";
|
|
3700
|
+
var InvalidJournalError = class extends Error {};
|
|
3701
|
+
function folderOf$2(sessionsDir, id) {
|
|
3702
|
+
if (!isSessionId(id) || !existsSync(sessionDatabase(sessionsDir, id))) throw new SessionNotFoundError(`no session "${id}"`);
|
|
3703
|
+
return sessionFolder(sessionsDir, id);
|
|
3704
|
+
}
|
|
3705
|
+
/**
|
|
3706
|
+
* The player's notes. They sit beside the database, so taking the story back does not touch them and a branch starts with a copy.
|
|
3707
|
+
* @throws {SessionNotFoundError} when the id names no session.
|
|
3708
|
+
*/
|
|
3709
|
+
async function readJournal(sessionsDir, id) {
|
|
3710
|
+
const file = join(folderOf$2(sessionsDir, id), JOURNAL_FILE);
|
|
3711
|
+
let value;
|
|
3712
|
+
try {
|
|
3713
|
+
value = JSON.parse(await readFile(file, "utf8"));
|
|
3714
|
+
} catch (error) {
|
|
3715
|
+
if (error.code === "ENOENT") return { text: "" };
|
|
3716
|
+
throw error;
|
|
3717
|
+
}
|
|
3718
|
+
const { text, updatedAt } = value ?? {};
|
|
3719
|
+
return {
|
|
3720
|
+
text: typeof text === "string" ? text : "",
|
|
3721
|
+
...typeof updatedAt === "string" ? { updatedAt } : {}
|
|
3722
|
+
};
|
|
3723
|
+
}
|
|
3724
|
+
/** @throws {InvalidJournalError} for text that is not a string or is over `MAX_JOURNAL`. */
|
|
3725
|
+
async function writeJournal(sessionsDir, id, body, now = () => /* @__PURE__ */ new Date()) {
|
|
3726
|
+
const folder = folderOf$2(sessionsDir, id);
|
|
3727
|
+
const text = body?.text;
|
|
3728
|
+
if (typeof text !== "string") throw new InvalidJournalError("the journal needs a text");
|
|
3729
|
+
if (text.length > 2e4) throw new InvalidJournalError(`the journal may hold at most ${MAX_JOURNAL} characters`);
|
|
3730
|
+
const journal = {
|
|
3731
|
+
text,
|
|
3732
|
+
updatedAt: now().toISOString()
|
|
3733
|
+
};
|
|
3734
|
+
await atomicWriteJson(join(folder, JOURNAL_FILE), journal);
|
|
3735
|
+
return journal;
|
|
3736
|
+
}
|
|
3737
|
+
// src/shared/reference.ts
|
|
3738
|
+
/** The pages of the reference: what the player may look up about the story, never what only the story knows. */
|
|
3739
|
+
const REFERENCE_SECTIONS = [
|
|
3740
|
+
"profile",
|
|
3741
|
+
"people",
|
|
3742
|
+
"places",
|
|
3743
|
+
"things"
|
|
3744
|
+
];
|
|
3745
|
+
const isReferenceSection = (value) => REFERENCE_SECTIONS.includes(value);
|
|
3746
|
+
// src/host/reference/profile.ts
|
|
3747
|
+
const keyOf$1 = (character) => character.sourceId ?? String(character.id);
|
|
3748
|
+
const BLOCKS = [
|
|
3749
|
+
{
|
|
3750
|
+
audiences: ["self", "observer"],
|
|
3751
|
+
build: (session, character, audience) => {
|
|
3752
|
+
const state = session.characterStates.get(character.id);
|
|
3753
|
+
return {
|
|
3754
|
+
aliases: character.aliases,
|
|
3755
|
+
...character.age === void 0 || character.age === null ? {} : { age: character.age },
|
|
3756
|
+
...character.gender === void 0 || character.gender === null ? {} : { gender: character.gender },
|
|
3757
|
+
...character.pronouns === void 0 || character.pronouns === null ? {} : { pronouns: character.pronouns },
|
|
3758
|
+
appearance: character.appearance,
|
|
3759
|
+
publicState: state?.publicState ?? "",
|
|
3760
|
+
values: shownVariables(session, "character", character.id, keyOf$1(character), audience === "self" ? "self" : "others").map(({ variable, value }) => ({
|
|
3761
|
+
name: variable.name,
|
|
3762
|
+
value: describeValue(variable, value)
|
|
3763
|
+
}))
|
|
3764
|
+
};
|
|
3765
|
+
}
|
|
3766
|
+
},
|
|
3767
|
+
{
|
|
3768
|
+
audiences: ["self"],
|
|
3769
|
+
build: (session, character) => {
|
|
3770
|
+
const state = session.characterStates.get(character.id);
|
|
3771
|
+
const groups = session.factionMemberships.ofCharacter(character.id, "active").flatMap((membership) => {
|
|
3772
|
+
const faction = session.factions.get(membership.factionId);
|
|
3773
|
+
return faction === void 0 ? [] : [{
|
|
3774
|
+
name: faction.name,
|
|
3775
|
+
role: membership.role
|
|
3776
|
+
}];
|
|
3777
|
+
});
|
|
3778
|
+
return {
|
|
3779
|
+
summary: character.summary,
|
|
3780
|
+
personality: character.personality,
|
|
3781
|
+
background: character.background,
|
|
3782
|
+
speech: character.speech,
|
|
3783
|
+
innerState: state?.innerState ?? "",
|
|
3784
|
+
activity: state?.activity ?? "",
|
|
3785
|
+
groups,
|
|
3786
|
+
goals: session.intents.list(character.id, { status: "active" }).map((intent) => ({
|
|
3787
|
+
name: intent.name,
|
|
3788
|
+
description: intent.description,
|
|
3789
|
+
status: intent.status,
|
|
3790
|
+
plan: intent.plan,
|
|
3791
|
+
...intent.deadline === void 0 ? {} : { deadline: intent.deadline }
|
|
3792
|
+
}))
|
|
3793
|
+
};
|
|
3794
|
+
}
|
|
3795
|
+
},
|
|
3796
|
+
{
|
|
3797
|
+
audiences: ["self"],
|
|
3798
|
+
build: (session, character) => {
|
|
3799
|
+
const recollections = session.events.perceivedBy(character.id).sort((a, b) => b.event.turn - a.event.turn || b.event.round - a.event.round);
|
|
3800
|
+
const beliefs = session.memories.list(character.id).sort((a, b) => b.turn - a.turn);
|
|
3801
|
+
return {
|
|
3802
|
+
recollections: recollections.slice(0, 100).map(({ perception, event }) => ({
|
|
3803
|
+
text: perception.content,
|
|
3804
|
+
gist: perception.gist,
|
|
3805
|
+
mode: perception.mode,
|
|
3806
|
+
turn: event.turn
|
|
3807
|
+
})),
|
|
3808
|
+
beliefs: beliefs.slice(0, 100).map((memory) => ({
|
|
3809
|
+
text: memory.text,
|
|
3810
|
+
kind: memory.kind,
|
|
3811
|
+
confidence: memory.confidence,
|
|
3812
|
+
turn: memory.turn
|
|
3813
|
+
})),
|
|
3814
|
+
totals: {
|
|
3815
|
+
recollections: recollections.length,
|
|
3816
|
+
beliefs: beliefs.length
|
|
3817
|
+
}
|
|
3818
|
+
};
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
];
|
|
3822
|
+
/** A character as the audience may see them: only the blocks that audience is allowed. */
|
|
3823
|
+
function profileOf(session, character, audience) {
|
|
3824
|
+
const profile = {
|
|
3825
|
+
key: keyOf$1(character),
|
|
3826
|
+
name: character.name,
|
|
3827
|
+
audience,
|
|
3828
|
+
aliases: [],
|
|
3829
|
+
appearance: "",
|
|
3830
|
+
publicState: "",
|
|
3831
|
+
values: []
|
|
3832
|
+
};
|
|
3833
|
+
for (const block of BLOCKS) if (block.audiences.includes(audience)) Object.assign(profile, block.build(session, character, audience));
|
|
3834
|
+
return profile;
|
|
3835
|
+
}
|
|
3836
|
+
// src/host/reference/reference.ts
|
|
3837
|
+
var UnknownSectionError = class extends Error {};
|
|
3838
|
+
/** Where the player's character is and what it has met or learned of: the only ground a page may read from. */
|
|
3839
|
+
function standpoint(session) {
|
|
3840
|
+
const player = session.characters.list().find((character) => character.control === "player");
|
|
3841
|
+
if (player === void 0) return void 0;
|
|
3842
|
+
const placement = session.placements.get("character", player.id);
|
|
3843
|
+
return {
|
|
3844
|
+
player,
|
|
3845
|
+
here: placement === void 0 ? void 0 : session.locations.get(placement.locationId)
|
|
3846
|
+
};
|
|
3847
|
+
}
|
|
3848
|
+
/**
|
|
3849
|
+
* The player's character in full, or another character the player has met or is with, as an observer sees them.
|
|
3850
|
+
* Anyone the player's character has not met is not shown.
|
|
3851
|
+
*/
|
|
3852
|
+
function profile(session, options) {
|
|
3853
|
+
const stand = standpoint(session);
|
|
3854
|
+
if (stand === void 0) return [];
|
|
3855
|
+
if (options.character === void 0 || options.character === keyOf$1(stand.player)) return [profileOf(session, stand.player, "self")];
|
|
3856
|
+
const other = people(session).some((person) => person.key === options.character) ? session.characters.list().find((character) => keyOf$1(character) === options.character) : void 0;
|
|
3857
|
+
return other === void 0 ? [] : [profileOf(session, other, "observer")];
|
|
3858
|
+
}
|
|
3859
|
+
function people(session) {
|
|
3860
|
+
const stand = standpoint(session);
|
|
3861
|
+
if (stand === void 0) return [];
|
|
3862
|
+
const present = new Set(stand.here === void 0 ? [] : session.placements.at(stand.here.id, "character").map((entry) => entry.entityId));
|
|
3863
|
+
const met = new Map(session.relationships.from(stand.player.id).map((relation) => [relation.toId, relation]));
|
|
3864
|
+
return session.characters.list().flatMap((character) => {
|
|
3865
|
+
if (character.id === stand.player.id || !present.has(character.id) && !met.has(character.id)) return [];
|
|
3866
|
+
const relation = met.get(character.id);
|
|
3867
|
+
return [{
|
|
3868
|
+
key: keyOf$1(character),
|
|
3869
|
+
name: character.name,
|
|
3870
|
+
publicState: session.characterStates.get(character.id)?.publicState ?? "",
|
|
3871
|
+
here: present.has(character.id),
|
|
3872
|
+
...relation === void 0 ? {} : {
|
|
3873
|
+
label: relation.label,
|
|
3874
|
+
summary: relation.summary
|
|
3875
|
+
}
|
|
3876
|
+
}];
|
|
3877
|
+
}).sort((a, b) => Number(b.here) - Number(a.here) || a.name.localeCompare(b.name));
|
|
3878
|
+
}
|
|
3879
|
+
function places(session) {
|
|
3880
|
+
const stand = standpoint(session);
|
|
3881
|
+
if (stand === void 0) return [];
|
|
3882
|
+
const known = new Set(session.knowledge.list(stand.player.id, "location").map((entry) => entry.subjectId));
|
|
3883
|
+
if (stand.here !== void 0) known.add(stand.here.id);
|
|
3884
|
+
const knownExits = new Set(session.knowledge.list(stand.player.id, "exit").map((entry) => entry.subjectId));
|
|
3885
|
+
const exits = session.locations.allExits();
|
|
3886
|
+
const placeOf = (id) => known.has(id) ? session.locations.get(id) : void 0;
|
|
3887
|
+
const nameOf = (id) => placeOf(id)?.name;
|
|
3888
|
+
return [...known].flatMap((id) => {
|
|
3889
|
+
const place = session.locations.get(id);
|
|
3890
|
+
if (place === void 0) return [];
|
|
3891
|
+
const here = place.id === stand.here?.id;
|
|
3892
|
+
const parent = place.parentId === void 0 ? void 0 : nameOf(place.parentId);
|
|
3893
|
+
return [{
|
|
3894
|
+
key: locationKey(place),
|
|
3895
|
+
name: place.name,
|
|
3896
|
+
here,
|
|
3897
|
+
...parent === void 0 ? {} : { parent },
|
|
3898
|
+
...here ? { description: place.description } : {},
|
|
3899
|
+
features: here ? place.features.map((feature) => feature.name) : [],
|
|
3900
|
+
ways: exits.filter((exit) => exit.fromId === place.id && (here || knownExits.has(exit.id))).flatMap((exit) => {
|
|
3901
|
+
const to = placeOf(exit.toId);
|
|
3902
|
+
return to === void 0 ? [] : [{
|
|
3903
|
+
to: to.name,
|
|
3904
|
+
toKey: locationKey(to),
|
|
3905
|
+
open: exit.state === "open"
|
|
3906
|
+
}];
|
|
3907
|
+
})
|
|
3908
|
+
}];
|
|
3909
|
+
}).sort((a, b) => Number(b.here) - Number(a.here) || a.name.localeCompare(b.name));
|
|
3910
|
+
}
|
|
3911
|
+
function things(session) {
|
|
3912
|
+
const stand = standpoint(session);
|
|
3913
|
+
if (stand === void 0) return [];
|
|
3914
|
+
const carried = session.items.contents({
|
|
3915
|
+
kind: "character",
|
|
3916
|
+
id: stand.player.id
|
|
3917
|
+
}).filter((entry) => !entry.item.hidden).map((entry) => {
|
|
3918
|
+
const holder = entry.holding.holder;
|
|
3919
|
+
return {
|
|
3920
|
+
name: entry.item.name,
|
|
3921
|
+
quantity: entry.item.quantity,
|
|
3922
|
+
where: holder.kind === "character" && holder.mode === "worn" ? "worn" : "carried"
|
|
3923
|
+
};
|
|
3924
|
+
});
|
|
3925
|
+
const around = stand.here === void 0 ? [] : session.items.contents({
|
|
3926
|
+
kind: "location",
|
|
3927
|
+
id: stand.here.id
|
|
3928
|
+
}).filter((entry) => !entry.item.hidden).map((entry) => ({
|
|
3929
|
+
name: entry.item.name,
|
|
3930
|
+
quantity: entry.item.quantity,
|
|
3931
|
+
where: "here"
|
|
3932
|
+
}));
|
|
3933
|
+
return [...carried, ...around];
|
|
3934
|
+
}
|
|
3935
|
+
/** One page per section; a new page is a new entry here and in `REFERENCE_SECTIONS`. */
|
|
3936
|
+
const PAGES = {
|
|
3937
|
+
profile,
|
|
3938
|
+
people,
|
|
3939
|
+
places,
|
|
3940
|
+
things
|
|
3941
|
+
};
|
|
3942
|
+
function referencePage(session, section, options = {}) {
|
|
3943
|
+
if (!isReferenceSection(section)) throw new UnknownSectionError(`no reference section "${section}"`);
|
|
3944
|
+
return {
|
|
3945
|
+
section,
|
|
3946
|
+
entries: PAGES[section](session, options)
|
|
3947
|
+
};
|
|
3948
|
+
}
|
|
3949
|
+
/** @throws {SessionNotFoundError} when the id names no session. */
|
|
3950
|
+
function referenceOfSession(deps, id, section, options = {}) {
|
|
3951
|
+
if (!isSessionId(id) || !existsSync(sessionDatabase(deps.sessionsDir(), id))) throw new SessionNotFoundError(`no session "${id}"`);
|
|
3952
|
+
return referencePage(deps.open(id), section, options);
|
|
3953
|
+
}
|
|
3954
|
+
// src/shared/recall-preview.ts
|
|
3955
|
+
/** The longest situation accepted. */
|
|
3956
|
+
const MAX_SITUATION = 4e3;
|
|
3693
3957
|
// src/host/http/routes/sessions.ts
|
|
3694
3958
|
/** The routes of the API for sessions. */
|
|
3695
3959
|
function sessionsRoutes({ sessions, externalTools, redundantLayers }) {
|
|
@@ -3794,6 +4058,35 @@ function sessionsRoutes({ sessions, externalTools, redundantLayers }) {
|
|
|
3794
4058
|
throw error;
|
|
3795
4059
|
}
|
|
3796
4060
|
} },
|
|
4061
|
+
"/sessions/reference": { GET: async (_req, res, url) => {
|
|
4062
|
+
try {
|
|
4063
|
+
sendJson(res, 200, sessions.reference(url.searchParams.get("id") ?? "", url.searchParams.get("section") ?? "", url.searchParams.get("character") ?? void 0));
|
|
4064
|
+
} catch (error) {
|
|
4065
|
+
if (error instanceof SessionNotFoundError) return sendError(res, 404, error.message);
|
|
4066
|
+
if (error instanceof UnknownSectionError) return sendError(res, 400, error.message);
|
|
4067
|
+
throw error;
|
|
4068
|
+
}
|
|
4069
|
+
} },
|
|
4070
|
+
"/sessions/journal": {
|
|
4071
|
+
GET: async (_req, res, url) => {
|
|
4072
|
+
try {
|
|
4073
|
+
sendJson(res, 200, await sessions.readJournal(url.searchParams.get("id") ?? ""));
|
|
4074
|
+
} catch (error) {
|
|
4075
|
+
if (error instanceof SessionNotFoundError) return sendError(res, 404, error.message);
|
|
4076
|
+
throw error;
|
|
4077
|
+
}
|
|
4078
|
+
},
|
|
4079
|
+
PUT: async (req, res, url) => {
|
|
4080
|
+
const body = await readJsonBody(req);
|
|
4081
|
+
try {
|
|
4082
|
+
sendJson(res, 200, await sessions.writeJournal(url.searchParams.get("id") ?? "", body));
|
|
4083
|
+
} catch (error) {
|
|
4084
|
+
if (error instanceof SessionNotFoundError) return sendError(res, 404, error.message);
|
|
4085
|
+
if (error instanceof InvalidJournalError) return sendError(res, 422, error.message);
|
|
4086
|
+
throw error;
|
|
4087
|
+
}
|
|
4088
|
+
}
|
|
4089
|
+
},
|
|
3797
4090
|
"/sessions/images": {
|
|
3798
4091
|
GET: async (_req, res, url) => {
|
|
3799
4092
|
try {
|
|
@@ -3943,6 +4236,30 @@ function sessionsRoutes({ sessions, externalTools, redundantLayers }) {
|
|
|
3943
4236
|
res.statusCode = 202;
|
|
3944
4237
|
res.end();
|
|
3945
4238
|
} },
|
|
4239
|
+
"/sessions/recall": { POST: async (req, res, url) => {
|
|
4240
|
+
const body = await readJsonBody(req);
|
|
4241
|
+
if (typeof body.situation !== "string" || body.situation.trim() === "") return sendError(res, 400, "a situation is needed");
|
|
4242
|
+
if (body.situation.length > 4e3) return sendError(res, 413, `the situation is longer than ${MAX_SITUATION} characters`);
|
|
4243
|
+
if (body.character !== void 0 && typeof body.character !== "string") return sendError(res, 400, "character must be a key");
|
|
4244
|
+
const abort = new AbortController();
|
|
4245
|
+
req.on("aborted", () => {
|
|
4246
|
+
abort.abort();
|
|
4247
|
+
});
|
|
4248
|
+
res.on("close", () => {
|
|
4249
|
+
if (!res.writableEnded) abort.abort();
|
|
4250
|
+
});
|
|
4251
|
+
try {
|
|
4252
|
+
sendJson(res, 200, await sessions.recallPreview(url.searchParams.get("id") ?? "", {
|
|
4253
|
+
situation: body.situation,
|
|
4254
|
+
...body.character === void 0 ? {} : { character: body.character }
|
|
4255
|
+
}, abort.signal));
|
|
4256
|
+
} catch (error) {
|
|
4257
|
+
if (error instanceof SessionNotFoundError) return sendError(res, 404, error.message);
|
|
4258
|
+
if (error instanceof AgentUnavailableError) return sendError(res, 503, error.message);
|
|
4259
|
+
if (error instanceof Error && /^no character /.test(error.message)) return sendError(res, 422, error.message);
|
|
4260
|
+
throw error;
|
|
4261
|
+
}
|
|
4262
|
+
} },
|
|
3946
4263
|
"/sessions/vectors/reset": { POST: async (_req, res, url) => {
|
|
3947
4264
|
try {
|
|
3948
4265
|
sessions.resetVectors(url.searchParams.get("id") ?? "");
|
|
@@ -5794,6 +6111,7 @@ function payloadOf(deps, id, settings) {
|
|
|
5794
6111
|
pendingConsolidation: deps.pendingConsolidation(id),
|
|
5795
6112
|
activity: deps.activity(id),
|
|
5796
6113
|
usage: deps.usage(id),
|
|
6114
|
+
trace: deps.trace(id),
|
|
5797
6115
|
interventions: deps.interventions(id),
|
|
5798
6116
|
vectors: deps.vectors(id),
|
|
5799
6117
|
reflection: deps.reflection(id),
|
|
@@ -7349,9 +7667,7 @@ function readStore(root) {
|
|
|
7349
7667
|
function writeStore(root, store) {
|
|
7350
7668
|
const folder = syncFolder(root);
|
|
7351
7669
|
mkdirSync(folder, { recursive: true });
|
|
7352
|
-
|
|
7353
|
-
writeFileSync(temporary, `${JSON.stringify(store, null, 2)}\n`);
|
|
7354
|
-
renameSync(temporary, join(folder, "state.json"));
|
|
7670
|
+
atomicWriteSync(join(folder, "state.json"), `${JSON.stringify(store, null, 2)}\n`);
|
|
7355
7671
|
}
|
|
7356
7672
|
// src/host/sync/units.ts
|
|
7357
7673
|
/** Folders of the root that are one unit each, whatever they hold. */
|
|
@@ -8313,6 +8629,7 @@ function apply(ctx, config) {
|
|
|
8313
8629
|
reflection: (id) => reflectionStatus(ctx.roleplayState.openSession(join(root.path, "sessions"), id), orchestration.reflecting(chatSessionId(id))),
|
|
8314
8630
|
activity: (id) => readActivity(ctx.roleplayState.openSession(join(root.path, "sessions"), id)),
|
|
8315
8631
|
usage: (id) => readUsage(ctx.roleplayState.openSession(join(root.path, "sessions"), id)),
|
|
8632
|
+
trace: (id) => readTraces(ctx.roleplayState.openSession(join(root.path, "sessions"), id)),
|
|
8316
8633
|
interventions: (id) => readInterventions(ctx.roleplayState.openSession(join(root.path, "sessions"), id))
|
|
8317
8634
|
};
|
|
8318
8635
|
const staging = new ImportStaging();
|
|
@@ -8703,6 +9020,12 @@ function apply(ctx, config) {
|
|
|
8703
9020
|
await agent.ensure(id, ctx.roleplayState.openSession(sessions, id).metadata.get().name);
|
|
8704
9021
|
await ctx.roleplayOrchestration.reflect(chatSessionId(id));
|
|
8705
9022
|
},
|
|
9023
|
+
recallPreview: async (id, request, signal) => {
|
|
9024
|
+
const sessions = join(root.path, "sessions");
|
|
9025
|
+
if (!isSessionId(id) || !existsSync(sessionDatabase(sessions, id))) throw new SessionNotFoundError(`no session "${id}"`);
|
|
9026
|
+
await agent.ensure(id, ctx.roleplayState.openSession(sessions, id).metadata.get().name);
|
|
9027
|
+
return ctx.roleplayOrchestration.recallPreview(chatSessionId(id), request, signal);
|
|
9028
|
+
},
|
|
8706
9029
|
resetVectors: (id) => {
|
|
8707
9030
|
const sessions = join(root.path, "sessions");
|
|
8708
9031
|
if (!isSessionId(id) || !existsSync(sessionDatabase(sessions, id))) throw new SessionNotFoundError(`no session "${id}"`);
|
|
@@ -8716,6 +9039,12 @@ function apply(ctx, config) {
|
|
|
8716
9039
|
sessionsDir: deps.sessionsDir,
|
|
8717
9040
|
open: (sessionId) => ctx.roleplayState.openSession(deps.sessionsDir(), sessionId)
|
|
8718
9041
|
}, id),
|
|
9042
|
+
reference: (id, section, character) => referenceOfSession({
|
|
9043
|
+
sessionsDir: deps.sessionsDir,
|
|
9044
|
+
open: (sessionId) => ctx.roleplayState.openSession(deps.sessionsDir(), sessionId)
|
|
9045
|
+
}, id, section, character === void 0 ? {} : { character }),
|
|
9046
|
+
readJournal: (id) => readJournal(deps.sessionsDir(), id),
|
|
9047
|
+
writeJournal: (id, body) => writeJournal(deps.sessionsDir(), id, body),
|
|
8719
9048
|
imageStatus: (id, node) => imagesOf(ctx, deps.sessionsDir, id).status(id, node),
|
|
8720
9049
|
generateImage: (id, node) => imagesOf(ctx, deps.sessionsDir, id).generate(id, node),
|
|
8721
9050
|
imageFile: async (id, node, serial) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "./access-
|
|
1
|
+
import { n as atomicWrite } from "./access-CXtaZNbx.js";
|
|
2
2
|
import { i as translator, n as withoutExtension, r as languageOf, t as trimCharacters } from "./text-CbGQhK1-.js";
|
|
3
3
|
import { dirname, extname, join } from "node:path";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
|
-
import { createHash
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
6
|
import { copyFile, link, mkdir, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
|
|
7
7
|
// src/host/import/run.ts
|
|
8
8
|
/** What `ImportContext.embed` rejects with when no embedding provider is selected or loaded: the checks that would use it go without. */
|
|
@@ -170,15 +170,10 @@ async function readImageFileMetadata(file) {
|
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
async function replaceAtomically(file, data) {
|
|
174
|
-
const temporary = `${file}.${process.pid}.${randomUUID()}.writing`;
|
|
175
|
-
await writeFile(temporary, data);
|
|
176
|
-
await rename(temporary, file);
|
|
177
|
-
}
|
|
178
173
|
/** Writes the metadata where the format keeps it, replacing what was there. */
|
|
179
174
|
async function writeImageFileMetadata(file, metadata) {
|
|
180
|
-
if (extname(file).toLowerCase() === ".png") await
|
|
181
|
-
else await
|
|
175
|
+
if (extname(file).toLowerCase() === ".png") await atomicWrite(file, withPngMetadata(await readFile(file), metadata));
|
|
176
|
+
else await atomicWrite(sidecarOf(file), `${JSON.stringify(metadata, null, 2)}\n`);
|
|
182
177
|
}
|
|
183
178
|
// src/host/images/storage.ts
|
|
184
179
|
const PLURAL = {
|
|
@@ -355,9 +350,7 @@ async function addToLibraryOnce(sessionFolder, bytes, originalName, known) {
|
|
|
355
350
|
await mkdir(directory, { recursive: true });
|
|
356
351
|
const name = libraryName(originalName, extension, (candidate) => existsSync(join(directory, candidate)));
|
|
357
352
|
const file = join(directory, name);
|
|
358
|
-
|
|
359
|
-
await writeFile(temporary, bytes);
|
|
360
|
-
await rename(temporary, file);
|
|
353
|
+
await atomicWrite(file, bytes);
|
|
361
354
|
await writeImageFileMetadata(file, {
|
|
362
355
|
schema: "dsh-roleplay-image/v3",
|
|
363
356
|
purpose: "uploaded",
|
|
@@ -381,4 +374,4 @@ async function addToLibrary(sessionFolder, bytes, originalName) {
|
|
|
381
374
|
}
|
|
382
375
|
export { slug as C, norm as S, uniqueKey as T, writeImageFileMetadata as _, LIBRARY_FOLDER as a, NoEmbeddingService as b, nextSceneSerial as c, sceneImagePath as d, writeImage as f, sidecarOf as g, readImageFileMetadata as h, libraryHashes as i, readImageMetadata as l, mediaTypeOf as m, addToLibraryOnce as n, entityImageDirectory as o, MEDIA_TYPES as p, imageExtensionOf as r, inheritImages as s, addToLibrary as t, referenceImagePath as u, readPngMetadata as v, trOf as w, mapLimit as x, withPngMetadata as y };
|
|
383
376
|
|
|
384
|
-
//# sourceMappingURL=library-
|
|
377
|
+
//# sourceMappingURL=library-GIlrkOim.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "./access-
|
|
2
|
-
import { Zt as ImportCardError, at as
|
|
3
|
-
import { Ft as LORE_SCOPES, J as cleanText, Pt as LORE_KINDS, Q as IMPORT_FOLDER, X as partsOf, Z as withPlayer, n as createPresetFromGuidance } from "./presets-
|
|
4
|
-
import { C as slug, T as uniqueKey, w as trOf, x as mapLimit } from "./library-
|
|
1
|
+
import "./access-CXtaZNbx.js";
|
|
2
|
+
import { Zt as ImportCardError, at as entriesOf, ct as loadLorebook, ft as updateLorebookInfo, i as contextOf, it as deleteLorebookEntry, lt as lorebookDirectory, pt as writeLorebookEntry, r as MAX_PREVIEW_TEXT, ut as readLorebook$1 } from "./authoring-tools-B4mEdKp_.js";
|
|
3
|
+
import { Ft as LORE_SCOPES, J as cleanText, Pt as LORE_KINDS, Q as IMPORT_FOLDER, X as partsOf, Z as withPlayer, n as createPresetFromGuidance } from "./presets-CvpsW_10.js";
|
|
4
|
+
import { C as slug, T as uniqueKey, w as trOf, x as mapLimit } from "./library-GIlrkOim.js";
|
|
5
5
|
import { i as translator, r as languageOf } from "./text-CbGQhK1-.js";
|
|
6
|
-
import {
|
|
6
|
+
import { ot as shippedPromptsDirectory } from "./hooks-DTjHWTfx.js";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { existsSync, readFileSync } from "node:fs";
|
|
9
9
|
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
@@ -696,4 +696,4 @@ async function lorebookApproval(exec, next, state) {
|
|
|
696
696
|
}
|
|
697
697
|
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
698
|
|
|
699
|
-
//# sourceMappingURL=lorebook-author-tools-
|
|
699
|
+
//# sourceMappingURL=lorebook-author-tools-BCFFJSle.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as guardAuthoringTurns } from "./turn-guard-
|
|
3
|
-
import { d as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-
|
|
4
|
-
import "./hooks-
|
|
1
|
+
import { lt as lorebookDirectory, n as limitAuthoringAgents } from "./authoring-tools-B4mEdKp_.js";
|
|
2
|
+
import { t as guardAuthoringTurns } from "./turn-guard-BzNeGNnc.js";
|
|
3
|
+
import { d as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-BCFFJSle.js";
|
|
4
|
+
import "./hooks-DTjHWTfx.js";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { existsSync, readdirSync } from "node:fs";
|
|
7
7
|
// src/lorebook-authoring.ts
|