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,20 +1,59 @@
1
+ /**
2
+ * Turning a pack's templates into real agents and rooms.
3
+ *
4
+ * A pack ships a room the way a recipe ships a method: `rooms/table.json` names
5
+ * the agents it wants **by template key**, and every one of those keys is resolved
6
+ * to a created agent before anything is written. That indirection is the whole
7
+ * point — a template cannot name a nickname, because a nickname is derived at
8
+ * creation from the bare name's first word, the user may rename afterwards, and
9
+ * two agents in one room may not share one.
10
+ *
11
+ * ## Why the room is created first
12
+ *
13
+ * An agent carries `ownerRoomId`, and `AppService.listAgents` skips any agent that
14
+ * has one. So an agent written for a room that then failed to save is invisible
15
+ * and unreachable for good. Creating the room first means its id exists before any
16
+ * agent claims it, and the rollback deletes the room, which takes its agents with
17
+ * it.
18
+ *
19
+ * ## Why models come from the request
20
+ *
21
+ * A template says `modelRole: 'economy'`, never a model id. A pack that named
22
+ * `claude-sonnet-5` would go stale and would assume the host's keys — but the
23
+ * split still matters, since the dnd5e pack exists partly so combat runs on a
24
+ * cheap agent. The caller supplies one model per role.
25
+ */
1
26
  import { PromptFolderDefaults } from '../../../shared/types/app.types';
2
27
  import { AppService } from '../app.service';
3
28
  import { RoomStoreService } from '../room/room-store.service';
4
29
  import { PackService } from './pack.service';
30
+ /** Which model an instantiated agent should use, per the role its template asks for. */
5
31
  export interface ModelChoice {
6
32
  aiServiceName: string;
7
33
  aiModel: string;
34
+ /** Same-service smaller model, for mechanical prompts. Optional. */
8
35
  smallModelName?: string;
9
36
  }
10
37
  export interface InstantiateModels {
11
38
  primary: ModelChoice;
39
+ /** Falls back to {@link primary} when the caller offers only one. */
12
40
  economy?: ModelChoice;
13
41
  }
42
+ /**
43
+ * Per-agent changes to a room template's roster, keyed by the key the template
44
+ * addresses that agent by — its `as` when it has one, its template key otherwise.
45
+ *
46
+ * The reason this exists: a template ships a cast with fixed names, and the one
47
+ * thing an app almost always has to change is what the person at the keyboard is
48
+ * called. Without it, naming the player means either building the room by hand —
49
+ * giving up the ordering and the rollback this service exists for — or renaming
50
+ * the agent afterwards, once it has already introduced itself.
51
+ */
14
52
  export type RosterOverrides = Record<string, Partial<PromptFolderDefaults>>;
15
53
  export interface InstantiateRoomResult {
16
54
  roomId: string;
17
55
  agentIds: string[];
56
+ /** Things that did not go as the template asked, but did not stop the room. */
18
57
  warnings: string[];
19
58
  }
20
59
  export declare class PackInstantiationService {
@@ -22,15 +61,74 @@ export declare class PackInstantiationService {
22
61
  private readonly packs;
23
62
  private readonly roomStore;
24
63
  constructor(app: AppService, packs: PackService, roomStore: RoomStoreService);
64
+ /**
65
+ * Builds a room from a pack's room template, with its whole cast.
66
+ *
67
+ * @param packName The pack holding the template
68
+ * @param roomKey The room template's key
69
+ * @param models One model per role the templates ask for
70
+ * @param name Overrides the template's room name
71
+ * @param overrides Per-agent changes, keyed by roster key — most usefully
72
+ * `{ player: { agentNickname: 'Homer' } }`. Applied over the template's own
73
+ * overrides, which are applied over the prompt folder's defaults
74
+ * @returns The room, its agents, and anything that did not go to plan
75
+ * @throws {NotFoundError} If the pack or the template does not exist
76
+ * @throws {ValidationError} If the pack is off, the template is inconsistent, or
77
+ * an override names a key that is not on the roster
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const { roomId } = await packInstantiation.instantiateRoom(
82
+ * 'dnd5e', 'table',
83
+ * { primary: { aiServiceName: 'Anthropic', aiModel: 'claude-sonnet-5' } },
84
+ * 'Tuesday Night Game',
85
+ * { player: { agentName: 'Homer', agentNickname: 'Homer' } },
86
+ * );
87
+ * ```
88
+ */
25
89
  instantiateRoom(packName: string, roomKey: string, models: InstantiateModels, name?: string, overrides?: RosterOverrides): Promise<InstantiateRoomResult>;
90
+ /**
91
+ * Builds a single free-standing agent from a pack's agent template.
92
+ *
93
+ * Free-standing rather than room-owned: this is the "preconfigured witness with
94
+ * the right statements attached" case, which has to be usable before any
95
+ * courtroom exists.
96
+ *
97
+ * @param packName The pack holding the template
98
+ * @param agentKey The agent template's key
99
+ * @param models One model per role
100
+ * @param overrides Anything the caller wants to change, e.g. the agent's name
101
+ * @returns The agent's id and anything that did not go to plan
102
+ * @throws {NotFoundError} If the pack or the template does not exist
103
+ * @throws {ValidationError} If the pack is off
104
+ */
26
105
  instantiateAgent(packName: string, agentKey: string, models: InstantiateModels, overrides?: Partial<PromptFolderDefaults>): Promise<{
27
106
  agentId: string;
28
107
  warnings: string[];
29
108
  }>;
109
+ /** The pack, or a refusal that says which of the two things is wrong. */
30
110
  private requireEnabledPack;
111
+ /**
112
+ * A template's prompt folder, qualified with its own pack when it is bare.
113
+ *
114
+ * A template may name another pack's folder outright — that is how a
115
+ * case-specific pack reuses a generic one's `witness` folder — so an
116
+ * already-qualified reference is left alone.
117
+ */
31
118
  private qualify;
119
+ /** Resolves every roster entry to its template, refusing an unknown key. */
32
120
  private resolveRoster;
121
+ /** Checks a leader/moderator key names someone on the roster. */
33
122
  private requireRosterKey;
123
+ /** The model for a template's declared role, falling back to the primary. */
34
124
  private modelFor;
125
+ /**
126
+ * The template's name, suffixed if the user already has a room by it.
127
+ *
128
+ * Nothing enforces unique room names and rooms key on a UUID, so a second
129
+ * instantiation already worked — it just produced two indistinguishable entries
130
+ * in the sidebar. The suffix also reaches the agents, whose stored names carry
131
+ * the room's as a prefix.
132
+ */
35
133
  private uniqueRoomName;
36
134
  }
@@ -1,4 +1,29 @@
1
1
  "use strict";
2
+ /**
3
+ * Turning a pack's templates into real agents and rooms.
4
+ *
5
+ * A pack ships a room the way a recipe ships a method: `rooms/table.json` names
6
+ * the agents it wants **by template key**, and every one of those keys is resolved
7
+ * to a created agent before anything is written. That indirection is the whole
8
+ * point — a template cannot name a nickname, because a nickname is derived at
9
+ * creation from the bare name's first word, the user may rename afterwards, and
10
+ * two agents in one room may not share one.
11
+ *
12
+ * ## Why the room is created first
13
+ *
14
+ * An agent carries `ownerRoomId`, and `AppService.listAgents` skips any agent that
15
+ * has one. So an agent written for a room that then failed to save is invisible
16
+ * and unreachable for good. Creating the room first means its id exists before any
17
+ * agent claims it, and the rollback deletes the room, which takes its agents with
18
+ * it.
19
+ *
20
+ * ## Why models come from the request
21
+ *
22
+ * A template says `modelRole: 'economy'`, never a model id. A pack that named
23
+ * `claude-sonnet-5` would go stale and would assume the host's keys — but the
24
+ * split still matters, since the dnd5e pack exists partly so combat runs on a
25
+ * cheap agent. The caller supplies one model per role.
26
+ */
2
27
  Object.defineProperty(exports, "__esModule", { value: true });
3
28
  exports.PackInstantiationService = void 0;
4
29
  const room_store_service_1 = require("../room/room-store.service");
@@ -15,12 +40,38 @@ class PackInstantiationService {
15
40
  this.packs = packs;
16
41
  this.roomStore = roomStore;
17
42
  }
43
+ /**
44
+ * Builds a room from a pack's room template, with its whole cast.
45
+ *
46
+ * @param packName The pack holding the template
47
+ * @param roomKey The room template's key
48
+ * @param models One model per role the templates ask for
49
+ * @param name Overrides the template's room name
50
+ * @param overrides Per-agent changes, keyed by roster key — most usefully
51
+ * `{ player: { agentNickname: 'Homer' } }`. Applied over the template's own
52
+ * overrides, which are applied over the prompt folder's defaults
53
+ * @returns The room, its agents, and anything that did not go to plan
54
+ * @throws {NotFoundError} If the pack or the template does not exist
55
+ * @throws {ValidationError} If the pack is off, the template is inconsistent, or
56
+ * an override names a key that is not on the roster
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const { roomId } = await packInstantiation.instantiateRoom(
61
+ * 'dnd5e', 'table',
62
+ * { primary: { aiServiceName: 'Anthropic', aiModel: 'claude-sonnet-5' } },
63
+ * 'Tuesday Night Game',
64
+ * { player: { agentName: 'Homer', agentNickname: 'Homer' } },
65
+ * );
66
+ * ```
67
+ */
18
68
  async instantiateRoom(packName, roomKey, models, name, overrides) {
19
69
  const pack = this.requireEnabledPack(packName);
20
70
  const template = pack.rooms.find((room) => room.key === roomKey);
21
71
  if (!template) {
22
72
  throw new errors_1.NotFoundError(`Pack "${packName}" has no room template "${roomKey}"`);
23
73
  }
74
+ // Everything that can be known before a side effect is checked before one.
24
75
  const roster = this.resolveRoster(pack, template, overrides);
25
76
  const leaderKey = this.requireRosterKey(template, roster, template.roomLeader, 'roomLeader');
26
77
  const moderatorKey = this.requireRosterKey(template, roster, template.moderator, 'moderator');
@@ -29,6 +80,10 @@ class PackInstantiationService {
29
80
  const agentIds = [];
30
81
  const warnings = [];
31
82
  try {
83
+ // The moderator first, whatever order the template lists it in.
84
+ // createRoomAgent refuses an agent that wants a moderator before the room
85
+ // names one, so a template that happened to list a player first would
86
+ // fail on a room that is otherwise perfectly well formed.
32
87
  const ordered = [...roster].sort((a, b) => Number(b.key === moderatorKey) - Number(a.key === moderatorKey));
33
88
  const nicknames = new Map();
34
89
  for (const entry of ordered) {
@@ -44,6 +99,8 @@ class PackInstantiationService {
44
99
  for (const id of created.unresolvedDocumentIds) {
45
100
  warnings.push(`"${created.nickname}" could not attach the document ${id}`);
46
101
  }
102
+ // Named as soon as it exists, so the next agent that wants a
103
+ // moderator finds one.
47
104
  if (entry.key === moderatorKey) {
48
105
  const room = await this.roomStore.getRoom(roomId);
49
106
  room?.setModerator(created.nickname);
@@ -58,15 +115,25 @@ class PackInstantiationService {
58
115
  name: roomName,
59
116
  goal: template.goal,
60
117
  turnMode: template.turnMode ?? 'broadcast',
118
+ // Resolved to the nicknames the created agents actually ended up
119
+ // with, never the template's keys.
61
120
  roomLeader: leaderKey ? (nicknames.get(leaderKey) ?? '') : '',
62
121
  moderator: moderatorKey ? (nicknames.get(moderatorKey) ?? '') : '',
63
122
  pack: packName,
64
123
  packRoomKey: template.key,
124
+ beginInstruction: template.beginInstruction ?? '',
125
+ // A template that names neither leaves the room on the server's
126
+ // default model, drawing only when an agent asks.
127
+ imageModel: template.imageModel,
128
+ illustrationMode: template.illustrationMode ?? 'on-request',
65
129
  });
66
130
  room.saveMetadata();
67
131
  return { roomId, agentIds, warnings };
68
132
  }
69
133
  catch (error) {
134
+ // A half-built room is worse than none: one that cannot route its
135
+ // members' messages eats them, and removeRoom deletes the agents it owns,
136
+ // which would otherwise be invisible to listAgents forever.
70
137
  logger_1.logger.warn(`Rolling back room ${roomId} after a failed instantiation: ${error.message}`);
71
138
  await this.app.deleteRoom(roomId).catch((cleanupError) => {
72
139
  logger_1.logger.error(`Could not roll back room ${roomId}:`, cleanupError);
@@ -74,6 +141,21 @@ class PackInstantiationService {
74
141
  throw error;
75
142
  }
76
143
  }
144
+ /**
145
+ * Builds a single free-standing agent from a pack's agent template.
146
+ *
147
+ * Free-standing rather than room-owned: this is the "preconfigured witness with
148
+ * the right statements attached" case, which has to be usable before any
149
+ * courtroom exists.
150
+ *
151
+ * @param packName The pack holding the template
152
+ * @param agentKey The agent template's key
153
+ * @param models One model per role
154
+ * @param overrides Anything the caller wants to change, e.g. the agent's name
155
+ * @returns The agent's id and anything that did not go to plan
156
+ * @throws {NotFoundError} If the pack or the template does not exist
157
+ * @throws {ValidationError} If the pack is off
158
+ */
77
159
  async instantiateAgent(packName, agentKey, models, overrides) {
78
160
  const pack = this.requireEnabledPack(packName);
79
161
  const template = pack.agents.find((agent) => agent.key === agentKey);
@@ -90,6 +172,7 @@ class PackInstantiationService {
90
172
  agent.save();
91
173
  return { agentId: agent.id, warnings: [] };
92
174
  }
175
+ /** The pack, or a refusal that says which of the two things is wrong. */
93
176
  requireEnabledPack(packName) {
94
177
  const pack = this.packs.getPack(packName);
95
178
  if (!pack.enabled) {
@@ -97,11 +180,19 @@ class PackInstantiationService {
97
180
  }
98
181
  return pack;
99
182
  }
183
+ /**
184
+ * A template's prompt folder, qualified with its own pack when it is bare.
185
+ *
186
+ * A template may name another pack's folder outright — that is how a
187
+ * case-specific pack reuses a generic one's `witness` folder — so an
188
+ * already-qualified reference is left alone.
189
+ */
100
190
  qualify(pack, promptFolder) {
101
191
  return (0, prompt_resolver_1.isPackFolder)(promptFolder)
102
192
  ? promptFolder
103
193
  : (0, prompt_resolver_1.formatPromptFolder)({ pack: pack.name, folder: promptFolder });
104
194
  }
195
+ /** Resolves every roster entry to its template, refusing an unknown key. */
105
196
  resolveRoster(pack, template, callerOverrides) {
106
197
  const byKey = new Map(pack.agents.map((agent) => [agent.key, agent]));
107
198
  const seen = new Set();
@@ -126,6 +217,9 @@ class PackInstantiationService {
126
217
  },
127
218
  };
128
219
  });
220
+ // A key with no seat is a typo, and a typo that silently does nothing is
221
+ // the failure this whole argument exists to prevent — the caller would get
222
+ // a room whose player is still called PlayerOne and no reason why.
129
223
  for (const key of Object.keys(callerOverrides ?? {})) {
130
224
  if (!resolved.some((entry) => entry.key === key)) {
131
225
  throw new errors_1.ValidationError(`Room template "${template.key}" has no agent "${key}" to override. ` +
@@ -134,6 +228,7 @@ class PackInstantiationService {
134
228
  }
135
229
  return resolved;
136
230
  }
231
+ /** Checks a leader/moderator key names someone on the roster. */
137
232
  requireRosterKey(template, roster, key, field) {
138
233
  if (!key)
139
234
  return undefined;
@@ -142,6 +237,7 @@ class PackInstantiationService {
142
237
  }
143
238
  return key;
144
239
  }
240
+ /** The model for a template's declared role, falling back to the primary. */
145
241
  modelFor(template, models) {
146
242
  const choice = template.modelRole === 'economy' ? (models.economy ?? models.primary) : models.primary;
147
243
  return {
@@ -150,6 +246,14 @@ class PackInstantiationService {
150
246
  smallModelName: choice.smallModelName,
151
247
  };
152
248
  }
249
+ /**
250
+ * The template's name, suffixed if the user already has a room by it.
251
+ *
252
+ * Nothing enforces unique room names and rooms key on a UUID, so a second
253
+ * instantiation already worked — it just produced two indistinguishable entries
254
+ * in the sidebar. The suffix also reaches the agents, whose stored names carry
255
+ * the room's as a prefix.
256
+ */
153
257
  async uniqueRoomName(preferred) {
154
258
  const taken = new Set((await this.roomStore.getTemplateRooms()).map((room) => room.name.trim().toLowerCase()));
155
259
  if (!taken.has(preferred.toLowerCase()))
@@ -1,52 +1,166 @@
1
+ /**
2
+ * What a pack directory is, and how to read one.
3
+ *
4
+ * A pack gathers everything one domain needs — prompt folders, documents, agent
5
+ * and room templates, and the names of the native tools it expects — into a
6
+ * directory a host can drop in or a user can create.
7
+ *
8
+ * ```
9
+ * packs/dnd5e/
10
+ * pack.json metadata; optional
11
+ * prompts/<folder>/ prompt folders, referenced as dnd5e:<folder>
12
+ * artifacts/ manifest.json + .md, read by pack-artifacts.ts
13
+ * agents/*.json agent templates
14
+ * rooms/*.json room templates
15
+ * ```
16
+ *
17
+ * Almost nothing is declared. The prompt folders, documents, templates and
18
+ * required tools are all discovered by reading the directory, because a declared
19
+ * copy of a directory listing drifts from it — which is the mistake
20
+ * `prompt-folders.spec.ts` exists to catch in the D&D prompts.
21
+ *
22
+ * `pack.json` is optional. A directory holding only `artifacts/manifest.json` is
23
+ * still a pack, titled after itself.
24
+ */
1
25
  import { PromptFolderDefaults } from '../../../shared/types/app.types';
26
+ /** Subdirectories of a pack, by what they hold. */
2
27
  export declare const PACK_SUBDIR: {
3
28
  readonly prompts: "prompts";
4
29
  readonly artifacts: "artifacts";
5
30
  readonly agents: "agents";
6
31
  readonly rooms: "rooms";
7
32
  };
33
+ /** The optional `pack.json`. */
8
34
  export interface PackManifest {
35
+ /** Must equal the directory name. */
9
36
  pack: string;
37
+ /** Display name; falls back to the pack name. */
10
38
  title?: string;
11
39
  description?: string;
12
40
  version?: string;
41
+ /**
42
+ * Tool names the pack needs that nothing else in it declares.
43
+ *
44
+ * Rarely needed: the requirement is normally derived from the `toolNames` its
45
+ * prompt folders and agent templates already grant. This is for a tool a pack
46
+ * expects to call but has not wired into a grant yet.
47
+ */
13
48
  requiresTools?: string[];
49
+ /**
50
+ * Other packs this one expects. A warning on the Packs page and nothing more —
51
+ * never an auto-enable, never a block.
52
+ */
14
53
  requiresPacks?: string[];
15
54
  }
55
+ /**
56
+ * One agent a pack ships, as a reference to a prompt folder plus overrides.
57
+ *
58
+ * Not a trimmed `AgentConfig`. `createAgentFromFolder` already exists so callers
59
+ * stop transcribing a folder's recipe, and `defaults_config.json` is the list
60
+ * `prompt-folders.spec.ts` treats as authoritative — a template with its own copy
61
+ * of `toolNames` would be a second list that drifts from it.
62
+ */
16
63
  export interface PackAgentTemplate {
64
+ /** Stable within the pack. Room templates reference agents by this. */
17
65
  key: string;
66
+ /** A folder in this pack, or a `<pack>:<folder>` reference to another. */
18
67
  promptFolder: string;
68
+ /** Shown in the pack listing and the pickers. Falls back to the key. */
19
69
  label?: string;
70
+ /**
71
+ * Which model tier this agent wants.
72
+ *
73
+ * A pack cannot name a model: the id goes stale and assumes the host's keys.
74
+ * But the split matters — the dnd5e pack exists partly so combat runs on a
75
+ * cheap agent — so the template says which tier it wants and instantiation
76
+ * supplies the models.
77
+ */
20
78
  modelRole?: 'primary' | 'economy';
79
+ /** Anything the folder's own defaults should not decide, e.g. a witness's name. */
21
80
  overrides?: Partial<PromptFolderDefaults>;
22
81
  }
82
+ /** One entry in a room template's roster. */
23
83
  export interface PackRoomAgentEntry {
84
+ /** An agent template key in this pack. */
24
85
  key: string;
86
+ /**
87
+ * A distinct key for this instance, when one template is used more than once.
88
+ * Lets `roomLeader` and `moderator` stay unambiguous with four players at a table.
89
+ */
25
90
  as?: string;
26
91
  overrides?: Partial<PromptFolderDefaults>;
27
92
  }
93
+ /** A room a pack ships, ready to instantiate with its whole cast. */
28
94
  export interface PackRoomTemplate {
29
95
  key: string;
30
96
  name: string;
31
97
  goal: string;
32
98
  turnMode?: 'broadcast' | 'directed';
99
+ /**
100
+ * Which entry in `image_models.json` draws this room, when the pack wants a
101
+ * particular one. Absent leaves the room on the server default.
102
+ */
103
+ imageModel?: string;
104
+ /** When the room illustrates itself. Absent means `on-request`. */
105
+ illustrationMode?: 'off' | 'on-request' | 'auto';
106
+ /**
107
+ * The roster, as loaded.
108
+ *
109
+ * In the JSON a bare string is accepted as sugar for `{ key }`;
110
+ * {@link readPack} normalizes it, so by the time anything else sees a template
111
+ * every entry is an object.
112
+ */
33
113
  agents: PackRoomAgentEntry[];
114
+ /**
115
+ * The leader, named by **agent key** rather than by nickname.
116
+ *
117
+ * A template cannot carry a nickname: the nickname is derived at creation from
118
+ * the bare name's first word, the user may rename, and two agents in a room may
119
+ * not share one. Instantiation resolves the key to whatever nickname the
120
+ * created agent ended up with.
121
+ */
34
122
  roomLeader?: string;
123
+ /** The moderator, also named by agent key. */
35
124
  moderator?: string;
125
+ /**
126
+ * What Begin sends to this room's leader, shipped with the template.
127
+ *
128
+ * Here rather than in whatever service builds the room, so a pack's opening
129
+ * move is written beside the prompts it has to agree with.
130
+ */
131
+ beginInstruction?: string;
36
132
  }
133
+ /** A pack directory, read. */
37
134
  export interface LoadedPack {
38
135
  name: string;
39
136
  title: string;
40
137
  description?: string;
41
138
  version?: string;
139
+ /** Where it lives. */
42
140
  dir: string;
141
+ /** Installed by the host, or created by this user. */
43
142
  origin: PackOrigin;
44
143
  promptFolders: string[];
45
144
  agents: PackAgentTemplate[];
46
145
  rooms: PackRoomTemplate[];
146
+ /** Tool names the pack's grants and manifest between them ask for. */
47
147
  requiresTools: string[];
48
148
  requiresPacks: string[];
49
149
  }
50
150
  export type PackOrigin = 'host' | 'user';
151
+ /**
152
+ * Reads a pack directory.
153
+ *
154
+ * Nothing here throws on bad content. A malformed template is dropped with a
155
+ * warning and the rest of the pack loads, for the same reason
156
+ * `pack-artifacts.ts` skips a bad manifest entry: one broken file a host dropped
157
+ * in must not take out the page that lists everything else.
158
+ *
159
+ * @param dir The pack directory
160
+ * @param name The directory name, which the manifest must agree with
161
+ * @param origin Where the directory came from
162
+ * @returns The pack, or null if the name is invalid or the directory is missing
163
+ */
51
164
  export declare function readPack(dir: string, name: string, origin: PackOrigin): LoadedPack | null;
165
+ /** The key an entry is addressed by, which is `as` when it has one. */
52
166
  export declare function roomAgentKey(entry: PackRoomAgentEntry): string;
@@ -1,4 +1,28 @@
1
1
  "use strict";
2
+ /**
3
+ * What a pack directory is, and how to read one.
4
+ *
5
+ * A pack gathers everything one domain needs — prompt folders, documents, agent
6
+ * and room templates, and the names of the native tools it expects — into a
7
+ * directory a host can drop in or a user can create.
8
+ *
9
+ * ```
10
+ * packs/dnd5e/
11
+ * pack.json metadata; optional
12
+ * prompts/<folder>/ prompt folders, referenced as dnd5e:<folder>
13
+ * artifacts/ manifest.json + .md, read by pack-artifacts.ts
14
+ * agents/*.json agent templates
15
+ * rooms/*.json room templates
16
+ * ```
17
+ *
18
+ * Almost nothing is declared. The prompt folders, documents, templates and
19
+ * required tools are all discovered by reading the directory, because a declared
20
+ * copy of a directory listing drifts from it — which is the mistake
21
+ * `prompt-folders.spec.ts` exists to catch in the D&D prompts.
22
+ *
23
+ * `pack.json` is optional. A directory holding only `artifacts/manifest.json` is
24
+ * still a pack, titled after itself.
25
+ */
2
26
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
27
  if (k2 === undefined) k2 = k;
4
28
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -40,12 +64,26 @@ const fs = __importStar(require("fs"));
40
64
  const path = __importStar(require("path"));
41
65
  const prompt_resolver_1 = require("../config/prompt-resolver");
42
66
  const logger_1 = require("../common/logger");
67
+ /** Subdirectories of a pack, by what they hold. */
43
68
  exports.PACK_SUBDIR = {
44
69
  prompts: 'prompts',
45
70
  artifacts: 'artifacts',
46
71
  agents: 'agents',
47
72
  rooms: 'rooms',
48
73
  };
74
+ /**
75
+ * Reads a pack directory.
76
+ *
77
+ * Nothing here throws on bad content. A malformed template is dropped with a
78
+ * warning and the rest of the pack loads, for the same reason
79
+ * `pack-artifacts.ts` skips a bad manifest entry: one broken file a host dropped
80
+ * in must not take out the page that lists everything else.
81
+ *
82
+ * @param dir The pack directory
83
+ * @param name The directory name, which the manifest must agree with
84
+ * @param origin Where the directory came from
85
+ * @returns The pack, or null if the name is invalid or the directory is missing
86
+ */
49
87
  function readPack(dir, name, origin) {
50
88
  if (!(0, prompt_resolver_1.isValidPackName)(name)) {
51
89
  logger_1.logger.warn(`Ignoring pack directory "${name}": a pack name must be lowercase letters, digits, "_" or "-"`);
@@ -72,6 +110,14 @@ function readPack(dir, name, origin) {
72
110
  requiresPacks: (manifest?.requiresPacks ?? []).filter(prompt_resolver_1.isValidPackName),
73
111
  };
74
112
  }
113
+ /**
114
+ * Every tool name the pack asks for, derived rather than declared.
115
+ *
116
+ * The union of what its prompt folders grant, what its agent templates add, and
117
+ * whatever `requiresTools` names. Derived because a hand-kept list disagrees with
118
+ * the grants sooner or later, and then the "missing tools" warning is wrong in
119
+ * whichever direction is least helpful.
120
+ */
75
121
  function deriveRequiredTools(dir, promptFolders, agents, manifest) {
76
122
  const names = new Set(manifest?.requiresTools ?? []);
77
123
  for (const folder of promptFolders) {
@@ -95,6 +141,7 @@ function readManifest(dir, name) {
95
141
  }
96
142
  return manifest;
97
143
  }
144
+ /** Reads every `.json` in a subdirectory, dropping the ones that do not validate. */
98
145
  function readTemplates(dir, subdir, validate) {
99
146
  const templateDir = path.join(dir, subdir);
100
147
  if (!fs.existsSync(templateDir))
@@ -118,6 +165,7 @@ function readTemplates(dir, subdir, validate) {
118
165
  }
119
166
  return templates;
120
167
  }
168
+ /** A key has to be usable in a filename and a JSON reference, so borrow the pack rule. */
121
169
  function isValidKey(key) {
122
170
  return typeof key === 'string' && /^[a-z0-9][a-z0-9_-]*$/.test(key);
123
171
  }
@@ -146,6 +194,15 @@ function validateAgentTemplate(value, file) {
146
194
  : {}),
147
195
  };
148
196
  }
197
+ /**
198
+ * Fields a template may never set.
199
+ *
200
+ * The billing three are the reason this is a list and not a comment: a pack that
201
+ * could set `disableBalanceCheck` is a pack that spends the host's money. The
202
+ * rest either resurrect state that belongs to some other agent (`history`,
203
+ * `attachedFiles`, the totals) or change which list the agent appears in
204
+ * (`isPublished`, `ownerRoomId`, the template ids).
205
+ */
149
206
  const FORBIDDEN_OVERRIDE_KEYS = new Set([
150
207
  'id',
151
208
  'createdAt',
@@ -210,9 +267,20 @@ function validateRoomTemplate(value, file) {
210
267
  ...(value.turnMode === 'directed' || value.turnMode === 'broadcast'
211
268
  ? { turnMode: value.turnMode }
212
269
  : {}),
270
+ ...(typeof value.imageModel === 'string' &&
271
+ value.imageModel.trim() && { imageModel: value.imageModel.trim() }),
272
+ ...(value.illustrationMode === 'off' ||
273
+ value.illustrationMode === 'on-request' ||
274
+ value.illustrationMode === 'auto'
275
+ ? { illustrationMode: value.illustrationMode }
276
+ : {}),
213
277
  agents,
214
278
  ...(isValidKey(value.roomLeader) && { roomLeader: value.roomLeader }),
215
279
  ...(isValidKey(value.moderator) && { moderator: value.moderator }),
280
+ ...(typeof value.beginInstruction === 'string' &&
281
+ value.beginInstruction.trim() && {
282
+ beginInstruction: value.beginInstruction.trim(),
283
+ }),
216
284
  };
217
285
  }
218
286
  function normalizeRoomAgentEntry(entry, file) {
@@ -231,6 +299,7 @@ function normalizeRoomAgentEntry(entry, file) {
231
299
  : {}),
232
300
  };
233
301
  }
302
+ /** The key an entry is addressed by, which is `as` when it has one. */
234
303
  function roomAgentKey(entry) {
235
304
  return entry.as ?? entry.key;
236
305
  }