@dsh-agentic-roleplay/core 0.6.1 → 0.7.1

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 (40) hide show
  1. package/lib/access-DtOxFKBK.js +150 -0
  2. package/lib/{authoring-tools-BGzzW6O5.js → authoring-tools-BKltdiea.js} +160 -74
  3. package/lib/authoring.js +10 -5
  4. package/lib/{child-D5SVNk4O.js → child-CyCViUKa.js} +48 -7
  5. package/lib/client.js +2157 -780
  6. package/lib/client.js.map +1 -1
  7. package/lib/compaction.js +3 -3
  8. package/lib/doctor.js +3 -3
  9. package/lib/{gallery-C7VOJ3xH.js → gallery-BxZGOgMb.js} +2 -2
  10. package/lib/{generator-CO8usAjE.js → generator-BFmSYvR8.js} +2 -2
  11. package/lib/helper.js +1 -1
  12. package/lib/{hooks-BLperIIB.js → hooks-HnqXO8mM.js} +10 -241
  13. package/lib/images.js +4 -4
  14. package/lib/index.js +1424 -203
  15. package/lib/{library-DsDc6fQa.js → library-BGxPKs9a.js} +6 -3
  16. package/lib/{lorebook-author-tools-C-cFiE6E.js → lorebook-author-tools-BAnUyRtS.js} +37 -29
  17. package/lib/lorebook-authoring.js +8 -3
  18. package/lib/{narration-_dA9oIt2.js → narration-DvFBqmqe.js} +9 -132
  19. package/lib/orchestration.js +13 -10
  20. package/lib/{pack-jail-BKFmbYP8.js → pack-jail-DLGguGS3.js} +20 -13
  21. package/lib/{packs-ZTG7fWut.js → packs-jowC-MN_.js} +2 -2
  22. package/lib/{presenter-agent-BHSbyWwZ.js → presenter-agent-DvZtnf0Q.js} +6 -6
  23. package/lib/{preset-CJLW8Mp0.js → preset-CXbC0NeU.js} +3 -3
  24. package/lib/{preset-author-tools-1RstgEZs.js → preset-author-tools-C26kj6t5.js} +14 -7
  25. package/lib/preset-authoring.js +9 -4
  26. package/lib/{reflection-6qfOC5OT.js → reflection-CvOZGjmn.js} +9 -170
  27. package/lib/{presets-DcPCnn8O.js → route-DRTJ_vcA.js} +165 -4
  28. package/lib/text-JbWfTHbr.js +295 -0
  29. package/lib/turn-guard-BvCs1VxB.js +53 -0
  30. package/package.json +29 -29
  31. package/prompts/en/import/cut-off.md +1 -0
  32. package/prompts/en/import/finish-failed.md +1 -1
  33. package/prompts/en/roleplay/decide-instruction.md +1 -0
  34. package/prompts/en/roleplay/decide-irrelevant.md +1 -0
  35. package/prompts/zh/import/cut-off.md +1 -0
  36. package/prompts/zh/import/finish-failed.md +1 -1
  37. package/prompts/zh/roleplay/decide-instruction.md +1 -0
  38. package/prompts/zh/roleplay/decide-irrelevant.md +1 -0
  39. package/lib/access-EbNdZFbk.js +0 -25
  40. package/lib/text-CT1re6XT.js +0 -18
@@ -0,0 +1,150 @@
1
+ //#region src/shared/chat.ts
2
+ const CHAT_PREFIX = "session-";
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
+ /** The DSH chat of a roleplay session is named after the session's id. */
5
+ function chatSessionId(sessionId) {
6
+ return `${CHAT_PREFIX}${sessionId}`;
7
+ }
8
+ /** The roleplay session a DSH chat id could belong to; ordinary DSH chats have ids of the same shape. */
9
+ function roleplaySessionOf(chat) {
10
+ if (!chat.startsWith(CHAT_PREFIX)) return void 0;
11
+ const id = chat.slice(8);
12
+ return UUID_V4.test(id) ? id : void 0;
13
+ }
14
+ //#endregion
15
+ //#region ../dsh-roleplay-model/src/variable.ts
16
+ /** What a variable holds: a number within bounds, a yes or no, or one of a list of words. */
17
+ const VARIABLE_KINDS = [
18
+ "number",
19
+ "flag",
20
+ "choice"
21
+ ];
22
+ /** What a variable is about: each character, item or place has its own value; `world` has one value for the whole story. */
23
+ const VARIABLE_SUBJECTS = [
24
+ "character",
25
+ "item",
26
+ "location",
27
+ "world"
28
+ ];
29
+ /**
30
+ * Who can tell what the value is. `public`: anyone present (what shows). `private`: the character it belongs to, and the
31
+ * game master (what it feels or knows of itself). `hidden`: only the game master and the record keeper.
32
+ */
33
+ const VARIABLE_VISIBILITIES = [
34
+ "public",
35
+ "private",
36
+ "hidden"
37
+ ];
38
+ [
39
+ {
40
+ key: "valence",
41
+ name: "Valence",
42
+ description: "How pleasant its mood is: -1 very unpleasant, 0 neutral, 1 very pleasant.",
43
+ labels: [
44
+ {
45
+ upTo: -.6,
46
+ label: "miserable"
47
+ },
48
+ {
49
+ upTo: -.25,
50
+ label: "unhappy"
51
+ },
52
+ {
53
+ upTo: .25,
54
+ label: "even"
55
+ },
56
+ {
57
+ upTo: .6,
58
+ label: "pleased"
59
+ },
60
+ {
61
+ upTo: 1,
62
+ label: "delighted"
63
+ }
64
+ ]
65
+ },
66
+ {
67
+ key: "arousal",
68
+ name: "Arousal",
69
+ description: "How worked up it is: -1 drowsy, 0 ordinary, 1 frantic.",
70
+ labels: [
71
+ {
72
+ upTo: -.6,
73
+ label: "drowsy"
74
+ },
75
+ {
76
+ upTo: -.25,
77
+ label: "calm"
78
+ },
79
+ {
80
+ upTo: .25,
81
+ label: "alert"
82
+ },
83
+ {
84
+ upTo: .6,
85
+ label: "keyed up"
86
+ },
87
+ {
88
+ upTo: 1,
89
+ label: "frantic"
90
+ }
91
+ ]
92
+ },
93
+ {
94
+ key: "dominance",
95
+ name: "Dominance",
96
+ description: "How much in control it feels: -1 helpless, 0 even, 1 commanding.",
97
+ labels: [
98
+ {
99
+ upTo: -.6,
100
+ label: "helpless"
101
+ },
102
+ {
103
+ upTo: -.25,
104
+ label: "uneasy"
105
+ },
106
+ {
107
+ upTo: .25,
108
+ label: "steady"
109
+ },
110
+ {
111
+ upTo: .6,
112
+ label: "confident"
113
+ },
114
+ {
115
+ upTo: 1,
116
+ label: "commanding"
117
+ }
118
+ ]
119
+ }
120
+ ].map(({ labels, ...rest }) => ({
121
+ ...rest,
122
+ kind: "number",
123
+ subject: "character",
124
+ only: [],
125
+ min: -1,
126
+ max: 1,
127
+ integer: false,
128
+ options: [],
129
+ default: 0,
130
+ baseline: true,
131
+ visibility: "private",
132
+ bands: labels.map((band) => ({
133
+ upTo: band.upTo,
134
+ label: band.label
135
+ })),
136
+ always: false,
137
+ builtin: true
138
+ }));
139
+ //#endregion
140
+ //#region src/host/prompts/access.ts
141
+ /** The prompt `id` in `language`, from the library of the agent's own context. */
142
+ function promptFor(agent, id, language, variables) {
143
+ const library = agent.ctx.get("roleplayPrompts");
144
+ if (library === void 0) throw new Error("the prompt library is not running");
145
+ return library.text(id, language, variables, roleplaySessionOf(agent.session.id));
146
+ }
147
+ //#endregion
148
+ export { chatSessionId as a, VARIABLE_VISIBILITIES as i, VARIABLE_KINDS as n, roleplaySessionOf as o, VARIABLE_SUBJECTS as r, promptFor as t };
149
+
150
+ //# sourceMappingURL=access-DtOxFKBK.js.map
@@ -1,9 +1,10 @@
1
- import { a as isPresetName, b as INTENT_STATUSES, m as PROSE_PROMPTS, x as INTENT_TYPES, y as INTENT_HORIZONS } from "./presets-DcPCnn8O.js";
2
- import { b as VARIABLE_VISIBILITIES, f as parseSwitchboard, v as VARIABLE_KINDS, y as VARIABLE_SUBJECTS } from "./narration-_dA9oIt2.js";
3
- import { B as loadPlots, G as formatIssue, H as plotReferenceProblems, J as PROMPTS_FOLDER, K as errorMessage, U as readDocument, W as Reader, a as externalWithheld, at as InvalidWorldError, et as promptProblem, r as externalGiven, t as externalToolLimit, tt as shippedLanguages } from "./hooks-BLperIIB.js";
4
- import { t as trimCharacters } from "./text-CT1re6XT.js";
5
- import { c as parseSampling, o as runChild } from "./child-D5SVNk4O.js";
6
- import { b as slug, c as referenceImagePath, d as MEDIA_TYPES, h as writeImageFileMetadata, n as imageExtensionOf, t as addToLibrary, v as mapLimit, x as uniqueKey, y as norm } from "./library-DsDc6fQa.js";
1
+ import { i as VARIABLE_VISIBILITIES, n as VARIABLE_KINDS, r as VARIABLE_SUBJECTS } from "./access-DtOxFKBK.js";
2
+ import { D as INTENT_TYPES, E as INTENT_STATUSES, T as INTENT_HORIZONS, b as PROSE_PROMPTS, d as isPresetName, n as askYesNo, o as yesAt } from "./route-DRTJ_vcA.js";
3
+ import { f as parseSwitchboard } from "./narration-DvFBqmqe.js";
4
+ import { B as loadPlots, G as formatIssue, H as plotReferenceProblems, J as PROMPTS_FOLDER, K as errorMessage, U as readDocument, W as Reader, a as externalWithheld, at as InvalidWorldError, et as promptProblem, r as externalGiven, t as externalToolLimit, tt as shippedLanguages } from "./hooks-HnqXO8mM.js";
5
+ import { t as trimCharacters } from "./text-JbWfTHbr.js";
6
+ import { c as runChild, h as currentTurn, s as namedModel, t as ChildTimeoutError, u as parseSampling } from "./child-CyCViUKa.js";
7
+ import { S as uniqueKey, b as slug, c as referenceImagePath, d as MEDIA_TYPES, h as writeImageFileMetadata, n as imageExtensionOf, t as addToLibrary, v as mapLimit, x as trOf, y as norm } from "./library-BGxPKs9a.js";
7
8
  import { dirname, join } from "node:path";
8
9
  import { existsSync, readFileSync } from "node:fs";
9
10
  import { createHash, randomUUID } from "node:crypto";
@@ -17,6 +18,24 @@ import { lookup } from "node:dns";
17
18
  import { request } from "node:http";
18
19
  import { request as request$1 } from "node:https";
19
20
  import { BlockList, isIP } from "node:net";
21
+ //#region src/shared/authoring-chat.ts
22
+ const PREFIX = "world-author-";
23
+ /** Stable DSH chat identity for the authoring conversation of one world. */
24
+ function authoringChatSessionId(worldId) {
25
+ if (worldId === "") throw new TypeError("world id cannot be empty");
26
+ return `${PREFIX}${encodeURIComponent(worldId)}`;
27
+ }
28
+ /** The authored world named by a dedicated authoring chat. */
29
+ function authoredWorldOf(chatSessionId) {
30
+ if (!chatSessionId.startsWith(PREFIX)) return void 0;
31
+ try {
32
+ const id = decodeURIComponent(chatSessionId.slice(13));
33
+ return id === "" ? void 0 : id;
34
+ } catch {
35
+ return;
36
+ }
37
+ }
38
+ //#endregion
20
39
  //#region ../dsh-roleplay-model/src/character.ts
21
40
  const CHARACTER_ROLES = ["playable", "npc"];
22
41
  const CHARACTER_TIERS = [
@@ -2550,15 +2569,16 @@ const CLASSIFY_SCHEMA = {
2550
2569
  required: ["roles", "targets"],
2551
2570
  additionalProperties: false
2552
2571
  };
2553
- function classifyJob(text, card, item) {
2572
+ function classifyJob(text, tr, card, item) {
2554
2573
  const header = [
2555
- `Card: ${card.name}`,
2556
- `Piece: ${item.label}`,
2557
- ...item.title === "" ? [] : [`Title: ${item.title}`],
2558
- ...item.keys.length === 0 ? [] : [`Keys: ${item.keys.join(", ")}`]
2574
+ tr("Card: {name}", { name: card.name }),
2575
+ tr("Piece: {label}", { label: item.label }),
2576
+ ...item.title === "" ? [] : [tr("Title: {title}", { title: item.title })],
2577
+ ...item.keys.length === 0 ? [] : [tr("Keys: {keys}", { keys: item.keys.join(", ") })]
2559
2578
  ];
2560
2579
  return {
2561
2580
  persona: text("import/classifier", { max: MAX_TARGETS }),
2581
+ maxTokens: 2e3,
2562
2582
  prompt: `${header.join("\n")}\n---\n${item.text.slice(0, SHOWN_CHARS)}`,
2563
2583
  result: CLASSIFY_SCHEMA,
2564
2584
  check: (value) => {
@@ -2574,13 +2594,49 @@ function playerRoleKept(roles, text) {
2574
2594
  const rest = roles.filter((role) => role !== "player");
2575
2595
  return rest.length === 0 ? ["character"] : rest;
2576
2596
  }
2597
+ /**
2598
+ * The role of a piece the decision model is sure is only an instruction, or only notes for the reader: such a piece names nobody, so the language model is not asked.
2599
+ * Anything it is not sure of, or any failure of it, is left to the language model; the decision model is never the only reader of a piece that may be about the story.
2600
+ */
2601
+ async function settledByDecision(ctx, card, item, problems) {
2602
+ if (ctx.decide === void 0) return void 0;
2603
+ try {
2604
+ const probabilities = await ctx.decide({
2605
+ card: card.name,
2606
+ piece: item.label,
2607
+ ...item.title === "" ? {} : { title: item.title },
2608
+ text: item.text.slice(0, SHOWN_CHARS)
2609
+ }, [{
2610
+ key: "instruction",
2611
+ instructions: ctx.text("roleplay/decide-instruction")
2612
+ }, {
2613
+ key: "irrelevant",
2614
+ instructions: ctx.text("roleplay/decide-irrelevant")
2615
+ }]);
2616
+ const sure = yesAt(ctx.confidence ?? .7);
2617
+ if ((probabilities.get("instruction") ?? 0) >= sure) return "instruction";
2618
+ if ((probabilities.get("irrelevant") ?? 0) >= sure) return "irrelevant";
2619
+ } catch (error) {
2620
+ problems.add(error instanceof Error ? error.message : String(error));
2621
+ }
2622
+ }
2577
2623
  /** Says what every piece is. A piece that cannot be classified is kept as world background, so that nothing is lost silently; the failures are returned. */
2578
2624
  async function classifyItems(ctx, card, items) {
2579
2625
  const failures = [];
2626
+ const problems = /* @__PURE__ */ new Set();
2627
+ let decided = 0;
2580
2628
  const answers = await mapLimit(items, ctx.concurrency, async (item, index) => {
2581
2629
  ctx.say(`classifying ${index + 1}/${items.length}: ${item.label}`);
2630
+ const settled = await settledByDecision(ctx, card, item, problems);
2631
+ if (settled !== void 0) {
2632
+ decided += 1;
2633
+ return {
2634
+ roles: [settled],
2635
+ targets: []
2636
+ };
2637
+ }
2582
2638
  try {
2583
- const value = await ctx.run(classifyJob(ctx.text, card, item));
2639
+ const value = await ctx.run(classifyJob(ctx.text, trOf(ctx), card, item));
2584
2640
  const seen = /* @__PURE__ */ new Set();
2585
2641
  const targets = value.targets.map((target) => ({
2586
2642
  name: target.name.trim(),
@@ -2603,9 +2659,11 @@ async function classifyItems(ctx, card, items) {
2603
2659
  };
2604
2660
  }
2605
2661
  });
2662
+ failures.push(...[...problems].map((problem) => `the decision model could not be used, the language model sorted those pieces: ${problem}`));
2606
2663
  return {
2607
2664
  classified: Object.fromEntries(items.map((item, index) => [item.id, answers[index]])),
2608
- failures
2665
+ failures,
2666
+ decided
2609
2667
  };
2610
2668
  }
2611
2669
  /** A name that is only part of one longer name of the same kind (a given name, a short form) is that entity: it is folded into it as an alias. Several longer names make it ambiguous, so it stays. */
@@ -2728,11 +2786,12 @@ function rosterCheck(answer) {
2728
2786
  }
2729
2787
  if (answer.characters.filter((entry) => entry.player === true).length > 1) return "at most one character is the player";
2730
2788
  }
2731
- function rosterJob(text, card, candidates, titleIsBeing) {
2732
- const lines = candidates.map((candidate) => `${candidate.kind}: ${candidate.name} (${candidate.pieces.length} piece${candidate.pieces.length === 1 ? "" : "s"}${candidate.player ? ", about the player's character" : ""}${candidate.titles.length === 0 ? "" : `; titles: ${candidate.titles.join(" / ")}`})`);
2789
+ function rosterJob(text, tr, card, candidates, titleIsBeing) {
2790
+ const lines = candidates.map((candidate) => `${candidate.kind}: ${candidate.name} (${tr("{count} pieces", { count: candidate.pieces.length })}${candidate.player ? `, ${tr("about the player's character")}` : ""}${candidate.titles.length === 0 ? "" : `; ${tr("titles: {titles}", { titles: candidate.titles.join(" / ") })}`})`);
2733
2791
  return {
2734
2792
  persona: text("import/roster"),
2735
- prompt: `Card title: ${card.name}\n${titleIsBeing}\n\nNames found:\n${lines.join("\n")}`,
2793
+ maxTokens: 8e3,
2794
+ prompt: `${tr("Card title: {name}", { name: card.name })}\n${titleIsBeing}\n\n${tr("Names found:")}\n${lines.join("\n")}`,
2736
2795
  result: ROSTER_SCHEMA,
2737
2796
  check: rosterCheck
2738
2797
  };
@@ -2762,7 +2821,8 @@ function foldNamedAliases(answer, text) {
2762
2821
  */
2763
2822
  async function buildRoster(ctx, card, items, classified) {
2764
2823
  const candidates = candidatesOf(items, classified);
2765
- const titleIsBeing = candidates.some((candidate) => candidate.kind === "character" && norm(candidate.name) === norm(card.name)) ? "The pieces name the card title as a character." : "The card title is not named as a character by any piece.";
2824
+ const tr = trOf(ctx);
2825
+ const titleIsBeing = candidates.some((candidate) => candidate.kind === "character" && norm(candidate.name) === norm(card.name)) ? tr("The pieces name the card title as a character.") : tr("The card title is not named as a character by any piece.");
2766
2826
  let answer;
2767
2827
  let failure;
2768
2828
  try {
@@ -2771,7 +2831,7 @@ async function buildRoster(ctx, card, items, classified) {
2771
2831
  places: [],
2772
2832
  factions: [],
2773
2833
  things: []
2774
- } : await ctx.run(rosterJob(ctx.text, card, candidates, titleIsBeing));
2834
+ } : await ctx.run(rosterJob(ctx.text, tr, card, candidates, titleIsBeing));
2775
2835
  } catch (error) {
2776
2836
  failure = `the list of names could not be merged: ${error instanceof Error ? error.message : String(error)}`;
2777
2837
  const folded = foldContained(candidates.map((candidate) => ({
@@ -2873,19 +2933,26 @@ function sourcesFor(entity, items, classified) {
2873
2933
  }
2874
2934
  return chosen;
2875
2935
  }
2876
- const rosterLines = (roster) => [
2877
- "character",
2878
- "place",
2879
- "faction",
2880
- "thing"
2881
- ].map((kind) => `${kind}s: ${roster.filter((entity) => entity.kind === kind).map((entity) => entity.name).join("; ") || "(none)"}`).join("\n");
2882
- function promptFor(entity, sources, roster, card) {
2936
+ const rosterLines = (roster, tr) => [
2937
+ ["character", tr("characters")],
2938
+ ["place", tr("places")],
2939
+ ["faction", tr("factions")],
2940
+ ["thing", tr("things")]
2941
+ ].map(([kind, label]) => `${label}: ${roster.filter((entity) => entity.kind === kind).map((entity) => entity.name).join("; ") || tr("(none)")}`).join("\n");
2942
+ function promptFor(entity, sources, roster, card, tr) {
2883
2943
  const pieces = sources.map((source) => `[${source.label}]${source.title === "" ? "" : ` ${source.title}`}\n${source.text}`);
2944
+ const made = entity.player ? tr("Make the {kind} that the player plays: {name}", {
2945
+ kind: entity.kind,
2946
+ name: entity.name
2947
+ }) : tr("Make the {kind}: {name}", {
2948
+ kind: entity.kind,
2949
+ name: entity.name
2950
+ });
2884
2951
  return [
2885
- `Card: ${card.name}`,
2886
- `Make the ${entity.kind}${entity.player ? " that the player plays" : ""}: ${entity.name}${entity.aliases.length === 0 ? "" : ` (also called: ${entity.aliases.join(", ")})`}`,
2887
- `The others in this world, which are the only ones you may refer to:\n${rosterLines(roster)}`,
2888
- `Source pieces:\n${pieces.length === 0 ? "(none: write only what the name itself implies, and leave the rest empty)" : pieces.join("\n\n---\n\n")}`
2952
+ tr("Card: {name}", { name: card.name }),
2953
+ `${made}${entity.aliases.length === 0 ? "" : ` ${tr("(also called: {names})", { names: entity.aliases.join(", ") })}`}`,
2954
+ `${tr("The others in this world, which are the only ones you may refer to:")}\n${rosterLines(roster, tr)}`,
2955
+ `${tr("Source pieces:")}\n${pieces.length === 0 ? tr("(none: write only what the name itself implies, and leave the rest empty)") : pieces.join("\n\n---\n\n")}`
2889
2956
  ].join("\n\n");
2890
2957
  }
2891
2958
  const str = (description) => ({
@@ -3511,8 +3578,8 @@ const GROUP_KINDS = {
3511
3578
  faction: "faction",
3512
3579
  thing: "item"
3513
3580
  };
3514
- function jobFor(text, entity, sources, roster, card) {
3515
- const prompt = promptFor(entity, sources, roster, card);
3581
+ function jobFor(text, tr, entity, sources, roster, card) {
3582
+ const prompt = promptFor(entity, sources, roster, card, tr);
3516
3583
  const make = {
3517
3584
  character: characterDocument,
3518
3585
  place: placeDocument,
@@ -3521,6 +3588,7 @@ function jobFor(text, entity, sources, roster, card) {
3521
3588
  }[entity.kind];
3522
3589
  return {
3523
3590
  persona: text(`import/${entity.kind}`, { rules: text("import/common-rules") }),
3591
+ maxTokens: entity.kind === "character" ? 6e3 : 3e3,
3524
3592
  prompt,
3525
3593
  result: {
3526
3594
  character: CHARACTER_SCHEMA,
@@ -3542,7 +3610,7 @@ async function extractEntities(ctx, card, items, classified, roster) {
3542
3610
  ctx.say(`writing ${entity.kind} ${index + 1}/${roster.length}: ${entity.name}`);
3543
3611
  const sources = sourcesFor(entity, items, classified);
3544
3612
  try {
3545
- const answer = await ctx.run(jobFor(ctx.text, entity, sources, roster, card));
3613
+ const answer = await ctx.run(jobFor(ctx.text, trOf(ctx), entity, sources, roster, card));
3546
3614
  return {
3547
3615
  entity,
3548
3616
  built: {
@@ -3581,11 +3649,13 @@ async function extractEntities(ctx, card, items, classified, roster) {
3581
3649
  const loreResults = await mapLimit(worldItems, ctx.concurrency, async (item, index) => {
3582
3650
  ctx.say(`writing background ${index + 1}/${worldItems.length}: ${item.label}`);
3583
3651
  try {
3584
- const prompt = `Card: ${card.name}\nPiece: ${item.label}${item.title === "" ? "" : `\nTitle: ${item.title}`}\n\nThe entities of this world, which are the only ones the entries may name as subjects:\n${rosterLines(roster)}\n\nSource piece:\n${item.text.slice(0, 5500)}`;
3652
+ const tr = trOf(ctx);
3653
+ const prompt = `${tr("Card: {name}", { name: card.name })}\n${tr("Piece: {label}", { label: item.label })}${item.title === "" ? "" : `\n${tr("Title: {title}", { title: item.title })}`}\n\n${tr("The entities of this world, which are the only ones the entries may name as subjects:")}\n${rosterLines(roster, tr)}\n\n${tr("Source piece:")}\n${item.text.slice(0, 5500)}`;
3585
3654
  return {
3586
3655
  item,
3587
3656
  answer: await ctx.run({
3588
3657
  persona: ctx.text("import/lore", { rules: ctx.text("import/common-rules") }),
3658
+ maxTokens: 1500 + item.text.length,
3589
3659
  prompt,
3590
3660
  result: LORE_SCHEMA,
3591
3661
  check: (value) => loreProblem(value, roster, item.text)
@@ -3670,9 +3740,11 @@ async function extractStyleFrom(ctx, name, pieces) {
3670
3740
  };
3671
3741
  ctx.say("writing the style prompts");
3672
3742
  try {
3673
- const prompt = `Card: ${name}\n\nThe instructions of the card:\n\n${pieces.join("\n\n---\n\n").slice(0, SOURCE_BUDGET_CHARS)}`;
3743
+ const tr = trOf(ctx);
3744
+ const prompt = `${tr("Card: {name}", { name })}\n\n${tr("The instructions of the card:")}\n\n${pieces.join("\n\n---\n\n").slice(0, SOURCE_BUDGET_CHARS)}`;
3674
3745
  const answer = await ctx.run({
3675
3746
  persona: ctx.text("import/style", { rules: ctx.text("import/common-rules") }),
3747
+ maxTokens: 8e3,
3676
3748
  prompt,
3677
3749
  result: STYLE_SCHEMA,
3678
3750
  check: (value) => styleProblem("roleplay/style", text(value.narration), list(value.persona_names)) ?? styleProblem("roleplay/character-style", text(value.characters), list(value.persona_names))
@@ -3863,9 +3935,11 @@ async function extractVariables(ctx, card, items, classified, roster) {
3863
3935
  ctx.say("looking for what the card tracks");
3864
3936
  try {
3865
3937
  const names = (kind) => roster.filter((entity) => entity.kind === kind).map((entity) => entity.name).join(", ");
3866
- const prompt = `Card: ${card.name}\n\nCharacters: ${names("character")}\nPlaces: ${names("place")}\nThings: ${names("thing")}\n\nThe pieces of the card that may describe what it tracks:\n\n${pieces.join("\n\n---\n\n").slice(0, SOURCE_BUDGET_CHARS)}`;
3938
+ const tr = trOf(ctx);
3939
+ const prompt = `${tr("Card: {name}", { name: card.name })}\n\n${tr("Characters:")} ${names("character")}\n${tr("Places:")} ${names("place")}\n${tr("Things:")} ${names("thing")}\n\n${tr("The pieces of the card that may describe what it tracks:")}\n\n${pieces.join("\n\n---\n\n").slice(0, SOURCE_BUDGET_CHARS)}`;
3867
3940
  const answer = await ctx.run({
3868
3941
  persona: ctx.text("import/variables", { rules: ctx.text("import/common-rules") }),
3942
+ maxTokens: 6e3,
3869
3943
  prompt,
3870
3944
  result: VARIABLES_SCHEMA,
3871
3945
  check: (value) => variablesProblem(variableDocuments(value, roster), roster)
@@ -4452,6 +4526,7 @@ function knowledgeProblems(characters, locations, items, lore = []) {
4452
4526
  const places = new Map(locations.map((location) => [location.id, location]));
4453
4527
  const things = new Set(items.map((item) => item.id));
4454
4528
  const loreIds = new Set(lore.map((entry) => entry.id));
4529
+ const wayExists = (from, to) => places.get(from)?.exits.some((exit) => exit.to === to) === true || places.get(to)?.exits.some((exit) => exit.to === from && !exit.oneWay) === true;
4455
4530
  return characters.flatMap((character) => {
4456
4531
  const prefix = `${character.id}: knowledge`;
4457
4532
  const knowledge = character.knowledge;
@@ -4459,7 +4534,7 @@ function knowledgeProblems(characters, locations, items, lore = []) {
4459
4534
  return [
4460
4535
  ...knowledge.locations.flatMap((key) => places.has(key) ? [] : [`${prefix}.locations: "${key}" is not a place of this world`]),
4461
4536
  ...knowledge.items.flatMap((key) => things.has(key) ? [] : [`${prefix}.items: "${key}" is not an item of this world`]),
4462
- ...knowledge.exits.flatMap(({ from, to }) => places.get(from)?.exits.some((exit) => exit.to === to) === true ? [] : [`${prefix}.exits: there is no exit from "${from}" to "${to}"`]),
4537
+ ...knowledge.exits.flatMap(({ from, to }) => wayExists(from, to) ? [] : [`${prefix}.exits: there is no exit from "${from}" to "${to}"`]),
4463
4538
  ...(knowledge.lore ?? []).flatMap((key) => loreIds.has(key) ? [] : [`${prefix}.lore: "${key}" is not lore of this world`])
4464
4539
  ];
4465
4540
  });
@@ -5080,19 +5155,20 @@ const WORLD_SCHEMA = {
5080
5155
  additionalProperties: false
5081
5156
  };
5082
5157
  const STARTING_TIME = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2})?)?$/;
5083
- function worldJob(text, card, roster, scenario, opening) {
5158
+ function worldJob(text, tr, card, roster, scenario, opening) {
5084
5159
  const names = (kind) => roster.filter((entity) => entity.kind === kind).slice(0, 15).map((entity) => entity.name).join("; ");
5085
5160
  return {
5086
5161
  persona: text("import/world-summary"),
5162
+ maxTokens: 1500,
5087
5163
  prompt: [
5088
- `Card: ${card.name}`,
5089
- ...card.tags.length === 0 ? [] : [`Card tags: ${card.tags.join(", ")}`],
5090
- `Characters: ${names("character") || "(none)"}`,
5091
- `Places: ${names("place") || "(none)"}`,
5092
- `Scenario:\n${scenario.slice(0, 1200) || "(none)"}`,
5093
- `Opening:\n${opening.slice(0, 1200) || "(none)"}`,
5094
- `Description:\n${cleanText(card.description, card.name).slice(0, 1200) || "(none)"}`,
5095
- `Creator's notes:\n${cleanText(card.creatorNotes, card.name).slice(0, 600) || "(none)"}`
5164
+ tr("Card: {name}", { name: card.name }),
5165
+ ...card.tags.length === 0 ? [] : [tr("Card tags: {tags}", { tags: card.tags.join(", ") })],
5166
+ `${tr("Characters:")} ${names("character") || tr("(none)")}`,
5167
+ `${tr("Places:")} ${names("place") || tr("(none)")}`,
5168
+ `${tr("Scenario:")}\n${scenario.slice(0, 1200) || tr("(none)")}`,
5169
+ `${tr("Opening:")}\n${opening.slice(0, 1200) || tr("(none)")}`,
5170
+ `${tr("Description:")}\n${cleanText(card.description, card.name).slice(0, 1200) || tr("(none)")}`,
5171
+ `${tr("Creator's notes:")}\n${cleanText(card.creatorNotes, card.name).slice(0, 600) || tr("(none)")}`
5096
5172
  ].join("\n\n"),
5097
5173
  result: WORLD_SCHEMA,
5098
5174
  check: (value) => {
@@ -5106,7 +5182,7 @@ function worldJob(text, card, roster, scenario, opening) {
5106
5182
  async function describeWorld(ctx, card, roster, items, opening) {
5107
5183
  const scenario = items.filter((item) => item.id.startsWith("field:scenario")).map((item) => item.text).join("\n\n");
5108
5184
  try {
5109
- const answer = await ctx.run(worldJob(ctx.text, card, roster, scenario, opening));
5185
+ const answer = await ctx.run(worldJob(ctx.text, trOf(ctx), card, roster, scenario, opening));
5110
5186
  return {
5111
5187
  description: answer.description.trim(),
5112
5188
  tags: [...new Set(answer.tags.map((tag) => tag.trim()))],
@@ -5698,8 +5774,8 @@ async function survey(ctx, world) {
5698
5774
  ], "the survey");
5699
5775
  const { card, items } = await load(world);
5700
5776
  ensurePictures(world, card.urls ?? []);
5701
- const { classified, failures } = await classifyItems(ctx, card, items);
5702
- if (items.length > 0 && failures.length === items.length) throw new Error(`no piece of the card could be read, so nothing was imported: ${failures[0]}`);
5777
+ const { classified, failures, decided } = await classifyItems(ctx, card, items);
5778
+ if (items.length > 0 && failures.length >= items.length && decided === 0) throw new Error(`no piece of the card could be read, so nothing was imported: ${failures[0]}`);
5703
5779
  const { roster, failure } = await buildRoster(ctx, card, items.filter((item) => !isLeftOut(classified[item.id])), classified);
5704
5780
  await writeJson(join(folder(world), CLASSIFICATION), classified);
5705
5781
  await writeJson(join(folder(world), ROSTER), roster);
@@ -5722,7 +5798,11 @@ async function survey(ctx, world) {
5722
5798
  things: names("thing")
5723
5799
  },
5724
5800
  playable: roster.find((entity) => entity.player)?.name,
5725
- notes: [...failures, ...failure === void 0 ? [] : [failure]]
5801
+ notes: [
5802
+ ...failures,
5803
+ ...decided === 0 ? [] : [`the decision model settled ${decided} of ${items.length} pieces as instructions or notes, without asking the language model`],
5804
+ ...failure === void 0 ? [] : [failure]
5805
+ ]
5726
5806
  };
5727
5807
  }
5728
5808
  /** Second step: write every character, place, faction, thing and background entry from the pieces that are about it. */
@@ -5785,30 +5865,14 @@ async function finish(ctx, world) {
5785
5865
  return result;
5786
5866
  }
5787
5867
  //#endregion
5788
- //#region src/shared/authoring-chat.ts
5789
- const PREFIX = "world-author-";
5790
- /** Stable DSH chat identity for the authoring conversation of one world. */
5791
- function authoringChatSessionId(worldId) {
5792
- if (worldId === "") throw new TypeError("world id cannot be empty");
5793
- return `${PREFIX}${encodeURIComponent(worldId)}`;
5794
- }
5795
- /** The authored world named by a dedicated authoring chat. */
5796
- function authoredWorldOf(chatSessionId) {
5797
- if (!chatSessionId.startsWith(PREFIX)) return void 0;
5798
- try {
5799
- const id = decodeURIComponent(chatSessionId.slice(13));
5800
- return id === "" ? void 0 : id;
5801
- } catch {
5802
- return;
5803
- }
5804
- }
5805
- //#endregion
5806
5868
  //#region src/host/import/tools.ts
5807
5869
  const SURVEY_TOOL = "import_survey";
5808
5870
  const BUILD_TOOL = "import_build";
5809
5871
  const FINISH_TOOL = "import_finish";
5810
5872
  /** How many times a turn that has not finished the import is sent back to it. */
5811
5873
  const MAX_OBJECTIONS = 3;
5874
+ /** The build is the slow step (minutes, one agent per entity); a turn that needs it more often than this is not converging on a card that will finish. */
5875
+ const MAX_BUILDS_PER_TURN = 2;
5812
5876
  /** A model call that fails is made once more before the piece it was for is given up. */
5813
5877
  const ATTEMPTS = 2;
5814
5878
  const CARD = `${IMPORT_FOLDER}/card.json`;
@@ -5830,7 +5894,7 @@ const output = (render) => ({
5830
5894
  });
5831
5895
  const json = (value) => JSON.parse(JSON.stringify(value));
5832
5896
  /** The runner of an import: every job is a narrow agent below the chat's own, on the chat's model. */
5833
- function contextOf(exec, settings, text) {
5897
+ function contextOf(exec, settings, text, language) {
5834
5898
  const agent = exec.agent;
5835
5899
  if (agent === void 0) throw new Error("the import tools can only be called by an agent");
5836
5900
  const run = async (job) => {
@@ -5842,7 +5906,9 @@ function contextOf(exec, settings, text) {
5842
5906
  prompt: job.prompt,
5843
5907
  result: job.result,
5844
5908
  ...job.check === void 0 ? {} : { beforeSubmit: (value) => job.check?.(value) },
5845
- maxTokens: settings.maxTokens,
5909
+ maxTokens: Math.min(job.maxTokens ?? settings.maxTokens, settings.maxTokens),
5910
+ timeoutMinutes: settings.timeoutMinutes,
5911
+ ...namedModel(settings.model),
5846
5912
  sampling: {
5847
5913
  temperature: settings.temperature,
5848
5914
  toolChoice: "required"
@@ -5850,14 +5916,24 @@ function contextOf(exec, settings, text) {
5850
5916
  ...settings.reasoning === "" ? {} : { reasoningEffort: settings.reasoning }
5851
5917
  });
5852
5918
  } catch (error) {
5853
- if (exec.signal.aborted || attempt >= ATTEMPTS) throw error;
5919
+ if (exec.signal.aborted || attempt >= ATTEMPTS || error instanceof ChildTimeoutError) throw error;
5854
5920
  }
5855
5921
  };
5922
+ const decide = settings.decisions === "decision" ? (state, asks) => {
5923
+ const service = agent.ctx.get("decisions");
5924
+ if (service === void 0) return Promise.reject(/* @__PURE__ */ new Error("no decision service is selected, or the selected one is not loaded"));
5925
+ return askYesNo(service, state, asks, exec.signal);
5926
+ } : void 0;
5856
5927
  return {
5857
5928
  run,
5858
5929
  concurrency: settings.concurrency,
5859
5930
  text,
5860
- say: () => void 0
5931
+ ...language === void 0 ? {} : { language },
5932
+ say: () => void 0,
5933
+ ...decide === void 0 ? {} : {
5934
+ decide,
5935
+ confidence: settings.confidence
5936
+ }
5861
5937
  };
5862
5938
  }
5863
5939
  async function worldOf(worlds, exec) {
@@ -5878,6 +5954,7 @@ const toolNames = {
5878
5954
  };
5879
5955
  /** The three steps of an import, as tools of the authoring chat. They do their work in agents of their own, one narrow job each. */
5880
5956
  function importTools(worlds, settings, prompting) {
5957
+ const builds = /* @__PURE__ */ new Map();
5881
5958
  /** Runs one step for the world of the calling chat; what the model should do next is told in the result, in the person's language. */
5882
5959
  const step = async (exec, work, next) => {
5883
5960
  const world = await worldOf(worlds, exec);
@@ -5886,7 +5963,7 @@ function importTools(worlds, settings, prompting) {
5886
5963
  ...toolNames,
5887
5964
  ...variables
5888
5965
  });
5889
- const result = await work(contextOf(exec, settings(), text), world.directory);
5966
+ const result = await work(contextOf(exec, settings(), text, language), world.directory);
5890
5967
  return json({
5891
5968
  ...result,
5892
5969
  next: next(text, result)
@@ -5912,6 +5989,15 @@ function importTools(worlds, settings, prompting) {
5912
5989
  isConcurrencySafe: () => false,
5913
5990
  async execute(args, exec) {
5914
5991
  checkedCard(args);
5992
+ const chat = exec.agent?.session.id ?? "";
5993
+ const turn = exec.agent === void 0 ? 0 : currentTurn(exec.agent);
5994
+ const seen = builds.get(chat);
5995
+ const count = seen?.turn === turn ? seen.count + 1 : 1;
5996
+ if (count > MAX_BUILDS_PER_TURN) throw new Error(`the build has already run ${MAX_BUILDS_PER_TURN} times in this turn: do not run it again, tell the person what is wrong and stop`);
5997
+ builds.set(chat, {
5998
+ turn,
5999
+ count
6000
+ });
5915
6001
  return await step(exec, build, (text) => text("import/next-build"));
5916
6002
  }
5917
6003
  }),
@@ -6049,6 +6135,6 @@ function limitAuthoringAgents(ctx, kindOf) {
6049
6135
  });
6050
6136
  }
6051
6137
  //#endregion
6052
- export { LOCATION_FILE_NAME as $, loadTriggers as A, parseLoreFile as At, loadItems as B, ImportCardError as Bt, populateLocations as C, readLorebook as Ct, populateVariables as D, LORE_DIR as Dt, populateTriggers as E, writeLorebookEntry as Et, loadCalendar as F, parseLoreEdit as Ft, extractStyleFrom as G, LORE_SCOPES as Gt, loadFactions as H, pictureOf as Ht, parseCalendarFile as I, parsePlaceEdit as It, withPlayer as J, DICE_RESULTS as Jt, cleanText as K, DICE_COMPARISONS as Kt, LOCATIONS_DIR as L, parseRelationEdit as Lt, loadDice as M, InvalidEditProblems as Mt, parseDiceFile as N, parseCharacterEdit as Nt, routineProblems as O, loadLore as Ot, CALENDAR_FILE_NAME as P, parseFactionEdit as Pt, variableProblems as Q, loadLocations as R, parseThingEdit as Rt, populateKnowledge as S, lorebookDirectory as St, populateRoutines as T, updateLorebookInfo as Tt, CHARACTERS_DIR as U, readCard as Ut, FACTIONS_DIR as V, isPng as Vt, loadCharacters as W, LORE_KINDS as Wt, loadVariables as X, VARIABLES_FILE_NAME as Y, parseVariablesFile as Z, populateCharacters as _, deleteLorebookEntry as _t, importHooks as a, CHARACTER_FILE_NAME as at, populateFactions as b, listLorebooks as bt, authoredWorldOf as c, ImportNotFoundError as ct, markReady as d, WORLD_FILE_NAME as dt, parseLocationFile as et, guardedLookup as f, parseWorldFile as ft, populateCalendar as g, deleteLorebook as gt, knowsCharacter as h, createLorebook as ht, contextOf as i, parseFactionFile as it, DICE_FILE_NAME as j, subfolders as jt, TRIGGERS_FILE_NAME as k, LORE_FILE_NAME as kt, authoringChatSessionId as l, ImportStore as lt, loadValidatedWorld as m, addLorebookEntries as mt, limitAuthoringAgents as n, parseItemFile as nt, importTools as o, parseCharacterFile as ot, vetUrl as p, parseWorldInfoEdit as pt, partsOf as q, DICE_READINGS as qt, MAX_PREVIEW_TEXT as r, FACTION_FILE_NAME as rt, worldOf as s, IMPORT_FOLDER as st, AuthoringTools as t, ITEM_FILE_NAME as tt, isReviewing as u, parseChoices as ut, populateClock as v, entriesOf as vt, populateLore as w, reserveLorebook as wt, populateItems as x, loadLorebook as xt, populateDice as y, isLorebookName as yt, ITEMS_DIR as z, IMPORT_COMMAND as zt };
6138
+ export { ITEM_FILE_NAME as $, loadDice as A, InvalidEditProblems as At, loadFactions as B, pictureOf as Bt, populateRoutines as C, updateLorebookInfo as Ct, TRIGGERS_FILE_NAME as D, LORE_FILE_NAME as Dt, routineProblems as E, loadLore as Et, LOCATIONS_DIR as F, parseRelationEdit as Ft, partsOf as G, DICE_READINGS as Gt, loadCharacters as H, LORE_KINDS as Ht, loadLocations as I, parseThingEdit as It, loadVariables as J, authoringChatSessionId as Jt, withPlayer as K, DICE_RESULTS as Kt, ITEMS_DIR as L, IMPORT_COMMAND as Lt, CALENDAR_FILE_NAME as M, parseFactionEdit as Mt, loadCalendar as N, parseLoreEdit as Nt, loadTriggers as O, parseLoreFile as Ot, parseCalendarFile as P, parsePlaceEdit as Pt, parseLocationFile as Q, loadItems as R, ImportCardError as Rt, populateLore as S, reserveLorebook as St, populateVariables as T, LORE_DIR as Tt, extractStyleFrom as U, LORE_SCOPES as Ut, CHARACTERS_DIR as V, readCard as Vt, cleanText as W, DICE_COMPARISONS as Wt, variableProblems as X, parseVariablesFile as Y, LOCATION_FILE_NAME as Z, populateDice as _, isLorebookName as _t, importHooks as a, IMPORT_FOLDER as at, populateKnowledge as b, lorebookDirectory as bt, isReviewing as c, parseChoices as ct, vetUrl as d, parseWorldInfoEdit as dt, parseItemFile as et, loadValidatedWorld as f, addLorebookEntries as ft, populateClock as g, entriesOf as gt, populateCharacters as h, deleteLorebookEntry as ht, contextOf as i, parseCharacterFile as it, parseDiceFile as j, parseCharacterEdit as jt, DICE_FILE_NAME as k, subfolders as kt, markReady as l, WORLD_FILE_NAME as lt, populateCalendar as m, deleteLorebook as mt, limitAuthoringAgents as n, parseFactionFile as nt, importTools as o, ImportNotFoundError as ot, knowsCharacter as p, createLorebook as pt, VARIABLES_FILE_NAME as q, authoredWorldOf as qt, MAX_PREVIEW_TEXT as r, CHARACTER_FILE_NAME as rt, worldOf as s, ImportStore as st, AuthoringTools as t, FACTION_FILE_NAME as tt, guardedLookup as u, parseWorldFile as ut, populateFactions as v, listLorebooks as vt, populateTriggers as w, writeLorebookEntry as wt, populateLocations as x, readLorebook as xt, populateItems as y, loadLorebook as yt, FACTIONS_DIR as z, isPng as zt };
6053
6139
 
6054
- //# sourceMappingURL=authoring-tools-BGzzW6O5.js.map
6140
+ //# sourceMappingURL=authoring-tools-BKltdiea.js.map
package/lib/authoring.js CHANGED
@@ -1,8 +1,9 @@
1
- import { Lt as parseRelationEdit, Mt as InvalidEditProblems, a as importHooks, c as authoredWorldOf, n as limitAuthoringAgents, o as importTools, u as isReviewing } from "./authoring-tools-BGzzW6O5.js";
2
- import { _ as readWorldPrompt, g as listWorldPrompts, h as deleteWorldPrompt, m as PROSE_PROMPTS, v as writeWorldPrompt } from "./presets-DcPCnn8O.js";
3
- import { G as formatIssue, V as parsePlotsFile, nt as shippedPromptsDirectory } from "./hooks-BLperIIB.js";
4
- import { C as readWorldEditor, F as loadWorldParts, H as translateTools, M as deleteTriggerDocument, N as readTriggerDocuments, P as writeTriggerDocument, R as presetTools, _ as editWorldPlots, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, i as checkWorldPack, l as deleteAuthoredEntity, o as listWorldPacks, r as registerPackJail, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument, v as editWorldRelation } from "./pack-jail-BKFmbYP8.js";
5
- import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-ZTG7fWut.js";
1
+ import { At as InvalidEditProblems, Ft as parseRelationEdit, a as importHooks, c as isReviewing, n as limitAuthoringAgents, o as importTools, qt as authoredWorldOf } from "./authoring-tools-BKltdiea.js";
2
+ import { C as readWorldPrompt, S as listWorldPrompts, b as PROSE_PROMPTS, w as writeWorldPrompt, x as deleteWorldPrompt } from "./route-DRTJ_vcA.js";
3
+ import { G as formatIssue, V as parsePlotsFile, nt as shippedPromptsDirectory } from "./hooks-HnqXO8mM.js";
4
+ import { C as readWorldEditor, F as loadWorldParts, H as translateTools, M as deleteTriggerDocument, N as readTriggerDocuments, P as writeTriggerDocument, R as presetTools, _ as editWorldPlots, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, i as checkWorldPack, l as deleteAuthoredEntity, o as listWorldPacks, r as registerPackJail, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument, v as editWorldRelation } from "./pack-jail-DLGguGS3.js";
5
+ import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-jowC-MN_.js";
6
+ import { t as guardAuthoringTurns } from "./turn-guard-BvCs1VxB.js";
6
7
  import { join, relative } from "node:path";
7
8
  import { defineTool } from "@deepseek-ai/dsh-tools";
8
9
  import { readFile } from "node:fs/promises";
@@ -747,6 +748,10 @@ function apply(ctx) {
747
748
  reviewing
748
749
  });
749
750
  limitAuthoringAgents(ctx, (chat) => authoredWorldOf(chat) === void 0 ? void 0 : "worldAuthoring");
751
+ guardAuthoringTurns(ctx, () => ctx.roleplayPrompts, (chat) => {
752
+ const world = authoredWorldOf(chat);
753
+ return world === void 0 ? void 0 : ctx.roleplayAuthoringLanguages.get(world);
754
+ }, () => ctx.roleplayImport.settings.reasoning);
750
755
  ctx.on("tools/pre-execute", (exec, next) => authoringApproval(exec, next, reviewing));
751
756
  for (const [name, order, id] of [[
752
757
  "WORLD_AUTHORING_PERSONA",