briyah 2.0.3 → 2.0.5

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 (391) hide show
  1. package/README.md +55 -8
  2. package/data/common/config/LICENSE-model-prices.md +65 -0
  3. package/data/common/config/markup +1 -1
  4. package/data/common/config/model_prices.json +47443 -46295
  5. package/data/common/config/story_models.json +3 -3
  6. package/data/common/prompts/illustrator/describe_scene.prompt +4 -4
  7. package/data/common/prompts/narrator/create_story.prompt +2 -0
  8. package/data/common/prompts/perceive.prompt +1 -1
  9. package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +1 -1
  10. package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +1 -1
  11. package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +795 -787
  12. package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +2 -1
  13. package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +1 -1
  14. package/data/packs/dnd5e/rooms/campaign.json +18 -15
  15. package/data/packs/dnd5e/rooms/table.json +17 -16
  16. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
  17. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +174 -3
  18. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +194 -3
  19. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +299 -19
  20. package/dist-sdk/server/src/ai/LLM/blank-image.d.ts +36 -0
  21. package/dist-sdk/server/src/ai/LLM/blank-image.js +80 -0
  22. package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
  23. package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
  24. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
  25. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
  26. package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
  27. package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
  28. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
  29. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +103 -4
  30. package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
  31. package/dist-sdk/server/src/ai/LLM/fal.service.js +56 -2
  32. package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
  33. package/dist-sdk/server/src/ai/LLM/googleai.service.js +43 -2
  34. package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
  35. package/dist-sdk/server/src/ai/LLM/grok.service.js +55 -3
  36. package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
  37. package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
  38. package/dist-sdk/server/src/ai/LLM/openai.service.js +81 -3
  39. package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
  40. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +45 -3
  41. package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
  42. package/dist-sdk/server/src/ai/LLM/together.service.js +61 -3
  43. package/dist-sdk/server/src/ai/agent-config.d.ts +15 -1
  44. package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
  45. package/dist-sdk/server/src/ai/agent-factory.js +20 -0
  46. package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
  47. package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
  48. package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
  49. package/dist-sdk/server/src/ai/agent-store.service.js +166 -7
  50. package/dist-sdk/server/src/ai/agent.d.ts +197 -2
  51. package/dist-sdk/server/src/ai/agent.js +225 -14
  52. package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
  53. package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
  54. package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
  55. package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
  56. package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
  57. package/dist-sdk/server/src/ai/artifact.service.js +148 -3
  58. package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
  59. package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
  60. package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
  61. package/dist-sdk/server/src/ai/model_prices.js +91 -5
  62. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
  63. package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
  64. package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
  65. package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
  66. package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
  67. package/dist-sdk/server/src/app/balance-message.service.js +24 -0
  68. package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
  69. package/dist-sdk/server/src/app/balance.module.js +4 -0
  70. package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
  71. package/dist-sdk/server/src/app/balance.service.js +54 -0
  72. package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
  73. package/dist-sdk/server/src/app/stripe.controller.js +35 -0
  74. package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
  75. package/dist-sdk/server/src/app/stripe.service.js +62 -0
  76. package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
  77. package/dist-sdk/server/src/app/transaction.service.js +36 -0
  78. package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
  79. package/dist-sdk/server/src/app/user-service-factory.js +46 -3
  80. package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
  81. package/dist-sdk/server/src/app/user-service-manager.js +43 -0
  82. package/dist-sdk/server/src/app.controller.d.ts +120 -0
  83. package/dist-sdk/server/src/app.controller.js +365 -14
  84. package/dist-sdk/server/src/app.module.js +28 -6
  85. package/dist-sdk/server/src/app.service.d.ts +1710 -4
  86. package/dist-sdk/server/src/app.service.js +1938 -20
  87. package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
  88. package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
  89. package/dist-sdk/server/src/auth/auth.controller.js +46 -0
  90. package/dist-sdk/server/src/auth/auth.module.js +3 -2
  91. package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
  92. package/dist-sdk/server/src/auth/auth.service.js +39 -3
  93. package/dist-sdk/server/src/auth/jwt-auth.guard.js +44 -0
  94. package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
  95. package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
  96. package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
  97. package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
  98. package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
  99. package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
  100. package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
  101. package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
  102. package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
  103. package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
  104. package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
  105. package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
  106. package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
  107. package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
  108. package/dist-sdk/server/src/auth/session.guard.js +8 -0
  109. package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
  110. package/dist-sdk/server/src/auth/twilio.service.js +30 -4
  111. package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
  112. package/dist-sdk/server/src/auth/users.service.js +42 -0
  113. package/dist-sdk/server/src/common/errors.d.ts +20 -0
  114. package/dist-sdk/server/src/common/errors.js +21 -0
  115. package/dist-sdk/server/src/config/env-config.d.ts +7 -0
  116. package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
  117. package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
  118. package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
  119. package/dist-sdk/server/src/config/user-config.service.js +57 -0
  120. package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
  121. package/dist-sdk/server/src/config/user-paths.service.js +67 -0
  122. package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
  123. package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
  124. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
  125. package/dist-sdk/server/src/packs/pack-instantiation.service.js +104 -0
  126. package/dist-sdk/server/src/packs/pack-manifest.d.ts +114 -0
  127. package/dist-sdk/server/src/packs/pack-manifest.js +69 -0
  128. package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
  129. package/dist-sdk/server/src/packs/pack.service.js +98 -1
  130. package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
  131. package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
  132. package/dist-sdk/server/src/room/artifact.d.ts +18 -0
  133. package/dist-sdk/server/src/room/illustration/illustration.service.d.ts +211 -0
  134. package/dist-sdk/server/src/room/illustration/illustration.service.js +771 -0
  135. package/dist-sdk/server/src/room/illustration/illustration.types.d.ts +101 -0
  136. package/dist-sdk/server/src/room/illustration/illustration.types.js +2 -0
  137. package/dist-sdk/server/src/room/message.d.ts +64 -0
  138. package/dist-sdk/server/src/room/message.js +77 -2
  139. package/dist-sdk/server/src/room/nickname.d.ts +26 -0
  140. package/dist-sdk/server/src/room/nickname.js +26 -0
  141. package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
  142. package/dist-sdk/server/src/room/room-config.d.ts +84 -1
  143. package/dist-sdk/server/src/room/room-config.js +19 -0
  144. package/dist-sdk/server/src/room/room-factory.d.ts +20 -0
  145. package/dist-sdk/server/src/room/room-factory.js +25 -0
  146. package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
  147. package/dist-sdk/server/src/room/room-message.service.js +28 -0
  148. package/dist-sdk/server/src/room/room-store.service.d.ts +184 -0
  149. package/dist-sdk/server/src/room/room-store.service.js +280 -6
  150. package/dist-sdk/server/src/room/room.d.ts +981 -1
  151. package/dist-sdk/server/src/room/room.js +1531 -27
  152. package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
  153. package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
  154. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
  155. package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
  156. package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
  157. package/dist-sdk/server/src/rpg/rpg.service.js +108 -1
  158. package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
  159. package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
  160. package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
  161. package/dist-sdk/server/src/sdk/briyah.js +285 -7
  162. package/dist-sdk/server/src/sdk/index.js +23 -0
  163. package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
  164. package/dist-sdk/server/src/shared/shared.module.js +13 -5
  165. package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
  166. package/dist-sdk/server/src/story/story-message.service.js +43 -0
  167. package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
  168. package/dist-sdk/server/src/story/story-progress.service.js +23 -0
  169. package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
  170. package/dist-sdk/server/src/story/story-store.service.js +136 -1
  171. package/dist-sdk/server/src/story/story.service.d.ts +366 -9
  172. package/dist-sdk/server/src/story/story.service.js +825 -374
  173. package/dist-sdk/server/src/tools/core/illustrate.tool.d.ts +14 -0
  174. package/dist-sdk/server/src/tools/core/illustrate.tool.js +80 -0
  175. package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
  176. package/dist-sdk/server/src/tools/core/index.js +24 -1
  177. package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
  178. package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
  179. package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
  180. package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
  181. package/dist-sdk/server/src/tools/native-tool.types.d.ts +266 -0
  182. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
  183. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
  184. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
  185. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
  186. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
  187. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
  188. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
  189. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
  190. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
  191. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
  192. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
  193. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
  194. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
  195. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
  196. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
  197. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
  198. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
  199. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
  200. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
  201. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
  202. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
  203. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
  204. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
  205. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
  206. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
  207. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
  208. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
  209. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
  210. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
  211. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
  212. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
  213. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
  214. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
  215. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
  216. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
  217. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
  218. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
  219. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
  220. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
  221. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
  222. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
  223. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
  224. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
  225. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
  226. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
  227. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
  228. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
  229. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
  230. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
  231. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
  232. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
  233. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
  234. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
  235. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
  236. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
  237. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
  238. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
  239. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
  240. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
  241. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
  242. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +201 -0
  243. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +149 -0
  244. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
  245. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
  246. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
  247. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
  248. package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
  249. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
  250. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
  251. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
  252. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
  253. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
  254. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
  255. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
  256. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
  257. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
  258. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
  259. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
  260. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
  261. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
  262. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +194 -0
  263. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +263 -1
  264. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
  265. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +127 -2
  266. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
  267. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
  268. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
  269. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
  270. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
  271. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
  272. package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
  273. package/dist-sdk/server/src/tools/packs/index.js +66 -0
  274. package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
  275. package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
  276. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +107 -3
  277. package/dist-sdk/server/src/tools/tool-execution.service.js +163 -19
  278. package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
  279. package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
  280. package/dist-sdk/shared/types/app.types.d.ts +328 -13
  281. package/dist-sdk/shared/types/app.types.js +18 -1
  282. package/package.json +167 -168
  283. package/data/common/config/random_words.txt +0 -2241
  284. package/data/common/story_ideas/biblical.json +0 -122
  285. package/data/common/story_ideas/fantasy.json +0 -82
  286. package/data/common/story_ideas/historical_fiction.json +0 -82
  287. package/data/common/story_ideas/science_fiction.json +0 -82
  288. package/docs/.nojekyll +0 -1
  289. package/docs/assets/hierarchy.js +0 -1
  290. package/docs/assets/highlight.css +0 -113
  291. package/docs/assets/icons.js +0 -18
  292. package/docs/assets/icons.svg +0 -1
  293. package/docs/assets/main.js +0 -60
  294. package/docs/assets/navigation.js +0 -1
  295. package/docs/assets/search.js +0 -1
  296. package/docs/assets/style.css +0 -1648
  297. package/docs/classes/Agent.html +0 -801
  298. package/docs/classes/Briyah.html +0 -296
  299. package/docs/classes/BriyahConfigService.html +0 -119
  300. package/docs/classes/NativeToolRegistry.html +0 -166
  301. package/docs/classes/PackInstantiationService.html +0 -157
  302. package/docs/classes/PackService.html +0 -247
  303. package/docs/classes/Room.html +0 -1434
  304. package/docs/classes/RoomMessage.html +0 -290
  305. package/docs/enums/MessageAction.html +0 -136
  306. package/docs/functions/availableToolPacks.html +0 -41
  307. package/docs/functions/buildMarkdown.html +0 -54
  308. package/docs/functions/dnd5eTools.html +0 -44
  309. package/docs/functions/installToolPacks.html +0 -51
  310. package/docs/functions/pageMarker.html +0 -45
  311. package/docs/functions/registerToolPacks.html +0 -54
  312. package/docs/functions/splitMarkdownIntoPages.html +0 -51
  313. package/docs/functions/stripWrappingFence.html +0 -52
  314. package/docs/hierarchy.html +0 -46
  315. package/docs/index.html +0 -595
  316. package/docs/interfaces/AgentCreationOptions.html +0 -125
  317. package/docs/interfaces/AgentInfo.html +0 -218
  318. package/docs/interfaces/AgentMessagesResponse.html +0 -74
  319. package/docs/interfaces/AppService.html +0 -3340
  320. package/docs/interfaces/Artifact.html +0 -95
  321. package/docs/interfaces/ArtifactMetadata.html +0 -112
  322. package/docs/interfaces/ArtifactWriteOptions.html +0 -90
  323. package/docs/interfaces/AttachDocumentResponse.html +0 -62
  324. package/docs/interfaces/BriyahConfigOptions.html +0 -124
  325. package/docs/interfaces/ChapterInfo.html +0 -62
  326. package/docs/interfaces/Character.html +0 -86
  327. package/docs/interfaces/ConversionAgent.html +0 -78
  328. package/docs/interfaces/CreateAgentResponse.html +0 -56
  329. package/docs/interfaces/CreateRoomResponse.html +0 -62
  330. package/docs/interfaces/CreateStoryResponse.html +0 -56
  331. package/docs/interfaces/FileList.html +0 -56
  332. package/docs/interfaces/FileMetadata.html +0 -89
  333. package/docs/interfaces/IConfigService.html +0 -79
  334. package/docs/interfaces/InstantiateModels.html +0 -64
  335. package/docs/interfaces/InstantiateRoomResult.html +0 -70
  336. package/docs/interfaces/LoadedPack.html +0 -131
  337. package/docs/interfaces/LoggingOptions.html +0 -92
  338. package/docs/interfaces/Message.html +0 -84
  339. package/docs/interfaces/ModelChoice.html +0 -73
  340. package/docs/interfaces/ModelInfo.html +0 -74
  341. package/docs/interfaces/NativeToolDefinition.html +0 -107
  342. package/docs/interfaces/PackAgentTemplate.html +0 -101
  343. package/docs/interfaces/PackRoomTemplate.html +0 -108
  344. package/docs/interfaces/PackView.html +0 -172
  345. package/docs/interfaces/PdfConversionOptions.html +0 -102
  346. package/docs/interfaces/PdfConversionResult.html +0 -97
  347. package/docs/interfaces/PdfMarkdownOptions.html +0 -198
  348. package/docs/interfaces/PdfMarkdownResult.html +0 -106
  349. package/docs/interfaces/PdfPageMarkdown.html +0 -94
  350. package/docs/interfaces/PreparedPromptResponse.html +0 -62
  351. package/docs/interfaces/ProcessTextResponse.html +0 -86
  352. package/docs/interfaces/PromptFile.html +0 -70
  353. package/docs/interfaces/PromptFileContent.html +0 -76
  354. package/docs/interfaces/PromptFilesResponse.html +0 -56
  355. package/docs/interfaces/PromptFolder.html +0 -80
  356. package/docs/interfaces/PromptFolderDefaults.html +0 -155
  357. package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
  358. package/docs/interfaces/PromptFoldersResponse.html +0 -56
  359. package/docs/interfaces/RoomDetails.html +0 -151
  360. package/docs/interfaces/RoomErrorUpdate.html +0 -82
  361. package/docs/interfaces/RoomInfo.html +0 -88
  362. package/docs/interfaces/RoomMessageUpdate.html +0 -113
  363. package/docs/interfaces/RoomMessagesResponse.html +0 -62
  364. package/docs/interfaces/SendMessageResult.html +0 -62
  365. package/docs/interfaces/StoryErrorEvent.html +0 -84
  366. package/docs/interfaces/StoryIdea.html +0 -74
  367. package/docs/interfaces/StoryInfo.html +0 -198
  368. package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
  369. package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
  370. package/docs/interfaces/StoryState.html +0 -108
  371. package/docs/interfaces/StoryStateEvent.html +0 -76
  372. package/docs/interfaces/ToolArtifact.html +0 -85
  373. package/docs/interfaces/ToolCaller.html +0 -77
  374. package/docs/interfaces/ToolDefinition.html +0 -80
  375. package/docs/interfaces/ToolHelpers.html +0 -105
  376. package/docs/interfaces/ToolPackDocuments.html +0 -100
  377. package/docs/interfaces/ToolParameter.html +0 -74
  378. package/docs/interfaces/ToolRoomAccess.html +0 -260
  379. package/docs/interfaces/ToolSummary.html +0 -74
  380. package/docs/interfaces/ToolsResponse.html +0 -68
  381. package/docs/interfaces/Transaction.html +0 -104
  382. package/docs/interfaces/TransactionHistoryResponse.html +0 -62
  383. package/docs/modules.html +0 -53
  384. package/docs/types/PackOrigin.html +0 -34
  385. package/docs/types/PromptScope.html +0 -34
  386. package/docs/types/RoomTurnMode.html +0 -42
  387. package/docs/types/RoomUpdate.html +0 -36
  388. package/docs/types/RosterOverrides.html +0 -42
  389. package/docs/types/ToolContext.html +0 -40
  390. package/docs/types/ToolRunResult.html +0 -34
  391. package/src/tools/packs/dnd5e/README.md +0 -867
@@ -1,76 +1,186 @@
1
+ /**
2
+ * The character sheet artifact: its canonical state, how it is parsed out of a
3
+ * Markdown artifact, and how the artifact is rendered back from state.
4
+ *
5
+ * A sheet artifact has three regions with different owners:
6
+ *
7
+ * 1. A rendered summary, regenerated from state on every write. Never
8
+ * authoritative — a human editing it in the Artifacts tab loses nothing,
9
+ * because the next tool call overwrites it.
10
+ * 2. A free-prose region between `<!-- briyah:notes -->` markers, preserved
11
+ * byte-for-byte across writes. This is where backstory and table notes live.
12
+ * 3. A fenced ```briyah-state block holding the canonical JSON. Located by its
13
+ * info string rather than by position, and tagged `briyah-state` rather than
14
+ * `json` both to make it unambiguous to find and to signal to the model that
15
+ * it must not be hand-edited.
16
+ *
17
+ * Keys in the state are abbreviated because the whole block is rendered into the
18
+ * prompt of every agent that can view the sheet, on every turn.
19
+ */
1
20
  import { AbilityKey } from '../data/srd';
21
+ /** The schema version, bumped when a migration becomes necessary. */
2
22
  export declare const SHEET_STATE_VERSION = 1;
3
23
  export declare const SHEET_NAME_PREFIX = "Sheet: ";
24
+ /**
25
+ * Monster combatants are filed apart from characters so that everything which
26
+ * walks the party — `Party Status`, `read_sheet character: "party"` — keeps
27
+ * walking the party only. See {@link isFoeArtifact}.
28
+ */
4
29
  export declare const FOE_NAME_PREFIX = "Foe: ";
5
30
  export declare const PARTY_STATUS_ARTIFACT = "Party Status";
6
31
  export declare const ENCOUNTER_ARTIFACT = "Encounter";
7
32
  export interface ClassEntry {
33
+ /** Class key, e.g. 'ranger'. */
8
34
  c: string;
35
+ /** Subclass name, free text. */
9
36
  sub?: string;
10
37
  lvl: number;
38
+ /** Hit die, e.g. 'd10'. */
11
39
  hd: string;
12
40
  }
13
41
  export interface ResourcePool {
14
42
  max: number;
15
43
  cur: number;
44
+ /** When the pool refills: 'short', 'long', or 'other' for manual only. */
16
45
  reset?: 'short' | 'long' | 'other';
17
46
  }
18
47
  export interface InventoryItem {
48
+ /** Item name. */
19
49
  n: string;
50
+ /** Quantity. */
20
51
  q: number;
52
+ /** True when worn or wielded. */
21
53
  eq?: boolean;
54
+ /** Remaining charges or uses, for things like a healer's kit. */
22
55
  chg?: number;
56
+ /**
57
+ * True when the character is attuned to this item.
58
+ *
59
+ * Kept on the inventory entry rather than in a list of its own, so it travels
60
+ * with the item: giving away an attuned ring cannot leave the attunement
61
+ * behind, and the three-item limit is a count over the inventory.
62
+ */
23
63
  att?: boolean;
24
64
  }
25
65
  export interface AttackEntry {
26
66
  n: string;
67
+ /** Attack bonus. */
27
68
  atk: number;
69
+ /** Damage dice expression, e.g. '1d8+3'. */
28
70
  dmg: string;
71
+ /** Damage type, e.g. 'piercing'. */
29
72
  type?: string;
30
73
  range?: string;
31
74
  props?: string[];
75
+ /**
76
+ * The rider a stat block prints after the damage, e.g. a wolf's "DC 11 Strength
77
+ * saving throw or be knocked prone". Carried onto the creature because it is the
78
+ * half of the attack the tools cannot roll for you, and an attack that reaches
79
+ * the table without it is adjudicated as though it did not exist.
80
+ */
32
81
  note?: string;
33
82
  }
83
+ /**
84
+ * A die another character has handed this one to spend on a future roll.
85
+ *
86
+ * Bardic Inspiration, Bless, Guidance: a resource whose whole effect happens on
87
+ * somebody else's sheet. Spending it used only to decrement the giver's counter,
88
+ * which meant the die existed nowhere — a bard gave Inspiration to a fighter, the
89
+ * fighter missed by three, and nothing surfaced the d6 that would have hit. The
90
+ * player had to say so afterwards, twice, and it still was not offered.
91
+ */
34
92
  export interface BoonEntry {
35
93
  n: string;
94
+ /** The die rolled when it is spent, e.g. 'd6'. */
36
95
  die: string;
96
+ /** Who gave it, so the table can see whose resource is riding on the roll. */
37
97
  from?: string;
38
98
  }
99
+ /**
100
+ * The d20 this character most recently rolled, so a held die can be added to *that*
101
+ * roll rather than to whatever the agent running the fight remembers of it.
102
+ *
103
+ * Kept only while the character is holding a boon — nobody else can use it, and
104
+ * recording one on every check in the game would cost a sheet write per roll.
105
+ *
106
+ * It exists because the arithmetic went missing without it. A ranger declared she
107
+ * was spending her Bardic Inspiration, the die was rolled *before* the attack, and
108
+ * the +1 was then never added: 12 against a DC of 13 was reported as a miss when
109
+ * 12 + 1 would have hit. She lost the die and the hit in the same breath.
110
+ */
39
111
  export interface PendingRoll {
112
+ /** attack, save, skill, ability or tool. */
40
113
  kind: string;
114
+ /** What was rolled — the attack, skill or ability — for the report. */
41
115
  subject?: string;
116
+ /** The total as rolled, modifiers included. */
42
117
  total: number;
118
+ /** The target number, when the caller gave one. */
43
119
  dc?: number;
120
+ /** The round it was rolled in, so a die cannot be added to a stale roll. */
44
121
  round?: number;
122
+ /** A natural 1 misses whatever is added to it, and no die can turn that. */
45
123
  natural1?: boolean;
46
124
  }
47
125
  export interface ConditionEntry {
48
126
  n: string;
127
+ /** Free-text duration, e.g. '2 rounds'. */
49
128
  dur?: string;
50
129
  }
51
130
  export interface SheetState {
131
+ /** Schema version. */
52
132
  v: number;
133
+ /** Revision counter, incremented on every write. */
53
134
  rev: number;
54
135
  name: string;
136
+ /** Nickname of the agent who plays this character. */
55
137
  owner?: string;
56
138
  race?: string;
139
+ /** 'Small' or 'Medium', from the race. */
57
140
  size?: string;
141
+ /** Darkvision range in feet, from the race. */
58
142
  darkvision?: number;
143
+ /** Languages known, seeded by the race. */
59
144
  languages?: string[];
60
145
  bg?: string;
61
146
  align?: string;
147
+ /**
148
+ * Url of the character's portrait, rendered into the summary as an image.
149
+ *
150
+ * Written well after the sheet is: `create_sheet` asks for the picture and the
151
+ * drawing takes minutes, so it lands in a later write. Stored rather than
152
+ * resolved on read — which is how a story finds a character's portrait — because
153
+ * nothing reads a room artifact on the way out. A sheet is what it says it is.
154
+ */
155
+ img?: string;
62
156
  class: ClassEntry[];
63
157
  abil: Record<AbilityKey, number>;
64
158
  saveProf: AbilityKey[];
65
159
  skillProf: string[];
66
160
  skillExp: string[];
161
+ /**
162
+ * Tools the character is proficient with, in the SRD table's spelling where it
163
+ * carries one. Stored rather than derived from the class and race, unlike weapon
164
+ * proficiency, because most of it is *chosen*: a bard's three instruments and a
165
+ * dwarf's one artisan's tool cannot be read back off anything.
166
+ *
167
+ * Held as written rather than lowercased, since these are display names —
168
+ * comparison goes through `nameKey` instead.
169
+ */
67
170
  toolProf: string[];
171
+ /**
172
+ * Tools the proficiency bonus is doubled for. Separate from `skillExp` because a
173
+ * rogue's Expertise may be spent on thieves' tools instead of a second skill, and
174
+ * folding a tool into the skill list would have `skillModifier` looking it up in
175
+ * the skill-to-ability map and finding nothing.
176
+ */
68
177
  toolExp: string[];
69
178
  hp: {
70
179
  max: number;
71
180
  cur: number;
72
181
  temp: number;
73
182
  };
183
+ /** Hit dice pools keyed by die, e.g. { d10: { max: 3, cur: 3 } }. */
74
184
  hd: Record<string, {
75
185
  max: number;
76
186
  cur: number;
@@ -78,21 +188,43 @@ export interface SheetState {
78
188
  ac: number;
79
189
  speed: number;
80
190
  initBonus: number;
191
+ /** Spell slots keyed by spell level as a string. */
81
192
  slots: Record<string, ResourcePool>;
193
+ /** Named feature and item uses, keyed by an internal snake_case key. */
82
194
  uses: Record<string, ResourcePool>;
83
195
  attacks: AttackEntry[];
196
+ /** Dice given by other characters, waiting to be spent on a roll. */
84
197
  boons?: BoonEntry[];
198
+ /** The roll a held die would be added to. Only kept while {@link boons} has one. */
85
199
  pendingRoll?: PendingRoll;
200
+ /**
201
+ * A stat block's Multiattack text, when it has one.
202
+ *
203
+ * Stored as the prose the block prints, because that is what it is — no count
204
+ * can be parsed out of "two with its scimitar and one with its dagger" reliably
205
+ * enough to enforce. Presence is what matters: it is the difference between a
206
+ * creature allowed more than one attack in a round and one that is not, which is
207
+ * the distinction the rules actually turn on.
208
+ */
86
209
  multiattack?: string;
87
210
  spells?: string[];
211
+ /** Feats taken, by name, in the order taken. */
88
212
  feats?: string[];
213
+ /**
214
+ * True when this character plays with the optional encumbrance variant.
215
+ *
216
+ * A table-wide rule living on a per-character sheet, because the pack has no
217
+ * room-level configuration. Set it for everyone or for nobody.
218
+ */
89
219
  encumbrance?: boolean;
90
220
  cond: ConditionEntry[];
221
+ /** Exhaustion level, 0 to 6. */
91
222
  exh: number;
92
223
  deathSaves: {
93
224
  s: number;
94
225
  f: number;
95
226
  };
227
+ /** True when the character is at 0 hit points but stable rather than dying. */
96
228
  stable: boolean;
97
229
  resist: string[];
98
230
  immune: string[];
@@ -100,26 +232,95 @@ export interface SheetState {
100
232
  inv: InventoryItem[];
101
233
  coin: Record<string, number>;
102
234
  xp: number;
235
+ /**
236
+ * True when this is a monster in the current fight rather than a character.
237
+ *
238
+ * Same shape as a character on purpose: every tool resolves its target by name
239
+ * through `loadSheet`, so one shape means they all work on a monster.
240
+ *
241
+ * Three rules differ. A foe dies outright at 0 rather than falling unconscious,
242
+ * its saves come from {@link saveBonus} rather than class proficiency, and
243
+ * `recomputeDerived` leaves it alone because it has no class to rebuild from.
244
+ */
103
245
  foe?: boolean;
246
+ /**
247
+ * Saving throw bonuses as printed on a stat block, which are flat numbers
248
+ * rather than an ability modifier plus proficiency. Consulted by
249
+ * {@link saveModifier} ahead of the class calculation; an ability absent here
250
+ * falls back to its own modifier, which is what a stat block means by
251
+ * listing only some of them.
252
+ */
104
253
  saveBonus?: Partial<Record<AbilityKey, number>>;
254
+ /** Anything a future pack version or a human added; round-tripped untouched. */
105
255
  [key: string]: any;
106
256
  }
107
257
  export declare class SheetError extends Error {
258
+ /** A machine-readable reason so callers can branch without parsing the message. */
108
259
  readonly violation: string;
109
260
  constructor(violation: string, message: string);
110
261
  }
262
+ /** The artifact name a character's sheet lives under. */
111
263
  export declare function sheetArtifactName(characterName: string): string;
264
+ /** Extracts the character name from a sheet artifact name. */
112
265
  export declare function characterNameFromArtifact(artifactName: string): string;
266
+ /** True when the artifact name is a character sheet. */
113
267
  export declare function isSheetArtifact(artifactName: string): boolean;
268
+ /** The artifact name a monster combatant lives under while a fight is running. */
114
269
  export declare function foeArtifactName(foeName: string): string;
270
+ /** Extracts the creature's name from a foe artifact name. */
115
271
  export declare function foeNameFromArtifact(artifactName: string): string;
272
+ /**
273
+ * True when the artifact name is a monster in the current fight.
274
+ *
275
+ * The separate prefix is a privacy boundary, not tidiness. `Party Status` is rebuilt
276
+ * from every `Sheet:` artifact and read by every player, so a monster filed there
277
+ * would publish its remaining hit points to the table — which the Dungeon Master's
278
+ * prompt forbids saying out loud.
279
+ */
116
280
  export declare function isFoeArtifact(artifactName: string): boolean;
281
+ /** Where a combatant's sheet belongs, party member or monster. */
117
282
  export declare function combatantArtifactName(state: SheetState): string;
283
+ /**
284
+ * Reads the canonical state out of a sheet artifact body.
285
+ * @param body The artifact body
286
+ * @returns The parsed state
287
+ * @throws {SheetError} With violation 'sheet_corrupt' when the state block is
288
+ * missing or unparseable, so the caller can refuse to write rather than
289
+ * overwriting whatever data survives.
290
+ */
118
291
  export declare function parseSheet(body: string): SheetState;
292
+ /** Extracts the free-prose region, or '' when there is none. */
119
293
  export declare function extractNotes(body: string): string;
294
+ /**
295
+ * Every field a sheet actually has, derived from {@link normalizeState} rather than
296
+ * listed by hand so the two cannot drift apart.
297
+ *
298
+ * `SheetState` ends in `[key: string]: any`, which lets a future version add a field
299
+ * without old sheets failing to load — but it also means TypeScript cannot enumerate
300
+ * the real fields, so `patch_sheet` needs this to tell `abil` from a typo of it.
301
+ *
302
+ * `normalizeState({})` sets every key explicitly, including the ones it leaves
303
+ * `undefined`, so its own output is the authoritative list.
304
+ * @returns The field names, sorted
305
+ */
120
306
  export declare function sheetFieldNames(): string[];
307
+ /**
308
+ * Reports the values that had to be corrected when reading a sheet, so the DM
309
+ * hears about it rather than the fix happening silently.
310
+ * @param raw The state as it was on disk
311
+ * @param normalized The state after normalization
312
+ * @returns Human-readable warnings, empty when the sheet was consistent
313
+ */
121
314
  export declare function collectWarnings(raw: any, normalized: SheetState): string[];
122
315
  export declare function clamp(value: number, min: number, max: number): number;
316
+ /**
317
+ * Renders a complete sheet artifact body from state, splicing the previous free
318
+ * prose back in verbatim.
319
+ * @param state The canonical state; its `rev` is incremented by the caller
320
+ * @param notes The prose region to preserve, from {@link extractNotes}
321
+ * @returns The artifact body
322
+ */
123
323
  export declare function renderSheet(state: SheetState, notes: string): string;
324
+ /** Formats a modifier with an explicit sign, e.g. '+3' or '-1'. */
124
325
  export declare function signed(value: number): string;
125
326
  export declare function titleCase(text: string): string;
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ /**
3
+ * The character sheet artifact: its canonical state, how it is parsed out of a
4
+ * Markdown artifact, and how the artifact is rendered back from state.
5
+ *
6
+ * A sheet artifact has three regions with different owners:
7
+ *
8
+ * 1. A rendered summary, regenerated from state on every write. Never
9
+ * authoritative — a human editing it in the Artifacts tab loses nothing,
10
+ * because the next tool call overwrites it.
11
+ * 2. A free-prose region between `<!-- briyah:notes -->` markers, preserved
12
+ * byte-for-byte across writes. This is where backstory and table notes live.
13
+ * 3. A fenced ```briyah-state block holding the canonical JSON. Located by its
14
+ * info string rather than by position, and tagged `briyah-state` rather than
15
+ * `json` both to make it unambiguous to find and to signal to the model that
16
+ * it must not be hand-edited.
17
+ *
18
+ * Keys in the state are abbreviated because the whole block is rendered into the
19
+ * prompt of every agent that can view the sheet, on every turn.
20
+ */
2
21
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
22
  if (k2 === undefined) k2 = k;
4
23
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -50,12 +69,19 @@ exports.renderSheet = renderSheet;
50
69
  exports.signed = signed;
51
70
  exports.titleCase = titleCase;
52
71
  const srd_1 = require("../data/srd");
72
+ // rules.ts imports only types from this module, so this direction is safe.
53
73
  const rules = __importStar(require("./rules"));
54
74
  const races_1 = require("./races");
55
75
  const kits_1 = require("./kits");
56
76
  const encumbrance_1 = require("./encumbrance");
77
+ /** The schema version, bumped when a migration becomes necessary. */
57
78
  exports.SHEET_STATE_VERSION = 1;
58
79
  exports.SHEET_NAME_PREFIX = 'Sheet: ';
80
+ /**
81
+ * Monster combatants are filed apart from characters so that everything which
82
+ * walks the party — `Party Status`, `read_sheet character: "party"` — keeps
83
+ * walking the party only. See {@link isFoeArtifact}.
84
+ */
59
85
  exports.FOE_NAME_PREFIX = 'Foe: ';
60
86
  exports.PARTY_STATUS_ARTIFACT = 'Party Status';
61
87
  exports.ENCOUNTER_ARTIFACT = 'Encounter';
@@ -64,6 +90,7 @@ const NOTES_OPEN = '<!-- briyah:notes -->';
64
90
  const NOTES_CLOSE = '<!-- /briyah:notes -->';
65
91
  const MAX_NOTES_CHARS = 1500;
66
92
  class SheetError extends Error {
93
+ /** A machine-readable reason so callers can branch without parsing the message. */
67
94
  violation;
68
95
  constructor(violation, message) {
69
96
  super(message);
@@ -72,31 +99,53 @@ class SheetError extends Error {
72
99
  }
73
100
  }
74
101
  exports.SheetError = SheetError;
102
+ /** The artifact name a character's sheet lives under. */
75
103
  function sheetArtifactName(characterName) {
76
104
  return `${exports.SHEET_NAME_PREFIX}${characterName}`;
77
105
  }
106
+ /** Extracts the character name from a sheet artifact name. */
78
107
  function characterNameFromArtifact(artifactName) {
79
108
  return artifactName.startsWith(exports.SHEET_NAME_PREFIX)
80
109
  ? artifactName.slice(exports.SHEET_NAME_PREFIX.length)
81
110
  : artifactName;
82
111
  }
112
+ /** True when the artifact name is a character sheet. */
83
113
  function isSheetArtifact(artifactName) {
84
114
  return artifactName.startsWith(exports.SHEET_NAME_PREFIX);
85
115
  }
116
+ /** The artifact name a monster combatant lives under while a fight is running. */
86
117
  function foeArtifactName(foeName) {
87
118
  return `${exports.FOE_NAME_PREFIX}${foeName}`;
88
119
  }
120
+ /** Extracts the creature's name from a foe artifact name. */
89
121
  function foeNameFromArtifact(artifactName) {
90
122
  return artifactName.startsWith(exports.FOE_NAME_PREFIX)
91
123
  ? artifactName.slice(exports.FOE_NAME_PREFIX.length)
92
124
  : artifactName;
93
125
  }
126
+ /**
127
+ * True when the artifact name is a monster in the current fight.
128
+ *
129
+ * The separate prefix is a privacy boundary, not tidiness. `Party Status` is rebuilt
130
+ * from every `Sheet:` artifact and read by every player, so a monster filed there
131
+ * would publish its remaining hit points to the table — which the Dungeon Master's
132
+ * prompt forbids saying out loud.
133
+ */
94
134
  function isFoeArtifact(artifactName) {
95
135
  return artifactName.startsWith(exports.FOE_NAME_PREFIX);
96
136
  }
137
+ /** Where a combatant's sheet belongs, party member or monster. */
97
138
  function combatantArtifactName(state) {
98
139
  return state.foe ? foeArtifactName(state.name) : sheetArtifactName(state.name);
99
140
  }
141
+ /**
142
+ * Reads the canonical state out of a sheet artifact body.
143
+ * @param body The artifact body
144
+ * @returns The parsed state
145
+ * @throws {SheetError} With violation 'sheet_corrupt' when the state block is
146
+ * missing or unparseable, so the caller can refuse to write rather than
147
+ * overwriting whatever data survives.
148
+ */
100
149
  function parseSheet(body) {
101
150
  const block = extractStateBlock(body);
102
151
  if (block === null) {
@@ -117,6 +166,7 @@ function parseSheet(body) {
117
166
  }
118
167
  return normalizeState(parsed);
119
168
  }
169
+ /** Extracts the raw text inside the state fence, or null when absent. */
120
170
  function extractStateBlock(body) {
121
171
  if (!body)
122
172
  return null;
@@ -129,6 +179,7 @@ function extractStateBlock(body) {
129
179
  return null;
130
180
  return lines.slice(openIndex + 1, openIndex + 1 + closeOffset).join('\n');
131
181
  }
182
+ /** Extracts the free-prose region, or '' when there is none. */
132
183
  function extractNotes(body) {
133
184
  if (!body)
134
185
  return '';
@@ -137,6 +188,8 @@ function extractNotes(body) {
137
188
  if (open !== -1 && close > open) {
138
189
  return body.slice(open + NOTES_OPEN.length, close).trim();
139
190
  }
191
+ // No markers: treat everything between the summary and the state fence as
192
+ // prose, so a human who deleted the markers loses nothing.
140
193
  const fenceIndex = body.indexOf('```' + STATE_FENCE_TAG);
141
194
  if (fenceIndex === -1)
142
195
  return '';
@@ -144,6 +197,13 @@ function extractNotes(body) {
144
197
  const headingIndex = beforeFence.search(/^##\s/m);
145
198
  return headingIndex === -1 ? '' : beforeFence.slice(headingIndex).trim();
146
199
  }
200
+ /**
201
+ * Fills in defaults and clamps values that cannot be legal, so a hand-edited
202
+ * sheet keeps the game running instead of failing mid-combat. Anything clamped
203
+ * is reported through {@link collectWarnings} rather than silently fixed.
204
+ * @param raw The parsed JSON
205
+ * @returns A state object with every field present
206
+ */
147
207
  function normalizeState(raw) {
148
208
  const abil = {};
149
209
  for (const ability of srd_1.ABILITIES) {
@@ -162,11 +222,13 @@ function normalizeState(raw) {
162
222
  languages: raw.languages ? toStringArray(raw.languages) : undefined,
163
223
  bg: raw.bg ? String(raw.bg) : undefined,
164
224
  align: raw.align ? String(raw.align) : undefined,
225
+ img: raw.img ? String(raw.img).trim() || undefined : undefined,
165
226
  class: Array.isArray(raw.class) && raw.class.length > 0 ? raw.class : [],
166
227
  abil: abil,
167
228
  saveProf: toStringArray(raw.saveProf),
168
229
  skillProf: toStringArray(raw.skillProf).map((s) => s.toLowerCase()),
169
230
  skillExp: toStringArray(raw.skillExp).map((s) => s.toLowerCase()),
231
+ // Not lowercased, unlike the skills: a tool is a display name.
170
232
  toolProf: toStringArray(raw.toolProf),
171
233
  toolExp: toStringArray(raw.toolExp),
172
234
  hp: {
@@ -203,9 +265,17 @@ function normalizeState(raw) {
203
265
  foe: raw.foe === true ? true : undefined,
204
266
  saveBonus: normalizeSaveBonus(raw.saveBonus),
205
267
  };
268
+ // Current hit points can never exceed the maximum or fall below zero.
206
269
  state.hp.cur = clamp(state.hp.cur, 0, state.hp.max);
207
270
  return state;
208
271
  }
272
+ /**
273
+ * Reads a stat block's flat saving throw bonuses, keeping only the abilities it
274
+ * actually lists. An absent one falls back to the ability modifier, which is what a
275
+ * stat block means by printing some saves and not others.
276
+ * @param raw The field as stored
277
+ * @returns The bonuses, or undefined when there are none
278
+ */
209
279
  function normalizeBoons(raw) {
210
280
  if (!Array.isArray(raw))
211
281
  return undefined;
@@ -248,9 +318,28 @@ function normalizeSaveBonus(raw) {
248
318
  }
249
319
  return Object.keys(out).length > 0 ? out : undefined;
250
320
  }
321
+ /**
322
+ * Every field a sheet actually has, derived from {@link normalizeState} rather than
323
+ * listed by hand so the two cannot drift apart.
324
+ *
325
+ * `SheetState` ends in `[key: string]: any`, which lets a future version add a field
326
+ * without old sheets failing to load — but it also means TypeScript cannot enumerate
327
+ * the real fields, so `patch_sheet` needs this to tell `abil` from a typo of it.
328
+ *
329
+ * `normalizeState({})` sets every key explicitly, including the ones it leaves
330
+ * `undefined`, so its own output is the authoritative list.
331
+ * @returns The field names, sorted
332
+ */
251
333
  function sheetFieldNames() {
252
334
  return Object.keys(normalizeState({})).sort();
253
335
  }
336
+ /**
337
+ * Reports the values that had to be corrected when reading a sheet, so the DM
338
+ * hears about it rather than the fix happening silently.
339
+ * @param raw The state as it was on disk
340
+ * @param normalized The state after normalization
341
+ * @returns Human-readable warnings, empty when the sheet was consistent
342
+ */
254
343
  function collectWarnings(raw, normalized) {
255
344
  const warnings = [];
256
345
  const rawCur = Number(raw?.hp?.cur);
@@ -326,6 +415,10 @@ function normalizeInventory(value) {
326
415
  if (typeof entry === 'string')
327
416
  return { n: entry, q: 1 };
328
417
  if (entry && typeof entry === 'object' && entry.n) {
418
+ // Rebuilt field by field rather than spread, so a hand-edited sheet
419
+ // cannot smuggle arbitrary keys into an inventory entry. Every flag
420
+ // an item can carry has to be listed here — one that is missing is
421
+ // silently discarded on the next read.
329
422
  const item = { n: String(entry.n), q: Math.max(Number(entry.q) || 1, 0) };
330
423
  if (entry.eq)
331
424
  item.eq = true;
@@ -353,6 +446,16 @@ function normalizeCoin(value) {
353
446
  function clamp(value, min, max) {
354
447
  return Math.min(Math.max(value, min), max);
355
448
  }
449
+ // ---------------------------------------------------------------------------
450
+ // Rendering
451
+ // ---------------------------------------------------------------------------
452
+ /**
453
+ * Renders a complete sheet artifact body from state, splicing the previous free
454
+ * prose back in verbatim.
455
+ * @param state The canonical state; its `rev` is incremented by the caller
456
+ * @param notes The prose region to preserve, from {@link extractNotes}
457
+ * @returns The artifact body
458
+ */
356
459
  function renderSheet(state, notes) {
357
460
  const summary = renderSummary(state);
358
461
  const prose = trimNotes(notes);
@@ -362,11 +465,14 @@ function renderSheet(state, notes) {
362
465
  sections.push([NOTES_OPEN, prose, NOTES_CLOSE].join('\n'));
363
466
  }
364
467
  else {
468
+ // Keep the markers even when empty so the next writer has an anchor and a
469
+ // human can see where their own notes are meant to go.
365
470
  sections.push([NOTES_OPEN, NOTES_CLOSE].join('\n'));
366
471
  }
367
472
  sections.push(stateBlock);
368
473
  return sections.join('\n\n') + '\n';
369
474
  }
475
+ /** Caps the prose region, dropping the oldest lines rather than the newest. */
370
476
  function trimNotes(notes) {
371
477
  const text = (notes || '').trim();
372
478
  if (text.length <= MAX_NOTES_CHARS)
@@ -382,9 +488,20 @@ function trimNotes(notes) {
382
488
  }
383
489
  return ['*(older notes trimmed)*', ...kept].join('\n');
384
490
  }
491
+ /** Formats a modifier with an explicit sign, e.g. '+3' or '-1'. */
385
492
  function signed(value) {
386
493
  return value >= 0 ? `+${value}` : `${value}`;
387
494
  }
495
+ /**
496
+ * The readable half of a monster's sheet.
497
+ *
498
+ * Not the character render: a foe has no class, level, proficiency bonus, hit dice
499
+ * or spell slots, and printing "Level 1" against a wight is worse than printing
500
+ * nothing. A fight needs its hit points, armour class, what it can do, and what is
501
+ * currently wrong with it.
502
+ * @param state The monster
503
+ * @returns The summary block
504
+ */
388
505
  function renderFoeSummary(state) {
389
506
  const lines = [`# ${state.name}`];
390
507
  const dead = state.deathSaves.f >= 3 || state.hp.cur <= 0;
@@ -421,6 +538,7 @@ function renderFoeSummary(state) {
421
538
  }
422
539
  return lines.join('\n');
423
540
  }
541
+ /** The human-readable half of the sheet, regenerated on every write. */
424
542
  function renderSummary(state) {
425
543
  if (state.foe)
426
544
  return renderFoeSummary(state);
@@ -443,7 +561,13 @@ function renderSummary(state) {
443
561
  ].filter(Boolean);
444
562
  lines.push(`*${descriptors.join(' — ')}*`);
445
563
  lines.push('');
564
+ if (state.img) {
565
+ lines.push(`![${state.name}](${state.img})`);
566
+ lines.push('');
567
+ }
446
568
  const tempNote = state.hp.temp > 0 ? ` (temp ${state.hp.temp})` : '';
569
+ // Exhaustion and heavy armour change the effective maximum and speed without
570
+ // touching the stored values, so the line shows what is actually in play.
447
571
  const maxHp = rules.effectiveMaxHp(state);
448
572
  const maxNote = maxHp === state.hp.max ? '' : ` of ${state.hp.max}, halved by exhaustion`;
449
573
  const movement = rules.effectiveSpeed(state);
@@ -464,6 +588,10 @@ function renderSummary(state) {
464
588
  .map((skill) => `${titleCase(skill)} ${signed(rules.skillModifier(state, skill))}`)
465
589
  .join(' · '));
466
590
  }
591
+ // Named on the sheet rather than left to a lookup: the DM asks for a thieves'
592
+ // tools check mid-scene, and the answer has to be in front of the player.
593
+ // No modifier is printed because the ability a tool check uses is the DM's call,
594
+ // so the only thing to show is the expertise marker the saves line also uses.
467
595
  const tools = [...new Set([...(state.toolProf || []), ...(state.toolExp || [])])];
468
596
  if (tools.length > 0) {
469
597
  lines.push('**Tools (proficient):** ' +
@@ -483,6 +611,8 @@ function renderSummary(state) {
483
611
  lines.push(...renderAttackRiders(state));
484
612
  }
485
613
  if (state.boons?.length) {
614
+ // The pending roll rides on this line rather than its own, because it only
615
+ // means anything while a die is held and it is why the die is still there.
486
616
  const pending = state.pendingRoll;
487
617
  const against = pending && pending.dc !== undefined
488
618
  ? ` — ${pending.subject || pending.kind} ${pending.total} vs ${pending.dc}, ${pending.dc - pending.total} short`
@@ -505,8 +635,15 @@ function renderSummary(state) {
505
635
  }
506
636
  const traits = (0, races_1.racialTraits)(state);
507
637
  if (traits.length > 0) {
638
+ // Names only. The full text is in the race table and comes back through
639
+ // `read_sheet` with section "race", so the sheet stays short — it is
640
+ // rendered into its owner's prompt on every single turn.
508
641
  lines.push(`**Racial traits:** ${traits.map((trait) => trait.n).join(', ')}`);
509
642
  }
643
+ // The name only. What the background *does* is in the `Background: <name>` document
644
+ // its player already reads, and anything recorded for this character is in the notes
645
+ // below — so repeating a paragraph of it in a block rendered on every turn would be
646
+ // paying twice for the same prose.
510
647
  if (state.bg)
511
648
  lines.push(`**Background:** ${state.bg}`);
512
649
  if (state.darkvision)
@@ -525,6 +662,9 @@ function renderSummary(state) {
525
662
  });
526
663
  if (gear.length > 0)
527
664
  lines.push(`**Gear:** ${gear.join(', ')}`);
665
+ // Shown only when it can actually matter. Without the variant, capacity is
666
+ // "high enough that most characters don't usually have to worry about it", and
667
+ // a line saying so every turn would be noise in the owner's prompt.
528
668
  const load = (0, encumbrance_1.encumbrance)(state);
529
669
  if (load.variant || load.tier !== 'unencumbered') {
530
670
  lines.push(`**Carrying:** ${(0, encumbrance_1.describeEncumbrance)(state)}`);
@@ -543,6 +683,15 @@ function renderSummary(state) {
543
683
  lines.push(`**Vulnerable to:** ${state.vuln.join(', ')}`);
544
684
  return lines.join('\n');
545
685
  }
686
+ /**
687
+ * The riders printed under the attack line, one per attack that has one.
688
+ *
689
+ * Their own lines rather than appended to the attack summary, because the summary is
690
+ * a single dense row and a rider is a sentence — inlined, the one thing on the line
691
+ * that needs acting on is the easiest to skim past.
692
+ * @param state The combatant
693
+ * @returns Zero or more lines
694
+ */
546
695
  function renderAttackRiders(state) {
547
696
  return state.attacks
548
697
  .filter((attack) => attack.note)