@dsh-agentic-roleplay/core 0.12.1 → 0.12.3
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/cordis.patch.yml +108 -0
- package/lib/{access-DifaiHrI.js → access-Csp80TFX.js} +2 -2
- package/lib/{authoring-tools-VOaXzr_R.js → authoring-tools-hacA5fG-.js} +1910 -1853
- package/lib/authoring.js +42 -34
- package/lib/{child-DzZ-aI6k.js → child-DTdY14S9.js} +45 -6
- package/lib/client.js +830 -571
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +3 -3
- package/lib/{dev-context-Bdm-eVer.js → dev-context-Cgv_wZbG.js} +12 -2
- package/lib/doctor.js +5 -4
- package/lib/{gallery-Ctz-UoFk.js → gallery-BNg0rPTp.js} +3 -3
- package/lib/{generator-Cv6WWmZT.js → generator-9-5at9cZ.js} +2 -2
- package/lib/helper.js +4 -10
- package/lib/{hooks-BdR3mBeM.js → hooks-DlrFO4aQ.js} +216 -45
- package/lib/images.js +4 -4
- package/lib/index.js +67 -45
- package/lib/{jail-Cp4zEfip.js → jail-DVbPSC0R.js} +2 -2
- package/lib/{library-BU2A_Dx8.js → library-DTxakw0z.js} +2 -2
- package/lib/{lorebook-author-tools-DUKcQu8P.js → lorebook-author-tools-dupq-kb_.js} +6 -6
- package/lib/lorebook-authoring.js +7 -6
- package/lib/{narration-CDsJ5wxH.js → narration--K2XVIHI.js} +2 -2
- package/lib/orchestration.js +12 -12
- package/lib/{pack-jail-CzHQu0n3.js → pack-jail-Bq0fzKi4.js} +43 -16
- package/lib/{packs-BZ-45J4-.js → packs-D-7EU3yU.js} +2 -2
- package/lib/{presenter-agent-C2ZkoxZu.js → presenter-agent-vFOxIuWv.js} +6 -6
- package/lib/{preset-BPnRPW-1.js → preset-RHcOG55T.js} +4 -4
- package/lib/{preset-author-tools-DBqPwn-o.js → preset-author-tools-Dwxnpv6V.js} +6 -6
- package/lib/preset-authoring.js +7 -6
- package/lib/{reflection-Cuy0YLv0.js → reflection-DibpEUQK.js} +7 -7
- package/lib/{serial-BZNeK57v.js → serial-CDGoXYh-.js} +1317 -1276
- package/lib/{turn-guard-xaFxYc1T.js → turn-guard-DDxikrq7.js} +3 -3
- package/package.json +4 -3
package/lib/compaction.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as liveSettings, t as decodeOutput } from "./narration
|
|
2
|
-
import { j as roleplaySessionOf, k as tokensOf, l as runChild, n as childModel, r as childSampling } from "./child-
|
|
3
|
-
import { t as promptFor } from "./access-
|
|
1
|
+
import { a as liveSettings, t as decodeOutput } from "./narration--K2XVIHI.js";
|
|
2
|
+
import { j as roleplaySessionOf, k as tokensOf, l as runChild, n as childModel, r as childSampling } from "./child-DTdY14S9.js";
|
|
3
|
+
import { t as promptFor } from "./access-Csp80TFX.js";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
6
6
|
import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
|
|
@@ -35,6 +35,16 @@ function silenceHarnessDevContext(ctx) {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
/** Removes DSH runtime facts from agents that receive their working context elsewhere. */
|
|
39
|
+
function silenceRuntimeContext(ctx) {
|
|
40
|
+
ctx.effect(() => ctx.systemPrompt.suppressRuntimeContext(), "roleplay: runtime context");
|
|
41
|
+
ctx.systemPrompt.context({
|
|
42
|
+
name: "working-directory:current",
|
|
43
|
+
order: ctx.systemPrompt.getContextOrder("WORKING_DIRECTORY"),
|
|
44
|
+
interpolate: false,
|
|
45
|
+
text: ""
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export { silenceRuntimeContext as n, silenceHarnessDevContext as t };
|
|
39
49
|
|
|
40
|
-
//# sourceMappingURL=dev-context-
|
|
50
|
+
//# sourceMappingURL=dev-context-Cgv_wZbG.js.map
|
package/lib/doctor.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as silenceHarnessDevContext } from "./dev-context-
|
|
2
|
-
import { A as chatSessionId } from "./child-
|
|
1
|
+
import { n as silenceRuntimeContext, t as silenceHarnessDevContext } from "./dev-context-Cgv_wZbG.js";
|
|
2
|
+
import { A as chatSessionId } from "./child-DTdY14S9.js";
|
|
3
3
|
import { n as doctorSessionOf } from "./doctor-chat-hL1a61hp.js";
|
|
4
|
-
import {
|
|
5
|
-
import { a as liveSettings } from "./narration
|
|
4
|
+
import { s as externalTools, t as externalToolLimit } from "./hooks-DlrFO4aQ.js";
|
|
5
|
+
import { a as liveSettings } from "./narration--K2XVIHI.js";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { createTools, isSessionId, sessionDatabase, sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
8
8
|
import { existsSync } from "node:fs";
|
|
@@ -79,6 +79,7 @@ function doctorApproval(exec) {
|
|
|
79
79
|
}
|
|
80
80
|
function apply(ctx) {
|
|
81
81
|
silenceHarnessDevContext(ctx);
|
|
82
|
+
silenceRuntimeContext(ctx);
|
|
82
83
|
const sessionsDir = () => join(ctx.roleplayRoot.path, "sessions");
|
|
83
84
|
const resolve = (chat) => {
|
|
84
85
|
const id = doctorSessionOf(chat);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as atomicWrite } from "./access-
|
|
2
|
-
import { _ as writeImageFileMetadata, a as LIBRARY_FOLDER, g as sidecarOf, h as readImageFileMetadata, m as mediaTypeOf, x as mapLimit } from "./library-
|
|
1
|
+
import { n as atomicWrite } from "./access-Csp80TFX.js";
|
|
2
|
+
import { _ as writeImageFileMetadata, a as LIBRARY_FOLDER, g as sidecarOf, h as readImageFileMetadata, m as mediaTypeOf, x as mapLimit } from "./library-DTxakw0z.js";
|
|
3
3
|
import { join, sep } from "node:path";
|
|
4
4
|
import { lstat, readFile, readdir, realpath, stat } from "node:fs/promises";
|
|
5
5
|
// src/host/images/gallery.ts
|
|
@@ -187,4 +187,4 @@ async function updateImage(sessionFolder, path, update) {
|
|
|
187
187
|
}
|
|
188
188
|
export { updateImage as i, galleryFile as n, listGallery as r, describeGalleryImage as t };
|
|
189
189
|
|
|
190
|
-
//# sourceMappingURL=gallery-
|
|
190
|
+
//# sourceMappingURL=gallery-BNg0rPTp.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as sceneImagePath, f as writeImage, u as referenceImagePath } from "./library-
|
|
1
|
+
import { d as sceneImagePath, f as writeImage, u as referenceImagePath } from "./library-DTxakw0z.js";
|
|
2
2
|
// src/host/images/generator.ts
|
|
3
3
|
const unique = (values) => [...new Set(values.map((value) => value.trim()).filter((value) => value !== ""))];
|
|
4
4
|
/** What a reference image shows: the subject and its stable look. */
|
|
@@ -147,4 +147,4 @@ async function generateTransientImage(service, request) {
|
|
|
147
147
|
}
|
|
148
148
|
export { uploadReferenceImage as a, transientPrompt as i, generateTransientImage as n, referencePrompt as r, generateReferenceImage as t };
|
|
149
149
|
|
|
150
|
-
//# sourceMappingURL=generator-
|
|
150
|
+
//# sourceMappingURL=generator-9-5at9cZ.js.map
|
package/lib/helper.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as silenceHarnessDevContext } from "./dev-context-
|
|
2
|
-
import { o as helpers } from "./child-
|
|
1
|
+
import { n as silenceRuntimeContext, t as silenceHarnessDevContext } from "./dev-context-Cgv_wZbG.js";
|
|
2
|
+
import { o as helpers } from "./child-DTdY14S9.js";
|
|
3
3
|
import { a as workspaceOf, n as storyRoots } from "./service-mRKwpWjX.js";
|
|
4
|
-
import { t as registerFoldersJail } from "./jail-
|
|
4
|
+
import { t as registerFoldersJail } from "./jail-DVbPSC0R.js";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
7
7
|
// src/helper.ts
|
|
@@ -22,13 +22,7 @@ function apply(ctx) {
|
|
|
22
22
|
return agent === void 0 ? "" : helpers.get(agent.session.id)?.persona ?? "";
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
|
|
26
|
-
ctx.systemPrompt.context({
|
|
27
|
-
name: "working-directory:current",
|
|
28
|
-
order: ctx.systemPrompt.getContextOrder("WORKING_DIRECTORY"),
|
|
29
|
-
interpolate: false,
|
|
30
|
-
text: ""
|
|
31
|
-
});
|
|
25
|
+
silenceRuntimeContext(ctx);
|
|
32
26
|
const rootOf = () => ctx.get("roleplayRoot")?.path;
|
|
33
27
|
registerFoldersJail(ctx, {
|
|
34
28
|
roots: async (session) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as addTokens, D as finishOf, E as cutOff, O as estimateAnswer, S as NO_TOKENS, a as childTrace, b as estimateTokens, f as tracerOf, j as roleplaySessionOf, l as runChild, n as childModel, r as childSampling, u as TurnTraces, v as requestsOf, x as tokensOf, y as blockText } from "./child-
|
|
2
|
-
import { _ as emptyStats, a as liveSettings, h as DECISION_SITES, m as rulesOf, n as encodeOutput, p as WORLD_RULES_KEY, r as encodePreview } from "./narration
|
|
3
|
-
import { t as promptFor } from "./access-
|
|
1
|
+
import { C as addTokens, D as finishOf, E as cutOff, O as estimateAnswer, S as NO_TOKENS, a as childTrace, b as estimateTokens, f as tracerOf, j as roleplaySessionOf, l as runChild, n as childModel, r as childSampling, u as TurnTraces, v as requestsOf, x as tokensOf, y as blockText } from "./child-DTdY14S9.js";
|
|
2
|
+
import { _ as emptyStats, a as liveSettings, h as DECISION_SITES, m as rulesOf, n as encodeOutput, p as WORLD_RULES_KEY, r as encodePreview } from "./narration--K2XVIHI.js";
|
|
3
|
+
import { t as promptFor } from "./access-Csp80TFX.js";
|
|
4
4
|
import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-Dfv8S8eq.js";
|
|
5
5
|
import { n as storyRoots } from "./service-mRKwpWjX.js";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
@@ -193,6 +193,51 @@ function skipTime(session, config, turn, round, wall, request) {
|
|
|
193
193
|
};
|
|
194
194
|
});
|
|
195
195
|
}
|
|
196
|
+
// src/host/commands/registry.ts
|
|
197
|
+
/**
|
|
198
|
+
* Registers the commands of the plugin's scope with DSH while the registry exists: they are listed, completed and run by the interface, and a command is not sent to the model.
|
|
199
|
+
* A plugin mounted by an agent preset registers them for that preset's agents only.
|
|
200
|
+
*/
|
|
201
|
+
function registerCommands(ctx, specs) {
|
|
202
|
+
ctx.inject(["commands"], (scope) => {
|
|
203
|
+
for (const spec of specs) scope.effect(() => scope.commands.register({
|
|
204
|
+
name: spec.name,
|
|
205
|
+
description: spec.description,
|
|
206
|
+
input: { hint: spec.hint },
|
|
207
|
+
...spec.recordInput === void 0 ? {} : { recordInput: spec.recordInput },
|
|
208
|
+
handler: (call) => spec.handler(call)
|
|
209
|
+
}), `roleplay: /${spec.name}`);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/** The registry of the running profile, or nothing when it has none. */
|
|
213
|
+
const registryOf = (ctx) => ctx.get("commands");
|
|
214
|
+
/**
|
|
215
|
+
* Runs a line the way the input box does when the agent knows the command it starts, for callers that are not the input box (the plugin's own starts, the HTTP API, the benchmark).
|
|
216
|
+
* Nothing when the line is no command of this agent; the caller then sends it on as a message.
|
|
217
|
+
*/
|
|
218
|
+
async function runCommandLine(ctx, agent, line, signal) {
|
|
219
|
+
const registry = registryOf(ctx);
|
|
220
|
+
if (registry === void 0) return void 0;
|
|
221
|
+
return (await registry.execute(agent, line, [], signal))?.result;
|
|
222
|
+
}
|
|
223
|
+
/** A command that was run from outside the input box and refused: what it says is for the person. */
|
|
224
|
+
var CommandRefusedError = class extends Error {};
|
|
225
|
+
/**
|
|
226
|
+
* Registers commands for one agent only, through the agent's own context: they are listed and run for that chat and for no other, and go with the agent. For commands that depend on
|
|
227
|
+
* what the chat holds (the commands a world defines).
|
|
228
|
+
*/
|
|
229
|
+
function registerAgentCommands(agent, specs) {
|
|
230
|
+
if (specs.length === 0) return;
|
|
231
|
+
agent.ctx.inject(["commands"], (scope) => {
|
|
232
|
+
for (const spec of specs) scope.effect(() => scope.commands.register({
|
|
233
|
+
name: spec.name,
|
|
234
|
+
description: spec.description,
|
|
235
|
+
input: { hint: spec.hint },
|
|
236
|
+
...spec.recordInput === void 0 ? {} : { recordInput: spec.recordInput },
|
|
237
|
+
handler: (call) => spec.handler(call)
|
|
238
|
+
}), `roleplay: /${spec.name}`);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
196
241
|
// src/host/sessions/errors.ts
|
|
197
242
|
var WorldNotFoundError = class extends Error {};
|
|
198
243
|
/** The world cannot be played as it is; `problems` say what to fix. */
|
|
@@ -227,6 +272,8 @@ function shippedPromptsDirectory(from = dirname(fileURLToPath(import.meta.url)))
|
|
|
227
272
|
if (dirname(directory) === directory) throw new Error("the prompts shipped with the package were not found");
|
|
228
273
|
}
|
|
229
274
|
}
|
|
275
|
+
/** A language tag as a world file or a person writes it: `ja`, `zh-CN`, `pt_BR`. */
|
|
276
|
+
const LANGUAGE_TAG = /^[A-Za-z]{2,3}(?:[-_][A-Za-z0-9]{2,8})?$/;
|
|
230
277
|
/** `zh-CN` and `ZH` are both `zh`; anything that is not a language tag is refused. */
|
|
231
278
|
function languageOf(tag) {
|
|
232
279
|
const primary = (tag ?? "en").trim().toLowerCase().split(/[-_]/)[0] ?? "";
|
|
@@ -236,7 +283,15 @@ function languageOf(tag) {
|
|
|
236
283
|
/** How a language is named inside a prompt, for the instruction to write in it. */
|
|
237
284
|
const LANGUAGE_NAMES$1 = {
|
|
238
285
|
en: "English",
|
|
239
|
-
zh: "中文"
|
|
286
|
+
zh: "中文",
|
|
287
|
+
ja: "日本語",
|
|
288
|
+
ko: "한국어",
|
|
289
|
+
es: "Español",
|
|
290
|
+
fr: "Français",
|
|
291
|
+
de: "Deutsch",
|
|
292
|
+
pt: "Português",
|
|
293
|
+
ru: "Русский",
|
|
294
|
+
it: "Italiano"
|
|
240
295
|
};
|
|
241
296
|
function fill(id, text, given, tag) {
|
|
242
297
|
const variables = {
|
|
@@ -253,7 +308,9 @@ function fill(id, text, given, tag) {
|
|
|
253
308
|
const textOf$1 = (path) => readFileSync(path, "utf8").replaceAll("\r\n", "\n");
|
|
254
309
|
/** A prompt as the package ships it, without a roleplay root: for code that has none, such as tests. */
|
|
255
310
|
function shippedText(id, language = "en", variables = {}) {
|
|
256
|
-
|
|
311
|
+
const directory = shippedPromptsDirectory();
|
|
312
|
+
const path = [language, "en"].map((name) => join(directory, name, `${id}.md`)).find((candidate) => existsSync(candidate)) ?? join(directory, language, `${id}.md`);
|
|
313
|
+
return fill(id, textOf$1(path), variables, language);
|
|
257
314
|
}
|
|
258
315
|
function listFiles(directory, prefix = "") {
|
|
259
316
|
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
@@ -2932,6 +2989,7 @@ function storeOf(session, folder, problem, queryVector, wall, prompt) {
|
|
|
2932
2989
|
recordDecisions: (site, report) => {
|
|
2933
2990
|
recordDecisions(folder, site, report);
|
|
2934
2991
|
},
|
|
2992
|
+
commands: () => commandsOf(session.metadata.getValue(COMMANDS_KEY)),
|
|
2935
2993
|
raiseCommand: (word, turn) => {
|
|
2936
2994
|
const commands = commandsOf(session.metadata.getValue(COMMANDS_KEY));
|
|
2937
2995
|
const used = word === void 0 ? void 0 : commands.find((command) => command.word === word.toLowerCase());
|
|
@@ -3047,20 +3105,6 @@ function storesOf(state, sessionsDir, problem = () => void 0, queryVector = () =
|
|
|
3047
3105
|
}
|
|
3048
3106
|
};
|
|
3049
3107
|
}
|
|
3050
|
-
// src/shared/ooc.ts
|
|
3051
|
-
/** The command or question in a player's message, or nothing when the message is an ordinary action. The request may be empty. */
|
|
3052
|
-
function parseOoc(text) {
|
|
3053
|
-
const value = text.trimStart();
|
|
3054
|
-
const boundary = value.search(/\s/u);
|
|
3055
|
-
const command = value.slice(0, boundary < 0 ? value.length : boundary).toLowerCase();
|
|
3056
|
-
if (command !== "/ooc" && command !== "/ask") return void 0;
|
|
3057
|
-
return {
|
|
3058
|
-
request: value.slice(command.length).trim(),
|
|
3059
|
-
question: command === "/ask"
|
|
3060
|
-
};
|
|
3061
|
-
}
|
|
3062
|
-
/** The longest answer to an out-of-character question. */
|
|
3063
|
-
const MAX_OOC_ANSWER = 1200;
|
|
3064
3108
|
// src/shared/tools.ts
|
|
3065
3109
|
/** What this version can offer. A name in a settings file or a world that is not here is kept and ignored. */
|
|
3066
3110
|
const OPTIONAL_TOOLS = [
|
|
@@ -4118,6 +4162,9 @@ function externalWithheld(registry, board, agent) {
|
|
|
4118
4162
|
function charactersGiven(registry, board, away) {
|
|
4119
4163
|
return away ? [] : externalGiven(registry, board, "characters");
|
|
4120
4164
|
}
|
|
4165
|
+
// src/shared/ooc.ts
|
|
4166
|
+
/** The longest answer to an out-of-character question. */
|
|
4167
|
+
const MAX_OOC_ANSWER = 1200;
|
|
4121
4168
|
// src/host/workspace/describe.ts
|
|
4122
4169
|
/** What an agent with file tools is told of where they reach: the shared workspace first, then the folders given to this story. Nothing for a story with no workspace. */
|
|
4123
4170
|
function foldersLine(roots, language) {
|
|
@@ -4300,19 +4347,10 @@ function answerRunner(deps) {
|
|
|
4300
4347
|
})).answer;
|
|
4301
4348
|
};
|
|
4302
4349
|
}
|
|
4303
|
-
// src/shared/dream.ts
|
|
4304
|
-
/** The dream a player asks to enter (`/dream`, `/dream Clara`, `/dream 做梦的人`), or nothing when the message does not start with `/dream`. `who` is empty when no one is named. */
|
|
4305
|
-
function parseDream(text) {
|
|
4306
|
-
const value = text.trimStart();
|
|
4307
|
-
if (value.slice(0, 6).toLowerCase() !== "/dream" || value.length > 6 && !/\s/u.test(value[6])) return void 0;
|
|
4308
|
-
return { who: value.slice(6).trim() };
|
|
4309
|
-
}
|
|
4310
4350
|
// src/shared/roll.ts
|
|
4311
|
-
/** The
|
|
4312
|
-
function
|
|
4313
|
-
const
|
|
4314
|
-
if (value.slice(0, 5).toLowerCase() !== "/roll" || value.length > 5 && !/\s/u.test(value[5])) return void 0;
|
|
4315
|
-
const body = value.slice(5).trimStart();
|
|
4351
|
+
/** The dice and the reason in what a player typed after `/roll`. The notation may be empty, and is then refused. */
|
|
4352
|
+
function rollArguments(rawInput) {
|
|
4353
|
+
const body = rawInput.trimStart();
|
|
4316
4354
|
const boundary = body.search(/\s/u);
|
|
4317
4355
|
return boundary < 0 ? {
|
|
4318
4356
|
expression: body,
|
|
@@ -4329,13 +4367,10 @@ const UNITS = [
|
|
|
4329
4367
|
[/^(?:d|day|days|天|日)$/iu, 1440]
|
|
4330
4368
|
];
|
|
4331
4369
|
/**
|
|
4332
|
-
* The wait in a player
|
|
4333
|
-
* unreadable, and is then `undefined` in `minutes`.
|
|
4370
|
+
* The wait in what a player typed after `/wait` (`2 hours`, `30m until the ferry`, `3天`). The time may be missing or unreadable, and is then `undefined` in `minutes`.
|
|
4334
4371
|
*/
|
|
4335
|
-
function
|
|
4336
|
-
const
|
|
4337
|
-
if (value.slice(0, 5).toLowerCase() !== "/wait" || value.length > 5 && !/\s/u.test(value[5])) return void 0;
|
|
4338
|
-
const body = value.slice(5).trim();
|
|
4372
|
+
function waitArguments(rawInput) {
|
|
4373
|
+
const body = rawInput.trim();
|
|
4339
4374
|
const match = /^(\d+(?:\.\d+)?)\s*([\p{L}]+)\s*(.*)$/su.exec(body);
|
|
4340
4375
|
if (match === null) return {
|
|
4341
4376
|
minutes: void 0,
|
|
@@ -4352,6 +4387,139 @@ function parseWait(text) {
|
|
|
4352
4387
|
reason: match[3].trim()
|
|
4353
4388
|
};
|
|
4354
4389
|
}
|
|
4390
|
+
// src/host/orchestration/player-commands.ts
|
|
4391
|
+
/** The most commands waiting for their turn to start: a command is taken the moment its message begins a turn, so this is only a bound. */
|
|
4392
|
+
const MAX_WAITING = 200;
|
|
4393
|
+
/**
|
|
4394
|
+
* What each command message was meant to do, by the id of the message the command sent: the turn that message begins takes it. Nothing reads the words of a message to tell a command from a move.
|
|
4395
|
+
*/
|
|
4396
|
+
var PlayerIntents = class {
|
|
4397
|
+
byMessage = /* @__PURE__ */ new Map();
|
|
4398
|
+
intend(messageId, command) {
|
|
4399
|
+
this.byMessage.set(messageId, command);
|
|
4400
|
+
for (const key of this.byMessage.keys()) {
|
|
4401
|
+
if (this.byMessage.size <= MAX_WAITING) break;
|
|
4402
|
+
this.byMessage.delete(key);
|
|
4403
|
+
}
|
|
4404
|
+
}
|
|
4405
|
+
/** The command of the first of these messages that has one, which is then forgotten. */
|
|
4406
|
+
take(messageIds) {
|
|
4407
|
+
for (const id of messageIds) {
|
|
4408
|
+
const command = this.byMessage.get(id);
|
|
4409
|
+
if (command !== void 0) {
|
|
4410
|
+
this.byMessage.delete(id);
|
|
4411
|
+
return command;
|
|
4412
|
+
}
|
|
4413
|
+
}
|
|
4414
|
+
}
|
|
4415
|
+
};
|
|
4416
|
+
/** The game master of a roleplay chat: the agent a player's command is for. */
|
|
4417
|
+
const isGameMaster = (agent) => agent.session.header.origin !== "subagent" && roleplaySessionOf(agent.session.id) !== void 0;
|
|
4418
|
+
/** Sends the command to the game master as the player's own message, which is what the turn it begins is the answer to. */
|
|
4419
|
+
function play(intents, agent, name, rawInput, command) {
|
|
4420
|
+
if (!isGameMaster(agent)) return {
|
|
4421
|
+
kind: "error",
|
|
4422
|
+
text: `/${name} is played in a roleplay chat`
|
|
4423
|
+
};
|
|
4424
|
+
const message = createUserMessage({
|
|
4425
|
+
content: [{
|
|
4426
|
+
type: "text",
|
|
4427
|
+
text: `/${name}${rawInput}`
|
|
4428
|
+
}],
|
|
4429
|
+
source: { kind: "user" }
|
|
4430
|
+
});
|
|
4431
|
+
intents.intend(String(message.id), command);
|
|
4432
|
+
agent.followup(message);
|
|
4433
|
+
return { kind: "success" };
|
|
4434
|
+
}
|
|
4435
|
+
/** The commands every roleplay chat has: out-of-character commands and questions, dice, time and dreams. */
|
|
4436
|
+
function playerCommands(intents) {
|
|
4437
|
+
const ooc = (name, description) => ({
|
|
4438
|
+
name,
|
|
4439
|
+
description,
|
|
4440
|
+
hint: name === "ooc" ? "<what to change in the story>" : "<what to ask>",
|
|
4441
|
+
recordInput: false,
|
|
4442
|
+
handler: ({ agent, rawInput }) => {
|
|
4443
|
+
const request = rawInput.trim();
|
|
4444
|
+
if (request === "") return {
|
|
4445
|
+
kind: "error",
|
|
4446
|
+
text: name === "ooc" ? "Say what to change: /ooc <what the story should do>" : "Say what to ask: /ask <your question>"
|
|
4447
|
+
};
|
|
4448
|
+
return play(intents, agent, name, rawInput, {
|
|
4449
|
+
kind: "ooc",
|
|
4450
|
+
request,
|
|
4451
|
+
question: name === "ask"
|
|
4452
|
+
});
|
|
4453
|
+
}
|
|
4454
|
+
});
|
|
4455
|
+
return [
|
|
4456
|
+
ooc("ooc", "Give the story an out-of-character instruction, outside what your character does"),
|
|
4457
|
+
ooc("ask", "Ask the story a question out of character; nothing in the story changes"),
|
|
4458
|
+
{
|
|
4459
|
+
name: "roll",
|
|
4460
|
+
description: "Roll dice as yourself: the result is told to the game master as a fact",
|
|
4461
|
+
hint: "<dice, for example 2d6+1> [why]",
|
|
4462
|
+
recordInput: false,
|
|
4463
|
+
handler: ({ agent, rawInput }) => {
|
|
4464
|
+
const roll = rollArguments(rawInput);
|
|
4465
|
+
if (roll.expression === "") return {
|
|
4466
|
+
kind: "error",
|
|
4467
|
+
text: "Say what to roll, for example /roll 2d6"
|
|
4468
|
+
};
|
|
4469
|
+
return play(intents, agent, "roll", rawInput, {
|
|
4470
|
+
kind: "roll",
|
|
4471
|
+
...roll
|
|
4472
|
+
});
|
|
4473
|
+
}
|
|
4474
|
+
},
|
|
4475
|
+
{
|
|
4476
|
+
name: "wait",
|
|
4477
|
+
description: "Let time pass in the story",
|
|
4478
|
+
hint: "<how long, for example 2 hours> [until what]",
|
|
4479
|
+
recordInput: false,
|
|
4480
|
+
handler: ({ agent, rawInput }) => {
|
|
4481
|
+
const wait = waitArguments(rawInput);
|
|
4482
|
+
if (wait.minutes === void 0) return {
|
|
4483
|
+
kind: "error",
|
|
4484
|
+
text: "Say how long, for example /wait 2 hours or /wait 30 minutes until the ferry"
|
|
4485
|
+
};
|
|
4486
|
+
return play(intents, agent, "wait", rawInput, {
|
|
4487
|
+
kind: "wait",
|
|
4488
|
+
minutes: wait.minutes,
|
|
4489
|
+
reason: wait.reason
|
|
4490
|
+
});
|
|
4491
|
+
}
|
|
4492
|
+
},
|
|
4493
|
+
{
|
|
4494
|
+
name: "dream",
|
|
4495
|
+
description: "Enter the dream of a character who is asleep",
|
|
4496
|
+
hint: "[whose dream]",
|
|
4497
|
+
recordInput: false,
|
|
4498
|
+
handler: ({ agent, rawInput }) => play(intents, agent, "dream", rawInput, {
|
|
4499
|
+
kind: "dream",
|
|
4500
|
+
who: rawInput.trim()
|
|
4501
|
+
})
|
|
4502
|
+
}
|
|
4503
|
+
];
|
|
4504
|
+
}
|
|
4505
|
+
/** DSH names a command with lower case ASCII letters, digits, `_` and `-`; a world's word may be in any script, and is then offered under the key of its flag, which is always such a name. */
|
|
4506
|
+
const COMMAND_NAME = /^[a-z][a-z0-9_-]*$/;
|
|
4507
|
+
/** The commands a world defines, for its chat: each is the player's move in the story, and raises the world's flag for the turn. */
|
|
4508
|
+
function worldCommands(intents, defined) {
|
|
4509
|
+
return defined.map((command) => {
|
|
4510
|
+
const name = COMMAND_NAME.test(command.word) ? command.word : command.key;
|
|
4511
|
+
return {
|
|
4512
|
+
name,
|
|
4513
|
+
description: name === command.word ? command.description : `/${command.word}: ${command.description}`,
|
|
4514
|
+
hint: "[what you do]",
|
|
4515
|
+
recordInput: false,
|
|
4516
|
+
handler: ({ agent, rawInput }) => play(intents, agent, name, rawInput, {
|
|
4517
|
+
kind: "world",
|
|
4518
|
+
word: command.word
|
|
4519
|
+
})
|
|
4520
|
+
};
|
|
4521
|
+
});
|
|
4522
|
+
}
|
|
4355
4523
|
// src/host/agents/repeat-guard.ts
|
|
4356
4524
|
/**
|
|
4357
4525
|
* Keeps an agent that is stuck from making the same call again and again (found live: an assistant made one create-and-list pair 47 times in a review, a game master repeated one
|
|
@@ -4486,6 +4654,8 @@ function commandBringsPeopleIn(store, command) {
|
|
|
4486
4654
|
}
|
|
4487
4655
|
function installHooks(ctx, deps) {
|
|
4488
4656
|
const { engine, boundaries, stores, timelines, previewTool } = deps;
|
|
4657
|
+
const intents = deps.intents ?? new PlayerIntents();
|
|
4658
|
+
registerCommands(ctx, playerCommands(intents));
|
|
4489
4659
|
/** The tools of the game master as the chat's settings say: its optional ones, and none of other plugins' that it was not given. */
|
|
4490
4660
|
const applyLimit = (agent, store) => {
|
|
4491
4661
|
externalToolLimit(agent, externalWithheld(agent.ctx.tools, store.settings().tools, "gameMaster"));
|
|
@@ -4550,6 +4720,7 @@ function installHooks(ctx, deps) {
|
|
|
4550
4720
|
if (store === void 0) return;
|
|
4551
4721
|
registerConditionalTools(agent, conditionsOf(agent.session.id));
|
|
4552
4722
|
applyLimit(agent, store);
|
|
4723
|
+
registerAgentCommands(agent, worldCommands(intents, store.commands?.() ?? []));
|
|
4553
4724
|
});
|
|
4554
4725
|
/** Where the open turn of each chat began, so its own events can be read back without walking the whole log. */
|
|
4555
4726
|
const openTurns = /* @__PURE__ */ new Map();
|
|
@@ -4633,10 +4804,10 @@ function installHooks(ctx, deps) {
|
|
|
4633
4804
|
turns.begin(owner.chat, payload.turn, text);
|
|
4634
4805
|
deps.rolls?.begin(owner.chat, store.story.metadata.get().id, began.parent);
|
|
4635
4806
|
const cast = store.cast();
|
|
4636
|
-
const
|
|
4637
|
-
const
|
|
4638
|
-
const used = store.raiseCommand?.(
|
|
4639
|
-
const dream =
|
|
4807
|
+
const intent = intents.take(payload.messages.filter((message) => message.source.kind === "user").map((message) => String(message.id)));
|
|
4808
|
+
const ooc = intent?.kind === "ooc" ? intent : void 0;
|
|
4809
|
+
const used = store.raiseCommand?.(intent?.kind === "world" ? intent.word : void 0, payload.turn);
|
|
4810
|
+
const dream = intent?.kind === "dream" ? intent : void 0;
|
|
4640
4811
|
const verdict = ooc === void 0 ? boundaries().inputValidator.validate({
|
|
4641
4812
|
text,
|
|
4642
4813
|
turn: payload.turn,
|
|
@@ -4718,7 +4889,7 @@ function installHooks(ctx, deps) {
|
|
|
4718
4889
|
if (arrived.length > 0) addLine("messages", tr("While the player was away, these messages reached their character, who has read them: {messages}. Refer to them only if the player does.", { messages: arrived.map((message) => `${message.name}: "${message.text}"`).join(" ") }));
|
|
4719
4890
|
const rules = store.rules();
|
|
4720
4891
|
if (rules.length > 0) addLine("rules", store.text("roleplay/rules", { rules: rules.map((rule) => `- ${rule}`).join("\n") }));
|
|
4721
|
-
const wanted =
|
|
4892
|
+
const wanted = intent?.kind === "roll" ? intent : void 0;
|
|
4722
4893
|
if (wanted !== void 0) try {
|
|
4723
4894
|
const made = rollPlain(wanted.expression, deps.rolls?.roller(owner.chat));
|
|
4724
4895
|
const roll = store.story.dice.record({
|
|
@@ -4773,7 +4944,7 @@ function installHooks(ctx, deps) {
|
|
|
4773
4944
|
}));
|
|
4774
4945
|
}
|
|
4775
4946
|
}
|
|
4776
|
-
const waiting =
|
|
4947
|
+
const waiting = intent?.kind === "wait" ? intent : void 0;
|
|
4777
4948
|
if (waiting !== void 0) {
|
|
4778
4949
|
const clock = store.settings().clock;
|
|
4779
4950
|
const refusal = clock.mode === "real" ? tr("this chat follows the clock on the wall, so time cannot be skipped") : waiting.minutes === void 0 ? tr("say how long, for example /wait 2 hours or /wait 30 minutes until the ferry") : waiting.minutes > clock.maxSkipDays * 1440 ? tr("that is more than the {days} days this chat allows in one skip", { days: clock.maxSkipDays }) : void 0;
|
|
@@ -4837,6 +5008,6 @@ function installHooks(ctx, deps) {
|
|
|
4837
5008
|
};
|
|
4838
5009
|
});
|
|
4839
5010
|
}
|
|
4840
|
-
export {
|
|
5011
|
+
export { copyWorldPrompts as $, plotProgressOf as A, parsePlotsFile as B, readNotes as C, referent as D, sameWords as E, textLanguage as F, readDocument as G, COMMANDS_KEY as H, wrongLanguage as I, errorMessage as J, Reader as K, readUsage as L, LANGUAGE_NAMES as M, STORY_LANGUAGES as N, RESULTS as O, isStoryLanguage as P, PromptLibrary as Q, PLOTS_FILE_NAME as R, notesOfSession as S, defaultBoundaries as T, commandFlagKey as U, plotReferenceProblems as V, commandsOf as W, LANGUAGE_TAG as X, LANGUAGE_FOLDER as Y, PROMPTS_FOLDER as Z, readTraces as _, ClockError as _t, MAX_OOC_ANSWER as a, shippedPromptsDirectory as at, readWithdrawn as b, AUTHORING_NEEDS as bt, externalWithheld as c, InvalidStartError as ct, record as d, SessionArchivedError as dt, inheritPrompts as et, toolEnabled as f, SessionNotFoundError as ft, readRunDetail as g, runCommandLine as gt, readActivity as h, registerCommands as ht, characterRunner as i, shippedLanguages as it, populatePlots as j, PLOTS_METADATA_KEY as k, PREVIEW_TOOL as l, InvalidWorldError as lt, readDecisionStats as m, CommandRefusedError as mt, installHooks as n, listFiles as nt, externalGiven as o, shippedText as ot, storesOf as p, WorldNotFoundError as pt, formatIssue as q, guardRepeatedCalls as r, promptProblem as rt, externalTools as s, AgentUnavailableError as st, externalToolLimit as t, languageOf as tt, createTools$1 as u, ReflectionRefusedError as ut, readVerdicts as v, describeWhen as vt, observeAsPlayer as w, addToNote as x, COMPARISONS as xt, writeVerdicts as y, zoneOf as yt, loadPlots as z };
|
|
4841
5012
|
|
|
4842
|
-
//# sourceMappingURL=hooks-
|
|
5013
|
+
//# sourceMappingURL=hooks-DlrFO4aQ.js.map
|
package/lib/images.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as searchImages, c as presentedFor, n as interpretImage, o as tokensOf, r as imageTools, s as present, t as runImagePresenter } from "./presenter-agent-
|
|
2
|
-
import { i as updateImage, r as listGallery } from "./gallery-
|
|
3
|
-
import { c as nextSceneSerial, d as sceneImagePath, l as readImageMetadata, o as entityImageDirectory, s as inheritImages, t as addToLibrary, u as referenceImagePath, v as readPngMetadata, y as withPngMetadata } from "./library-
|
|
4
|
-
import { i as transientPrompt, n as generateTransientImage, r as referencePrompt, t as generateReferenceImage } from "./generator-
|
|
1
|
+
import { a as searchImages, c as presentedFor, n as interpretImage, o as tokensOf, r as imageTools, s as present, t as runImagePresenter } from "./presenter-agent-vFOxIuWv.js";
|
|
2
|
+
import { i as updateImage, r as listGallery } from "./gallery-BNg0rPTp.js";
|
|
3
|
+
import { c as nextSceneSerial, d as sceneImagePath, l as readImageMetadata, o as entityImageDirectory, s as inheritImages, t as addToLibrary, u as referenceImagePath, v as readPngMetadata, y as withPngMetadata } from "./library-DTxakw0z.js";
|
|
4
|
+
import { i as transientPrompt, n as generateTransientImage, r as referencePrompt, t as generateReferenceImage } from "./generator-9-5at9cZ.js";
|
|
5
5
|
export { addToLibrary, entityImageDirectory, generateReferenceImage, generateTransientImage, imageTools, inheritImages, interpretImage, listGallery, nextSceneSerial, present, presentedFor, readImageMetadata, readPngMetadata, referenceImagePath, referencePrompt, runImagePresenter, sceneImagePath, searchImages, tokensOf, transientPrompt, updateImage, withPngMetadata };
|