@dsh-agentic-roleplay/core 0.8.1 → 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.
Files changed (35) hide show
  1. package/lib/{access-DtOxFKBK.js → access-CfQWbNZP.js} +4 -7
  2. package/lib/{authoring-tools-DNnx0Nts.js → authoring-tools-BgmC2oqU.js} +223 -106
  3. package/lib/authoring.js +15 -22
  4. package/lib/{child-D6mpkkCE.js → child-lYYeOwl2.js} +28 -51
  5. package/lib/client.js +615 -778
  6. package/lib/client.js.map +1 -1
  7. package/lib/compaction.js +8 -13
  8. package/lib/{doctor-chat-ByDfCMeo.js → doctor-chat-hL1a61hp.js} +2 -3
  9. package/lib/doctor.js +6 -8
  10. package/lib/{gallery-D9nG3C78.js → gallery-D1V4h8vh.js} +3 -4
  11. package/lib/{generator-r1Czm7oi.js → generator-CLPosooC.js} +3 -4
  12. package/lib/helper.js +2 -3
  13. package/lib/{hooks-BQCzgggH.js → hooks-rQTTeOC4.js} +69 -97
  14. package/lib/images.js +4 -4
  15. package/lib/index.js +194 -264
  16. package/lib/{library-zI-2tG7h.js → library-Dfu0dgRj.js} +9 -15
  17. package/lib/{lorebook-author-tools-ywaYicwd.js → lorebook-author-tools-BAaAqZZm.js} +10 -13
  18. package/lib/lorebook-authoring.js +5 -6
  19. package/lib/{narration-CnBlVure.js → narration-CjB_KwwY.js} +9 -15
  20. package/lib/orchestration.js +53 -64
  21. package/lib/{pack-jail-5EJ-WYyW.js → pack-jail-CN-314ln.js} +76 -81
  22. package/lib/{packs-Cv8hanXJ.js → packs-DIj5BEfq.js} +6 -10
  23. package/lib/{presenter-agent-BSaMSd3G.js → presenter-agent-DR0KvLE0.js} +12 -18
  24. package/lib/{preset-CWI3-0r1.js → preset-CscHj1-Y.js} +5 -6
  25. package/lib/{preset-author-tools-BrJYa2cr.js → preset-author-tools-CxluF8qc.js} +12 -14
  26. package/lib/preset-authoring.js +6 -7
  27. package/lib/{presets-MwOSMMyu.js → presets-HB8kJTaE.js} +51 -56
  28. package/lib/{reflection-zSaMsjKj.js → reflection-Dg1xtOTW.js} +19 -30
  29. package/lib/{text-BzudpQLS.js → text-DyRN4nDP.js} +6 -8
  30. package/lib/{turn-guard-Cv8pfHEA.js → turn-guard-g_hDn0jR.js} +6 -11
  31. package/package.json +29 -29
  32. package/prompts/en/import/casting.md +1 -1
  33. package/prompts/en/import/character.md +1 -0
  34. package/prompts/zh/import/casting.md +1 -1
  35. package/prompts/zh/import/character.md +1 -0
package/lib/compaction.js CHANGED
@@ -1,10 +1,10 @@
1
- import { o as roleplaySessionOf, t as promptFor } from "./access-DtOxFKBK.js";
2
- import { a as liveSettings, t as decodeOutput } from "./narration-CnBlVure.js";
3
- import { c as runChild, n as childModel, r as childSampling, y as tokensOf } from "./child-D6mpkkCE.js";
1
+ import { a as liveSettings, t as decodeOutput } from "./narration-CjB_KwwY.js";
2
+ import { o as roleplaySessionOf, t as promptFor } from "./access-CfQWbNZP.js";
3
+ import { c as runChild, n as childModel, r as childSampling, y as tokensOf } from "./child-lYYeOwl2.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";
7
- //#region src/host/compaction/chronicle.ts
7
+ // src/host/compaction/chronicle.ts
8
8
  const CJK = /\p{Script=Han}|\p{Script=Hiragana}|\p{Script=Katakana}|\p{Script=Hangul}/gu;
9
9
  /** A rough size of a text in tokens: scripts written without spaces are denser than the rest. */
10
10
  function estimateTokens(text) {
@@ -127,8 +127,7 @@ function composeSummary(story) {
127
127
  const digests = story.summaries.list("digest");
128
128
  return [chapters.length === 0 ? "" : `Story so far (long term):\n${chapters.map((summary) => `${span(summary)}: ${summary.text}`).join("\n\n")}`, digests.length === 0 ? "" : `Recently (short term):\n${digests.map((summary) => `${span(summary)}: ${summary.text}`).join("\n\n")}`].filter((part) => part !== "").join("\n\n");
129
129
  }
130
- //#endregion
131
- //#region src/host/compaction/chronicler.ts
130
+ // src/host/compaction/chronicler.ts
132
131
  const SUMMARY_SCHEMA = {
133
132
  type: "object",
134
133
  properties: { summary: {
@@ -157,8 +156,7 @@ function childChronicler(parent, settings) {
157
156
  })).summary;
158
157
  } };
159
158
  }
160
- //#endregion
161
- //#region src/host/compaction/range.ts
159
+ // src/host/compaction/range.ts
162
160
  /** The turn each event belongs to: the latest turn that had started by then. */
163
161
  function turnsOf(events) {
164
162
  const turns = /* @__PURE__ */ new Map();
@@ -200,8 +198,7 @@ function selectFoldRange(input) {
200
198
  }
201
199
  return null;
202
200
  }
203
- //#endregion
204
- //#region src/host/compaction/engine.ts
201
+ // src/host/compaction/engine.ts
205
202
  /** Folding more often than this size is pointless, whatever the window. */
206
203
  const MIN_LIMIT = 4e3;
207
204
  const textOf = (content) => content.flatMap((block) => block.type === "text" ? [block.text] : []).join("\n");
@@ -318,10 +315,8 @@ var RoleplayCompaction = class extends BasicCompactionEngine {
318
315
  };
319
316
  }
320
317
  };
321
- //#endregion
322
- //#region src/compaction.ts
318
+ // src/compaction.ts
323
319
  const name = "@dsh-agentic-roleplay/core/compaction";
324
- //#endregion
325
320
  export { RoleplayCompaction, RoleplayCompaction as default, name };
326
321
 
327
322
  //# sourceMappingURL=compaction.js.map
@@ -1,4 +1,4 @@
1
- //#region src/shared/doctor-chat.ts
1
+ // src/shared/doctor-chat.ts
2
2
  const PREFIX = "doctor-";
3
3
  const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
4
4
  /** Stable DSH chat identity for the session doctor of one roleplay session. */
@@ -11,7 +11,6 @@ function doctorSessionOf(chat) {
11
11
  const id = chat.slice(7);
12
12
  return UUID_V4.test(id) ? id : void 0;
13
13
  }
14
- //#endregion
15
14
  export { doctorSessionOf as n, doctorChatSessionId as t };
16
15
 
17
- //# sourceMappingURL=doctor-chat-ByDfCMeo.js.map
16
+ //# sourceMappingURL=doctor-chat-hL1a61hp.js.map
package/lib/doctor.js CHANGED
@@ -1,13 +1,13 @@
1
- import { a as chatSessionId } from "./access-DtOxFKBK.js";
2
- import { a as liveSettings } from "./narration-CnBlVure.js";
3
- import { i as externalTools, t as externalToolLimit } from "./hooks-BQCzgggH.js";
4
- import { n as doctorSessionOf } from "./doctor-chat-ByDfCMeo.js";
1
+ import { a as chatSessionId } from "./access-CfQWbNZP.js";
2
+ import { n as doctorSessionOf } from "./doctor-chat-hL1a61hp.js";
3
+ import { i as externalTools, t as externalToolLimit } from "./hooks-rQTTeOC4.js";
4
+ import { a as liveSettings } from "./narration-CjB_KwwY.js";
5
5
  import { join } from "node:path";
6
6
  import { existsSync } from "node:fs";
7
7
  import { SessionId } from "@deepseek-ai/dsh-session";
8
8
  import { defineTool } from "@deepseek-ai/dsh-tools";
9
9
  import { createTools, isSessionId, sessionDatabase, sessionFolder } from "@dsh-agentic-roleplay/state";
10
- //#region src/host/agent/doctor-undo.ts
10
+ // src/host/agent/doctor-undo.ts
11
11
  const UNDO_SNAPSHOT = "doctor-undo";
12
12
  const UNDO_KEY = "doctor.undo";
13
13
  var UndoRefusedError = class extends Error {};
@@ -34,8 +34,7 @@ async function undoLastEdit(deps, id) {
34
34
  deps.state.restore(dir, id, UNDO_SNAPSHOT);
35
35
  deps.state.removeSnapshot(dir, id, UNDO_SNAPSHOT);
36
36
  }
37
- //#endregion
38
- //#region src/doctor.ts
37
+ // src/doctor.ts
39
38
  const name = "@dsh-agentic-roleplay/core/doctor";
40
39
  const inject = [
41
40
  "roleplayState",
@@ -163,7 +162,6 @@ function undoTool(deps) {
163
162
  }
164
163
  });
165
164
  }
166
- //#endregion
167
165
  export { apply, doctorApproval, inject, name };
168
166
 
169
167
  //# sourceMappingURL=doctor.js.map
@@ -1,8 +1,8 @@
1
- import { _ as writeImageFileMetadata, a as LIBRARY_FOLDER, b as mapLimit, g as sidecarOf, h as readImageFileMetadata, m as mediaTypeOf } from "./library-zI-2tG7h.js";
1
+ import { _ as writeImageFileMetadata, a as LIBRARY_FOLDER, b as mapLimit, g as sidecarOf, h as readImageFileMetadata, m as mediaTypeOf } from "./library-Dfu0dgRj.js";
2
2
  import { join, sep } from "node:path";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { lstat, mkdir, readFile, readdir, realpath, rename, stat, writeFile } from "node:fs/promises";
5
- //#region src/host/images/gallery.ts
5
+ // src/host/images/gallery.ts
6
6
  const READ_AT_ONCE = 8;
7
7
  const SEGMENT = /^[\p{L}\p{N}][\p{L}\p{N}\p{M}._-]{0,199}$/u;
8
8
  const CACHE_FILE = ".index.json";
@@ -189,7 +189,6 @@ async function updateImage(sessionFolder, path, update) {
189
189
  await writeImageFileMetadata(file, next);
190
190
  return await describe(join(sessionFolder, "images"), path);
191
191
  }
192
- //#endregion
193
192
  export { updateImage as i, galleryFile as n, listGallery as r, describeGalleryImage as t };
194
193
 
195
- //# sourceMappingURL=gallery-D9nG3C78.js.map
194
+ //# sourceMappingURL=gallery-D1V4h8vh.js.map
@@ -1,5 +1,5 @@
1
- import { d as sceneImagePath, f as writeImage, u as referenceImagePath } from "./library-zI-2tG7h.js";
2
- //#region src/host/images/generator.ts
1
+ import { d as sceneImagePath, f as writeImage, u as referenceImagePath } from "./library-Dfu0dgRj.js";
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. */
5
5
  function referenceDescription(request) {
@@ -139,7 +139,6 @@ async function generateTransientImage(service, request) {
139
139
  await writeImage(path, image.data, metadata);
140
140
  return path;
141
141
  }
142
- //#endregion
143
142
  export { uploadReferenceImage as a, transientPrompt as i, generateTransientImage as n, referencePrompt as r, generateReferenceImage as t };
144
143
 
145
- //# sourceMappingURL=generator-r1Czm7oi.js.map
144
+ //# sourceMappingURL=generator-CLPosooC.js.map
package/lib/helper.js CHANGED
@@ -1,5 +1,5 @@
1
- import { o as helpers } from "./child-D6mpkkCE.js";
2
- //#region src/helper.ts
1
+ import { o as helpers } from "./child-lYYeOwl2.js";
2
+ // src/helper.ts
3
3
  const name = "@dsh-agentic-roleplay/core/helper";
4
4
  const inject = ["tools", "systemPrompt"];
5
5
  /**
@@ -20,7 +20,6 @@ function apply(ctx) {
20
20
  helpers.get(agent.session.id)?.setup(agent);
21
21
  });
22
22
  }
23
- //#endregion
24
23
  export { apply, inject, name };
25
24
 
26
25
  //# sourceMappingURL=helper.js.map
@@ -1,7 +1,7 @@
1
- import { o as roleplaySessionOf, t as promptFor } from "./access-DtOxFKBK.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-CnBlVure.js";
3
- import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-BzudpQLS.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-D6mpkkCE.js";
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
7
  import { readFile, stat } from "node:fs/promises";
@@ -10,7 +10,25 @@ import { defineTool } from "@deepseek-ai/dsh-tools";
10
10
  import { fileURLToPath } from "node:url";
11
11
  import { Service } from "@deepseek-ai/cordis";
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
- //#region ../dsh-roleplay-model/src/plot.ts
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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,7 @@ async function readDocument(file, parse, problems) {
395
408
  message: formatIssue(issue)
396
409
  });
397
410
  }
398
- //#endregion
399
- //#region src/shared/commands.ts
411
+ // src/shared/commands.ts
400
412
  const COMMANDS_KEY = "roleplay.commands";
401
413
  /** The name of the flag a command raises. */
402
414
  const commandFlagKey = (command) => `command_${command.key}`;
@@ -405,8 +417,7 @@ function commandsOf(value) {
405
417
  if (!Array.isArray(value)) return [];
406
418
  return value.filter((entry) => typeof entry === "object" && entry !== null && typeof entry.word === "string" && typeof entry.key === "string" && typeof entry.description === "string");
407
419
  }
408
- //#endregion
409
- //#region src/host/plots/load.ts
420
+ // src/host/plots/load.ts
410
421
  const PLOTS_FILE_NAME = "plots.json";
411
422
  function development(reader, fallback) {
412
423
  return {
@@ -515,8 +526,7 @@ function plotReferenceProblems(plots, entities) {
515
526
  const known = new Set(entities);
516
527
  return plots.flatMap((plot) => plot.participants.filter((participant) => !known.has(participant)).map((participant) => `plot "${plot.id}" names unknown participant "${participant}"`));
517
528
  }
518
- //#endregion
519
- //#region src/host/translate/language.ts
529
+ // src/host/translate/language.ts
520
530
  const STORY_LANGUAGES = ["en", "zh"];
521
531
  /** Less than this many letters of either script is too little to tell a language. */
522
532
  const MIN_LETTERS = 20;
@@ -562,8 +572,7 @@ function wrongLanguage(wanted, texts, options = {}) {
562
572
  });
563
573
  return wrong.length === 0 ? void 0 : `${wrong.join(" and ")}: write it in ${LANGUAGE_NAMES[wanted].en} (${LANGUAGE_NAMES[wanted][wanted]})`;
564
574
  }
565
- //#endregion
566
- //#region src/host/pacing/director.ts
575
+ // src/host/pacing/director.ts
567
576
  const PLOTS_METADATA_KEY = "roleplay.pacing.plots";
568
577
  function populatePlots(metadata, plots) {
569
578
  const progress = plots.map((plot) => ({
@@ -658,8 +667,7 @@ function updatePlotProgress(store, plotId, developmentId, action) {
658
667
  store.story.metadata.setValue(PLOTS_METADATA_KEY, plots);
659
668
  return progress;
660
669
  }
661
- //#endregion
662
- //#region src/host/orchestration/protocol.ts
670
+ // src/host/orchestration/protocol.ts
663
671
  const COMMITMENTS = [
664
672
  "low",
665
673
  "medium",
@@ -800,8 +808,7 @@ function parseCharacterAction(value) {
800
808
  ...told === "" ? {} : { account: told }
801
809
  };
802
810
  }
803
- //#endregion
804
- //#region src/host/clock/story-clock.ts
811
+ // src/host/clock/story-clock.ts
805
812
  var ClockError = class extends Error {};
806
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. */
807
814
  function describeWhen(instant, now, zone, language = "en") {
@@ -948,8 +955,7 @@ function skipTime(session, config, turn, round, wall, request) {
948
955
  };
949
956
  });
950
957
  }
951
- //#endregion
952
- //#region src/host/orchestration/observation.ts
958
+ // src/host/orchestration/observation.ts
953
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. */
954
960
  function observeSurroundings(session, characterId, turn) {
955
961
  const placement = session.placements.get("character", characterId);
@@ -977,16 +983,14 @@ function observeAsPlayer(session, turn) {
977
983
  const player = session.characters.list().find((character) => character.control === "player");
978
984
  if (player !== void 0) observeSurroundings(session, player.id, turn);
979
985
  }
980
- //#endregion
981
- //#region src/shared/notes.ts
986
+ // src/shared/notes.ts
982
987
  /** The kinds the host stores; `unwritten` is made when the notes are read, from the rounds still waiting for the record keeper. */
983
988
  const NOTE_KINDS = [
984
989
  "suggestions",
985
990
  "away",
986
991
  "world"
987
992
  ];
988
- //#endregion
989
- //#region src/host/sessions/notes.ts
993
+ // src/host/sessions/notes.ts
990
994
  const KEY$4 = "notes";
991
995
  const isNote = (value) => {
992
996
  if (typeof value !== "object" || value === null) return false;
@@ -1032,8 +1036,7 @@ function notesOfSession(deps, id) {
1032
1036
  count: waiting
1033
1037
  }];
1034
1038
  }
1035
- //#endregion
1036
- //#region src/host/triggers/deliver.ts
1039
+ // src/host/triggers/deliver.ts
1037
1040
  const KEY$3 = "triggers.withdrawn";
1038
1041
  /** Why a note was withdrawn instead of told, by the number of the note. */
1039
1042
  function readWithdrawn(session) {
@@ -1066,8 +1069,7 @@ function deliverNow(session, notes, clock) {
1066
1069
  text
1067
1070
  }));
1068
1071
  }
1069
- //#endregion
1070
- //#region src/host/triggers/judged.ts
1072
+ // src/host/triggers/judged.ts
1071
1073
  const KEY$2 = "triggers.judged";
1072
1074
  function readVerdicts(session) {
1073
1075
  const stored = session.metadata.getValue(KEY$2);
@@ -1091,8 +1093,7 @@ const verdictReader = (session) => {
1091
1093
  const verdicts = readVerdicts(session);
1092
1094
  return (statement) => verdicts[statement]?.holds === true;
1093
1095
  };
1094
- //#endregion
1095
- //#region src/host/triggers/notes.ts
1096
+ // src/host/triggers/notes.ts
1096
1097
  /** The beat effect of a note's trigger that has the world author make something instead of telling the game master. */
1097
1098
  function authorEffect(session, note) {
1098
1099
  if (note.kind !== "beat") return void 0;
@@ -1218,8 +1219,7 @@ function noteStore(session, settings, clock) {
1218
1219
  }
1219
1220
  };
1220
1221
  }
1221
- //#endregion
1222
- //#region src/host/sessions/activity.ts
1222
+ // src/host/sessions/activity.ts
1223
1223
  const KEY$1 = "activity";
1224
1224
  const isEntry = (value) => {
1225
1225
  if (typeof value !== "object" || value === null) return false;
@@ -1262,8 +1262,7 @@ function readRunDetail(folder, run) {
1262
1262
  function forgetRunDetails(folder, dropped) {
1263
1263
  for (const entry of dropped) if (entry.run !== void 0) rmSync(runFile(folder, entry.run), { force: true });
1264
1264
  }
1265
- //#endregion
1266
- //#region src/host/decisions/stats.ts
1265
+ // src/host/decisions/stats.ts
1267
1266
  const DECISIONS_FILE = "decisions.json";
1268
1267
  const isSite = (value) => typeof value === "object" && value !== null && [
1269
1268
  "runs",
@@ -1317,8 +1316,7 @@ function recordDecisions(folder, site, report, now = () => /* @__PURE__ */ new D
1317
1316
  writeFileSync(aside, JSON.stringify(stats, null, 2));
1318
1317
  renameSync(aside, target);
1319
1318
  }
1320
- //#endregion
1321
- //#region src/host/sessions/usage.ts
1319
+ // src/host/sessions/usage.ts
1322
1320
  const KEY = "usage";
1323
1321
  const isCount = (value) => typeof value === "object" && value !== null && [
1324
1322
  "input",
@@ -1354,8 +1352,7 @@ function addUsage(session, turn, who, tokens) {
1354
1352
  all.sort((a, b) => a.turn - b.turn);
1355
1353
  session.metadata.setValue(KEY, all);
1356
1354
  }
1357
- //#endregion
1358
- //#region src/host/clock/agenda.ts
1355
+ // src/host/clock/agenda.ts
1359
1356
  const CURSOR = "agenda.cursor";
1360
1357
  const ASKED = "agenda.asked";
1361
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. */
@@ -1543,8 +1540,7 @@ function sceneAgenda(session, zone, now, moved) {
1543
1540
  engagements
1544
1541
  };
1545
1542
  }
1546
- //#endregion
1547
- //#region src/host/clock/passage.ts
1543
+ // src/host/clock/passage.ts
1548
1544
  /** The start of a turn: the time, how long the player was away, and what the days of the characters make of it. */
1549
1545
  function startTurn(session, config, turn, wall) {
1550
1546
  const started = beginTurn(session, config, turn, wall);
@@ -1575,8 +1571,7 @@ function agendaFor(session, config, turn, wall, characterId) {
1575
1571
  const time = readTime(session, config, turn, wall());
1576
1572
  return agendaView(session, characterId, zoneOf(config), time.now);
1577
1573
  }
1578
- //#endregion
1579
- //#region src/host/clock/offscene.ts
1574
+ // src/host/clock/offscene.ts
1580
1575
  const HANDLED = "offscene.handled";
1581
1576
  const keyOf = (character) => character.sourceId ?? String(character.id);
1582
1577
  function handledKeys(session) {
@@ -1658,8 +1653,7 @@ function dueOffScene(session, zone, now, language = "en") {
1658
1653
  }
1659
1654
  return items.sort((a, b) => a.at - b.at);
1660
1655
  }
1661
- //#endregion
1662
- //#region src/host/variables/describe.ts
1656
+ // src/host/variables/describe.ts
1663
1657
  /** What is tracked of a subject, in a line: `Health: hurt (2); Valence: unhappy (-0.4), usually even (0)`. */
1664
1658
  function describeShown(shown) {
1665
1659
  return shown.map(({ variable, value, baseline }) => {
@@ -1667,8 +1661,7 @@ function describeShown(shown) {
1667
1661
  return `${variable.name}: ${describeValue(variable, value)}${usual}`;
1668
1662
  }).join("; ");
1669
1663
  }
1670
- //#endregion
1671
- //#region src/host/orchestration/skeleton.ts
1664
+ // src/host/orchestration/skeleton.ts
1672
1665
  const PLAIN_IMPORTANCE = 2;
1673
1666
  const CONSEQUENTIAL_IMPORTANCE = 3;
1674
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. */
@@ -1725,8 +1718,7 @@ function skeletonEvents(round) {
1725
1718
  return events;
1726
1719
  });
1727
1720
  }
1728
- //#endregion
1729
- //#region src/host/orchestration/store.ts
1721
+ // src/host/orchestration/store.ts
1730
1722
  /** The rules the session copied from its world when it started. */
1731
1723
  function worldRules(session) {
1732
1724
  const value = session.metadata.getValue(WORLD_RULES_KEY);
@@ -2117,8 +2109,7 @@ function storesOf(state, sessionsDir, problem = () => void 0, queryVector = () =
2117
2109
  }
2118
2110
  };
2119
2111
  }
2120
- //#endregion
2121
- //#region src/shared/ooc.ts
2112
+ // src/shared/ooc.ts
2122
2113
  /** The command or question in a player's message, or nothing when the message is an ordinary action. The request may be empty. */
2123
2114
  function parseOoc(text) {
2124
2115
  const value = text.trimStart();
@@ -2132,8 +2123,7 @@ function parseOoc(text) {
2132
2123
  }
2133
2124
  /** The longest answer to an out-of-character question. */
2134
2125
  const MAX_OOC_ANSWER = 1200;
2135
- //#endregion
2136
- //#region src/shared/roll.ts
2126
+ // src/shared/roll.ts
2137
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. */
2138
2128
  function parseRoll(text) {
2139
2129
  const value = text.trimStart();
@@ -2148,10 +2138,7 @@ function parseRoll(text) {
2148
2138
  reason: body.slice(boundary).trim()
2149
2139
  };
2150
2140
  }
2151
- //#endregion
2152
- //#region src/host/agents/repeat-guard.ts
2153
- /** Refused repeats after which the turn is ended instead of being refused again. */
2154
- const REFUSALS_BEFORE_STOP = 5;
2141
+ // src/host/agents/repeat-guard.ts
2155
2142
  /**
2156
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
2157
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.
@@ -2173,15 +2160,14 @@ function guardRepeatedCalls(ctx, languageOf, limit) {
2173
2160
  const count = (seen.get(signature) ?? 0) + 1;
2174
2161
  seen.set(signature, count);
2175
2162
  if (count <= limit) return await next();
2176
- if (count > limit + REFUSALS_BEFORE_STOP) exec.agent?.cancel({ kind: "user" }, { keepInbox: true });
2163
+ if (count > limit + 5) exec.agent?.cancel({ kind: "user" }, { keepInbox: true });
2177
2164
  return {
2178
2165
  kind: "deny",
2179
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 })
2180
2167
  };
2181
2168
  }, { prepend: true });
2182
2169
  }
2183
- //#endregion
2184
- //#region src/shared/tools.ts
2170
+ // src/shared/tools.ts
2185
2171
  /** What this version can offer. A name in a settings file or a world that is not here is kept and ignored. */
2186
2172
  const OPTIONAL_TOOLS = [
2187
2173
  {
@@ -2253,8 +2239,7 @@ function toolEnabled(board, agent, id) {
2253
2239
  function externalEnabled(board, agent, name) {
2254
2240
  return board[agent]?.[name] === true;
2255
2241
  }
2256
- //#endregion
2257
- //#region src/host/orchestration/character-runner.ts
2242
+ // src/host/orchestration/character-runner.ts
2258
2243
  /**
2259
2244
  * Runs each character as a one-shot child of the game master. It is the character and nothing
2260
2245
  * else: it knows what its brief gives it, and its only tool (when the chat allows it) reaches
@@ -2392,19 +2377,7 @@ function answerRunner(deps) {
2392
2377
  })).answer;
2393
2378
  };
2394
2379
  }
2395
- //#endregion
2396
- //#region src/host/orchestration/boundaries.ts
2397
- /** Why the game master may ask for something to be made up: the story genuinely needs it. */
2398
- const AUTHORING_NEEDS = [
2399
- "scene_change",
2400
- "arrival",
2401
- "introduction",
2402
- "object",
2403
- "variable",
2404
- "trigger"
2405
- ];
2406
- //#endregion
2407
- //#region src/host/pacing/author.ts
2380
+ // src/host/pacing/author.ts
2408
2381
  const RESULT = {
2409
2382
  type: "object",
2410
2383
  required: [
@@ -2544,8 +2517,7 @@ async function authorPlot(parent, store, turn, signal) {
2544
2517
  addSessionPlot(store, checked);
2545
2518
  return checked;
2546
2519
  }
2547
- //#endregion
2548
- //#region src/host/orchestration/tools.ts
2520
+ // src/host/orchestration/tools.ts
2549
2521
  const ACTIVATE_TOOL = "activate_characters";
2550
2522
  const RESOLVE_TOOL = "resolve_round";
2551
2523
  const NARRATE_TOOL = "narrate";
@@ -3329,8 +3301,7 @@ function createTools$1(deps) {
3329
3301
  narrate
3330
3302
  ];
3331
3303
  }
3332
- //#endregion
3333
- //#region src/host/tools/external.ts
3304
+ // src/host/tools/external.ts
3334
3305
  /** The reserved transport DSH presents tools through; it is never a tool of its own to switch. */
3335
3306
  const RESERVED = /* @__PURE__ */ new Set(["run_code"]);
3336
3307
  let own;
@@ -3362,8 +3333,7 @@ function externalGiven(registry, board, agent) {
3362
3333
  function externalWithheld(registry, board, agent) {
3363
3334
  return externalTools(registry).map((tool) => tool.name).filter((name) => !externalEnabled(board, agent, name));
3364
3335
  }
3365
- //#endregion
3366
- //#region src/host/orchestration/hooks.ts
3336
+ // src/host/orchestration/hooks.ts
3367
3337
  const notice = (text) => createUserMessage({
3368
3338
  content: [{
3369
3339
  type: "text",
@@ -3443,8 +3413,11 @@ function externalToolLimit(agent, withheld) {
3443
3413
  * that uses the preset and also hear the agents that chat spawns, so each one
3444
3414
  * first checks that it is looking at the game master of a roleplay chat.
3445
3415
  */
3446
- /** Identical calls the game master may make in one turn: a refused resolution is mended and sent again, so a few repeats are work, many are a loop. */
3447
- const MASTER_SAME_CALL = 4;
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
+ }
3448
3421
  function installHooks(ctx, deps) {
3449
3422
  const { engine, boundaries, stores, timelines, previewTool } = deps;
3450
3423
  const showPreviewTool = previewToggle(previewTool);
@@ -3458,7 +3431,7 @@ function installHooks(ctx, deps) {
3458
3431
  guardRepeatedCalls(ctx, (exec) => {
3459
3432
  const owner = exec.agent === void 0 ? void 0 : ownerOf(exec.agent, 0);
3460
3433
  return owner === void 0 ? void 0 : stores(owner.chat)?.settings().prompts.language;
3461
- }, MASTER_SAME_CALL);
3434
+ }, 4);
3462
3435
  ctx.on("agent/created", ({ agent }) => {
3463
3436
  const owner = ownerOf(agent, 0);
3464
3437
  const store = owner === void 0 ? void 0 : stores(owner.chat);
@@ -3557,10 +3530,10 @@ function installHooks(ctx, deps) {
3557
3530
  ...queryVector === void 0 ? {} : { queryVector }
3558
3531
  })];
3559
3532
  const pacing = ooc === void 0 ? pacingAdvice(store, payload.turn) : void 0;
3560
- if (used !== void 0) lines.push(tr("The player used the world's command /{word}: {description}", {
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.", {
3561
3534
  word: used.word,
3562
3535
  description: used.description
3563
- }));
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(" "));
3564
3537
  if (pacing !== void 0) lines.push(describePacingAdvice(pacing));
3565
3538
  else if (ooc === void 0 && plotAuthorNeeded(store, payload.turn)) lines.push(store.text("roleplay/plot-hint"));
3566
3539
  const rules = store.rules();
@@ -3604,7 +3577,6 @@ function installHooks(ctx, deps) {
3604
3577
  };
3605
3578
  });
3606
3579
  }
3607
- //#endregion
3608
- export { copyWorldPrompts as $, RESULTS as A, PLOTS_FILE_NAME as B, notesOfSession as C, describeTime as D, ClockError as E, LANGUAGE_NAMES as F, commandFlagKey as G, parsePlotsFile as H, STORY_LANGUAGES as I, formatIssue as J, readDocument as K, isStoryLanguage as L, PLOTS_METADATA_KEY as M, plotProgressOf as N, describeWhen as O, populatePlots as P, PromptLibrary as Q, textLanguage as R, addToNote as S, observeAsPlayer as T, plotReferenceProblems as U, loadPlots as V, COMMANDS_KEY as W, LANGUAGE_FOLDER as X, errorMessage as Y, PROMPTS_FOLDER as Z, readActivity as _, externalWithheld as a, shippedPromptsDirectory as at, writeVerdicts as b, record as c, InvalidStartError as ct, toolEnabled as d, SessionArchivedError as dt, inheritPrompts as et, guardRepeatedCalls as f, SessionNotFoundError as ft, readDecisionStats as g, readUsage as h, externalTools as i, shippedLanguages as it, answerLimits as j, zoneOf as k, AUTHORING_NEEDS as l, InvalidWorldError as lt, storesOf as m, installHooks as n, listFiles as nt, PREVIEW_TOOL as o, shippedText as ot, MAX_OOC_ANSWER 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, characterRunner as u, ReflectionRefusedError as ut, readRunDetail as v, readNotes as w, readWithdrawn as x, readVerdicts as y, wrongLanguage 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 };
3609
3581
 
3610
- //# sourceMappingURL=hooks-BQCzgggH.js.map
3582
+ //# sourceMappingURL=hooks-rQTTeOC4.js.map
package/lib/images.js CHANGED
@@ -1,5 +1,5 @@
1
- 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-zI-2tG7h.js";
2
- import { i as transientPrompt, n as generateTransientImage, r as referencePrompt, t as generateReferenceImage } from "./generator-r1Czm7oi.js";
3
- import { i as updateImage, r as listGallery } from "./gallery-D9nG3C78.js";
4
- 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-BSaMSd3G.js";
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 };