@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.
Files changed (58) hide show
  1. package/README.md +1 -1
  2. package/lib/{access-DtOxFKBK.js → access-CfQWbNZP.js} +4 -7
  3. package/lib/authoring-tools-BgmC2oqU.js +3691 -0
  4. package/lib/authoring.js +59 -24
  5. package/lib/{child-CyCViUKa.js → child-lYYeOwl2.js} +147 -46
  6. package/lib/client.js +931 -860
  7. package/lib/client.js.map +1 -1
  8. package/lib/compaction.js +8 -13
  9. package/lib/{doctor-chat-ByDfCMeo.js → doctor-chat-hL1a61hp.js} +2 -3
  10. package/lib/doctor.js +6 -8
  11. package/lib/{gallery-DmBZ2L5l.js → gallery-D1V4h8vh.js} +3 -4
  12. package/lib/{generator-BmdoTIL2.js → generator-CLPosooC.js} +3 -4
  13. package/lib/helper.js +2 -3
  14. package/lib/{hooks-C8eELrni.js → hooks-rQTTeOC4.js} +144 -88
  15. package/lib/images.js +4 -4
  16. package/lib/index.js +1024 -913
  17. package/lib/{library-lVNf9qG_.js → library-Dfu0dgRj.js} +32 -21
  18. package/lib/{lorebook-author-tools-BDOs4i5C.js → lorebook-author-tools-BAaAqZZm.js} +11 -14
  19. package/lib/lorebook-authoring.js +5 -6
  20. package/lib/{narration-DvFBqmqe.js → narration-CjB_KwwY.js} +58 -20
  21. package/lib/orchestration.js +138 -72
  22. package/lib/{pack-jail-DeTscGT2.js → pack-jail-CN-314ln.js} +94 -137
  23. package/lib/{packs-CY8ms8v_.js → packs-DIj5BEfq.js} +6 -10
  24. package/lib/{presenter-agent-cFR4sos3.js → presenter-agent-DR0KvLE0.js} +13 -19
  25. package/lib/{preset-n4-j6k4S.js → preset-CscHj1-Y.js} +5 -5
  26. package/lib/{preset-author-tools-2m4BLtws.js → preset-author-tools-CxluF8qc.js} +13 -15
  27. package/lib/preset-authoring.js +6 -7
  28. package/lib/presets-HB8kJTaE.js +3993 -0
  29. package/lib/{reflection-CJB5s0ip.js → reflection-Dg1xtOTW.js} +137 -148
  30. package/lib/{text-Cwl5s0j0.js → text-DyRN4nDP.js} +13 -7
  31. package/lib/{turn-guard-BvCs1VxB.js → turn-guard-g_hDn0jR.js} +6 -7
  32. package/package.json +29 -29
  33. package/prompts/en/import/casting.md +14 -0
  34. package/prompts/en/import/character.md +1 -0
  35. package/prompts/en/import/classifier.md +9 -0
  36. package/prompts/en/import/finish-draft.md +1 -0
  37. package/prompts/en/import/generator.md +8 -0
  38. package/prompts/en/import/notice-repair.md +4 -0
  39. package/prompts/en/import/repair-again.md +3 -0
  40. package/prompts/en/import/roster.md +1 -0
  41. package/prompts/en/import/variables.md +1 -0
  42. package/prompts/en/roleplay/game-master.md +3 -0
  43. package/prompts/en/roleplay/standing.md +1 -0
  44. package/prompts/en/world/author.md +1 -1
  45. package/prompts/zh/import/casting.md +14 -0
  46. package/prompts/zh/import/character.md +1 -0
  47. package/prompts/zh/import/classifier.md +9 -0
  48. package/prompts/zh/import/finish-draft.md +1 -0
  49. package/prompts/zh/import/generator.md +8 -0
  50. package/prompts/zh/import/notice-repair.md +4 -0
  51. package/prompts/zh/import/repair-again.md +3 -0
  52. package/prompts/zh/import/roster.md +1 -0
  53. package/prompts/zh/import/variables.md +1 -0
  54. package/prompts/zh/roleplay/game-master.md +3 -0
  55. package/prompts/zh/roleplay/standing.md +1 -0
  56. package/prompts/zh/world/author.md +1 -1
  57. package/lib/authoring-tools-CIsWbq0B.js +0 -6317
  58. package/lib/route-C6SHz9j2.js +0 -518
@@ -1,21 +1,21 @@
1
- import { a as chatSessionId, o as roleplaySessionOf, t as promptFor } from "./access-DtOxFKBK.js";
2
- import { E as INTENT_STATUSES, a as routeVerdicts, i as noAt, n as askYesNo, o as yesAt, t as announceProblem } from "./route-C6SHz9j2.js";
3
- import { _ as referent, a as whereabouts, g as sameWords, n as memoryReflector, r as recordFailure, s as Timelines, t as dueReflection } from "./reflection-CJB5s0ip.js";
4
- import { a as liveSettings, g as GATE_SITES, n as encodeOutput } from "./narration-DvFBqmqe.js";
5
- import { D as describeWhen, O as zoneOf, R as wrongLanguage, T as ClockError, c as record, d as toolEnabled, f as MAX_OOC_ANSWER, k as RESULTS, l as AUTHORING_NEEDS, n as installHooks, o as PREVIEW_TOOL, ot as ReflectionRefusedError, p as storesOf, r as externalGiven, s as createTools$1, u as characterRunner, v as readVerdicts, y as writeVerdicts } from "./hooks-C8eELrni.js";
6
- import { i as translator, r as languageOf } from "./text-Cwl5s0j0.js";
7
- import { a as childTrace, c as runChild, h as currentTurn, n as childModel, r as childSampling, v as estimateAnswer, y as tokensOf } from "./child-CyCViUKa.js";
8
- import { S as slug, t as addToLibrary, w as uniqueKey } from "./library-lVNf9qG_.js";
9
- import { _ as API_PREFIX } from "./packs-CY8ms8v_.js";
10
- import { i as updateImage, r as listGallery, t as describeGalleryImage } from "./gallery-DmBZ2L5l.js";
11
- import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-cFR4sos3.js";
1
+ import { a as chatSessionId, o as roleplaySessionOf, t as promptFor } from "./access-CfQWbNZP.js";
2
+ import { D as describeWhen, G as commandsOf, O as zoneOf, R as wrongLanguage, T as ClockError, U as COMMANDS_KEY, W as commandFlagKey, c as record, f as MAX_OOC_ANSWER, k as RESULTS, l as characterRunner, mt as AUTHORING_NEEDS, n as installHooks, o as PREVIEW_TOOL, ot as shippedText, p as storesOf, r as externalGiven, s as createTools$1, u as toolEnabled, ut as ReflectionRefusedError, v as readVerdicts, y as writeVerdicts } from "./hooks-rQTTeOC4.js";
3
+ import { a as childTrace, c as runChild, h as currentTurn, n as childModel, r as childSampling, v as estimateAnswer, y as tokensOf } from "./child-lYYeOwl2.js";
4
+ import { _ as referent, a as whereabouts, g as sameWords, n as memoryReflector, r as recordFailure, s as Timelines, t as dueReflection } from "./reflection-Dg1xtOTW.js";
5
+ import { B as noAt, H as yesAt, I as announceProblem, L as askYesNo, Lt as INTENT_STATUSES, V as routeVerdicts, m as STANDING_PROMPT, z as modeFor } from "./presets-HB8kJTaE.js";
6
+ import { i as translator, r as languageOf } from "./text-DyRN4nDP.js";
7
+ import { a as liveSettings, n as encodeOutput, v as GATE_SITES } from "./narration-CjB_KwwY.js";
8
+ import { S as slug, t as addToLibrary, w as uniqueKey } from "./library-Dfu0dgRj.js";
9
+ import { _ as API_PREFIX } from "./packs-DIj5BEfq.js";
10
+ import { i as updateImage, r as listGallery, t as describeGalleryImage } from "./gallery-D1V4h8vh.js";
11
+ import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-DR0KvLE0.js";
12
12
  import { join } from "node:path";
13
13
  import { existsSync } from "node:fs";
14
+ import { readdir } from "node:fs/promises";
14
15
  import { SessionId } from "@deepseek-ai/dsh-session";
15
16
  import { defineTool } from "@deepseek-ai/dsh-tools";
16
- import { readdir } from "node:fs/promises";
17
17
  import { InvalidEditError, characterKey, createDiceTools, createTools, dayPart, describeDuration, describeHolder, describeInstant, describeValue, itemKey, judgedStatements, lintWorld, localTime, locationKey, mentioned, parseRecordsEdit, rollForCheck, sessionDatabase, sessionFolder } from "@dsh-agentic-roleplay/state";
18
- //#region src/host/tools/resource-hint.ts
18
+ // src/host/tools/resource-hint.ts
19
19
  /** The name DSH's MCP resource plugin gives the prompt paragraph it adds for every agent; a section of the same name in an agent's scope replaces it. */
20
20
  const RESOURCE_HINT_SECTION = "mcp-resource-servers";
21
21
  const RESOURCE_TOOLS = [
@@ -42,8 +42,7 @@ function resourceHint(visible, registered, tr) {
42
42
  servers: JSON.stringify(servers)
43
43
  });
44
44
  }
45
- //#endregion
46
- //#region src/host/memory/tags.ts
45
+ // src/host/memory/tags.ts
47
46
  const MIN_FUZZY_LENGTH = 5;
48
47
  const plain = (tag) => tag.normalize("NFKC").trim().toLowerCase().replace(/[\s_]+/g, "-");
49
48
  /** What two spellings of one word share: separators and a plural ending do not make a different tag. */
@@ -81,8 +80,7 @@ function canonicalTags(known, tags) {
81
80
  });
82
81
  return [...new Set(canonical)];
83
82
  }
84
- //#endregion
85
- //#region src/host/orchestration/committer.ts
83
+ // src/host/orchestration/committer.ts
86
84
  /** How many of the tags in use a brief lists. */
87
85
  const TAGS_LISTED = 60;
88
86
  /** What the keeper reads back by default: the parts of the records its edits write. */
@@ -329,8 +327,7 @@ function suggestionProblems(lines, wanted) {
329
327
  }
330
328
  /** One short line each: whitespace is collapsed. */
331
329
  const tidySuggestions = (lines) => lines.map((line) => line.trim().replace(/\s+/g, " "));
332
- //#endregion
333
- //#region src/host/orchestration/suggester.ts
330
+ // src/host/orchestration/suggester.ts
334
331
  const RESULT$3 = {
335
332
  type: "object",
336
333
  properties: { options: {
@@ -379,8 +376,7 @@ function suggestionWriter(deps) {
379
376
  })).options;
380
377
  } };
381
378
  }
382
- //#endregion
383
- //#region src/host/triggers/judge.ts
379
+ // src/host/triggers/judge.ts
384
380
  const RESULT$2 = {
385
381
  type: "object",
386
382
  properties: { verdicts: {
@@ -490,7 +486,7 @@ function triggerJudge(deps) {
490
486
  return new Map(keys.map((key) => [key, asked.get(`s${key}`)]));
491
487
  };
492
488
  const routed = await routeVerdicts({
493
- mode: settings.decisions.triggers,
489
+ mode: modeFor(settings.decisions.triggers, deps.decisions?.()),
494
490
  yesAt: yesAt(settings.decisions.confidence),
495
491
  noAt: noAt(settings.decisions.confidence),
496
492
  turn: job.turn,
@@ -589,8 +585,7 @@ function ruleChecks(deps) {
589
585
  return found.map((key) => rules[Number(key.slice(4))]);
590
586
  } };
591
587
  }
592
- //#endregion
593
- //#region src/host/decisions/gates.ts
588
+ // src/host/decisions/gates.ts
594
589
  /**
595
590
  * How far below the threshold a probability may fall and still be not sure. A decision model gives a rare fault a low probability even when it
596
591
  * sees it (measured: faults between 0.3 and 0.9, clean passages below 0.4), so a gate's cut is its own threshold, not the chat's confidence.
@@ -714,8 +709,7 @@ async function secretFindings(job, decisions, service, seen, signal, say) {
714
709
  message: `the output may give away what ${job.player === "" ? "the player's character" : job.player} does not know yet (${titles.join("; ")}): show only what can be seen or heard, and let the rest be learned in the story; if this is meant to be revealed now, deliver it again unchanged`
715
710
  }];
716
711
  }
717
- //#endregion
718
- //#region src/host/factions/strategist.ts
712
+ // src/host/factions/strategist.ts
719
713
  const LAST_KEY = "strategy.last";
720
714
  const DAY_MS = 864e5;
721
715
  /** Rounds numbered from here belong to what organisations did, as off-stage rounds have their own range. */
@@ -921,8 +915,7 @@ function factionStrategist(deps) {
921
915
  return { acted };
922
916
  } };
923
917
  }
924
- //#endregion
925
- //#region src/host/authoring/author-agent.ts
918
+ // src/host/authoring/author-agent.ts
926
919
  /** How many calls of the tools of other plugins the author may make on top of its own budget. */
927
920
  const EXTERNAL_CALLS = 10;
928
921
  /** A made-up thing in one edit: its name, description and the handful of fields a character, place or item carries. */
@@ -932,6 +925,30 @@ const THING_TEXT_CHARS = 300;
932
925
  const FIT_TEXTS = 6;
933
926
  const FIT_TEXT_CHARS = 200;
934
927
  const editEstimate = (things, texts, chars, language) => estimateAnswer(Array.from({ length: Math.max(1, things) * texts }, () => chars), language);
928
+ /** The keys of the people, places and things an edit makes that this run made already: made once, they are connected, not made again. */
929
+ function madeAgain(args, work) {
930
+ const made = new Set(work.created.map((entry) => entry.key));
931
+ const keys = [
932
+ "characters",
933
+ "places",
934
+ "items"
935
+ ].flatMap((field) => (Array.isArray(args[field]) ? args[field] : []).flatMap((entry) => typeof entry === "object" && entry !== null && typeof entry.key === "string" ? [entry.key] : []));
936
+ return [...new Set(keys.filter((key) => made.has(key)))];
937
+ }
938
+ /** A person made up without a place joins the scene: the place of the player's character, which is where the author is told to put them. */
939
+ function placedWhereThePlayerIs(args, store) {
940
+ if (!Array.isArray(args["characters"])) return args;
941
+ const here = store.cast().find((member) => member.character.control === "player")?.place?.location;
942
+ if (here === void 0) return args;
943
+ const characters = args["characters"].map((entry) => typeof entry === "object" && entry !== null && entry["place"] === void 0 ? {
944
+ ...entry,
945
+ place: { location: locationKey(here) }
946
+ } : entry);
947
+ return {
948
+ ...args,
949
+ characters
950
+ };
951
+ }
935
952
  function authorTools(job, work, mode, limits) {
936
953
  const link = {
937
954
  session: job.store.story,
@@ -971,9 +988,28 @@ function authorTools(job, work, mode, limits) {
971
988
  const edit = parseRecordsEdit(args);
972
989
  const makes = (edit.characters?.length ?? 0) + (edit.places?.length ?? 0) + (edit.items?.length ?? 0) + (edit.variables?.length ?? 0) + (edit.triggers?.length ?? 0);
973
990
  if (mode === "consolidate" && makes > 0) throw new Error("fitting things in does not make up anything new: connect what exists");
974
- const already = job.store.story.consolidation.createdIn(job.turn).length;
975
- if (makes > 0 && already + makes > limits.perTurn) throw new Error(`this edit makes ${makes} new thing${makes === 1 ? "" : "s"} and ${already} ${already === 1 ? "was" : "were"} already made this turn, which would pass the ${limits.perTurn} this chat allows per turn: make fewer, or none`);
976
- const result = await tool.execute(args, exec);
991
+ const madeBefore = job.store.story.consolidation.createdIn(job.turn);
992
+ const allowed = [
993
+ [
994
+ "character",
995
+ edit.characters?.length ?? 0,
996
+ madeBefore.filter((entry) => entry.kind === "character").length
997
+ ],
998
+ [
999
+ "place",
1000
+ edit.places?.length ?? 0,
1001
+ madeBefore.filter((entry) => entry.kind === "location").length
1002
+ ],
1003
+ [
1004
+ "other thing",
1005
+ (edit.items?.length ?? 0) + (edit.variables?.length ?? 0) + (edit.triggers?.length ?? 0),
1006
+ 0
1007
+ ]
1008
+ ];
1009
+ for (const [noun, now, already] of allowed) if (now > 0 && already + now > limits.perTurn) throw new Error(`this edit makes ${now} new ${noun}${now === 1 ? "" : "s"} and ${already} ${already === 1 ? "was" : "were"} already made this turn, which would pass the ${limits.perTurn} this chat allows per turn for each kind: make fewer, or none`);
1010
+ const again = madeAgain(args, work);
1011
+ if (again.length > 0) throw new Error(`${again.join(", ")} ${again.length === 1 ? "is" : "are"} already made in this run: do not make ${again.length === 1 ? "it" : "them"} again. A later edit_world call leaves ${again.length === 1 ? "it" : "them"} out and only adds what is still missing (relationships, ways, moves); when nothing is missing, call submit_result with outcome created.`);
1012
+ const result = await tool.execute(placedWhereThePlayerIs(args, job.store), exec);
977
1013
  for (const key of result.character_keys ?? []) work.created.push({
978
1014
  kind: "character",
979
1015
  key
@@ -1049,7 +1085,7 @@ function createPrompt(job, perTurn) {
1049
1085
  `The game master asks for something to be made up. Reason given: ${job.need}.`,
1050
1086
  `What it says is needed: ${job.what}`,
1051
1087
  "",
1052
- `It is turn ${job.turn}. At most ${perTurn} new thing${perTurn === 1 ? "" : "s"} may be made in a turn, and ${store.story.consolidation.createdIn(job.turn).length} already ${store.story.consolidation.createdIn(job.turn).length === 1 ? "was" : "were"} this turn.`,
1088
+ `It is turn ${job.turn}. At most ${perTurn} new character${perTurn === 1 ? "" : "s"} and ${perTurn} new place${perTurn === 1 ? "" : "s"} may be made in a turn (each kind has its own allowance); already made this turn: ${store.story.consolidation.createdIn(job.turn).filter((entry) => entry.kind === "character").length} character(s), ${store.story.consolidation.createdIn(job.turn).filter((entry) => entry.kind === "location").length} place(s).`,
1053
1089
  here === void 0 ? "The story is not in any place yet." : `The story is in ${here.name} (${locationKey(here)}). With the player's character: ${present.filter((member) => member.character.control !== "player").map((member) => `${member.character.name} (${member.key})`).join(", ") || "no one else"}.`,
1054
1090
  "",
1055
1091
  "## What happened lately",
@@ -1194,6 +1230,12 @@ function worldAuthor(deps) {
1194
1230
  return errors.length === 0 ? void 0 : `what you made is not usable yet; fix it with edit_world:\n${describeFindings(errors).join("\n")}`;
1195
1231
  },
1196
1232
  maxCalls: 30 + (given(parent).length > 0 ? EXTERNAL_CALLS : 0)
1233
+ }).catch((error) => {
1234
+ if (work.created.length === 0 || signal.aborted) throw error;
1235
+ return {
1236
+ outcome: "created",
1237
+ summary: `the author made it but did not finish its report (${error instanceof Error ? error.message : String(error)})`
1238
+ };
1197
1239
  });
1198
1240
  const label = names(job.store);
1199
1241
  const created = work.created.map((entry) => ({
@@ -1247,12 +1289,10 @@ function worldAuthor(deps) {
1247
1289
  }
1248
1290
  };
1249
1291
  }
1250
- //#endregion
1251
- //#region src/host/orchestration/prompt.ts
1292
+ // src/host/orchestration/prompt.ts
1252
1293
  const PROTOCOL_SECTION = "roleplay:protocol";
1253
1294
  const PERSONA_SECTION = "roleplay:persona";
1254
- //#endregion
1255
- //#region src/host/dice/describe.ts
1295
+ // src/host/dice/describe.ts
1256
1296
  const sentenceBody = (value) => {
1257
1297
  let end = value.length;
1258
1298
  while (end > 0 && (value[end - 1] === "." || /\s/u.test(value[end - 1]))) end -= 1;
@@ -1276,8 +1316,7 @@ function describeChecks(checks, tr) {
1276
1316
  });
1277
1317
  return [tr("The checks of this story:"), ...lines].join("\n");
1278
1318
  }
1279
- //#endregion
1280
- //#region src/host/orchestration/check-tool.ts
1319
+ // src/host/orchestration/check-tool.ts
1281
1320
  const CHECK_NARRATE_TOOL = "roll_and_narrate";
1282
1321
  const BRANCHES = [
1283
1322
  ["succeeded", "on_success"],
@@ -1443,8 +1482,7 @@ function createCheckNarrateTool(deps) {
1443
1482
  }
1444
1483
  });
1445
1484
  }
1446
- //#endregion
1447
- //#region src/host/memory/embedding-index.ts
1485
+ // src/host/memory/embedding-index.ts
1448
1486
  const BATCH = 32;
1449
1487
  /**
1450
1488
  * Keeps the vectors of a chat's texts: embeds what has none yet, and gives the vector of a moment to
@@ -1534,8 +1572,7 @@ var EmbeddingIndex = class {
1534
1572
  this.deps.problem(message);
1535
1573
  }
1536
1574
  };
1537
- //#endregion
1538
- //#region src/host/memory/rerank-memories.ts
1575
+ // src/host/memory/rerank-memories.ts
1539
1576
  /**
1540
1577
  * Judges the pool of memories a recall over-retrieved with a reranking service, by reading the
1541
1578
  * situation and each memory together. Without a service it has nothing to judge and says so, and the
@@ -1565,8 +1602,7 @@ function rerankMemories(deps) {
1565
1602
  }
1566
1603
  };
1567
1604
  }
1568
- //#endregion
1569
- //#region src/host/orchestration/suggestion-fallback.ts
1605
+ // src/host/orchestration/suggestion-fallback.ts
1570
1606
  /**
1571
1607
  * Lines made from the story's own data when the suggester could not make any, so the player is never left with an empty tray:
1572
1608
  * someone to talk to, a way out, a thing to look at, then plain standbys. No model is asked.
@@ -1595,8 +1631,7 @@ function fallbackSuggestions(store, count) {
1595
1631
  const lines = tidySuggestions(picked).map((line) => line.length > 200 ? `${line.slice(0, 199)}…` : line);
1596
1632
  return suggestionProblems(lines, count).length === 0 ? lines : [];
1597
1633
  }
1598
- //#endregion
1599
- //#region src/host/orchestration/after-turn.ts
1634
+ // src/host/orchestration/after-turn.ts
1600
1635
  /** Something made up that has waited this many turns is fitted into the world even if few are waiting. */
1601
1636
  const STALE_AFTER_TURNS = 4;
1602
1637
  const messageOf = (error) => error instanceof Error ? error.message : String(error);
@@ -1611,6 +1646,7 @@ var AfterTurnJobs = class {
1611
1646
  strategizing = /* @__PURE__ */ new Set();
1612
1647
  judging = /* @__PURE__ */ new Set();
1613
1648
  reflecting = /* @__PURE__ */ new Set();
1649
+ casting = /* @__PURE__ */ new Set();
1614
1650
  constructor(deps) {
1615
1651
  this.deps = deps;
1616
1652
  }
@@ -1618,6 +1654,7 @@ var AfterTurnJobs = class {
1618
1654
  this.consolidate(owner, cancel);
1619
1655
  this.strategize(owner, cancel);
1620
1656
  this.judge(owner, cancel);
1657
+ this.cast(owner, cancel);
1621
1658
  const reason = this.reflectionDue(owner);
1622
1659
  if (reason !== void 0) this.reflect(owner, reason, cancel);
1623
1660
  }
@@ -1693,6 +1730,37 @@ var AfterTurnJobs = class {
1693
1730
  this.strategizing.delete(owner.chat);
1694
1731
  }));
1695
1732
  }
1733
+ /** What a trigger asked the world author to make (a beat with `dispatch: author`) is made now, one request after the other: the game master is never asked, so it cannot ignore it. */
1734
+ cast(owner, cancel) {
1735
+ const store = this.deps.stores(owner.chat);
1736
+ if (store === void 0 || this.casting.has(owner.chat) || store.claimAuthorBeats === void 0 || !store.settings().authoring.enabled) return;
1737
+ const requests = store.claimAuthorBeats();
1738
+ if (requests.length === 0) return;
1739
+ this.casting.add(owner.chat);
1740
+ this.deps.track(owner.chat, (async () => {
1741
+ for (const request of requests) {
1742
+ const need = AUTHORING_NEEDS.find((candidate) => candidate === request.need);
1743
+ if (need === void 0) {
1744
+ this.deps.problem(`a trigger asked the world author for "${request.need}", which is not a reason to make something up`);
1745
+ continue;
1746
+ }
1747
+ try {
1748
+ await this.deps.boundaries().author.create({
1749
+ chat: owner.chat,
1750
+ turn: owner.turn,
1751
+ need,
1752
+ what: request.text,
1753
+ store
1754
+ }, cancel);
1755
+ this.deps.written(owner.chat);
1756
+ } catch (error) {
1757
+ if (!cancel.aborted) this.deps.problem(`the world author could not make what a trigger asked for: ${messageOf(error)}`);
1758
+ }
1759
+ }
1760
+ })().finally(() => {
1761
+ this.casting.delete(owner.chat);
1762
+ }));
1763
+ }
1696
1764
  /** The statements that triggers wait on are judged; a trigger fires from the verdict at the next look. */
1697
1765
  judge(owner, cancel) {
1698
1766
  const store = this.deps.stores(owner.chat);
@@ -1709,8 +1777,7 @@ var AfterTurnJobs = class {
1709
1777
  }));
1710
1778
  }
1711
1779
  };
1712
- //#endregion
1713
- //#region src/host/orchestration/turn-rules.ts
1780
+ // src/host/orchestration/turn-rules.ts
1714
1781
  /** Whether the game master still has to judge the player's action. */
1715
1782
  function judgeDue(state) {
1716
1783
  return state.judgeWanted === true && state.phase === "idle" && state.ooc === void 0 && state.judgement === void 0;
@@ -1879,8 +1946,7 @@ function decisions(state) {
1879
1946
  }
1880
1947
  return decided;
1881
1948
  }
1882
- //#endregion
1883
- //#region src/host/orchestration/character-attempt.ts
1949
+ // src/host/orchestration/character-attempt.ts
1884
1950
  /** Every character acts at the same time; one that fails or answers badly is reported, not fatal. */
1885
1951
  async function askCharacters(deps, owner, number, keys, cast, state, run, signal, away = false) {
1886
1952
  const { store, boundaries } = deps;
@@ -1972,8 +2038,7 @@ async function askCharacters(deps, owner, number, keys, cast, state, run, signal
1972
2038
  failures: answers.filter((answer) => "reason" in answer)
1973
2039
  };
1974
2040
  }
1975
- //#endregion
1976
- //#region src/host/orchestration/round-record.ts
2041
+ // src/host/orchestration/round-record.ts
1977
2042
  /** Records the game master's decisions as a finished round: what the characters did and said, what changed in the story, and the round queued for the keeper. `fire` runs the triggers the round may have made true. */
1978
2043
  function recordRound(store, owner, state, fire) {
1979
2044
  const decided = decisions(state);
@@ -2121,8 +2186,7 @@ function recordRound(store, owner, state, fire) {
2121
2186
  }] : [])
2122
2187
  };
2123
2188
  }
2124
- //#endregion
2125
- //#region src/host/orchestration/question-request.ts
2189
+ // src/host/orchestration/question-request.ts
2126
2190
  /** What the player's character is given to answer a question with: the same as a character is given to act, with the question as the moment. */
2127
2191
  async function questionRequest(boundaries, store, owner, question, signal) {
2128
2192
  const cast = store.cast();
@@ -2161,8 +2225,7 @@ async function questionRequest(boundaries, store, owner, question, signal) {
2161
2225
  ...memories.length === 0 ? {} : { memories }
2162
2226
  };
2163
2227
  }
2164
- //#endregion
2165
- //#region src/host/orchestration/world-making.ts
2228
+ // src/host/orchestration/world-making.ts
2166
2229
  /**
2167
2230
  * The game master asks for something to be made up (a place the story has gone to, someone who has
2168
2231
  * joined): the world author decides whether the story genuinely needs it, and makes it or says why not.
@@ -2179,8 +2242,9 @@ async function expandWorld(boundaries, store, state, owner, input, signal) {
2179
2242
  if (what === "") throw new Error("say what is needed, from what the story has established: who or where, and why now");
2180
2243
  const { authoring } = store.settings();
2181
2244
  if (!authoring.enabled) throw new Error("this world is closed: nothing can be made up in it");
2182
- const made = store.story.consolidation.createdIn(owner.turn).length;
2183
- if (made >= authoring.perTurn) throw new Error(`${made} new thing${made === 1 ? " was" : "s were"} already made up this turn, which is the most this chat allows: work with what exists`);
2245
+ const kind = need === "scene_change" ? "location" : need === "arrival" || need === "introduction" ? "character" : void 0;
2246
+ const made = store.story.consolidation.createdIn(owner.turn).filter((entry) => kind === void 0 || entry.kind === kind).length;
2247
+ if (made >= authoring.perTurn) throw new Error(`${made} new ${kind === "location" ? made === 1 ? "place was" : "places were" : kind === "character" ? made === 1 ? "character was" : "characters were" : made === 1 ? "thing was" : "things were"} already made up this turn, which is the most this chat allows: work with what exists, and do not ask again this turn`);
2184
2248
  return await boundaries.author.create({
2185
2249
  chat: owner.chat,
2186
2250
  turn: owner.turn,
@@ -2233,8 +2297,7 @@ function introduceThing(store, state, owner, input) {
2233
2297
  where: "heldBy" in placed ? `held by ${placed.heldBy}` : "inside" in placed ? `inside ${placed.inside}` : `at ${placed.at.location}`
2234
2298
  };
2235
2299
  }
2236
- //#endregion
2237
- //#region src/host/orchestration/turn-text.ts
2300
+ // src/host/orchestration/turn-text.ts
2238
2301
  /**
2239
2302
  * A model sometimes sends who speaks as a segment of its own (an utterance with no character whose text is the character's key or name) followed by the words with no
2240
2303
  * character either. When the label is exactly a character of the scene, the label is folded into the words that follow it.
@@ -2317,8 +2380,7 @@ function checkedOutput(narrationChecker, language, state, segments, silent) {
2317
2380
  repaired: true
2318
2381
  };
2319
2382
  }
2320
- //#endregion
2321
- //#region src/host/dice/view.ts
2383
+ // src/host/dice/view.ts
2322
2384
  const sign = (value) => value >= 0 ? `+${value}` : String(value);
2323
2385
  /** A roll as the player reads it: what it was for, what fell, what it came to and what the world's check made of it. */
2324
2386
  function rollView(roll) {
@@ -2417,8 +2479,7 @@ async function runOffScene(deps, owner, state, store, due, limit) {
2417
2479
  }
2418
2480
  }
2419
2481
  }
2420
- //#endregion
2421
- //#region src/host/orchestration/turn-engine.ts
2482
+ // src/host/orchestration/turn-engine.ts
2422
2483
  const MAX_OBJECTIONS = 3;
2423
2484
  /** The most a single round may be said to take: a day. A longer time passing is skipped with `advanceTime`. */
2424
2485
  const MAX_ROUND_SECONDS = 86400;
@@ -3228,8 +3289,7 @@ var TurnEngine = class {
3228
3289
  return output;
3229
3290
  }
3230
3291
  };
3231
- //#endregion
3232
- //#region src/host/images/jobs.ts
3292
+ // src/host/images/jobs.ts
3233
3293
  /** The same service, whose requests stand where the job's do unless a call says otherwise. */
3234
3294
  function withPriority(service, priority, highRes) {
3235
3295
  return Object.create(service, { generate: { value: (prompt, options) => service.generate(prompt, {
@@ -3448,8 +3508,7 @@ var ImageJobs = class {
3448
3508
  return `${id}/${node}`;
3449
3509
  }
3450
3510
  };
3451
- //#endregion
3452
- //#region src/orchestration.ts
3511
+ // src/orchestration.ts
3453
3512
  const WORKING_DIRECTORY_CONTEXT = "working-directory:current";
3454
3513
  const name = "@dsh-agentic-roleplay/core/orchestration";
3455
3514
  /**
@@ -3526,11 +3585,13 @@ function apply(ctx) {
3526
3585
  const id = roleplaySessionOf(agentSessionId);
3527
3586
  const agent = ctx.agents.get(SessionId(agentSessionId));
3528
3587
  if (id === void 0 || agent === void 0) return void 0;
3588
+ const session = ctx.roleplayState.openSession(sessionsDir(), id);
3529
3589
  return {
3530
- session: ctx.roleplayState.openSession(sessionsDir(), id),
3590
+ session,
3531
3591
  turn: currentTurn(agent),
3532
3592
  policy: liveSettings(sessionFolder(sessionsDir(), id)).memory,
3533
- queryVector: (text, signal) => index.queryVector(agentSessionId, text, signal)
3593
+ queryVector: (text, signal) => index.queryVector(agentSessionId, text, signal),
3594
+ engineVariables: () => commandsOf(session.metadata.getValue(COMMANDS_KEY)).map(commandFlagKey)
3534
3595
  };
3535
3596
  }), "roleplay: state tools");
3536
3597
  const settingsOf = (context) => {
@@ -3558,6 +3619,11 @@ function apply(ctx) {
3558
3619
  checks
3559
3620
  }, chat.session);
3560
3621
  };
3622
+ /** What the world carries as standing rules (the card's always-on rules), with a line that says what they are; nothing for a world that has none. */
3623
+ const standingSection = (text, language) => {
3624
+ if (text.trim() === shippedText("roleplay/standing", language).trim()) return "";
3625
+ return `${translator(languageOf(language))("The standing rules of this world. Apply them on every turn:")}\n\n${text}`;
3626
+ };
3561
3627
  for (const [name, order, id] of [[
3562
3628
  PERSONA_SECTION,
3563
3629
  ctx.systemPrompt.getSectionOrder("DEPLOYMENT_PERSONA_PREFIX"),
@@ -3576,7 +3642,8 @@ function apply(ctx) {
3576
3642
  const part = (name) => ctx.roleplayPrompts.text(name, language, {}, chat?.session);
3577
3643
  const variables = id === "roleplay/game-master" ? {
3578
3644
  preview: chat?.settings.preview.enabled === false ? "" : part("roleplay/preview"),
3579
- dice: diceSection(context, chat, language)
3645
+ dice: diceSection(context, chat, language),
3646
+ standing: standingSection(part(STANDING_PROMPT), language)
3580
3647
  } : id === "roleplay/persona" ? { style: part("roleplay/style") } : {};
3581
3648
  return ctx.roleplayPrompts.text(id, language, variables, chat?.session);
3582
3649
  }
@@ -3688,7 +3755,6 @@ function apply(ctx) {
3688
3755
  optionalTools: [...createDiceTools(diceLink), createCheckNarrateTool(toolDeps)]
3689
3756
  });
3690
3757
  }
3691
- //#endregion
3692
3758
  export { apply, inject, name };
3693
3759
 
3694
3760
  //# sourceMappingURL=orchestration.js.map