briyah 1.4.1 → 2.0.0

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 (227) hide show
  1. package/README.md +1092 -849
  2. package/data/common/config/markup +1 -1
  3. package/data/common/prompts/character/progress_character.json +5 -5
  4. package/data/common/prompts/illustrator/describe_scene.json +11 -3
  5. package/data/common/prompts/perceive.json +2 -2
  6. package/data/common/prompts/room_moderator/moderate.json +34 -34
  7. package/data/common/prompts/story_moderator/moderate.json +62 -62
  8. package/data/packs/dnd5e/agents/battle-master.json +6 -0
  9. package/data/packs/dnd5e/agents/campaign-designer.json +6 -0
  10. package/data/packs/dnd5e/agents/character-creator.json +6 -0
  11. package/data/packs/dnd5e/agents/dungeon-master.json +6 -0
  12. package/data/packs/dnd5e/agents/player.json +13 -0
  13. package/data/packs/dnd5e/agents/table-moderator.json +6 -0
  14. package/data/{common/artifacts/dnd5e/dungeon_master-procedure.md → packs/dnd5e/artifacts/battle_master-combat.md} +31 -131
  15. package/data/packs/dnd5e/artifacts/dungeon_master-procedure.md +192 -0
  16. package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/manifest.json +8 -2
  17. package/data/packs/dnd5e/pack.json +6 -0
  18. package/data/packs/dnd5e/prompts/battle_master/defaults_config.json +23 -0
  19. package/data/packs/dnd5e/prompts/battle_master/perceive.json +33 -0
  20. package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +378 -0
  21. package/data/{common → packs/dnd5e}/prompts/character_creator/defaults_config.json +1 -1
  22. package/data/{common → packs/dnd5e}/prompts/character_creator/perceive.prompt +29 -0
  23. package/data/{common → packs/dnd5e}/prompts/dnd_player/perceive.prompt +40 -22
  24. package/data/{common → packs/dnd5e}/prompts/dnd_room_moderator/moderate.json +34 -34
  25. package/data/{common → packs/dnd5e}/prompts/dnd_room_moderator/moderate.prompt +14 -3
  26. package/data/{common → packs/dnd5e}/prompts/dungeon_master/defaults_config.json +1 -0
  27. package/data/{common → packs/dnd5e}/prompts/dungeon_master/perceive.prompt +122 -115
  28. package/data/packs/dnd5e/prompts/dungeon_master/system_instruction.prompt +0 -0
  29. package/data/packs/dnd5e/rooms/table.json +16 -0
  30. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +4 -13
  31. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +2 -1
  32. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +65 -77
  33. package/dist-sdk/server/src/ai/agent-config.d.ts +2 -0
  34. package/dist-sdk/server/src/ai/agent-store.service.js +8 -0
  35. package/dist-sdk/server/src/ai/agent.d.ts +6 -0
  36. package/dist-sdk/server/src/ai/agent.js +25 -2
  37. package/dist-sdk/server/src/ai/artifact.service.d.ts +3 -1
  38. package/dist-sdk/server/src/ai/artifact.service.js +12 -5
  39. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +3 -3
  40. package/dist-sdk/server/src/ai/pack-artifacts.js +21 -15
  41. package/dist-sdk/server/src/app/user-service-factory.js +9 -1
  42. package/dist-sdk/server/src/app.controller.d.ts +11 -11
  43. package/dist-sdk/server/src/app.controller.js +178 -88
  44. package/dist-sdk/server/src/app.service.d.ts +36 -8
  45. package/dist-sdk/server/src/app.service.js +147 -91
  46. package/dist-sdk/server/src/common/errors.d.ts +0 -3
  47. package/dist-sdk/server/src/common/errors.js +1 -11
  48. package/dist-sdk/server/src/config/prompt-resolver.d.ts +39 -0
  49. package/dist-sdk/server/src/config/prompt-resolver.js +189 -0
  50. package/dist-sdk/server/src/config/user-config.service.d.ts +17 -0
  51. package/dist-sdk/server/src/config/user-config.service.js +103 -0
  52. package/dist-sdk/server/src/config/user-paths.service.d.ts +4 -4
  53. package/dist-sdk/server/src/config/user-paths.service.js +12 -16
  54. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +35 -0
  55. package/dist-sdk/server/src/packs/pack-instantiation.service.js +154 -0
  56. package/dist-sdk/server/src/packs/pack-manifest.d.ts +52 -0
  57. package/dist-sdk/server/src/packs/pack-manifest.js +256 -0
  58. package/dist-sdk/server/src/packs/pack.service.d.ts +24 -0
  59. package/dist-sdk/server/src/packs/pack.service.js +151 -0
  60. package/dist-sdk/server/src/room/room-config.d.ts +5 -0
  61. package/dist-sdk/server/src/room/room-store.service.d.ts +3 -0
  62. package/dist-sdk/server/src/room/room-store.service.js +41 -5
  63. package/dist-sdk/server/src/room/room.d.ts +10 -2
  64. package/dist-sdk/server/src/room/room.js +37 -6
  65. package/dist-sdk/server/src/sdk/briyah.d.ts +2 -0
  66. package/dist-sdk/server/src/sdk/briyah.js +45 -8
  67. package/dist-sdk/server/src/sdk/index.d.ts +8 -3
  68. package/dist-sdk/server/src/sdk/index.js +6 -2
  69. package/dist-sdk/server/src/shared/shared.module.js +0 -3
  70. package/dist-sdk/server/src/story/story.service.d.ts +2 -2
  71. package/dist-sdk/server/src/story/story.service.js +2 -2
  72. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +17 -0
  73. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +54 -0
  74. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +3 -0
  75. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +6 -0
  76. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +2 -0
  77. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +4 -0
  78. package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.d.ts +1 -1
  79. package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.js +6 -3
  80. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +3 -0
  81. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +45 -5
  82. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +27 -0
  83. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +103 -0
  84. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +7 -0
  85. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +83 -0
  86. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +19 -0
  87. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +130 -0
  88. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +2 -1
  89. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +13 -2
  90. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +6 -0
  91. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +16 -0
  92. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +10 -0
  93. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +82 -1
  94. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +2 -0
  95. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +51 -6
  96. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +19 -9
  97. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +2 -0
  98. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +134 -0
  99. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +31 -13
  100. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +2 -0
  101. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +25 -8
  102. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +70 -4
  103. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +27 -0
  104. package/dist-sdk/server/src/tools/packs/index.d.ts +1 -2
  105. package/dist-sdk/server/src/tools/packs/index.js +5 -11
  106. package/dist-sdk/shared/types/app.types.d.ts +72 -13
  107. package/docs/assets/hierarchy.js +1 -1
  108. package/docs/assets/highlight.css +8 -1
  109. package/docs/assets/icons.js +1 -1
  110. package/docs/assets/icons.svg +1 -1
  111. package/docs/assets/main.js +4 -4
  112. package/docs/assets/navigation.js +1 -1
  113. package/docs/assets/search.js +1 -1
  114. package/docs/assets/style.css +18 -3
  115. package/docs/classes/Agent.html +702 -37
  116. package/docs/classes/Briyah.html +250 -33
  117. package/docs/classes/BriyahConfigService.html +117 -10
  118. package/docs/classes/NativeToolRegistry.html +156 -11
  119. package/docs/classes/PackInstantiationService.html +146 -0
  120. package/docs/classes/PackService.html +247 -0
  121. package/docs/classes/Room.html +1196 -74
  122. package/docs/classes/RoomMessage.html +260 -29
  123. package/docs/enums/MessageAction.html +123 -3
  124. package/docs/functions/availableToolPacks.html +41 -2
  125. package/docs/functions/dnd5eTools.html +42 -3
  126. package/docs/functions/installToolPacks.html +48 -0
  127. package/docs/functions/registerToolPacks.html +54 -6
  128. package/docs/hierarchy.html +42 -1
  129. package/docs/index.html +218 -30
  130. package/docs/interfaces/AgentCreationOptions.html +125 -0
  131. package/docs/interfaces/AgentInfo.html +188 -3
  132. package/docs/interfaces/AgentMessagesResponse.html +71 -2
  133. package/docs/interfaces/AppService.html +2799 -466
  134. package/docs/interfaces/Artifact.html +81 -4
  135. package/docs/interfaces/ArtifactMetadata.html +104 -3
  136. package/docs/interfaces/ArtifactWriteOptions.html +75 -6
  137. package/docs/interfaces/AttachDocumentResponse.html +61 -2
  138. package/docs/interfaces/BriyahConfigOptions.html +107 -10
  139. package/docs/interfaces/ChapterInfo.html +61 -2
  140. package/docs/interfaces/Character.html +81 -2
  141. package/docs/interfaces/CreateAgentResponse.html +56 -2
  142. package/docs/interfaces/CreateRoomResponse.html +61 -2
  143. package/docs/interfaces/CreateStoryResponse.html +56 -2
  144. package/docs/interfaces/FileList.html +56 -2
  145. package/docs/interfaces/FileMetadata.html +84 -3
  146. package/docs/interfaces/IConfigService.html +76 -3
  147. package/docs/interfaces/InstantiateModels.html +64 -0
  148. package/docs/interfaces/InstantiateRoomResult.html +70 -0
  149. package/docs/interfaces/LoadedPack.html +131 -0
  150. package/docs/interfaces/LoggingOptions.html +86 -7
  151. package/docs/interfaces/Message.html +80 -2
  152. package/docs/interfaces/ModelChoice.html +73 -0
  153. package/docs/interfaces/ModelInfo.html +71 -2
  154. package/docs/interfaces/NativeToolDefinition.html +96 -9
  155. package/docs/interfaces/PackAgentTemplate.html +101 -0
  156. package/docs/interfaces/PackRoomTemplate.html +108 -0
  157. package/docs/interfaces/PackView.html +172 -0
  158. package/docs/interfaces/PreparedPromptResponse.html +61 -2
  159. package/docs/interfaces/ProcessTextResponse.html +81 -2
  160. package/docs/interfaces/PromptFile.html +69 -2
  161. package/docs/interfaces/PromptFileContent.html +75 -2
  162. package/docs/interfaces/PromptFilesResponse.html +56 -2
  163. package/docs/interfaces/PromptFolder.html +79 -2
  164. package/docs/interfaces/PromptFolderDefaults.html +155 -0
  165. package/docs/interfaces/PromptFolderDefaultsResponse.html +66 -0
  166. package/docs/interfaces/PromptFoldersResponse.html +56 -2
  167. package/docs/interfaces/RoomDetails.html +133 -4
  168. package/docs/interfaces/RoomInfo.html +84 -2
  169. package/docs/interfaces/RoomMessageUpdate.html +91 -2
  170. package/docs/interfaces/RoomMessagesResponse.html +61 -2
  171. package/docs/interfaces/SendMessageResult.html +61 -2
  172. package/docs/interfaces/StoryErrorEvent.html +76 -4
  173. package/docs/interfaces/StoryIdea.html +71 -2
  174. package/docs/interfaces/StoryInfo.html +173 -3
  175. package/docs/interfaces/StoryIntroduceCharacterEvent.html +71 -4
  176. package/docs/interfaces/StoryProgressChapterEvent.html +64 -3
  177. package/docs/interfaces/StoryState.html +99 -6
  178. package/docs/interfaces/StoryStateEvent.html +69 -3
  179. package/docs/interfaces/ToolArtifact.html +81 -4
  180. package/docs/interfaces/ToolCaller.html +75 -6
  181. package/docs/interfaces/ToolDefinition.html +76 -2
  182. package/docs/interfaces/ToolHelpers.html +91 -6
  183. package/docs/interfaces/ToolParameter.html +71 -2
  184. package/docs/interfaces/ToolRoomAccess.html +200 -24
  185. package/docs/interfaces/ToolSummary.html +71 -2
  186. package/docs/interfaces/ToolsResponse.html +66 -2
  187. package/docs/interfaces/Transaction.html +96 -2
  188. package/docs/interfaces/TransactionHistoryResponse.html +61 -2
  189. package/docs/modules.html +53 -1
  190. package/docs/types/PackOrigin.html +34 -0
  191. package/docs/types/PromptScope.html +34 -1
  192. package/docs/types/RoomTurnMode.html +42 -0
  193. package/docs/types/ToolContext.html +36 -2
  194. package/docs/types/ToolRunResult.html +34 -1
  195. package/package.json +139 -139
  196. package/src/tools/packs/dnd5e/README.md +162 -26
  197. package/dist-sdk/server/src/library/library.service.d.ts +0 -14
  198. package/dist-sdk/server/src/library/library.service.js +0 -165
  199. package/docs/functions/enabledToolPacks.html +0 -2
  200. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/campaign_designer-setting.md +0 -0
  201. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/character_creator-basics.md +0 -0
  202. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-barbarian.md +0 -0
  203. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-bard.md +0 -0
  204. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-cleric.md +0 -0
  205. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-druid.md +0 -0
  206. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-fighter.md +0 -0
  207. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-monk.md +0 -0
  208. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-paladin.md +0 -0
  209. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-ranger.md +0 -0
  210. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-rogue.md +0 -0
  211. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-sorcerer.md +0 -0
  212. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-warlock.md +0 -0
  213. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-wizard.md +0 -0
  214. /package/data/{common/prompts/campaign_designer → packs/dnd5e/prompts/battle_master}/system_instruction.prompt +0 -0
  215. /package/data/{common → packs/dnd5e}/prompts/campaign_designer/defaults_config.json +0 -0
  216. /package/data/{common → packs/dnd5e}/prompts/campaign_designer/perceive.json +0 -0
  217. /package/data/{common → packs/dnd5e}/prompts/campaign_designer/perceive.prompt +0 -0
  218. /package/data/{common/prompts/character_creator → packs/dnd5e/prompts/campaign_designer}/system_instruction.prompt +0 -0
  219. /package/data/{common → packs/dnd5e}/prompts/character_creator/perceive.json +0 -0
  220. /package/data/{common/prompts/dnd_player → packs/dnd5e/prompts/character_creator}/system_instruction.prompt +0 -0
  221. /package/data/{common → packs/dnd5e}/prompts/dnd_player/defaults_config.json +0 -0
  222. /package/data/{common → packs/dnd5e}/prompts/dnd_player/perceive.json +0 -0
  223. /package/data/{common/prompts/dnd_room_moderator → packs/dnd5e/prompts/dnd_player}/system_instruction.prompt +0 -0
  224. /package/data/{common → packs/dnd5e}/prompts/dnd_room_moderator/defaults_config.json +0 -0
  225. /package/data/{common/prompts/dungeon_master → packs/dnd5e/prompts/dnd_room_moderator}/system_instruction.prompt +0 -0
  226. /package/data/{common → packs/dnd5e}/prompts/dungeon_master/compact_agent.prompt +0 -0
  227. /package/data/{common → packs/dnd5e}/prompts/dungeon_master/perceive.json +0 -0
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encounterTool = void 0;
4
+ const coerce_1 = require("../engine/coerce");
5
+ const encounter_1 = require("../engine/encounter");
6
+ const sheet_1 = require("../engine/sheet");
7
+ const shared_1 = require("./shared");
8
+ function isDown(room, combatant) {
9
+ if (!combatant.foe)
10
+ return false;
11
+ const artifact = room.get((0, sheet_1.foeArtifactName)(combatant.name));
12
+ if (!artifact)
13
+ return true;
14
+ try {
15
+ return (0, sheet_1.parseSheet)(artifact.body).hp.cur <= 0;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ function downNames(room, state) {
22
+ return state.order.filter((c) => isDown(room, c)).map((c) => c.name);
23
+ }
24
+ function describe(room, state) {
25
+ const up = (0, encounter_1.currentCombatant)(state);
26
+ return {
27
+ encounter: state.name,
28
+ round: state.round,
29
+ turn: up?.name,
30
+ order: state.order.map((c, i) => ({
31
+ position: i + 1,
32
+ name: c.name,
33
+ initiative: c.init,
34
+ acted: i < state.turn,
35
+ up: i === state.turn,
36
+ down: isDown(room, c) || undefined,
37
+ })),
38
+ };
39
+ }
40
+ exports.encounterTool = {
41
+ name: 'encounter',
42
+ description: 'Read or advance the fight in progress. "action" is status (the default — the round, the initiative order, and whose turn it is), next (mark the current combatant done and move to the next, rolling into the next round at the end of the order), remove (take a combatant out of the order entirely), or end (finish the fight and clear its monsters). A dead monster is skipped automatically by "next", so you never call on a corpse; a dying character is not skipped, because their turn is when they roll a death saving throw. Use "next" once per turn instead of re-copying the order into your situation line — the stored order cannot drift, and a re-copied one did.',
43
+ parameters: [
44
+ {
45
+ name: 'action',
46
+ type: 'string',
47
+ description: 'status, next, remove, or end',
48
+ required: false,
49
+ },
50
+ {
51
+ name: 'combatant',
52
+ type: 'string',
53
+ description: 'For "remove", who to take out of the order',
54
+ required: false,
55
+ },
56
+ ],
57
+ async handler(args, helpers) {
58
+ const room = (0, shared_1.requireRoom)(helpers);
59
+ const action = (0, coerce_1.str)(args.action, 'action', 'status').toLowerCase().trim();
60
+ let state;
61
+ try {
62
+ state = (0, encounter_1.parseEncounter)(room.get(sheet_1.ENCOUNTER_ARTIFACT)?.body);
63
+ }
64
+ catch (e) {
65
+ if (e instanceof encounter_1.EncounterError) {
66
+ return {
67
+ applied: false,
68
+ violation: e.violation,
69
+ message: e.message,
70
+ options: ['Call roll_initiative to start a fresh encounter'],
71
+ };
72
+ }
73
+ throw e;
74
+ }
75
+ if (action === 'end') {
76
+ const cleared = (0, shared_1.clearFoes)(room);
77
+ room.remove(sheet_1.ENCOUNTER_ARTIFACT);
78
+ return {
79
+ ended: true,
80
+ clearedMonsters: cleared.length > 0 ? cleared : undefined,
81
+ note: 'The encounter is over. Report the outcome to the room leader and stop.',
82
+ };
83
+ }
84
+ if (!state) {
85
+ return {
86
+ applied: false,
87
+ violation: 'no_encounter',
88
+ message: 'No fight is running.',
89
+ options: ['Call roll_initiative to start one'],
90
+ };
91
+ }
92
+ if (action === 'status') {
93
+ return describe(room, state);
94
+ }
95
+ if (action === 'remove') {
96
+ const name = (0, coerce_1.str)(args.combatant, 'combatant');
97
+ if (!name) {
98
+ throw new Error('Removing a combatant needs a "combatant" name.');
99
+ }
100
+ if (!(0, encounter_1.removeCombatant)(state, name)) {
101
+ return {
102
+ applied: false,
103
+ violation: 'not_in_encounter',
104
+ message: `"${name}" is not in the initiative order.`,
105
+ options: [`In the order: ${state.order.map((c) => c.name).join(', ')}`],
106
+ };
107
+ }
108
+ writeEncounter(room, state);
109
+ return { removed: name, ...describe(room, state) };
110
+ }
111
+ if (action !== 'next') {
112
+ throw new Error(`"${action}" is not an action. Use status, next, remove, or end.`);
113
+ }
114
+ const before = state.round;
115
+ const { combatant, skipped } = (0, encounter_1.advanceTurn)(state, (c) => isDown(room, c));
116
+ writeEncounter(room, state);
117
+ const remaining = (0, shared_1.listFoeNames)(room).filter((name) => !isDown(room, { name, init: 0, foe: true }));
118
+ return {
119
+ ...describe(room, state),
120
+ newRound: state.round > before ? state.round : undefined,
121
+ skipped: skipped.length > 0 ? skipped : undefined,
122
+ monstersStanding: remaining.length,
123
+ note: remaining.length === 0
124
+ ? 'No monster is still standing. If the fight is over, call encounter with action "end" and report the outcome to the room leader.'
125
+ : `${combatant?.name} is up.`,
126
+ };
127
+ },
128
+ };
129
+ function writeEncounter(room, state) {
130
+ room.update(sheet_1.ENCOUNTER_ARTIFACT, () => (0, encounter_1.renderEncounter)(state, downNames(room, state)), {
131
+ viewers: room.agentNicknames,
132
+ transient: true,
133
+ });
134
+ }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.statBlockTool = void 0;
4
4
  const coerce_1 = require("../engine/coerce");
5
- const dice_1 = require("../engine/dice");
5
+ const foes_1 = require("../engine/foes");
6
6
  const bestiary_1 = require("../engine/bestiary");
7
7
  const srd_1 = require("../data/srd");
8
8
  const coerce_2 = require("../engine/coerce");
@@ -32,6 +32,12 @@ exports.statBlockTool = {
32
32
  description: 'How many of this creature are present; returns a rolled hit point total for each',
33
33
  required: false,
34
34
  },
35
+ {
36
+ name: 'place',
37
+ type: 'boolean',
38
+ description: 'Put them in the fight as tracked combatants, named Goblin A, Goblin B and so on. Their hit points are then kept for you: roll their attacks with check, apply damage with apply_hp, and set conditions with conditions, all by name. Do this at the start of every encounter.',
39
+ required: false,
40
+ },
35
41
  {
36
42
  name: 'filter',
37
43
  type: 'string',
@@ -96,7 +102,7 @@ exports.statBlockTool = {
96
102
  block: compact(resolved.block),
97
103
  statBlock: (0, bestiary_1.describeMonster)(resolved.block),
98
104
  attribution: resolved.source === 'srd' ? srd_1.SRD_ATTRIBUTION : undefined,
99
- ...instanceHitPoints(resolved.block, args.count),
105
+ ...instanceHitPoints(helpers.room, resolved.block, args.count, (0, coerce_1.bool)(args.place)),
100
106
  };
101
107
  },
102
108
  };
@@ -117,26 +123,38 @@ function define(room, creature, raw, campaign) {
117
123
  note: `Stored in the "${bestiary_1.BESTIARY_ARTIFACT}" artifact. Look it up with stat_block from now on; it overrides any built-in creature of the same name.`,
118
124
  };
119
125
  }
120
- function instanceHitPoints(block, count) {
121
- if (count === undefined || count === null || count === '')
122
- return {};
126
+ function instanceHitPoints(room, block, count, place) {
127
+ if (count === undefined || count === null || count === '') {
128
+ if (!place)
129
+ return {};
130
+ count = 1;
131
+ }
123
132
  const wanted = (0, coerce_1.int)(count, 'count', 1);
124
133
  if (wanted < 1)
125
134
  return {};
126
135
  if (wanted > MAX_INSTANCES) {
127
136
  throw new Error(`At most ${MAX_INSTANCES} of one creature per call; ${wanted} were asked for. Run them as two groups.`);
128
137
  }
129
- const labels = 'ABCDEFGHIJKL';
130
- const instances = [];
131
- for (let i = 0; i < wanted; i++) {
132
- const hp = block.hpDice
133
- ? Math.max((0, dice_1.rollOne)(block.hpDice, dice_1.defaultRng).total, 1)
134
- : block.hp;
135
- instances.push({ name: `${block.name} ${labels[i]}`, hp });
138
+ const names = (0, foes_1.foeNames)(block.name, wanted);
139
+ const instances = names.map((name) => ({ name, hp: (0, foes_1.rollFoeHitPoints)(block) }));
140
+ if (!place) {
141
+ return {
142
+ instances,
143
+ instanceNote: 'These totals are not stored anywhere. Pass place=true to put them in the fight, and then check, apply_hp and conditions all work on them by name.',
144
+ };
145
+ }
146
+ if (!room) {
147
+ throw new Error('Placing combatants needs a room: run this from a room conversation rather than the Tools test panel.');
148
+ }
149
+ for (const instance of instances) {
150
+ const state = (0, foes_1.buildFoe)(block, instance.name, instance.hp, room.caller.nickname);
151
+ (0, shared_1.writeNewSheet)(room, state, '', true);
136
152
  }
137
153
  return {
138
154
  instances,
139
- instanceNote: 'These totals are not stored anywhere. Track them in your situation line as the fight runs.',
155
+ placed: names,
156
+ placeNote: `In the fight now. Roll their attacks with check (character: "${names[0]}", kind: "attack", subject: "${block.attacks?.[0]?.n || 'its attack'}", dc: the target's AC) — ` +
157
+ 'it compares against the armour class for you. Apply damage to them with apply_hp, and set conditions with conditions. Their hit points are tracked for you; do not carry them in your situation line.',
140
158
  };
141
159
  }
142
160
  function compact(block) {
@@ -18,6 +18,8 @@ export interface LoadedSheet {
18
18
  warnings: string[];
19
19
  }
20
20
  export declare function listCharacterNames(room: ToolRoomAccess): string[];
21
+ export declare function listFoeNames(room: ToolRoomAccess): string[];
22
+ export declare function clearFoes(room: ToolRoomAccess, keep?: string[]): string[];
21
23
  export declare function loadSheet(room: ToolRoomAccess, name: string): LoadedSheet;
22
24
  export declare function mutateSheet(room: ToolRoomAccess, name: string, mutate: (sheet: LoadedSheet) => MutationResult): {
23
25
  result: MutationResult;
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireRoom = requireRoom;
4
4
  exports.listCharacterNames = listCharacterNames;
5
+ exports.listFoeNames = listFoeNames;
6
+ exports.clearFoes = clearFoes;
5
7
  exports.loadSheet = loadSheet;
6
8
  exports.mutateSheet = mutateSheet;
7
9
  exports.writeNewSheet = writeNewSheet;
@@ -27,16 +29,31 @@ function listCharacterNames(room) {
27
29
  .filter(sheet_1.isSheetArtifact)
28
30
  .map(sheet_1.characterNameFromArtifact);
29
31
  }
32
+ function listFoeNames(room) {
33
+ return room.list().filter(sheet_1.isFoeArtifact).map(sheet_1.foeNameFromArtifact);
34
+ }
35
+ function clearFoes(room, keep = []) {
36
+ const kept = new Set(keep.map((name) => (0, coerce_1.nameKey)(name)));
37
+ const removed = listFoeNames(room).filter((name) => !kept.has((0, coerce_1.nameKey)(name)));
38
+ for (const name of removed)
39
+ room.remove((0, sheet_1.foeArtifactName)(name));
40
+ return removed;
41
+ }
30
42
  function loadSheet(room, name) {
31
- const known = listCharacterNames(room);
32
- if (known.length === 0) {
43
+ const characters = listCharacterNames(room);
44
+ const foes = listFoeNames(room);
45
+ if (characters.length === 0 && foes.length === 0) {
33
46
  throw new Error('No character sheets exist in this room yet. Create one with create_sheet first.');
34
47
  }
35
- const matched = (0, coerce_1.matchName)(name, known);
36
- if (!matched) {
37
- throw new Error(`No sheet named "${name}". Known sheets: ${known.join(', ')}.`);
48
+ const matched = (0, coerce_1.matchName)(name, characters);
49
+ const matchedFoe = matched ? undefined : (0, coerce_1.matchName)(name, foes);
50
+ if (!matched && !matchedFoe) {
51
+ throw new Error(`No combatant named "${name}". Characters: ${characters.join(', ') || 'none'}.` +
52
+ ` Monsters in this fight: ${foes.join(', ') || 'none'}.`);
38
53
  }
39
- const artifactName = (0, sheet_1.sheetArtifactName)(matched);
54
+ const artifactName = matched
55
+ ? (0, sheet_1.sheetArtifactName)(matched)
56
+ : (0, sheet_1.foeArtifactName)(matchedFoe);
40
57
  const artifact = room.get(artifactName);
41
58
  if (!artifact) {
42
59
  throw new Error(`The sheet artifact "${artifactName}" disappeared while being read.`);
@@ -51,7 +68,7 @@ function loadSheet(room, name) {
51
68
  const state = (0, sheet_1.parseSheet)(artifact.body);
52
69
  return {
53
70
  artifactName,
54
- characterName: matched,
71
+ characterName: matched || matchedFoe,
55
72
  state,
56
73
  notes: (0, sheet_1.extractNotes)(artifact.body),
57
74
  warnings: (0, sheet_1.collectWarnings)(raw, state),
@@ -85,7 +102,7 @@ function mutateSheet(room, name, mutate) {
85
102
  return { result, sheet };
86
103
  }
87
104
  function writeNewSheet(room, state, notes, replace) {
88
- const artifactName = (0, sheet_1.sheetArtifactName)(state.name);
105
+ const artifactName = (0, sheet_1.combatantArtifactName)(state);
89
106
  const existing = room.get(artifactName);
90
107
  if (existing && !replace) {
91
108
  throw new Error(`A sheet for "${state.name}" already exists. Pass replace=true to overwrite it, or use patch_sheet to change specific fields.`);
@@ -49,7 +49,7 @@ const SPEC_EXAMPLE = '{"class":"Ranger","subclass":"Hunter","level":3,"race":"Wo
49
49
  const SET_EXAMPLE = '{"ac":18,"hp.max":32,"speed":25,"resist":["fire"],"uses.channel_divinity.cur":0}';
50
50
  exports.createSheetTool = {
51
51
  name: 'create_sheet',
52
- description: 'Create a character sheet. "character" is the character\'s name. "spec" is a JSON object describing them; only the class is genuinely required and everything else is derived or defaulted. Hit points, armour class, proficiency bonus, saving throws, skill modifiers, spell slots and hit dice are all computed from the 5e rules, so do not work them out yourself. Include a "backstory" string to seed the sheet\'s notes section, which later tool calls never overwrite. "owner" is the nickname of the agent who plays this character — set it, because the sheet is made readable to that agent alone, and because it is how the rest of the table is told who they are: the owning agent\'s public description becomes the character\'s name, race and class, replacing whatever placeholder they were created with. Set "replace" to true to overwrite an existing sheet. Example spec: ' +
52
+ description: 'Create a character sheet. "character" is the character\'s name. "spec" is a JSON object describing them; only the class is genuinely required and everything else is derived or defaulted. Hit points, armour class, proficiency bonus, saving throws, skill modifiers, spell slots and hit dice are all computed from the 5e rules, so do not work them out yourself. Put tool proficiencies the player *chose* in "tools", e.g. "tools":["Lute","Drum","Flute"] for a bard — the ones their class, race and background grant outright are added for you, and the result says which choices are still owed. Include a "backstory" string to seed the sheet\'s notes section, which later tool calls never overwrite. "owner" is the nickname of the agent who plays this character — set it, because the sheet is made readable to that agent alone, and because it is how the rest of the table is told who they are: the owning agent\'s public description becomes the character\'s name, race and class, replacing whatever placeholder they were created with. Set "replace" to true to overwrite an existing sheet. Example spec: ' +
53
53
  SPEC_EXAMPLE,
54
54
  parameters: [
55
55
  { name: 'character', type: 'string', description: "The character's name", required: true },
@@ -82,6 +82,7 @@ exports.createSheetTool = {
82
82
  const state = (0, character_1.buildCharacter)(name, spec, owner);
83
83
  const raceResult = (0, character_1.lastRaceResult)();
84
84
  const backgroundResult = (0, character_1.lastBackgroundResult)();
85
+ const classToolResult = (0, character_1.lastClassToolResult)();
85
86
  for (const item of state.inv) {
86
87
  if (isWorn(item.n))
87
88
  item.eq = true;
@@ -128,6 +129,15 @@ exports.createSheetTool = {
128
129
  }
129
130
  : undefined,
130
131
  raceProblems: raceResult.problems.length > 0 ? raceResult.problems : undefined,
132
+ tools: state.toolProf.length > 0 || classToolResult.outstanding.length > 0
133
+ ? {
134
+ proficient: state.toolProf.length > 0 ? state.toolProf : undefined,
135
+ fromClass: classToolResult.added.length > 0 ? classToolResult.added : undefined,
136
+ stillToChoose: classToolResult.outstanding.length > 0
137
+ ? classToolResult.outstanding
138
+ : undefined,
139
+ }
140
+ : undefined,
131
141
  derived: {
132
142
  hitPoints: `${state.hp.cur}/${state.hp.max}`,
133
143
  armorClass: `${state.ac} (${rules.computeArmorClass(state).explanation})`,
@@ -269,6 +279,8 @@ exports.readSheetTool = {
269
279
  .skillNames()
270
280
  .map((skill) => [(0, sheet_1.titleCase)(skill), (0, sheet_1.signed)(rules.skillModifier(state, skill))]));
271
281
  result.passivePerception = rules.passivePerception(state);
282
+ if (state.toolProf.length > 0)
283
+ result.toolProficiencies = state.toolProf;
272
284
  }
273
285
  if (wants('spells')) {
274
286
  result.spells = {
@@ -318,7 +330,7 @@ exports.patchSheetTool = {
318
330
  name: 'patch_sheet',
319
331
  description: 'Set fields on a character sheet directly, for anything the other tools do not cover. "set" is a JSON object of dotted paths to values applied to the sheet\'s underlying state, for example ' +
320
332
  SET_EXAMPLE +
321
- '. "append" adds entries to a list field, e.g. {"attacks":[{"n":"Dagger","atk":5,"dmg":"1d4+3","type":"piercing"}]}. "note" appends a line to the character\'s notes, which no other tool overwrites. Set "recompute" to true to recalculate hit points, armour class, initiative and spell slots after the change — do that after altering abilities, level, or equipment. A change that would leave the sheet inconsistent is refused with an explanation. Prefer a specific tool when one exists: this one does no rules reasoning for you.',
333
+ '. "append" adds entries to a list field, e.g. {"attacks":[{"n":"Dagger","atk":5,"dmg":"1d4+3","type":"piercing"}]}. "note" appends a line to the character\'s notes, which no other tool overwrites. Set "recompute" to true to recalculate hit points, armour class, initiative and spell slots after the change — do that after altering abilities, level, or equipment. **A sheet has a fixed set of fields and you cannot invent one** — a path whose first segment is not a real field is refused and the refusal lists them, so check the name rather than guessing (ability scores live under "abil", not "abilities"). Anything the sheet does not model — a racial trait from outside the SRD, a feature with no pool — goes in "note". A change that would leave the sheet inconsistent is refused with an explanation. Prefer a specific tool when one exists: this one does no rules reasoning for you.',
322
334
  parameters: [
323
335
  { name: 'character', type: 'string', description: 'Whose sheet to change', required: true },
324
336
  {
@@ -359,6 +371,23 @@ exports.patchSheetTool = {
359
371
  const sheet = (0, shared_1.loadSheet)(room, character);
360
372
  const candidate = (0, character_1.cloneState)(sheet.state);
361
373
  const applied = [];
374
+ const rejected = [...Object.keys(set), ...Object.keys(append)]
375
+ .map((path) => ({ path, problem: pathProblem(candidate, path) }))
376
+ .filter((entry) => entry.problem);
377
+ if (rejected.length > 0) {
378
+ return {
379
+ applied: false,
380
+ violation: 'unknown_field',
381
+ message: rejected.map((entry) => entry.problem).join(' '),
382
+ rule: 'A sheet has a fixed set of fields. Anything else belongs in the notes.',
383
+ options: [
384
+ `Fields on a sheet: ${(0, sheet_1.sheetFieldNames)().join(', ')}`,
385
+ 'For something the sheet does not model — a racial trait from outside the SRD, a class feature with no pool — use the "note" parameter instead, which appends to the character\'s notes and is never overwritten',
386
+ 'Read the sheet back with read_sheet if you are unsure what a field is called',
387
+ ],
388
+ state: (0, shared_1.liveState)(sheet.state),
389
+ };
390
+ }
362
391
  for (const [path, value] of Object.entries(set)) {
363
392
  setPath(candidate, path, value);
364
393
  applied.push(`${path} = ${JSON.stringify(value)}`);
@@ -366,7 +395,19 @@ exports.patchSheetTool = {
366
395
  for (const [path, value] of Object.entries(append)) {
367
396
  const target = getPath(candidate, path);
368
397
  if (!Array.isArray(target)) {
369
- throw new Error(`"${path}" is not a list on this sheet, so nothing can be appended to it.`);
398
+ return {
399
+ applied: false,
400
+ violation: 'not_a_list',
401
+ message: `"${path}" is not a list on this sheet, so nothing can be appended to it.`,
402
+ options: [
403
+ `Lists you can append to: ${(0, sheet_1.sheetFieldNames)()
404
+ .filter((field) => Array.isArray(candidate[field]))
405
+ .join(', ')}`,
406
+ 'Use "set" to replace the value outright',
407
+ 'Use the "note" parameter for prose the sheet does not model',
408
+ ],
409
+ state: (0, shared_1.liveState)(sheet.state),
410
+ };
370
411
  }
371
412
  const additions = Array.isArray(value) ? value : [value];
372
413
  target.push(...additions);
@@ -408,13 +449,38 @@ exports.patchSheetTool = {
408
449
  function getPath(state, path) {
409
450
  return path.split('.').reduce((node, key) => (node === undefined ? undefined : node[key]), state);
410
451
  }
452
+ function pathProblem(state, path) {
453
+ const keys = String(path).split('.');
454
+ const root = keys[0];
455
+ if (!root)
456
+ return `"${path}" is not a field name.`;
457
+ if (!(0, sheet_1.sheetFieldNames)().includes(root)) {
458
+ return `"${root}" is not a field on a character sheet, so "${path}" would have created a new one that nothing reads.`;
459
+ }
460
+ let node = state;
461
+ for (let i = 0; i < keys.length - 1; i++) {
462
+ const value = node[keys[i]];
463
+ if (value === undefined || value === null) {
464
+ return '';
465
+ }
466
+ if (typeof value !== 'object' || Array.isArray(value)) {
467
+ const shape = Array.isArray(value) ? 'a list' : `a ${typeof value}`;
468
+ return `"${keys.slice(0, i + 1).join('.')}" is ${shape}, not an object, so "${path}" cannot be written inside it.`;
469
+ }
470
+ node = value;
471
+ }
472
+ return '';
473
+ }
411
474
  function setPath(state, path, value) {
412
475
  const keys = path.split('.');
413
476
  let node = state;
414
477
  for (const key of keys.slice(0, -1)) {
415
- if (node[key] === undefined || node[key] === null || typeof node[key] !== 'object') {
478
+ if (node[key] === undefined || node[key] === null) {
416
479
  node[key] = {};
417
480
  }
481
+ else if (typeof node[key] !== 'object' || Array.isArray(node[key])) {
482
+ throw new Error(`"${key}" already holds ${Array.isArray(node[key]) ? 'a list' : `a ${typeof node[key]}`}, so "${path}" cannot be written inside it.`);
483
+ }
418
484
  node = node[key];
419
485
  }
420
486
  node[keys[keys.length - 1]] = value;
@@ -42,6 +42,8 @@ const items_1 = require("../engine/items");
42
42
  const races_1 = require("../engine/races");
43
43
  const feats_1 = require("../engine/feats");
44
44
  const backgrounds_1 = require("../engine/backgrounds");
45
+ const kits_1 = require("../engine/kits");
46
+ const kits_2 = require("../data/kits");
45
47
  const gear_1 = require("../data/gear");
46
48
  const backgrounds_2 = require("../data/backgrounds");
47
49
  const feats_2 = require("../data/feats");
@@ -487,6 +489,29 @@ exports.rulesLookupTool = {
487
489
  attribution: srd_1.SRD_ATTRIBUTION,
488
490
  };
489
491
  }
492
+ if (/^(tool|tools|tool proficienc|artisans? tools|gaming set|musical instrument)/.test(topic)) {
493
+ return {
494
+ topic,
495
+ kind: 'rule',
496
+ text: kits_2.TOOLS_RULE,
497
+ tools: Object.fromEntries(Object.keys(kits_2.TOOL_CATEGORY_LABEL).map((category) => [
498
+ category,
499
+ (0, kits_1.toolsInCategory)(category),
500
+ ])),
501
+ attribution: srd_1.SRD_ATTRIBUTION,
502
+ };
503
+ }
504
+ const tool = (0, kits_1.resolveTool)(topic);
505
+ if (tool.tool) {
506
+ return {
507
+ topic,
508
+ kind: 'tool',
509
+ text: `**${tool.tool.name}** — ${kits_2.TOOL_CATEGORY_LABEL[tool.tool.category]}. ` +
510
+ 'Proficiency adds your proficiency bonus to an ability check made with it; the DM chooses which ability the check uses.',
511
+ tool: tool.tool,
512
+ attribution: srd_1.SRD_ATTRIBUTION,
513
+ };
514
+ }
490
515
  if (topic === 'feat' || topic === 'feats') {
491
516
  return { topic, kind: 'rule', text: feats_2.FEATS_RULE, attribution: srd_1.SRD_ATTRIBUTION };
492
517
  }
@@ -539,8 +564,10 @@ exports.rulesLookupTool = {
539
564
  ...(0, races_1.raceNames)().map((name) => name.toLowerCase()),
540
565
  ...(0, feats_1.featNames)().map((name) => name.toLowerCase()),
541
566
  ...(0, backgrounds_1.backgroundNames)().map((name) => name.toLowerCase()),
567
+ ...(0, kits_1.toolNames)().map((name) => name.toLowerCase()),
542
568
  'feats',
543
569
  'backgrounds',
570
+ 'tools',
544
571
  'carrying capacity',
545
572
  'encumbrance',
546
573
  ].filter((known) => known.includes(topic.split(' ')[0]) || topic.includes(known.split(' ')[0]));
@@ -1,7 +1,6 @@
1
1
  import { NativeToolRegistry } from '../native-tool-registry.service';
2
2
  import { dnd5eTools } from './dnd5e';
3
+ export declare function installToolPacks(registry: NativeToolRegistry): string[];
3
4
  export declare function registerToolPacks(registry: NativeToolRegistry, packList: string | undefined): string[];
4
5
  export declare function availableToolPacks(): string[];
5
- export declare function enabledToolPacks(): string[];
6
- export declare function resetEnabledToolPacks(): void;
7
6
  export { dnd5eTools };
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dnd5eTools = void 0;
4
+ exports.installToolPacks = installToolPacks;
4
5
  exports.registerToolPacks = registerToolPacks;
5
6
  exports.availableToolPacks = availableToolPacks;
6
- exports.enabledToolPacks = enabledToolPacks;
7
- exports.resetEnabledToolPacks = resetEnabledToolPacks;
8
7
  const dnd5e_1 = require("./dnd5e");
9
8
  Object.defineProperty(exports, "dnd5eTools", { enumerable: true, get: function () { return dnd5e_1.dnd5eTools; } });
10
9
  const logger_1 = require("../../common/logger");
11
10
  const PACKS = {
12
11
  dnd5e: dnd5e_1.dnd5eTools,
13
12
  };
14
- const enabled = new Set();
13
+ function installToolPacks(registry) {
14
+ return registerToolPacks(registry, Object.keys(PACKS).join(','));
15
+ }
15
16
  function registerToolPacks(registry, packList) {
16
17
  const names = (packList || '')
17
18
  .split(',')
@@ -23,12 +24,11 @@ function registerToolPacks(registry, packList) {
23
24
  for (const name of names) {
24
25
  const pack = PACKS[name];
25
26
  if (!pack) {
26
- logger_1.logger.warn(`Unknown tool pack "${name}" in BRIYAH_TOOL_PACKS; available packs: ${Object.keys(PACKS).join(', ')}`);
27
+ logger_1.logger.warn(`Unknown tool pack "${name}"; available packs: ${Object.keys(PACKS).join(', ')}`);
27
28
  continue;
28
29
  }
29
30
  const tools = pack().map((tool) => ({ ...tool, group: name }));
30
31
  registry.registerTools(tools);
31
- enabled.add(name);
32
32
  registered.push(...tools.map((tool) => tool.name));
33
33
  logger_1.logger.log(`Registered tool pack "${name}" with ${tools.length} tools`);
34
34
  }
@@ -37,9 +37,3 @@ function registerToolPacks(registry, packList) {
37
37
  function availableToolPacks() {
38
38
  return Object.keys(PACKS);
39
39
  }
40
- function enabledToolPacks() {
41
- return [...enabled];
42
- }
43
- function resetEnabledToolPacks() {
44
- enabled.clear();
45
- }