briyah 2.0.2 → 2.0.4

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 (477) hide show
  1. package/LICENSE +216 -0
  2. package/README.md +43 -7
  3. package/data/common/config/LICENSE-model-prices.md +65 -0
  4. package/data/common/config/markup +1 -1
  5. package/data/common/config/model_prices.json +47443 -46295
  6. package/data/common/prompts/narrator/create_story.prompt +2 -0
  7. package/data/packs/dnd5e/agents/player.json +11 -11
  8. package/data/packs/dnd5e/prompts/character_creator/defaults_config.json +21 -20
  9. package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +19 -12
  10. package/data/packs/dnd5e/prompts/dnd_player/perceive.prompt +10 -6
  11. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
  12. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
  13. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
  14. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
  15. package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
  16. package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
  17. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
  18. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
  19. package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
  20. package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
  21. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
  22. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
  23. package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
  24. package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
  25. package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
  26. package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
  27. package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
  28. package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
  29. package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
  30. package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
  31. package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
  32. package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
  33. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
  34. package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
  35. package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
  36. package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
  37. package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
  38. package/dist-sdk/server/src/ai/agent-factory.js +20 -0
  39. package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
  40. package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
  41. package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
  42. package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
  43. package/dist-sdk/server/src/ai/agent.d.ts +196 -0
  44. package/dist-sdk/server/src/ai/agent.js +224 -11
  45. package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
  46. package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
  47. package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
  48. package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
  49. package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
  50. package/dist-sdk/server/src/ai/artifact.service.js +148 -3
  51. package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
  52. package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
  53. package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
  54. package/dist-sdk/server/src/ai/model_prices.js +91 -5
  55. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
  56. package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
  57. package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
  58. package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
  59. package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
  60. package/dist-sdk/server/src/app/balance-message.service.js +24 -0
  61. package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
  62. package/dist-sdk/server/src/app/balance.module.js +4 -0
  63. package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
  64. package/dist-sdk/server/src/app/balance.service.js +54 -0
  65. package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
  66. package/dist-sdk/server/src/app/stripe.controller.js +35 -0
  67. package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
  68. package/dist-sdk/server/src/app/stripe.service.js +62 -0
  69. package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
  70. package/dist-sdk/server/src/app/transaction.service.js +36 -0
  71. package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
  72. package/dist-sdk/server/src/app/user-service-factory.js +38 -1
  73. package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
  74. package/dist-sdk/server/src/app/user-service-manager.js +43 -0
  75. package/dist-sdk/server/src/app.controller.d.ts +87 -0
  76. package/dist-sdk/server/src/app.controller.js +272 -12
  77. package/dist-sdk/server/src/app.module.js +28 -6
  78. package/dist-sdk/server/src/app.service.d.ts +1662 -0
  79. package/dist-sdk/server/src/app.service.js +1862 -6
  80. package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
  81. package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
  82. package/dist-sdk/server/src/auth/auth.controller.js +46 -0
  83. package/dist-sdk/server/src/auth/auth.module.js +3 -2
  84. package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
  85. package/dist-sdk/server/src/auth/auth.service.js +39 -3
  86. package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
  87. package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
  88. package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
  89. package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
  90. package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
  91. package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
  92. package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
  93. package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
  94. package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
  95. package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
  96. package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
  97. package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
  98. package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
  99. package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
  100. package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
  101. package/dist-sdk/server/src/auth/session.guard.js +8 -0
  102. package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
  103. package/dist-sdk/server/src/auth/twilio.service.js +30 -4
  104. package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
  105. package/dist-sdk/server/src/auth/users.service.js +42 -0
  106. package/dist-sdk/server/src/common/errors.d.ts +20 -0
  107. package/dist-sdk/server/src/common/errors.js +21 -0
  108. package/dist-sdk/server/src/config/env-config.d.ts +7 -0
  109. package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
  110. package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
  111. package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
  112. package/dist-sdk/server/src/config/user-config.service.js +57 -0
  113. package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
  114. package/dist-sdk/server/src/config/user-paths.service.js +67 -0
  115. package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
  116. package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
  117. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
  118. package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
  119. package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
  120. package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
  121. package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
  122. package/dist-sdk/server/src/packs/pack.service.js +98 -1
  123. package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
  124. package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
  125. package/dist-sdk/server/src/room/artifact.d.ts +18 -0
  126. package/dist-sdk/server/src/room/message.d.ts +64 -0
  127. package/dist-sdk/server/src/room/message.js +77 -2
  128. package/dist-sdk/server/src/room/nickname.d.ts +27 -0
  129. package/dist-sdk/server/src/room/nickname.js +41 -0
  130. package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
  131. package/dist-sdk/server/src/room/room-config.d.ts +26 -0
  132. package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
  133. package/dist-sdk/server/src/room/room-factory.js +14 -0
  134. package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
  135. package/dist-sdk/server/src/room/room-message.service.js +28 -0
  136. package/dist-sdk/server/src/room/room-store.service.d.ts +177 -0
  137. package/dist-sdk/server/src/room/room-store.service.js +242 -5
  138. package/dist-sdk/server/src/room/room.d.ts +906 -1
  139. package/dist-sdk/server/src/room/room.js +1525 -34
  140. package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
  141. package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
  142. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +38 -3
  143. package/dist-sdk/server/src/rpg/rpg-roster.js +49 -49
  144. package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
  145. package/dist-sdk/server/src/rpg/rpg.service.js +108 -5
  146. package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
  147. package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
  148. package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
  149. package/dist-sdk/server/src/sdk/briyah.js +285 -7
  150. package/dist-sdk/server/src/sdk/index.d.ts +0 -1
  151. package/dist-sdk/server/src/sdk/index.js +24 -3
  152. package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
  153. package/dist-sdk/server/src/shared/shared.module.js +13 -5
  154. package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
  155. package/dist-sdk/server/src/story/story-message.service.js +43 -0
  156. package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
  157. package/dist-sdk/server/src/story/story-progress.service.js +23 -0
  158. package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
  159. package/dist-sdk/server/src/story/story-store.service.js +136 -1
  160. package/dist-sdk/server/src/story/story.service.d.ts +398 -0
  161. package/dist-sdk/server/src/story/story.service.js +829 -25
  162. package/dist-sdk/server/src/tools/core/index.d.ts +25 -0
  163. package/dist-sdk/server/src/tools/core/index.js +31 -0
  164. package/dist-sdk/server/src/tools/core/rename.tool.d.ts +10 -0
  165. package/dist-sdk/server/src/tools/core/rename.tool.js +72 -0
  166. package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
  167. package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
  168. package/dist-sdk/server/src/tools/native-tool.types.d.ts +186 -0
  169. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
  170. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
  171. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
  172. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
  173. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
  174. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
  175. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
  176. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
  177. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
  178. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
  179. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
  180. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
  181. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
  182. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
  183. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
  184. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
  185. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
  186. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
  187. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
  188. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
  189. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
  190. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
  191. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
  192. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
  193. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
  194. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
  195. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
  196. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
  197. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
  198. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
  199. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
  200. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
  201. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
  202. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
  203. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
  204. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
  205. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
  206. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
  207. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
  208. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
  209. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
  210. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
  211. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
  212. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
  213. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
  214. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
  215. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
  216. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
  217. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
  218. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
  219. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
  220. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
  221. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
  222. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
  223. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
  224. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
  225. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
  226. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
  227. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
  228. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
  229. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
  230. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
  231. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
  232. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
  233. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
  234. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
  235. package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
  236. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
  237. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
  238. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
  239. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
  240. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
  241. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
  242. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
  243. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
  244. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
  245. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
  246. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
  247. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
  248. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
  249. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
  250. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
  251. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
  252. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +125 -1
  253. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
  254. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
  255. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
  256. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
  257. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
  258. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
  259. package/dist-sdk/server/src/tools/packs/index.d.ts +52 -2
  260. package/dist-sdk/server/src/tools/packs/index.js +83 -9
  261. package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
  262. package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
  263. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
  264. package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
  265. package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
  266. package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
  267. package/dist-sdk/shared/types/app.types.d.ts +285 -14
  268. package/dist-sdk/shared/types/app.types.js +3 -0
  269. package/package.json +167 -139
  270. package/data/common/config/random_words.txt +0 -2241
  271. package/data/common/story_ideas/biblical.json +0 -122
  272. package/data/common/story_ideas/fantasy.json +0 -82
  273. package/data/common/story_ideas/historical_fiction.json +0 -82
  274. package/data/common/story_ideas/science_fiction.json +0 -82
  275. package/data/packs/acts/agents/character-guide.json +0 -6
  276. package/data/packs/acts/agents/discipleship-mentor.json +0 -6
  277. package/data/packs/acts/agents/mentor-coach.json +0 -6
  278. package/data/packs/acts/agents/student.json +0 -13
  279. package/data/packs/acts/agents/table-moderator.json +0 -6
  280. package/data/packs/acts/artifacts/chapter-01-acts-1.md +0 -405
  281. package/data/packs/acts/artifacts/chapter-02-acts-2.md +0 -443
  282. package/data/packs/acts/artifacts/chapter-03-acts-3.md +0 -409
  283. package/data/packs/acts/artifacts/chapter-04-acts-4.md +0 -438
  284. package/data/packs/acts/artifacts/chapter-05-acts-5.md +0 -434
  285. package/data/packs/acts/artifacts/chapter-06-acts-6.md +0 -441
  286. package/data/packs/acts/artifacts/chapter-07-acts-7.md +0 -472
  287. package/data/packs/acts/artifacts/chapter-08-acts-8.md +0 -512
  288. package/data/packs/acts/artifacts/chapter-09-acts-9.md +0 -346
  289. package/data/packs/acts/artifacts/chapter-10-acts-10.md +0 -367
  290. package/data/packs/acts/artifacts/chapter-11-acts-11.md +0 -391
  291. package/data/packs/acts/artifacts/chapter-12-acts-12.md +0 -390
  292. package/data/packs/acts/artifacts/chapter-13-acts-13.md +0 -388
  293. package/data/packs/acts/artifacts/chapter-14-acts-14.md +0 -466
  294. package/data/packs/acts/artifacts/chapter-15-acts-15.md +0 -413
  295. package/data/packs/acts/artifacts/chapter-16-acts-16.md +0 -585
  296. package/data/packs/acts/artifacts/chapter-17-acts-17.md +0 -428
  297. package/data/packs/acts/artifacts/chapter-18-acts-18.md +0 -486
  298. package/data/packs/acts/artifacts/chapter-19-acts-19.md +0 -461
  299. package/data/packs/acts/artifacts/chapter-20-acts-20.md +0 -389
  300. package/data/packs/acts/artifacts/chapter-21-acts-21.md +0 -452
  301. package/data/packs/acts/artifacts/chapter-22-acts-22.md +0 -424
  302. package/data/packs/acts/artifacts/chapter-23-acts-23.md +0 -395
  303. package/data/packs/acts/artifacts/chapter-24-acts-24.md +0 -446
  304. package/data/packs/acts/artifacts/chapter-25-acts-25.md +0 -391
  305. package/data/packs/acts/artifacts/chapter-26-acts-26.md +0 -431
  306. package/data/packs/acts/artifacts/chapter-27-acts-27.md +0 -530
  307. package/data/packs/acts/artifacts/chapter-28-acts-28.md +0 -1871
  308. package/data/packs/acts/artifacts/chapters.manifest.json +0 -170
  309. package/data/packs/acts/artifacts/character_guide-creation.md +0 -112
  310. package/data/packs/acts/artifacts/discipleship_mentor-procedure.md +0 -154
  311. package/data/packs/acts/artifacts/discipleship_mentor-systems.md +0 -72
  312. package/data/packs/acts/artifacts/manifest.json +0 -197
  313. package/data/packs/acts/artifacts/stage-guide.md +0 -94
  314. package/data/packs/acts/pack.json +0 -6
  315. package/data/packs/acts/prompts/acts_player/defaults_config.json +0 -5
  316. package/data/packs/acts/prompts/acts_player/perceive.json +0 -29
  317. package/data/packs/acts/prompts/acts_player/perceive.prompt +0 -87
  318. package/data/packs/acts/prompts/acts_player/system_instruction.prompt +0 -0
  319. package/data/packs/acts/prompts/acts_room_moderator/defaults_config.json +0 -9
  320. package/data/packs/acts/prompts/acts_room_moderator/moderate.json +0 -34
  321. package/data/packs/acts/prompts/acts_room_moderator/moderate.prompt +0 -70
  322. package/data/packs/acts/prompts/acts_room_moderator/system_instruction.prompt +0 -0
  323. package/data/packs/acts/prompts/character_guide/defaults_config.json +0 -18
  324. package/data/packs/acts/prompts/character_guide/perceive.json +0 -29
  325. package/data/packs/acts/prompts/character_guide/perceive.prompt +0 -140
  326. package/data/packs/acts/prompts/character_guide/system_instruction.prompt +0 -0
  327. package/data/packs/acts/prompts/discipleship_mentor/defaults_config.json +0 -23
  328. package/data/packs/acts/prompts/discipleship_mentor/perceive.json +0 -33
  329. package/data/packs/acts/prompts/discipleship_mentor/perceive.prompt +0 -245
  330. package/data/packs/acts/prompts/discipleship_mentor/system_instruction.prompt +0 -0
  331. package/data/packs/acts/prompts/mentor_coach/defaults_config.json +0 -13
  332. package/data/packs/acts/prompts/mentor_coach/perceive.json +0 -29
  333. package/data/packs/acts/prompts/mentor_coach/perceive.prompt +0 -87
  334. package/data/packs/acts/prompts/mentor_coach/system_instruction.prompt +0 -0
  335. package/data/packs/acts/rooms/session.json +0 -14
  336. package/data/packs/acts/rooms/training.json +0 -58
  337. package/dist-sdk/server/src/tools/packs/acts/data/cards.d.ts +0 -53
  338. package/dist-sdk/server/src/tools/packs/acts/data/cards.js +0 -54
  339. package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.d.ts +0 -2
  340. package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.js +0 -185
  341. package/dist-sdk/server/src/tools/packs/acts/data/encounters.d.ts +0 -12
  342. package/dist-sdk/server/src/tools/packs/acts/data/encounters.js +0 -102
  343. package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.d.ts +0 -2
  344. package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.js +0 -196
  345. package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.d.ts +0 -2
  346. package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.js +0 -1311
  347. package/dist-sdk/server/src/tools/packs/acts/engine/cards.d.ts +0 -5
  348. package/dist-sdk/server/src/tools/packs/acts/engine/cards.js +0 -27
  349. package/dist-sdk/server/src/tools/packs/acts/engine/challenge.d.ts +0 -37
  350. package/dist-sdk/server/src/tools/packs/acts/engine/challenge.js +0 -120
  351. package/dist-sdk/server/src/tools/packs/acts/engine/dice.d.ts +0 -20
  352. package/dist-sdk/server/src/tools/packs/acts/engine/dice.js +0 -41
  353. package/dist-sdk/server/src/tools/packs/acts/engine/sheet.d.ts +0 -54
  354. package/dist-sdk/server/src/tools/packs/acts/engine/sheet.js +0 -200
  355. package/dist-sdk/server/src/tools/packs/acts/index.d.ts +0 -2
  356. package/dist-sdk/server/src/tools/packs/acts/index.js +0 -24
  357. package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.d.ts +0 -2
  358. package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.js +0 -184
  359. package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.d.ts +0 -2
  360. package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.js +0 -107
  361. package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.d.ts +0 -3
  362. package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.js +0 -146
  363. package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.d.ts +0 -4
  364. package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.js +0 -241
  365. package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.d.ts +0 -3
  366. package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.js +0 -72
  367. package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.d.ts +0 -2
  368. package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.js +0 -75
  369. package/dist-sdk/server/src/tools/packs/acts/tools/shared.d.ts +0 -20
  370. package/dist-sdk/server/src/tools/packs/acts/tools/shared.js +0 -70
  371. package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.d.ts +0 -4
  372. package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.js +0 -215
  373. package/docs/.nojekyll +0 -1
  374. package/docs/assets/hierarchy.js +0 -1
  375. package/docs/assets/highlight.css +0 -113
  376. package/docs/assets/icons.js +0 -18
  377. package/docs/assets/icons.svg +0 -1
  378. package/docs/assets/main.js +0 -60
  379. package/docs/assets/navigation.js +0 -1
  380. package/docs/assets/search.js +0 -1
  381. package/docs/assets/style.css +0 -1648
  382. package/docs/classes/Agent.html +0 -801
  383. package/docs/classes/Briyah.html +0 -296
  384. package/docs/classes/BriyahConfigService.html +0 -119
  385. package/docs/classes/NativeToolRegistry.html +0 -166
  386. package/docs/classes/PackInstantiationService.html +0 -157
  387. package/docs/classes/PackService.html +0 -247
  388. package/docs/classes/Room.html +0 -1338
  389. package/docs/classes/RoomMessage.html +0 -290
  390. package/docs/enums/MessageAction.html +0 -136
  391. package/docs/functions/actsTools.html +0 -44
  392. package/docs/functions/availableToolPacks.html +0 -41
  393. package/docs/functions/buildMarkdown.html +0 -54
  394. package/docs/functions/dnd5eTools.html +0 -44
  395. package/docs/functions/installToolPacks.html +0 -48
  396. package/docs/functions/pageMarker.html +0 -45
  397. package/docs/functions/registerToolPacks.html +0 -54
  398. package/docs/functions/splitMarkdownIntoPages.html +0 -51
  399. package/docs/functions/stripWrappingFence.html +0 -52
  400. package/docs/hierarchy.html +0 -46
  401. package/docs/index.html +0 -595
  402. package/docs/interfaces/AgentCreationOptions.html +0 -125
  403. package/docs/interfaces/AgentInfo.html +0 -218
  404. package/docs/interfaces/AgentMessagesResponse.html +0 -74
  405. package/docs/interfaces/AppService.html +0 -3337
  406. package/docs/interfaces/Artifact.html +0 -95
  407. package/docs/interfaces/ArtifactMetadata.html +0 -112
  408. package/docs/interfaces/ArtifactWriteOptions.html +0 -90
  409. package/docs/interfaces/AttachDocumentResponse.html +0 -62
  410. package/docs/interfaces/BriyahConfigOptions.html +0 -124
  411. package/docs/interfaces/ChapterInfo.html +0 -62
  412. package/docs/interfaces/Character.html +0 -86
  413. package/docs/interfaces/ConversionAgent.html +0 -78
  414. package/docs/interfaces/CreateAgentResponse.html +0 -56
  415. package/docs/interfaces/CreateRoomResponse.html +0 -62
  416. package/docs/interfaces/CreateStoryResponse.html +0 -56
  417. package/docs/interfaces/FileList.html +0 -56
  418. package/docs/interfaces/FileMetadata.html +0 -89
  419. package/docs/interfaces/IConfigService.html +0 -79
  420. package/docs/interfaces/InstantiateModels.html +0 -64
  421. package/docs/interfaces/InstantiateRoomResult.html +0 -70
  422. package/docs/interfaces/LoadedPack.html +0 -131
  423. package/docs/interfaces/LoggingOptions.html +0 -92
  424. package/docs/interfaces/Message.html +0 -84
  425. package/docs/interfaces/ModelChoice.html +0 -73
  426. package/docs/interfaces/ModelInfo.html +0 -74
  427. package/docs/interfaces/NativeToolDefinition.html +0 -107
  428. package/docs/interfaces/PackAgentTemplate.html +0 -101
  429. package/docs/interfaces/PackRoomTemplate.html +0 -108
  430. package/docs/interfaces/PackView.html +0 -172
  431. package/docs/interfaces/PdfConversionOptions.html +0 -102
  432. package/docs/interfaces/PdfConversionResult.html +0 -97
  433. package/docs/interfaces/PdfMarkdownOptions.html +0 -198
  434. package/docs/interfaces/PdfMarkdownResult.html +0 -106
  435. package/docs/interfaces/PdfPageMarkdown.html +0 -94
  436. package/docs/interfaces/PreparedPromptResponse.html +0 -62
  437. package/docs/interfaces/ProcessTextResponse.html +0 -86
  438. package/docs/interfaces/PromptFile.html +0 -70
  439. package/docs/interfaces/PromptFileContent.html +0 -76
  440. package/docs/interfaces/PromptFilesResponse.html +0 -56
  441. package/docs/interfaces/PromptFolder.html +0 -80
  442. package/docs/interfaces/PromptFolderDefaults.html +0 -155
  443. package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
  444. package/docs/interfaces/PromptFoldersResponse.html +0 -56
  445. package/docs/interfaces/RoomDetails.html +0 -151
  446. package/docs/interfaces/RoomErrorUpdate.html +0 -82
  447. package/docs/interfaces/RoomInfo.html +0 -88
  448. package/docs/interfaces/RoomMessageUpdate.html +0 -113
  449. package/docs/interfaces/RoomMessagesResponse.html +0 -62
  450. package/docs/interfaces/SendMessageResult.html +0 -62
  451. package/docs/interfaces/StoryErrorEvent.html +0 -84
  452. package/docs/interfaces/StoryIdea.html +0 -74
  453. package/docs/interfaces/StoryInfo.html +0 -198
  454. package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
  455. package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
  456. package/docs/interfaces/StoryState.html +0 -108
  457. package/docs/interfaces/StoryStateEvent.html +0 -76
  458. package/docs/interfaces/ToolArtifact.html +0 -85
  459. package/docs/interfaces/ToolCaller.html +0 -77
  460. package/docs/interfaces/ToolDefinition.html +0 -80
  461. package/docs/interfaces/ToolHelpers.html +0 -105
  462. package/docs/interfaces/ToolPackDocuments.html +0 -100
  463. package/docs/interfaces/ToolParameter.html +0 -74
  464. package/docs/interfaces/ToolRoomAccess.html +0 -227
  465. package/docs/interfaces/ToolSummary.html +0 -74
  466. package/docs/interfaces/ToolsResponse.html +0 -68
  467. package/docs/interfaces/Transaction.html +0 -104
  468. package/docs/interfaces/TransactionHistoryResponse.html +0 -62
  469. package/docs/modules.html +0 -53
  470. package/docs/types/PackOrigin.html +0 -34
  471. package/docs/types/PromptScope.html +0 -34
  472. package/docs/types/RoomTurnMode.html +0 -42
  473. package/docs/types/RoomUpdate.html +0 -36
  474. package/docs/types/RosterOverrides.html +0 -42
  475. package/docs/types/ToolContext.html +0 -40
  476. package/docs/types/ToolRunResult.html +0 -34
  477. package/src/tools/packs/dnd5e/README.md +0 -867
@@ -1 +1,12 @@
1
+ /**
2
+ * Argument coercion, re-exported from where it now lives.
3
+ *
4
+ * The implementation moved to `server/src/tools/shared/coerce.ts` when a second
5
+ * pack needed it: nothing in it is about D&D, and every pack has the same problem
6
+ * — tool arguments arrive from `JSON.parse` of text an LLM wrote, with no type
7
+ * checking anywhere in the path.
8
+ *
9
+ * Kept as a re-export rather than removed so this pack's ten importers, and any
10
+ * host reaching in, keep working against one implementation.
11
+ */
1
12
  export * from '../../../shared/coerce';
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ /**
3
+ * Argument coercion, re-exported from where it now lives.
4
+ *
5
+ * The implementation moved to `server/src/tools/shared/coerce.ts` when a second
6
+ * pack needed it: nothing in it is about D&D, and every pack has the same problem
7
+ * — tool arguments arrive from `JSON.parse` of text an LLM wrote, with no type
8
+ * checking anywhere in the path.
9
+ *
10
+ * Kept as a re-export rather than removed so this pack's ten importers, and any
11
+ * host reaching in, keep working against one implementation.
12
+ */
2
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
14
  if (k2 === undefined) k2 = k;
4
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,34 +1,99 @@
1
+ /**
2
+ * Dice expression parsing and rolling. Pure apart from the RNG, which is
3
+ * injectable so tests can be deterministic.
4
+ *
5
+ * Grammar, in the order a term may appear:
6
+ * [label=] NdM [modifiers] [+K|-K ...] [xN]
7
+ * where modifiers are, in any order and any case:
8
+ * kh[N] / kl[N] keep the highest / lowest N dice (default 1)
9
+ * dh[N] / dl[N] drop the highest / lowest N dice (default 1)
10
+ * adv / dis shorthand for 2d20kh1 / 2d20kl1 on a single d20
11
+ * r1 reroll each 1 once, keeping the new value
12
+ * min2 treat any die below 2 as 2 (great weapon fighting)
13
+ * crit double the number of dice (a critical hit's damage)
14
+ */
15
+ /** Rolls an integer in [1, sides]. */
1
16
  export type Rng = (sides: number) => number;
2
17
  export declare const defaultRng: Rng;
18
+ /** Hard caps so one call cannot produce an unreadable or oversized result. */
3
19
  export declare const MAX_EXPRESSIONS = 20;
4
20
  export declare const MAX_DICE_PER_CALL = 100;
5
21
  export declare const MAX_REPEAT = 20;
6
22
  export interface DieRoll {
23
+ /** The face rolled, after any reroll or minimum was applied. */
7
24
  value: number;
25
+ /** The original face, present only when a modifier changed it. */
8
26
  original?: number;
27
+ /** True when this die was dropped by a keep/drop modifier. */
9
28
  dropped?: boolean;
10
29
  }
11
30
  export interface RollResult {
31
+ /** The label, or the expression text when unlabelled. */
12
32
  label: string;
33
+ /** The expression as parsed, echoed so the caller can confirm intent. */
13
34
  expression: string;
14
35
  dice: DieRoll[];
36
+ /** The flat modifier applied after the dice. */
15
37
  modifier: number;
16
38
  total: number;
39
+ /** The faces of the dice that counted, for a d20 test's natural roll. */
17
40
  kept: number[];
41
+ /** True when a single kept d20 came up 20, false when 1, absent otherwise. */
18
42
  natural20?: boolean;
19
43
  natural1?: boolean;
20
44
  }
21
45
  export declare class DiceError extends Error {
22
46
  constructor(message: string);
23
47
  }
48
+ /**
49
+ * Splits a semicolon-separated expression list and rolls each one.
50
+ * @param expressions The raw `expressions` argument
51
+ * @param rng The random source
52
+ * @returns One result per rolled expression, expanded for any `xN` repeat
53
+ * @throws {DiceError} On an unparseable expression or an exceeded cap
54
+ */
24
55
  export declare function rollExpressions(expressions: string, rng?: Rng): RollResult[];
56
+ /**
57
+ * Rolls a single already-parsed expression string.
58
+ * @param expression One expression, e.g. `1d20+5 adv`
59
+ * @param rng The random source
60
+ * @returns The roll result
61
+ */
25
62
  export declare function rollOne(expression: string, rng?: Rng): RollResult;
63
+ /**
64
+ * Rolls a d20 test: one d20 plus a modifier, with advantage or disadvantage.
65
+ * @param modifier The total bonus to add
66
+ * @param mode 'normal', 'advantage' or 'disadvantage'
67
+ * @param rng The random source
68
+ * @returns The roll result
69
+ */
26
70
  export declare function rollD20(modifier: number, mode: 'normal' | 'advantage' | 'disadvantage', rng?: Rng): RollResult;
71
+ /**
72
+ * Renders a roll for a tool result: compact, but showing every die so the DM can
73
+ * narrate and a player can see the roll was real.
74
+ * @param result The roll to describe
75
+ * @returns A one-line summary, e.g. `attack: [17] +5 = 22` or `4d6kh3: [5 4 4 ~2] = 13`
76
+ */
77
+ /** An attack's damage, rolled and described. */
27
78
  export interface DamageRoll {
79
+ /** The expression as rolled, including `crit` when the dice were doubled. */
28
80
  expression: string;
29
81
  total: number;
30
82
  type?: string;
31
83
  detail: string;
32
84
  }
85
+ /**
86
+ * Rolls an attack's damage.
87
+ *
88
+ * Here rather than beside the check tool because two tools now need it: `check`
89
+ * rolls damage when an attack lands, and `spend` rolls it when a held die turns a
90
+ * miss into a hit. One implementation means the two cannot disagree about how a
91
+ * critical doubles.
92
+ * @param expression The damage dice, e.g. '1d8+3'
93
+ * @param type The damage type, for the report
94
+ * @param critical Whether to double the dice
95
+ * @param rng The random source
96
+ * @returns The roll, never below zero
97
+ */
33
98
  export declare function rollDamage(expression: string, type: string | undefined, critical: boolean, rng?: Rng): DamageRoll;
34
99
  export declare function describeRoll(result: RollResult): string;
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ /**
3
+ * Dice expression parsing and rolling. Pure apart from the RNG, which is
4
+ * injectable so tests can be deterministic.
5
+ *
6
+ * Grammar, in the order a term may appear:
7
+ * [label=] NdM [modifiers] [+K|-K ...] [xN]
8
+ * where modifiers are, in any order and any case:
9
+ * kh[N] / kl[N] keep the highest / lowest N dice (default 1)
10
+ * dh[N] / dl[N] drop the highest / lowest N dice (default 1)
11
+ * adv / dis shorthand for 2d20kh1 / 2d20kl1 on a single d20
12
+ * r1 reroll each 1 once, keeping the new value
13
+ * min2 treat any die below 2 as 2 (great weapon fighting)
14
+ * crit double the number of dice (a critical hit's damage)
15
+ */
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.DiceError = exports.MAX_REPEAT = exports.MAX_DICE_PER_CALL = exports.MAX_EXPRESSIONS = exports.defaultRng = void 0;
4
18
  exports.rollExpressions = rollExpressions;
@@ -8,6 +22,7 @@ exports.rollDamage = rollDamage;
8
22
  exports.describeRoll = describeRoll;
9
23
  const defaultRng = (sides) => Math.floor(Math.random() * sides) + 1;
10
24
  exports.defaultRng = defaultRng;
25
+ /** Hard caps so one call cannot produce an unreadable or oversized result. */
11
26
  exports.MAX_EXPRESSIONS = 20;
12
27
  exports.MAX_DICE_PER_CALL = 100;
13
28
  exports.MAX_REPEAT = 20;
@@ -18,6 +33,13 @@ class DiceError extends Error {
18
33
  }
19
34
  }
20
35
  exports.DiceError = DiceError;
36
+ /**
37
+ * Splits a semicolon-separated expression list and rolls each one.
38
+ * @param expressions The raw `expressions` argument
39
+ * @param rng The random source
40
+ * @returns One result per rolled expression, expanded for any `xN` repeat
41
+ * @throws {DiceError} On an unparseable expression or an exceeded cap
42
+ */
21
43
  function rollExpressions(expressions, rng = exports.defaultRng) {
22
44
  const terms = String(expressions)
23
45
  .split(';')
@@ -43,11 +65,24 @@ function rollExpressions(expressions, rng = exports.defaultRng) {
43
65
  }
44
66
  return results;
45
67
  }
68
+ /**
69
+ * Rolls a single already-parsed expression string.
70
+ * @param expression One expression, e.g. `1d20+5 adv`
71
+ * @param rng The random source
72
+ * @returns The roll result
73
+ */
46
74
  function rollOne(expression, rng = exports.defaultRng) {
47
75
  const term = parseTerm(expression);
48
76
  term.repeat = 1;
49
77
  return rollTerm(term, termLabel(term), rng);
50
78
  }
79
+ /**
80
+ * Rolls a d20 test: one d20 plus a modifier, with advantage or disadvantage.
81
+ * @param modifier The total bonus to add
82
+ * @param mode 'normal', 'advantage' or 'disadvantage'
83
+ * @param rng The random source
84
+ * @returns The roll result
85
+ */
51
86
  function rollD20(modifier, mode, rng = exports.defaultRng) {
52
87
  const term = {
53
88
  count: mode === 'normal' ? 1 : 2,
@@ -69,9 +104,17 @@ function termLabel(term) {
69
104
  const mod = term.modifier === 0 ? '' : term.modifier > 0 ? `+${term.modifier}` : `${term.modifier}`;
70
105
  return `${term.count}d${term.sides}${mod}`;
71
106
  }
107
+ /**
108
+ * Parses one expression term.
109
+ * @param text The term, optionally prefixed with `label=`
110
+ * @returns The parsed term
111
+ * @throws {DiceError} If the term has no dice or an unsupported modifier
112
+ */
72
113
  function parseTerm(text) {
73
114
  let body = text.trim();
74
115
  let label;
116
+ // A label is `name=` before the dice. Guard against matching the '=' of a
117
+ // future comparison operator by requiring the label to be word-ish.
75
118
  const labelMatch = /^([A-Za-z][A-Za-z0-9 _'-]*)=\s*(.+)$/.exec(body);
76
119
  if (labelMatch) {
77
120
  label = labelMatch[1].trim();
@@ -86,8 +129,14 @@ function parseTerm(text) {
86
129
  minimumTwo: false,
87
130
  repeat: 1,
88
131
  };
132
+ // The dice term is extracted first. Modifiers are often written flush against
133
+ // it ("4d6kh3"), which leaves no word boundary for the modifier patterns to
134
+ // anchor on; removing the dice first gives every modifier clean edges.
89
135
  const diceMatch = /(\d*)\s*d\s*(\d+)/i.exec(body);
90
136
  if (!diceMatch) {
137
+ // A bare number is a constant, not an error. Several SRD creatures deal
138
+ // flat damage with no die at all — a cat's claws do 1 slashing — and the
139
+ // Dungeon Master rolls those through the same tool as everything else.
91
140
  const constant = /^[+-]?\d+$/.exec(body);
92
141
  if (constant) {
93
142
  term.count = 0;
@@ -107,6 +156,7 @@ function parseTerm(text) {
107
156
  throw new DiceError(`"${text}" rolls no dice.`);
108
157
  if (term.sides < 2)
109
158
  throw new DiceError(`A die must have at least 2 sides ("${text}").`);
159
+ // Word modifiers next, so what remains is arithmetic.
110
160
  const takeWord = (pattern) => {
111
161
  const match = pattern.exec(rest);
112
162
  if (match) {
@@ -128,6 +178,7 @@ function parseTerm(text) {
128
178
  const dropHigh = takeWord(/\bdh(\d*)\b/i);
129
179
  const dropLow = takeWord(/\bdl(\d*)\b/i);
130
180
  const repeat = takeWord(/\bx(\d+)\b/i);
181
+ // Whatever arithmetic remains is the flat modifier.
131
182
  const remaining = rest.replace(/\s+/g, '');
132
183
  if (remaining) {
133
184
  const parts = remaining.match(/[+-]\d+/g);
@@ -190,12 +241,14 @@ function rollTerm(term, label, rng) {
190
241
  total,
191
242
  kept,
192
243
  };
244
+ // Only a single kept d20 has a meaningful natural result.
193
245
  if (term.sides === 20 && kept.length === 1) {
194
246
  result.natural20 = kept[0] === 20;
195
247
  result.natural1 = kept[0] === 1;
196
248
  }
197
249
  return result;
198
250
  }
251
+ /** Marks dice as dropped per the term's keep/drop modifiers. */
199
252
  function applyKeepDrop(dice, term) {
200
253
  const keepCount = term.keepHighest !== undefined
201
254
  ? term.keepHighest
@@ -205,6 +258,7 @@ function applyKeepDrop(dice, term) {
205
258
  if (keepCount === undefined && term.dropHighest === undefined && term.dropLowest === undefined) {
206
259
  return;
207
260
  }
261
+ // Sort indices by value so ties drop deterministically (lowest index first).
208
262
  const order = dice.map((d, i) => ({ i, value: d.value })).sort((a, b) => a.value - b.value || a.i - b.i);
209
263
  const markDropped = (entries) => {
210
264
  for (const entry of entries)
@@ -248,6 +302,19 @@ function describeTerm(term) {
248
302
  parts.push(term.modifier > 0 ? `+${term.modifier}` : `${term.modifier}`);
249
303
  return parts.join(' ');
250
304
  }
305
+ /**
306
+ * Rolls an attack's damage.
307
+ *
308
+ * Here rather than beside the check tool because two tools now need it: `check`
309
+ * rolls damage when an attack lands, and `spend` rolls it when a held die turns a
310
+ * miss into a hit. One implementation means the two cannot disagree about how a
311
+ * critical doubles.
312
+ * @param expression The damage dice, e.g. '1d8+3'
313
+ * @param type The damage type, for the report
314
+ * @param critical Whether to double the dice
315
+ * @param rng The random source
316
+ * @returns The roll, never below zero
317
+ */
251
318
  function rollDamage(expression, type, critical, rng = exports.defaultRng) {
252
319
  const toRoll = critical ? `${expression} crit` : expression;
253
320
  const roll = rollOne(toRoll, rng);
@@ -1,32 +1,105 @@
1
+ /**
2
+ * The `Encounter` artifact: whose turn it is, and which round.
3
+ *
4
+ * Turn order is state the tools maintain rather than something the agent running the
5
+ * fight re-states each message, because a re-stated order drifts. Same shape as every
6
+ * other artifact the pack owns: a readable summary for the person at the table above
7
+ * a fenced `briyah-state` block for the tools.
8
+ *
9
+ * Whose turn it is is an **index**, not a set of done-flags. There is one number to
10
+ * be wrong about, and "everyone before it has acted" cannot contradict itself the way
11
+ * a list of ticks can.
12
+ *
13
+ * Pure, with no room access, like the rest of `engine/`.
14
+ */
15
+ /** The schema version, bumped when a migration becomes necessary. */
1
16
  export declare const ENCOUNTER_STATE_VERSION = 1;
2
17
  export interface Combatant {
3
18
  name: string;
19
+ /** The initiative total this combatant rolled. */
4
20
  init: number;
21
+ /** True for a monster, so a turn can be skipped once it is dead. */
5
22
  foe?: boolean;
6
23
  }
7
24
  export interface EncounterState {
8
25
  v: number;
26
+ /** What this fight is called, for the render. */
9
27
  name: string;
10
28
  round: number;
29
+ /**
30
+ * Index into {@link order} of whose turn it is. Everyone before it has acted
31
+ * this round; everyone from it onward has not.
32
+ */
11
33
  turn: number;
12
34
  order: Combatant[];
35
+ /**
36
+ * Attack rolls made this round, keyed by {@link combatantKey}. Cleared when the
37
+ * round rolls over.
38
+ *
39
+ * Here rather than on the creature because it is about the round, not the
40
+ * creature, and this is the only object that knows when a round ends. It is what
41
+ * stops a creature attacking twice in a round — which is not a hypothetical: a
42
+ * wolf with a single Bite and no Multiattack bit once before its turn came up and
43
+ * again after it did, and the second one killed a player character.
44
+ */
13
45
  atk?: Record<string, number>;
14
46
  }
47
+ /** How a combatant is keyed in {@link EncounterState.atk}. */
15
48
  export declare function combatantKey(name: string): string;
16
49
  export declare class EncounterError extends Error {
50
+ /** A machine-readable reason so callers can branch without parsing the message. */
17
51
  readonly violation: string;
18
52
  constructor(violation: string, message: string);
19
53
  }
54
+ /** A fight that has just been rolled for, on round one with the first combatant up. */
20
55
  export declare function newEncounter(name: string, order: Combatant[]): EncounterState;
56
+ /**
57
+ * Reads the encounter out of its artifact body.
58
+ * @param body The artifact body, or undefined when no fight is running
59
+ * @returns The state, or null when there is no fight
60
+ * @throws {EncounterError} When the block exists but cannot be read, so a caller
61
+ * refuses to overwrite rather than destroying what survives.
62
+ */
21
63
  export declare function parseEncounter(body: string | undefined): EncounterState | null;
64
+ /** How many attack rolls a combatant has already made this round. */
22
65
  export declare function attacksThisRound(state: EncounterState, name: string): number;
66
+ /** Records an attack roll against the current round's budget. */
23
67
  export declare function recordAttack(state: EncounterState, name: string): void;
68
+ /**
69
+ * Where a combatant sits in the order relative to the turn pointer.
70
+ * @param state The encounter
71
+ * @param name The combatant
72
+ * @returns 'past' when their turn this round is over, 'up' when it is theirs now,
73
+ * 'ahead' when it has not come round yet, and 'absent' when they are not in the
74
+ * fight at all — a creature outside the order is not governed by it.
75
+ */
24
76
  export declare function turnStanding(state: EncounterState, name: string): 'past' | 'up' | 'ahead' | 'absent';
77
+ /** Whose turn it currently is. */
25
78
  export declare function currentCombatant(state: EncounterState): Combatant;
79
+ /**
80
+ * Moves to the next combatant, wrapping into the next round.
81
+ *
82
+ * `skip` is consulted for each candidate so a dead monster does not get a turn; the
83
+ * order alone carries nothing to tell a caller that. An order where everyone is
84
+ * skippable advances the round and stops rather than looping forever.
85
+ * @param state The encounter, mutated in place
86
+ * @param skip Answers whether a combatant should be passed over
87
+ * @returns Who is up now, and whether the round advanced
88
+ */
26
89
  export declare function advanceTurn(state: EncounterState, skip?: (combatant: Combatant) => boolean): {
27
90
  combatant: Combatant;
28
91
  newRound: boolean;
29
92
  skipped: string[];
30
93
  };
94
+ /** Removes a combatant from the order, keeping the turn pointing at the same one. */
31
95
  export declare function removeCombatant(state: EncounterState, name: string): boolean;
96
+ /**
97
+ * Renders the artifact: a readable order above the state the tools read.
98
+ *
99
+ * The marks are the point — a person glancing at this wants to see how far round the
100
+ * table has got without counting. `←` is up now, `✓` has acted this round.
101
+ * @param state The encounter
102
+ * @param dead Names that are down, marked so nobody wonders why they are skipped
103
+ * @returns The artifact body
104
+ */
32
105
  export declare function renderEncounter(state: EncounterState, dead?: string[]): string;
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ /**
3
+ * The `Encounter` artifact: whose turn it is, and which round.
4
+ *
5
+ * Turn order is state the tools maintain rather than something the agent running the
6
+ * fight re-states each message, because a re-stated order drifts. Same shape as every
7
+ * other artifact the pack owns: a readable summary for the person at the table above
8
+ * a fenced `briyah-state` block for the tools.
9
+ *
10
+ * Whose turn it is is an **index**, not a set of done-flags. There is one number to
11
+ * be wrong about, and "everyone before it has acted" cannot contradict itself the way
12
+ * a list of ticks can.
13
+ *
14
+ * Pure, with no room access, like the rest of `engine/`.
15
+ */
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.EncounterError = exports.ENCOUNTER_STATE_VERSION = void 0;
4
18
  exports.combatantKey = combatantKey;
@@ -12,11 +26,14 @@ exports.advanceTurn = advanceTurn;
12
26
  exports.removeCombatant = removeCombatant;
13
27
  exports.renderEncounter = renderEncounter;
14
28
  const STATE_FENCE_TAG = 'briyah-state';
29
+ /** The schema version, bumped when a migration becomes necessary. */
15
30
  exports.ENCOUNTER_STATE_VERSION = 1;
31
+ /** How a combatant is keyed in {@link EncounterState.atk}. */
16
32
  function combatantKey(name) {
17
33
  return name.trim().toLowerCase();
18
34
  }
19
35
  class EncounterError extends Error {
36
+ /** A machine-readable reason so callers can branch without parsing the message. */
20
37
  violation;
21
38
  constructor(violation, message) {
22
39
  super(message);
@@ -25,15 +42,25 @@ class EncounterError extends Error {
25
42
  }
26
43
  }
27
44
  exports.EncounterError = EncounterError;
45
+ /** A fight that has just been rolled for, on round one with the first combatant up. */
28
46
  function newEncounter(name, order) {
29
47
  return { v: exports.ENCOUNTER_STATE_VERSION, name, round: 1, turn: 0, order, atk: {} };
30
48
  }
49
+ /**
50
+ * Reads the encounter out of its artifact body.
51
+ * @param body The artifact body, or undefined when no fight is running
52
+ * @returns The state, or null when there is no fight
53
+ * @throws {EncounterError} When the block exists but cannot be read, so a caller
54
+ * refuses to overwrite rather than destroying what survives.
55
+ */
31
56
  function parseEncounter(body) {
32
57
  if (!body || !body.trim())
33
58
  return null;
34
59
  const lines = body.split('\n');
35
60
  const open = lines.findIndex((line) => line.trim() === '```' + STATE_FENCE_TAG);
36
61
  if (open === -1) {
62
+ // Overwritten by hand, or written before the state block existed. Reported
63
+ // rather than guessed at.
37
64
  throw new EncounterError('encounter_corrupt', `The "Encounter" artifact has no "${STATE_FENCE_TAG}" block, so the turn order cannot be read. Roll initiative again to start a fresh one.`);
38
65
  }
39
66
  const closeOffset = lines.slice(open + 1).findIndex((line) => line.trim() === '```');
@@ -77,15 +104,25 @@ function parseEncounter(body) {
77
104
  atk,
78
105
  };
79
106
  }
107
+ /** How many attack rolls a combatant has already made this round. */
80
108
  function attacksThisRound(state, name) {
81
109
  return state.atk?.[combatantKey(name)] || 0;
82
110
  }
111
+ /** Records an attack roll against the current round's budget. */
83
112
  function recordAttack(state, name) {
84
113
  if (!state.atk)
85
114
  state.atk = {};
86
115
  const key = combatantKey(name);
87
116
  state.atk[key] = (state.atk[key] || 0) + 1;
88
117
  }
118
+ /**
119
+ * Where a combatant sits in the order relative to the turn pointer.
120
+ * @param state The encounter
121
+ * @param name The combatant
122
+ * @returns 'past' when their turn this round is over, 'up' when it is theirs now,
123
+ * 'ahead' when it has not come round yet, and 'absent' when they are not in the
124
+ * fight at all — a creature outside the order is not governed by it.
125
+ */
89
126
  function turnStanding(state, name) {
90
127
  const key = combatantKey(name);
91
128
  const index = state.order.findIndex((entry) => combatantKey(entry.name) === key);
@@ -97,9 +134,20 @@ function turnStanding(state, name) {
97
134
  return 'up';
98
135
  return 'ahead';
99
136
  }
137
+ /** Whose turn it currently is. */
100
138
  function currentCombatant(state) {
101
139
  return state.order[state.turn];
102
140
  }
141
+ /**
142
+ * Moves to the next combatant, wrapping into the next round.
143
+ *
144
+ * `skip` is consulted for each candidate so a dead monster does not get a turn; the
145
+ * order alone carries nothing to tell a caller that. An order where everyone is
146
+ * skippable advances the round and stops rather than looping forever.
147
+ * @param state The encounter, mutated in place
148
+ * @param skip Answers whether a combatant should be passed over
149
+ * @returns Who is up now, and whether the round advanced
150
+ */
103
151
  function advanceTurn(state, skip = () => false) {
104
152
  const skipped = [];
105
153
  let newRound = false;
@@ -109,6 +157,9 @@ function advanceTurn(state, skip = () => false) {
109
157
  state.turn = 0;
110
158
  state.round += 1;
111
159
  newRound = true;
160
+ // Everyone's attack is available again. Cleared on the way into the new
161
+ // round rather than as each turn ends, because a creature may legitimately
162
+ // act before its own turn comes up and the budget has to outlive that.
112
163
  state.atk = {};
113
164
  }
114
165
  const candidate = state.order[state.turn];
@@ -116,8 +167,10 @@ function advanceTurn(state, skip = () => false) {
116
167
  return { combatant: candidate, newRound, skipped };
117
168
  skipped.push(candidate.name);
118
169
  }
170
+ // Everyone left is skippable: the fight is over in all but name.
119
171
  return { combatant: state.order[state.turn], newRound, skipped };
120
172
  }
173
+ /** Removes a combatant from the order, keeping the turn pointing at the same one. */
121
174
  function removeCombatant(state, name) {
122
175
  const index = state.order.findIndex((entry) => entry.name.toLowerCase() === name.trim().toLowerCase());
123
176
  if (index === -1)
@@ -127,12 +180,22 @@ function removeCombatant(state, name) {
127
180
  state.turn = 0;
128
181
  return true;
129
182
  }
183
+ // Removing someone earlier in the order shifts everyone after them down one.
130
184
  if (index < state.turn)
131
185
  state.turn -= 1;
132
186
  if (state.turn >= state.order.length)
133
187
  state.turn = 0;
134
188
  return true;
135
189
  }
190
+ /**
191
+ * Renders the artifact: a readable order above the state the tools read.
192
+ *
193
+ * The marks are the point — a person glancing at this wants to see how far round the
194
+ * table has got without counting. `←` is up now, `✓` has acted this round.
195
+ * @param state The encounter
196
+ * @param dead Names that are down, marked so nobody wonders why they are skipped
197
+ * @returns The artifact body
198
+ */
136
199
  function renderEncounter(state, dead = []) {
137
200
  const down = new Set(dead.map((name) => name.toLowerCase()));
138
201
  const lines = [`# ${state.name}`, '', `**Round ${state.round}**`, ''];
@@ -1,26 +1,92 @@
1
+ /**
2
+ * Carrying capacity, and the optional encumbrance variant.
3
+ *
4
+ * Two regimes, and the difference matters. The **base rule** is always in force and
5
+ * is almost never binding — capacity is Strength × 15, "high enough that most
6
+ * characters don't usually have to worry about it" — so the only thing it changes is
7
+ * a speed of 5 feet while dragging something too heavy.
8
+ *
9
+ * The **variant** is opt-in, and turning it on has a consequence the rules state
10
+ * outright: "when you use this variant, ignore the Strength column of the Armor
11
+ * table." So a character playing with encumbrance stops taking the heavy-armour
12
+ * speed penalty and starts taking a weight penalty instead. Applying both would
13
+ * charge them twice for the same plate mail.
14
+ *
15
+ * Pure, with no room access, like the rest of `engine/`.
16
+ */
1
17
  import type { SheetState } from './sheet';
18
+ /**
19
+ * What one of an item weighs, in pounds.
20
+ *
21
+ * Three lookups, in order, and each earns its place. An exact name; then the same
22
+ * words with a comma swapped round, because the SRD files things for sorting rather
23
+ * than for reading — `Clothes, common` is what a person writes as "common clothes",
24
+ * exactly as `Crossbow, light` is a light crossbow. Then a bundle: the SRD prices
25
+ * ammunition twenty at a time, so `Arrows (20) — 1 lb.` means one arrow weighs a
26
+ * twentieth of a pound and a sheet saying `arrows x40` should come to two.
27
+ * @param name The item as written on the sheet
28
+ * @returns Pounds for one, or null when the SRD never prints a weight for it
29
+ */
2
30
  export declare function itemWeight(name: string): number | null;
3
31
  export interface CarriedWeight {
32
+ /** Total pounds of everything whose weight is known. */
4
33
  pounds: number;
34
+ /**
35
+ * Items carried whose weight the SRD never prints — vestments, a holy symbol, a
36
+ * campaign's own trinket. Named rather than assumed to weigh nothing, so a total
37
+ * is never mistaken for the whole truth.
38
+ */
5
39
  unweighed: string[];
6
40
  }
41
+ /**
42
+ * Adds up what the character is carrying.
43
+ * @param state The character
44
+ * @returns The total, and whatever could not be weighed
45
+ */
7
46
  export declare function carriedWeight(state: SheetState): CarriedWeight;
8
47
  export interface CarryingCapacity {
48
+ /** Strength × 15, adjusted for size. */
9
49
  capacity: number;
50
+ /** Twice that: what can be pushed, dragged or lifted. */
10
51
  pushDragLift: number;
52
+ /** The variant's first threshold, Strength × 5. */
11
53
  encumberedAt: number;
54
+ /** The variant's second, Strength × 10. */
12
55
  heavilyEncumberedAt: number;
13
56
  }
57
+ /**
58
+ * What this character can carry.
59
+ *
60
+ * Size adjusts every figure: "for each size category above Medium, double the
61
+ * creature's carrying capacity ... for a Tiny creature, halve these weights."
62
+ * @param state The character
63
+ * @returns The capacity and the variant's thresholds
64
+ */
14
65
  export declare function carryingCapacity(state: SheetState): CarryingCapacity;
66
+ /** Where a character sits against the thresholds. */
15
67
  export type EncumbranceTier = 'unencumbered' | 'encumbered' | 'heavily encumbered' | 'over capacity';
68
+ /** True when this character plays with the optional encumbrance variant. */
16
69
  export declare function usesVariant(state: SheetState): boolean;
17
70
  export interface EncumbranceState {
18
71
  tier: EncumbranceTier;
72
+ /** Feet to subtract from speed. */
19
73
  speedPenalty: number;
74
+ /** True when Strength, Dexterity and Constitution rolls have disadvantage. */
20
75
  disadvantage: boolean;
21
76
  carried: CarriedWeight;
22
77
  capacity: CarryingCapacity;
78
+ /** True when the variant is in force; the tiers are meaningless without it. */
23
79
  variant: boolean;
24
80
  }
81
+ /**
82
+ * Works out the character's encumbrance.
83
+ *
84
+ * Without the variant only one thing bites: carrying more than capacity, which the
85
+ * base rules cover by dropping speed to 5 feet while you drag it. With the variant,
86
+ * the two thresholds apply instead.
87
+ * @param state The character
88
+ * @returns The tier and what it costs
89
+ */
25
90
  export declare function encumbrance(state: SheetState): EncumbranceState;
91
+ /** A readable line for the sheet and for `read_sheet`. */
26
92
  export declare function describeEncumbrance(state: SheetState): string;