@dsh-agentic-roleplay/core 0.11.0 → 0.12.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-CXtaZNbx.js → access-DAw54-NI.js} +6 -15
- package/lib/{authoring-tools--6V1pIIL.js → authoring-tools-4NgDhIJV.js} +116 -13
- package/lib/authoring.js +38 -8
- package/lib/{child-C9nPIy9j.js → child-D3QUNb3m.js} +121 -2
- package/lib/client.js +1389 -475
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +3 -3
- package/lib/doctor.js +3 -3
- package/lib/{gallery-CtG-bDzz.js → gallery-Ct6nm4UQ.js} +3 -3
- package/lib/{generator-nLoPM5MF.js → generator-CI8fOnXy.js} +9 -3
- package/lib/helper.js +22 -1
- package/lib/{hooks-DORky4KT.js → hooks-BNeoGMHZ.js} +1342 -293
- package/lib/images.js +4 -4
- package/lib/index.js +444 -24
- package/lib/jail-BIF79PJO.js +107 -0
- package/lib/{library-CH-ahlm0.js → library-BF9ZMSFz.js} +3 -3
- package/lib/{lorebook-author-tools-BrVde1N-.js → lorebook-author-tools-DBk-V0hp.js} +7 -7
- package/lib/lorebook-authoring.js +4 -4
- package/lib/{narration-B0hConSw.js → narration-xvErE2yp.js} +34 -3
- package/lib/orchestration.js +915 -59
- package/lib/{pack-jail-Bk82pX9t.js → pack-jail-C8EyX9Ix.js} +18 -14
- package/lib/{packs-ELfh8yh1.js → packs-S0SzrVv-.js} +2 -2
- package/lib/{presenter-agent-UKbKYXMO.js → presenter-agent-Bc478nTA.js} +11 -8
- package/lib/{preset-D9Sfc8sf.js → preset-SJZyw0kt.js} +4 -4
- package/lib/{preset-author-tools-B3pFL1-e.js → preset-author-tools-CzogjK42.js} +7 -7
- package/lib/preset-authoring.js +5 -5
- package/lib/{presets-BRt4Xsy4.js → presets-DQ5rioMh.js} +251 -49
- package/lib/{reflection-CHiHsY4Y.js → reflection-buQiSdvq.js} +17 -609
- package/lib/service-mRKwpWjX.js +140 -0
- package/lib/{text-CzqhC8sT.js → text-Dfv8S8eq.js} +36 -2
- package/lib/{turn-guard-B53qOWEU.js → turn-guard-BSAba8sp.js} +3 -3
- package/package.json +3 -3
- package/prompts/en/import/finish-ok.md +1 -1
- package/prompts/en/import/generator.md +1 -1
- package/prompts/en/import/style.md +1 -1
- package/prompts/en/import/variables.md +3 -1
- package/prompts/en/roleplay/character-decide.md +1 -1
- package/prompts/en/roleplay/character-lookup.md +1 -1
- package/prompts/en/roleplay/decide-errand.md +1 -0
- package/prompts/en/roleplay/decide-message.md +1 -0
- package/prompts/en/roleplay/decide-reuse.md +3 -0
- package/prompts/en/roleplay/decide-variable.md +1 -0
- package/prompts/en/roleplay/dream.md +1 -0
- package/prompts/en/roleplay/gate-repeat.md +1 -0
- package/prompts/en/roleplay/image-presenter.md +1 -0
- package/prompts/en/roleplay/track-values.md +1 -0
- package/prompts/en/roleplay/track-variables.md +1 -0
- package/prompts/zh/import/finish-ok.md +1 -1
- package/prompts/zh/import/generator.md +1 -1
- package/prompts/zh/import/style.md +1 -1
- package/prompts/zh/import/variables.md +3 -1
- package/prompts/zh/roleplay/character-decide.md +1 -1
- package/prompts/zh/roleplay/character-lookup.md +1 -1
- package/prompts/zh/roleplay/decide-errand.md +1 -0
- package/prompts/zh/roleplay/decide-message.md +1 -0
- package/prompts/zh/roleplay/decide-reuse.md +3 -0
- package/prompts/zh/roleplay/decide-variable.md +1 -0
- package/prompts/zh/roleplay/dream.md +1 -0
- package/prompts/zh/roleplay/gate-repeat.md +1 -0
- package/prompts/zh/roleplay/image-presenter.md +1 -0
- package/prompts/zh/roleplay/track-values.md +1 -0
- package/prompts/zh/roleplay/track-variables.md +1 -0
package/lib/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $t as subfolders, At as populateLore, Bt as loadLocations, Ct as populateCharacters, Dt as populateItems, E as loadWorldParts, Et as populateFactions, F as localChanges, Ft as TRIGGERS_FILE_NAME, G as vetUrl, Gt as DICE_FILE_NAME, Ht as loadItems, I as readOrigin, Jt as CALENDAR_FILE_NAME, Kt as loadDice, L as writeOrigin, M as describeChanges, Mt as populateTriggers, N as hashWorld, Nt as populateVariables, Ot as populateKnowledge, P as isUnchanged, Pt as routineProblems, Qt as loadCharacters, R as CatalogueError, St as populateCalendar, T as readWorldInfo, Tt as populateDice, U as guardedLookup, Xt as parseCalendarFile, Yt as loadCalendar, Zt as CHARACTERS_DIR, _ as runChecks, _t as writeLorebookEntry, an as readCard, at as addLorebookEntries, c as importPhase, cn as DICE_RESULTS, ct as deleteLorebookEntry, d as markReady, dt as listLorebooks, en as knownOutputCeiling, et as WORLD_FILE_NAME, f as settleDraft, ft as loadLorebook, gt as updateLorebookInfo, ht as reserveLorebook, in as pictureOf, it as questionView, jt as populateRoutines, kt as populateLocations, ln as authoredWorldOf, lt as entriesOf, nn as cardFormat, nt as parseWorldInfoEdit, on as DICE_COMPARISONS, ot as createLorebook, p as structureImport, pt as lorebookDirectory, qt as parseDiceFile, rn as isPng, rt as combineAnswers, sn as DICE_READINGS, st as deleteLorebook, t as AuthoringTools, tn as ImportCardError, tt as parseWorldFile, u as keepDraft, ut as isLorebookName, vt as checkWorld, w as editWorldInfo, wt as populateClock, xt as knowsCharacter, yt as loadValidatedWorld } from "./authoring-tools
|
|
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 {
|
|
6
|
-
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-
|
|
7
|
-
import { $ as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-
|
|
11
|
-
import { _ as
|
|
12
|
-
import { n as readPreset, r as selectPrompts, t as previewPreset } from "./preset-
|
|
13
|
-
import { C as slug, T as uniqueKey, d as sceneImagePath, s as inheritImages, t as addToLibrary, u as referenceImagePath } from "./library-
|
|
1
|
+
import { A as chatSessionId, _ as RECOVERY_SHRINK, g as RECOVERY_FLOOR, h as sharedSamplingOf, i as childSamplingOf, j as roleplaySessionOf, m as parseSampling, s as isUnfinishedCall, w as totalTokens } from "./child-D3QUNb3m.js";
|
|
2
|
+
import { $t as subfolders, At as populateLore, Bt as loadLocations, Ct as populateCharacters, Dt as populateItems, E as loadWorldParts, Et as populateFactions, F as localChanges, Ft as TRIGGERS_FILE_NAME, G as vetUrl, Gt as DICE_FILE_NAME, Ht as loadItems, I as readOrigin, Jt as CALENDAR_FILE_NAME, Kt as loadDice, L as writeOrigin, M as describeChanges, Mt as populateTriggers, N as hashWorld, Nt as populateVariables, Ot as populateKnowledge, P as isUnchanged, Pt as routineProblems, Qt as loadCharacters, R as CatalogueError, St as populateCalendar, T as readWorldInfo, Tt as populateDice, U as guardedLookup, Xt as parseCalendarFile, Yt as loadCalendar, Zt as CHARACTERS_DIR, _ as runChecks, _t as writeLorebookEntry, an as readCard, at as addLorebookEntries, c as importPhase, cn as DICE_RESULTS, ct as deleteLorebookEntry, d as markReady, dt as listLorebooks, en as knownOutputCeiling, et as WORLD_FILE_NAME, f as settleDraft, ft as loadLorebook, gt as updateLorebookInfo, ht as reserveLorebook, in as pictureOf, it as questionView, jt as populateRoutines, kt as populateLocations, ln as authoredWorldOf, lt as entriesOf, nn as cardFormat, nt as parseWorldInfoEdit, on as DICE_COMPARISONS, ot as createLorebook, p as structureImport, pt as lorebookDirectory, qt as parseDiceFile, rn as isPng, rt as combineAnswers, sn as DICE_READINGS, st as deleteLorebook, t as AuthoringTools, tn as ImportCardError, tt as parseWorldFile, u as keepDraft, ut as isLorebookName, vt as checkWorld, w as editWorldInfo, wt as populateClock, xt as knowsCharacter, yt as loadValidatedWorld } from "./authoring-tools-4NgDhIJV.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-DBk-V0hp.js";
|
|
4
|
+
import { a as presetChatSessionId, n as narrationImportMessage, o as presetOfChat } from "./preset-author-tools-CzogjK42.js";
|
|
5
|
+
import { A as plotProgressOf, B as parsePlotsFile, C as readNotes, G as readDocument, H as COMMANDS_KEY, J as errorMessage, L as readUsage, Q as copyWorldPrompts, S as notesOfSession, T as defaultBoundaries, V as plotReferenceProblems, X as PROMPTS_FOLDER, Y as LANGUAGE_FOLDER, Z as PromptLibrary, _ as readTraces, b as readWithdrawn, ct as InvalidWorldError, dt as SessionNotFoundError, et as languageOf, ft as WorldNotFoundError, g as readRunDetail, h as readActivity, ht as zoneOf, j as populatePlots, k as PLOTS_METADATA_KEY, lt as ReflectionRefusedError, m as readDecisionStats, nt as promptProblem, o as externalTools, ot as AgentUnavailableError, q as formatIssue, rt as shippedLanguages, st as InvalidStartError, tt as listFiles, ut as SessionArchivedError, w as observeAsPlayer, x as addToNote } from "./hooks-BNeoGMHZ.js";
|
|
6
|
+
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-xvErE2yp.js";
|
|
7
|
+
import { $ as IMPORT_FOLDER, Bt as LORE_KINDS, Ft as parseLoreEdit, G as deleteWorldPrompt, It as parsePlaceEdit, J as writeWorldPrompt, K as listWorldPrompts, Lt as parseRelationEdit, Mt as InvalidEditProblems, Nt as parseCharacterEdit, Ot as CHARACTER_FILE_NAME, Pt as parseFactionEdit, Q as withPlayer, Rt as parseThingEdit, Vt as LORE_SCOPES, Z as partsOf, _t as variableProblems, a as isPresetName, at as readImportFolder, c as presetDirectory, d as savePresetFromWorld, et as ImportNotFoundError, gt as parseVariablesFile, ht as loadVariables, i as deletePreset, it as parseChoices, kt as parseCharacterFile, mt as VARIABLES_FILE_NAME, o as listPresets, p as updatePresetInfo, pt as sourceSummary, q as readWorldPrompt, r as createPresetFromShipped, s as loadPreset, st as IMPORT_COMMAND, t as PRESET_FILE, tt as ImportStore, u as reservePreset, zt as guarded } from "./presets-DQ5rioMh.js";
|
|
8
|
+
import { $ as DOCTOR_OPENING_SOURCE, A as worldEntityImageFile, B as languageOfDocuments, C as readWorldEditor, D as uploadWorldCharacterPortrait, E as replaceFile, F as PRESET_FILE$1, 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-C8EyX9Ix.js";
|
|
9
|
+
import { a as VARIABLE_KINDS, i as atomicWriteSync, n as atomicWrite, o as VARIABLE_SUBJECTS, r as atomicWriteJson, s as VARIABLE_VISIBILITIES } from "./access-DAw54-NI.js";
|
|
10
|
+
import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-Dfv8S8eq.js";
|
|
11
|
+
import { _ as snapshotOf, c as copyPreset, d as switchPreset, f as readTimeline, g as pathTo, h as childrenOf, i as reflectionStatus, l as presetStatus, m as START_SNAPSHOT, o as TimelineError, p as writeTimeline, u as recordPreset } from "./reflection-buQiSdvq.js";
|
|
12
|
+
import { n as readPreset, r as selectPrompts, t as previewPreset } from "./preset-SJZyw0kt.js";
|
|
13
|
+
import { C as slug, T as uniqueKey, d as sceneImagePath, s as inheritImages, t as addToLibrary, u as referenceImagePath } from "./library-BF9ZMSFz.js";
|
|
14
|
+
import { o as FOLDER_ACCESS, r as InvalidFoldersError, t as StoryFoldersService } from "./service-mRKwpWjX.js";
|
|
14
15
|
import { t as doctorChatSessionId } from "./doctor-chat-hL1a61hp.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-
|
|
16
|
-
import { a as uploadReferenceImage, t as generateReferenceImage } from "./generator-
|
|
17
|
-
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-
|
|
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-S0SzrVv-.js";
|
|
17
|
+
import { a as uploadReferenceImage, t as generateReferenceImage } from "./generator-CI8fOnXy.js";
|
|
18
|
+
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-Ct6nm4UQ.js";
|
|
18
19
|
import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from "node:path";
|
|
19
20
|
import { SESSION_DATABASE_FILE, addLocalDays, createSessionStore, describeInstant, describeValue, holidaysOn, isSessionId, itemKey, lintWorld, locationKey, openSessionStore, parseInstant, readCalendar, seasonOf, sessionDatabase, sessionFolder, shownVariables, systemTimeZone } from "@dsh-agentic-roleplay/state";
|
|
20
21
|
import { copyFileSync, cpSync, createReadStream, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -30,6 +31,194 @@ import { homedir } from "node:os";
|
|
|
30
31
|
import { pipeline } from "node:stream/promises";
|
|
31
32
|
import { spawn } from "node:child_process";
|
|
32
33
|
import z from "@deepseek-ai/schemastery";
|
|
34
|
+
// src/shared/offload.ts
|
|
35
|
+
/** The kinds of model a story uses that may have to share one machine's memory. `main` is whatever model the chat itself is set to. */
|
|
36
|
+
const OFFLOAD_ROLES = [
|
|
37
|
+
"main",
|
|
38
|
+
"embedding",
|
|
39
|
+
"reranker",
|
|
40
|
+
"decision",
|
|
41
|
+
"image",
|
|
42
|
+
"speech"
|
|
43
|
+
];
|
|
44
|
+
const DEFAULT_OFFLOAD = {
|
|
45
|
+
models: {},
|
|
46
|
+
groups: []
|
|
47
|
+
};
|
|
48
|
+
const isRole = (value) => OFFLOAD_ROLES.includes(value);
|
|
49
|
+
const text$1 = (value) => typeof value === "string" ? value.trim() : "";
|
|
50
|
+
/** The configuration as written, brought to its shape: unknown roles and blank entries are dropped, a group lists each role once and has at least two. */
|
|
51
|
+
function offloadOf(value) {
|
|
52
|
+
const row = typeof value === "object" && value !== null ? value : {};
|
|
53
|
+
const models = {};
|
|
54
|
+
const given = typeof row["models"] === "object" && row["models"] !== null ? row["models"] : {};
|
|
55
|
+
for (const role of OFFLOAD_ROLES) {
|
|
56
|
+
if (role === "main") continue;
|
|
57
|
+
const entry = given[role];
|
|
58
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
59
|
+
const route = text$1(entry["route"]);
|
|
60
|
+
const model = text$1(entry["model"]);
|
|
61
|
+
if (route !== "" || model !== "") models[role] = {
|
|
62
|
+
route,
|
|
63
|
+
model
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
models,
|
|
68
|
+
groups: (Array.isArray(row["groups"]) ? row["groups"] : []).map((group) => OFFLOAD_ROLES.filter((role) => Array.isArray(group) && group.some((member) => isRole(member) && member === role))).filter((group) => group.length >= 2)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** The roles that may not be loaded together with `role`. */
|
|
72
|
+
function conflictsOf(config, role) {
|
|
73
|
+
const others = /* @__PURE__ */ new Set();
|
|
74
|
+
for (const group of config.groups) if (group.includes(role)) {
|
|
75
|
+
for (const member of group) if (member !== role) others.add(member);
|
|
76
|
+
}
|
|
77
|
+
return [...others];
|
|
78
|
+
}
|
|
79
|
+
// src/host/residency/residency.ts
|
|
80
|
+
/**
|
|
81
|
+
* Keeps the models that cannot share memory from being loaded together. Before a model of a role is used, the models of the roles that
|
|
82
|
+
* conflict with it are unloaded; the server loads what is asked of it on its own, so nothing is loaded here. Which models may still be
|
|
83
|
+
* resident is only what this process has used since it started or since it unloaded them (a server that was already running is asked
|
|
84
|
+
* once), so a role used again and again costs nothing.
|
|
85
|
+
*/
|
|
86
|
+
var ModelResidency = class {
|
|
87
|
+
deps;
|
|
88
|
+
possible = /* @__PURE__ */ new Set([
|
|
89
|
+
"main",
|
|
90
|
+
"embedding",
|
|
91
|
+
"reranker",
|
|
92
|
+
"decision",
|
|
93
|
+
"image",
|
|
94
|
+
"speech"
|
|
95
|
+
]);
|
|
96
|
+
turn = Promise.resolve();
|
|
97
|
+
reported = /* @__PURE__ */ new Set();
|
|
98
|
+
lastMain;
|
|
99
|
+
active = /* @__PURE__ */ new Map();
|
|
100
|
+
drained = /* @__PURE__ */ new Map();
|
|
101
|
+
constructor(deps) {
|
|
102
|
+
this.deps = deps;
|
|
103
|
+
}
|
|
104
|
+
/** Whether using `role` ever unloads `other`. */
|
|
105
|
+
conflicts(role, other) {
|
|
106
|
+
return conflictsOf(this.deps.config(), role).includes(other);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Makes room for `role`. @param main the chat's own model, which is what `main` stands for; the last one seen is used when a caller does not know it.
|
|
110
|
+
* Never fails: a model that cannot be unloaded is reported once and the work goes on, because the server may well manage on its own.
|
|
111
|
+
*/
|
|
112
|
+
async ensure(role, main) {
|
|
113
|
+
if (role === "main" && main !== void 0) this.lastMain = main;
|
|
114
|
+
const config = this.deps.config();
|
|
115
|
+
if (conflictsOf(config, role).every((other) => !this.possible.has(other))) {
|
|
116
|
+
this.possible.add(role);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
for (let busy = this.busy(role); busy.length > 0; busy = this.busy(role)) await Promise.all(busy.map((other) => this.idle(other)));
|
|
120
|
+
const done = this.turn.then(async () => {
|
|
121
|
+
for (const victim of conflictsOf(this.deps.config(), role).filter((other) => this.possible.has(other) && !this.inUse(other))) await this.unload(victim, config, main ?? this.lastMain);
|
|
122
|
+
this.possible.add(role);
|
|
123
|
+
});
|
|
124
|
+
this.turn = done.catch(() => void 0);
|
|
125
|
+
await done;
|
|
126
|
+
}
|
|
127
|
+
/** Switches to `role`, reserves it before another switch can begin, and keeps that model resident for the call. */
|
|
128
|
+
async run(role, call, main) {
|
|
129
|
+
if (role === "main" && main !== void 0) this.lastMain = main;
|
|
130
|
+
const ready = this.turn.then(async () => {
|
|
131
|
+
for (let busy = this.busy(role); busy.length > 0; busy = this.busy(role)) await Promise.all(busy.map((other) => this.idle(other)));
|
|
132
|
+
const config = this.deps.config();
|
|
133
|
+
for (const victim of conflictsOf(config, role).filter((other) => this.possible.has(other) && !this.inUse(other))) await this.unload(victim, config, main ?? this.lastMain);
|
|
134
|
+
this.possible.add(role);
|
|
135
|
+
this.active.set(role, (this.active.get(role) ?? 0) + 1);
|
|
136
|
+
});
|
|
137
|
+
this.turn = ready.catch(() => void 0);
|
|
138
|
+
await ready;
|
|
139
|
+
try {
|
|
140
|
+
return await call();
|
|
141
|
+
} finally {
|
|
142
|
+
this.release(role);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** Runs a call that uses a model of `role`, so that the model is not unloaded while the call is on. */
|
|
146
|
+
async using(role, call) {
|
|
147
|
+
this.active.set(role, (this.active.get(role) ?? 0) + 1);
|
|
148
|
+
try {
|
|
149
|
+
return await call();
|
|
150
|
+
} finally {
|
|
151
|
+
this.release(role);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
release(role) {
|
|
155
|
+
const left = (this.active.get(role) ?? 1) - 1;
|
|
156
|
+
if (left > 0) this.active.set(role, left);
|
|
157
|
+
else {
|
|
158
|
+
this.active.delete(role);
|
|
159
|
+
for (const resume of this.drained.get(role) ?? []) resume();
|
|
160
|
+
this.drained.delete(role);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
inUse(role) {
|
|
164
|
+
return (this.active.get(role) ?? 0) > 0;
|
|
165
|
+
}
|
|
166
|
+
/** The roles that conflict with `role`, may be resident and have calls on. */
|
|
167
|
+
busy(role) {
|
|
168
|
+
return conflictsOf(this.deps.config(), role).filter((other) => this.possible.has(other) && this.inUse(other));
|
|
169
|
+
}
|
|
170
|
+
idle(role) {
|
|
171
|
+
return new Promise((resolve) => {
|
|
172
|
+
this.drained.set(role, [...this.drained.get(role) ?? [], resolve]);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
async unload(role, config, main) {
|
|
176
|
+
const target = role === "main" ? main === void 0 ? void 0 : {
|
|
177
|
+
route: main.provider,
|
|
178
|
+
model: main.model
|
|
179
|
+
} : config.models[role];
|
|
180
|
+
if (target === void 0 || target.route === "" || target.model === "") {
|
|
181
|
+
this.report(`offload: the ${role} model is not set, so it is not unloaded`);
|
|
182
|
+
this.possible.delete(role);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const admin = this.deps.admin();
|
|
186
|
+
if (admin === void 0) {
|
|
187
|
+
this.report("offload: the AI providers plugin offers no model administration, so nothing is unloaded");
|
|
188
|
+
this.possible.delete(role);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
const operations = admin.operations(target.route);
|
|
193
|
+
if (!operations.includes("unload")) {
|
|
194
|
+
this.report(`offload: the route "${target.route}" cannot unload models`);
|
|
195
|
+
this.possible.delete(role);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (operations.includes("status") && await this.loaded(admin, target) === false) {
|
|
199
|
+
this.possible.delete(role);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
await admin.unload(target.route, target.model);
|
|
203
|
+
this.possible.delete(role);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
this.report(`offload: could not unload ${target.model} on ${target.route}: ${error instanceof Error ? error.message : String(error)}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** Whether the server has the model in memory; a server that cannot say is taken to have it, since unloading what is not there is harmless. */
|
|
209
|
+
async loaded(admin, target) {
|
|
210
|
+
try {
|
|
211
|
+
return (await admin.status(target.route, target.model)).state !== "uninitialized";
|
|
212
|
+
} catch {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
report(message) {
|
|
217
|
+
if (this.reported.has(message)) return;
|
|
218
|
+
this.reported.add(message);
|
|
219
|
+
this.deps.problem(message);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
33
222
|
// src/host/prompts/manage.ts
|
|
34
223
|
/** A prompt the person asked for does not exist or cannot be written; the message says why. */
|
|
35
224
|
var PromptEditError = class extends Error {};
|
|
@@ -810,7 +999,7 @@ async function uploadPreset(deps, worldId, file, name, language) {
|
|
|
810
999
|
if (world === void 0) throw new WorldNotFoundError(`there is no world with id "${worldId}"`);
|
|
811
1000
|
const preset = readPreset(file, name);
|
|
812
1001
|
await mkdir(join(world.directory, IMPORT_FOLDER), { recursive: true });
|
|
813
|
-
await writeFile(join(world.directory, IMPORT_FOLDER, PRESET_FILE), file);
|
|
1002
|
+
await writeFile(join(world.directory, IMPORT_FOLDER, PRESET_FILE$1), file);
|
|
814
1003
|
const chatSessionId = await deps.authoring.ensure(world.summary.id, world.summary.name, authoringTitle(world.summary.name, language), language);
|
|
815
1004
|
let failure;
|
|
816
1005
|
try {
|
|
@@ -1276,6 +1465,49 @@ var Lorebooks = class {
|
|
|
1276
1465
|
};
|
|
1277
1466
|
}
|
|
1278
1467
|
};
|
|
1468
|
+
// src/host/autonomy/ticker.ts
|
|
1469
|
+
/**
|
|
1470
|
+
* Looks at the stories that switched on going on while their player is away, one after the other and one at a time: a story that did not is never touched, and
|
|
1471
|
+
* a story that cannot be looked at is reported and left for the next time.
|
|
1472
|
+
*/
|
|
1473
|
+
var AutonomyTicker = class {
|
|
1474
|
+
deps;
|
|
1475
|
+
running = false;
|
|
1476
|
+
constructor(deps) {
|
|
1477
|
+
this.deps = deps;
|
|
1478
|
+
}
|
|
1479
|
+
/** @returns how many stories were looked at. */
|
|
1480
|
+
async run(signal) {
|
|
1481
|
+
if (this.running) return 0;
|
|
1482
|
+
this.running = true;
|
|
1483
|
+
let looked = 0;
|
|
1484
|
+
try {
|
|
1485
|
+
for (const session of this.deps.sessions()) {
|
|
1486
|
+
if (signal.aborted) break;
|
|
1487
|
+
if (session.archived) continue;
|
|
1488
|
+
let on;
|
|
1489
|
+
try {
|
|
1490
|
+
const { autonomy, clock } = this.deps.settings(session.id);
|
|
1491
|
+
on = autonomy.enabled && clock.mode === "real";
|
|
1492
|
+
} catch (error) {
|
|
1493
|
+
this.deps.problem(`the settings of "${session.name}" could not be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
1494
|
+
continue;
|
|
1495
|
+
}
|
|
1496
|
+
if (!on) continue;
|
|
1497
|
+
try {
|
|
1498
|
+
await this.deps.ensure(session.id, session.name);
|
|
1499
|
+
await this.deps.tick(`session-${session.id}`, signal);
|
|
1500
|
+
looked += 1;
|
|
1501
|
+
} catch (error) {
|
|
1502
|
+
if (!signal.aborted) this.deps.problem(`"${session.name}" could not be looked at while its player is away: ${error instanceof Error ? error.message : String(error)}`);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
} finally {
|
|
1506
|
+
this.running = false;
|
|
1507
|
+
}
|
|
1508
|
+
return looked;
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1279
1511
|
const KIND = {
|
|
1280
1512
|
folder: "sessions",
|
|
1281
1513
|
projectTitle: "Session Doctor",
|
|
@@ -1355,10 +1587,17 @@ var RoleplayOrchestration = class extends Service {
|
|
|
1355
1587
|
recallPreview = () => Promise.reject(/* @__PURE__ */ new Error("the orchestration is not running"));
|
|
1356
1588
|
/** Whether a turn of the chat is being played; there while the orchestration is. */
|
|
1357
1589
|
playing = () => false;
|
|
1590
|
+
/** One look at a story that goes on while its player is away (the characters' days, and perhaps a message); there while the orchestration is. */
|
|
1591
|
+
autonomy = () => Promise.resolve({
|
|
1592
|
+
outcome: "off",
|
|
1593
|
+
moved: 0
|
|
1594
|
+
});
|
|
1358
1595
|
/** Whether a reflection of the chat is running; there while the orchestration is. */
|
|
1359
1596
|
reflecting = () => false;
|
|
1360
1597
|
/** What the story's turns are and taking the story back to one; there while the orchestration is. */
|
|
1361
1598
|
timelines;
|
|
1599
|
+
/** Unloads the models that cannot share memory with the one about to be used; there while the plugin is. */
|
|
1600
|
+
residency;
|
|
1362
1601
|
/** Background scene illustration jobs; there while the orchestration is mounted. */
|
|
1363
1602
|
images;
|
|
1364
1603
|
constructor(ctx) {
|
|
@@ -1501,7 +1740,7 @@ var Presets = class {
|
|
|
1501
1740
|
const directory = await reservePreset(root, name, title ?? uploaded.name, uploaded.sampling);
|
|
1502
1741
|
try {
|
|
1503
1742
|
await mkdir(join(directory, IMPORT_FOLDER), { recursive: true });
|
|
1504
|
-
await writeFile(join(directory, IMPORT_FOLDER, PRESET_FILE
|
|
1743
|
+
await writeFile(join(directory, IMPORT_FOLDER, PRESET_FILE), file);
|
|
1505
1744
|
} catch (error) {
|
|
1506
1745
|
await deletePreset(root, name);
|
|
1507
1746
|
throw error;
|
|
@@ -1950,6 +2189,48 @@ function lorebookRoutes(api) {
|
|
|
1950
2189
|
} }
|
|
1951
2190
|
};
|
|
1952
2191
|
}
|
|
2192
|
+
// src/host/workspace/routes.ts
|
|
2193
|
+
function parseFolders(body) {
|
|
2194
|
+
if (!Array.isArray(body["folders"])) return "\"folders\" must be a list";
|
|
2195
|
+
const folders = [];
|
|
2196
|
+
for (const entry of body["folders"]) {
|
|
2197
|
+
const folder = entry;
|
|
2198
|
+
if (typeof folder !== "object" || folder === null || typeof folder["path"] !== "string" || !FOLDER_ACCESS.includes(folder["access"])) return "each folder needs a \"path\" and an \"access\" of read or write";
|
|
2199
|
+
folders.push({
|
|
2200
|
+
path: folder["path"],
|
|
2201
|
+
access: folder["access"]
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
return folders;
|
|
2205
|
+
}
|
|
2206
|
+
function folderRoutes(api) {
|
|
2207
|
+
const failed = (res, error) => {
|
|
2208
|
+
if (error instanceof SessionNotFoundError) return sendError(res, 404, error.message);
|
|
2209
|
+
if (error instanceof InvalidFoldersError) return sendJson(res, 422, {
|
|
2210
|
+
message: error.message,
|
|
2211
|
+
problems: error.problems
|
|
2212
|
+
});
|
|
2213
|
+
throw error;
|
|
2214
|
+
};
|
|
2215
|
+
return { "/sessions/folders": {
|
|
2216
|
+
GET: async (_req, res, url) => {
|
|
2217
|
+
try {
|
|
2218
|
+
sendJson(res, 200, await api.status(url.searchParams.get("id") ?? ""));
|
|
2219
|
+
} catch (error) {
|
|
2220
|
+
failed(res, error);
|
|
2221
|
+
}
|
|
2222
|
+
},
|
|
2223
|
+
PUT: async (req, res, url) => {
|
|
2224
|
+
const folders = parseFolders(await readJsonBody(req));
|
|
2225
|
+
if (typeof folders === "string") return sendError(res, 400, folders);
|
|
2226
|
+
try {
|
|
2227
|
+
sendJson(res, 200, await api.set(url.searchParams.get("id") ?? "", folders));
|
|
2228
|
+
} catch (error) {
|
|
2229
|
+
failed(res, error);
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
} };
|
|
2233
|
+
}
|
|
1953
2234
|
// src/host/prompts/routes.ts
|
|
1954
2235
|
function promptRoutes(api) {
|
|
1955
2236
|
const fail = (res, error) => {
|
|
@@ -2259,7 +2540,7 @@ function playerViewOf(session, options) {
|
|
|
2259
2540
|
summary: player.summary,
|
|
2260
2541
|
publicState: playerState?.publicState ?? ""
|
|
2261
2542
|
};
|
|
2262
|
-
view.variables.push(...shown(player.name, shownVariables(session, "character", player.id, keyOf$3(player), "
|
|
2543
|
+
view.variables.push(...shown(player.name, shownVariables(session, "character", player.id, keyOf$3(player), "self")));
|
|
2263
2544
|
const placement = session.placements.get("character", player.id);
|
|
2264
2545
|
const here = placement === void 0 ? void 0 : session.locations.get(placement.locationId);
|
|
2265
2546
|
const known = new Set(session.knowledge.list(player.id, "location").map((entry) => entry.subjectId));
|
|
@@ -3615,7 +3896,8 @@ const ROUTINE_FIELDS = [
|
|
|
3615
3896
|
"location",
|
|
3616
3897
|
"feature",
|
|
3617
3898
|
"position",
|
|
3618
|
-
"interruptible"
|
|
3899
|
+
"interruptible",
|
|
3900
|
+
"sleep"
|
|
3619
3901
|
];
|
|
3620
3902
|
/**
|
|
3621
3903
|
* The windows of a day as the browser sends them.
|
|
@@ -3650,6 +3932,7 @@ function parseRoutineEdit(value) {
|
|
|
3650
3932
|
]) if (entry[key] !== void 0 && typeof entry[key] !== "string") problems.push(`${at}.${key} must be text`);
|
|
3651
3933
|
if (entry["days"] !== void 0 && !(Array.isArray(entry["days"]) && entry["days"].every((day) => typeof day === "string"))) problems.push(`${at}.days must be a list of days`);
|
|
3652
3934
|
if (entry["interruptible"] !== void 0 && typeof entry["interruptible"] !== "boolean") problems.push(`${at}.interruptible must be true or false`);
|
|
3935
|
+
if (entry["sleep"] !== void 0 && typeof entry["sleep"] !== "boolean") problems.push(`${at}.sleep must be true or false`);
|
|
3653
3936
|
const text = (key) => typeof entry[key] === "string" ? entry[key].trim() : "";
|
|
3654
3937
|
return {
|
|
3655
3938
|
days: Array.isArray(entry["days"]) ? entry["days"].map((day) => day.trim().toLowerCase()).filter((day) => day !== "") : [],
|
|
@@ -3660,7 +3943,8 @@ function parseRoutineEdit(value) {
|
|
|
3660
3943
|
...text("location") === "" ? {} : { location: text("location") },
|
|
3661
3944
|
...text("feature") === "" ? {} : { feature: text("feature") },
|
|
3662
3945
|
...text("position") === "" ? {} : { position: text("position") },
|
|
3663
|
-
interruptible: entry["interruptible"] !== false
|
|
3946
|
+
interruptible: entry["interruptible"] !== false,
|
|
3947
|
+
...entry["sleep"] === true ? { sleep: true } : {}
|
|
3664
3948
|
};
|
|
3665
3949
|
});
|
|
3666
3950
|
if (problems.length > 0) throw new InvalidEditProblems(problems);
|
|
@@ -3673,6 +3957,7 @@ const VARIABLE_FIELDS = [
|
|
|
3673
3957
|
"subject",
|
|
3674
3958
|
"visibility",
|
|
3675
3959
|
"description",
|
|
3960
|
+
"update",
|
|
3676
3961
|
"min",
|
|
3677
3962
|
"max",
|
|
3678
3963
|
"integer",
|
|
@@ -3749,6 +4034,7 @@ function parseVariablesEdit(value) {
|
|
|
3749
4034
|
subject: text("subject"),
|
|
3750
4035
|
visibility: text("visibility"),
|
|
3751
4036
|
...text("description") === "" ? {} : { description: text("description") },
|
|
4037
|
+
...text("update") === "" ? {} : { update: text("update") },
|
|
3752
4038
|
...min === void 0 ? {} : { min },
|
|
3753
4039
|
...max === void 0 ? {} : { max },
|
|
3754
4040
|
...integer === true ? { integer } : {},
|
|
@@ -4656,6 +4942,7 @@ async function writeJournal(sessionsDir, id, body, now = () => /* @__PURE__ */ n
|
|
|
4656
4942
|
// src/shared/reference.ts
|
|
4657
4943
|
/** The pages of the reference: what the player may look up about the story, never what only the story knows. */
|
|
4658
4944
|
const REFERENCE_SECTIONS = [
|
|
4945
|
+
"status",
|
|
4659
4946
|
"profile",
|
|
4660
4947
|
"people",
|
|
4661
4948
|
"places",
|
|
@@ -4893,8 +5180,71 @@ function quests(session, options) {
|
|
|
4893
5180
|
...threads.filter((thread) => thread.status === "resolved").reverse()
|
|
4894
5181
|
];
|
|
4895
5182
|
}
|
|
5183
|
+
/**
|
|
5184
|
+
* Every tracked value the player may read, by subject: the world's, their own (private ones too), the place's, those of the people they have met or are with, and of the things they carry
|
|
5185
|
+
* or see lying about, without the feelings every story has (the profile tells those in words). What is hidden, and what is private to someone else, is not read.
|
|
5186
|
+
*/
|
|
5187
|
+
function status(session) {
|
|
5188
|
+
const stand = standpoint(session);
|
|
5189
|
+
if (stand === void 0) return [];
|
|
5190
|
+
const values = (kind, id, key, audience) => shownVariables(session, kind, id, key, audience, { all: true }).filter(({ variable }) => variable.builtin !== true).map(({ variable, value }) => ({
|
|
5191
|
+
name: variable.name,
|
|
5192
|
+
value: describeValue(variable, value)
|
|
5193
|
+
}));
|
|
5194
|
+
const groups = [
|
|
5195
|
+
{
|
|
5196
|
+
subject: "world",
|
|
5197
|
+
values: values("world", 0, "world", "others")
|
|
5198
|
+
},
|
|
5199
|
+
{
|
|
5200
|
+
subject: "player",
|
|
5201
|
+
key: keyOf$1(stand.player),
|
|
5202
|
+
name: stand.player.name,
|
|
5203
|
+
values: values("character", stand.player.id, keyOf$1(stand.player), "self")
|
|
5204
|
+
},
|
|
5205
|
+
...stand.here === void 0 ? [] : [{
|
|
5206
|
+
subject: "place",
|
|
5207
|
+
key: locationKey(stand.here),
|
|
5208
|
+
name: stand.here.name,
|
|
5209
|
+
here: true,
|
|
5210
|
+
values: values("location", stand.here.id, locationKey(stand.here), "others")
|
|
5211
|
+
}],
|
|
5212
|
+
...people(session).flatMap((person) => {
|
|
5213
|
+
const character = session.characters.list().find((candidate) => keyOf$1(candidate) === person.key);
|
|
5214
|
+
return character === void 0 ? [] : [{
|
|
5215
|
+
subject: "person",
|
|
5216
|
+
key: person.key,
|
|
5217
|
+
name: person.name,
|
|
5218
|
+
here: person.here,
|
|
5219
|
+
values: values("character", character.id, person.key, "others")
|
|
5220
|
+
}];
|
|
5221
|
+
})
|
|
5222
|
+
];
|
|
5223
|
+
const things = [...session.items.contents({
|
|
5224
|
+
kind: "character",
|
|
5225
|
+
id: stand.player.id
|
|
5226
|
+
}).map((entry) => ({
|
|
5227
|
+
entry,
|
|
5228
|
+
here: false
|
|
5229
|
+
})), ...stand.here === void 0 ? [] : session.items.contents({
|
|
5230
|
+
kind: "location",
|
|
5231
|
+
id: stand.here.id
|
|
5232
|
+
}).map((entry) => ({
|
|
5233
|
+
entry,
|
|
5234
|
+
here: true
|
|
5235
|
+
}))].filter(({ entry }) => !entry.item.hidden);
|
|
5236
|
+
for (const { entry, here } of things) groups.push({
|
|
5237
|
+
subject: "thing",
|
|
5238
|
+
key: itemKey(entry.item),
|
|
5239
|
+
name: entry.item.name,
|
|
5240
|
+
here,
|
|
5241
|
+
values: values("item", entry.item.id, itemKey(entry.item), "others")
|
|
5242
|
+
});
|
|
5243
|
+
return groups.filter((group) => group.values.length > 0);
|
|
5244
|
+
}
|
|
4896
5245
|
/** One page per section; a new page is a new entry here and in `REFERENCE_SECTIONS`. */
|
|
4897
5246
|
const PAGES = {
|
|
5247
|
+
status,
|
|
4898
5248
|
profile,
|
|
4899
5249
|
people,
|
|
4900
5250
|
places,
|
|
@@ -5489,6 +5839,7 @@ function createApiHandler(deps) {
|
|
|
5489
5839
|
...interfaceRoutes(packs),
|
|
5490
5840
|
...presetRoutes(presets),
|
|
5491
5841
|
...lorebookRoutes(lorebooks),
|
|
5842
|
+
...folderRoutes(deps.folders),
|
|
5492
5843
|
...promptRoutes(deps.prompts),
|
|
5493
5844
|
...syncRoutes(sync)
|
|
5494
5845
|
};
|
|
@@ -5566,7 +5917,8 @@ async function deleteSession(deps, id) {
|
|
|
5566
5917
|
const ROOT_LAYOUT = [
|
|
5567
5918
|
"characters",
|
|
5568
5919
|
"sessions",
|
|
5569
|
-
"worlds"
|
|
5920
|
+
"worlds",
|
|
5921
|
+
"workspace"
|
|
5570
5922
|
];
|
|
5571
5923
|
/**
|
|
5572
5924
|
* Resolve the configured root to an absolute, normalized path.
|
|
@@ -6900,6 +7252,18 @@ async function startSession(deps, request) {
|
|
|
6900
7252
|
mode: answers.clockMode
|
|
6901
7253
|
}
|
|
6902
7254
|
};
|
|
7255
|
+
const givenAutonomy = (request.settings?.autonomy)?.enabled;
|
|
7256
|
+
if (world.autonomy === true && givenAutonomy === void 0) settings = {
|
|
7257
|
+
...settings,
|
|
7258
|
+
autonomy: {
|
|
7259
|
+
...settings.autonomy,
|
|
7260
|
+
enabled: true
|
|
7261
|
+
},
|
|
7262
|
+
...givenClock === void 0 && answers.clockMode === void 0 ? { clock: {
|
|
7263
|
+
...settings.clock,
|
|
7264
|
+
mode: "real"
|
|
7265
|
+
} } : {}
|
|
7266
|
+
};
|
|
6903
7267
|
const timeZone = settings.clock.timeZone !== "" ? settings.clock.timeZone : settings.clock.mode === "real" ? systemTimeZone() : world.clock?.timeZone ?? "UTC";
|
|
6904
7268
|
const tools = Object.fromEntries([.../* @__PURE__ */ new Set([
|
|
6905
7269
|
...Object.keys(world.tools ?? {}),
|
|
@@ -7680,6 +8044,7 @@ async function loadWorld(folder, dir, file, problems) {
|
|
|
7680
8044
|
...world.startQuestions === void 0 ? {} : { startQuestions: world.startQuestions },
|
|
7681
8045
|
...world.rules === void 0 ? {} : { rules: world.rules },
|
|
7682
8046
|
...world.tools === void 0 ? {} : { tools: world.tools },
|
|
8047
|
+
...world.autonomy === void 0 ? {} : { autonomy: world.autonomy },
|
|
7683
8048
|
...world.narrationVoice === void 0 ? {} : { narrationVoice: world.narrationVoice },
|
|
7684
8049
|
...world.sampling === void 0 ? {} : { sampling: world.sampling },
|
|
7685
8050
|
...world.preset === void 0 ? {} : { preset: world.preset },
|
|
@@ -9713,8 +10078,16 @@ const Config = z.object({
|
|
|
9713
10078
|
passwordRef: z.string().default(""),
|
|
9714
10079
|
intervalMinutes: z.number().min(0).default(0)
|
|
9715
10080
|
}).default({ ...DEFAULT_SYNC }).volatile(),
|
|
10081
|
+
offload: z.object({
|
|
10082
|
+
models: z.dict(z.object({
|
|
10083
|
+
route: z.string().default(""),
|
|
10084
|
+
model: z.string().default("")
|
|
10085
|
+
})).default({}),
|
|
10086
|
+
groups: z.array(z.array(z.string())).default([])
|
|
10087
|
+
}).default({ ...DEFAULT_OFFLOAD }).volatile(),
|
|
9716
10088
|
catalogueMaxBytes: z.number().min(1024).default(268435456).volatile(),
|
|
9717
10089
|
catalogueTrashDays: z.number().min(0).default(30).volatile(),
|
|
10090
|
+
autonomyTickSeconds: z.number().min(0).max(3600).default(30).volatile(),
|
|
9718
10091
|
importMaxUploadBytes: z.number().min(1024).default(104857600).volatile(),
|
|
9719
10092
|
importConcurrency: z.number().min(1).max(16).default(4).volatile(),
|
|
9720
10093
|
importReasoning: z.string().default("").volatile(),
|
|
@@ -9763,6 +10136,13 @@ function apply(ctx, config) {
|
|
|
9763
10136
|
const root = new RoleplayRoot(ctx, config.rootPath);
|
|
9764
10137
|
root.start();
|
|
9765
10138
|
const orchestration = new RoleplayOrchestration(ctx);
|
|
10139
|
+
orchestration.residency = new ModelResidency({
|
|
10140
|
+
config: () => offloadOf(config.offload.get()),
|
|
10141
|
+
admin: () => ctx.get("aiModels"),
|
|
10142
|
+
problem: (message) => {
|
|
10143
|
+
ctx.logger.warn(`roleplay: ${message}`);
|
|
10144
|
+
}
|
|
10145
|
+
});
|
|
9766
10146
|
const worlds = new WorldCatalog(ctx, root);
|
|
9767
10147
|
const prompts = new PromptLibrary(ctx, root);
|
|
9768
10148
|
prompts.bootstrap();
|
|
@@ -9772,6 +10152,38 @@ function apply(ctx, config) {
|
|
|
9772
10152
|
const languages = new AuthoringLanguages(ctx, () => join(root.path, "worlds"));
|
|
9773
10153
|
const authoringTools = new AuthoringTools(ctx, () => config.authoringTools.get());
|
|
9774
10154
|
const agent = new AgentSessions(agentServicesOf(ctx), () => root.path);
|
|
10155
|
+
const autonomy = new AutonomyTicker({
|
|
10156
|
+
sessions: () => listSessions({
|
|
10157
|
+
state: ctx.roleplayState,
|
|
10158
|
+
sessionsDir: () => join(root.path, "sessions")
|
|
10159
|
+
}).sessions.map((session) => ({
|
|
10160
|
+
id: session.id,
|
|
10161
|
+
name: session.name,
|
|
10162
|
+
archived: session.archivedAt !== void 0
|
|
10163
|
+
})),
|
|
10164
|
+
settings: (id) => liveSettings(sessionFolder(join(root.path, "sessions"), id)),
|
|
10165
|
+
ensure: async (id, name) => await agent.ensure(id, name),
|
|
10166
|
+
tick: async (chat, signal) => await orchestration.autonomy(chat, signal),
|
|
10167
|
+
problem: (message) => {
|
|
10168
|
+
ctx.logger.warn(`roleplay: ${message}`);
|
|
10169
|
+
}
|
|
10170
|
+
});
|
|
10171
|
+
ctx.effect(() => {
|
|
10172
|
+
let timer;
|
|
10173
|
+
const controller = new AbortController();
|
|
10174
|
+
const later = () => {
|
|
10175
|
+
const seconds = config.autonomyTickSeconds.get();
|
|
10176
|
+
timer = setTimeout(() => {
|
|
10177
|
+
(seconds === 0 ? Promise.resolve(0) : autonomy.run(controller.signal)).finally(later);
|
|
10178
|
+
}, Math.max(5, seconds === 0 ? 60 : seconds) * 1e3);
|
|
10179
|
+
timer.unref();
|
|
10180
|
+
};
|
|
10181
|
+
later();
|
|
10182
|
+
return () => {
|
|
10183
|
+
controller.abort();
|
|
10184
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
10185
|
+
};
|
|
10186
|
+
}, "roleplay: stories that go on while the player is away");
|
|
9775
10187
|
const authoring = new AuthoringSessions(agentServicesOf(ctx), () => root.path, prompts, languages);
|
|
9776
10188
|
const presetAuthoring = new PresetAuthoringSessions(agentServicesOf(ctx), () => root.path, prompts, languages);
|
|
9777
10189
|
const lorebookAuthoring = new LorebookAuthoringSessions(agentServicesOf(ctx), () => root.path, prompts, languages);
|
|
@@ -9951,6 +10363,14 @@ function apply(ctx, config) {
|
|
|
9951
10363
|
catalogue,
|
|
9952
10364
|
presets: presetLibrary,
|
|
9953
10365
|
lorebooks: lorebookLibrary,
|
|
10366
|
+
folders: new StoryFoldersService({
|
|
10367
|
+
root: () => root.path,
|
|
10368
|
+
sessionFolder: (id) => {
|
|
10369
|
+
const sessions = join(root.path, "sessions");
|
|
10370
|
+
if (!isSessionId(id) || !existsSync(sessionDatabase(sessions, id))) throw new SessionNotFoundError(`no session "${id}"`);
|
|
10371
|
+
return sessionFolder(sessions, id);
|
|
10372
|
+
}
|
|
10373
|
+
}),
|
|
9954
10374
|
prompts: new PromptManager(prompts),
|
|
9955
10375
|
packs: new InterfaceService({
|
|
9956
10376
|
open: (id) => ctx.roleplayState.openSession(deps.sessionsDir(), id),
|
|
@@ -10338,12 +10758,12 @@ async function editableWorld(worlds, worldId, rootPath) {
|
|
|
10338
10758
|
};
|
|
10339
10759
|
}
|
|
10340
10760
|
function imageGenerationOf(ctx) {
|
|
10341
|
-
const service = ctx.get("imageGeneration");
|
|
10761
|
+
const service = guarded(ctx.roleplayOrchestration.residency, "image", ctx.get("imageGeneration"), ["generate"]);
|
|
10342
10762
|
if (service === void 0) throw new AgentUnavailableError("no image generation provider is selected");
|
|
10343
10763
|
return service;
|
|
10344
10764
|
}
|
|
10345
10765
|
function textToSpeechOf(ctx) {
|
|
10346
|
-
const service = ctx.get("textToSpeech");
|
|
10766
|
+
const service = guarded(ctx.roleplayOrchestration.residency, "speech", ctx.get("textToSpeech"), ["synthesize"]);
|
|
10347
10767
|
if (service === void 0) throw new AgentUnavailableError("no text-to-speech provider is selected");
|
|
10348
10768
|
return service;
|
|
10349
10769
|
}
|