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,9 +1,59 @@
1
+ /**
2
+ * Reading `rpg_models.json`, and turning a friendly name into models.
3
+ *
4
+ * The file is the short curated list the create-campaign dialog offers, for two
5
+ * separate choices: the campaign's quality tier, which configures the whole hidden
6
+ * crew, and each AI player's own model. One list serves both because an entry carries
7
+ * both roles.
8
+ *
9
+ * The common-config directory is a parameter rather than read from a service, so a
10
+ * spec can point at a fixture instead of the deployment's real file.
11
+ */
1
12
  import { RpgModelEntry, RpgModelOption } from '../../../shared/types/app.types';
2
13
  import { InstantiateModels } from '../packs/pack-instantiation.service';
14
+ /**
15
+ * The file's entries, or an empty list when it cannot be read.
16
+ *
17
+ * Re-read on every call, as `story_models.json` is, so a host who edits the list does
18
+ * not have to restart the server to see it.
19
+ */
3
20
  export declare function readRpgModels(commonConfigDir: string): RpgModelEntry[];
21
+ /** An entry as the client is offered it: the name, the blurb, and nothing else. */
4
22
  export declare function toRpgModelOption(entry: RpgModelEntry, isDefault: boolean): RpgModelOption;
23
+ /** The whole list, projected, with exactly one entry marked as the default. */
5
24
  export declare function listRpgModelOptions(commonConfigDir: string): RpgModelOption[];
25
+ /**
26
+ * The entry a friendly name refers to.
27
+ *
28
+ * An unknown name is refused rather than falling back, because a name the file does
29
+ * not have means the client and the file disagree — and the cost of guessing is a
30
+ * player billed for a model they did not choose.
31
+ *
32
+ * @throws {ValidationError} If no entry has that name
33
+ * @throws {NotFoundError} If the file has no entries at all
34
+ */
6
35
  export declare function resolveRpgModel(commonConfigDir: string, name: string): RpgModelEntry;
36
+ /**
37
+ * The models the hidden crew is built with, from the chosen quality tier.
38
+ *
39
+ * The tier's `model` is the Dungeon Master's — the one `modelRole: 'primary'` agent at
40
+ * the table, and the one whose quality decides whether the game is any good. The
41
+ * economy tier runs the other four, which is the split the dnd5e pack exists for.
42
+ *
43
+ * @param qualityName A friendly name, or absent to take the file's default
44
+ * @throws {ValidationError} If the name is not in the file
45
+ * @throws {NotFoundError} If the file has no entries
46
+ */
7
47
  export declare function resolveCrewModels(commonConfigDir: string, qualityName?: string): InstantiateModels;
48
+ /**
49
+ * The entry to preselect: the one flagged in the file, else the one named by
50
+ * DEFAULT_RPG_MODEL, else the first. Null when the file has no entries.
51
+ */
8
52
  export declare function pickDefaultEntry(entries: RpgModelEntry[]): RpgModelEntry | null;
53
+ /**
54
+ * The friendly name an agent's service and model came from, for a roster listing.
55
+ *
56
+ * Absent when the pair is not on the list, which happens when the agent's model was
57
+ * changed from the Agents page. Reported as absent rather than guessed.
58
+ */
9
59
  export declare function friendlyModelName(commonConfigDir: string, service: string, model: string): string | undefined;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ /**
3
+ * Reading `rpg_models.json`, and turning a friendly name into models.
4
+ *
5
+ * The file is the short curated list the create-campaign dialog offers, for two
6
+ * separate choices: the campaign's quality tier, which configures the whole hidden
7
+ * crew, and each AI player's own model. One list serves both because an entry carries
8
+ * both roles.
9
+ *
10
+ * The common-config directory is a parameter rather than read from a service, so a
11
+ * spec can point at a fixture instead of the deployment's real file.
12
+ */
2
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
14
  if (k2 === undefined) k2 = k;
4
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -45,6 +56,12 @@ const path = __importStar(require("path"));
45
56
  const errors_1 = require("../common/errors");
46
57
  const logger_1 = require("../common/logger");
47
58
  const RPG_MODELS_FILE = 'rpg_models.json';
59
+ /**
60
+ * The file's entries, or an empty list when it cannot be read.
61
+ *
62
+ * Re-read on every call, as `story_models.json` is, so a host who edits the list does
63
+ * not have to restart the server to see it.
64
+ */
48
65
  function readRpgModels(commonConfigDir) {
49
66
  const filePath = path.join(commonConfigDir, RPG_MODELS_FILE);
50
67
  try {
@@ -56,6 +73,7 @@ function readRpgModels(commonConfigDir) {
56
73
  return [];
57
74
  }
58
75
  }
76
+ /** An entry as the client is offered it: the name, the blurb, and nothing else. */
59
77
  function toRpgModelOption(entry, isDefault) {
60
78
  return {
61
79
  name: entry.name,
@@ -64,11 +82,22 @@ function toRpgModelOption(entry, isDefault) {
64
82
  isDefault,
65
83
  };
66
84
  }
85
+ /** The whole list, projected, with exactly one entry marked as the default. */
67
86
  function listRpgModelOptions(commonConfigDir) {
68
87
  const entries = readRpgModels(commonConfigDir);
69
88
  const preferred = pickDefaultEntry(entries);
70
89
  return entries.map((entry) => toRpgModelOption(entry, entry.name === preferred?.name));
71
90
  }
91
+ /**
92
+ * The entry a friendly name refers to.
93
+ *
94
+ * An unknown name is refused rather than falling back, because a name the file does
95
+ * not have means the client and the file disagree — and the cost of guessing is a
96
+ * player billed for a model they did not choose.
97
+ *
98
+ * @throws {ValidationError} If no entry has that name
99
+ * @throws {NotFoundError} If the file has no entries at all
100
+ */
72
101
  function resolveRpgModel(commonConfigDir, name) {
73
102
  const entries = readRpgModels(commonConfigDir);
74
103
  if (entries.length === 0) {
@@ -82,6 +111,17 @@ function resolveRpgModel(commonConfigDir, name) {
82
111
  }
83
112
  return match;
84
113
  }
114
+ /**
115
+ * The models the hidden crew is built with, from the chosen quality tier.
116
+ *
117
+ * The tier's `model` is the Dungeon Master's — the one `modelRole: 'primary'` agent at
118
+ * the table, and the one whose quality decides whether the game is any good. The
119
+ * economy tier runs the other four, which is the split the dnd5e pack exists for.
120
+ *
121
+ * @param qualityName A friendly name, or absent to take the file's default
122
+ * @throws {ValidationError} If the name is not in the file
123
+ * @throws {NotFoundError} If the file has no entries
124
+ */
85
125
  function resolveCrewModels(commonConfigDir, qualityName) {
86
126
  const entry = qualityName?.trim()
87
127
  ? resolveRpgModel(commonConfigDir, qualityName)
@@ -92,6 +132,8 @@ function resolveCrewModels(commonConfigDir, qualityName) {
92
132
  aiModel: entry.model,
93
133
  smallModelName: entry.small_model,
94
134
  },
135
+ // Built only when the entry names one: absent lets `modelFor` fall back to the
136
+ // primary rather than this module keeping a second copy of that rule.
95
137
  economy: entry.economy_service || entry.economy_model
96
138
  ? {
97
139
  aiServiceName: entry.economy_service ?? entry.service,
@@ -101,6 +143,10 @@ function resolveCrewModels(commonConfigDir, qualityName) {
101
143
  : undefined,
102
144
  };
103
145
  }
146
+ /**
147
+ * The entry to preselect: the one flagged in the file, else the one named by
148
+ * DEFAULT_RPG_MODEL, else the first. Null when the file has no entries.
149
+ */
104
150
  function pickDefaultEntry(entries) {
105
151
  if (entries.length === 0)
106
152
  return null;
@@ -116,6 +162,7 @@ function pickDefaultEntry(entries) {
116
162
  }
117
163
  return entries[0];
118
164
  }
165
+ /** @throws {NotFoundError} If the file has no entries */
119
166
  function requireDefaultEntry(commonConfigDir) {
120
167
  const entry = pickDefaultEntry(readRpgModels(commonConfigDir));
121
168
  if (!entry) {
@@ -123,6 +170,12 @@ function requireDefaultEntry(commonConfigDir) {
123
170
  }
124
171
  return entry;
125
172
  }
173
+ /**
174
+ * The friendly name an agent's service and model came from, for a roster listing.
175
+ *
176
+ * Absent when the pair is not on the list, which happens when the agent's model was
177
+ * changed from the Agents page. Reported as absent rather than guessed.
178
+ */
126
179
  function friendlyModelName(commonConfigDir, service, model) {
127
180
  return readRpgModels(commonConfigDir).find((entry) => entry.service === service && entry.model === model)?.name;
128
181
  }
@@ -1,8 +1,45 @@
1
+ /**
2
+ * What a campaign's party may be, decided before anything is created.
3
+ *
4
+ * Pure on purpose: no filesystem, no Nest, no `AppService`. Every rule here is one
5
+ * the room would otherwise enforce badly or late, and the whole point is to refuse a
6
+ * party the room could not route while refusing costs nothing.
7
+ */
1
8
  import { RpgPlayerRequest } from '../../../shared/types/app.types';
9
+ /** The pack a campaign is built from. */
2
10
  export declare const RPG_PACK = "dnd5e";
11
+ /** The pack's player-less room template — the crew, and no seats. */
3
12
  export declare const RPG_ROOM_KEY = "campaign";
13
+ /** The prompt folder every player is created from, pack-qualified. */
4
14
  export declare const RPG_PLAYER_FOLDER = "dnd5e:dnd_player";
15
+ /** The pack agent template a player is filed under, and the roster discriminator. */
5
16
  export declare const RPG_PLAYER_AGENT_KEY = "player";
17
+ /**
18
+ * How many players one table seats.
19
+ *
20
+ * Not a technical limit — the room does not care. Six is a table, and every player
21
+ * beyond it is another agent perceiving every message.
22
+ */
6
23
  export declare const RPG_MAX_PLAYERS = 6;
24
+ /**
25
+ * The names a party is seated under, in order.
26
+ *
27
+ * A seat is a placeholder, not a character. Players choose a character during
28
+ * character creation and are renamed to it then — which is the only point at which
29
+ * they know what the classes and races on offer are. Generated here rather than
30
+ * asked for, so they are unique by construction and nothing has to be refused.
31
+ */
7
32
  export declare const RPG_SEAT_NAMES: readonly ["Player One", "Player Two", "Player Three", "Player Four", "Player Five", "Player Six"];
33
+ /**
34
+ * Refuses a party the room could not seat, before a single agent exists.
35
+ *
36
+ * Much smaller than it was. It used to police character names — length, punctuation,
37
+ * collisions with the crew and with each other — because the party was named here.
38
+ * Now the party is seated under {@link RPG_SEAT_NAMES} and named in the game, so the
39
+ * only collision left is one a player invents at the table, and
40
+ * `Room.renameAgent` refuses that where it happens.
41
+ *
42
+ * @param players The requested party, in seating order
43
+ * @throws {ValidationError} Naming the offending seat and why
44
+ */
8
45
  export declare function assertSeatable(players: RpgPlayerRequest[] | undefined): void;
@@ -1,13 +1,38 @@
1
1
  "use strict";
2
+ /**
3
+ * What a campaign's party may be, decided before anything is created.
4
+ *
5
+ * Pure on purpose: no filesystem, no Nest, no `AppService`. Every rule here is one
6
+ * the room would otherwise enforce badly or late, and the whole point is to refuse a
7
+ * party the room could not route while refusing costs nothing.
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  exports.RPG_SEAT_NAMES = exports.RPG_MAX_PLAYERS = exports.RPG_PLAYER_AGENT_KEY = exports.RPG_PLAYER_FOLDER = exports.RPG_ROOM_KEY = exports.RPG_PACK = void 0;
4
11
  exports.assertSeatable = assertSeatable;
5
12
  const errors_1 = require("../common/errors");
13
+ /** The pack a campaign is built from. */
6
14
  exports.RPG_PACK = 'dnd5e';
15
+ /** The pack's player-less room template — the crew, and no seats. */
7
16
  exports.RPG_ROOM_KEY = 'campaign';
17
+ /** The prompt folder every player is created from, pack-qualified. */
8
18
  exports.RPG_PLAYER_FOLDER = `${exports.RPG_PACK}:dnd_player`;
19
+ /** The pack agent template a player is filed under, and the roster discriminator. */
9
20
  exports.RPG_PLAYER_AGENT_KEY = 'player';
21
+ /**
22
+ * How many players one table seats.
23
+ *
24
+ * Not a technical limit — the room does not care. Six is a table, and every player
25
+ * beyond it is another agent perceiving every message.
26
+ */
10
27
  exports.RPG_MAX_PLAYERS = 6;
28
+ /**
29
+ * The names a party is seated under, in order.
30
+ *
31
+ * A seat is a placeholder, not a character. Players choose a character during
32
+ * character creation and are renamed to it then — which is the only point at which
33
+ * they know what the classes and races on offer are. Generated here rather than
34
+ * asked for, so they are unique by construction and nothing has to be refused.
35
+ */
11
36
  exports.RPG_SEAT_NAMES = [
12
37
  'Player One',
13
38
  'Player Two',
@@ -16,6 +41,18 @@ exports.RPG_SEAT_NAMES = [
16
41
  'Player Five',
17
42
  'Player Six',
18
43
  ];
44
+ /**
45
+ * Refuses a party the room could not seat, before a single agent exists.
46
+ *
47
+ * Much smaller than it was. It used to police character names — length, punctuation,
48
+ * collisions with the crew and with each other — because the party was named here.
49
+ * Now the party is seated under {@link RPG_SEAT_NAMES} and named in the game, so the
50
+ * only collision left is one a player invents at the table, and
51
+ * `Room.renameAgent` refuses that where it happens.
52
+ *
53
+ * @param players The requested party, in seating order
54
+ * @throws {ValidationError} Naming the offending seat and why
55
+ */
19
56
  function assertSeatable(players) {
20
57
  if (!players || players.length === 0) {
21
58
  throw new errors_1.ValidationError('A campaign needs at least one player.');
@@ -1,3 +1,27 @@
1
+ /**
2
+ * Campaigns: a streamlined way to start and hold a fifth-edition game.
3
+ *
4
+ * A campaign is not a new kind of thing. It is an ordinary room built from the dnd5e
5
+ * pack's `campaign` template — the Dungeon Master, Battle Master, Character Creator,
6
+ * Campaign Designer and Table Moderator — with a party seated on top and the whole
7
+ * thing published, so the link the party plays through exists from the first moment.
8
+ *
9
+ * ## Why there is no campaign store
10
+ *
11
+ * Everything a campaign is, a room already holds: its roster, its turn mode, its
12
+ * leader and moderator, its artifacts, its transcript and its cost. Which agent is a
13
+ * player is `isControlledByHuman`; a character's personality is `privateContext`; a
14
+ * crew member's role is `packAgentKey`. A store would be a second copy of all of that,
15
+ * and it would drift the moment somebody renamed an agent from the Agents page. So a
16
+ * campaign is discovered by filtering rooms, and its details are derived per request.
17
+ *
18
+ * ## Why every write goes through AppService
19
+ *
20
+ * This service never touches `AgentStoreService` or `RoomStoreService`. It goes
21
+ * through the same `createRoom`, `createRoomAgent` and `deleteRoom` paths the API
22
+ * uses — the same discipline `PackInstantiationService` keeps, and what makes the
23
+ * rollback below correct rather than approximate.
24
+ */
1
25
  import { CreateRpgCampaignRequest, CreateRpgCampaignResponse, RpgCampaignDetails, RpgCampaignInfo, RpgModelOption } from '../../../shared/types/app.types';
2
26
  import { AppService } from '../app.service';
3
27
  import { UserConfigService } from '../config/user-config.service';
@@ -10,20 +34,83 @@ export declare class RpgService {
10
34
  private readonly userPaths;
11
35
  private readonly userId;
12
36
  constructor(app: AppService, packs: PackService, userConfig: UserConfigService, userPaths: UserPathsService, userId: string);
37
+ /** The models a campaign may be built with, as the client is offered them. */
13
38
  listModels(): RpgModelOption[];
39
+ /**
40
+ * Builds a campaign and publishes it.
41
+ *
42
+ * Three phases, one compensating action. Everything that can be known is checked
43
+ * before the first side effect; then the crew; then the party and the publish. Any
44
+ * failure past the first agent deletes the room, which takes its agents with it.
45
+ *
46
+ * Synchronous throughout, unlike story creation: nothing in the dnd5e pack fires a
47
+ * prompt at instantiation, so this is file I/O for a dozen agents. It either
48
+ * returns a campaign that can be played or leaves nothing behind.
49
+ *
50
+ * @param request The campaign's name, quality tier and party
51
+ * @returns The campaign, its public link, and anything that did not go to plan
52
+ * @throws {ValidationError} If the party or the quality tier is not acceptable
53
+ * @throws {NotFoundError} If this deployment does not ship the dnd5e pack
54
+ */
14
55
  createCampaign(request: CreateRpgCampaignRequest): Promise<CreateRpgCampaignResponse>;
56
+ /** Every campaign this user has, newest first. */
15
57
  listCampaigns(): Promise<RpgCampaignInfo[]>;
58
+ /**
59
+ * One campaign, with its party and its crew.
60
+ *
61
+ * Derived on every request rather than cached, so a change made from the Rooms or
62
+ * Agents page — a seventh player, a renamed character — shows up here.
63
+ *
64
+ * @throws {NotFoundError} If there is no such campaign
65
+ */
16
66
  getCampaign(campaignId: string): Promise<RpgCampaignDetails>;
67
+ /**
68
+ * Publishes a campaign that has no live link.
69
+ *
70
+ * Only reachable when an instance was deleted by hand, since creation publishes.
71
+ * It mints a new id, so the old link — if anyone still has it — stops working.
72
+ *
73
+ * @throws {NotFoundError} If there is no such campaign
74
+ * @throws {ValidationError} If the campaign already has a link
75
+ */
17
76
  republishCampaign(campaignId: string): Promise<{
18
77
  instanceId: string;
19
78
  publicPath: string;
20
79
  }>;
80
+ /** Each seat with its model resolved up front. @throws {ValidationError} */
21
81
  private resolveSeats;
82
+ /** The economy tier a human player rides, which is the cheapest seat available. */
22
83
  private economyModel;
84
+ /**
85
+ * Makes sure the pack a campaign is built from is available and on.
86
+ *
87
+ * Enabling it here rather than in `PackInstantiationService`: self-enabling
88
+ * instantiation would change behaviour for every pack to suit one feature. A user
89
+ * on the RPG surface asking for a campaign has unambiguously asked for the dnd5e
90
+ * content, and has no Packs page to be sent to.
91
+ *
92
+ * @throws {NotFoundError} If the deployment does not ship the pack
93
+ */
23
94
  private ensurePackReady;
95
+ /**
96
+ * A room built from the campaign template.
97
+ *
98
+ * Both halves matter: `pack` alone would also match a table built by hand from the
99
+ * Packs page, which has a player seat the RPG page did not create and does not
100
+ * know how to show.
101
+ */
24
102
  private isCampaign;
103
+ /** @throws {NotFoundError} If the room is missing or is not a campaign */
25
104
  private requireCampaign;
105
+ /** The listing shape, including the published link the party plays through. */
26
106
  private summarize;
107
+ /**
108
+ * The party and the crew.
109
+ *
110
+ * Split on the pack template key rather than on `isControlledByHuman`, because an
111
+ * AI player is a player too — it is seated from the same template and shown in the
112
+ * same roster.
113
+ */
27
114
  private splitRoster;
28
115
  private isPlayer;
29
116
  }
@@ -1,4 +1,28 @@
1
1
  "use strict";
2
+ /**
3
+ * Campaigns: a streamlined way to start and hold a fifth-edition game.
4
+ *
5
+ * A campaign is not a new kind of thing. It is an ordinary room built from the dnd5e
6
+ * pack's `campaign` template — the Dungeon Master, Battle Master, Character Creator,
7
+ * Campaign Designer and Table Moderator — with a party seated on top and the whole
8
+ * thing published, so the link the party plays through exists from the first moment.
9
+ *
10
+ * ## Why there is no campaign store
11
+ *
12
+ * Everything a campaign is, a room already holds: its roster, its turn mode, its
13
+ * leader and moderator, its artifacts, its transcript and its cost. Which agent is a
14
+ * player is `isControlledByHuman`; a character's personality is `privateContext`; a
15
+ * crew member's role is `packAgentKey`. A store would be a second copy of all of that,
16
+ * and it would drift the moment somebody renamed an agent from the Agents page. So a
17
+ * campaign is discovered by filtering rooms, and its details are derived per request.
18
+ *
19
+ * ## Why every write goes through AppService
20
+ *
21
+ * This service never touches `AgentStoreService` or `RoomStoreService`. It goes
22
+ * through the same `createRoom`, `createRoomAgent` and `deleteRoom` paths the API
23
+ * uses — the same discipline `PackInstantiationService` keeps, and what makes the
24
+ * rollback below correct rather than approximate.
25
+ */
2
26
  Object.defineProperty(exports, "__esModule", { value: true });
3
27
  exports.RpgService = void 0;
4
28
  const errors_1 = require("../common/errors");
@@ -18,9 +42,26 @@ class RpgService {
18
42
  this.userPaths = userPaths;
19
43
  this.userId = userId;
20
44
  }
45
+ /** The models a campaign may be built with, as the client is offered them. */
21
46
  listModels() {
22
47
  return (0, rpg_models_1.listRpgModelOptions)(this.userPaths.getCommonConfigDir());
23
48
  }
49
+ /**
50
+ * Builds a campaign and publishes it.
51
+ *
52
+ * Three phases, one compensating action. Everything that can be known is checked
53
+ * before the first side effect; then the crew; then the party and the publish. Any
54
+ * failure past the first agent deletes the room, which takes its agents with it.
55
+ *
56
+ * Synchronous throughout, unlike story creation: nothing in the dnd5e pack fires a
57
+ * prompt at instantiation, so this is file I/O for a dozen agents. It either
58
+ * returns a campaign that can be played or leaves nothing behind.
59
+ *
60
+ * @param request The campaign's name, quality tier and party
61
+ * @returns The campaign, its public link, and anything that did not go to plan
62
+ * @throws {ValidationError} If the party or the quality tier is not acceptable
63
+ * @throws {NotFoundError} If this deployment does not ship the dnd5e pack
64
+ */
24
65
  async createCampaign(request) {
25
66
  const name = request.name?.trim();
26
67
  if (!name) {
@@ -29,13 +70,18 @@ class RpgService {
29
70
  if (name.length > 200) {
30
71
  throw new errors_1.ValidationError('Campaign name too long (200 characters).');
31
72
  }
73
+ // Phase 0: nothing here has an effect, so a typo in the fourth player's model
74
+ // surfaces before three agents exist.
32
75
  (0, rpg_roster_1.assertSeatable)(request.players);
33
76
  const seats = this.resolveSeats(request.players);
34
77
  const crewModels = (0, rpg_models_1.resolveCrewModels)(this.userPaths.getCommonConfigDir(), request.quality);
35
78
  this.ensurePackReady();
79
+ // Phase 1: the crew. This rolls itself back on failure.
36
80
  const built = await this.app.packInstantiation.instantiateRoom(rpg_roster_1.RPG_PACK, rpg_roster_1.RPG_ROOM_KEY, crewModels, name);
37
81
  const campaignId = built.roomId;
38
82
  const warnings = [...built.warnings];
83
+ // Phase 2: the party, then the link. From here the room exists, so a failure
84
+ // has something to undo.
39
85
  try {
40
86
  const players = [];
41
87
  for (const seat of seats) {
@@ -46,10 +92,18 @@ class RpgService {
46
92
  smallModelName: seat.model?.small_model ?? crewModels.primary.smallModelName,
47
93
  overrides: {
48
94
  agentName: seat.seatName,
95
+ // A placeholder, and unique by construction. The character
96
+ // creator renames the agent to whatever character the player
97
+ // invents, which is what gives the table one name per person
98
+ // instead of a seat name and a character name for each.
49
99
  agentNickname: seat.seatName.replace(/\s+/g, ''),
50
100
  description: `${seat.seatName}, a player at the table. Renamed to their character once their sheet is built.`,
51
101
  controlledByHuman: seat.isHuman,
52
- useModerator: true,
102
+ // AI players only. A person at the table keeps the action and
103
+ // target pickers, so they can whisper to another player or
104
+ // address the DM directly rather than having the moderator
105
+ // decide both from their text.
106
+ useModerator: !seat.isHuman,
53
107
  ...(seat.isHuman ? {} : { privateContext: seat.personality }),
54
108
  },
55
109
  pack: rpg_roster_1.RPG_PACK,
@@ -77,6 +131,11 @@ class RpgService {
77
131
  };
78
132
  }
79
133
  catch (error) {
134
+ // A campaign short a player is a table where the Dungeon Master addresses
135
+ // somebody who is not there, and a campaign with no link has nothing to
136
+ // play in. Neither is a state the UI has a screen for, so there is no
137
+ // partial success worth keeping. deleteRoom also takes the agents the room
138
+ // owns, which listAgents would otherwise never show again.
80
139
  logger_1.logger.warn(`Rolling back campaign ${campaignId}: ${error.message}`);
81
140
  await this.app.deleteRoom(campaignId).catch((cleanupError) => {
82
141
  logger_1.logger.error(`Could not roll back campaign ${campaignId}:`, cleanupError);
@@ -84,6 +143,7 @@ class RpgService {
84
143
  throw error;
85
144
  }
86
145
  }
146
+ /** Every campaign this user has, newest first. */
87
147
  async listCampaigns() {
88
148
  const rooms = await this.app.listRooms();
89
149
  const campaigns = [];
@@ -95,6 +155,14 @@ class RpgService {
95
155
  }
96
156
  return campaigns.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
97
157
  }
158
+ /**
159
+ * One campaign, with its party and its crew.
160
+ *
161
+ * Derived on every request rather than cached, so a change made from the Rooms or
162
+ * Agents page — a seventh player, a renamed character — shows up here.
163
+ *
164
+ * @throws {NotFoundError} If there is no such campaign
165
+ */
98
166
  async getCampaign(campaignId) {
99
167
  const room = await this.requireCampaign(campaignId);
100
168
  const summary = await this.summarize(room);
@@ -106,6 +174,15 @@ class RpgService {
106
174
  crew,
107
175
  };
108
176
  }
177
+ /**
178
+ * Publishes a campaign that has no live link.
179
+ *
180
+ * Only reachable when an instance was deleted by hand, since creation publishes.
181
+ * It mints a new id, so the old link — if anyone still has it — stops working.
182
+ *
183
+ * @throws {NotFoundError} If there is no such campaign
184
+ * @throws {ValidationError} If the campaign already has a link
185
+ */
109
186
  async republishCampaign(campaignId) {
110
187
  const room = await this.requireCampaign(campaignId);
111
188
  const existing = await this.app.getPublishedRoomInstances(campaignId);
@@ -115,6 +192,7 @@ class RpgService {
115
192
  const instanceId = await this.app.publishRoom(campaignId, room.getName(), this.userId);
116
193
  return { instanceId, publicPath: `/public/rooms/${instanceId}` };
117
194
  }
195
+ /** Each seat with its model resolved up front. @throws {ValidationError} */
118
196
  resolveSeats(players) {
119
197
  const configDir = this.userPaths.getCommonConfigDir();
120
198
  return players.map((player, index) => ({
@@ -126,9 +204,20 @@ class RpgService {
126
204
  : (0, rpg_models_1.resolveRpgModel)(configDir, player.modelName),
127
205
  }));
128
206
  }
207
+ /** The economy tier a human player rides, which is the cheapest seat available. */
129
208
  economyModel(models) {
130
209
  return (models.economy ?? models.primary).aiModel;
131
210
  }
211
+ /**
212
+ * Makes sure the pack a campaign is built from is available and on.
213
+ *
214
+ * Enabling it here rather than in `PackInstantiationService`: self-enabling
215
+ * instantiation would change behaviour for every pack to suit one feature. A user
216
+ * on the RPG surface asking for a campaign has unambiguously asked for the dnd5e
217
+ * content, and has no Packs page to be sent to.
218
+ *
219
+ * @throws {NotFoundError} If the deployment does not ship the pack
220
+ */
132
221
  ensurePackReady() {
133
222
  if (!this.packs.installedPackNames().includes(rpg_roster_1.RPG_PACK)) {
134
223
  throw new errors_1.NotFoundError('This deployment does not ship the D&D pack.');
@@ -138,9 +227,17 @@ class RpgService {
138
227
  this.userConfig.setPackEnabled(rpg_roster_1.RPG_PACK, true);
139
228
  }
140
229
  }
230
+ /**
231
+ * A room built from the campaign template.
232
+ *
233
+ * Both halves matter: `pack` alone would also match a table built by hand from the
234
+ * Packs page, which has a player seat the RPG page did not create and does not
235
+ * know how to show.
236
+ */
141
237
  isCampaign(room) {
142
238
  return room.getPack() === rpg_roster_1.RPG_PACK && room.getPackRoomKey() === rpg_roster_1.RPG_ROOM_KEY;
143
239
  }
240
+ /** @throws {NotFoundError} If the room is missing or is not a campaign */
144
241
  async requireCampaign(campaignId) {
145
242
  const room = await this.app.getRoomById(campaignId);
146
243
  if (!room || !this.isCampaign(room)) {
@@ -148,6 +245,7 @@ class RpgService {
148
245
  }
149
246
  return room;
150
247
  }
248
+ /** The listing shape, including the published link the party plays through. */
151
249
  async summarize(room) {
152
250
  const instances = await this.app.getPublishedRoomInstances(room.getId());
153
251
  const instance = instances[0];
@@ -159,12 +257,21 @@ class RpgService {
159
257
  instanceId: instance?.id,
160
258
  playerCount: players.length,
161
259
  playerNames: players.map((agent) => agent.agentNickname),
260
+ // Summed from the instance when there is one: that is the room the party
261
+ // actually plays in, so it is the room that costs anything.
162
262
  totalCost: instance
163
263
  ? instance.totalCost
164
264
  : agents.reduce((sum, agent) => sum + agent.totalCost, 0),
165
265
  createdAt: room.getCreatedAt().toISOString(),
166
266
  };
167
267
  }
268
+ /**
269
+ * The party and the crew.
270
+ *
271
+ * Split on the pack template key rather than on `isControlledByHuman`, because an
272
+ * AI player is a player too — it is seated from the same template and shown in the
273
+ * same roster.
274
+ */
168
275
  splitRoster(room) {
169
276
  const configDir = this.userPaths.getCommonConfigDir();
170
277
  const players = [];