@dsh-agentic-roleplay/core 0.7.3 → 0.8.2
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/README.md +1 -1
- package/lib/{access-DtOxFKBK.js → access-CfQWbNZP.js} +4 -7
- package/lib/authoring-tools-BgmC2oqU.js +3691 -0
- package/lib/authoring.js +59 -24
- package/lib/{child-CyCViUKa.js → child-lYYeOwl2.js} +147 -46
- package/lib/client.js +931 -860
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +8 -13
- package/lib/{doctor-chat-ByDfCMeo.js → doctor-chat-hL1a61hp.js} +2 -3
- package/lib/doctor.js +6 -8
- package/lib/{gallery-DmBZ2L5l.js → gallery-D1V4h8vh.js} +3 -4
- package/lib/{generator-BmdoTIL2.js → generator-CLPosooC.js} +3 -4
- package/lib/helper.js +2 -3
- package/lib/{hooks-C8eELrni.js → hooks-rQTTeOC4.js} +144 -88
- package/lib/images.js +4 -4
- package/lib/index.js +1024 -913
- package/lib/{library-lVNf9qG_.js → library-Dfu0dgRj.js} +32 -21
- package/lib/{lorebook-author-tools-BDOs4i5C.js → lorebook-author-tools-BAaAqZZm.js} +11 -14
- package/lib/lorebook-authoring.js +5 -6
- package/lib/{narration-DvFBqmqe.js → narration-CjB_KwwY.js} +58 -20
- package/lib/orchestration.js +138 -72
- package/lib/{pack-jail-DeTscGT2.js → pack-jail-CN-314ln.js} +94 -137
- package/lib/{packs-CY8ms8v_.js → packs-DIj5BEfq.js} +6 -10
- package/lib/{presenter-agent-cFR4sos3.js → presenter-agent-DR0KvLE0.js} +13 -19
- package/lib/{preset-n4-j6k4S.js → preset-CscHj1-Y.js} +5 -5
- package/lib/{preset-author-tools-2m4BLtws.js → preset-author-tools-CxluF8qc.js} +13 -15
- package/lib/preset-authoring.js +6 -7
- package/lib/presets-HB8kJTaE.js +3993 -0
- package/lib/{reflection-CJB5s0ip.js → reflection-Dg1xtOTW.js} +137 -148
- package/lib/{text-Cwl5s0j0.js → text-DyRN4nDP.js} +13 -7
- package/lib/{turn-guard-BvCs1VxB.js → turn-guard-g_hDn0jR.js} +6 -7
- package/package.json +29 -29
- package/prompts/en/import/casting.md +14 -0
- package/prompts/en/import/character.md +1 -0
- package/prompts/en/import/classifier.md +9 -0
- package/prompts/en/import/finish-draft.md +1 -0
- package/prompts/en/import/generator.md +8 -0
- package/prompts/en/import/notice-repair.md +4 -0
- package/prompts/en/import/repair-again.md +3 -0
- package/prompts/en/import/roster.md +1 -0
- package/prompts/en/import/variables.md +1 -0
- package/prompts/en/roleplay/game-master.md +3 -0
- package/prompts/en/roleplay/standing.md +1 -0
- package/prompts/en/world/author.md +1 -1
- package/prompts/zh/import/casting.md +14 -0
- package/prompts/zh/import/character.md +1 -0
- package/prompts/zh/import/classifier.md +9 -0
- package/prompts/zh/import/finish-draft.md +1 -0
- package/prompts/zh/import/generator.md +8 -0
- package/prompts/zh/import/notice-repair.md +4 -0
- package/prompts/zh/import/repair-again.md +3 -0
- package/prompts/zh/import/roster.md +1 -0
- package/prompts/zh/import/variables.md +1 -0
- package/prompts/zh/roleplay/game-master.md +3 -0
- package/prompts/zh/roleplay/standing.md +1 -0
- package/prompts/zh/world/author.md +1 -1
- package/lib/authoring-tools-CIsWbq0B.js +0 -6317
- package/lib/route-C6SHz9j2.js +0 -518
|
@@ -1,16 +1,34 @@
|
|
|
1
|
-
import { o as roleplaySessionOf, t as promptFor } from "./access-
|
|
2
|
-
import { _ as
|
|
3
|
-
import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-
|
|
4
|
-
import { a as childTrace, c as runChild, f as tokensOf, m as addTokens, n as childModel, p as NO_TOKENS, r as childSampling, v as estimateAnswer } from "./child-
|
|
1
|
+
import { o as roleplaySessionOf, t as promptFor } from "./access-CfQWbNZP.js";
|
|
2
|
+
import { _ as DECISION_SITES, a as liveSettings, g as rulesOf, h as WORLD_RULES_KEY, n as encodeOutput, r as encodePreview, y as emptyStats } from "./narration-CjB_KwwY.js";
|
|
3
|
+
import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-DyRN4nDP.js";
|
|
4
|
+
import { a as childTrace, c as runChild, f as tokensOf, m as addTokens, n as childModel, p as NO_TOKENS, r as childSampling, v as estimateAnswer } from "./child-lYYeOwl2.js";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
import { copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { readFile, stat } from "node:fs/promises";
|
|
7
8
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
8
9
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
9
10
|
import { fileURLToPath } from "node:url";
|
|
10
11
|
import { Service } from "@deepseek-ai/cordis";
|
|
11
|
-
import { readFile, stat } from "node:fs/promises";
|
|
12
12
|
import { DAY, ENGAGEMENT_GRACE, ITEM_ACTIONS, MINUTE, SECOND, addLocalDays, agendaAt, announcements, applyItemPlan, changeItem, changeVariable, clockTime, createCharacterTools, createDiceTools, createTools, dayPart, describeDuration, describeInstant, describeValue, holidaysOn, inAudience, isSessionId, itemKey, localTime, locationKey, nextOccurrence, nextTimeOfDay, occurrenceAt, parseInstant, planItemChange, planVariableChange, readCalendar, rollPlain, seasonOf, sessionDatabase, sessionFolder, shownVariables } from "@dsh-agentic-roleplay/state";
|
|
13
|
-
|
|
13
|
+
// ../dsh-roleplay-model/src/trigger.ts
|
|
14
|
+
/** The reasons the world author is asked to make something up in play; a trigger that has the author make a person names one of them. */
|
|
15
|
+
const AUTHORING_NEEDS = [
|
|
16
|
+
"scene_change",
|
|
17
|
+
"arrival",
|
|
18
|
+
"introduction",
|
|
19
|
+
"object",
|
|
20
|
+
"variable",
|
|
21
|
+
"trigger"
|
|
22
|
+
];
|
|
23
|
+
const COMPARISONS = [
|
|
24
|
+
"eq",
|
|
25
|
+
"ne",
|
|
26
|
+
"lt",
|
|
27
|
+
"le",
|
|
28
|
+
"gt",
|
|
29
|
+
"ge"
|
|
30
|
+
];
|
|
31
|
+
// ../dsh-roleplay-model/src/plot.ts
|
|
14
32
|
const PLOT_STATUSES = [
|
|
15
33
|
"dormant",
|
|
16
34
|
"available",
|
|
@@ -27,8 +45,7 @@ const PLOT_NUDGE_MODES = [
|
|
|
27
45
|
"escalation",
|
|
28
46
|
"breathing_room"
|
|
29
47
|
];
|
|
30
|
-
|
|
31
|
-
//#region src/host/sessions/errors.ts
|
|
48
|
+
// src/host/sessions/errors.ts
|
|
32
49
|
var WorldNotFoundError = class extends Error {};
|
|
33
50
|
/** The world cannot be played as it is; `problems` say what to fix. */
|
|
34
51
|
var InvalidWorldError = class extends Error {
|
|
@@ -47,8 +64,7 @@ var AgentUnavailableError = class extends Error {};
|
|
|
47
64
|
var SessionArchivedError = class extends Error {};
|
|
48
65
|
/** A reflection cannot be started now: a turn is being played, or one is already running. */
|
|
49
66
|
var ReflectionRefusedError = class extends Error {};
|
|
50
|
-
|
|
51
|
-
//#region src/host/prompts/library.ts
|
|
67
|
+
// src/host/prompts/library.ts
|
|
52
68
|
const PROMPTS_FOLDER = "prompts";
|
|
53
69
|
const SESSION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
54
70
|
const ID = /^[a-z0-9-]+(\/[a-z0-9-]+)*$/;
|
|
@@ -232,13 +248,11 @@ function inheritPrompts(from, to) {
|
|
|
232
248
|
function shippedLanguages(shipped = shippedPromptsDirectory()) {
|
|
233
249
|
return readdirSync(shipped, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
234
250
|
}
|
|
235
|
-
|
|
236
|
-
//#region src/host/errors.ts
|
|
251
|
+
// src/host/errors.ts
|
|
237
252
|
function errorMessage(error) {
|
|
238
253
|
return error instanceof Error ? error.message : String(error);
|
|
239
254
|
}
|
|
240
|
-
|
|
241
|
-
//#region src/host/validation.ts
|
|
255
|
+
// src/host/validation.ts
|
|
242
256
|
function formatIssue({ path, message }) {
|
|
243
257
|
return path === "" ? message : `${path}: ${message}`;
|
|
244
258
|
}
|
|
@@ -372,8 +386,7 @@ var Reader = class Reader {
|
|
|
372
386
|
return this.path === "" ? key : key === "" ? this.path : `${this.path}.${key}`;
|
|
373
387
|
}
|
|
374
388
|
};
|
|
375
|
-
|
|
376
|
-
//#region src/host/read-document.ts
|
|
389
|
+
// src/host/read-document.ts
|
|
377
390
|
/** Authored documents are short; a larger file is not one. */
|
|
378
391
|
const MAX_DOCUMENT_BYTES = 1048576;
|
|
379
392
|
/**
|
|
@@ -395,8 +408,16 @@ async function readDocument(file, parse, problems) {
|
|
|
395
408
|
message: formatIssue(issue)
|
|
396
409
|
});
|
|
397
410
|
}
|
|
398
|
-
|
|
399
|
-
|
|
411
|
+
// src/shared/commands.ts
|
|
412
|
+
const COMMANDS_KEY = "roleplay.commands";
|
|
413
|
+
/** The name of the flag a command raises. */
|
|
414
|
+
const commandFlagKey = (command) => `command_${command.key}`;
|
|
415
|
+
/** The commands kept with a story, or none when the value is missing or is not a list of commands. */
|
|
416
|
+
function commandsOf(value) {
|
|
417
|
+
if (!Array.isArray(value)) return [];
|
|
418
|
+
return value.filter((entry) => typeof entry === "object" && entry !== null && typeof entry.word === "string" && typeof entry.key === "string" && typeof entry.description === "string");
|
|
419
|
+
}
|
|
420
|
+
// src/host/plots/load.ts
|
|
400
421
|
const PLOTS_FILE_NAME = "plots.json";
|
|
401
422
|
function development(reader, fallback) {
|
|
402
423
|
return {
|
|
@@ -505,8 +526,7 @@ function plotReferenceProblems(plots, entities) {
|
|
|
505
526
|
const known = new Set(entities);
|
|
506
527
|
return plots.flatMap((plot) => plot.participants.filter((participant) => !known.has(participant)).map((participant) => `plot "${plot.id}" names unknown participant "${participant}"`));
|
|
507
528
|
}
|
|
508
|
-
|
|
509
|
-
//#region src/host/translate/language.ts
|
|
529
|
+
// src/host/translate/language.ts
|
|
510
530
|
const STORY_LANGUAGES = ["en", "zh"];
|
|
511
531
|
/** Less than this many letters of either script is too little to tell a language. */
|
|
512
532
|
const MIN_LETTERS = 20;
|
|
@@ -552,8 +572,7 @@ function wrongLanguage(wanted, texts, options = {}) {
|
|
|
552
572
|
});
|
|
553
573
|
return wrong.length === 0 ? void 0 : `${wrong.join(" and ")}: write it in ${LANGUAGE_NAMES[wanted].en} (${LANGUAGE_NAMES[wanted][wanted]})`;
|
|
554
574
|
}
|
|
555
|
-
|
|
556
|
-
//#region src/host/pacing/director.ts
|
|
575
|
+
// src/host/pacing/director.ts
|
|
557
576
|
const PLOTS_METADATA_KEY = "roleplay.pacing.plots";
|
|
558
577
|
function populatePlots(metadata, plots) {
|
|
559
578
|
const progress = plots.map((plot) => ({
|
|
@@ -648,8 +667,7 @@ function updatePlotProgress(store, plotId, developmentId, action) {
|
|
|
648
667
|
store.story.metadata.setValue(PLOTS_METADATA_KEY, plots);
|
|
649
668
|
return progress;
|
|
650
669
|
}
|
|
651
|
-
|
|
652
|
-
//#region src/host/orchestration/protocol.ts
|
|
670
|
+
// src/host/orchestration/protocol.ts
|
|
653
671
|
const COMMITMENTS = [
|
|
654
672
|
"low",
|
|
655
673
|
"medium",
|
|
@@ -790,8 +808,7 @@ function parseCharacterAction(value) {
|
|
|
790
808
|
...told === "" ? {} : { account: told }
|
|
791
809
|
};
|
|
792
810
|
}
|
|
793
|
-
|
|
794
|
-
//#region src/host/clock/story-clock.ts
|
|
811
|
+
// src/host/clock/story-clock.ts
|
|
795
812
|
var ClockError = class extends Error {};
|
|
796
813
|
/** A moment as it is told next to `now`: the clock when it is the same day, the date as well when it is not. */
|
|
797
814
|
function describeWhen(instant, now, zone, language = "en") {
|
|
@@ -938,8 +955,7 @@ function skipTime(session, config, turn, round, wall, request) {
|
|
|
938
955
|
};
|
|
939
956
|
});
|
|
940
957
|
}
|
|
941
|
-
|
|
942
|
-
//#region src/host/orchestration/observation.ts
|
|
958
|
+
// src/host/orchestration/observation.ts
|
|
943
959
|
/** What a character takes in where it stands and of what it carries: the place, the ways out and what they lead to, what lies in the open, what it holds. */
|
|
944
960
|
function observeSurroundings(session, characterId, turn) {
|
|
945
961
|
const placement = session.placements.get("character", characterId);
|
|
@@ -967,16 +983,14 @@ function observeAsPlayer(session, turn) {
|
|
|
967
983
|
const player = session.characters.list().find((character) => character.control === "player");
|
|
968
984
|
if (player !== void 0) observeSurroundings(session, player.id, turn);
|
|
969
985
|
}
|
|
970
|
-
|
|
971
|
-
//#region src/shared/notes.ts
|
|
986
|
+
// src/shared/notes.ts
|
|
972
987
|
/** The kinds the host stores; `unwritten` is made when the notes are read, from the rounds still waiting for the record keeper. */
|
|
973
988
|
const NOTE_KINDS = [
|
|
974
989
|
"suggestions",
|
|
975
990
|
"away",
|
|
976
991
|
"world"
|
|
977
992
|
];
|
|
978
|
-
|
|
979
|
-
//#region src/host/sessions/notes.ts
|
|
993
|
+
// src/host/sessions/notes.ts
|
|
980
994
|
const KEY$4 = "notes";
|
|
981
995
|
const isNote = (value) => {
|
|
982
996
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -1022,8 +1036,7 @@ function notesOfSession(deps, id) {
|
|
|
1022
1036
|
count: waiting
|
|
1023
1037
|
}];
|
|
1024
1038
|
}
|
|
1025
|
-
|
|
1026
|
-
//#region src/host/triggers/deliver.ts
|
|
1039
|
+
// src/host/triggers/deliver.ts
|
|
1027
1040
|
const KEY$3 = "triggers.withdrawn";
|
|
1028
1041
|
/** Why a note was withdrawn instead of told, by the number of the note. */
|
|
1029
1042
|
function readWithdrawn(session) {
|
|
@@ -1056,8 +1069,7 @@ function deliverNow(session, notes, clock) {
|
|
|
1056
1069
|
text
|
|
1057
1070
|
}));
|
|
1058
1071
|
}
|
|
1059
|
-
|
|
1060
|
-
//#region src/host/triggers/judged.ts
|
|
1072
|
+
// src/host/triggers/judged.ts
|
|
1061
1073
|
const KEY$2 = "triggers.judged";
|
|
1062
1074
|
function readVerdicts(session) {
|
|
1063
1075
|
const stored = session.metadata.getValue(KEY$2);
|
|
@@ -1081,8 +1093,12 @@ const verdictReader = (session) => {
|
|
|
1081
1093
|
const verdicts = readVerdicts(session);
|
|
1082
1094
|
return (statement) => verdicts[statement]?.holds === true;
|
|
1083
1095
|
};
|
|
1084
|
-
|
|
1085
|
-
|
|
1096
|
+
// src/host/triggers/notes.ts
|
|
1097
|
+
/** The beat effect of a note's trigger that has the world author make something instead of telling the game master. */
|
|
1098
|
+
function authorEffect(session, note) {
|
|
1099
|
+
if (note.kind !== "beat") return void 0;
|
|
1100
|
+
for (const effect of session.triggers.list().find((trigger) => trigger.id === note.triggerId)?.effects ?? []) if (effect.type === "beat" && effect.dispatch === "author") return { need: effect.need ?? "arrival" };
|
|
1101
|
+
}
|
|
1086
1102
|
/** Fires the triggers whose conditions just came true, and says what each did in words. A trigger that could not be applied is reported and given up. */
|
|
1087
1103
|
function fireTriggers(session, input) {
|
|
1088
1104
|
const { settings, turn, round, now, zone, problem } = input;
|
|
@@ -1098,7 +1114,7 @@ function fireTriggers(session, input) {
|
|
|
1098
1114
|
});
|
|
1099
1115
|
for (const failure of run.failed) problem(`the trigger "${failure.trigger.key}" could not fire and is given up: ${failure.problem}`);
|
|
1100
1116
|
const names = new Map(session.characters.list().map((character) => [character.id, character.name]));
|
|
1101
|
-
const fresh = session.triggers.notes({ status: "pending" }).filter((note) => note.id > before);
|
|
1117
|
+
const fresh = session.triggers.notes({ status: "pending" }).filter((note) => note.id > before && authorEffect(session, note) === void 0);
|
|
1102
1118
|
const told = new Map(deliverNow(session, fresh, {
|
|
1103
1119
|
now,
|
|
1104
1120
|
zone
|
|
@@ -1156,7 +1172,24 @@ function noteStore(session, settings, clock) {
|
|
|
1156
1172
|
pendingBeats: () => deliverNow(session, session.triggers.notes({
|
|
1157
1173
|
status: "pending",
|
|
1158
1174
|
kind: "beat"
|
|
1159
|
-
}), clock(session.metadata.get().turns + 1)),
|
|
1175
|
+
}).filter((note) => authorEffect(session, note) === void 0), clock(session.metadata.get().turns + 1)),
|
|
1176
|
+
claimAuthorBeats: () => {
|
|
1177
|
+
const claimed = [];
|
|
1178
|
+
for (const note of session.triggers.notes({
|
|
1179
|
+
status: "pending",
|
|
1180
|
+
kind: "beat"
|
|
1181
|
+
})) {
|
|
1182
|
+
const effect = authorEffect(session, note);
|
|
1183
|
+
if (effect === void 0) continue;
|
|
1184
|
+
session.triggers.resolveNote(note.id, "done");
|
|
1185
|
+
claimed.push({
|
|
1186
|
+
id: note.id,
|
|
1187
|
+
need: effect.need,
|
|
1188
|
+
text: note.text
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
return claimed;
|
|
1192
|
+
},
|
|
1160
1193
|
resolveBeats: (ids) => {
|
|
1161
1194
|
const pending = new Set(session.triggers.notes({
|
|
1162
1195
|
status: "pending",
|
|
@@ -1186,8 +1219,7 @@ function noteStore(session, settings, clock) {
|
|
|
1186
1219
|
}
|
|
1187
1220
|
};
|
|
1188
1221
|
}
|
|
1189
|
-
|
|
1190
|
-
//#region src/host/sessions/activity.ts
|
|
1222
|
+
// src/host/sessions/activity.ts
|
|
1191
1223
|
const KEY$1 = "activity";
|
|
1192
1224
|
const isEntry = (value) => {
|
|
1193
1225
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -1230,8 +1262,7 @@ function readRunDetail(folder, run) {
|
|
|
1230
1262
|
function forgetRunDetails(folder, dropped) {
|
|
1231
1263
|
for (const entry of dropped) if (entry.run !== void 0) rmSync(runFile(folder, entry.run), { force: true });
|
|
1232
1264
|
}
|
|
1233
|
-
|
|
1234
|
-
//#region src/host/decisions/stats.ts
|
|
1265
|
+
// src/host/decisions/stats.ts
|
|
1235
1266
|
const DECISIONS_FILE = "decisions.json";
|
|
1236
1267
|
const isSite = (value) => typeof value === "object" && value !== null && [
|
|
1237
1268
|
"runs",
|
|
@@ -1285,8 +1316,7 @@ function recordDecisions(folder, site, report, now = () => /* @__PURE__ */ new D
|
|
|
1285
1316
|
writeFileSync(aside, JSON.stringify(stats, null, 2));
|
|
1286
1317
|
renameSync(aside, target);
|
|
1287
1318
|
}
|
|
1288
|
-
|
|
1289
|
-
//#region src/host/sessions/usage.ts
|
|
1319
|
+
// src/host/sessions/usage.ts
|
|
1290
1320
|
const KEY = "usage";
|
|
1291
1321
|
const isCount = (value) => typeof value === "object" && value !== null && [
|
|
1292
1322
|
"input",
|
|
@@ -1322,8 +1352,7 @@ function addUsage(session, turn, who, tokens) {
|
|
|
1322
1352
|
all.sort((a, b) => a.turn - b.turn);
|
|
1323
1353
|
session.metadata.setValue(KEY, all);
|
|
1324
1354
|
}
|
|
1325
|
-
|
|
1326
|
-
//#region src/host/clock/agenda.ts
|
|
1355
|
+
// src/host/clock/agenda.ts
|
|
1327
1356
|
const CURSOR = "agenda.cursor";
|
|
1328
1357
|
const ASKED = "agenda.asked";
|
|
1329
1358
|
/** Characters on their way to the place their day has them at, by character id: they get there when the way has taken as long as it takes. */
|
|
@@ -1511,8 +1540,7 @@ function sceneAgenda(session, zone, now, moved) {
|
|
|
1511
1540
|
engagements
|
|
1512
1541
|
};
|
|
1513
1542
|
}
|
|
1514
|
-
|
|
1515
|
-
//#region src/host/clock/passage.ts
|
|
1543
|
+
// src/host/clock/passage.ts
|
|
1516
1544
|
/** The start of a turn: the time, how long the player was away, and what the days of the characters make of it. */
|
|
1517
1545
|
function startTurn(session, config, turn, wall) {
|
|
1518
1546
|
const started = beginTurn(session, config, turn, wall);
|
|
@@ -1543,8 +1571,7 @@ function agendaFor(session, config, turn, wall, characterId) {
|
|
|
1543
1571
|
const time = readTime(session, config, turn, wall());
|
|
1544
1572
|
return agendaView(session, characterId, zoneOf(config), time.now);
|
|
1545
1573
|
}
|
|
1546
|
-
|
|
1547
|
-
//#region src/host/clock/offscene.ts
|
|
1574
|
+
// src/host/clock/offscene.ts
|
|
1548
1575
|
const HANDLED = "offscene.handled";
|
|
1549
1576
|
const keyOf = (character) => character.sourceId ?? String(character.id);
|
|
1550
1577
|
function handledKeys(session) {
|
|
@@ -1626,8 +1653,7 @@ function dueOffScene(session, zone, now, language = "en") {
|
|
|
1626
1653
|
}
|
|
1627
1654
|
return items.sort((a, b) => a.at - b.at);
|
|
1628
1655
|
}
|
|
1629
|
-
|
|
1630
|
-
//#region src/host/variables/describe.ts
|
|
1656
|
+
// src/host/variables/describe.ts
|
|
1631
1657
|
/** What is tracked of a subject, in a line: `Health: hurt (2); Valence: unhappy (-0.4), usually even (0)`. */
|
|
1632
1658
|
function describeShown(shown) {
|
|
1633
1659
|
return shown.map(({ variable, value, baseline }) => {
|
|
@@ -1635,8 +1661,7 @@ function describeShown(shown) {
|
|
|
1635
1661
|
return `${variable.name}: ${describeValue(variable, value)}${usual}`;
|
|
1636
1662
|
}).join("; ");
|
|
1637
1663
|
}
|
|
1638
|
-
|
|
1639
|
-
//#region src/host/orchestration/skeleton.ts
|
|
1664
|
+
// src/host/orchestration/skeleton.ts
|
|
1640
1665
|
const PLAIN_IMPORTANCE = 2;
|
|
1641
1666
|
const CONSEQUENTIAL_IMPORTANCE = 3;
|
|
1642
1667
|
/** Who took in what an entry did: the people in the same place, the actor included; off stage, only those named in the round. */
|
|
@@ -1693,8 +1718,7 @@ function skeletonEvents(round) {
|
|
|
1693
1718
|
return events;
|
|
1694
1719
|
});
|
|
1695
1720
|
}
|
|
1696
|
-
|
|
1697
|
-
//#region src/host/orchestration/store.ts
|
|
1721
|
+
// src/host/orchestration/store.ts
|
|
1698
1722
|
/** The rules the session copied from its world when it started. */
|
|
1699
1723
|
function worldRules(session) {
|
|
1700
1724
|
const value = session.metadata.getValue(WORLD_RULES_KEY);
|
|
@@ -2024,6 +2048,14 @@ function storeOf(session, folder, problem, queryVector, wall, prompt) {
|
|
|
2024
2048
|
recordDecisions: (site, report) => {
|
|
2025
2049
|
recordDecisions(folder, site, report);
|
|
2026
2050
|
},
|
|
2051
|
+
raiseCommand: (word, turn) => {
|
|
2052
|
+
const commands = commandsOf(session.metadata.getValue(COMMANDS_KEY));
|
|
2053
|
+
const used = word === void 0 ? void 0 : commands.find((command) => command.word === word.toLowerCase());
|
|
2054
|
+
session.transaction(() => {
|
|
2055
|
+
for (const command of commands) session.variables.set(commandFlagKey(command), "world", 0, { value: command === used }, turn);
|
|
2056
|
+
});
|
|
2057
|
+
return used;
|
|
2058
|
+
},
|
|
2027
2059
|
recordUsage: (turn, tokens) => {
|
|
2028
2060
|
addUsage(session, turn, "master", tokens);
|
|
2029
2061
|
},
|
|
@@ -2077,8 +2109,7 @@ function storesOf(state, sessionsDir, problem = () => void 0, queryVector = () =
|
|
|
2077
2109
|
}
|
|
2078
2110
|
};
|
|
2079
2111
|
}
|
|
2080
|
-
|
|
2081
|
-
//#region src/shared/ooc.ts
|
|
2112
|
+
// src/shared/ooc.ts
|
|
2082
2113
|
/** The command or question in a player's message, or nothing when the message is an ordinary action. The request may be empty. */
|
|
2083
2114
|
function parseOoc(text) {
|
|
2084
2115
|
const value = text.trimStart();
|
|
@@ -2092,8 +2123,7 @@ function parseOoc(text) {
|
|
|
2092
2123
|
}
|
|
2093
2124
|
/** The longest answer to an out-of-character question. */
|
|
2094
2125
|
const MAX_OOC_ANSWER = 1200;
|
|
2095
|
-
|
|
2096
|
-
//#region src/shared/roll.ts
|
|
2126
|
+
// src/shared/roll.ts
|
|
2097
2127
|
/** The roll in a player's message, or nothing when the message does not start with `/roll`. The notation may be empty, and is then refused. */
|
|
2098
2128
|
function parseRoll(text) {
|
|
2099
2129
|
const value = text.trimStart();
|
|
@@ -2108,8 +2138,36 @@ function parseRoll(text) {
|
|
|
2108
2138
|
reason: body.slice(boundary).trim()
|
|
2109
2139
|
};
|
|
2110
2140
|
}
|
|
2111
|
-
|
|
2112
|
-
|
|
2141
|
+
// src/host/agents/repeat-guard.ts
|
|
2142
|
+
/**
|
|
2143
|
+
* 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
|
|
2144
|
+
* refused round resolution): past `limit` identical calls in one turn the call is refused with a word that sends it on, and when it goes on regardless the turn is ended. The count starts over at the first step of every turn.
|
|
2145
|
+
* @param languageOf the language of the chat the call belongs to, or nothing when the guard does not apply to it.
|
|
2146
|
+
*/
|
|
2147
|
+
function guardRepeatedCalls(ctx, languageOf, limit) {
|
|
2148
|
+
const calls = /* @__PURE__ */ new Map();
|
|
2149
|
+
ctx.on("agent/pre-step", async (payload, next) => {
|
|
2150
|
+
if (payload.step === 1) calls.delete(payload.agent.session.id);
|
|
2151
|
+
return await next();
|
|
2152
|
+
});
|
|
2153
|
+
ctx.on("tools/pre-execute", async (exec, next) => {
|
|
2154
|
+
const chat = exec.agent?.session.id;
|
|
2155
|
+
const language = chat === void 0 || exec.agent?.session.header.origin === "subagent" ? void 0 : languageOf(exec);
|
|
2156
|
+
if (chat === void 0 || language === void 0) return await next();
|
|
2157
|
+
const signature = `${exec.name}:${JSON.stringify(exec.arguments)}`;
|
|
2158
|
+
const seen = calls.get(chat) ?? /* @__PURE__ */ new Map();
|
|
2159
|
+
calls.set(chat, seen);
|
|
2160
|
+
const count = (seen.get(signature) ?? 0) + 1;
|
|
2161
|
+
seen.set(signature, count);
|
|
2162
|
+
if (count <= limit) return await next();
|
|
2163
|
+
if (count > limit + 5) exec.agent?.cancel({ kind: "user" }, { keepInbox: true });
|
|
2164
|
+
return {
|
|
2165
|
+
kind: "deny",
|
|
2166
|
+
reason: translator(languageOf$1(language))("This exact call was already made {count} times in this turn with the same result. Do not repeat it: go on with the next step, or finish and say what is left.", { count: count - 1 })
|
|
2167
|
+
};
|
|
2168
|
+
}, { prepend: true });
|
|
2169
|
+
}
|
|
2170
|
+
// src/shared/tools.ts
|
|
2113
2171
|
/** What this version can offer. A name in a settings file or a world that is not here is kept and ignored. */
|
|
2114
2172
|
const OPTIONAL_TOOLS = [
|
|
2115
2173
|
{
|
|
@@ -2181,8 +2239,7 @@ function toolEnabled(board, agent, id) {
|
|
|
2181
2239
|
function externalEnabled(board, agent, name) {
|
|
2182
2240
|
return board[agent]?.[name] === true;
|
|
2183
2241
|
}
|
|
2184
|
-
|
|
2185
|
-
//#region src/host/orchestration/character-runner.ts
|
|
2242
|
+
// src/host/orchestration/character-runner.ts
|
|
2186
2243
|
/**
|
|
2187
2244
|
* Runs each character as a one-shot child of the game master. It is the character and nothing
|
|
2188
2245
|
* else: it knows what its brief gives it, and its only tool (when the chat allows it) reaches
|
|
@@ -2320,19 +2377,7 @@ function answerRunner(deps) {
|
|
|
2320
2377
|
})).answer;
|
|
2321
2378
|
};
|
|
2322
2379
|
}
|
|
2323
|
-
|
|
2324
|
-
//#region src/host/orchestration/boundaries.ts
|
|
2325
|
-
/** Why the game master may ask for something to be made up: the story genuinely needs it. */
|
|
2326
|
-
const AUTHORING_NEEDS = [
|
|
2327
|
-
"scene_change",
|
|
2328
|
-
"arrival",
|
|
2329
|
-
"introduction",
|
|
2330
|
-
"object",
|
|
2331
|
-
"variable",
|
|
2332
|
-
"trigger"
|
|
2333
|
-
];
|
|
2334
|
-
//#endregion
|
|
2335
|
-
//#region src/host/pacing/author.ts
|
|
2380
|
+
// src/host/pacing/author.ts
|
|
2336
2381
|
const RESULT = {
|
|
2337
2382
|
type: "object",
|
|
2338
2383
|
required: [
|
|
@@ -2472,8 +2517,7 @@ async function authorPlot(parent, store, turn, signal) {
|
|
|
2472
2517
|
addSessionPlot(store, checked);
|
|
2473
2518
|
return checked;
|
|
2474
2519
|
}
|
|
2475
|
-
|
|
2476
|
-
//#region src/host/orchestration/tools.ts
|
|
2520
|
+
// src/host/orchestration/tools.ts
|
|
2477
2521
|
const ACTIVATE_TOOL = "activate_characters";
|
|
2478
2522
|
const RESOLVE_TOOL = "resolve_round";
|
|
2479
2523
|
const NARRATE_TOOL = "narrate";
|
|
@@ -3257,8 +3301,7 @@ function createTools$1(deps) {
|
|
|
3257
3301
|
narrate
|
|
3258
3302
|
];
|
|
3259
3303
|
}
|
|
3260
|
-
|
|
3261
|
-
//#region src/host/tools/external.ts
|
|
3304
|
+
// src/host/tools/external.ts
|
|
3262
3305
|
/** The reserved transport DSH presents tools through; it is never a tool of its own to switch. */
|
|
3263
3306
|
const RESERVED = /* @__PURE__ */ new Set(["run_code"]);
|
|
3264
3307
|
let own;
|
|
@@ -3290,8 +3333,7 @@ function externalGiven(registry, board, agent) {
|
|
|
3290
3333
|
function externalWithheld(registry, board, agent) {
|
|
3291
3334
|
return externalTools(registry).map((tool) => tool.name).filter((name) => !externalEnabled(board, agent, name));
|
|
3292
3335
|
}
|
|
3293
|
-
|
|
3294
|
-
//#region src/host/orchestration/hooks.ts
|
|
3336
|
+
// src/host/orchestration/hooks.ts
|
|
3295
3337
|
const notice = (text) => createUserMessage({
|
|
3296
3338
|
content: [{
|
|
3297
3339
|
type: "text",
|
|
@@ -3371,6 +3413,11 @@ function externalToolLimit(agent, withheld) {
|
|
|
3371
3413
|
* that uses the preset and also hear the agents that chat spawns, so each one
|
|
3372
3414
|
* first checks that it is looking at the game master of a roleplay chat.
|
|
3373
3415
|
*/
|
|
3416
|
+
/** Whether a trigger that has the world author make a person waits on the flag of a command: then the world, not the game master, brings the person in. */
|
|
3417
|
+
function commandBringsPeopleIn(store, command) {
|
|
3418
|
+
const flag = commandFlagKey(command);
|
|
3419
|
+
return store.story.triggers.list().some((trigger) => JSON.stringify(trigger.condition).includes(`"${flag}"`) && trigger.effects.some((effect) => effect.type === "beat" && effect.dispatch === "author"));
|
|
3420
|
+
}
|
|
3374
3421
|
function installHooks(ctx, deps) {
|
|
3375
3422
|
const { engine, boundaries, stores, timelines, previewTool } = deps;
|
|
3376
3423
|
const showPreviewTool = previewToggle(previewTool);
|
|
@@ -3381,6 +3428,10 @@ function installHooks(ctx, deps) {
|
|
|
3381
3428
|
showOptionalTools(agent, (tool) => toolEnabled(tools, "gameMaster", tool));
|
|
3382
3429
|
externalToolLimit(agent, externalWithheld(agent.ctx.tools, tools, "gameMaster"));
|
|
3383
3430
|
};
|
|
3431
|
+
guardRepeatedCalls(ctx, (exec) => {
|
|
3432
|
+
const owner = exec.agent === void 0 ? void 0 : ownerOf(exec.agent, 0);
|
|
3433
|
+
return owner === void 0 ? void 0 : stores(owner.chat)?.settings().prompts.language;
|
|
3434
|
+
}, 4);
|
|
3384
3435
|
ctx.on("agent/created", ({ agent }) => {
|
|
3385
3436
|
const owner = ownerOf(agent, 0);
|
|
3386
3437
|
const store = owner === void 0 ? void 0 : stores(owner.chat);
|
|
@@ -3429,6 +3480,8 @@ function installHooks(ctx, deps) {
|
|
|
3429
3480
|
await timelines.begin(owner.chat, payload.turn, text);
|
|
3430
3481
|
const cast = store.cast();
|
|
3431
3482
|
const ooc = parseOoc(text);
|
|
3483
|
+
const command = ooc === void 0 ? /^\/([\p{L}\p{N}_]+)/u.exec(text.trim())?.[1] : void 0;
|
|
3484
|
+
const used = store.raiseCommand?.(command, payload.turn);
|
|
3432
3485
|
const verdict = ooc === void 0 ? boundaries().inputValidator.validate({
|
|
3433
3486
|
text,
|
|
3434
3487
|
turn: payload.turn,
|
|
@@ -3477,6 +3530,10 @@ function installHooks(ctx, deps) {
|
|
|
3477
3530
|
...queryVector === void 0 ? {} : { queryVector }
|
|
3478
3531
|
})];
|
|
3479
3532
|
const pacing = ooc === void 0 ? pacingAdvice(store, payload.turn) : void 0;
|
|
3533
|
+
if (used !== void 0) lines.push([tr("The player used the world's command /{word}: {description} It is part of the story, not an out-of-character command: play it in the story. The world raises and lowers the command's own flag itself: never change it.", {
|
|
3534
|
+
word: used.word,
|
|
3535
|
+
description: used.description
|
|
3536
|
+
}), ...commandBringsPeopleIn(store, used) ? [tr("The world itself brings in anyone this command calls for, after this turn: do not make them up yourself with expand_world.")] : []].join(" "));
|
|
3480
3537
|
if (pacing !== void 0) lines.push(describePacingAdvice(pacing));
|
|
3481
3538
|
else if (ooc === void 0 && plotAuthorNeeded(store, payload.turn)) lines.push(store.text("roleplay/plot-hint"));
|
|
3482
3539
|
const rules = store.rules();
|
|
@@ -3520,7 +3577,6 @@ function installHooks(ctx, deps) {
|
|
|
3520
3577
|
};
|
|
3521
3578
|
});
|
|
3522
3579
|
}
|
|
3523
|
-
|
|
3524
|
-
export { listFiles as $, answerLimits as A, loadPlots as B, readNotes as C, describeWhen as D, describeTime as E, STORY_LANGUAGES as F, formatIssue as G, plotReferenceProblems as H, isStoryLanguage as I, PROMPTS_FOLDER as J, errorMessage as K, textLanguage as L, plotProgressOf as M, populatePlots as N, zoneOf as O, LANGUAGE_NAMES as P, languageOf as Q, wrongLanguage as R, notesOfSession as S, ClockError as T, readDocument as U, parsePlotsFile as V, Reader as W, copyWorldPrompts as X, PromptLibrary as Y, inheritPrompts as Z, readRunDetail as _, externalWithheld as a, InvalidWorldError as at, readWithdrawn as b, record as c, SessionNotFoundError as ct, toolEnabled as d, promptProblem as et, MAX_OOC_ANSWER as f, readActivity as g, readDecisionStats as h, externalTools as i, InvalidStartError as it, PLOTS_METADATA_KEY as j, RESULTS as k, AUTHORING_NEEDS as l, WorldNotFoundError as lt, readUsage as m, installHooks as n, shippedPromptsDirectory as nt, PREVIEW_TOOL as o, ReflectionRefusedError as ot, storesOf as p, LANGUAGE_FOLDER as q, externalGiven as r, AgentUnavailableError as rt, createTools$1 as s, SessionArchivedError as st, externalToolLimit as t, shippedLanguages as tt, characterRunner as u, readVerdicts as v, observeAsPlayer as w, addToNote as x, writeVerdicts as y, PLOTS_FILE_NAME as z };
|
|
3580
|
+
export { copyWorldPrompts as $, answerLimits as A, loadPlots as B, readNotes as C, describeWhen as D, describeTime as E, STORY_LANGUAGES as F, commandsOf as G, plotReferenceProblems as H, isStoryLanguage as I, formatIssue as J, readDocument as K, textLanguage as L, plotProgressOf as M, populatePlots as N, zoneOf as O, LANGUAGE_NAMES as P, PromptLibrary as Q, wrongLanguage as R, notesOfSession as S, ClockError as T, COMMANDS_KEY as U, parsePlotsFile as V, commandFlagKey as W, LANGUAGE_FOLDER as X, errorMessage as Y, PROMPTS_FOLDER as Z, readRunDetail as _, externalWithheld as a, shippedPromptsDirectory as at, readWithdrawn as b, record as c, InvalidStartError as ct, guardRepeatedCalls as d, SessionArchivedError as dt, inheritPrompts as et, MAX_OOC_ANSWER as f, SessionNotFoundError as ft, readActivity as g, readDecisionStats as h, COMPARISONS as ht, externalTools as i, shippedLanguages as it, PLOTS_METADATA_KEY as j, RESULTS as k, characterRunner as l, InvalidWorldError as lt, readUsage as m, AUTHORING_NEEDS as mt, installHooks as n, listFiles as nt, PREVIEW_TOOL as o, shippedText as ot, storesOf as p, WorldNotFoundError as pt, Reader as q, externalGiven as r, promptProblem as rt, createTools$1 as s, AgentUnavailableError as st, externalToolLimit as t, languageOf as tt, toolEnabled as u, ReflectionRefusedError as ut, readVerdicts as v, observeAsPlayer as w, addToNote as x, writeVerdicts as y, PLOTS_FILE_NAME as z };
|
|
3525
3581
|
|
|
3526
|
-
//# sourceMappingURL=hooks-
|
|
3582
|
+
//# sourceMappingURL=hooks-rQTTeOC4.js.map
|
package/lib/images.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { a as tokensOf, i as searchImages, n as interpretImage, o as present, r as imageTools, s as presentedFor, t as runImagePresenter } from "./presenter-agent-DR0KvLE0.js";
|
|
2
|
+
import { i as updateImage, r as listGallery } from "./gallery-D1V4h8vh.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-Dfu0dgRj.js";
|
|
4
|
+
import { i as transientPrompt, n as generateTransientImage, r as referencePrompt, t as generateReferenceImage } from "./generator-CLPosooC.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 };
|