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,867 +0,0 @@
1
- # The 5e pack
2
-
3
- Everything a Briyah room needs to run a fifth-edition tabletop game. A game is an
4
- ordinary room, assembled from agents, prompt folders, tool grants and a room leader —
5
- there is no D&D domain model, no room subclass, no message action. This directory holds
6
- the *code* — the dice and the arithmetic — and the rest of the pack's content sits in
7
- `server/data/packs/dnd5e/`:
8
-
9
- ```
10
- server/data/packs/dnd5e/
11
- ├── pack.json
12
- ├── prompts/ dungeon_master, dnd_player, character_creator,
13
- │ campaign_designer, battle_master, dnd_room_moderator
14
- ├── artifacts/ 17 documents: combat procedure, the planes, twelve classes, one background
15
- ├── agents/ six agent templates
16
- └── rooms/ table.json — the whole table in one action, one player seat
17
- campaign.json — the crew and no seats, for a caller seating its own party
18
- ```
19
-
20
- The **Briyah RPG** page (`server/src/rpg/`) is a convenience layer over `campaign.json`: it
21
- builds one of these rooms, seats the party the user described and publishes it. It holds no
22
- state — a campaign *is* the room — and nothing in this pack knows it exists. Keep it that way.
23
-
24
- The two `packs` directories are different things and it is worth keeping them
25
- straight: `server/src/tools/packs/dnd5e/` is this pack's tool code, compiled into the
26
- build; `server/data/packs/dnd5e/` is its content, which a user can override per-file.
27
-
28
- Prompt folders are referenced pack-qualified — `dnd5e:dungeon_master`, not
29
- `dungeon_master`.
30
-
31
- Each folder carries a `defaults_config.json`, so selecting it in the create-agent dialog fills
32
- in that role's name, nickname, description, tool grants and cache TTL. The grant table below is
33
- what those files declare. `prompt-folders.spec.ts` reads them as the grant list, checking both that
34
- every name is a tool the pack registers and that the specialist's prompt mentions it — a typo would
35
- otherwise show up mid-session as an agent that cannot roll.
36
-
37
- | Agent | Prompt folder | Tools it is granted |
38
- |---|---|---|
39
- | Dungeon Master | `dungeon_master` | all twenty |
40
- | Player | `dnd_player` | none — see [Why players get no tools](#why-players-get-no-tools) |
41
- | Character creator | `character_creator` | `class_guide`, `create_sheet`, `read_sheet`, `patch_sheet`, `level_up`, `roll_dice`, `rules_lookup`, `spell` |
42
- | Campaign designer | `campaign_designer` | `stat_block`, `magic_item`, `rules_lookup` |
43
- | Battle Master | `battle_master` | `roll_initiative`, `encounter`, `roll_dice`, `check`, `apply_hp`, `conditions`, `spend`, `read_sheet`, `stat_block`, `spell`, `magic_item`, `rules_lookup` |
44
-
45
- ## Why combat is a separate agent
46
-
47
- The Dungeon Master is the most expensive agent at the table: it carries the whole campaign
48
- history plus its procedure document in a cached prefix. A fight is a dozen tool calls of
49
- bookkeeping, and every one of them re-sends all of that. None of the bookkeeping needs the
50
- campaign history, and none of the narration needs the combat rules — so they are split along
51
- the agent boundary rather than tuned.
52
-
53
- The **Battle Master** runs encounters and nothing else. It holds the combat document, a short
54
- history window (`maxHistoryMessages: 20`), and should be created on a **cheap model** — it does
55
- arithmetic and reports outcomes, it does not write prose. The Dungeon Master hands over at the
56
- moment it would have rolled initiative, stays out of the fight entirely, and picks the story back
57
- up from a single outcome report.
58
-
59
- A 20-message window is narrower than a real fight, and that is deliberate: the window's job is to
60
- stop the second encounter carrying the first. What keeps the *current* encounter intact is the
61
- room's **history pin**, set automatically when the leader hands a specialist a task, which makes
62
- trimming keep everything since the handoff. See the `rooms` skill; the pack needs to do nothing
63
- for it beyond having a window at all.
64
-
65
- ### Monsters are combatants, not prose
66
-
67
- `stat_block` with **`place: true`** writes each creature as a `Foe: <name>` artifact with its own
68
- rolled hit points. From then on `check`, `apply_hp`, `conditions` and `spend` all work on it by
69
- name, because every one of them resolves its target through `loadSheet` — a monster is the same
70
- shape as a character, with `foe: true`, no class, and its stat block's flat save bonuses in
71
- `saveBonus`.
72
-
73
- Three things follow, and each replaces something that went wrong in a played fight:
74
-
75
- - **`check` compares an attack to armour class.** `roll_dice` returns a number and leaves the
76
- comparison to whoever reads it; in round one of the first real fight a 15 against AC 16 dealt
77
- seven damage. A placed monster attacks through `check` with the target's AC in `dc`, and the
78
- tool answers `passed`.
79
- - **Hit points are stored, not restated.** They used to live only as arithmetic in the Battle
80
- Master's `situation` line. Across four rounds that drifted (`25-3 = 19`), then was lost when
81
- the agent's history window trimmed the early rounds, then was re-read from the stat block —
82
- restoring the boss to full and erasing three rounds of the party's damage, invisibly.
83
- - **A monster dies at 0** rather than falling unconscious and rolling death saves.
84
-
85
- Two invariants worth keeping:
86
-
87
- - **The `Foe:` prefix is a privacy boundary.** `Party Status` and `read_sheet character: "party"`
88
- are rebuilt from every `Sheet:` artifact and read by every player. A monster filed under that
89
- prefix would publish its exact remaining hit points to the table — the one thing the Dungeon
90
- Master's prompt forbids saying out loud.
91
- - **`roll_initiative` clears the previous fight's monsters, keeping the ones it names.** Cleared
92
- on the way in rather than the way out, because a fight ends with a message rather than a tool
93
- call and the Battle Master did not reliably signal the end at all. Keeping the named ones
94
- matters just as much: a fight is set up by placing and *then* rolling, so clearing everything
95
- would delete the combatants placed seconds earlier.
96
-
97
- This is additive. The DM still grants all twenty tools, so a table with no Battle Master runs
98
- exactly as it did before — but its procedure document no longer carries the combat rules, so
99
- attach `5e · battle_master — combat mechanics` to the DM as well if you run it that way.
100
-
101
- Two things make the handoff work, and both are prompt-level rather than code-level:
102
-
103
- - **A non-leader agent can drive turn order.** `Room.selectResponders` resolves a message's
104
- targets before it falls back to the room leader, so the Battle Master naming a combatant is
105
- what prompts them. Nothing in the dispatch path cares that it is not the leader.
106
- - **Players must answer whoever addressed them.** `dnd_player`'s prompt used to hard-code the
107
- room leader as the reply target. If that regresses, a player answers the DM mid-fight, the DM
108
- picks up the turn, and combat silently reverts to the old behaviour with no error anywhere.
109
- `prompt-folders.spec.ts` guards it.
110
-
111
- ## What the pack knows, and what still needs a document
112
-
113
- 875 SRD entries are built in and reachable through a tool, which is paid for once in a tool
114
- result rather than on every cached call:
115
-
116
- | Tool | Covers |
117
- |---|---|
118
- | `stat_block` | 317 creatures |
119
- | `magic_item` | 239 magic items |
120
- | `spell` | 319 spells, and each class's list |
121
- | `rules_lookup` | Conditions, rules, tables, 37 weapons, armour, 9 races, the SRD feat, the backgrounds the table has written up, carrying capacity |
122
-
123
- **The one real gap is class features by level.** The pack knows a class's hit die, saving
124
- throws, skill list, casting progression, subclass level and ASI levels — but not what Rage or
125
- Sneak Attack or Channel Divinity do. That, deeper combat procedure, and anything your table
126
- plays with from outside the SRD are what a rule document is still for.
127
-
128
- The pack ships seventeen documents distilled from the SRD for exactly those gaps, in
129
- `server/data/packs/dnd5e/artifacts/` beside a `manifest.json`. **They need no upload**: they appear
130
- on the Artifacts page as read-only artifacts whenever the pack is enabled, and the create-agent
131
- dialog pre-ticks the right one as soon as a prompt folder is selected.
132
-
133
- | Document | For | How it gets there |
134
- |---|---|---|
135
- | `dungeon_master-procedure.md` | The Dungeon Master — DCs, travel, light, objects, traps, resting, downtime | Pre-ticked on the folder |
136
- | `battle_master-combat.md` | The Battle Master — the round, actions, movement, attacks, damage rulings | Pre-ticked on the folder |
137
- | `character_creator-basics.md` | The character creator — what the tools answer, and languages | Pre-ticked on the folder |
138
- | `campaign_designer-setting.md` | The campaign designer — the planes and the SRD pantheons | Pre-ticked on the folder |
139
- | `class-<name>.md` ×12 | The creator building that class, and the agent playing it | `class_guide`, during creation |
140
- | `background-<name>.md` ×1 | The creator building that background, and the agent playing it | `rules_lookup` and `create_sheet`, during creation |
141
-
142
- The DC table and the vision rules are deliberately in **both** procedure documents. They are
143
- cheap, and each agent hits a wall without them: the Battle Master sets DCs for improvised actions
144
- and resolves a shove as a contest, and the Dungeon Master needs the same table out of combat.
145
-
146
- ### Class and background documents attach themselves
147
-
148
- The class documents are the one group nobody ticks, because the tick could never be in the right
149
- place. A player's class is chosen *after* their agent exists, so at creation time there is nothing
150
- to tick; and the creator, handed players one at a time, cannot know what any of them will pick. It
151
- carried all twelve for a while — ~11.4k cached tokens for the two or three the party actually
152
- played — and before that carried none, which produced a fighter with neither Second Wind nor the
153
- fighting style he had chosen and two casters with spell slots and no spells.
154
-
155
- So `class_guide` does it:
156
-
157
- - **The files are the list of playable classes.** `class_guide` with `class: "list"` reads
158
- `class-*.md` out of the pack's `artifacts/` directory, so a table adds a class by dropping in a
159
- file — no manifest entry, no code, no re-tick. Removing one removes it from what a creator may
160
- offer.
161
- - **Reading is free of standing cost.** `class_guide` with a class name returns the document in a
162
- tool result, which is what the creator wants while a player is still choosing between two
163
- classes.
164
- - **Sharing is one artifact per class.** Add `players` and the document becomes `Class: Wizard`,
165
- viewable by the creator and the agents playing that class and nobody else. Cached rather than
166
- transient, which is the right way round here: a class document never changes, so it is paid for
167
- once and read free every turn after.
168
- - **`create_sheet` shares it too**, for the sheet's owner, because that is the moment a class stops
169
- being a choice and becomes a fact. A class the creator forgot to share still reaches its player,
170
- and a multiclass character gets one document per class. A class the pack has no document for is
171
- reported in `classesWithoutRules` rather than failing the sheet.
172
-
173
- The result is that the creator ends up holding the classes being played rather than all twelve, and
174
- each player holds their own — which is what the twelve separate files were always for.
175
-
176
- **Backgrounds work the same way**, with `rules_lookup` in place of `class_guide` — it already
177
- answered a background name and needed no new tool, no new grant and no extra prompt text. The one
178
- difference is what the file has to carry: a class document is prose nothing computes from, so
179
- handing it over is the whole job, while a background *would* be computed from if there were a table
180
- to compute from. There is not, deliberately — see [Backgrounds](#backgrounds).
181
-
182
- Everything else is attached to **exactly one** agent. `attachedArtifacts` is per-agent and each
183
- provider injects it as a `Document:` message into only that agent's requests, so the DM carries
184
- neither the creation chapters nor whatever the designer is reading. That is the reason these are
185
- separate agents rather than modes of the DM.
186
-
187
- `docs/dnd5e-rule-documents/README.md` records what was left out of the distillation and why.
188
-
189
- ## Where creature statistics come from
190
-
191
- The DM must never invent a creature's numbers — a made-up monster corrupts every roll in the
192
- fight — so `stat_block` gives it three routes, in order:
193
-
194
- 1. **The shipped table** (`data/monsters.generated.ts`): all 317 SRD creatures, from the
195
- commoner to the tarrasque. One cheap call, no waiting.
196
- 2. **The room's `Bestiary`**: creatures particular to this campaign, written with
197
- `stat_block`'s `define` parameter by either the designer or the DM. A bestiary entry
198
- **overrides** a shipped creature of the same name, so a game can say "our goblins carry
199
- crossbows".
200
- 3. **Ask the designer**, only for a creature that should be theirs to design.
201
-
202
- This is the reason the designer exists for *world-building* rather than for monster lookup. An
203
- earlier version of this pack routed every stat block through the designer, which made the
204
- common case — the DM needs numbers for an ordinary goblin — cost a whisper, a republish, a
205
- reply, and a cache rebuild, in the middle of a fight. `stat_block` makes it one call.
206
-
207
- Values are transcribed from SRD 5.1; anything you disagree with can be overridden in the
208
- `Bestiary` without touching the code.
209
-
210
- ### Regenerating the shipped table
211
-
212
- `data/monsters.ts` owns the shapes; `data/monsters.generated.ts` is written by
213
- `server/scripts/import-srd-monsters.js` from a checkout of
214
- [OldManUmby/DND.SRD.Wiki](https://github.com/OldManUmby/DND.SRD.Wiki), which is SRD 5.1 plus
215
- the Nov 2018 errata under the same licence.
216
-
217
- ```bash
218
- node scripts/import-srd-monsters.js ../docs/dnd.srd.5.1-0.5.2 --verbose
219
- ```
220
-
221
- Nothing in the build runs it, so the pack does not depend on the source repository being
222
- present. The parse is strict: a creature that does not match the expected shape is reported
223
- and skipped rather than written half-formed, since a wrong number in a stat block is worse
224
- than a missing creature. Re-run it by hand and read the diff.
225
-
226
- ### Why a large table is not a problem
227
-
228
- Lookup is a keyed map hit, so an exact name costs the same at 2,000 creatures as at 24
229
- (measured: ~0.01 ms either way), and keys are re-normalized rather than trusted, so a row
230
- written straight from a source document — `"Ogre Zombie (Variant)"` — still resolves. Two
231
- things do scale, and both are handled:
232
-
233
- - **Ambiguity.** A partial name that matches several creatures returns the candidates and asks
234
- which was meant, rather than silently picking the first. With a large table `"giant"` matches
235
- a dozen creatures, and a wrong monster in a real fight is worse than a failed lookup. An exact
236
- name still wins outright, so `"bandit"` resolves cleanly even though `"bandit captain"` exists.
237
- - **Narrowing.** `filter` matches a creature's **kind and size as well as its name**, because
238
- those are the terms a person narrows by — `"fey"`, `"undead"`, `"devil"`, `"huge"`. A name-only
239
- filter answered "fey" with an empty list and a note that anything unlisted needs defining, which
240
- reads as "this table has no fey creatures" rather than "ask a different way"; `magic_item`'s
241
- filter had spanned name, type and rarity all along. A filtered listing now says so, so an empty
242
- one is not read as absence.
243
- - **Result size.** `list` is capped at 60 names per source and reports totals plus a `truncated`
244
- flag, and takes a `filter`. A failed lookup returns at most eight near matches and a count,
245
- never the whole table. This matters because `truncateResult` replaces an over-16 KB result with
246
- a mangled *string* rather than clipping it, which would destroy the JSON precisely on the error
247
- path. Measured at 2,000 creatures: `list` 1.2 KB, a miss 0.4 KB.
248
-
249
- `monster.tool.spec.ts` guards the table itself — no two keys normalizing to the same name, every
250
- key agreeing with its creature's name, every entry passing the same validation a hand-written
251
- definition does, every damage and hit-dice expression actually rollable, every prose section
252
- having both a name and a body, every saving throw numeric, every entry rendering, and the
253
- largest creature's `stat_block` result staying inside the 16 KB cap. Those are the checks that
254
- catch a bad row at CI time rather than mid-fight. Tests about *listing*, ambiguity and near
255
- matches run against a fixture table instead, so they test the behaviour rather than the data.
256
-
257
- The one thing that stays linear is a *miss*, which runs the fuzzy tiers over every name: about
258
- 4 ms at 2,000 creatures. That is not worth optimizing — it only happens when a lookup fails, and
259
- 4 ms is invisible next to a model round-trip.
260
-
261
- **What it does not do:** a stat block is a template, not an instance. `count` returns an
262
- individually rolled hit point total per creature in a group, but nothing stores them — the DM
263
- tracks monster hit points in its `situation` line, and `apply_hp` remains for characters with
264
- sheets. Making monsters first-class would mean instantiating them as ownerless sheets, which is
265
- a larger change than this.
266
-
267
- ## Weapons and magic items
268
-
269
- Two more tables, both there for the same reason as the bestiary: to stop a number being
270
- invented.
271
-
272
- **Weapons** (`data/weapons.ts`, 37 of them) turn an equipment list into attack lines.
273
- `create_sheet` derives `attacks` from the weapons a character carries unless the caller passed
274
- its own, and `inventory` keeps them in step as gear changes. The engine picks the ability
275
- correctly — Strength for a melee weapon, the better of Strength and Dexterity for a finesse
276
- one, Dexterity for a ranged one, and the *melee* ability for a thrown melee weapon — adds
277
- proficiency only when one of the character's classes actually grants that weapon (a wizard has
278
- five, not a category), and uses the two-handed die for a versatile weapon. There is no weapon
279
- tool: `rules_lookup` answers `topic: "glaive"` and `topic: "chain mail"`, and the pack already
280
- has as many tools as a five-call turn can chain.
281
-
282
- **Tools** — the rulebook kind, thieves' tools and artisan's tools — live in `data/kits.ts`,
283
- named that way because `tools/` next door holds the Briyah tool definitions and a `data/tools.ts`
284
- beside it would read as the wrong thing. Thirty-nine entries in five categories, hand-written.
285
-
286
- Tool proficiency is the one proficiency that is **stored** on the sheet, in `toolProf`, rather
287
- than derived from the class and race the way weapon proficiency is. It has to be: most of it is
288
- *chosen*. A bard picks three instruments out of ten and a dwarf picks one artisan's tool out of
289
- three, and there is nothing to derive that from. So `create_sheet` takes the player's picks in
290
- `spec.tools`, adds what the class and race grant outright, and reports the choices still owed — a
291
- bard who named no instruments is told they owe three. A background's tools arrive in `spec.tools`
292
- too, since a background is a document rather than a table. A tool outside the table is accepted as
293
- written, since the SRD's own background customization rule invites inventing one.
294
-
295
- The two derived sources share one *consumed* set with the player's own picks, which is the part
296
- that is easy to break. Without it a
297
- dwarf monk — offered an artisan's tool by each — has both choices settled by a single pick and
298
- quietly loses a proficiency. The race is applied before the class for the same reason: a race
299
- offers a shortlist and a class offers a whole category, so settling the narrow one first leaves
300
- the player the wider one to spend.
301
-
302
- `check` rolls one with `kind: "tool"`. **The ability is the DM's**, because the rules make it so —
303
- the SRD fixes no ability to a tool and picks one per situation, a Dexterity check to force a lock
304
- and an Intelligence check to identify a poison. The tool defaults to Dexterity, since traps and
305
- locks are most of what gets rolled, and every result names the ability it used (`Thieves' tools
306
- (DEX)`) so a wrong default is visible rather than silent. Proficiency is added only when the
307
- character has it and doubled from `toolExp`, which is where a rogue's Expertise goes when it is
308
- spent on thieves' tools rather than on a second skill — `create_sheet` sorts an `expertise` list
309
- into the skills and the tools rather than dropping what is not a skill. A character without the
310
- proficiency still rolls and is told no bonus applied: using a tool unproficiently is legal.
311
-
312
- `syncWeaponAttacks` only ever touches an entry whose name is **exactly** a table weapon.
313
- "Longsword +1", "Claws" and anything hand-written are left alone — a fuzzy match would mistake
314
- the first for a plain longsword and quietly strip its bonus.
315
-
316
- **Magic items** (`data/magic-items.generated.ts`, 239 of them) work like creatures: the
317
- `magic_item` tool looks one up or defines a campaign item into a `Magic Items` artifact that
318
- overrides the book. An item *is* its text, so the prose is the payload and only the fields a
319
- tool computes from are structured — type, rarity, attunement, charges, and the twenty bonuses
320
- written plainly enough to trust. Anything conditional stays in the text on purpose: the
321
- arrow-catching shield's +2 applies only against ranged attacks, and a bonus wrongly structured
322
- is one that silently applies twice.
323
-
324
- **Attunement** is tracked as `att` on the inventory entry, so it travels with the item and the
325
- three-item limit is a count rather than a second list to keep in step. Exceeding it is a
326
- refusal naming what is already attuned. An item needing attunement contributes nothing until it
327
- has it — which is the whole point of tracking it, since a ring of protection in a pocket should
328
- not be adding to armour class.
329
-
330
- ### Regenerating the item table
331
-
332
- ```bash
333
- node scripts/import-srd-items.js ../docs/dnd.srd.5.1-0.5.2 --verbose
334
- ```
335
-
336
- Two items exceed the 6 KB text cap and are truncated with a pointer to the rule document — the
337
- wand of wonder and the deck of many things, both of which are random tables the DM should read
338
- from the source anyway.
339
-
340
- ## Races
341
-
342
- `data/races.ts` is **hand-written**, unlike the creature and item tables. Nine races and four
343
- subraces is small enough to check by eye, and the thing that mattered was splitting what is
344
- mechanical — ability increases, speed, size, darkvision, proficiencies, resistances — from prose
345
- the player just reads. A generator would have to guess that split.
346
-
347
- `create_sheet` applies it, which means **the `abilities` in a spec are the scores *before* the
348
- race**. That is the one thing to get right on the calling side, and the creator's prompt says it
349
- three times, because adding the bonus by hand as well is the obvious mistake and the sheet cannot
350
- tell the difference afterwards. The result's `race` field lists exactly what was applied so it can
351
- be checked, and `applyRacialBonuses: false` exists for rebuilding a sheet whose numbers were
352
- already finished.
353
-
354
- Applied **once**, at creation. The increases land in `abil`, which then holds the character's
355
- real scores — there is no separate base — so `recomputeDerived` reads the race for hit points and
356
- speed but never touches ability scores. That is what makes levelling up safe.
357
-
358
- **Languages** are the one racial grant that arrives from two directions, and they follow the same
359
- shape as tool proficiencies: stored rather than derived, because most of them are *chosen*. A race
360
- carries the ones it speaks natively and, for a half-elf or a human, a count of extras the player
361
- picks; a background grants more, and a background is a document rather than a table, so nothing
362
- here can know how many. Both go in `spec.languages`, and what the race speaks is added on top.
363
-
364
- The spec field is passed onto the sheet **before** `applyRace` runs, for the same reason
365
- `spec.tools` is: it is what lets the race see a choice already covered and ask only for the
366
- shortfall. `create_sheet` reports the finished list, which matters precisely because that
367
- suppression makes a partial answer quiet — a half-elf acolyte owes three and the pack can only
368
- count one of them, so the list is the check. Before the field existed there was nowhere for any of
369
- them to go, and that character finished speaking only Common and Elvish.
370
-
371
- Three racial rules are genuinely derived rather than stored, so they stay right as a character
372
- changes:
373
-
374
- - the **hill dwarf's** extra hit point per level, read on every recompute;
375
- - the **dwarf's** immunity to the heavy-armour speed penalty, read by `effectiveSpeed`;
376
- - **weapon proficiency**, so a dwarf wizard really is proficient with a warhammer.
377
-
378
- SRD 5.1 carries **one** subrace per race where full 5e has several. An unrecognised *subrace*
379
- resolves to its base race and says so — a mountain dwarf is a real thing, just not here. An
380
- unrecognised *race* resolves to nothing and is reported, because guessing would silently change
381
- ability scores.
382
-
383
- ## Spells
384
-
385
- 319 of them, generated by `scripts/import-srd-spells.js`, with a `spell` tool that looks one up
386
- or lists what a class can cast at a level.
387
-
388
- ```bash
389
- node scripts/import-srd-spells.js ../docs/dnd.srd.5.1-0.5.2 --verbose
390
- ```
391
-
392
- The importer reads **two** files. A spell's own page carries no class information at all; which
393
- classes may cast it lives in `Spells/## Spell Lists.md`, and without it there is no way to tell a
394
- player that a wizard cannot take *cure wounds*. A spell that ends up on nobody's list is reported,
395
- because that means the lists failed to parse rather than that the spell is unusual — the guard in
396
- `spell.tool.spec.ts` asserts all 319 are on at least one.
397
-
398
- `concentration` is derived from the duration rather than trusted, and asserted both ways: exactly
399
- the spells whose duration begins "Concentration" carry the flag. `At Higher Levels` is split into
400
- its own field, since deciding whether to upcast is the one thing a caller looks for separately.
401
-
402
- **There is no `define`, unlike `stat_block` and `magic_item`.** Those two need a structured home
403
- because tools compute from them — a creature's attack bonus, an item's contribution to armour
404
- class. Nothing computes from a spell: its effect is prose the DM adjudicates, so a homebrew spell
405
- needs a description in the `Campaign` document and a name on the sheet, both of which already
406
- work. A fourth campaign artifact holding fields no tool reads would be shape for its own sake.
407
-
408
- **A spell off the character's class list is reported, never refused**, by both `create_sheet` and
409
- `level_up`. A subclass, a racial trait or a magic item can all grant one — a High Elf knows a
410
- wizard cantrip whatever its class — so refusing would be wrong more often than right. Naming it
411
- lets a real mistake get noticed.
412
-
413
- ## Carrying capacity and encumbrance
414
-
415
- Two regimes, and keeping them apart is the whole job.
416
-
417
- The **base rule** is always in force and almost never binding — capacity is Strength × 15, which
418
- the SRD itself calls "high enough that most characters don't usually have to worry about it". The
419
- only thing it changes is dropping speed to 5 feet while dragging something past capacity. So the
420
- sheet does not print a carrying line at all in that case: it would be noise in the owner's prompt
421
- every turn.
422
-
423
- The **variant is opt-in**, set with `encumbrance: true` on the sheet, and turning it on has a
424
- consequence the rules state outright: *"when you use this variant, ignore the Strength column of
425
- the Armor table."* So `effectiveSpeed` stops applying the heavy-armour penalty and starts applying
426
- a weight one. Doing both would charge a Strength 12 fighter twice for the same plate mail, and
427
- there is a test that pins exactly that.
428
-
429
- Above Strength × 5 costs 10 feet; above Strength × 10 costs 20 feet **and** disadvantage on every
430
- ability check, attack roll and saving throw that uses Strength, Dexterity or Constitution. That
431
- last part reaches all three kinds of roll, so `conditionEffects` consults the skill-to-ability map
432
- rather than guessing which checks are physical.
433
-
434
- It is a table-wide rule living on a per-character sheet, because the pack has no room-level
435
- configuration. Set it for everyone or for nobody.
436
-
437
- ### Weights, and what has none
438
-
439
- `scripts/import-srd-gear.js` reads the three places the SRD prints a pound figure — the gear,
440
- armour and weapon tables — into one name-to-pounds map.
441
-
442
- ```bash
443
- node scripts/import-srd-gear.js ../docs/dnd.srd.5.1-0.5.2 --verbose
444
- ```
445
-
446
- Three lookups, each earning its place: an exact name; the same words with a comma swapped, since
447
- the SRD files things for sorting rather than reading (`Clothes, common` is what a person writes as
448
- "common clothes", exactly as `Crossbow, light` is a light crossbow); then a bundle, because
449
- `Arrows (20) — 1 lb.` means one arrow weighs a twentieth of a pound and `arrows x40` should come
450
- to two.
451
-
452
- **A dash in the table is zero; absent from the table is unknown**, and the difference is
453
- load-bearing. The SRD prints no weight for vestments, a holy symbol or a campaign's own trinket,
454
- so `carriedWeight` *names* what it could not weigh and every report says how many items that was.
455
- A total is a floor, never the whole truth, and saying so is better than quietly treating a
456
- breastplate-sized unknown as weightless.
457
-
458
- Coin counts at fifty pieces to the pound.
459
-
460
- ## Backgrounds
461
-
462
- **There is no background table.** A background is a `background-<name>.md` document in
463
- `server/data/packs/dnd5e/artifacts/`, exactly like a class document, and a table adds one by
464
- dropping in a file. The SRD's Acolyte ships as one of those files and is not special: nothing in
465
- the code knows its name.
466
-
467
- That is not a shortcut — it is what the licence and the rules together point at. SRD 5.1 carries
468
- **one** background, and the other twelve everybody actually plays are outside CC-BY-4.0 and must
469
- not live in `data/`. Meanwhile the SRD hands over the extensibility itself: its *Customizing a
470
- Background* rule says in as many words that you may replace the feature, choose any two skills,
471
- and choose any two tool proficiencies or languages. So a table inventing "Sailor" is playing by
472
- the book, and a one-entry table of grants only made the *licensed* background behave unlike every
473
- background at a real table.
474
-
475
- So:
476
-
477
- - `rules_lookup` with `topic: "backgrounds"` returns the customization rule **and** the names the
478
- table has written up. `rules_lookup` with a background's name returns its document — skills,
479
- languages, equipment, feature, and the suggested traits, ideals, bonds and flaws a creator reads
480
- out to a player who says "I don't know what they're like".
481
- - **Nothing about a background is applied automatically.** The two skills go in `skills`, the
482
- languages in `languages`, the gear in `equipment`, the coin in `coin`, and the tool proficiencies
483
- in `tools` — read off the document by whoever is building the character, exactly as a class's
484
- starting equipment always has been. `create_sheet` records the name and says so in
485
- `background.stillToChoose` on every build, since a background whose skills were never passed
486
- leaves no trace on the finished sheet.
487
- - `create_sheet` **shares the document** with the character's owner as `Background: <name>`, the
488
- same way it shares their class. A background nobody wrote up shares nothing and is not reported
489
- as a problem: it is ordinary legal play.
490
-
491
- The sheet render carries the background's **name** and not its prose, for the same reason it
492
- carries racial trait names only: that block is in its owner's prompt on every turn, and the player
493
- already holds the document. A background's feature is prose no field models — put it in `note` if
494
- the table wants it on the sheet.
495
-
496
- `BACKGROUNDS_RULE` in `data/backgrounds.ts` is all that is left in code, because a rule is not a
497
- background.
498
-
499
- ## Feats
500
-
501
- SRD 5.1 carries **one** feat: Grappler. That is the licence, not an omission — the rest of 5e's
502
- feats are outside CC-BY-4.0 and must not be added to `data/`. So the work here was the mechanism
503
- rather than the table, and the mechanism was the part that was broken: `level_up` took a `feat`
504
- name, echoed it into a details line, and **threw it away**. A character who took a feat had taken
505
- nothing.
506
-
507
- Now `feats` is a field on the sheet, and `level_up`:
508
-
509
- - **refuses an ability score improvement and a feat at the same level.** The rule is "you can
510
- forgo taking that feature to take a feat instead" — one or the other. Both were previously
511
- applied happily.
512
- - **refuses a duplicate**, since a feat can be taken only once.
513
- - **refuses an unmet prerequisite**, naming the shortfall: Grappler needs Strength 13.
514
- - **accepts a feat from outside the SRD** by name, records it, and says its effect needs
515
- `patch_sheet`. Refusing would make the pack unusable at any table that plays with more than
516
- one feat; applying an invented effect would be worse.
517
-
518
- Everything is vetted before anything is written, so a refusal leaves the character exactly as
519
- they were rather than half-levelled.
520
-
521
- A feat's `grants` can carry ability increases, skills, weapon proficiencies, resistances, speed
522
- and limited-use pools — none of which the one SRD feat needs, since Grappler's benefit is a rule
523
- about advantage rather than a number. The structure is there for the feats a campaign adds, and
524
- `feats.spec.ts` exercises it by adding one to the table temporarily.
525
-
526
- ## How a session starts
527
-
528
- 1. The DM whispers the **campaign designer** to interview the human player and publish
529
- `Campaign`. The designer asks about tone, setting, what the player wants to spend time
530
- doing, lethality and anything to avoid — one question per message — then writes the world.
531
- 2. The DM whispers the **character creator** one player's name at a time; the creator
532
- interviews that player and whispers back as each sheet lands. Each class the party picks
533
- arrives as a `Class: <Class>` artifact the creator and that player can read — nothing to
534
- attach by hand, and nothing to remember before play.
535
- 3. Play begins.
536
-
537
- Every handover is a whisper, so uninvited players are neither prompted nor told anything —
538
- `canHear` restricts a whisper to its targets, which
539
- `server/src/room/directed-handoff.spec.ts` pins down. All of it still appears in the room log,
540
- so the person running the game watches the whole setup even though no agent but the two
541
- involved can see it.
542
-
543
- ### When the party goes off the map
544
-
545
- The DM whispers the designer what actually happened — where the party went, what they ignored,
546
- and what stat blocks are missing — and the designer republishes `Campaign` around the game
547
- being played. Both prompts forbid herding the party back: no collapsed bridges, no insistent
548
- messengers. Abandoned factions keep pursuing their aims offstage, and what they achieve
549
- unopposed becomes a consequence the party meets later.
550
-
551
- The campaign document is written as a **situation rather than a plot** for this reason —
552
- factions with motives and clocks, places with something present, people with a want and a
553
- secret, and an explicit list of what was left blank. There is no scene sequence to derail.
554
-
555
- Keep the creator in the room afterwards: in directed mode it is never prompted unless
556
- addressed, so it costs nothing at rest, and the DM calls it back for every level-up. Give it a
557
- bounded `maxHistoryMessages` (60) — its history still accumulates public messages through
558
- `hear()` even while it stays silent. Sixty rather than twenty because an interview with a human
559
- runs one question per turn and can outgrow a narrow window; the room's history pin protects the
560
- interview in flight, and the window is the backstop.
561
-
562
- ### Levelling up
563
-
564
- Split the same way creation is, and for the same reason: the choices a level offers come out of
565
- the character-creation rules, which the creator carries and the DM does not.
566
-
567
- 1. The DM calls `award_xp`. It **applies nothing** — it reports `levelUpsAvailable`, each entry
568
- naming the character, the level reached, and exactly what must be chosen.
569
- 2. The DM whispers the creator with one character and that `choices` list copied verbatim. The
570
- list is already correct for that class at that level, and the classes differ: a fighter
571
- improves at levels a ranger does not, a cleric picks its subclass at 1 and a wizard at 2.
572
- 3. The creator interviews the player — one question at a time for the human, everything at once
573
- for an AI — and applies it with `level_up`, then reports back.
574
-
575
- Two rules keep this from being expensive or destructive. The creator must never call
576
- `create_sheet` on a character who already has one, because rebuilding discards their notes,
577
- inventory and current hit points; and it must never rewrite the owning agent's description,
578
- which was written once at creation without a level precisely so it never needs writing again.
579
- The DM chooses the moment, and it is not mid-combat.
580
-
581
- `prompt-folders.spec.ts` guards the parts of this that live in prose — including that every tool
582
- a specialist is granted is actually named in its prompt, which is how `level_up` came to be
583
- granted to the creator and mentioned nowhere.
584
-
585
- ## Turning it on
586
-
587
- Enable **D&D 5th Edition** on the Packs page. That is per user: the tools are registered
588
- process-wide at boot, and enabling is what makes them grantable to *your* agents and puts
589
- the pack's prompt folders and documents in your lists. `BRIYAH_TOOL_PACKS` no longer does
590
- anything.
591
-
592
- Expand the pack's row and press **Create Room** on the *D&D Table* template, or pick it
593
- from "Copy an Existing Room" in the Create Room dialog. Either builds the room and its six
594
- agents in one action, already carrying their prompt folders, tool grants and documents, with
595
- turn mode **directed** and the Dungeon Master as leader. You are asked for two models: the
596
- primary one runs the Dungeon Master, and the economy one runs everybody else — see
597
- [Why combat is a separate agent](#why-combat-is-a-separate-agent) for why that split is the
598
- point.
599
-
600
- If you only want to *play*, the **RPG page** does all of the above and publishes the room, and
601
- enables this pack for you on the way — so a player never sees the Packs page. Come here instead
602
- when you are working on the pack: the RPG page hides every choice, which is the wrong shape for
603
- testing a prompt folder or a grant.
604
-
605
- Disabling the pack later hides its prompts, documents, tools, agents and rooms from your
606
- pages. It does not stop a room that already exists from working.
607
-
608
- ### From the SDK
609
-
610
- Two calls, and neither is about tools — the pack's tools are installed when you construct
611
- `Briyah`, and there is nothing to register:
612
-
613
- ```ts
614
- const app = briyah.getAppService('user-123');
615
-
616
- app.packs.setEnabled('dnd5e', true); // per user, and required
617
-
618
- const { roomId, warnings } = await app.packInstantiation.instantiateRoom(
619
- 'dnd5e',
620
- 'table',
621
- {
622
- primary: { aiServiceName: 'Anthropic', aiModel: 'claude-sonnet-5' },
623
- economy: { aiServiceName: 'Anthropic', aiModel: 'claude-haiku-4-5' },
624
- },
625
- 'Tuesday Night Game', // optional room name
626
- { player: { agentName: 'Homer', agentNickname: 'Homer' } }, // optional per-seat overrides
627
- );
628
- ```
629
-
630
- That is the same six-agent table the button builds. The fifth argument names any seat by its
631
- template key — `table_moderator`, `dungeon_master`, `battle_master`, `character_creator`,
632
- `campaign_designer`, `player` — which is how the person at the keyboard gets their own name
633
- instead of `PlayerOne`. `warnings` reports anything that did not go to plan without stopping the
634
- room, such as a document that failed to attach; log it, because a missing document is a
635
- capability an agent appears to have and does not.
636
-
637
- **Enable before you build.** A pack-qualified folder (`dnd5e:dungeon_master`) always resolves,
638
- but a bare `dungeon_master` reaches the pack only once it is enabled, and `instantiateRoom`
639
- refuses a pack that is off.
640
-
641
- To filter or wrap the tool definitions rather than take them all, pass them to the constructor:
642
-
643
- ```ts
644
- import { Briyah, dnd5eTools } from 'briyah';
645
- const briyah = new Briyah({ tools: dnd5eTools() });
646
- ```
647
-
648
- The main README's [Example 11](../../../../README.md#example-11-seating-a-whole-dd-table) has the
649
- console loop that goes with this, and the by-hand version.
650
-
651
- ## The tools
652
-
653
- | Tool | What it does |
654
- |---|---|
655
- | `roll_dice` | Rolls dice expressions in a labelled, semicolon-separated batch |
656
- | `roll_initiative` | Rolls a whole encounter's initiative in one call and starts the `Encounter` state |
657
- | `encounter` | Reads and advances the fight: the round, whose turn it is, removing a combatant, ending it |
658
- | `check` | Any d20 test, with modifiers read off the character's sheet; rolls damage for attacks, and tool checks with the ability the DM names |
659
- | `apply_hp` | Damage, healing, temporary hit points, the dying sequence, death saves |
660
- | `rest` | Short and long rests, including spending hit dice |
661
- | `spend` | Spell slots, hit dice, feature uses, item charges |
662
- | `conditions` | Conditions and exhaustion, returning the mechanical effects they impose |
663
- | `inventory` | Items, currency, transfers between characters, equipping armour |
664
- | `award_xp` | Awards experience and reports available level-ups without applying them |
665
- | `award_coin` | Divides money across the whole party in one call |
666
- | `level_up` | Applies a level and recalculates everything downstream |
667
- | `class_guide` | Lists the classes this table allows, and hands a class's rules to whoever plays it |
668
- | `create_sheet` | Builds a character sheet, computing everything the rules determine |
669
- | `read_sheet` | Reads a sheet or a one-line party summary, optionally narrowed to a section |
670
- | `patch_sheet` | Sets fields directly, validated — the escape hatch when no other tool fits |
671
- | `stat_block` | Looks up a creature, or defines one for this campaign |
672
- | `magic_item` | Looks up a magic item, or defines one for this campaign |
673
- | `spell` | Looks up a spell, or lists what a class can cast |
674
- | `rules_lookup` | SRD excerpts for conditions, rules, tables, equipment and tools |
675
-
676
- **Labels on `roll_dice` use `=`, not `:`.** Expressions are semicolon-separated and each may
677
- carry a name, which is what makes a multi-roll result readable:
678
-
679
- ```
680
- attack=1d20+4; damage=2d6+2 correct
681
- attack: 1d20+4; damage: 2d6+2 parsed as part of the expression, and fails
682
- ```
683
-
684
- Worth stating because a colon is the natural guess — it is how the rest of a tool call is
685
- written — and because a monster's turn is the common case for a labelled batch: one call
686
- carrying the to-hit and the damage together, rather than two. `roll_dice` takes up to 20
687
- expressions and accepts `adv`/`dis`, `kh`/`kl`, `dh`/`dl`, `r1`, `min2`, `crit` and `xN`.
688
-
689
- Suggested grants:
690
-
691
- | Agent | Prompt folder | Tools |
692
- |---|---|---|
693
- | Dungeon Master | `dungeon_master` | all twenty |
694
- | AI player | `dnd_player` | **none** — see below |
695
- | Human player | `dnd_player` | none |
696
- | Character creator | `character_creator` | `class_guide`, `create_sheet`, `read_sheet`, `patch_sheet`, `level_up`, `roll_dice`, `rules_lookup`, `spell` |
697
- | Campaign designer | `campaign_designer` | `stat_block`, `magic_item`, `rules_lookup` |
698
-
699
- The designer writes the `Campaign` document with the `publish` action rather than a tool. Its two
700
- lookups exist so it can check what the book already has and define only what the campaign
701
- genuinely invented — a creature into the `Bestiary`, an item into `Magic Items`. Both land where
702
- the DM's own lookups find them, so the campaign document stays short and neither definition
703
- touches anybody's cached prompt.
704
-
705
- The character creator holds `level_up` because **it runs level-ups too, not just creation**.
706
- The choices a level offers come out of the character-creation rules it carries and the Dungeon
707
- Master does not, and a level-up is the same job as building a sheet: a private interview with
708
- one player. The DM awards the experience with `award_xp`, which reports what must be chosen
709
- and applies nothing, then hands that list to the creator.
710
-
711
- ### Why players get no tools
712
-
713
- Not an oversight, and not only a trust decision — players have nothing to call a tool *for*.
714
- A character's sheet is an artifact they are a viewer of, so it is already rendered into
715
- their perceive prompt every turn, as is the shared `Party Status`. `read_sheet` exists for
716
- the **Dungeon Master**, which is deliberately *not* a viewer of the sheets (see below); it
717
- is a cache-avoidance mechanism, not a data-access one.
718
-
719
- That leaves rolling and state changes, and both belong to the DM:
720
-
721
- - **Rolling.** `runAgentTurn` lets an agent chain up to five private `EXECUTE`s and only its
722
- final audible message reaches the room. `MessageAction.TOOL` notices are visible to no
723
- agent at all (`canHear` returns false for them) and are not rendered in the room log
724
- unless the reader has turned on "Show Hidden Messages". So a player with dice could roll
725
- five times and report the
726
- best, and no other agent — including the DM — could tell. One roller means one source of
727
- truth.
728
- - **State.** `spend` accepts a negative amount to *restore* a resource, so a player holding
729
- it could quietly refill their own spell slots.
730
-
731
- A human-controlled agent additionally never takes an AI turn at all — `Room.perceive`
732
- returns early for it — so its `toolNames` would be inert regardless. The DM prompt is
733
- explicit that it rolls for every player and must never wait for one to roll.
734
-
735
- `dnd_player/perceive.json` omits `execute` from its action enum, so with
736
- `additionalProperties: false` a player cannot emit a tool call even if one were granted.
737
-
738
- `award_xp` deliberately does not apply the level it reports. The hit point increase, ability
739
- score improvements and new spells are the player's choices; the tool lists what must be
740
- decided and waits for `level_up`.
741
-
742
- ## The artifacts it maintains
743
-
744
- | Artifact | Viewers | Contents |
745
- |---|---|---|
746
- | `Sheet: <Character>` | that character's agent | The full sheet |
747
- | `Party Status` | every agent | One line per character: level, hit points, armour class, conditions |
748
- | `Encounter` | every agent | The round and the initiative order, transient; no monster hit points |
749
- | `Class: <Class>` | the character creator, and every agent playing that class | The class's proficiencies, equipment, features by level and resource counts |
750
- | `Campaign` | the Dungeon Master (and its author) | The world: factions, places, people, hooks |
751
- | `Bestiary` | its author only | Creature statistics particular to this campaign |
752
-
753
- `Class: <Class>` is the one artifact that is written **once and then read forever**, so it is the
754
- one where caching is straightforwardly right. Sheets, `Party Status` and `Encounter` are transient
755
- because they change every round; a class document never changes at all.
756
-
757
- `Bestiary` is scoped to whoever wrote it because everything reads it through `stat_block`, so
758
- nobody needs it in a cached prompt — the same reasoning as the character sheets. You can still
759
- read and hand-edit it in the Artifacts tab.
760
-
761
- `Campaign` is the one changing artifact the DM *is* a viewer of, and that is a deliberate
762
- exception: the DM consults it constantly, so reading it through a tool every turn would cost
763
- far more than carrying it. The price is that a redesign invalidates the DM's cached prefix,
764
- including its attached play rules. Redesigns happen a handful of times a campaign, so that is
765
- the right side of the trade — but it is why the designer is told to publish a revision only
766
- when the game has actually moved, not to tinker.
767
-
768
- ### Where a character's public identity lives
769
-
770
- Agents are created before their characters exist, so their descriptions start as
771
- placeholders. `create_sheet` therefore rewrites the owning agent's description **once**, to
772
- `Thorin Ironfoot — Mountain Dwarf Fighter`, using the new `ToolRoomAccess.setDescription`.
773
-
774
- It deliberately carries no level, hit points or conditions. A description is rendered into
775
- the roster of every *other* agent's cached prompt prefix, so each write invalidates the whole
776
- room's cache; character creation is the one moment when that is cheap, because play has not
777
- started. Everything that changes goes in `Party Status`, which is re-rendered from the sheets
778
- and costs nothing to update.
779
-
780
- So the split is: **description** = who you are, written once; **`Party Status`** = what state
781
- you are in, rewritten freely.
782
-
783
- ### Why the Dungeon Master cannot see the sheets
784
-
785
- A viewer has an artifact rendered into its **cached** prompt prefix, ahead of its attached
786
- documents. So if the Dungeon Master could view five sheets, every hit point change would
787
- invalidate its cache — including the rule documents attached to it, which are usually the
788
- largest thing in the room. A DM carrying 15k tokens of rules would re-pay for them on every
789
- hit.
790
-
791
- So sheets are scoped to their owner and attributed to their owner, and the Dungeon Master
792
- reads them through `read_sheet` instead. A tool result lands in history rather than in the
793
- cached prefix, which the conversation was going to invalidate anyway.
794
-
795
- The human user is unaffected by this scoping: the room's artifact list ignores `viewers`,
796
- so every sheet is readable and editable in the client's Artifacts tab.
797
-
798
- ## The sheet format
799
-
800
- One Markdown artifact per character, in three regions:
801
-
802
- 1. A **rendered summary**, regenerated from state on every write. Never authoritative, so a
803
- human editing it loses nothing.
804
- 2. A **free-prose region** between `<!-- briyah:notes -->` markers, preserved byte-for-byte
805
- across writes. Backstory and table notes live here; no tool overwrites it.
806
- 3. A fenced **` ```briyah-state `** block holding the canonical JSON. Located by its info
807
- string, and tagged that way both to be unambiguous to find and to tell the model not to
808
- hand-edit it.
809
-
810
- If the state block is missing or unparseable, every writing tool **refuses to write** and
811
- returns recovery instructions rather than overwriting whatever data survives. `Sheet
812
- Backups` is where the last good copy lives, since room artifacts have no version history.
813
-
814
- ## Two failure channels
815
-
816
- Used consistently, because they mean different things to a model:
817
-
818
- - **Operational failures** — a bad argument, an unknown character, a corrupt sheet, no
819
- room — are thrown, and surface as `{ ok: false, error }`. These read as "the tool broke".
820
- - **Rules refusals** — no spell slots left, already dead — are *returned successfully*
821
- with `applied: false`, the `rule` that was violated, and an `options` list of what is
822
- legal instead. These read as a ruling. The `options` field is what stops a model
823
- retrying the same rejected call.
824
-
825
- ## Design constraints worth knowing before extending it
826
-
827
- - **Parameters cannot express nested shapes.** `ToolParameter` has only a type word and a
828
- prose description. Complex input is therefore a single `string` parameter carrying JSON
829
- or a delimited mini-syntax, with two or three verbatim examples in the description —
830
- models reproduce a shown example far more reliably than they invent a shape.
831
- - **Nothing validates argument types.** A parameter declared `number` arrives as `"3"`
832
- routinely; one declared `string` and documented as JSON arrives as a real object about as
833
- often as a string. Everything goes through `engine/coerce.ts` first.
834
- - **An agent may chain at most five tool calls per turn.** Tools are coarse-grained and
835
- batch-capable for this reason: a combat round has to fit.
836
- - **Results are truncated at 16 KB**, and truncation replaces the whole result with a
837
- mangled string rather than clipping it, destroying the JSON. Every tool stays inside the
838
- limit by construction — batches cap at 12 entries, `roll_dice` at 20 expressions.
839
- - **Read-modify-write must not yield.** `ToolRoomAccess` is synchronous on purpose;
840
- concurrent tool calls are real, since commissioned agents run their turns under
841
- `Promise.allSettled`. Use `room.update()` and do not `await` inside the callback.
842
-
843
- ## Layout
844
-
845
- ```
846
- engine/ pure logic, no room access
847
- coerce.ts argument coercion
848
- dice.ts expression parser and roller
849
- rules.ts derived statistics from sheet state
850
- sheet.ts the character sheet artifact: parse and render
851
- character.ts construction and the rules-aware mutations
852
- bestiary.ts the Bestiary artifact: parse, render, resolve creature lookups
853
- guides.ts which classes and backgrounds the shipped files define, and where a shared one lives
854
- data/ SRD 5.1 tables and monsters, and the licence
855
- tools/ one file per group of tools; thin wrappers over the engine
856
- prompt-folders.spec.ts structural guards on the four prompt folders and their defaults
857
- ```
858
-
859
- `rules.ts` imports only *types* from `sheet.ts`, never values, so `sheet.ts` can render
860
- using it without a runtime cycle.
861
-
862
- ## Licensing
863
-
864
- Rules data is derived from SRD 5.1, published by Wizards of the Coast under CC-BY-4.0. See
865
- `data/LICENSE-SRD.md` for the attribution and what may be added. Only SRD content belongs
866
- in `data/`; anything beyond it belongs in a rule document the user uploads and attaches to
867
- their Dungeon Master agent.