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,14 +1,32 @@
1
+ /**
2
+ * Magic item lookup, and the bonuses an attuned item contributes.
3
+ *
4
+ * Resolution mirrors `bestiary.ts` exactly, for the same reason: a partial name
5
+ * that matches several items reports the candidates rather than picking one, and a
6
+ * campaign's own items override the book. Pure, with no room access.
7
+ */
1
8
  import { MagicItem, MAX_ATTUNED_ITEMS } from '../data/magic-items';
2
9
  import type { SheetState } from './sheet';
10
+ /** How many names a listing returns before it asks the caller to narrow. */
3
11
  export declare const ITEM_LIST_CAP = 60;
12
+ /** How many suggestions a failed lookup offers. */
4
13
  export declare const ITEM_NEAR_MATCH_CAP = 8;
5
14
  export type ItemSource = 'campaign' | 'srd';
15
+ /** The outcome of an item lookup. Not a discriminated union — see `MonsterLookup`. */
6
16
  export interface ItemLookup {
7
17
  item?: MagicItem;
8
18
  source?: ItemSource;
19
+ /** Candidate names when the query matched several. */
9
20
  ambiguous?: string[];
10
21
  }
22
+ /** Resets the item index. Only needed by tests that mutate the table. */
11
23
  export declare function resetItemIndex(): void;
24
+ /**
25
+ * Resolves an item name, preferring the campaign's own entry.
26
+ * @param name The item the caller asked for
27
+ * @param campaign Campaign items keyed by normalized name
28
+ * @returns The item, the candidates, or an empty result
29
+ */
12
30
  export declare function resolveItem(name: string, campaign?: Record<string, MagicItem>): ItemLookup;
13
31
  export interface ItemListing {
14
32
  campaign: string[];
@@ -18,14 +36,53 @@ export interface ItemListing {
18
36
  truncated?: boolean;
19
37
  filter?: string;
20
38
  }
39
+ /**
40
+ * Lists the items available, capped and optionally filtered.
41
+ *
42
+ * The filter matches the name, the type and the rarity, so `filter: "ring"` and
43
+ * `filter: "legendary"` both narrow usefully — with 239 items a name-only filter
44
+ * leaves the list still truncated most of the time.
45
+ * @param campaign Campaign items
46
+ * @param filter Optional text to narrow by
47
+ * @returns The listing, with totals so the caller knows it was capped
48
+ */
21
49
  export declare function availableItems(campaign?: Record<string, MagicItem>, filter?: string): ItemListing;
50
+ /**
51
+ * Suggests items a failed lookup might have meant. Bounded, so a miss never
52
+ * returns the whole table.
53
+ * @param name The name that failed
54
+ * @param campaign Campaign items
55
+ * @param limit How many to return
56
+ * @returns The closest names, best first
57
+ */
22
58
  export declare function nearItems(name: string, campaign?: Record<string, MagicItem>, limit?: number): string[];
59
+ /** Renders one item as readable markdown. */
23
60
  export declare function describeItem(item: MagicItem): string;
61
+ /** An item on a sheet, paired with its table entry when it has one. */
24
62
  export interface AttunedItem {
25
63
  name: string;
26
64
  item?: MagicItem;
27
65
  }
66
+ /**
67
+ * The items this character is attuned to.
68
+ *
69
+ * Attunement lives on the inventory entry as `att`, so it travels with the item
70
+ * and cannot drift from what they are carrying.
71
+ * @param state The character
72
+ * @param campaign Campaign items, for resolving names
73
+ * @returns One entry per attuned item, in inventory order
74
+ */
28
75
  export declare function attunedItems(state: SheetState, campaign?: Record<string, MagicItem>): AttunedItem[];
76
+ /**
77
+ * The armour class contribution of the character's magic items.
78
+ *
79
+ * Only counts an item that is **attuned when it needs to be**: a ring of
80
+ * protection does nothing in a pocket, and nothing on a finger without attunement.
81
+ * An item that needs no attunement counts once equipped.
82
+ * @param state The character
83
+ * @param campaign Campaign items
84
+ * @returns The total bonus and which items gave it
85
+ */
29
86
  export declare function magicAcBonus(state: SheetState, campaign?: Record<string, MagicItem>): {
30
87
  bonus: number;
31
88
  sources: string[];
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ /**
3
+ * Magic item lookup, and the bonuses an attuned item contributes.
4
+ *
5
+ * Resolution mirrors `bestiary.ts` exactly, for the same reason: a partial name
6
+ * that matches several items reports the candidates rather than picking one, and a
7
+ * campaign's own items override the book. Pure, with no room access.
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  exports.MAX_ATTUNED_ITEMS = exports.ITEM_NEAR_MATCH_CAP = exports.ITEM_LIST_CAP = void 0;
4
11
  exports.resetItemIndex = resetItemIndex;
@@ -11,7 +18,9 @@ exports.magicAcBonus = magicAcBonus;
11
18
  const magic_items_1 = require("../data/magic-items");
12
19
  Object.defineProperty(exports, "MAX_ATTUNED_ITEMS", { enumerable: true, get: function () { return magic_items_1.MAX_ATTUNED_ITEMS; } });
13
20
  const coerce_1 = require("./coerce");
21
+ /** How many names a listing returns before it asks the caller to narrow. */
14
22
  exports.ITEM_LIST_CAP = 60;
23
+ /** How many suggestions a failed lookup offers. */
15
24
  exports.ITEM_NEAR_MATCH_CAP = 8;
16
25
  let itemIndexCache = null;
17
26
  function itemIndex() {
@@ -23,9 +32,16 @@ function itemIndex() {
23
32
  }
24
33
  return itemIndexCache;
25
34
  }
35
+ /** Resets the item index. Only needed by tests that mutate the table. */
26
36
  function resetItemIndex() {
27
37
  itemIndexCache = null;
28
38
  }
39
+ /**
40
+ * Resolves an item name, preferring the campaign's own entry.
41
+ * @param name The item the caller asked for
42
+ * @param campaign Campaign items keyed by normalized name
43
+ * @returns The item, the candidates, or an empty result
44
+ */
29
45
  function resolveItem(name, campaign = {}) {
30
46
  const key = (0, coerce_1.nameKey)(name || '');
31
47
  if (!key)
@@ -50,6 +66,16 @@ function resolveItem(name, campaign = {}) {
50
66
  }
51
67
  return {};
52
68
  }
69
+ /**
70
+ * Lists the items available, capped and optionally filtered.
71
+ *
72
+ * The filter matches the name, the type and the rarity, so `filter: "ring"` and
73
+ * `filter: "legendary"` both narrow usefully — with 239 items a name-only filter
74
+ * leaves the list still truncated most of the time.
75
+ * @param campaign Campaign items
76
+ * @param filter Optional text to narrow by
77
+ * @returns The listing, with totals so the caller knows it was capped
78
+ */
53
79
  function availableItems(campaign = {}, filter) {
54
80
  const needle = (0, coerce_1.nameKey)(filter || '');
55
81
  const keep = (item) => !needle ||
@@ -69,6 +95,14 @@ function availableItems(campaign = {}, filter) {
69
95
  filter: filter || undefined,
70
96
  };
71
97
  }
98
+ /**
99
+ * Suggests items a failed lookup might have meant. Bounded, so a miss never
100
+ * returns the whole table.
101
+ * @param name The name that failed
102
+ * @param campaign Campaign items
103
+ * @param limit How many to return
104
+ * @returns The closest names, best first
105
+ */
72
106
  function nearItems(name, campaign = {}, limit = exports.ITEM_NEAR_MATCH_CAP) {
73
107
  const words = (0, coerce_1.nameKey)(name).split(' ').filter((w) => w.length > 2);
74
108
  if (words.length === 0)
@@ -87,6 +121,7 @@ function nearItems(name, campaign = {}, limit = exports.ITEM_NEAR_MATCH_CAP) {
87
121
  .slice(0, limit)
88
122
  .map((entry) => entry.candidate);
89
123
  }
124
+ /** Renders one item as readable markdown. */
90
125
  function describeItem(item) {
91
126
  const descriptor = [
92
127
  item.subtype ? `${item.type} (${item.subtype})` : item.type,
@@ -115,11 +150,30 @@ function describeItem(item) {
115
150
  lines.push('', item.text);
116
151
  return lines.join('\n');
117
152
  }
153
+ /**
154
+ * The items this character is attuned to.
155
+ *
156
+ * Attunement lives on the inventory entry as `att`, so it travels with the item
157
+ * and cannot drift from what they are carrying.
158
+ * @param state The character
159
+ * @param campaign Campaign items, for resolving names
160
+ * @returns One entry per attuned item, in inventory order
161
+ */
118
162
  function attunedItems(state, campaign = {}) {
119
163
  return state.inv
120
164
  .filter((entry) => entry.att)
121
165
  .map((entry) => ({ name: entry.n, item: resolveItem(entry.n, campaign).item }));
122
166
  }
167
+ /**
168
+ * The armour class contribution of the character's magic items.
169
+ *
170
+ * Only counts an item that is **attuned when it needs to be**: a ring of
171
+ * protection does nothing in a pocket, and nothing on a finger without attunement.
172
+ * An item that needs no attunement counts once equipped.
173
+ * @param state The character
174
+ * @param campaign Campaign items
175
+ * @returns The total bonus and which items gave it
176
+ */
123
177
  function magicAcBonus(state, campaign = {}) {
124
178
  let bonus = 0;
125
179
  const sources = [];
@@ -1,19 +1,100 @@
1
+ /**
2
+ * Tool proficiency: resolving a tool by name, and applying what a class, race or
3
+ * background grants.
4
+ *
5
+ * Named for `data/kits.ts` and for the same reason — "tools" is taken by the Briyah
6
+ * tool layer in `tools/`.
7
+ *
8
+ * Unlike weapon proficiency, which {@link isProficientWith} derives from the race and
9
+ * class every time it is needed, tool proficiency is **stored** on the sheet. It has
10
+ * to be: most of it is chosen rather than granted. A bard picks three instruments out
11
+ * of ten and a dwarf picks one artisan's tool out of three, and there is nowhere to
12
+ * derive that choice from.
13
+ *
14
+ * Pure, with no room access, like the rest of `engine/`.
15
+ */
1
16
  import { ToolCategory, ToolGrant, ToolKit } from '../data/kits';
2
17
  import type { SheetState } from './sheet';
3
18
  export interface ToolLookup {
4
19
  tool?: ToolKit;
20
+ /** Candidate names when a partial name matched several. */
5
21
  ambiguous?: string[];
6
22
  }
23
+ /**
24
+ * Resolves a tool name against the SRD table.
25
+ *
26
+ * Resolves the same way creatures, items and spells do: an exact keyed hit first,
27
+ * `matchNames` tiers only on a miss, and ambiguity reported rather than picked.
28
+ * @param name The tool as written
29
+ * @returns The tool, candidates, or an empty result for one outside the SRD
30
+ */
7
31
  export declare function resolveTool(name: string): ToolLookup;
32
+ /**
33
+ * The table's spelling of a tool, or the name as written when it is not in the table.
34
+ *
35
+ * Never refuses. A table that plays with a tool the SRD does not carry keeps it
36
+ * exactly as they typed it, which is the same stance backgrounds and feats take.
37
+ * @param name The tool as written
38
+ * @returns The canonical name, trimmed
39
+ */
8
40
  export declare function canonicalToolName(name: string): string;
41
+ /** Every tool name in the SRD table, sorted. */
9
42
  export declare function toolNames(): string[];
43
+ /** The tools in a category, for a message naming what a choice may be spent on. */
10
44
  export declare function toolsInCategory(category: ToolCategory): string[];
45
+ /** Canonicalizes a list of tool names, dropping blanks and duplicates. */
11
46
  export declare function canonicalToolNames(names: string[] | undefined): string[];
47
+ /**
48
+ * Whether the character is proficient with a tool.
49
+ *
50
+ * Compared through {@link nameKey}, so a sheet holding `Thieves' tools` answers to
51
+ * `thieves tools` and `Thieves' Tools` alike.
52
+ * @param state The character
53
+ * @param name The tool
54
+ * @returns True when it is on their sheet
55
+ */
12
56
  export declare function hasToolProficiency(state: SheetState, name: string): boolean;
57
+ /**
58
+ * Whether the character has expertise with a tool — a rogue who spent one of their
59
+ * two Expertise picks on thieves' tools rather than on a second skill.
60
+ * @param state The character
61
+ * @param name The tool
62
+ * @returns True when the proficiency bonus is doubled for it
63
+ */
13
64
  export declare function hasToolExpertise(state: SheetState, name: string): boolean;
65
+ /**
66
+ * Adds a tool proficiency to a character.
67
+ * @param state The character, mutated in place
68
+ * @param name The tool
69
+ * @returns True when it was added, false when they already had it
70
+ */
14
71
  export declare function addToolProficiency(state: SheetState, name: string): boolean;
15
72
  export interface ToolGrantResult {
73
+ /** Proficiencies actually written to the sheet. */
16
74
  added: string[];
75
+ /** Choices the player still has to make, in plain language. */
17
76
  outstanding: string[];
18
77
  }
78
+ /**
79
+ * Applies a tool grant, writing what is granted outright and reporting what is not.
80
+ *
81
+ * A tool the character already has is **not** silently skipped. The rules say to take
82
+ * a different proficiency of the same kind instead, which is a choice, so it comes
83
+ * back in `outstanding` for the player to make — the same handling `applyBackground`
84
+ * gives a duplicated skill.
85
+ *
86
+ * Choices are settled against what the character already holds, because the player's
87
+ * picks arrive in the spec and are on the sheet before this runs: a bard listing three
88
+ * instruments owes nothing, and a bard listing one still owes two.
89
+ *
90
+ * Pass the same `consumed` set to every grant a character receives, or one pick will
91
+ * settle two choices and the player quietly loses a proficiency — a dwarf monk offered
92
+ * an artisan's tool by each has to name two, not one.
93
+ *
94
+ * @param state The character, mutated in place
95
+ * @param grant What the class, race or background gives
96
+ * @param source What is doing the granting, for the message
97
+ * @param consumed Tool keys already spent settling an earlier choice, added to here
98
+ * @returns What was written and what the player still owes
99
+ */
19
100
  export declare function grantTools(state: SheetState, grant: ToolGrant | undefined, source: string, consumed?: Set<string>): ToolGrantResult;
@@ -1,4 +1,19 @@
1
1
  "use strict";
2
+ /**
3
+ * Tool proficiency: resolving a tool by name, and applying what a class, race or
4
+ * background grants.
5
+ *
6
+ * Named for `data/kits.ts` and for the same reason — "tools" is taken by the Briyah
7
+ * tool layer in `tools/`.
8
+ *
9
+ * Unlike weapon proficiency, which {@link isProficientWith} derives from the race and
10
+ * class every time it is needed, tool proficiency is **stored** on the sheet. It has
11
+ * to be: most of it is chosen rather than granted. A bard picks three instruments out
12
+ * of ten and a dwarf picks one artisan's tool out of three, and there is nowhere to
13
+ * derive that choice from.
14
+ *
15
+ * Pure, with no room access, like the rest of `engine/`.
16
+ */
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.resolveTool = resolveTool;
4
19
  exports.canonicalToolName = canonicalToolName;
@@ -11,6 +26,14 @@ exports.addToolProficiency = addToolProficiency;
11
26
  exports.grantTools = grantTools;
12
27
  const kits_1 = require("../data/kits");
13
28
  const coerce_1 = require("./coerce");
29
+ /**
30
+ * Resolves a tool name against the SRD table.
31
+ *
32
+ * Resolves the same way creatures, items and spells do: an exact keyed hit first,
33
+ * `matchNames` tiers only on a miss, and ambiguity reported rather than picked.
34
+ * @param name The tool as written
35
+ * @returns The tool, candidates, or an empty result for one outside the SRD
36
+ */
14
37
  function resolveTool(name) {
15
38
  const key = (0, coerce_1.nameKey)(name || '');
16
39
  if (!key)
@@ -26,20 +49,31 @@ function resolveTool(name) {
26
49
  }
27
50
  return {};
28
51
  }
52
+ /**
53
+ * The table's spelling of a tool, or the name as written when it is not in the table.
54
+ *
55
+ * Never refuses. A table that plays with a tool the SRD does not carry keeps it
56
+ * exactly as they typed it, which is the same stance backgrounds and feats take.
57
+ * @param name The tool as written
58
+ * @returns The canonical name, trimmed
59
+ */
29
60
  function canonicalToolName(name) {
30
61
  const written = String(name || '').trim();
31
62
  const { tool } = resolveTool(written);
32
63
  return tool ? tool.name : written;
33
64
  }
65
+ /** Every tool name in the SRD table, sorted. */
34
66
  function toolNames() {
35
67
  return Object.values(kits_1.TOOL_KITS).map((tool) => tool.name).sort();
36
68
  }
69
+ /** The tools in a category, for a message naming what a choice may be spent on. */
37
70
  function toolsInCategory(category) {
38
71
  return Object.values(kits_1.TOOL_KITS)
39
72
  .filter((tool) => tool.category === category)
40
73
  .map((tool) => tool.name)
41
74
  .sort();
42
75
  }
76
+ /** Canonicalizes a list of tool names, dropping blanks and duplicates. */
43
77
  function canonicalToolNames(names) {
44
78
  if (!Array.isArray(names))
45
79
  return [];
@@ -57,18 +91,40 @@ function canonicalToolNames(names) {
57
91
  }
58
92
  return out;
59
93
  }
94
+ /**
95
+ * Whether the character is proficient with a tool.
96
+ *
97
+ * Compared through {@link nameKey}, so a sheet holding `Thieves' tools` answers to
98
+ * `thieves tools` and `Thieves' Tools` alike.
99
+ * @param state The character
100
+ * @param name The tool
101
+ * @returns True when it is on their sheet
102
+ */
60
103
  function hasToolProficiency(state, name) {
61
104
  const key = (0, coerce_1.nameKey)(canonicalToolName(name));
62
105
  if (!key)
63
106
  return false;
64
107
  return (state.toolProf || []).some((held) => (0, coerce_1.nameKey)(held) === key);
65
108
  }
109
+ /**
110
+ * Whether the character has expertise with a tool — a rogue who spent one of their
111
+ * two Expertise picks on thieves' tools rather than on a second skill.
112
+ * @param state The character
113
+ * @param name The tool
114
+ * @returns True when the proficiency bonus is doubled for it
115
+ */
66
116
  function hasToolExpertise(state, name) {
67
117
  const key = (0, coerce_1.nameKey)(canonicalToolName(name));
68
118
  if (!key)
69
119
  return false;
70
120
  return (state.toolExp || []).some((held) => (0, coerce_1.nameKey)(held) === key);
71
121
  }
122
+ /**
123
+ * Adds a tool proficiency to a character.
124
+ * @param state The character, mutated in place
125
+ * @param name The tool
126
+ * @returns True when it was added, false when they already had it
127
+ */
72
128
  function addToolProficiency(state, name) {
73
129
  const canonical = canonicalToolName(name);
74
130
  if (!canonical || hasToolProficiency(state, canonical))
@@ -76,6 +132,7 @@ function addToolProficiency(state, name) {
76
132
  state.toolProf = [...(state.toolProf || []), canonical];
77
133
  return true;
78
134
  }
135
+ /** Whether a tool the character holds counts towards a particular choice. */
79
136
  function satisfiesChoice(held, choice) {
80
137
  const key = (0, coerce_1.nameKey)(held);
81
138
  if (choice.options) {
@@ -84,6 +141,7 @@ function satisfiesChoice(held, choice) {
84
141
  const { tool } = resolveTool(held);
85
142
  return Boolean(tool && choice.from?.includes(tool.category));
86
143
  }
144
+ /** How a choice reads when the player still owes it. */
87
145
  function describeChoice(choice, owed) {
88
146
  const what = choice.options
89
147
  ? choice.options.join(', ')
@@ -92,6 +150,28 @@ function describeChoice(choice, owed) {
92
150
  .join(' or ');
93
151
  return `${owed} tool proficienc${owed === 1 ? 'y' : 'ies'} of the player's choice: ${what}`;
94
152
  }
153
+ /**
154
+ * Applies a tool grant, writing what is granted outright and reporting what is not.
155
+ *
156
+ * A tool the character already has is **not** silently skipped. The rules say to take
157
+ * a different proficiency of the same kind instead, which is a choice, so it comes
158
+ * back in `outstanding` for the player to make — the same handling `applyBackground`
159
+ * gives a duplicated skill.
160
+ *
161
+ * Choices are settled against what the character already holds, because the player's
162
+ * picks arrive in the spec and are on the sheet before this runs: a bard listing three
163
+ * instruments owes nothing, and a bard listing one still owes two.
164
+ *
165
+ * Pass the same `consumed` set to every grant a character receives, or one pick will
166
+ * settle two choices and the player quietly loses a proficiency — a dwarf monk offered
167
+ * an artisan's tool by each has to name two, not one.
168
+ *
169
+ * @param state The character, mutated in place
170
+ * @param grant What the class, race or background gives
171
+ * @param source What is doing the granting, for the message
172
+ * @param consumed Tool keys already spent settling an earlier choice, added to here
173
+ * @returns What was written and what the player still owes
174
+ */
95
175
  function grantTools(state, grant, source, consumed = new Set()) {
96
176
  const result = { added: [], outstanding: [] };
97
177
  if (!grant)
@@ -104,6 +184,8 @@ function grantTools(state, grant, source, consumed = new Set()) {
104
184
  }
105
185
  addToolProficiency(state, canonical);
106
186
  result.added.push(canonical);
187
+ // Spent: a proficiency granted outright must not also settle a choice, or the
188
+ // player is one pick short and never told.
107
189
  consumed.add((0, coerce_1.nameKey)(canonical));
108
190
  }
109
191
  for (const choice of grant.choices || []) {
@@ -120,6 +202,9 @@ function grantTools(state, grant, source, consumed = new Set()) {
120
202
  if (owed > 0)
121
203
  result.outstanding.push(describeChoice(choice, owed));
122
204
  }
205
+ // A tool outside the SRD table cannot be proven to be an instrument, so it does
206
+ // not settle a category choice. Say so rather than letting the reader wonder why
207
+ // the ocarina they listed did not count.
123
208
  if (result.outstanding.length > 0) {
124
209
  const unknown = (state.toolProf || []).filter((held) => !resolveTool(held).tool);
125
210
  if (unknown.length > 0) {
@@ -1,27 +1,87 @@
1
+ /**
2
+ * Resolving a race from free text, and applying what it grants.
3
+ *
4
+ * `race` on a sheet is whatever someone typed — "Hill Dwarf", "wood elf",
5
+ * "Human" — so resolution is deliberately forgiving in one direction only: an
6
+ * unrecognised *subrace* still resolves to its base race, because SRD 5.1 carries
7
+ * one subrace per race and plenty of tables play with more. An unrecognised
8
+ * *race* resolves to nothing, since guessing one would silently change a
9
+ * character's ability scores.
10
+ *
11
+ * Pure, with no room access, like the rest of `engine/`.
12
+ */
1
13
  import { AbilityKey } from '../data/srd';
2
14
  import { RaceRules, RaceTrait, SubraceRules } from '../data/races';
3
15
  import type { SheetState } from './sheet';
4
16
  export interface RaceLookup {
17
+ /** The `RACES` key, for tables keyed the same way. */
5
18
  key?: string;
6
19
  race?: RaceRules;
7
20
  subrace?: SubraceRules;
21
+ /**
22
+ * A subrace the SRD does not carry, kept so it can be reported rather than
23
+ * silently dropped: "Mountain Dwarf" is a real thing, just not here.
24
+ */
8
25
  unknownSubrace?: string;
9
26
  }
27
+ /** Resets the race index. Only needed by tests that mutate the table. */
10
28
  export declare function resetRaceIndex(): void;
29
+ /**
30
+ * Resolves a race, and a subrace when one is named.
31
+ * @param input The race as written on the sheet or by a player
32
+ * @returns The race and subrace, or an empty result when no race matched
33
+ */
11
34
  export declare function resolveRace(input: string): RaceLookup;
35
+ /** Every race name, and every subrace, for an error message or a listing. */
12
36
  export declare function raceNames(): string[];
37
+ /** The ability increases a race and subrace grant, combined. */
13
38
  export declare function racialAbilityIncreases(lookup: RaceLookup): Partial<Record<AbilityKey, number>>;
14
39
  export interface RaceApplication {
40
+ /** What was recognised, for the caller to echo back. */
15
41
  race?: string;
16
42
  subrace?: string;
43
+ /** Ability increases actually applied, so a reader can check the arithmetic. */
17
44
  increases: Partial<Record<AbilityKey, number>>;
45
+ /** Tool proficiencies the race granted outright. */
18
46
  tools: string[];
47
+ /** Things the player still has to pick, in plain language. */
19
48
  outstanding: string[];
49
+ /** Anything that could not be applied as asked. */
20
50
  problems: string[];
21
51
  }
52
+ /**
53
+ * Applies a race to a freshly built character.
54
+ *
55
+ * **Call this exactly once, at creation.** The ability increases go into `abil`,
56
+ * which then holds the character's real scores — there is no separate "base"
57
+ * anywhere, so applying twice would raise them twice. `recomputeDerived` reads the
58
+ * race for hit points and speed but never touches ability scores, which is what
59
+ * makes levelling up safe.
60
+ * @param state The character, mutated in place
61
+ * @param chosen Ability increases the player picked, where the race offers a choice
62
+ * @param consumedTools Tool picks already spent settling another source's choice
63
+ * @returns What was applied and what the player still owes
64
+ */
22
65
  export declare function applyRace(state: SheetState, chosen?: Partial<Record<AbilityKey, number>>, consumedTools?: Set<string>): RaceApplication;
66
+ /**
67
+ * Weapon table keys the character's race grants proficiency with.
68
+ *
69
+ * Separate from `applyRace` because proficiency is consulted every time an attack
70
+ * line is built, not stored — the same reason class proficiency is not stored.
71
+ * @param state The character
72
+ * @returns Weapon keys, empty when the race grants none
73
+ */
23
74
  export declare function racialWeaponProficiencies(state: SheetState): string[];
75
+ /**
76
+ * Extra hit points per level from the race — the hill dwarf's Dwarven Toughness.
77
+ * Derived rather than stored, so it stays right as the character levels.
78
+ * @param state The character
79
+ * @returns Hit points to add for every level
80
+ */
24
81
  export declare function racialHpPerLevel(state: SheetState): number;
82
+ /** True when heavy armour does not slow this character — the dwarf only. */
25
83
  export declare function ignoresHeavyArmorSpeed(state: SheetState): boolean;
84
+ /** The racial traits a character has, for the sheet render and `read_sheet`. */
26
85
  export declare function racialTraits(state: SheetState): RaceTrait[];
86
+ /** Renders a race as readable markdown, for a rules lookup. */
27
87
  export declare function describeRace(race: RaceRules, subrace?: SubraceRules): string;