briyah 2.0.0 → 2.0.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 (320) hide show
  1. package/README.md +263 -74
  2. package/data/common/config/markup +1 -1
  3. package/data/common/config/model_prices.json +46369 -46361
  4. package/data/common/config/rpg_models.json +60 -0
  5. package/data/common/prompts/narrator/create_chapter.prompt +12 -1
  6. package/data/common/prompts/pdf_converter/convert_pdf_page.prompt +8 -1
  7. package/data/common/prompts/perceive.prompt +287 -291
  8. package/data/packs/acts/agents/character-guide.json +6 -0
  9. package/data/packs/acts/agents/discipleship-mentor.json +6 -0
  10. package/data/packs/acts/agents/mentor-coach.json +6 -0
  11. package/data/packs/acts/agents/student.json +13 -0
  12. package/data/packs/acts/agents/table-moderator.json +6 -0
  13. package/data/packs/acts/artifacts/chapter-01-acts-1.md +405 -0
  14. package/data/packs/acts/artifacts/chapter-02-acts-2.md +443 -0
  15. package/data/packs/acts/artifacts/chapter-03-acts-3.md +409 -0
  16. package/data/packs/acts/artifacts/chapter-04-acts-4.md +438 -0
  17. package/data/packs/acts/artifacts/chapter-05-acts-5.md +434 -0
  18. package/data/packs/acts/artifacts/chapter-06-acts-6.md +441 -0
  19. package/data/packs/acts/artifacts/chapter-07-acts-7.md +472 -0
  20. package/data/packs/acts/artifacts/chapter-08-acts-8.md +512 -0
  21. package/data/packs/acts/artifacts/chapter-09-acts-9.md +346 -0
  22. package/data/packs/acts/artifacts/chapter-10-acts-10.md +367 -0
  23. package/data/packs/acts/artifacts/chapter-11-acts-11.md +391 -0
  24. package/data/packs/acts/artifacts/chapter-12-acts-12.md +390 -0
  25. package/data/packs/acts/artifacts/chapter-13-acts-13.md +388 -0
  26. package/data/packs/acts/artifacts/chapter-14-acts-14.md +466 -0
  27. package/data/packs/acts/artifacts/chapter-15-acts-15.md +413 -0
  28. package/data/packs/acts/artifacts/chapter-16-acts-16.md +585 -0
  29. package/data/packs/acts/artifacts/chapter-17-acts-17.md +428 -0
  30. package/data/packs/acts/artifacts/chapter-18-acts-18.md +486 -0
  31. package/data/packs/acts/artifacts/chapter-19-acts-19.md +461 -0
  32. package/data/packs/acts/artifacts/chapter-20-acts-20.md +389 -0
  33. package/data/packs/acts/artifacts/chapter-21-acts-21.md +452 -0
  34. package/data/packs/acts/artifacts/chapter-22-acts-22.md +424 -0
  35. package/data/packs/acts/artifacts/chapter-23-acts-23.md +395 -0
  36. package/data/packs/acts/artifacts/chapter-24-acts-24.md +446 -0
  37. package/data/packs/acts/artifacts/chapter-25-acts-25.md +391 -0
  38. package/data/packs/acts/artifacts/chapter-26-acts-26.md +431 -0
  39. package/data/packs/acts/artifacts/chapter-27-acts-27.md +530 -0
  40. package/data/packs/acts/artifacts/chapter-28-acts-28.md +1871 -0
  41. package/data/packs/acts/artifacts/chapters.manifest.json +170 -0
  42. package/data/packs/acts/artifacts/character_guide-creation.md +112 -0
  43. package/data/packs/acts/artifacts/discipleship_mentor-procedure.md +154 -0
  44. package/data/packs/acts/artifacts/discipleship_mentor-systems.md +72 -0
  45. package/data/packs/acts/artifacts/manifest.json +197 -0
  46. package/data/packs/acts/artifacts/stage-guide.md +94 -0
  47. package/data/packs/acts/pack.json +6 -0
  48. package/data/packs/acts/prompts/acts_player/defaults_config.json +5 -0
  49. package/data/packs/acts/prompts/acts_player/perceive.json +29 -0
  50. package/data/packs/acts/prompts/acts_player/perceive.prompt +87 -0
  51. package/data/packs/acts/prompts/acts_player/system_instruction.prompt +0 -0
  52. package/data/packs/acts/prompts/acts_room_moderator/defaults_config.json +9 -0
  53. package/data/packs/acts/prompts/acts_room_moderator/moderate.json +34 -0
  54. package/data/packs/acts/prompts/acts_room_moderator/moderate.prompt +70 -0
  55. package/data/packs/acts/prompts/acts_room_moderator/system_instruction.prompt +0 -0
  56. package/data/packs/acts/prompts/character_guide/defaults_config.json +18 -0
  57. package/data/packs/acts/prompts/character_guide/perceive.json +29 -0
  58. package/data/packs/acts/prompts/character_guide/perceive.prompt +140 -0
  59. package/data/packs/acts/prompts/character_guide/system_instruction.prompt +0 -0
  60. package/data/packs/acts/prompts/discipleship_mentor/defaults_config.json +23 -0
  61. package/data/packs/acts/prompts/discipleship_mentor/perceive.json +33 -0
  62. package/data/packs/acts/prompts/discipleship_mentor/perceive.prompt +245 -0
  63. package/data/packs/acts/prompts/discipleship_mentor/system_instruction.prompt +0 -0
  64. package/data/packs/acts/prompts/mentor_coach/defaults_config.json +13 -0
  65. package/data/packs/acts/prompts/mentor_coach/perceive.json +29 -0
  66. package/data/packs/acts/prompts/mentor_coach/perceive.prompt +87 -0
  67. package/data/packs/acts/prompts/mentor_coach/system_instruction.prompt +0 -0
  68. package/data/packs/acts/rooms/session.json +14 -0
  69. package/data/packs/acts/rooms/training.json +58 -0
  70. package/data/packs/dnd5e/artifacts/background-acolyte.md +66 -0
  71. package/data/packs/dnd5e/artifacts/character_creator-basics.md +31 -13
  72. package/data/packs/dnd5e/artifacts/class-barbarian.md +4 -1
  73. package/data/packs/dnd5e/artifacts/class-bard.md +2 -1
  74. package/data/packs/dnd5e/artifacts/class-cleric.md +2 -1
  75. package/data/packs/dnd5e/artifacts/class-druid.md +3 -1
  76. package/data/packs/dnd5e/artifacts/class-fighter.md +3 -1
  77. package/data/packs/dnd5e/artifacts/class-monk.md +2 -1
  78. package/data/packs/dnd5e/artifacts/class-paladin.md +2 -1
  79. package/data/packs/dnd5e/artifacts/class-ranger.md +3 -1
  80. package/data/packs/dnd5e/artifacts/class-rogue.md +3 -1
  81. package/data/packs/dnd5e/artifacts/class-sorcerer.md +2 -1
  82. package/data/packs/dnd5e/artifacts/class-warlock.md +3 -1
  83. package/data/packs/dnd5e/artifacts/class-wizard.md +2 -1
  84. package/data/packs/dnd5e/artifacts/manifest.json +6 -0
  85. package/data/packs/dnd5e/pack.json +1 -1
  86. package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +491 -378
  87. package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +24 -7
  88. package/data/packs/dnd5e/prompts/character_creator/defaults_config.json +2 -13
  89. package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +217 -87
  90. package/data/packs/dnd5e/prompts/dnd_player/defaults_config.json +5 -5
  91. package/data/packs/dnd5e/prompts/dnd_player/perceive.prompt +18 -4
  92. package/data/packs/dnd5e/prompts/dnd_room_moderator/defaults_config.json +9 -9
  93. package/data/packs/dnd5e/prompts/dnd_room_moderator/moderate.prompt +13 -10
  94. package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +32 -30
  95. package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +794 -764
  96. package/data/packs/dnd5e/rooms/campaign.json +15 -0
  97. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +3 -0
  98. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +40 -11
  99. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +1 -0
  100. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +16 -0
  101. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +5 -3
  102. package/dist-sdk/server/src/ai/agent-store.service.js +1 -1
  103. package/dist-sdk/server/src/ai/artifact.service.d.ts +2 -0
  104. package/dist-sdk/server/src/ai/artifact.service.js +6 -0
  105. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +2 -0
  106. package/dist-sdk/server/src/ai/pack-artifacts.js +65 -8
  107. package/dist-sdk/server/src/app/user-service-factory.js +6 -1
  108. package/dist-sdk/server/src/app/user-service-manager.js +1 -1
  109. package/dist-sdk/server/src/app.controller.d.ts +9 -1
  110. package/dist-sdk/server/src/app.controller.js +124 -13
  111. package/dist-sdk/server/src/app.service.d.ts +25 -2
  112. package/dist-sdk/server/src/app.service.js +122 -110
  113. package/dist-sdk/server/src/auth/auth.controller.js +4 -0
  114. package/dist-sdk/server/src/auth/auth.service.d.ts +2 -1
  115. package/dist-sdk/server/src/auth/dto/phone-login.dto.d.ts +2 -1
  116. package/dist-sdk/server/src/config/prompt-resolver.d.ts +2 -0
  117. package/dist-sdk/server/src/config/prompt-resolver.js +14 -7
  118. package/dist-sdk/server/src/documents/pdf-conversion.d.ts +43 -0
  119. package/dist-sdk/server/src/documents/pdf-conversion.js +175 -0
  120. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +2 -1
  121. package/dist-sdk/server/src/packs/pack-instantiation.service.js +16 -5
  122. package/dist-sdk/server/src/room/room-message.service.d.ts +2 -1
  123. package/dist-sdk/server/src/room/room-message.service.js +3 -2
  124. package/dist-sdk/server/src/room/room-store.service.js +5 -1
  125. package/dist-sdk/server/src/room/room.d.ts +15 -2
  126. package/dist-sdk/server/src/room/room.js +86 -25
  127. package/dist-sdk/server/src/rpg/rpg-models.d.ts +9 -0
  128. package/dist-sdk/server/src/rpg/rpg-models.js +128 -0
  129. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +10 -0
  130. package/dist-sdk/server/src/rpg/rpg-roster.js +71 -0
  131. package/dist-sdk/server/src/rpg/rpg.service.d.ts +29 -0
  132. package/dist-sdk/server/src/rpg/rpg.service.js +199 -0
  133. package/dist-sdk/server/src/sdk/index.d.ts +7 -4
  134. package/dist-sdk/server/src/sdk/index.js +8 -1
  135. package/dist-sdk/server/src/story/story.service.d.ts +2 -1
  136. package/dist-sdk/server/src/story/story.service.js +42 -4
  137. package/dist-sdk/server/src/tools/native-tool.types.d.ts +5 -0
  138. package/dist-sdk/server/src/tools/packs/acts/data/cards.d.ts +53 -0
  139. package/dist-sdk/server/src/tools/packs/acts/data/cards.js +54 -0
  140. package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.d.ts +2 -0
  141. package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.js +185 -0
  142. package/dist-sdk/server/src/tools/packs/acts/data/encounters.d.ts +12 -0
  143. package/dist-sdk/server/src/tools/packs/acts/data/encounters.js +102 -0
  144. package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.d.ts +2 -0
  145. package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.js +196 -0
  146. package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.d.ts +2 -0
  147. package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.js +1311 -0
  148. package/dist-sdk/server/src/tools/packs/acts/engine/cards.d.ts +5 -0
  149. package/dist-sdk/server/src/tools/packs/acts/engine/cards.js +27 -0
  150. package/dist-sdk/server/src/tools/packs/acts/engine/challenge.d.ts +37 -0
  151. package/dist-sdk/server/src/tools/packs/acts/engine/challenge.js +120 -0
  152. package/dist-sdk/server/src/tools/packs/acts/engine/dice.d.ts +20 -0
  153. package/dist-sdk/server/src/tools/packs/acts/engine/dice.js +41 -0
  154. package/dist-sdk/server/src/tools/packs/acts/engine/sheet.d.ts +54 -0
  155. package/dist-sdk/server/src/tools/packs/acts/engine/sheet.js +200 -0
  156. package/dist-sdk/server/src/tools/packs/acts/index.d.ts +2 -0
  157. package/dist-sdk/server/src/tools/packs/acts/index.js +24 -0
  158. package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.d.ts +2 -0
  159. package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.js +184 -0
  160. package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.d.ts +2 -0
  161. package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.js +107 -0
  162. package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.d.ts +3 -0
  163. package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.js +146 -0
  164. package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.d.ts +4 -0
  165. package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.js +241 -0
  166. package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.d.ts +3 -0
  167. package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.js +72 -0
  168. package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.d.ts +2 -0
  169. package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.js +75 -0
  170. package/dist-sdk/server/src/tools/packs/acts/tools/shared.d.ts +20 -0
  171. package/dist-sdk/server/src/tools/packs/acts/tools/shared.js +70 -0
  172. package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.d.ts +4 -0
  173. package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.js +215 -0
  174. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +0 -21
  175. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +1 -56
  176. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +10 -0
  177. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +67 -0
  178. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +5 -0
  179. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +7 -1
  180. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +4 -3
  181. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +6 -0
  182. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +92 -0
  183. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +32 -5
  184. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +177 -28
  185. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +1 -13
  186. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +15 -145
  187. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +7 -0
  188. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +11 -0
  189. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +5 -0
  190. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +45 -2
  191. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +3 -0
  192. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +21 -0
  193. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +45 -0
  194. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +6 -4
  195. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +17 -0
  196. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +56 -4
  197. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +3 -0
  198. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +117 -15
  199. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +2 -0
  200. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +96 -0
  201. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +40 -3
  202. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +36 -27
  203. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +7 -4
  204. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +15 -1
  205. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +73 -0
  206. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +40 -12
  207. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +68 -2
  208. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
  209. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +119 -14
  210. package/dist-sdk/server/src/tools/packs/index.d.ts +2 -1
  211. package/dist-sdk/server/src/tools/packs/index.js +4 -1
  212. package/dist-sdk/server/src/tools/shared/coerce.d.ts +13 -0
  213. package/dist-sdk/server/src/tools/shared/coerce.js +147 -0
  214. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +3 -2
  215. package/dist-sdk/server/src/tools/tool-execution.service.js +4 -1
  216. package/dist-sdk/shared/types/app.types.d.ts +73 -0
  217. package/dist-sdk/shared/types/app.types.js +2 -1
  218. package/docs/assets/hierarchy.js +1 -1
  219. package/docs/assets/highlight.css +7 -0
  220. package/docs/assets/navigation.js +1 -1
  221. package/docs/assets/search.js +1 -1
  222. package/docs/classes/Agent.html +73 -73
  223. package/docs/classes/Briyah.html +16 -16
  224. package/docs/classes/BriyahConfigService.html +7 -7
  225. package/docs/classes/NativeToolRegistry.html +10 -10
  226. package/docs/classes/PackInstantiationService.html +20 -9
  227. package/docs/classes/PackService.html +13 -13
  228. package/docs/classes/Room.html +118 -93
  229. package/docs/classes/RoomMessage.html +22 -22
  230. package/docs/enums/MessageAction.html +18 -18
  231. package/docs/functions/actsTools.html +44 -0
  232. package/docs/functions/availableToolPacks.html +4 -4
  233. package/docs/functions/buildMarkdown.html +54 -0
  234. package/docs/functions/dnd5eTools.html +4 -4
  235. package/docs/functions/installToolPacks.html +4 -4
  236. package/docs/functions/pageMarker.html +45 -0
  237. package/docs/functions/registerToolPacks.html +4 -4
  238. package/docs/functions/splitMarkdownIntoPages.html +51 -0
  239. package/docs/functions/stripWrappingFence.html +52 -0
  240. package/docs/hierarchy.html +13 -9
  241. package/docs/index.html +161 -44
  242. package/docs/interfaces/AgentCreationOptions.html +12 -12
  243. package/docs/interfaces/AgentInfo.html +30 -30
  244. package/docs/interfaces/AgentMessagesResponse.html +8 -8
  245. package/docs/interfaces/AppService.html +300 -194
  246. package/docs/interfaces/Artifact.html +9 -9
  247. package/docs/interfaces/ArtifactMetadata.html +13 -13
  248. package/docs/interfaces/ArtifactWriteOptions.html +7 -7
  249. package/docs/interfaces/AttachDocumentResponse.html +6 -6
  250. package/docs/interfaces/BriyahConfigOptions.html +12 -12
  251. package/docs/interfaces/ChapterInfo.html +6 -6
  252. package/docs/interfaces/Character.html +10 -10
  253. package/docs/interfaces/ConversionAgent.html +78 -0
  254. package/docs/interfaces/CreateAgentResponse.html +5 -5
  255. package/docs/interfaces/CreateRoomResponse.html +6 -6
  256. package/docs/interfaces/CreateStoryResponse.html +5 -5
  257. package/docs/interfaces/FileList.html +5 -5
  258. package/docs/interfaces/FileMetadata.html +10 -10
  259. package/docs/interfaces/IConfigService.html +5 -5
  260. package/docs/interfaces/InstantiateModels.html +6 -6
  261. package/docs/interfaces/InstantiateRoomResult.html +7 -7
  262. package/docs/interfaces/LoadedPack.html +16 -16
  263. package/docs/interfaces/LoggingOptions.html +9 -9
  264. package/docs/interfaces/Message.html +9 -9
  265. package/docs/interfaces/ModelChoice.html +7 -7
  266. package/docs/interfaces/ModelInfo.html +8 -8
  267. package/docs/interfaces/NativeToolDefinition.html +10 -10
  268. package/docs/interfaces/PackAgentTemplate.html +9 -9
  269. package/docs/interfaces/PackRoomTemplate.html +11 -11
  270. package/docs/interfaces/PackView.html +20 -20
  271. package/docs/interfaces/PdfConversionOptions.html +102 -0
  272. package/docs/interfaces/PdfConversionResult.html +97 -0
  273. package/docs/interfaces/PdfMarkdownOptions.html +198 -0
  274. package/docs/interfaces/PdfMarkdownResult.html +106 -0
  275. package/docs/interfaces/PdfPageMarkdown.html +94 -0
  276. package/docs/interfaces/PreparedPromptResponse.html +6 -6
  277. package/docs/interfaces/ProcessTextResponse.html +10 -10
  278. package/docs/interfaces/PromptFile.html +7 -7
  279. package/docs/interfaces/PromptFileContent.html +8 -8
  280. package/docs/interfaces/PromptFilesResponse.html +5 -5
  281. package/docs/interfaces/PromptFolder.html +8 -8
  282. package/docs/interfaces/PromptFolderDefaults.html +19 -19
  283. package/docs/interfaces/PromptFolderDefaultsResponse.html +21 -8
  284. package/docs/interfaces/PromptFoldersResponse.html +5 -5
  285. package/docs/interfaces/RoomDetails.html +19 -19
  286. package/docs/interfaces/RoomErrorUpdate.html +82 -0
  287. package/docs/interfaces/RoomInfo.html +10 -10
  288. package/docs/interfaces/RoomMessageUpdate.html +30 -15
  289. package/docs/interfaces/RoomMessagesResponse.html +6 -6
  290. package/docs/interfaces/SendMessageResult.html +6 -6
  291. package/docs/interfaces/StoryErrorEvent.html +8 -8
  292. package/docs/interfaces/StoryIdea.html +8 -8
  293. package/docs/interfaces/StoryInfo.html +28 -28
  294. package/docs/interfaces/StoryIntroduceCharacterEvent.html +7 -7
  295. package/docs/interfaces/StoryProgressChapterEvent.html +6 -6
  296. package/docs/interfaces/StoryState.html +12 -12
  297. package/docs/interfaces/StoryStateEvent.html +7 -7
  298. package/docs/interfaces/ToolArtifact.html +9 -9
  299. package/docs/interfaces/ToolCaller.html +7 -7
  300. package/docs/interfaces/ToolDefinition.html +9 -9
  301. package/docs/interfaces/ToolHelpers.html +17 -8
  302. package/docs/interfaces/ToolPackDocuments.html +100 -0
  303. package/docs/interfaces/ToolParameter.html +8 -8
  304. package/docs/interfaces/ToolRoomAccess.html +14 -14
  305. package/docs/interfaces/ToolSummary.html +8 -8
  306. package/docs/interfaces/ToolsResponse.html +7 -7
  307. package/docs/interfaces/Transaction.html +13 -13
  308. package/docs/interfaces/TransactionHistoryResponse.html +6 -6
  309. package/docs/modules.html +10 -10
  310. package/docs/types/PackOrigin.html +4 -4
  311. package/docs/types/PromptScope.html +4 -4
  312. package/docs/types/RoomTurnMode.html +4 -4
  313. package/docs/types/RoomUpdate.html +36 -0
  314. package/docs/types/RosterOverrides.html +42 -0
  315. package/docs/types/ToolContext.html +4 -4
  316. package/docs/types/ToolRunResult.html +4 -4
  317. package/package.json +1 -1
  318. package/src/tools/packs/dnd5e/README.md +186 -69
  319. package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.d.ts +0 -20
  320. package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.js +0 -112
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_GUIDE_CHARS = exports.BACKGROUND_GUIDE = exports.CLASS_GUIDE = exports.DND5E_PACK = void 0;
4
+ exports.guideNameFromFile = guideNameFromFile;
5
+ exports.listGuides = listGuides;
6
+ exports.resolveGuide = resolveGuide;
7
+ exports.guideArtifactName = guideArtifactName;
8
+ const coerce_1 = require("./coerce");
9
+ const sheet_1 = require("./sheet");
10
+ exports.DND5E_PACK = 'dnd5e';
11
+ exports.CLASS_GUIDE = {
12
+ label: 'class',
13
+ prefix: 'class-',
14
+ artifactPrefix: 'Class: ',
15
+ };
16
+ exports.BACKGROUND_GUIDE = {
17
+ label: 'background',
18
+ prefix: 'background-',
19
+ artifactPrefix: 'Background: ',
20
+ };
21
+ exports.MAX_GUIDE_CHARS = 12_000;
22
+ function guideNameFromFile(kind, fileName) {
23
+ return (0, sheet_1.titleCase)(fileName
24
+ .slice(kind.prefix.length)
25
+ .replace(/\.md$/i, '')
26
+ .replace(/[-_]+/g, ' ')
27
+ .trim());
28
+ }
29
+ function listGuides(kind, files) {
30
+ return files
31
+ .filter((file) => file.toLowerCase().startsWith(kind.prefix))
32
+ .map((fileName) => ({ fileName, name: guideNameFromFile(kind, fileName) }));
33
+ }
34
+ function resolveGuide(wanted, guides) {
35
+ const names = guides.map((guide) => guide.name);
36
+ const matched = (0, coerce_1.matchNames)(wanted, names);
37
+ if (matched.length === 0)
38
+ return {};
39
+ if (matched.length > 1)
40
+ return { ambiguous: matched };
41
+ return { guide: guides.find((guide) => guide.name === matched[0]) };
42
+ }
43
+ function guideArtifactName(kind, name) {
44
+ return `${kind.artifactPrefix}${name}`;
45
+ }
@@ -121,11 +121,13 @@ function applyRace(state, chosen = {}, consumedTools = new Set()) {
121
121
  state.size = race.size;
122
122
  if (race.darkvision)
123
123
  state.darkvision = race.darkvision;
124
- const languages = [...race.languages];
125
- state.languages = [...new Set([...(state.languages || []), ...languages])];
124
+ const native = new Set(race.languages.map((language) => language.toLowerCase()));
125
+ const supplied = (state.languages || []).filter((language) => !native.has(language.toLowerCase()));
126
+ state.languages = [...new Set([...(state.languages || []), ...race.languages])];
126
127
  const languageChoices = (race.languageChoices || 0) + (subrace?.languageChoices || 0);
127
- if (languageChoices > 0) {
128
- result.outstanding.push(`${languageChoices} extra language${languageChoices === 1 ? '' : 's'} of the player's choice`);
128
+ const owedLanguages = languageChoices - supplied.length;
129
+ if (owedLanguages > 0) {
130
+ result.outstanding.push(`${owedLanguages} extra language${owedLanguages === 1 ? '' : 's'} of the player's choice`);
129
131
  }
130
132
  for (const skill of [...(race.skills || []), ...(subrace?.skills || [])]) {
131
133
  if (!state.skillProf.includes(skill))
@@ -29,6 +29,20 @@ export interface AttackEntry {
29
29
  type?: string;
30
30
  range?: string;
31
31
  props?: string[];
32
+ note?: string;
33
+ }
34
+ export interface BoonEntry {
35
+ n: string;
36
+ die: string;
37
+ from?: string;
38
+ }
39
+ export interface PendingRoll {
40
+ kind: string;
41
+ subject?: string;
42
+ total: number;
43
+ dc?: number;
44
+ round?: number;
45
+ natural1?: boolean;
32
46
  }
33
47
  export interface ConditionEntry {
34
48
  n: string;
@@ -67,6 +81,9 @@ export interface SheetState {
67
81
  slots: Record<string, ResourcePool>;
68
82
  uses: Record<string, ResourcePool>;
69
83
  attacks: AttackEntry[];
84
+ boons?: BoonEntry[];
85
+ pendingRoll?: PendingRoll;
86
+ multiattack?: string;
70
87
  spells?: string[];
71
88
  feats?: string[];
72
89
  encumbrance?: boolean;
@@ -52,7 +52,6 @@ exports.titleCase = titleCase;
52
52
  const srd_1 = require("../data/srd");
53
53
  const rules = __importStar(require("./rules"));
54
54
  const races_1 = require("./races");
55
- const backgrounds_1 = require("./backgrounds");
56
55
  const kits_1 = require("./kits");
57
56
  const encumbrance_1 = require("./encumbrance");
58
57
  exports.SHEET_STATE_VERSION = 1;
@@ -182,6 +181,9 @@ function normalizeState(raw) {
182
181
  slots: normalizeResources(raw.slots),
183
182
  uses: normalizeResources(raw.uses),
184
183
  attacks: Array.isArray(raw.attacks) ? raw.attacks : [],
184
+ multiattack: raw.multiattack ? String(raw.multiattack) : undefined,
185
+ boons: normalizeBoons(raw.boons),
186
+ pendingRoll: normalizePendingRoll(raw.pendingRoll),
185
187
  spells: Array.isArray(raw.spells) ? raw.spells : undefined,
186
188
  feats: Array.isArray(raw.feats) && raw.feats.length > 0 ? toStringArray(raw.feats) : undefined,
187
189
  encumbrance: raw.encumbrance === true ? true : undefined,
@@ -204,6 +206,37 @@ function normalizeState(raw) {
204
206
  state.hp.cur = clamp(state.hp.cur, 0, state.hp.max);
205
207
  return state;
206
208
  }
209
+ function normalizeBoons(raw) {
210
+ if (!Array.isArray(raw))
211
+ return undefined;
212
+ const boons = raw
213
+ .filter((entry) => entry && entry.n && entry.die)
214
+ .map((entry) => ({
215
+ n: String(entry.n),
216
+ die: String(entry.die),
217
+ from: entry.from ? String(entry.from) : undefined,
218
+ }));
219
+ return boons.length > 0 ? boons : undefined;
220
+ }
221
+ function normalizePendingRoll(raw) {
222
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
223
+ return undefined;
224
+ if (!Number.isFinite(Number(raw.total)))
225
+ return undefined;
226
+ const pending = {
227
+ kind: String(raw.kind || 'check'),
228
+ total: Number(raw.total),
229
+ };
230
+ if (raw.subject)
231
+ pending.subject = String(raw.subject);
232
+ if (Number.isFinite(Number(raw.dc)))
233
+ pending.dc = Number(raw.dc);
234
+ if (Number.isFinite(Number(raw.round)))
235
+ pending.round = Number(raw.round);
236
+ if (raw.natural1 === true)
237
+ pending.natural1 = true;
238
+ return pending;
239
+ }
207
240
  function normalizeSaveBonus(raw) {
208
241
  if (!raw || typeof raw !== 'object' || Array.isArray(raw))
209
242
  return undefined;
@@ -372,7 +405,10 @@ function renderFoeSummary(state) {
372
405
  return `${attack.n} ${signed(attack.atk)} (${attack.dmg}${type}${range})`;
373
406
  })
374
407
  .join(' · '));
408
+ lines.push(...renderAttackRiders(state));
375
409
  }
410
+ if (state.multiattack)
411
+ lines.push(`**Multiattack:** ${state.multiattack}`);
376
412
  if (state.resist.length > 0)
377
413
  lines.push(`**Resistant to:** ${state.resist.join(', ')}`);
378
414
  if (state.immune.length > 0)
@@ -444,6 +480,18 @@ function renderSummary(state) {
444
480
  return `${attack.n} ${signed(attack.atk)} (${attack.dmg}${type}${range})`;
445
481
  })
446
482
  .join(' · '));
483
+ lines.push(...renderAttackRiders(state));
484
+ }
485
+ if (state.boons?.length) {
486
+ const pending = state.pendingRoll;
487
+ const against = pending && pending.dc !== undefined
488
+ ? ` — ${pending.subject || pending.kind} ${pending.total} vs ${pending.dc}, ${pending.dc - pending.total} short`
489
+ : '';
490
+ lines.push('**Held:** ' +
491
+ state.boons
492
+ .map((boon) => `${boon.n} ${boon.die}${boon.from ? ` from ${boon.from}` : ''}`)
493
+ .join(' · ') +
494
+ against);
447
495
  }
448
496
  const resources = renderResources(state);
449
497
  if (resources)
@@ -459,9 +507,8 @@ function renderSummary(state) {
459
507
  if (traits.length > 0) {
460
508
  lines.push(`**Racial traits:** ${traits.map((trait) => trait.n).join(', ')}`);
461
509
  }
462
- const feature = (0, backgrounds_1.backgroundFeature)(state);
463
- if (feature)
464
- lines.push(`**Background feature:** ${feature.n}`);
510
+ if (state.bg)
511
+ lines.push(`**Background:** ${state.bg}`);
465
512
  if (state.darkvision)
466
513
  lines.push(`**Darkvision:** ${state.darkvision} ft`);
467
514
  if (state.languages?.length)
@@ -496,6 +543,11 @@ function renderSummary(state) {
496
543
  lines.push(`**Vulnerable to:** ${state.vuln.join(', ')}`);
497
544
  return lines.join('\n');
498
545
  }
546
+ function renderAttackRiders(state) {
547
+ return state.attacks
548
+ .filter((attack) => attack.note)
549
+ .map((attack) => `**${attack.n}:** ${attack.note}`);
550
+ }
499
551
  function renderResources(state) {
500
552
  const parts = [];
501
553
  for (const [die, pool] of Object.entries(state.hd)) {
@@ -7,6 +7,7 @@ const dice_tools_1 = require("./tools/dice.tools");
7
7
  const state_tools_1 = require("./tools/state.tools");
8
8
  const sheet_tools_1 = require("./tools/sheet.tools");
9
9
  const world_tools_1 = require("./tools/world.tools");
10
+ const class_tool_1 = require("./tools/class.tool");
10
11
  const encounter_tool_1 = require("./tools/encounter.tool");
11
12
  const monster_tool_1 = require("./tools/monster.tool");
12
13
  const item_tool_1 = require("./tools/item.tool");
@@ -23,7 +24,9 @@ function dnd5eTools() {
23
24
  world_tools_1.conditionsTool,
24
25
  world_tools_1.inventoryTool,
25
26
  world_tools_1.awardXpTool,
27
+ world_tools_1.awardCoinTool,
26
28
  world_tools_1.levelUpTool,
29
+ class_tool_1.classGuideTool,
27
30
  sheet_tools_1.createSheetTool,
28
31
  sheet_tools_1.readSheetTool,
29
32
  sheet_tools_1.patchSheetTool,
@@ -40,6 +40,7 @@ const rules = __importStar(require("../engine/rules"));
40
40
  const sheet_1 = require("../engine/sheet");
41
41
  const character_1 = require("../engine/character");
42
42
  const kits_1 = require("../engine/kits");
43
+ const encounter_1 = require("../engine/encounter");
43
44
  const shared_1 = require("./shared");
44
45
  const BATCH_EXAMPLE = '[{"character":"Thalia","kind":"save","subject":"dex","dc":15},{"character":"Dorn","kind":"save","subject":"dex","dc":15}]';
45
46
  const MAX_BATCH = 12;
@@ -48,7 +49,7 @@ exports.checkTool = {
48
49
  name: 'check',
49
50
  description: 'Make one or more d20 rolls for a character using the modifiers on their sheet. "kind" is skill, ability, save, attack, initiative, tool, or death (a death saving throw). "subject" names what is rolled: a skill (stealth), an ability (dex), a tool (thieves\' tools), or an attack listed on the sheet (Longbow). For a tool check the proficiency bonus is added only if the character actually has that tool proficiency, and doubled for expertise; "ability" says which ability the check uses and defaults to dex, so pass it for anything that is not a Dexterity check — "ability":"int" to identify a poison with a poisoner\'s kit. Give "dc" if you know the target number; omit it to get the raw total and judge for yourself. "mode" is normal, advantage or disadvantage — the character\'s own conditions and exhaustion are applied on top of what you ask for. "bonus" is any situational modifier. For an attack it also rolls damage, doubling the dice on a critical hit. Death saving throws are recorded on the sheet, and three successes or failures are reported. To make several rolls at once — a group saving throw, two attacks in a round — set "batch" to a JSON array of objects using the same keys and leave the other parameters out: ' +
50
51
  BATCH_EXAMPLE +
51
- '. One batched call costs one turn instead of several.',
52
+ '. One batched call costs one turn instead of several. While a fight is running the initiative order is enforced for the attacks of a **monster**: one that has already taken its turn this round cannot attack again, and one without Multiattack gets a single attack per round whether it hits or misses. Rolling for a monster that has not reached its turn yet is allowed, so a group can still be batched into one call — it simply spends the attack they would have made on their own turn. Set "reaction" for an opportunity attack, which happens outside the turn order by definition; a creature gets one reaction per round. Player characters are not budgeted, because two-weapon fighting, Extra Attack and a multi-beam cantrip all give more than one attack roll in a turn. An attack that imposes a saving throw or a condition comes back with that rider in "rider"; adjudicate it before moving on. If the roll misses and the character is holding a die another character gave them — Bardic Inspiration, Bless — it comes back in "boon" with how far short the roll fell; offer it to them before calling the outcome, and spend it with the spend tool.',
52
53
  parameters: [
53
54
  { name: 'character', type: 'string', description: 'Whose sheet to roll from', required: false },
54
55
  {
@@ -82,6 +83,12 @@ exports.checkTool = {
82
83
  description: 'A situational modifier to add on top of the sheet',
83
84
  required: false,
84
85
  },
86
+ {
87
+ name: 'reaction',
88
+ type: 'boolean',
89
+ description: "True when the attack is a reaction, e.g. an opportunity attack, so it may happen outside the creature's turn",
90
+ required: false,
91
+ },
85
92
  {
86
93
  name: 'batch',
87
94
  type: 'string',
@@ -95,10 +102,13 @@ exports.checkTool = {
95
102
  if (requests.length > MAX_BATCH) {
96
103
  throw new Error(`At most ${MAX_BATCH} rolls per call; ${requests.length} were given. Split them across turns.`);
97
104
  }
105
+ const encounter = requests.some((r) => r.kind === 'attack') ? (0, shared_1.readEncounter)(room) : null;
98
106
  const outcomes = [];
99
107
  for (const request of requests) {
100
- outcomes.push(resolveCheck(room, request));
108
+ outcomes.push(resolveCheck(room, request, encounter));
101
109
  }
110
+ if (encounter)
111
+ (0, shared_1.writeEncounter)(room, encounter);
102
112
  if (outcomes.length === 1)
103
113
  return outcomes[0];
104
114
  return {
@@ -127,6 +137,7 @@ function collectRequests(args) {
127
137
  mode: entry.mode !== undefined ? (0, coerce_1.str)(entry.mode, 'mode') : undefined,
128
138
  bonus: entry.bonus !== undefined && entry.bonus !== '' ? (0, coerce_1.int)(entry.bonus, 'bonus', 0) : 0,
129
139
  ability: entry.ability !== undefined ? (0, coerce_1.str)(entry.ability, 'ability') : undefined,
140
+ reaction: entry.reaction === true || entry.reaction === 'true',
130
141
  };
131
142
  });
132
143
  }
@@ -161,12 +172,23 @@ function normalizeMode(raw) {
161
172
  return 'disadvantage';
162
173
  return 'normal';
163
174
  }
164
- function resolveCheck(room, request) {
175
+ function resolveCheck(room, request, encounter) {
165
176
  if (request.kind === 'death') {
166
177
  return resolveDeathSave(room, request);
167
178
  }
168
179
  const sheet = (0, shared_1.loadSheet)(room, request.character);
169
180
  const state = sheet.state;
181
+ const governs = request.kind === 'attack' && !request.reaction ? encounter : null;
182
+ if (governs) {
183
+ const refusal = refuseIllegalAttack(governs, state);
184
+ if (refusal)
185
+ return refusal;
186
+ }
187
+ if (request.reaction && encounter) {
188
+ const refusal = refuseSpentReaction(encounter, state);
189
+ if (refusal)
190
+ return refusal;
191
+ }
170
192
  const resolved = resolveModifier(state, request);
171
193
  const asked = normalizeMode(request.mode);
172
194
  const kind = request.kind === 'attack' ? 'attack' : request.kind === 'save' ? 'save' : 'check';
@@ -217,6 +239,10 @@ function resolveCheck(room, request) {
217
239
  detail: '',
218
240
  };
219
241
  if (request.kind === 'attack') {
242
+ if (governs)
243
+ (0, encounter_1.recordAttack)(governs, state.name);
244
+ if (request.reaction && encounter)
245
+ (0, encounter_1.recordAttack)(encounter, reactionKey(state.name));
220
246
  if (roll.natural20)
221
247
  outcome.critical = 'hit';
222
248
  if (roll.natural1)
@@ -226,7 +252,9 @@ function resolveCheck(room, request) {
226
252
  outcome.passed = roll.natural20 ? true : roll.natural1 ? false : roll.total >= request.dc;
227
253
  }
228
254
  if (resolved.attack && outcome.passed !== false) {
229
- outcome.damage = rollDamage(resolved.attack.dmg, resolved.attack.type, outcome.critical === 'hit');
255
+ outcome.damage = (0, dice_1.rollDamage)(resolved.attack.dmg, resolved.attack.type, outcome.critical === 'hit');
256
+ if (resolved.attack.note)
257
+ outcome.rider = resolved.attack.note;
230
258
  }
231
259
  }
232
260
  else if (request.dc !== undefined) {
@@ -234,6 +262,10 @@ function resolveCheck(room, request) {
234
262
  outcome.passed = roll.total >= request.dc;
235
263
  }
236
264
  outcome.detail = describeOutcome(outcome, roll.kept[0]);
265
+ outcome.boon = offerHeldDie(state, outcome);
266
+ if ((state.boons || []).length > 0) {
267
+ recordPendingRoll(room, state, request, outcome, encounter);
268
+ }
237
269
  if (resolved.note)
238
270
  outcome.note = resolved.note;
239
271
  if (sheet.warnings.length > 0) {
@@ -248,6 +280,86 @@ function resolveCheck(room, request) {
248
280
  }
249
281
  return outcome;
250
282
  }
283
+ function refuseIllegalAttack(encounter, state) {
284
+ if (!state.foe)
285
+ return undefined;
286
+ const standing = (0, encounter_1.turnStanding)(encounter, state.name);
287
+ if (standing === 'absent')
288
+ return undefined;
289
+ const up = (0, encounter_1.currentCombatant)(encounter)?.name;
290
+ if (standing === 'past') {
291
+ return {
292
+ applied: false,
293
+ violation: 'turn_passed',
294
+ message: `${state.name} has already taken their turn this round. It is ${up}'s turn in round ${encounter.round}.`,
295
+ rule: 'A creature acts once per round, on its own initiative count.',
296
+ options: [
297
+ `Roll for ${up} instead`,
298
+ 'Call encounter with no action to see the round and the order',
299
+ ],
300
+ };
301
+ }
302
+ const made = (0, encounter_1.attacksThisRound)(encounter, state.name);
303
+ if (made > 0 && !state.multiattack) {
304
+ return {
305
+ applied: false,
306
+ violation: 'attack_spent',
307
+ message: `${state.name} has already attacked in round ${encounter.round} and has no Multiattack, so they cannot attack again until round ${encounter.round + 1}.`,
308
+ rule: 'The Attack action is one attack unless the creature has Multiattack or a feature granting an extra attack.',
309
+ options: [
310
+ `End ${state.name}'s turn with encounter action "next"`,
311
+ 'Roll a different creature\'s attack',
312
+ `If ${state.name} really does have Multiattack, add it with patch_sheet and roll again`,
313
+ ],
314
+ };
315
+ }
316
+ return undefined;
317
+ }
318
+ function recordPendingRoll(room, state, request, outcome, encounter) {
319
+ const pending = { kind: request.kind, total: outcome.total };
320
+ if (outcome.what)
321
+ pending.subject = outcome.what;
322
+ if (outcome.dc !== undefined)
323
+ pending.dc = outcome.dc;
324
+ if (encounter)
325
+ pending.round = encounter.round;
326
+ if (outcome.critical === 'miss')
327
+ pending.natural1 = true;
328
+ (0, shared_1.mutateSheet)(room, state.name, (sheet) => {
329
+ sheet.state.pendingRoll = pending;
330
+ return { ok: true, state: sheet.state, summary: 'roll recorded' };
331
+ });
332
+ }
333
+ function offerHeldDie(state, outcome) {
334
+ if (outcome.passed !== false || outcome.dc === undefined)
335
+ return undefined;
336
+ if (outcome.critical === 'miss')
337
+ return undefined;
338
+ const held = state.boons || [];
339
+ if (held.length === 0)
340
+ return undefined;
341
+ const short = outcome.dc - outcome.total;
342
+ const usable = held.find((boon) => (Number(/d(\d+)/.exec(boon.die)?.[1]) || 0) >= short);
343
+ if (!usable)
344
+ return undefined;
345
+ return { name: usable.n, die: usable.die, from: usable.from, short };
346
+ }
347
+ function reactionKey(name) {
348
+ return `${name} (reaction)`;
349
+ }
350
+ function refuseSpentReaction(encounter, state) {
351
+ if (!state.foe)
352
+ return undefined;
353
+ if ((0, encounter_1.attacksThisRound)(encounter, reactionKey(state.name)) === 0)
354
+ return undefined;
355
+ return {
356
+ applied: false,
357
+ violation: 'reaction_spent',
358
+ message: `${state.name} has already used its reaction in round ${encounter.round}.`,
359
+ rule: 'A creature gets one reaction per round, and regains it at the start of its turn.',
360
+ options: [`Wait until round ${encounter.round + 1}`, "Roll a different creature's attack"],
361
+ };
362
+ }
251
363
  function toolAbility(request) {
252
364
  const named = (request.ability || '').trim();
253
365
  if (!named)
@@ -275,7 +387,7 @@ function resolveModifier(state, request) {
275
387
  return {
276
388
  modifier: attack.atk,
277
389
  label: attack.n,
278
- attack: { dmg: attack.dmg, type: attack.type },
390
+ attack: { dmg: attack.dmg, type: attack.type, note: attack.note },
279
391
  };
280
392
  }
281
393
  if (request.kind === 'tool') {
@@ -317,16 +429,6 @@ function resolveModifier(state, request) {
317
429
  label: `${ability.toUpperCase()} check`,
318
430
  };
319
431
  }
320
- function rollDamage(expression, type, critical) {
321
- const toRoll = critical ? `${expression} crit` : expression;
322
- const roll = (0, dice_1.rollOne)(toRoll, dice_1.defaultRng);
323
- return {
324
- expression: toRoll,
325
- total: Math.max(roll.total, 0),
326
- type,
327
- detail: (0, dice_1.describeRoll)(roll),
328
- };
329
- }
330
432
  function describeOutcome(outcome, naturalRoll) {
331
433
  const parts = [
332
434
  `${outcome.character} ${outcome.what}: ${naturalRoll} ${(0, sheet_1.signed)(outcome.modifier)} = ${outcome.total}`,
@@ -0,0 +1,2 @@
1
+ import { NativeToolDefinition } from '../../../native-tool.types';
2
+ export declare const classGuideTool: NativeToolDefinition;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.classGuideTool = void 0;
4
+ const coerce_1 = require("../engine/coerce");
5
+ const guides_1 = require("../engine/guides");
6
+ const shared_1 = require("./shared");
7
+ exports.classGuideTool = {
8
+ name: 'class_guide',
9
+ description: 'The classes this table allows, and the rules for playing one. Set "class" to "list" to get every class a character may be built as — that list is the authority, and a class not on it has no rules here. Set "class" to a class name to get that class\'s proficiencies, starting equipment, features by level, and the resource counts no other tool models: how many cantrips and spells are known, rage uses, ki points, sneak attack dice. Add "players" — a semicolon-separated list of agent nicknames — once a player has settled on that class, and the whole document becomes a permanent document those agents read on every turn, so the player knows how to play their own class for the rest of the campaign. Without "players" nothing is shared and the document is simply returned, which is what you want while a player is still choosing. Examples: class = "list"; class = "wizard"; class = "wizard", players = "Lyra".',
10
+ parameters: [
11
+ {
12
+ name: 'class',
13
+ type: 'string',
14
+ description: 'The class to read, or "list" for every class this table allows',
15
+ required: true,
16
+ },
17
+ {
18
+ name: 'players',
19
+ type: 'string',
20
+ description: 'Semicolon-separated nicknames of the agents playing this class, e.g. "Lyra; Sable". Omit while a player is still choosing.',
21
+ required: false,
22
+ },
23
+ ],
24
+ async handler(args, helpers) {
25
+ const documents = (0, shared_1.requirePackDocuments)(helpers);
26
+ const wanted = (0, coerce_1.str)(args.class, 'class');
27
+ if (!wanted)
28
+ throw new Error('Name a class, or "list" to see which ones this table allows.');
29
+ const guides = (0, guides_1.listGuides)(guides_1.CLASS_GUIDE, documents.list(guides_1.DND5E_PACK, guides_1.CLASS_GUIDE.prefix));
30
+ if (guides.length === 0) {
31
+ throw new Error(`No class documents are installed. The operator adds one by putting a "${guides_1.CLASS_GUIDE.prefix}<class>.md" file in the pack's artifacts directory.`);
32
+ }
33
+ const names = guides.map((guide) => guide.name);
34
+ if (['list', 'all', 'classes'].includes(wanted.toLowerCase())) {
35
+ return {
36
+ classes: names,
37
+ count: names.length,
38
+ note: 'These are the only classes this table has rules for. Offer a player one of these; anything else has no features, no starting equipment and no resource counts, so it cannot be built correctly.',
39
+ };
40
+ }
41
+ const resolved = (0, guides_1.resolveGuide)(wanted, guides);
42
+ if (resolved.ambiguous) {
43
+ return {
44
+ found: false,
45
+ class: wanted,
46
+ ambiguous: resolved.ambiguous,
47
+ message: `"${wanted}" matches ${resolved.ambiguous.length} classes. Ask again with the full name.`,
48
+ note: 'Do not pick one. A character built as the wrong class is wrong in every feature it has.',
49
+ };
50
+ }
51
+ if (!resolved.guide) {
52
+ return {
53
+ found: false,
54
+ class: wanted,
55
+ message: `This table has no rules for a "${wanted}".`,
56
+ classes: names,
57
+ options: [
58
+ 'Offer the player one of the classes listed above',
59
+ `Ask the operator to add a "${guides_1.CLASS_GUIDE.prefix}${wanted.toLowerCase().replace(/\s+/g, '-')}.md" document to the pack, if the table means to play it`,
60
+ ],
61
+ note: 'Do not build it from memory. A class you invent has resource counts nobody can check.',
62
+ };
63
+ }
64
+ const { name: className, fileName } = resolved.guide;
65
+ const body = documents.read(guides_1.DND5E_PACK, fileName);
66
+ if (!body || !body.trim()) {
67
+ throw new Error(`The document for the ${className} class ("${fileName}") is missing or empty. The operator restores it in the pack's artifacts directory.`);
68
+ }
69
+ const players = (0, coerce_1.list)(args.players);
70
+ const shared = players.length > 0
71
+ ? (0, shared_1.shareGuide)((0, shared_1.requireRoom)(helpers), guides_1.CLASS_GUIDE, className, body, players)
72
+ : undefined;
73
+ const clipped = body.length > guides_1.MAX_GUIDE_CHARS;
74
+ return {
75
+ found: true,
76
+ class: className,
77
+ document: clipped ? `${body.slice(0, guides_1.MAX_GUIDE_CHARS)}\n\n[...]` : body,
78
+ truncated: clipped || undefined,
79
+ shared: shared
80
+ ? {
81
+ artifact: shared.artifactName,
82
+ viewers: shared.viewers,
83
+ unknownPlayers: shared.unknown.length > 0 ? shared.unknown : undefined,
84
+ }
85
+ : undefined,
86
+ note: shared
87
+ ? `${shared.viewers.join(', ')} now read "${shared.artifactName}" on every turn, so nobody has to be told these rules again.` +
88
+ (shared.unknown.length > 0
89
+ ? ` No agent here is called ${shared.unknown.join(' or ')} — call this again with the right nickname, or those players never get it.`
90
+ : '')
91
+ : clipped
92
+ ? `Only the first ${guides_1.MAX_GUIDE_CHARS} characters are shown. Pass "players" to share the whole document as "${(0, guides_1.guideArtifactName)(guides_1.CLASS_GUIDE, className)}", which carries all of it.`
93
+ : 'Nothing was shared. Once the player settles on this class, call again with "players" so they carry these rules for the rest of the campaign.',
94
+ };
95
+ },
96
+ };
@@ -9,7 +9,7 @@ const shared_1 = require("./shared");
9
9
  const coerce_2 = require("../engine/coerce");
10
10
  exports.rollDiceTool = {
11
11
  name: 'roll_dice',
12
- description: 'Roll dice and get the totals. "expressions" is a semicolon-separated list, each optionally labelled with "label=". Supports NdM with + and - modifiers, kh/kl (keep the highest/lowest N, default 1), dh/dl (drop), adv/dis (roll a d20 twice and take the higher/lower), r1 (reroll each 1 once), min2 (treat dice below 2 as 2), crit (double the dice), and xN (repeat the roll N times). Returns each label with its individual dice, any dropped dice, and the total. At most 20 expressions and 100 dice per call. Examples: "attack=1d20+5 adv; damage=2d6+3" — "hp=4d6kh3 x6" — "1d20".',
12
+ description: 'Roll dice and get the totals. "expressions" is a semicolon-separated list, each optionally labelled with "label=". Supports NdM with + and - modifiers, kh/kl (keep the highest/lowest N, default 1), dh/dl (drop), adv/dis (roll a d20 twice and take the higher/lower), r1 (reroll each 1 once), min2 (treat dice below 2 as 2), crit (double the dice), and xN (repeat the roll N times). Returns each label with its individual dice, any dropped dice, and the total. At most 20 expressions and 100 dice per call. Examples: "attack=1d20+5 adv; damage=2d6+3" — "hp=4d6kh3 x6" — "1d20". This is for rolls that are not a tracked combatant\'s attack: a breath weapon\'s damage, hit points, a saving throw you are adjudicating yourself. A placed combatant\'s attack and its damage go through check instead, which is the only thing that compares the roll to the target\'s armour class — rolling the damage here would skip the attack roll entirely, and is refused while a fight is running.',
13
13
  parameters: [
14
14
  {
15
15
  name: 'expressions',
@@ -24,11 +24,17 @@ exports.rollDiceTool = {
24
24
  required: false,
25
25
  },
26
26
  ],
27
- async handler(args) {
27
+ async handler(args, helpers) {
28
28
  const expressions = (0, coerce_1.str)(args.expressions, 'expressions');
29
+ const reason = args.reason ? (0, coerce_1.str)(args.reason, 'reason') : undefined;
30
+ const refusal = helpers?.room
31
+ ? refuseCombatantAttack(helpers.room, `${expressions} ${reason || ''}`)
32
+ : undefined;
33
+ if (refusal)
34
+ return refusal;
29
35
  const results = (0, dice_1.rollExpressions)(expressions);
30
36
  return {
31
- reason: args.reason ? (0, coerce_1.str)(args.reason, 'reason') : undefined,
37
+ reason,
32
38
  rolls: results.map((result) => ({
33
39
  label: result.label,
34
40
  dice: result.dice.map((d) => d.value),
@@ -42,6 +48,37 @@ exports.rollDiceTool = {
42
48
  };
43
49
  },
44
50
  };
51
+ function refuseCombatantAttack(room, text) {
52
+ const encounter = (0, shared_1.readEncounter)(room);
53
+ if (!encounter)
54
+ return undefined;
55
+ const haystack = text.toLowerCase();
56
+ for (const combatant of encounter.order) {
57
+ if (!haystack.includes(combatant.name.toLowerCase()))
58
+ continue;
59
+ let attacks;
60
+ try {
61
+ attacks = (0, shared_1.loadSheet)(room, combatant.name).state.attacks.map((a) => a.n);
62
+ }
63
+ catch {
64
+ continue;
65
+ }
66
+ const named = attacks.find((attack) => haystack.includes(attack.toLowerCase()));
67
+ if (!named)
68
+ continue;
69
+ return {
70
+ applied: false,
71
+ violation: 'attack_needs_check',
72
+ message: `${combatant.name}'s ${named} is an attack and has to go through check, which rolls it against the target's armour class and rolls the damage on a hit. Rolling the damage here skips the attack roll.`,
73
+ rule: 'An attack hits only if the attack roll meets or beats the target\'s AC. A hit on an unconscious target is an automatic critical, not an automatic hit.',
74
+ options: [
75
+ `check with {"character": "${combatant.name}", "kind": "attack", "subject": "${named}", "dc": <the target's AC>}`,
76
+ 'If this is not an attack roll, say what it is in "reason" without naming the attack',
77
+ ],
78
+ };
79
+ }
80
+ return undefined;
81
+ }
45
82
  exports.rollInitiativeTool = {
46
83
  name: 'roll_initiative',
47
84
  description: 'Roll initiative for a whole encounter in one call and get the turn order. "combatants" is a semicolon-separated list: a bare Name for a character who has a sheet (their modifier is read from it), or Name+N / Name-N for monsters and NPCs. Ties break toward the higher modifier, then by the order given. The order is also written to the "Encounter" artifact so everyone can see whose turn it is. Example: "Thalia; Dorn; Goblin A+2; Goblin B+2; Hobgoblin Captain+1".',