briyah 2.0.3 → 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 (371) hide show
  1. package/README.md +43 -7
  2. package/data/common/config/LICENSE-model-prices.md +65 -0
  3. package/data/common/config/model_prices.json +47443 -46295
  4. package/data/common/prompts/narrator/create_story.prompt +2 -0
  5. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
  6. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
  7. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
  8. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
  9. package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
  10. package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
  11. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
  12. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
  13. package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
  14. package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
  15. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
  16. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
  17. package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
  18. package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
  19. package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
  20. package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
  21. package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
  22. package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
  23. package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
  24. package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
  25. package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
  26. package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
  27. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
  28. package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
  29. package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
  30. package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
  31. package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
  32. package/dist-sdk/server/src/ai/agent-factory.js +20 -0
  33. package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
  34. package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
  35. package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
  36. package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
  37. package/dist-sdk/server/src/ai/agent.d.ts +196 -0
  38. package/dist-sdk/server/src/ai/agent.js +224 -11
  39. package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
  40. package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
  41. package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
  42. package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
  43. package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
  44. package/dist-sdk/server/src/ai/artifact.service.js +148 -3
  45. package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
  46. package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
  47. package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
  48. package/dist-sdk/server/src/ai/model_prices.js +91 -5
  49. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
  50. package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
  51. package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
  52. package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
  53. package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
  54. package/dist-sdk/server/src/app/balance-message.service.js +24 -0
  55. package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
  56. package/dist-sdk/server/src/app/balance.module.js +4 -0
  57. package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
  58. package/dist-sdk/server/src/app/balance.service.js +54 -0
  59. package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
  60. package/dist-sdk/server/src/app/stripe.controller.js +35 -0
  61. package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
  62. package/dist-sdk/server/src/app/stripe.service.js +62 -0
  63. package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
  64. package/dist-sdk/server/src/app/transaction.service.js +36 -0
  65. package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
  66. package/dist-sdk/server/src/app/user-service-factory.js +38 -1
  67. package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
  68. package/dist-sdk/server/src/app/user-service-manager.js +43 -0
  69. package/dist-sdk/server/src/app.controller.d.ts +87 -0
  70. package/dist-sdk/server/src/app.controller.js +272 -12
  71. package/dist-sdk/server/src/app.module.js +28 -6
  72. package/dist-sdk/server/src/app.service.d.ts +1661 -0
  73. package/dist-sdk/server/src/app.service.js +1837 -4
  74. package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
  75. package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
  76. package/dist-sdk/server/src/auth/auth.controller.js +46 -0
  77. package/dist-sdk/server/src/auth/auth.module.js +3 -2
  78. package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
  79. package/dist-sdk/server/src/auth/auth.service.js +39 -3
  80. package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
  81. package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
  82. package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
  83. package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
  84. package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
  85. package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
  86. package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
  87. package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
  88. package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
  89. package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
  90. package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
  91. package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
  92. package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
  93. package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
  94. package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
  95. package/dist-sdk/server/src/auth/session.guard.js +8 -0
  96. package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
  97. package/dist-sdk/server/src/auth/twilio.service.js +30 -4
  98. package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
  99. package/dist-sdk/server/src/auth/users.service.js +42 -0
  100. package/dist-sdk/server/src/common/errors.d.ts +20 -0
  101. package/dist-sdk/server/src/common/errors.js +21 -0
  102. package/dist-sdk/server/src/config/env-config.d.ts +7 -0
  103. package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
  104. package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
  105. package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
  106. package/dist-sdk/server/src/config/user-config.service.js +57 -0
  107. package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
  108. package/dist-sdk/server/src/config/user-paths.service.js +67 -0
  109. package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
  110. package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
  111. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
  112. package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
  113. package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
  114. package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
  115. package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
  116. package/dist-sdk/server/src/packs/pack.service.js +98 -1
  117. package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
  118. package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
  119. package/dist-sdk/server/src/room/artifact.d.ts +18 -0
  120. package/dist-sdk/server/src/room/message.d.ts +64 -0
  121. package/dist-sdk/server/src/room/message.js +77 -2
  122. package/dist-sdk/server/src/room/nickname.d.ts +26 -0
  123. package/dist-sdk/server/src/room/nickname.js +26 -0
  124. package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
  125. package/dist-sdk/server/src/room/room-config.d.ts +26 -0
  126. package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
  127. package/dist-sdk/server/src/room/room-factory.js +14 -0
  128. package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
  129. package/dist-sdk/server/src/room/room-message.service.js +28 -0
  130. package/dist-sdk/server/src/room/room-store.service.d.ts +176 -0
  131. package/dist-sdk/server/src/room/room-store.service.js +238 -5
  132. package/dist-sdk/server/src/room/room.d.ts +878 -0
  133. package/dist-sdk/server/src/room/room.js +1291 -23
  134. package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
  135. package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
  136. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
  137. package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
  138. package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
  139. package/dist-sdk/server/src/rpg/rpg.service.js +103 -0
  140. package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
  141. package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
  142. package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
  143. package/dist-sdk/server/src/sdk/briyah.js +285 -7
  144. package/dist-sdk/server/src/sdk/index.js +23 -0
  145. package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
  146. package/dist-sdk/server/src/shared/shared.module.js +13 -5
  147. package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
  148. package/dist-sdk/server/src/story/story-message.service.js +43 -0
  149. package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
  150. package/dist-sdk/server/src/story/story-progress.service.js +23 -0
  151. package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
  152. package/dist-sdk/server/src/story/story-store.service.js +136 -1
  153. package/dist-sdk/server/src/story/story.service.d.ts +398 -0
  154. package/dist-sdk/server/src/story/story.service.js +829 -25
  155. package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
  156. package/dist-sdk/server/src/tools/core/index.js +22 -0
  157. package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
  158. package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
  159. package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
  160. package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
  161. package/dist-sdk/server/src/tools/native-tool.types.d.ts +176 -0
  162. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
  163. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
  164. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
  165. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
  166. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
  167. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
  168. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
  169. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
  170. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
  171. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
  172. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
  173. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
  174. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
  175. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
  176. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
  177. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
  178. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
  179. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
  180. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
  181. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
  182. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
  183. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
  184. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
  185. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
  186. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
  187. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
  188. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
  189. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
  190. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
  191. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
  192. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
  193. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
  194. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
  195. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
  196. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
  197. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
  198. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
  199. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
  200. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
  201. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
  202. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
  203. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
  204. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
  205. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
  206. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
  207. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
  208. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
  209. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
  210. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
  211. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
  212. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
  213. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
  214. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
  215. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
  216. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
  217. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
  218. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
  219. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
  220. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
  221. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
  222. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
  223. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
  224. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
  225. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
  226. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
  227. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
  228. package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
  229. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
  230. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
  231. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
  232. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
  233. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
  234. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
  235. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
  236. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
  237. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
  238. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
  239. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
  240. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
  241. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
  242. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
  243. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
  244. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
  245. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +116 -0
  246. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
  247. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
  248. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
  249. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
  250. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
  251. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
  252. package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
  253. package/dist-sdk/server/src/tools/packs/index.js +66 -0
  254. package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
  255. package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
  256. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
  257. package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
  258. package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
  259. package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
  260. package/dist-sdk/shared/types/app.types.d.ts +285 -13
  261. package/dist-sdk/shared/types/app.types.js +3 -0
  262. package/package.json +167 -168
  263. package/data/common/config/random_words.txt +0 -2241
  264. package/data/common/story_ideas/biblical.json +0 -122
  265. package/data/common/story_ideas/fantasy.json +0 -82
  266. package/data/common/story_ideas/historical_fiction.json +0 -82
  267. package/data/common/story_ideas/science_fiction.json +0 -82
  268. package/docs/.nojekyll +0 -1
  269. package/docs/assets/hierarchy.js +0 -1
  270. package/docs/assets/highlight.css +0 -113
  271. package/docs/assets/icons.js +0 -18
  272. package/docs/assets/icons.svg +0 -1
  273. package/docs/assets/main.js +0 -60
  274. package/docs/assets/navigation.js +0 -1
  275. package/docs/assets/search.js +0 -1
  276. package/docs/assets/style.css +0 -1648
  277. package/docs/classes/Agent.html +0 -801
  278. package/docs/classes/Briyah.html +0 -296
  279. package/docs/classes/BriyahConfigService.html +0 -119
  280. package/docs/classes/NativeToolRegistry.html +0 -166
  281. package/docs/classes/PackInstantiationService.html +0 -157
  282. package/docs/classes/PackService.html +0 -247
  283. package/docs/classes/Room.html +0 -1434
  284. package/docs/classes/RoomMessage.html +0 -290
  285. package/docs/enums/MessageAction.html +0 -136
  286. package/docs/functions/availableToolPacks.html +0 -41
  287. package/docs/functions/buildMarkdown.html +0 -54
  288. package/docs/functions/dnd5eTools.html +0 -44
  289. package/docs/functions/installToolPacks.html +0 -51
  290. package/docs/functions/pageMarker.html +0 -45
  291. package/docs/functions/registerToolPacks.html +0 -54
  292. package/docs/functions/splitMarkdownIntoPages.html +0 -51
  293. package/docs/functions/stripWrappingFence.html +0 -52
  294. package/docs/hierarchy.html +0 -46
  295. package/docs/index.html +0 -595
  296. package/docs/interfaces/AgentCreationOptions.html +0 -125
  297. package/docs/interfaces/AgentInfo.html +0 -218
  298. package/docs/interfaces/AgentMessagesResponse.html +0 -74
  299. package/docs/interfaces/AppService.html +0 -3340
  300. package/docs/interfaces/Artifact.html +0 -95
  301. package/docs/interfaces/ArtifactMetadata.html +0 -112
  302. package/docs/interfaces/ArtifactWriteOptions.html +0 -90
  303. package/docs/interfaces/AttachDocumentResponse.html +0 -62
  304. package/docs/interfaces/BriyahConfigOptions.html +0 -124
  305. package/docs/interfaces/ChapterInfo.html +0 -62
  306. package/docs/interfaces/Character.html +0 -86
  307. package/docs/interfaces/ConversionAgent.html +0 -78
  308. package/docs/interfaces/CreateAgentResponse.html +0 -56
  309. package/docs/interfaces/CreateRoomResponse.html +0 -62
  310. package/docs/interfaces/CreateStoryResponse.html +0 -56
  311. package/docs/interfaces/FileList.html +0 -56
  312. package/docs/interfaces/FileMetadata.html +0 -89
  313. package/docs/interfaces/IConfigService.html +0 -79
  314. package/docs/interfaces/InstantiateModels.html +0 -64
  315. package/docs/interfaces/InstantiateRoomResult.html +0 -70
  316. package/docs/interfaces/LoadedPack.html +0 -131
  317. package/docs/interfaces/LoggingOptions.html +0 -92
  318. package/docs/interfaces/Message.html +0 -84
  319. package/docs/interfaces/ModelChoice.html +0 -73
  320. package/docs/interfaces/ModelInfo.html +0 -74
  321. package/docs/interfaces/NativeToolDefinition.html +0 -107
  322. package/docs/interfaces/PackAgentTemplate.html +0 -101
  323. package/docs/interfaces/PackRoomTemplate.html +0 -108
  324. package/docs/interfaces/PackView.html +0 -172
  325. package/docs/interfaces/PdfConversionOptions.html +0 -102
  326. package/docs/interfaces/PdfConversionResult.html +0 -97
  327. package/docs/interfaces/PdfMarkdownOptions.html +0 -198
  328. package/docs/interfaces/PdfMarkdownResult.html +0 -106
  329. package/docs/interfaces/PdfPageMarkdown.html +0 -94
  330. package/docs/interfaces/PreparedPromptResponse.html +0 -62
  331. package/docs/interfaces/ProcessTextResponse.html +0 -86
  332. package/docs/interfaces/PromptFile.html +0 -70
  333. package/docs/interfaces/PromptFileContent.html +0 -76
  334. package/docs/interfaces/PromptFilesResponse.html +0 -56
  335. package/docs/interfaces/PromptFolder.html +0 -80
  336. package/docs/interfaces/PromptFolderDefaults.html +0 -155
  337. package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
  338. package/docs/interfaces/PromptFoldersResponse.html +0 -56
  339. package/docs/interfaces/RoomDetails.html +0 -151
  340. package/docs/interfaces/RoomErrorUpdate.html +0 -82
  341. package/docs/interfaces/RoomInfo.html +0 -88
  342. package/docs/interfaces/RoomMessageUpdate.html +0 -113
  343. package/docs/interfaces/RoomMessagesResponse.html +0 -62
  344. package/docs/interfaces/SendMessageResult.html +0 -62
  345. package/docs/interfaces/StoryErrorEvent.html +0 -84
  346. package/docs/interfaces/StoryIdea.html +0 -74
  347. package/docs/interfaces/StoryInfo.html +0 -198
  348. package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
  349. package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
  350. package/docs/interfaces/StoryState.html +0 -108
  351. package/docs/interfaces/StoryStateEvent.html +0 -76
  352. package/docs/interfaces/ToolArtifact.html +0 -85
  353. package/docs/interfaces/ToolCaller.html +0 -77
  354. package/docs/interfaces/ToolDefinition.html +0 -80
  355. package/docs/interfaces/ToolHelpers.html +0 -105
  356. package/docs/interfaces/ToolPackDocuments.html +0 -100
  357. package/docs/interfaces/ToolParameter.html +0 -74
  358. package/docs/interfaces/ToolRoomAccess.html +0 -260
  359. package/docs/interfaces/ToolSummary.html +0 -74
  360. package/docs/interfaces/ToolsResponse.html +0 -68
  361. package/docs/interfaces/Transaction.html +0 -104
  362. package/docs/interfaces/TransactionHistoryResponse.html +0 -62
  363. package/docs/modules.html +0 -53
  364. package/docs/types/PackOrigin.html +0 -34
  365. package/docs/types/PromptScope.html +0 -34
  366. package/docs/types/RoomTurnMode.html +0 -42
  367. package/docs/types/RoomUpdate.html +0 -36
  368. package/docs/types/RosterOverrides.html +0 -42
  369. package/docs/types/ToolContext.html +0 -40
  370. package/docs/types/ToolRunResult.html +0 -34
  371. package/src/tools/packs/dnd5e/README.md +0 -867
@@ -1,30 +1,122 @@
1
+ /**
2
+ * The room's bestiary: creature statistics that belong to one campaign rather
3
+ * than to the rules.
4
+ *
5
+ * Two sources resolve in order — the room's `Bestiary` artifact first, then the
6
+ * shipped SRD table. Campaign entries winning means a game can say "our goblins
7
+ * carry crossbows" and override the book, which mirrors how Briyah resolves tools
8
+ * native-first.
9
+ *
10
+ * The artifact carries a readable summary above a fenced `briyah-state` block, the
11
+ * same shape as a character sheet, for the same reason: the render is for the
12
+ * person running the game, the fence is what the tools read.
13
+ */
1
14
  import { MonsterBlock } from '../data/monsters';
2
15
  export declare const BESTIARY_ARTIFACT = "Bestiary";
16
+ /** How many names a listing returns before it asks the caller to narrow. */
3
17
  export declare const MONSTER_LIST_CAP = 60;
18
+ /** How many suggestions a failed lookup offers. */
4
19
  export declare const NEAR_MATCH_CAP = 8;
20
+ /** Where a resolved creature came from. */
5
21
  export type MonsterSource = 'bestiary' | 'srd';
22
+ /**
23
+ * The outcome of a creature lookup. Not a discriminated union: this project
24
+ * compiles with `strictNullChecks: false`, which disables narrowing on a
25
+ * discriminant, so a caller checks the fields directly.
26
+ */
6
27
  export interface MonsterLookup {
28
+ /** The creature, when exactly one matched. */
7
29
  block?: MonsterBlock;
8
30
  source?: MonsterSource;
31
+ /**
32
+ * The candidate names, when the query matched several. Reported rather than
33
+ * resolved: with a large table, "giant" matches a dozen creatures, and
34
+ * silently returning whichever was declared first is a wrong monster in a
35
+ * real fight.
36
+ */
9
37
  ambiguous?: string[];
10
38
  }
11
39
  export declare class BestiaryError extends Error {
12
40
  readonly violation: string;
13
41
  constructor(violation: string, message: string);
14
42
  }
43
+ /**
44
+ * Reads the campaign creatures out of a `Bestiary` artifact body.
45
+ * @param body The artifact body, or undefined when the artifact does not exist
46
+ * @returns Creature blocks keyed by lowercase name; empty when absent
47
+ * @throws {BestiaryError} When the state block exists but cannot be read, so a
48
+ * caller refuses to overwrite rather than destroying what survives.
49
+ */
15
50
  export declare function parseBestiary(body: string | undefined): Record<string, MonsterBlock>;
51
+ /**
52
+ * Resolves a creature name, preferring the campaign's own entry.
53
+ *
54
+ * An exact name is a single map lookup, which is the path taken almost every
55
+ * time. The loose tiers only run on a miss, and when they match more than one
56
+ * creature the ambiguity is returned rather than resolved.
57
+ * @param name The creature the caller asked for
58
+ * @param campaign Entries from {@link parseBestiary}, keyed by normalized name
59
+ * @returns The creature, the candidates, or an empty result
60
+ */
16
61
  export declare function resolveMonster(name: string, campaign: Record<string, MonsterBlock>): MonsterLookup;
17
62
  export interface MonsterListing {
18
63
  campaign: string[];
19
64
  shipped: string[];
20
65
  campaignTotal: number;
21
66
  shippedTotal: number;
67
+ /** True when either list was capped, so the caller knows to narrow. */
22
68
  truncated?: boolean;
23
69
  filter?: string;
24
70
  }
71
+ /**
72
+ * Lists the creatures available in this room, capped.
73
+ *
74
+ * Capped because the whole list goes into a tool result, and a result over
75
+ * 16 KB is replaced wholesale by a truncated string rather than being clipped —
76
+ * which would destroy the JSON exactly when the caller needs it most.
77
+ *
78
+ * **The filter matches a creature's kind and size as well as its name**, because
79
+ * those are the terms a person narrows by: a designer looking for fey creatures
80
+ * asks for "fey", which is nobody's *name* and every fey creature's `kind`. A
81
+ * name-only filter answered that with an empty list and a note saying anything
82
+ * unlisted needs defining — which reads as "this table has no fey creatures"
83
+ * rather than "ask a different way". `magic_item`'s filter already spans name,
84
+ * type and rarity for the same reason.
85
+ * @param campaign Entries from {@link parseBestiary}
86
+ * @param filter Optional substring, matched against name, kind and size
87
+ * @returns The listing, with totals so the caller can tell it was capped
88
+ */
25
89
  export declare function availableMonsters(campaign: Record<string, MonsterBlock>, filter?: string): MonsterListing;
90
+ /**
91
+ * Suggests creatures a failed lookup might have meant, scored by how many words
92
+ * of the query they contain. Bounded, so a miss never returns the whole table.
93
+ * @param name The name that failed to resolve
94
+ * @param campaign Entries from {@link parseBestiary}
95
+ * @param limit How many suggestions to return
96
+ * @returns The closest names, best first
97
+ */
26
98
  export declare function nearMonsters(name: string, campaign: Record<string, MonsterBlock>, limit?: number): string[];
99
+ /** Resets the shipped index. Only needed by tests that mutate the table. */
27
100
  export declare function resetShippedIndex(): void;
101
+ /**
102
+ * Fills in defaults and rejects a block that could not be run at a table.
103
+ * @param name The creature name the caller supplied
104
+ * @param raw The block as written
105
+ * @returns A block with every required field present
106
+ * @throws {BestiaryError} When the block is missing something a fight needs, or
107
+ * when a field is not the shape the renderer reads
108
+ */
28
109
  export declare function normalizeMonster(name: string, raw: any): MonsterBlock;
110
+ /**
111
+ * Renders the whole bestiary artifact from its entries.
112
+ * @param entries Creature blocks keyed by lowercase name
113
+ * @returns The artifact body
114
+ */
29
115
  export declare function renderBestiary(entries: Record<string, MonsterBlock>): string;
116
+ /**
117
+ * Renders one creature as readable markdown, in the order a stat block is
118
+ * written: what it is, what it can take, what it knows, then what it does.
119
+ * @param block The creature
120
+ * @returns A compact stat block
121
+ */
30
122
  export declare function describeMonster(block: MonsterBlock): string;
@@ -1,4 +1,17 @@
1
1
  "use strict";
2
+ /**
3
+ * The room's bestiary: creature statistics that belong to one campaign rather
4
+ * than to the rules.
5
+ *
6
+ * Two sources resolve in order — the room's `Bestiary` artifact first, then the
7
+ * shipped SRD table. Campaign entries winning means a game can say "our goblins
8
+ * carry crossbows" and override the book, which mirrors how Briyah resolves tools
9
+ * native-first.
10
+ *
11
+ * The artifact carries a readable summary above a fenced `briyah-state` block, the
12
+ * same shape as a character sheet, for the same reason: the render is for the
13
+ * person running the game, the fence is what the tools read.
14
+ */
2
15
  Object.defineProperty(exports, "__esModule", { value: true });
3
16
  exports.BestiaryError = exports.NEAR_MATCH_CAP = exports.MONSTER_LIST_CAP = exports.BESTIARY_ARTIFACT = void 0;
4
17
  exports.parseBestiary = parseBestiary;
@@ -15,8 +28,19 @@ const coerce_1 = require("./coerce");
15
28
  const sheet_1 = require("./sheet");
16
29
  exports.BESTIARY_ARTIFACT = 'Bestiary';
17
30
  const STATE_FENCE_TAG = 'briyah-state';
31
+ /** How many names a listing returns before it asks the caller to narrow. */
18
32
  exports.MONSTER_LIST_CAP = 60;
33
+ /** How many suggestions a failed lookup offers. */
19
34
  exports.NEAR_MATCH_CAP = 8;
35
+ /**
36
+ * The shipped creatures indexed by normalized name, built once.
37
+ *
38
+ * Keys are re-normalized rather than trusted, so a bulk import that writes
39
+ * `"Ogre Zombie"` or `"Kobold (Winged)"` still resolves. A collision here means
40
+ * one entry silently shadows another; `monster.tool.spec.ts` asserts there are
41
+ * none, which is the guard that matters when the table is generated rather than
42
+ * hand-written.
43
+ */
20
44
  let shippedIndexCache = null;
21
45
  function shippedIndex() {
22
46
  if (!shippedIndexCache) {
@@ -27,6 +51,7 @@ function shippedIndex() {
27
51
  }
28
52
  return shippedIndexCache;
29
53
  }
54
+ /** Every shipped creature's normalized key, for fuzzy matching. */
30
55
  function shippedKeys() {
31
56
  return [...shippedIndex().keys()];
32
57
  }
@@ -39,6 +64,13 @@ class BestiaryError extends Error {
39
64
  }
40
65
  }
41
66
  exports.BestiaryError = BestiaryError;
67
+ /**
68
+ * Reads the campaign creatures out of a `Bestiary` artifact body.
69
+ * @param body The artifact body, or undefined when the artifact does not exist
70
+ * @returns Creature blocks keyed by lowercase name; empty when absent
71
+ * @throws {BestiaryError} When the state block exists but cannot be read, so a
72
+ * caller refuses to overwrite rather than destroying what survives.
73
+ */
42
74
  function parseBestiary(body) {
43
75
  if (!body || !body.trim())
44
76
  return {};
@@ -69,10 +101,21 @@ function parseBestiary(body) {
69
101
  }
70
102
  return out;
71
103
  }
104
+ /**
105
+ * Resolves a creature name, preferring the campaign's own entry.
106
+ *
107
+ * An exact name is a single map lookup, which is the path taken almost every
108
+ * time. The loose tiers only run on a miss, and when they match more than one
109
+ * creature the ambiguity is returned rather than resolved.
110
+ * @param name The creature the caller asked for
111
+ * @param campaign Entries from {@link parseBestiary}, keyed by normalized name
112
+ * @returns The creature, the candidates, or an empty result
113
+ */
72
114
  function resolveMonster(name, campaign) {
73
115
  const key = (0, coerce_1.nameKey)(name);
74
116
  if (!key)
75
117
  return {};
118
+ // Exact match, campaign first so a game can override the book.
76
119
  if (campaign[key])
77
120
  return { block: campaign[key], source: 'bestiary' };
78
121
  const shipped = shippedIndex().get(key);
@@ -94,8 +137,28 @@ function resolveMonster(name, campaign) {
94
137
  }
95
138
  return {};
96
139
  }
140
+ /**
141
+ * Lists the creatures available in this room, capped.
142
+ *
143
+ * Capped because the whole list goes into a tool result, and a result over
144
+ * 16 KB is replaced wholesale by a truncated string rather than being clipped —
145
+ * which would destroy the JSON exactly when the caller needs it most.
146
+ *
147
+ * **The filter matches a creature's kind and size as well as its name**, because
148
+ * those are the terms a person narrows by: a designer looking for fey creatures
149
+ * asks for "fey", which is nobody's *name* and every fey creature's `kind`. A
150
+ * name-only filter answered that with an empty list and a note saying anything
151
+ * unlisted needs defining — which reads as "this table has no fey creatures"
152
+ * rather than "ask a different way". `magic_item`'s filter already spans name,
153
+ * type and rarity for the same reason.
154
+ * @param campaign Entries from {@link parseBestiary}
155
+ * @param filter Optional substring, matched against name, kind and size
156
+ * @returns The listing, with totals so the caller can tell it was capped
157
+ */
97
158
  function availableMonsters(campaign, filter) {
98
159
  const needle = (0, coerce_1.nameKey)(filter || '');
160
+ // `nameKey` strips punctuation, so a kind of "fiend (devil)" normalizes to
161
+ // "fiend devil" and matches a filter of either "fiend" or "devil".
99
162
  const keep = (block) => !needle ||
100
163
  [block.name, block.kind, block.size].some((field) => field && (0, coerce_1.nameKey)(field).includes(needle));
101
164
  const campaignAll = Object.values(campaign)
@@ -117,6 +180,14 @@ function availableMonsters(campaign, filter) {
117
180
  filter: filter || undefined,
118
181
  };
119
182
  }
183
+ /**
184
+ * Suggests creatures a failed lookup might have meant, scored by how many words
185
+ * of the query they contain. Bounded, so a miss never returns the whole table.
186
+ * @param name The name that failed to resolve
187
+ * @param campaign Entries from {@link parseBestiary}
188
+ * @param limit How many suggestions to return
189
+ * @returns The closest names, best first
190
+ */
120
191
  function nearMonsters(name, campaign, limit = exports.NEAR_MATCH_CAP) {
121
192
  const words = (0, coerce_1.nameKey)(name).split(' ').filter((w) => w.length > 2);
122
193
  if (words.length === 0)
@@ -136,9 +207,29 @@ function nearMonsters(name, campaign, limit = exports.NEAR_MATCH_CAP) {
136
207
  .slice(0, limit)
137
208
  .map((entry) => entry.candidate);
138
209
  }
210
+ /** Resets the shipped index. Only needed by tests that mutate the table. */
139
211
  function resetShippedIndex() {
140
212
  shippedIndexCache = null;
141
213
  }
214
+ /**
215
+ * Reads one of the fields that is a list of named paragraphs.
216
+ *
217
+ * The shape is checked even when the creature has attacks and would run without
218
+ * it, because `describeMonster` iterates these fields and reads `.n` and `.text`
219
+ * off each entry. Handed a string, `for...of` walks its *characters*, and the
220
+ * creature renders as one `**undefined.** undefined` line per character — which
221
+ * is what a prose `traits` did to a real bestiary, 410 lines of it, reported as
222
+ * a successful define.
223
+ *
224
+ * Rejected rather than coerced: a paragraph of prose usually holds several
225
+ * traits, and splitting it is guesswork that ends up in the campaign's own data.
226
+ * The error reaches the model in-band, so it can send the right shape instead.
227
+ * @param name The creature being defined
228
+ * @param field Which field is being read, for the error message
229
+ * @param value The field as written
230
+ * @returns The entries, or undefined when the field was absent
231
+ * @throws {BestiaryError} When the field is present but not a list of {n, text}
232
+ */
142
233
  function proseList(name, field, value) {
143
234
  if (value === undefined || value === null)
144
235
  return undefined;
@@ -153,6 +244,17 @@ function proseList(name, field, value) {
153
244
  return { ...entry, n: String(entry.n), text: String(entry.text) };
154
245
  });
155
246
  }
247
+ /**
248
+ * Reads one of the damage/condition fields, each a plain list of words.
249
+ *
250
+ * `describeMonster` calls `.join()` on these, which a string does not have — so
251
+ * an unchecked one is a thrown TypeError rather than a bad render.
252
+ * @param name The creature being defined
253
+ * @param field Which field is being read, for the error message
254
+ * @param value The field as written
255
+ * @returns The entries, or undefined when the field was absent
256
+ * @throws {BestiaryError} When the field is present but not a list of strings
257
+ */
156
258
  function wordList(name, field, value) {
157
259
  if (value === undefined || value === null)
158
260
  return undefined;
@@ -161,6 +263,14 @@ function wordList(name, field, value) {
161
263
  }
162
264
  return value.map((entry) => String(entry));
163
265
  }
266
+ /**
267
+ * Fills in defaults and rejects a block that could not be run at a table.
268
+ * @param name The creature name the caller supplied
269
+ * @param raw The block as written
270
+ * @returns A block with every required field present
271
+ * @throws {BestiaryError} When the block is missing something a fight needs, or
272
+ * when a field is not the shape the renderer reads
273
+ */
164
274
  function normalizeMonster(name, raw) {
165
275
  if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
166
276
  throw new BestiaryError('bad_block', `A creature definition must be a JSON object. Example: {"ac":14,"hp":27,"speed":"30 ft.","abil":{"str":12,"dex":16,"con":12,"int":10,"wis":11,"cha":10},"attacks":[{"n":"Shortsword","atk":5,"dmg":"1d6+3","type":"piercing"}]}`);
@@ -174,6 +284,8 @@ function normalizeMonster(name, raw) {
174
284
  throw new BestiaryError('bad_block', `"${name}" needs a numeric hit point total ("hp").`);
175
285
  }
176
286
  const attacks = Array.isArray(raw.attacks) ? raw.attacks : [];
287
+ // Checked before the "can it do anything" test below, so a malformed field is
288
+ // reported as the wrong shape rather than as a creature with nothing to do.
177
289
  const traits = proseList(name, 'traits', raw.traits);
178
290
  const actions = proseList(name, 'actions', raw.actions);
179
291
  const reactions = proseList(name, 'reactions', raw.reactions);
@@ -181,6 +293,11 @@ function normalizeMonster(name, raw) {
181
293
  const immune = wordList(name, 'immune', raw.immune);
182
294
  const vuln = wordList(name, 'vuln', raw.vuln);
183
295
  const condImmune = wordList(name, 'condImmune', raw.condImmune);
296
+ // A creature needs something beyond its numbers, but it need not be an attack
297
+ // roll. A shrieker only shrieks, a frog only jumps, and a noncombat NPC only
298
+ // talks; all three are worth having statistics for. What this still rejects is
299
+ // a block with nothing to do at all, which is almost always a `define` call
300
+ // that dropped its attacks.
184
301
  const hasSomethingToDo = [traits, actions, reactions].some((list) => list && list.length > 0);
185
302
  if (attacks.length === 0 && !hasSomethingToDo && !raw.legendary) {
186
303
  throw new BestiaryError('bad_block', `"${name}" has nothing it can do. Give it an attack: [{"n":"Claws","atk":4,"dmg":"2d4+2","type":"slashing"}], or an action: [{"n":"Shriek","text":"Emits a shriek audible within 300 feet."}].`);
@@ -193,6 +310,8 @@ function normalizeMonster(name, raw) {
193
310
  const abil = {};
194
311
  for (const ability of srd_1.ABILITIES) {
195
312
  const score = Number(raw.abil?.[ability]);
313
+ // A creature with no listed score is treated as average rather than rejected:
314
+ // a missing Intelligence should not stop a fight from being run.
196
315
  abil[ability] = Number.isFinite(score) ? score : 10;
197
316
  }
198
317
  const block = {
@@ -204,6 +323,9 @@ function normalizeMonster(name, raw) {
204
323
  abil,
205
324
  attacks: attacks.map((a) => ({ ...a, atk: Number(a.atk), dmg: String(a.dmg) })),
206
325
  };
326
+ // The validated forms replace what the spread copied, so what is stored is
327
+ // what the renderer can read. Assigned only when present, so an absent field
328
+ // stays absent rather than becoming an empty list.
207
329
  if (traits)
208
330
  block.traits = traits;
209
331
  if (actions)
@@ -218,6 +340,7 @@ function normalizeMonster(name, raw) {
218
340
  block.vuln = vuln;
219
341
  if (condImmune)
220
342
  block.condImmune = condImmune;
343
+ // A legendary block written by hand often arrives with only the options.
221
344
  if (raw.legendary) {
222
345
  const options = proseList(name, 'legendary.options', raw.legendary.options) ?? [];
223
346
  if (options.length === 0) {
@@ -230,6 +353,11 @@ function normalizeMonster(name, raw) {
230
353
  }
231
354
  return block;
232
355
  }
356
+ /**
357
+ * Renders the whole bestiary artifact from its entries.
358
+ * @param entries Creature blocks keyed by lowercase name
359
+ * @returns The artifact body
360
+ */
233
361
  function renderBestiary(entries) {
234
362
  const names = Object.keys(entries).sort();
235
363
  const lines = [
@@ -250,6 +378,12 @@ function renderBestiary(entries) {
250
378
  lines.push('```' + STATE_FENCE_TAG, JSON.stringify(entries), '```', '');
251
379
  return lines.join('\n');
252
380
  }
381
+ /**
382
+ * Renders one creature as readable markdown, in the order a stat block is
383
+ * written: what it is, what it can take, what it knows, then what it does.
384
+ * @param block The creature
385
+ * @returns A compact stat block
386
+ */
253
387
  function describeMonster(block) {
254
388
  const lines = [];
255
389
  const descriptors = [block.size, block.kind].filter(Boolean).join(' ');
@@ -315,16 +449,34 @@ function describeMonster(block) {
315
449
  }
316
450
  return lines.join('\n');
317
451
  }
452
+ /**
453
+ * The usable entries of a named-paragraph field, for rendering.
454
+ *
455
+ * `normalizeMonster` rejects a bad shape now, but a bestiary written before it
456
+ * did still holds one, and iterating a string there walks its characters — which
457
+ * turned one creature into 410 lines of `**undefined.** undefined`. Skipping
458
+ * what cannot be rendered keeps a stat block readable while the campaign's own
459
+ * data is repaired.
460
+ * @param value The field as stored
461
+ * @returns The entries that have both a name and text
462
+ */
318
463
  function paragraphs(value) {
319
464
  if (!Array.isArray(value))
320
465
  return [];
321
466
  return value.filter((entry) => entry && typeof entry === 'object' && entry.n && entry.text);
322
467
  }
468
+ /**
469
+ * A damage or condition list joined for display, or '' when there is nothing
470
+ * renderable. A string here would otherwise reach `.join` and throw.
471
+ * @param value The field as stored
472
+ * @returns The joined words, or '' to skip the line
473
+ */
323
474
  function words(value) {
324
475
  if (!Array.isArray(value) || value.length === 0)
325
476
  return '';
326
477
  return value.map((entry) => String(entry)).join(', ');
327
478
  }
479
+ /** The modifier for a raw ability score. */
328
480
  function abilityModifier(score) {
329
481
  return Math.floor(((Number(score) || 10) - 10) / 2);
330
482
  }
@@ -1,9 +1,37 @@
1
+ /**
2
+ * The room's `Magic Items` artifact: items that belong to one campaign rather than
3
+ * to the book.
4
+ *
5
+ * Deliberately the same design as `bestiary.ts` — a readable render above a fenced
6
+ * `briyah-state` block, campaign entries winning over the shipped table, and a
7
+ * refusal rather than an overwrite when the state block cannot be read. A game
8
+ * that wants a different cloak of elvenkind says so here without touching code.
9
+ */
1
10
  import { MagicItem } from '../data/magic-items';
2
11
  export declare const ITEMS_ARTIFACT = "Magic Items";
3
12
  export declare class ItemError extends Error {
4
13
  readonly violation: string;
5
14
  constructor(violation: string, message: string);
6
15
  }
16
+ /**
17
+ * Reads the campaign items out of a `Magic Items` artifact body.
18
+ * @param body The artifact body, or undefined when the artifact does not exist
19
+ * @returns Items keyed by normalized name; empty when absent
20
+ * @throws {ItemError} When the state block exists but cannot be read, so a caller
21
+ * refuses rather than destroying what survives.
22
+ */
7
23
  export declare function parseCampaignItems(body: string | undefined): Record<string, MagicItem>;
24
+ /**
25
+ * Fills in defaults and rejects an item that could not be used at a table.
26
+ * @param name The item name the caller supplied
27
+ * @param raw The item as written
28
+ * @returns An item with every required field present
29
+ * @throws {ItemError} When the definition is missing what an item needs
30
+ */
8
31
  export declare function normalizeItem(name: string, raw: any): MagicItem;
32
+ /**
33
+ * Renders the whole campaign items artifact.
34
+ * @param entries Items keyed by normalized name
35
+ * @returns The artifact body
36
+ */
9
37
  export declare function renderCampaignItems(entries: Record<string, MagicItem>): string;
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ /**
3
+ * The room's `Magic Items` artifact: items that belong to one campaign rather than
4
+ * to the book.
5
+ *
6
+ * Deliberately the same design as `bestiary.ts` — a readable render above a fenced
7
+ * `briyah-state` block, campaign entries winning over the shipped table, and a
8
+ * refusal rather than an overwrite when the state block cannot be read. A game
9
+ * that wants a different cloak of elvenkind says so here without touching code.
10
+ */
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.ItemError = exports.ITEMS_ARTIFACT = void 0;
4
13
  exports.parseCampaignItems = parseCampaignItems;
@@ -17,6 +26,13 @@ class ItemError extends Error {
17
26
  }
18
27
  }
19
28
  exports.ItemError = ItemError;
29
+ /**
30
+ * Reads the campaign items out of a `Magic Items` artifact body.
31
+ * @param body The artifact body, or undefined when the artifact does not exist
32
+ * @returns Items keyed by normalized name; empty when absent
33
+ * @throws {ItemError} When the state block exists but cannot be read, so a caller
34
+ * refuses rather than destroying what survives.
35
+ */
20
36
  function parseCampaignItems(body) {
21
37
  if (!body || !body.trim())
22
38
  return {};
@@ -46,6 +62,13 @@ function parseCampaignItems(body) {
46
62
  }
47
63
  return out;
48
64
  }
65
+ /**
66
+ * Fills in defaults and rejects an item that could not be used at a table.
67
+ * @param name The item name the caller supplied
68
+ * @param raw The item as written
69
+ * @returns An item with every required field present
70
+ * @throws {ItemError} When the definition is missing what an item needs
71
+ */
49
72
  function normalizeItem(name, raw) {
50
73
  if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
51
74
  throw new ItemError('bad_item', `An item definition must be a JSON object. Example: {"name":"Kesh's signet","type":"ring","rarity":"rare","attunement":true,"text":"What it does."}`);
@@ -60,6 +83,7 @@ function normalizeItem(name, raw) {
60
83
  type: String(raw.type || 'wondrous item').toLowerCase(),
61
84
  text,
62
85
  };
86
+ // Bonuses are numbers the tools add to rolls; a string would concatenate.
63
87
  for (const field of ['acBonus', 'attackBonus', 'damageBonus', 'saveBonus']) {
64
88
  if (item[field] === undefined)
65
89
  continue;
@@ -78,6 +102,11 @@ function normalizeItem(name, raw) {
78
102
  }
79
103
  return item;
80
104
  }
105
+ /**
106
+ * Renders the whole campaign items artifact.
107
+ * @param entries Items keyed by normalized name
108
+ * @returns The artifact body
109
+ */
81
110
  function renderCampaignItems(entries) {
82
111
  const names = Object.keys(entries).sort();
83
112
  const lines = [
@@ -1,6 +1,37 @@
1
+ /**
2
+ * Keeping a caster's attack cantrips on their `attacks` list.
3
+ *
4
+ * The same job {@link syncWeaponAttacks} does for carried weapons, for the one kind
5
+ * of spell that is mechanically a weapon. A cantrip is chosen once and never
6
+ * prepared, so a caster who knows Fire Bolt can always cast it — which makes the
7
+ * sheet, not the spell list, the right place for it to live.
8
+ *
9
+ * Pure, with no room access, like the rest of `engine/`.
10
+ */
1
11
  import { AttackEntry, SheetState } from './sheet';
12
+ /**
13
+ * Rebuilds the attack entries for the attack cantrips a character knows.
14
+ *
15
+ * Entries are derived rather than merged: the attack bonus follows the spellcasting
16
+ * ability and the proficiency bonus, and the dice step up at 5th, 11th and 17th
17
+ * level, so a stored copy goes stale the moment the character levels. A cantrip that
18
+ * has been unlearned loses its entry for the same reason.
19
+ *
20
+ * A hand-written attack that happens to share a cantrip's name is replaced. That is
21
+ * the intent: the tools' number is the correct one, and the alternative is a wizard
22
+ * whose Fire Bolt quietly keeps a level-1 bonus for the rest of the campaign.
23
+ *
24
+ * @param state The character, mutated in place
25
+ * @returns The cantrips added and removed, for the caller to report
26
+ */
2
27
  export declare function syncCantripAttacks(state: SheetState): {
3
28
  added: string[];
4
29
  removed: string[];
5
30
  };
31
+ /**
32
+ * Builds one cantrip's attack entry from the character's own numbers.
33
+ * @param state The character
34
+ * @param name The cantrip, as the character spells it
35
+ * @returns The attack entry
36
+ */
6
37
  export declare function cantripAttack(state: SheetState, name: string): AttackEntry;
@@ -1,4 +1,14 @@
1
1
  "use strict";
2
+ /**
3
+ * Keeping a caster's attack cantrips on their `attacks` list.
4
+ *
5
+ * The same job {@link syncWeaponAttacks} does for carried weapons, for the one kind
6
+ * of spell that is mechanically a weapon. A cantrip is chosen once and never
7
+ * prepared, so a caster who knows Fire Bolt can always cast it — which makes the
8
+ * sheet, not the spell list, the right place for it to live.
9
+ *
10
+ * Pure, with no room access, like the rest of `engine/`.
11
+ */
2
12
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
13
  if (k2 === undefined) k2 = k;
4
14
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -37,10 +47,27 @@ exports.syncCantripAttacks = syncCantripAttacks;
37
47
  exports.cantripAttack = cantripAttack;
38
48
  const cantrips_1 = require("../data/cantrips");
39
49
  const rules = __importStar(require("./rules"));
50
+ /** How a cantrip name is matched, ignoring case and stray spaces. */
40
51
  function key(name) {
41
52
  return name.trim().toLowerCase();
42
53
  }
54
+ /**
55
+ * Rebuilds the attack entries for the attack cantrips a character knows.
56
+ *
57
+ * Entries are derived rather than merged: the attack bonus follows the spellcasting
58
+ * ability and the proficiency bonus, and the dice step up at 5th, 11th and 17th
59
+ * level, so a stored copy goes stale the moment the character levels. A cantrip that
60
+ * has been unlearned loses its entry for the same reason.
61
+ *
62
+ * A hand-written attack that happens to share a cantrip's name is replaced. That is
63
+ * the intent: the tools' number is the correct one, and the alternative is a wizard
64
+ * whose Fire Bolt quietly keeps a level-1 bonus for the rest of the campaign.
65
+ *
66
+ * @param state The character, mutated in place
67
+ * @returns The cantrips added and removed, for the caller to report
68
+ */
43
69
  function syncCantripAttacks(state) {
70
+ // A monster's attacks come off its stat block whole; nothing here applies.
44
71
  if (state.foe)
45
72
  return { added: [], removed: [] };
46
73
  const known = new Map();
@@ -54,11 +81,11 @@ function syncCantripAttacks(state) {
54
81
  for (const attack of state.attacks) {
55
82
  const cantrip = cantrips_1.CANTRIP_ATTACKS[key(attack.n)];
56
83
  if (!cantrip) {
57
- kept.push(attack);
84
+ kept.push(attack); // Not a cantrip: a weapon, or something hand-written.
58
85
  continue;
59
86
  }
60
87
  if (known.has(key(attack.n)))
61
- continue;
88
+ continue; // Rebuilt below, so it cannot go stale.
62
89
  removed.push(attack.n);
63
90
  }
64
91
  for (const [, name] of known) {
@@ -69,6 +96,12 @@ function syncCantripAttacks(state) {
69
96
  state.attacks = kept;
70
97
  return { added, removed };
71
98
  }
99
+ /**
100
+ * Builds one cantrip's attack entry from the character's own numbers.
101
+ * @param state The character
102
+ * @param name The cantrip, as the character spells it
103
+ * @returns The attack entry
104
+ */
72
105
  function cantripAttack(state, name) {
73
106
  const cantrip = cantrips_1.CANTRIP_ATTACKS[key(name)];
74
107
  const entry = {
@@ -83,6 +116,7 @@ function cantripAttack(state, name) {
83
116
  entry.note = cantrip.note;
84
117
  return entry;
85
118
  }
119
+ /** Title-cases a cantrip name, so the sheet reads 'Fire Bolt' whatever was typed. */
86
120
  function titleCase(name) {
87
121
  return name
88
122
  .trim()