@dsh-agentic-roleplay/core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{notes-CJzbN_-E.js → activity-BbqFG9-3.js} +35 -9
- package/lib/authoring.js +3 -3
- package/lib/client.js +880 -372
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +1 -1
- package/lib/{documents-BBq88wXP.js → documents-ZVoUTnD2.js} +54 -33
- package/lib/{gallery-CjG9_4Sz.js → gallery-KGCdeCnM.js} +2 -2
- package/lib/{generator-pxZS-pu-.js → generator-NYnNdpWb.js} +100 -9
- package/lib/images.js +3 -3
- package/lib/index.js +220 -15
- package/lib/{narration-tYy6Rkfr.js → narration-DcnCqA1l.js} +20 -3
- package/lib/orchestration.js +510 -82
- package/lib/{presenter-agent-DbZALurg.js → presenter-agent-7j1c7QEz.js} +3 -3
- package/lib/{worlds-Bj-EGS_i.js → worlds-DYgjdH8O.js} +28 -2
- package/package.json +3 -2
- package/prompts/en/roleplay/faction-strategist.md +5 -0
- package/prompts/en/roleplay/trigger-judge.md +3 -0
- package/prompts/zh/roleplay/faction-strategist.md +5 -0
- package/prompts/zh/roleplay/trigger-judge.md +3 -0
- package/starter-worlds/blackwater-observatory/characters/arthur-moore/character.json +65 -0
- package/starter-worlds/blackwater-observatory/characters/clara-whitlock/character.json +87 -0
- package/starter-worlds/blackwater-observatory/characters/eleanor-graves/character.json +80 -0
- package/starter-worlds/blackwater-observatory/characters/marcus-reed/character.json +73 -0
- package/starter-worlds/blackwater-observatory/items/anonymous-letter/item.json +9 -0
- package/starter-worlds/blackwater-observatory/items/brass-laboratory-key/item.json +10 -0
- package/starter-worlds/blackwater-observatory/items/claras-gossip-notebook/item.json +9 -0
- package/starter-worlds/blackwater-observatory/items/harlans-notebook/item.json +10 -0
- package/starter-worlds/blackwater-observatory/items/investigators-coat/item.json +10 -0
- package/starter-worlds/blackwater-observatory/items/investigators-notebook/item.json +9 -0
- package/starter-worlds/blackwater-observatory/items/locked-filing-cabinet/item.json +10 -0
- package/starter-worlds/blackwater-observatory/items/marcus-calibration-notes/item.json +9 -0
- package/starter-worlds/blackwater-observatory/items/mayors-administrative-seal/item.json +9 -0
- package/starter-worlds/blackwater-observatory/items/municipal-lockbox/item.json +10 -0
- package/starter-worlds/blackwater-observatory/items/pocket-revolver/item.json +10 -0
- package/starter-worlds/blackwater-observatory/items/room-7-cash-receipt/item.json +9 -0
- package/starter-worlds/blackwater-observatory/items/rusting-mine-cart/item.json +10 -0
- package/starter-worlds/blackwater-observatory/items/signal-recording-strip/item.json +9 -0
- package/starter-worlds/blackwater-observatory/items/silver-pocket-watch/item.json +9 -0
- package/starter-worlds/blackwater-observatory/items/survey-archive-cabinet/item.json +10 -0
- package/starter-worlds/blackwater-observatory/items/surveyors-map/item.json +10 -0
- package/starter-worlds/blackwater-observatory/items/unknown-visitors-note-fragment/item.json +10 -0
- package/starter-worlds/blackwater-observatory/locations/blackwater-ridge/location.json +5 -0
- package/starter-worlds/blackwater-observatory/locations/iron-stag-bar/location.json +30 -0
- package/starter-worlds/blackwater-observatory/locations/iron-stag-room-7/location.json +18 -0
- package/starter-worlds/blackwater-observatory/locations/north-forest-cabin/location.json +18 -0
- package/starter-worlds/blackwater-observatory/locations/observatory-directors-office/location.json +20 -0
- package/starter-worlds/blackwater-observatory/locations/observatory-telescope-chamber/location.json +25 -0
- package/starter-worlds/blackwater-observatory/locations/old-mine-entrance/location.json +27 -0
- package/starter-worlds/blackwater-observatory/locations/old-mine-main-tunnel/location.json +13 -0
- package/starter-worlds/blackwater-observatory/locations/town-hall-mayors-office/location.json +25 -0
- package/starter-worlds/blackwater-observatory/locations/town-hall-records-room/location.json +13 -0
- package/starter-worlds/blackwater-observatory/locations/town-square/location.json +30 -0
- package/starter-worlds/blackwater-observatory/triggers.json +20 -0
- package/starter-worlds/blackwater-observatory/variables.json +39 -0
- package/starter-worlds/blackwater-observatory/world.json +27 -0
package/lib/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { n as roleplaySessionOf, t as chatSessionId } from "./chat-AKrVcWIC.js";
|
|
2
|
-
import { $ as
|
|
3
|
-
import { a as
|
|
2
|
+
import { $ as variableProblems, A as populateCharacters, B as routineProblems, D as markReady, F as populateLocations, G as subfolders, H as loadItems, I as populateLore, J as listWorldPrompts, L as populateRoutines, M as populateFactions, N as populateItems, P as populateKnowledge, Q as parseVariablesFile, R as populateTriggers, U as CHARACTERS_DIR, V as loadLocations, W as loadCharacters, X as writeWorldPrompt, Y as readWorldPrompt, Z as VARIABLES_FILE_NAME, _ as replaceFile$1, at as parseChoices, c as editWorldLore$1, ct as parseWorldInfoEdit, d as editWorldPlots$1, dt as parseFactionEdit, et as CHARACTER_FILE_NAME, f as editWorldRelation$1, ft as parseLoreEdit, g as readWorldEditor, gt as IMPORT_COMMAND, h as generateWorldCharacterPortrait, ht as parseThingEdit, i as readAuthoredEntityDocument, it as ImportStore, j as populateClock, k as loadValidatedWorld, l as editWorldNarrationVoice, lt as InvalidEditProblems, m as entityFolder, mt as parseRelationEdit, n as createAuthoredEntity, nt as IMPORT_FOLDER, o as editWorldCharacter$1, ot as WORLD_FILE_NAME, p as editWorldThing$1, pt as parsePlaceEdit, q as deleteWorldPrompt, r as deleteAuthoredEntity, rt as ImportNotFoundError, s as editWorldFaction$1, st as parseWorldFile, tt as parseCharacterFile, u as editWorldPlace$1, ut as parseCharacterEdit, v as uploadWorldCharacterPortrait, x as authoringChatSessionId, y as worldCharacterPortraitFile, z as populateVariables } from "./documents-ZVoUTnD2.js";
|
|
3
|
+
import { C as SessionArchivedError, S as InvalidWorldError, T as WorldNotFoundError, a as plotReferenceProblems, b as AgentUnavailableError, d as PromptLibrary, f as copyWorldPrompts, i as parsePlotsFile, l as formatIssue, m as languageOf, o as readDocument$1, s as errorMessage, t as API_PREFIX, w as SessionNotFoundError, x as InvalidStartError } from "./worlds-DYgjdH8O.js";
|
|
4
|
+
import { a as liveSettings, c as writeSettings, d as parseSettings, f as WORLD_RULES_KEY, i as InvalidSettingsError, l as DEFAULT_SETTINGS, n as encodeOutput, o as readSettings, s as useChildReasoning, u as SETTINGS_SPEC } from "./narration-DcnCqA1l.js";
|
|
4
5
|
import { n as VARIABLE_SUBJECTS, r as VARIABLE_VISIBILITIES, t as VARIABLE_KINDS } from "./src-CWTNeL6Y.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-CjG9_4Sz.js";
|
|
6
|
+
import { O as childSamplingOf, T as uniqueKey, a as uploadReferenceImage, m as sceneImagePath, o as addToLibrary, p as referenceImagePath, t as generateReferenceImage, u as inheritImages, w as slug } from "./generator-NYnNdpWb.js";
|
|
7
|
+
import { a as notesOfSession, c as PLOTS_METADATA_KEY, g as TimelineError, m as populatePlots, p as plotProgressOf, r as addToNote, t as readActivity, v as defaultBoundaries } from "./activity-BbqFG9-3.js";
|
|
8
|
+
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-KGCdeCnM.js";
|
|
9
9
|
import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve } from "node:path";
|
|
10
10
|
import { createReadStream, existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { randomUUID } from "node:crypto";
|
|
@@ -13,9 +13,10 @@ import { Session, SessionId } from "@deepseek-ai/dsh-session";
|
|
|
13
13
|
import { ToolCallId, createMessage, createSystemMessage, createToolResultMessage } from "@deepseek-ai/dsh-llm";
|
|
14
14
|
import { setApprovalPolicy } from "@deepseek-ai/dsh-user-approval";
|
|
15
15
|
import { inflateSync } from "node:zlib";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
16
17
|
import { Service } from "@deepseek-ai/cordis";
|
|
17
|
-
import { chmod, copyFile, lstat, mkdir, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
18
|
-
import { isSessionId, parseInstant, sessionDatabase, sessionFolder, systemTimeZone } from "@dsh-agentic-roleplay/state";
|
|
18
|
+
import { chmod, copyFile, cp, lstat, mkdir, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
19
|
+
import { isSessionId, lintWorld, parseInstant, sessionDatabase, sessionFolder, systemTimeZone } from "@dsh-agentic-roleplay/state";
|
|
19
20
|
import { pipeline } from "node:stream/promises";
|
|
20
21
|
import { homedir } from "node:os";
|
|
21
22
|
import z from "@deepseek-ai/schemastery";
|
|
@@ -860,6 +861,72 @@ function parseVariablesEdit(value) {
|
|
|
860
861
|
return declarations;
|
|
861
862
|
}
|
|
862
863
|
//#endregion
|
|
864
|
+
//#region src/host/worlds/starter.ts
|
|
865
|
+
const STARTER_FOLDER = "starter-worlds";
|
|
866
|
+
/** Names a starter world that the package does not ship. */
|
|
867
|
+
var UnknownStarterError = class extends Error {};
|
|
868
|
+
/** The folder of the worlds that ship with the package, found from this module so that it works from source and from the build. */
|
|
869
|
+
function starterDirectory(from = dirname(fileURLToPath(import.meta.url))) {
|
|
870
|
+
for (let directory = from;; directory = dirname(directory)) {
|
|
871
|
+
const candidate = join(directory, STARTER_FOLDER);
|
|
872
|
+
if (existsSync(join(directory, "package.json")) && existsSync(candidate)) return candidate;
|
|
873
|
+
if (dirname(directory) === directory) throw new Error("the starter worlds shipped with the package were not found");
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
async function shipped(directory) {
|
|
877
|
+
const found = [];
|
|
878
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
879
|
+
if (!entry.isDirectory()) continue;
|
|
880
|
+
const document = JSON.parse(await readFile(join(directory, entry.name, WORLD_FILE_NAME), "utf8"));
|
|
881
|
+
if (typeof document.id !== "string" || typeof document.name !== "string") throw new Error(`the starter world "${entry.name}" has no id or name`);
|
|
882
|
+
found.push({
|
|
883
|
+
folder: entry.name,
|
|
884
|
+
id: document.id,
|
|
885
|
+
name: document.name,
|
|
886
|
+
description: typeof document.description === "string" ? document.description : "",
|
|
887
|
+
tags: Array.isArray(document.metadata?.tags) ? document.metadata.tags.filter((tag) => typeof tag === "string") : []
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
return found.sort((a, b) => a.folder.localeCompare(b.folder));
|
|
891
|
+
}
|
|
892
|
+
/** The worlds the package ships, each with whether the person's worlds have it already. */
|
|
893
|
+
async function listStarterWorlds(catalog, directory = starterDirectory()) {
|
|
894
|
+
const known = await catalog.list();
|
|
895
|
+
return (await shipped(directory)).map(({ id, ...world }) => ({
|
|
896
|
+
...world,
|
|
897
|
+
installed: known.worlds.some((existing) => existing.id === id) || existsSync(join(catalog.directory, world.folder))
|
|
898
|
+
}));
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Copies a shipped world into the person's worlds, as a world of their own to play and edit, and makes the catalogue see it. Nothing is overwritten.
|
|
902
|
+
* @throws {UnknownStarterError} when the package ships no such world.
|
|
903
|
+
* @throws {WorldFolderExistsError} when the person already has that folder or a world with the same id.
|
|
904
|
+
*/
|
|
905
|
+
async function addStarterWorld(catalog, folder, directory = starterDirectory()) {
|
|
906
|
+
const world = (await shipped(directory)).find((candidate) => candidate.folder === folder);
|
|
907
|
+
if (world === void 0) throw new UnknownStarterError(`there is no starter world "${folder}"`);
|
|
908
|
+
if ((await catalog.list({ refresh: true })).worlds.some((existing) => existing.id === world.id)) throw new WorldFolderExistsError(`you already have "${world.name}"`);
|
|
909
|
+
const target = join(catalog.directory, world.folder);
|
|
910
|
+
if (existsSync(target)) throw new WorldFolderExistsError(`a world folder named "${world.folder}" already exists`);
|
|
911
|
+
await mkdir(catalog.directory, { recursive: true });
|
|
912
|
+
try {
|
|
913
|
+
await cp(join(directory, world.folder), target, {
|
|
914
|
+
recursive: true,
|
|
915
|
+
errorOnExist: true,
|
|
916
|
+
force: false
|
|
917
|
+
});
|
|
918
|
+
} catch (error) {
|
|
919
|
+
await rm(target, {
|
|
920
|
+
recursive: true,
|
|
921
|
+
force: true
|
|
922
|
+
});
|
|
923
|
+
throw error;
|
|
924
|
+
}
|
|
925
|
+
const added = (await catalog.list({ refresh: true })).worlds.find((candidate) => candidate.id === world.id);
|
|
926
|
+
if (added === void 0) throw new Error(`added "${world.name}" but it was not found when the catalogue refreshed`);
|
|
927
|
+
return added;
|
|
928
|
+
}
|
|
929
|
+
//#endregion
|
|
863
930
|
//#region src/host/http/respond.ts
|
|
864
931
|
function sendJson(res, status, payload) {
|
|
865
932
|
res.statusCode = status;
|
|
@@ -966,7 +1033,7 @@ function languageField(value) {
|
|
|
966
1033
|
throw new InvalidEditProblems([error instanceof Error ? error.message : String(error)]);
|
|
967
1034
|
}
|
|
968
1035
|
}
|
|
969
|
-
function createApiHandler({ worlds, createWorld, authorWorld, worldCharacters, importer, avatars, worldFiles, worldEditor, sessions, connection, speech }) {
|
|
1036
|
+
function createApiHandler({ worlds, createWorld, starter, authorWorld, worldCharacters, importer, avatars, worldFiles, worldEditor, sessions, connection, speech }) {
|
|
970
1037
|
const routes = {
|
|
971
1038
|
"/speech/capabilities": { GET: async (_req, res) => {
|
|
972
1039
|
sendJson(res, 200, { streaming: speech.streaming() });
|
|
@@ -1007,6 +1074,22 @@ function createApiHandler({ worlds, createWorld, authorWorld, worldCharacters, i
|
|
|
1007
1074
|
}
|
|
1008
1075
|
}
|
|
1009
1076
|
},
|
|
1077
|
+
"/worlds/starter": {
|
|
1078
|
+
GET: async (_req, res) => {
|
|
1079
|
+
sendJson(res, 200, await starter.list());
|
|
1080
|
+
},
|
|
1081
|
+
POST: async (req, res) => {
|
|
1082
|
+
const body = await readJsonBody(req);
|
|
1083
|
+
if (typeof body.folder !== "string") return sendError(res, 400, "folder must be text");
|
|
1084
|
+
try {
|
|
1085
|
+
sendJson(res, 201, await starter.add(body.folder));
|
|
1086
|
+
} catch (error) {
|
|
1087
|
+
if (error instanceof UnknownStarterError) return sendError(res, 404, error.message);
|
|
1088
|
+
if (error instanceof WorldFolderExistsError) return sendError(res, 409, error.message);
|
|
1089
|
+
throw error;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
},
|
|
1010
1093
|
"/worlds/import/card": { POST: async (req, res, url) => {
|
|
1011
1094
|
const name = decodeURIComponent(String(req.headers["x-file-name"] ?? url.searchParams.get("name") ?? "card"));
|
|
1012
1095
|
try {
|
|
@@ -1383,6 +1466,19 @@ function createApiHandler({ worlds, createWorld, authorWorld, worldCharacters, i
|
|
|
1383
1466
|
return sendError(res, 409, error instanceof Error ? error.message : String(error));
|
|
1384
1467
|
}
|
|
1385
1468
|
} },
|
|
1469
|
+
"/worlds/state/character/portrait/upload": { POST: async (req, res, url) => {
|
|
1470
|
+
const name = decodeURIComponent(String(req.headers["x-file-name"] ?? "portrait.png"));
|
|
1471
|
+
try {
|
|
1472
|
+
sendJson(res, 200, await worldEditor.uploadPortrait(url.searchParams.get("id") ?? "", url.searchParams.get("key") ?? "", await readBinaryBody(req, MAX_UPLOAD_BYTES), name));
|
|
1473
|
+
} catch (error) {
|
|
1474
|
+
if (error instanceof WorldNotFoundError) return sendError(res, 404, error.message);
|
|
1475
|
+
if (error instanceof InvalidEditProblems) return sendJson(res, 422, {
|
|
1476
|
+
message: error.message,
|
|
1477
|
+
problems: error.problems
|
|
1478
|
+
});
|
|
1479
|
+
throw error;
|
|
1480
|
+
}
|
|
1481
|
+
} },
|
|
1386
1482
|
"/worlds/state/character/portrait/file": { GET: async (_req, res, url) => {
|
|
1387
1483
|
try {
|
|
1388
1484
|
await sendImage(res, await worldEditor.portraitFile(url.searchParams.get("id") ?? "", url.searchParams.get("key") ?? ""));
|
|
@@ -1707,6 +1803,19 @@ function createApiHandler({ worlds, createWorld, authorWorld, worldCharacters, i
|
|
|
1707
1803
|
return sendError(res, 409, error instanceof Error ? error.message : String(error));
|
|
1708
1804
|
}
|
|
1709
1805
|
} },
|
|
1806
|
+
"/sessions/world/character/portrait/upload": { POST: async (req, res, url) => {
|
|
1807
|
+
const name = decodeURIComponent(String(req.headers["x-file-name"] ?? "portrait.png"));
|
|
1808
|
+
try {
|
|
1809
|
+
sendJson(res, 200, await sessions.uploadPortrait(url.searchParams.get("id") ?? "", url.searchParams.get("key") ?? "", await readBinaryBody(req, MAX_UPLOAD_BYTES), name));
|
|
1810
|
+
} catch (error) {
|
|
1811
|
+
if (error instanceof SessionNotFoundError) return sendError(res, 404, error.message);
|
|
1812
|
+
if (error instanceof InvalidEditProblems) return sendJson(res, 422, {
|
|
1813
|
+
message: error.message,
|
|
1814
|
+
problems: error.problems
|
|
1815
|
+
});
|
|
1816
|
+
throw error;
|
|
1817
|
+
}
|
|
1818
|
+
} },
|
|
1710
1819
|
"/sessions/world/character/portrait/file": { GET: async (_req, res, url) => {
|
|
1711
1820
|
try {
|
|
1712
1821
|
await sendImage(res, await sessions.portraitFile(url.searchParams.get("id") ?? "", url.searchParams.get("key") ?? ""));
|
|
@@ -1714,6 +1823,16 @@ function createApiHandler({ worlds, createWorld, authorWorld, worldCharacters, i
|
|
|
1714
1823
|
return sendError(res, 404, error instanceof Error ? error.message : String(error));
|
|
1715
1824
|
}
|
|
1716
1825
|
} },
|
|
1826
|
+
"/sessions/vectors/reset": { POST: async (_req, res, url) => {
|
|
1827
|
+
try {
|
|
1828
|
+
sessions.resetVectors(url.searchParams.get("id") ?? "");
|
|
1829
|
+
} catch (error) {
|
|
1830
|
+
if (error instanceof SessionNotFoundError) return sendError(res, 404, error.message);
|
|
1831
|
+
throw error;
|
|
1832
|
+
}
|
|
1833
|
+
res.statusCode = 204;
|
|
1834
|
+
res.end();
|
|
1835
|
+
} },
|
|
1717
1836
|
"/sessions/rename": { POST: async (req, res, url) => {
|
|
1718
1837
|
const body = await readJsonBody(req);
|
|
1719
1838
|
const name = typeof body === "object" && body !== null ? body.name : void 0;
|
|
@@ -2461,7 +2580,13 @@ function editWorldPlace(deps, id, key, edit) {
|
|
|
2461
2580
|
if (place === void 0) throw new InvalidEditProblems([`there is no place "${key}"`]);
|
|
2462
2581
|
try {
|
|
2463
2582
|
session.transaction(() => {
|
|
2464
|
-
const { visualIdentity, ...
|
|
2583
|
+
const { visualIdentity, parent, ...rest } = edit;
|
|
2584
|
+
const container = parent === void 0 ? void 0 : parent === null ? null : session.locations.list().find((candidate) => (candidate.sourceId ?? String(candidate.id)) === parent)?.id;
|
|
2585
|
+
if (container === void 0 && parent !== void 0) throw new InvalidEditProblems([`there is no place "${parent}" to put it in`]);
|
|
2586
|
+
const patch = {
|
|
2587
|
+
...rest,
|
|
2588
|
+
...container === void 0 ? {} : { parentId: container }
|
|
2589
|
+
};
|
|
2465
2590
|
if (Object.keys(patch).length > 0) session.locations.update(place.id, patch);
|
|
2466
2591
|
if (visualIdentity === null) session.visualIdentities.remove("location", place.id);
|
|
2467
2592
|
else if (visualIdentity !== void 0) session.visualIdentities.set("location", place.id, visualIdentity);
|
|
@@ -2478,10 +2603,13 @@ function editWorldThing(deps, id, key, edit) {
|
|
|
2478
2603
|
if (item === void 0) throw new InvalidEditProblems([`there is no thing "${key}"`]);
|
|
2479
2604
|
try {
|
|
2480
2605
|
session.transaction(() => {
|
|
2481
|
-
const { visualIdentity, containerState, ...patch } = edit;
|
|
2606
|
+
const { visualIdentity, containerState, owner, ...patch } = edit;
|
|
2607
|
+
const holder = owner === void 0 ? void 0 : owner === null ? null : session.characters.list().find((candidate) => (candidate.sourceId ?? String(candidate.id)) === owner)?.id;
|
|
2608
|
+
if (holder === void 0 && owner !== void 0) throw new InvalidEditProblems([`there is no character "${owner}" to own it`]);
|
|
2482
2609
|
const changes = {
|
|
2483
2610
|
...patch,
|
|
2484
|
-
...containerState === void 0 ? {} : { container: { state: containerState } }
|
|
2611
|
+
...containerState === void 0 ? {} : { container: { state: containerState } },
|
|
2612
|
+
...holder === void 0 ? {} : { ownerId: holder }
|
|
2485
2613
|
};
|
|
2486
2614
|
if (Object.keys(changes).length > 0) session.items.update(item.id, changes);
|
|
2487
2615
|
if (visualIdentity === null) session.visualIdentities.remove("item", item.id);
|
|
@@ -2647,6 +2775,28 @@ async function generateSessionCharacterPortrait(deps, id, key, service) {
|
|
|
2647
2775
|
});
|
|
2648
2776
|
return worldOf(session, deps.sessionsDir());
|
|
2649
2777
|
}
|
|
2778
|
+
/** The picture the player brought becomes the session character's portrait. */
|
|
2779
|
+
async function uploadSessionCharacterPortrait(deps, id, key, png, originalName) {
|
|
2780
|
+
const session = sessionOf(deps, id);
|
|
2781
|
+
const character = characterOf(session, key);
|
|
2782
|
+
const identity = session.visualIdentities.get("character", character.id);
|
|
2783
|
+
try {
|
|
2784
|
+
await uploadReferenceImage({
|
|
2785
|
+
root: sessionFolder(deps.sessionsDir(), id),
|
|
2786
|
+
subject: {
|
|
2787
|
+
kind: "character",
|
|
2788
|
+
localId: character.sourceId ?? character.id,
|
|
2789
|
+
name: character.name,
|
|
2790
|
+
...identity?.globalId === void 0 ? {} : { globalId: identity.globalId }
|
|
2791
|
+
},
|
|
2792
|
+
png,
|
|
2793
|
+
...originalName === void 0 ? {} : { originalName }
|
|
2794
|
+
});
|
|
2795
|
+
} catch (error) {
|
|
2796
|
+
throw new InvalidEditProblems([error instanceof Error ? error.message : String(error)]);
|
|
2797
|
+
}
|
|
2798
|
+
return worldOf(session, deps.sessionsDir());
|
|
2799
|
+
}
|
|
2650
2800
|
/** Resolve a portrait through session state so request parameters cannot select arbitrary files. */
|
|
2651
2801
|
async function sessionCharacterPortraitFile(deps, id, key) {
|
|
2652
2802
|
const session = sessionOf(deps, id);
|
|
@@ -2833,6 +2983,7 @@ function infoOf(document) {
|
|
|
2833
2983
|
authorUrl: textOf(author["url"]),
|
|
2834
2984
|
timeZone: textOf(document["time_zone"]),
|
|
2835
2985
|
startingTime: textOf(document["starting_time"]),
|
|
2986
|
+
version: typeof document["version"] === "number" ? String(document["version"]) : textOf(document["version"]),
|
|
2836
2987
|
alternateOpenings: Array.isArray(document["alternate_openings"]) ? document["alternate_openings"].flatMap((entry) => typeof entry === "object" && entry !== null && typeof entry["text"] === "string" ? [{
|
|
2837
2988
|
title: textOf(entry["title"]),
|
|
2838
2989
|
text: entry["text"]
|
|
@@ -2887,6 +3038,7 @@ async function editWorldInfo(directory, edit) {
|
|
|
2887
3038
|
}
|
|
2888
3039
|
if (edit.timeZone !== void 0) setOrRemove(document, "time_zone", edit.timeZone);
|
|
2889
3040
|
if (edit.startingTime !== void 0) setOrRemove(document, "starting_time", edit.startingTime);
|
|
3041
|
+
if (edit.version !== void 0) setOrRemove(document, "version", edit.version);
|
|
2890
3042
|
if (edit.alternateOpenings !== void 0) {
|
|
2891
3043
|
if (edit.alternateOpenings.length === 0) delete document["alternate_openings"];
|
|
2892
3044
|
else document["alternate_openings"] = edit.alternateOpenings.map((entry) => ({
|
|
@@ -2908,6 +3060,15 @@ async function editWorldInfo(directory, edit) {
|
|
|
2908
3060
|
* @throws {InvalidStartError} when the name or the player's character is not acceptable.
|
|
2909
3061
|
* @throws {AgentUnavailableError} when the chat cannot be created.
|
|
2910
3062
|
*/
|
|
3063
|
+
/** What is unfinished in the world as it was started, errors first, for the player's card before the first message. */
|
|
3064
|
+
function worldFindings(session) {
|
|
3065
|
+
const rank = {
|
|
3066
|
+
error: 0,
|
|
3067
|
+
warning: 1,
|
|
3068
|
+
info: 2
|
|
3069
|
+
};
|
|
3070
|
+
return lintWorld(session).filter((finding) => finding.severity !== "info").sort((a, b) => rank[a.severity] - rank[b.severity]).map((finding) => finding.message);
|
|
3071
|
+
}
|
|
2911
3072
|
async function startSession(deps, request) {
|
|
2912
3073
|
const world = await deps.worlds.find(request.worldId);
|
|
2913
3074
|
if (world === void 0) throw new WorldNotFoundError(`there is no world with id "${request.worldId}"`);
|
|
@@ -2958,6 +3119,7 @@ async function startSession(deps, request) {
|
|
|
2958
3119
|
world: {
|
|
2959
3120
|
id: world.summary.id,
|
|
2960
3121
|
name: world.summary.name,
|
|
3122
|
+
...world.summary.version === void 0 ? {} : { version: world.summary.version },
|
|
2961
3123
|
source: `worlds/${world.folder}`
|
|
2962
3124
|
}
|
|
2963
3125
|
});
|
|
@@ -2989,6 +3151,7 @@ async function startSession(deps, request) {
|
|
|
2989
3151
|
const promptProblems = copyWorldPrompts(world.directory, sessionFolder(sessionsDir, id));
|
|
2990
3152
|
if (promptProblems.length > 0) throw new InvalidWorldError(`the prompts of "${world.summary.name}" have ${promptProblems.length} problem(s)`, promptProblems);
|
|
2991
3153
|
writeSettings(sessionFolder(sessionsDir, id), settings);
|
|
3154
|
+
addToNote(session, "world", 1, worldFindings(session));
|
|
2992
3155
|
chatSessionId = await deps.agent.ensure(id, name, opening);
|
|
2993
3156
|
} catch (error) {
|
|
2994
3157
|
deps.state.deleteSession(sessionsDir, id);
|
|
@@ -3131,10 +3294,35 @@ function payloadOf(deps, id, settings) {
|
|
|
3131
3294
|
bounds: SETTINGS_SPEC,
|
|
3132
3295
|
pendingRecords: deps.pendingRecords(id),
|
|
3133
3296
|
pendingConsolidation: deps.pendingConsolidation(id),
|
|
3297
|
+
activity: deps.activity(id),
|
|
3298
|
+
vectors: deps.vectors(id),
|
|
3134
3299
|
...clockMode === void 0 ? {} : { clockMode }
|
|
3135
3300
|
};
|
|
3136
3301
|
}
|
|
3137
3302
|
//#endregion
|
|
3303
|
+
//#region src/host/sessions/vectors.ts
|
|
3304
|
+
/** How many waiting texts are counted before saying "that many": the number is for reassurance, not accounting. */
|
|
3305
|
+
const MAX_COUNTED = 1e4;
|
|
3306
|
+
function vectorStatus(session) {
|
|
3307
|
+
const info = session.recallIndex.info();
|
|
3308
|
+
return {
|
|
3309
|
+
available: session.recallIndex.vectors.available,
|
|
3310
|
+
...info === void 0 ? {
|
|
3311
|
+
embedded: 0,
|
|
3312
|
+
pending: session.recallIndex.pending(MAX_COUNTED).length
|
|
3313
|
+
} : {
|
|
3314
|
+
model: info.model,
|
|
3315
|
+
dimensions: info.dimensions,
|
|
3316
|
+
embedded: info.embedded,
|
|
3317
|
+
pending: info.pending
|
|
3318
|
+
}
|
|
3319
|
+
};
|
|
3320
|
+
}
|
|
3321
|
+
/** Forgets the stored vectors; the texts stay and are embedded again, by the model now selected, the next time the story searches. */
|
|
3322
|
+
function resetVectors(session) {
|
|
3323
|
+
session.recallIndex.reset();
|
|
3324
|
+
}
|
|
3325
|
+
//#endregion
|
|
3138
3326
|
//#region src/host/sessions/open-session.ts
|
|
3139
3327
|
/** Make sure a session has its DSH chat, so that it can be opened. */
|
|
3140
3328
|
async function openSession(deps, id) {
|
|
@@ -3387,7 +3575,8 @@ async function loadWorld(folder, dir, file, problems) {
|
|
|
3387
3575
|
name: world.name,
|
|
3388
3576
|
description: world.description,
|
|
3389
3577
|
tags: world.tags,
|
|
3390
|
-
...world.author === void 0 ? {} : { author: world.author }
|
|
3578
|
+
...world.author === void 0 ? {} : { author: world.author },
|
|
3579
|
+
...world.version === void 0 ? {} : { version: world.version }
|
|
3391
3580
|
},
|
|
3392
3581
|
...world.opening === void 0 ? {} : { opening: world.opening },
|
|
3393
3582
|
...world.clock === void 0 ? {} : { clock: world.clock },
|
|
@@ -3641,7 +3830,9 @@ function apply(ctx, config) {
|
|
|
3641
3830
|
sessionsDir: () => join(root.path, "sessions"),
|
|
3642
3831
|
pendingRecords: (id) => ctx.roleplayState.openSession(join(root.path, "sessions"), id).pendingCommits.list().length,
|
|
3643
3832
|
clockMode: (id) => ctx.roleplayState.openSession(join(root.path, "sessions"), id).clock.get()?.mode,
|
|
3644
|
-
pendingConsolidation: (id) => ctx.roleplayState.openSession(join(root.path, "sessions"), id).consolidation.pending().length
|
|
3833
|
+
pendingConsolidation: (id) => ctx.roleplayState.openSession(join(root.path, "sessions"), id).consolidation.pending().length,
|
|
3834
|
+
vectors: (id) => vectorStatus(ctx.roleplayState.openSession(join(root.path, "sessions"), id)),
|
|
3835
|
+
activity: (id) => readActivity(ctx.roleplayState.openSession(join(root.path, "sessions"), id))
|
|
3645
3836
|
};
|
|
3646
3837
|
const purgeChat = purgeOf(ctx, config.sessionStorePath);
|
|
3647
3838
|
const deps = {
|
|
@@ -3659,6 +3850,10 @@ function apply(ctx, config) {
|
|
|
3659
3850
|
},
|
|
3660
3851
|
worlds,
|
|
3661
3852
|
createWorld: (input) => createWorld(worlds, input),
|
|
3853
|
+
starter: {
|
|
3854
|
+
list: () => listStarterWorlds(worlds),
|
|
3855
|
+
add: (folder) => addStarterWorld(worlds, folder)
|
|
3856
|
+
},
|
|
3662
3857
|
authorWorld: async (worldId, title, language) => {
|
|
3663
3858
|
const world = await worlds.find(worldId);
|
|
3664
3859
|
if (world === void 0) throw new WorldNotFoundError(`there is no world with id "${worldId}"`);
|
|
@@ -3733,7 +3928,8 @@ function apply(ctx, config) {
|
|
|
3733
3928
|
editRelation: async (worldId, edit) => await editWorldRelation$1(await editableWorld(worlds, worldId, root.path), edit),
|
|
3734
3929
|
editNarrationVoice: async (worldId, voice) => await editWorldNarrationVoice(await editableWorld(worlds, worldId, root.path), voice),
|
|
3735
3930
|
generatePortrait: async (worldId, key) => await generateWorldCharacterPortrait(await editableWorld(worlds, worldId, root.path), key, imageGenerationOf(ctx)),
|
|
3736
|
-
portraitFile: async (worldId, key) => await worldCharacterPortraitFile(await editableWorld(worlds, worldId, root.path), key)
|
|
3931
|
+
portraitFile: async (worldId, key) => await worldCharacterPortraitFile(await editableWorld(worlds, worldId, root.path), key),
|
|
3932
|
+
uploadPortrait: async (worldId, key, png, name) => await uploadWorldCharacterPortrait(await editableWorld(worlds, worldId, root.path), key, png, name)
|
|
3737
3933
|
},
|
|
3738
3934
|
sessions: {
|
|
3739
3935
|
list: () => listSessions(deps),
|
|
@@ -3797,6 +3993,10 @@ function apply(ctx, config) {
|
|
|
3797
3993
|
state: ctx.roleplayState,
|
|
3798
3994
|
sessionsDir: deps.sessionsDir
|
|
3799
3995
|
}, id, key),
|
|
3996
|
+
uploadPortrait: (id, key, png, name) => uploadSessionCharacterPortrait({
|
|
3997
|
+
state: ctx.roleplayState,
|
|
3998
|
+
sessionsDir: deps.sessionsDir
|
|
3999
|
+
}, id, key, png, name),
|
|
3800
4000
|
world: (id) => readWorldState({
|
|
3801
4001
|
state: ctx.roleplayState,
|
|
3802
4002
|
sessionsDir: deps.sessionsDir
|
|
@@ -3810,6 +4010,11 @@ function apply(ctx, config) {
|
|
|
3810
4010
|
writeSettings: (id, value) => writeChatSettings(settingsDeps, id, value),
|
|
3811
4011
|
timeline: (id) => timelinesOf(ctx, deps.sessionsDir, id).view(id),
|
|
3812
4012
|
moveTimeline: (id, to) => timelinesOf(ctx, deps.sessionsDir, id).move(chatSessionId(id), to === "start" ? null : to),
|
|
4013
|
+
resetVectors: (id) => {
|
|
4014
|
+
const sessions = join(root.path, "sessions");
|
|
4015
|
+
if (!isSessionId(id) || !existsSync(sessionDatabase(sessions, id))) throw new SessionNotFoundError(`no session "${id}"`);
|
|
4016
|
+
resetVectors(ctx.roleplayState.openSession(sessions, id));
|
|
4017
|
+
},
|
|
3813
4018
|
notes: (id) => notesOfSession({
|
|
3814
4019
|
sessionsDir: deps.sessionsDir,
|
|
3815
4020
|
open: (sessionId) => ctx.roleplayState.openSession(deps.sessionsDir(), sessionId)
|
|
@@ -54,6 +54,7 @@ const SETTINGS_SPEC = {
|
|
|
54
54
|
flaky: flag(true),
|
|
55
55
|
recall: integer(1, 30, 12),
|
|
56
56
|
lookup: flag(true),
|
|
57
|
+
lookupCalls: integer(1, 20, 5),
|
|
57
58
|
verify: flag(true),
|
|
58
59
|
backlogRounds: integer(1, 100, 6),
|
|
59
60
|
overRetrieve: integer(1, 10, 4)
|
|
@@ -80,6 +81,7 @@ const SETTINGS_SPEC = {
|
|
|
80
81
|
offstage: {
|
|
81
82
|
perTurn: integer(0, 5, 2),
|
|
82
83
|
perCharacter: integer(1, 3, 1),
|
|
84
|
+
joint: flag(true),
|
|
83
85
|
summary: flag(true)
|
|
84
86
|
},
|
|
85
87
|
sampling: {
|
|
@@ -89,15 +91,27 @@ const SETTINGS_SPEC = {
|
|
|
89
91
|
authoring: ratio(0, 2, .4),
|
|
90
92
|
records: ratio(0, 2, .1),
|
|
91
93
|
tools: choice(["auto", "required"], "required"),
|
|
92
|
-
maxTokens: integer(256, 64e3, 8e3)
|
|
94
|
+
maxTokens: integer(256, 64e3, 8e3),
|
|
95
|
+
shortMaxTokens: integer(256, 64e3, 2e3)
|
|
93
96
|
},
|
|
94
97
|
prompts: { language: text(8, "en") },
|
|
95
98
|
reasoning: { children: text(40, "") },
|
|
99
|
+
factions: {
|
|
100
|
+
perTurn: integer(0, 3, 1),
|
|
101
|
+
everyDays: integer(1, 365, 3)
|
|
102
|
+
},
|
|
103
|
+
models: {
|
|
104
|
+
characters: text(200, ""),
|
|
105
|
+
records: text(200, ""),
|
|
106
|
+
suggestions: text(200, ""),
|
|
107
|
+
authoring: text(200, "")
|
|
108
|
+
},
|
|
96
109
|
triggers: {
|
|
97
110
|
enabled: flag(true),
|
|
98
111
|
maxFires: integer(1, 10, 3),
|
|
99
112
|
beatTurns: integer(1, 20, 3),
|
|
100
|
-
cueTurns: integer(1, 20, 2)
|
|
113
|
+
cueTurns: integer(1, 20, 2),
|
|
114
|
+
judgedPerTurn: integer(0, 5, 2)
|
|
101
115
|
},
|
|
102
116
|
rewind: { keepSnapshots: integer(0, 500, 30) },
|
|
103
117
|
rules: { own: text(MAX_OWN_RULES, "") },
|
|
@@ -137,6 +151,8 @@ function isTimeZone(zone) {
|
|
|
137
151
|
return false;
|
|
138
152
|
}
|
|
139
153
|
}
|
|
154
|
+
/** A model as `provider/model`: both parts present, no spaces. */
|
|
155
|
+
const MODEL_NAME = /^[^\s/]+\/\S+$/;
|
|
140
156
|
const OPTION_NAME = /^[A-Za-z][A-Za-z0-9_]{0,39}$/;
|
|
141
157
|
/** The options, or what is wrong with them. */
|
|
142
158
|
function parseOptions(value, name) {
|
|
@@ -188,6 +204,7 @@ function parseSettings(value) {
|
|
|
188
204
|
const parsed = parseLevel(SETTINGS_SPEC, value, "", problems);
|
|
189
205
|
const zone = parsed["clock"]?.timeZone;
|
|
190
206
|
if (typeof zone === "string" && zone !== "" && !isTimeZone(zone)) problems.push(`"clock.timeZone" is not a time zone this system knows: write it like Europe/London or UTC`);
|
|
207
|
+
for (const [kind, name] of Object.entries(parsed["models"] ?? {})) if (typeof name === "string" && name !== "" && !MODEL_NAME.test(name)) problems.push(`"models.${kind}" must be written provider/model, for example localai/qwen`);
|
|
191
208
|
return problems.length > 0 ? {
|
|
192
209
|
ok: false,
|
|
193
210
|
problems
|
|
@@ -332,4 +349,4 @@ function decodeOutput(text) {
|
|
|
332
349
|
//#endregion
|
|
333
350
|
export { liveSettings as a, writeSettings as c, parseSettings as d, WORLD_RULES_KEY as f, InvalidSettingsError as i, DEFAULT_SETTINGS as l, encodeOutput as n, readSettings as o, rulesOf as p, encodePreview as r, useChildReasoning as s, decodeOutput as t, SETTINGS_SPEC as u };
|
|
334
351
|
|
|
335
|
-
//# sourceMappingURL=narration-
|
|
352
|
+
//# sourceMappingURL=narration-DcnCqA1l.js.map
|