briyah 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (477) hide show
  1. package/LICENSE +216 -0
  2. package/README.md +43 -7
  3. package/data/common/config/LICENSE-model-prices.md +65 -0
  4. package/data/common/config/markup +1 -1
  5. package/data/common/config/model_prices.json +47443 -46295
  6. package/data/common/prompts/narrator/create_story.prompt +2 -0
  7. package/data/packs/dnd5e/agents/player.json +11 -11
  8. package/data/packs/dnd5e/prompts/character_creator/defaults_config.json +21 -20
  9. package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +19 -12
  10. package/data/packs/dnd5e/prompts/dnd_player/perceive.prompt +10 -6
  11. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
  12. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
  13. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
  14. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
  15. package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
  16. package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
  17. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
  18. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
  19. package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
  20. package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
  21. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
  22. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
  23. package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
  24. package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
  25. package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
  26. package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
  27. package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
  28. package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
  29. package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
  30. package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
  31. package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
  32. package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
  33. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
  34. package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
  35. package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
  36. package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
  37. package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
  38. package/dist-sdk/server/src/ai/agent-factory.js +20 -0
  39. package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
  40. package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
  41. package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
  42. package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
  43. package/dist-sdk/server/src/ai/agent.d.ts +196 -0
  44. package/dist-sdk/server/src/ai/agent.js +224 -11
  45. package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
  46. package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
  47. package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
  48. package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
  49. package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
  50. package/dist-sdk/server/src/ai/artifact.service.js +148 -3
  51. package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
  52. package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
  53. package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
  54. package/dist-sdk/server/src/ai/model_prices.js +91 -5
  55. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
  56. package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
  57. package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
  58. package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
  59. package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
  60. package/dist-sdk/server/src/app/balance-message.service.js +24 -0
  61. package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
  62. package/dist-sdk/server/src/app/balance.module.js +4 -0
  63. package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
  64. package/dist-sdk/server/src/app/balance.service.js +54 -0
  65. package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
  66. package/dist-sdk/server/src/app/stripe.controller.js +35 -0
  67. package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
  68. package/dist-sdk/server/src/app/stripe.service.js +62 -0
  69. package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
  70. package/dist-sdk/server/src/app/transaction.service.js +36 -0
  71. package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
  72. package/dist-sdk/server/src/app/user-service-factory.js +38 -1
  73. package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
  74. package/dist-sdk/server/src/app/user-service-manager.js +43 -0
  75. package/dist-sdk/server/src/app.controller.d.ts +87 -0
  76. package/dist-sdk/server/src/app.controller.js +272 -12
  77. package/dist-sdk/server/src/app.module.js +28 -6
  78. package/dist-sdk/server/src/app.service.d.ts +1662 -0
  79. package/dist-sdk/server/src/app.service.js +1862 -6
  80. package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
  81. package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
  82. package/dist-sdk/server/src/auth/auth.controller.js +46 -0
  83. package/dist-sdk/server/src/auth/auth.module.js +3 -2
  84. package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
  85. package/dist-sdk/server/src/auth/auth.service.js +39 -3
  86. package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
  87. package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
  88. package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
  89. package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
  90. package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
  91. package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
  92. package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
  93. package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
  94. package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
  95. package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
  96. package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
  97. package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
  98. package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
  99. package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
  100. package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
  101. package/dist-sdk/server/src/auth/session.guard.js +8 -0
  102. package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
  103. package/dist-sdk/server/src/auth/twilio.service.js +30 -4
  104. package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
  105. package/dist-sdk/server/src/auth/users.service.js +42 -0
  106. package/dist-sdk/server/src/common/errors.d.ts +20 -0
  107. package/dist-sdk/server/src/common/errors.js +21 -0
  108. package/dist-sdk/server/src/config/env-config.d.ts +7 -0
  109. package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
  110. package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
  111. package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
  112. package/dist-sdk/server/src/config/user-config.service.js +57 -0
  113. package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
  114. package/dist-sdk/server/src/config/user-paths.service.js +67 -0
  115. package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
  116. package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
  117. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
  118. package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
  119. package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
  120. package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
  121. package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
  122. package/dist-sdk/server/src/packs/pack.service.js +98 -1
  123. package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
  124. package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
  125. package/dist-sdk/server/src/room/artifact.d.ts +18 -0
  126. package/dist-sdk/server/src/room/message.d.ts +64 -0
  127. package/dist-sdk/server/src/room/message.js +77 -2
  128. package/dist-sdk/server/src/room/nickname.d.ts +27 -0
  129. package/dist-sdk/server/src/room/nickname.js +41 -0
  130. package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
  131. package/dist-sdk/server/src/room/room-config.d.ts +26 -0
  132. package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
  133. package/dist-sdk/server/src/room/room-factory.js +14 -0
  134. package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
  135. package/dist-sdk/server/src/room/room-message.service.js +28 -0
  136. package/dist-sdk/server/src/room/room-store.service.d.ts +177 -0
  137. package/dist-sdk/server/src/room/room-store.service.js +242 -5
  138. package/dist-sdk/server/src/room/room.d.ts +906 -1
  139. package/dist-sdk/server/src/room/room.js +1525 -34
  140. package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
  141. package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
  142. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +38 -3
  143. package/dist-sdk/server/src/rpg/rpg-roster.js +49 -49
  144. package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
  145. package/dist-sdk/server/src/rpg/rpg.service.js +108 -5
  146. package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
  147. package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
  148. package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
  149. package/dist-sdk/server/src/sdk/briyah.js +285 -7
  150. package/dist-sdk/server/src/sdk/index.d.ts +0 -1
  151. package/dist-sdk/server/src/sdk/index.js +24 -3
  152. package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
  153. package/dist-sdk/server/src/shared/shared.module.js +13 -5
  154. package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
  155. package/dist-sdk/server/src/story/story-message.service.js +43 -0
  156. package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
  157. package/dist-sdk/server/src/story/story-progress.service.js +23 -0
  158. package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
  159. package/dist-sdk/server/src/story/story-store.service.js +136 -1
  160. package/dist-sdk/server/src/story/story.service.d.ts +398 -0
  161. package/dist-sdk/server/src/story/story.service.js +829 -25
  162. package/dist-sdk/server/src/tools/core/index.d.ts +25 -0
  163. package/dist-sdk/server/src/tools/core/index.js +31 -0
  164. package/dist-sdk/server/src/tools/core/rename.tool.d.ts +10 -0
  165. package/dist-sdk/server/src/tools/core/rename.tool.js +72 -0
  166. package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
  167. package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
  168. package/dist-sdk/server/src/tools/native-tool.types.d.ts +186 -0
  169. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
  170. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
  171. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
  172. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
  173. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
  174. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
  175. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
  176. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
  177. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
  178. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
  179. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
  180. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
  181. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
  182. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
  183. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
  184. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
  185. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
  186. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
  187. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
  188. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
  189. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
  190. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
  191. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
  192. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
  193. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
  194. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
  195. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
  196. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
  197. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
  198. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
  199. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
  200. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
  201. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
  202. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
  203. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
  204. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
  205. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
  206. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
  207. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
  208. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
  209. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
  210. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
  211. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
  212. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
  213. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
  214. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
  215. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
  216. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
  217. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
  218. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
  219. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
  220. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
  221. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
  222. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
  223. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
  224. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
  225. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
  226. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
  227. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
  228. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
  229. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
  230. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
  231. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
  232. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
  233. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
  234. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
  235. package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
  236. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
  237. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
  238. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
  239. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
  240. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
  241. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
  242. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
  243. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
  244. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
  245. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
  246. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
  247. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
  248. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
  249. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
  250. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
  251. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
  252. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +125 -1
  253. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
  254. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
  255. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
  256. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
  257. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
  258. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
  259. package/dist-sdk/server/src/tools/packs/index.d.ts +52 -2
  260. package/dist-sdk/server/src/tools/packs/index.js +83 -9
  261. package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
  262. package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
  263. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
  264. package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
  265. package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
  266. package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
  267. package/dist-sdk/shared/types/app.types.d.ts +285 -14
  268. package/dist-sdk/shared/types/app.types.js +3 -0
  269. package/package.json +167 -139
  270. package/data/common/config/random_words.txt +0 -2241
  271. package/data/common/story_ideas/biblical.json +0 -122
  272. package/data/common/story_ideas/fantasy.json +0 -82
  273. package/data/common/story_ideas/historical_fiction.json +0 -82
  274. package/data/common/story_ideas/science_fiction.json +0 -82
  275. package/data/packs/acts/agents/character-guide.json +0 -6
  276. package/data/packs/acts/agents/discipleship-mentor.json +0 -6
  277. package/data/packs/acts/agents/mentor-coach.json +0 -6
  278. package/data/packs/acts/agents/student.json +0 -13
  279. package/data/packs/acts/agents/table-moderator.json +0 -6
  280. package/data/packs/acts/artifacts/chapter-01-acts-1.md +0 -405
  281. package/data/packs/acts/artifacts/chapter-02-acts-2.md +0 -443
  282. package/data/packs/acts/artifacts/chapter-03-acts-3.md +0 -409
  283. package/data/packs/acts/artifacts/chapter-04-acts-4.md +0 -438
  284. package/data/packs/acts/artifacts/chapter-05-acts-5.md +0 -434
  285. package/data/packs/acts/artifacts/chapter-06-acts-6.md +0 -441
  286. package/data/packs/acts/artifacts/chapter-07-acts-7.md +0 -472
  287. package/data/packs/acts/artifacts/chapter-08-acts-8.md +0 -512
  288. package/data/packs/acts/artifacts/chapter-09-acts-9.md +0 -346
  289. package/data/packs/acts/artifacts/chapter-10-acts-10.md +0 -367
  290. package/data/packs/acts/artifacts/chapter-11-acts-11.md +0 -391
  291. package/data/packs/acts/artifacts/chapter-12-acts-12.md +0 -390
  292. package/data/packs/acts/artifacts/chapter-13-acts-13.md +0 -388
  293. package/data/packs/acts/artifacts/chapter-14-acts-14.md +0 -466
  294. package/data/packs/acts/artifacts/chapter-15-acts-15.md +0 -413
  295. package/data/packs/acts/artifacts/chapter-16-acts-16.md +0 -585
  296. package/data/packs/acts/artifacts/chapter-17-acts-17.md +0 -428
  297. package/data/packs/acts/artifacts/chapter-18-acts-18.md +0 -486
  298. package/data/packs/acts/artifacts/chapter-19-acts-19.md +0 -461
  299. package/data/packs/acts/artifacts/chapter-20-acts-20.md +0 -389
  300. package/data/packs/acts/artifacts/chapter-21-acts-21.md +0 -452
  301. package/data/packs/acts/artifacts/chapter-22-acts-22.md +0 -424
  302. package/data/packs/acts/artifacts/chapter-23-acts-23.md +0 -395
  303. package/data/packs/acts/artifacts/chapter-24-acts-24.md +0 -446
  304. package/data/packs/acts/artifacts/chapter-25-acts-25.md +0 -391
  305. package/data/packs/acts/artifacts/chapter-26-acts-26.md +0 -431
  306. package/data/packs/acts/artifacts/chapter-27-acts-27.md +0 -530
  307. package/data/packs/acts/artifacts/chapter-28-acts-28.md +0 -1871
  308. package/data/packs/acts/artifacts/chapters.manifest.json +0 -170
  309. package/data/packs/acts/artifacts/character_guide-creation.md +0 -112
  310. package/data/packs/acts/artifacts/discipleship_mentor-procedure.md +0 -154
  311. package/data/packs/acts/artifacts/discipleship_mentor-systems.md +0 -72
  312. package/data/packs/acts/artifacts/manifest.json +0 -197
  313. package/data/packs/acts/artifacts/stage-guide.md +0 -94
  314. package/data/packs/acts/pack.json +0 -6
  315. package/data/packs/acts/prompts/acts_player/defaults_config.json +0 -5
  316. package/data/packs/acts/prompts/acts_player/perceive.json +0 -29
  317. package/data/packs/acts/prompts/acts_player/perceive.prompt +0 -87
  318. package/data/packs/acts/prompts/acts_player/system_instruction.prompt +0 -0
  319. package/data/packs/acts/prompts/acts_room_moderator/defaults_config.json +0 -9
  320. package/data/packs/acts/prompts/acts_room_moderator/moderate.json +0 -34
  321. package/data/packs/acts/prompts/acts_room_moderator/moderate.prompt +0 -70
  322. package/data/packs/acts/prompts/acts_room_moderator/system_instruction.prompt +0 -0
  323. package/data/packs/acts/prompts/character_guide/defaults_config.json +0 -18
  324. package/data/packs/acts/prompts/character_guide/perceive.json +0 -29
  325. package/data/packs/acts/prompts/character_guide/perceive.prompt +0 -140
  326. package/data/packs/acts/prompts/character_guide/system_instruction.prompt +0 -0
  327. package/data/packs/acts/prompts/discipleship_mentor/defaults_config.json +0 -23
  328. package/data/packs/acts/prompts/discipleship_mentor/perceive.json +0 -33
  329. package/data/packs/acts/prompts/discipleship_mentor/perceive.prompt +0 -245
  330. package/data/packs/acts/prompts/discipleship_mentor/system_instruction.prompt +0 -0
  331. package/data/packs/acts/prompts/mentor_coach/defaults_config.json +0 -13
  332. package/data/packs/acts/prompts/mentor_coach/perceive.json +0 -29
  333. package/data/packs/acts/prompts/mentor_coach/perceive.prompt +0 -87
  334. package/data/packs/acts/prompts/mentor_coach/system_instruction.prompt +0 -0
  335. package/data/packs/acts/rooms/session.json +0 -14
  336. package/data/packs/acts/rooms/training.json +0 -58
  337. package/dist-sdk/server/src/tools/packs/acts/data/cards.d.ts +0 -53
  338. package/dist-sdk/server/src/tools/packs/acts/data/cards.js +0 -54
  339. package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.d.ts +0 -2
  340. package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.js +0 -185
  341. package/dist-sdk/server/src/tools/packs/acts/data/encounters.d.ts +0 -12
  342. package/dist-sdk/server/src/tools/packs/acts/data/encounters.js +0 -102
  343. package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.d.ts +0 -2
  344. package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.js +0 -196
  345. package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.d.ts +0 -2
  346. package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.js +0 -1311
  347. package/dist-sdk/server/src/tools/packs/acts/engine/cards.d.ts +0 -5
  348. package/dist-sdk/server/src/tools/packs/acts/engine/cards.js +0 -27
  349. package/dist-sdk/server/src/tools/packs/acts/engine/challenge.d.ts +0 -37
  350. package/dist-sdk/server/src/tools/packs/acts/engine/challenge.js +0 -120
  351. package/dist-sdk/server/src/tools/packs/acts/engine/dice.d.ts +0 -20
  352. package/dist-sdk/server/src/tools/packs/acts/engine/dice.js +0 -41
  353. package/dist-sdk/server/src/tools/packs/acts/engine/sheet.d.ts +0 -54
  354. package/dist-sdk/server/src/tools/packs/acts/engine/sheet.js +0 -200
  355. package/dist-sdk/server/src/tools/packs/acts/index.d.ts +0 -2
  356. package/dist-sdk/server/src/tools/packs/acts/index.js +0 -24
  357. package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.d.ts +0 -2
  358. package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.js +0 -184
  359. package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.d.ts +0 -2
  360. package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.js +0 -107
  361. package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.d.ts +0 -3
  362. package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.js +0 -146
  363. package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.d.ts +0 -4
  364. package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.js +0 -241
  365. package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.d.ts +0 -3
  366. package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.js +0 -72
  367. package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.d.ts +0 -2
  368. package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.js +0 -75
  369. package/dist-sdk/server/src/tools/packs/acts/tools/shared.d.ts +0 -20
  370. package/dist-sdk/server/src/tools/packs/acts/tools/shared.js +0 -70
  371. package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.d.ts +0 -4
  372. package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.js +0 -215
  373. package/docs/.nojekyll +0 -1
  374. package/docs/assets/hierarchy.js +0 -1
  375. package/docs/assets/highlight.css +0 -113
  376. package/docs/assets/icons.js +0 -18
  377. package/docs/assets/icons.svg +0 -1
  378. package/docs/assets/main.js +0 -60
  379. package/docs/assets/navigation.js +0 -1
  380. package/docs/assets/search.js +0 -1
  381. package/docs/assets/style.css +0 -1648
  382. package/docs/classes/Agent.html +0 -801
  383. package/docs/classes/Briyah.html +0 -296
  384. package/docs/classes/BriyahConfigService.html +0 -119
  385. package/docs/classes/NativeToolRegistry.html +0 -166
  386. package/docs/classes/PackInstantiationService.html +0 -157
  387. package/docs/classes/PackService.html +0 -247
  388. package/docs/classes/Room.html +0 -1338
  389. package/docs/classes/RoomMessage.html +0 -290
  390. package/docs/enums/MessageAction.html +0 -136
  391. package/docs/functions/actsTools.html +0 -44
  392. package/docs/functions/availableToolPacks.html +0 -41
  393. package/docs/functions/buildMarkdown.html +0 -54
  394. package/docs/functions/dnd5eTools.html +0 -44
  395. package/docs/functions/installToolPacks.html +0 -48
  396. package/docs/functions/pageMarker.html +0 -45
  397. package/docs/functions/registerToolPacks.html +0 -54
  398. package/docs/functions/splitMarkdownIntoPages.html +0 -51
  399. package/docs/functions/stripWrappingFence.html +0 -52
  400. package/docs/hierarchy.html +0 -46
  401. package/docs/index.html +0 -595
  402. package/docs/interfaces/AgentCreationOptions.html +0 -125
  403. package/docs/interfaces/AgentInfo.html +0 -218
  404. package/docs/interfaces/AgentMessagesResponse.html +0 -74
  405. package/docs/interfaces/AppService.html +0 -3337
  406. package/docs/interfaces/Artifact.html +0 -95
  407. package/docs/interfaces/ArtifactMetadata.html +0 -112
  408. package/docs/interfaces/ArtifactWriteOptions.html +0 -90
  409. package/docs/interfaces/AttachDocumentResponse.html +0 -62
  410. package/docs/interfaces/BriyahConfigOptions.html +0 -124
  411. package/docs/interfaces/ChapterInfo.html +0 -62
  412. package/docs/interfaces/Character.html +0 -86
  413. package/docs/interfaces/ConversionAgent.html +0 -78
  414. package/docs/interfaces/CreateAgentResponse.html +0 -56
  415. package/docs/interfaces/CreateRoomResponse.html +0 -62
  416. package/docs/interfaces/CreateStoryResponse.html +0 -56
  417. package/docs/interfaces/FileList.html +0 -56
  418. package/docs/interfaces/FileMetadata.html +0 -89
  419. package/docs/interfaces/IConfigService.html +0 -79
  420. package/docs/interfaces/InstantiateModels.html +0 -64
  421. package/docs/interfaces/InstantiateRoomResult.html +0 -70
  422. package/docs/interfaces/LoadedPack.html +0 -131
  423. package/docs/interfaces/LoggingOptions.html +0 -92
  424. package/docs/interfaces/Message.html +0 -84
  425. package/docs/interfaces/ModelChoice.html +0 -73
  426. package/docs/interfaces/ModelInfo.html +0 -74
  427. package/docs/interfaces/NativeToolDefinition.html +0 -107
  428. package/docs/interfaces/PackAgentTemplate.html +0 -101
  429. package/docs/interfaces/PackRoomTemplate.html +0 -108
  430. package/docs/interfaces/PackView.html +0 -172
  431. package/docs/interfaces/PdfConversionOptions.html +0 -102
  432. package/docs/interfaces/PdfConversionResult.html +0 -97
  433. package/docs/interfaces/PdfMarkdownOptions.html +0 -198
  434. package/docs/interfaces/PdfMarkdownResult.html +0 -106
  435. package/docs/interfaces/PdfPageMarkdown.html +0 -94
  436. package/docs/interfaces/PreparedPromptResponse.html +0 -62
  437. package/docs/interfaces/ProcessTextResponse.html +0 -86
  438. package/docs/interfaces/PromptFile.html +0 -70
  439. package/docs/interfaces/PromptFileContent.html +0 -76
  440. package/docs/interfaces/PromptFilesResponse.html +0 -56
  441. package/docs/interfaces/PromptFolder.html +0 -80
  442. package/docs/interfaces/PromptFolderDefaults.html +0 -155
  443. package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
  444. package/docs/interfaces/PromptFoldersResponse.html +0 -56
  445. package/docs/interfaces/RoomDetails.html +0 -151
  446. package/docs/interfaces/RoomErrorUpdate.html +0 -82
  447. package/docs/interfaces/RoomInfo.html +0 -88
  448. package/docs/interfaces/RoomMessageUpdate.html +0 -113
  449. package/docs/interfaces/RoomMessagesResponse.html +0 -62
  450. package/docs/interfaces/SendMessageResult.html +0 -62
  451. package/docs/interfaces/StoryErrorEvent.html +0 -84
  452. package/docs/interfaces/StoryIdea.html +0 -74
  453. package/docs/interfaces/StoryInfo.html +0 -198
  454. package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
  455. package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
  456. package/docs/interfaces/StoryState.html +0 -108
  457. package/docs/interfaces/StoryStateEvent.html +0 -76
  458. package/docs/interfaces/ToolArtifact.html +0 -85
  459. package/docs/interfaces/ToolCaller.html +0 -77
  460. package/docs/interfaces/ToolDefinition.html +0 -80
  461. package/docs/interfaces/ToolHelpers.html +0 -105
  462. package/docs/interfaces/ToolPackDocuments.html +0 -100
  463. package/docs/interfaces/ToolParameter.html +0 -74
  464. package/docs/interfaces/ToolRoomAccess.html +0 -227
  465. package/docs/interfaces/ToolSummary.html +0 -74
  466. package/docs/interfaces/ToolsResponse.html +0 -68
  467. package/docs/interfaces/Transaction.html +0 -104
  468. package/docs/interfaces/TransactionHistoryResponse.html +0 -62
  469. package/docs/modules.html +0 -53
  470. package/docs/types/PackOrigin.html +0 -34
  471. package/docs/types/PromptScope.html +0 -34
  472. package/docs/types/RoomTurnMode.html +0 -42
  473. package/docs/types/RoomUpdate.html +0 -36
  474. package/docs/types/RosterOverrides.html +0 -42
  475. package/docs/types/ToolContext.html +0 -40
  476. package/docs/types/ToolRunResult.html +0 -34
  477. package/src/tools/packs/dnd5e/README.md +0 -867
@@ -9,8 +9,14 @@ class Agent {
9
9
  agentName;
10
10
  agentNickname;
11
11
  history;
12
- fullContextFiles = true;
12
+ fullContextFiles = true; // If true, include the complete contents of files in the prompt context, otherwise files will be searched in a vector store
13
+ /**
14
+ * Generates a nickname from an agent name by taking the first word
15
+ * @param agentName The full agent name
16
+ * @returns The first word as nickname, or the full name if empty
17
+ */
13
18
  static generateNickname(agentName) {
19
+ // Take first word of agent name as nickname
14
20
  const firstName = agentName.trim().split(/\s+/)[0];
15
21
  return firstName || agentName;
16
22
  }
@@ -19,47 +25,116 @@ class Agent {
19
25
  totalOutputTokens = 0;
20
26
  totalCost = 0;
21
27
  totalMarkup = 0;
22
- markupRate = 2;
23
- disableMarkup = false;
24
- disableBalanceCheck = false;
28
+ markupRate = 2; // Default markup rate multiplier
29
+ disableMarkup = false; // When true, markup is always 0 regardless of markupRate
30
+ disableBalanceCheck = false; // When true, skip balance check but still decrement
25
31
  isPublished = false;
26
32
  templateAgentId;
27
- ownerRoomId;
33
+ ownerRoomId; // The room this agent belongs to; it is hidden from the agent list and deleted with the room
34
+ /** The pack this agent is filed under. See {@link AgentConfig.pack}. */
28
35
  pack;
36
+ /** The pack template's key, when this agent came from one. */
29
37
  packAgentKey;
38
+ // AI Service-specific data
30
39
  openai;
31
40
  assistant;
32
41
  vectorStore;
42
+ // Service references (framework plumbing — hidden from SDK docs)
43
+ /** @internal Direct reference to the AI service */
33
44
  aiService;
45
+ /** @internal Reference to ArtifactService for retrieving artifact content */
34
46
  artifactService;
47
+ /** @internal Reference to user-specific filesystem paths */
35
48
  userPaths;
49
+ /** @internal Reference to environment-variable configuration */
36
50
  configService;
51
+ /** @internal Reference to balance service for cost tracking and limits */
37
52
  balanceService;
53
+ // Clonable configuration properties
38
54
  description;
55
+ /**
56
+ * Private, agent-specific context that is visible only to this agent — never to
57
+ * other agents. Injected into the agent's transient (uncached) prompt message
58
+ * rather than the cached system instructions, so it can change frequently without
59
+ * invalidating the prompt cache. In stories this holds the character's inventory
60
+ * and conditions; contrast with {@link description}, which is the public
61
+ * appearance every other agent can see.
62
+ */
39
63
  privateContext = '';
40
64
  promptFolder;
65
+ /**
66
+ * The packs the owning user has enabled, consulted only when
67
+ * {@link promptFolder} is a bare name — a pack-qualified one always resolves.
68
+ *
69
+ * A thunk rather than an array because an agent outlives a toggle: the user
70
+ * can enable a pack while this instance is cached, and a snapshot taken at
71
+ * construction would need invalidating across every cached agent, room and
72
+ * service. Reading through the thunk means there is nothing to invalidate.
73
+ *
74
+ * Absent means "scan no packs", which is exactly the behaviour from before
75
+ * packs existed. Deliberately not in `AgentConfig` — it belongs to the user,
76
+ * not the agent, and persisting it would freeze a copy of the enabled set.
77
+ */
41
78
  enabledPacks;
42
79
  systemInstruction;
43
- maxHistoryMessages;
80
+ maxHistoryMessages; // If set, keep only last N messages (rolling window)
81
+ /**
82
+ * Index into {@link history} below which the rolling window may trim, and at or
83
+ * above which it may not. Protects a task that must survive intact from an agent
84
+ * whose window is deliberately short.
85
+ *
86
+ * **Deliberately not in `AgentConfig` and never saved.** `maxHistoryMessages` is
87
+ * operator configuration; this is transient state about the task in flight, and
88
+ * persisting it would leave an agent looking as though its window had been
89
+ * changed by hand. A restart clears it, costing at most the protection on one
90
+ * task in progress.
91
+ *
92
+ * It also needs no clearing. Re-pinning ends the previous pin, so an abandoned
93
+ * task is reclaimed the next time one starts, and the worst a stale pin can do is
94
+ * keep more history than intended — never drop any.
95
+ */
44
96
  historyPin;
45
97
  modelName;
46
- smallModelName;
98
+ smallModelName; // Same-service smaller model used by withSmallModel for mechanical prompts
47
99
  serviceName;
48
100
  reasoningEffort;
49
101
  allowSearch;
50
102
  maxOutputTokens = 0;
51
103
  attachedFiles = [];
52
- attachedArtifacts = [];
104
+ attachedArtifacts = []; // Array of artifact IDs
53
105
  isControlledByHuman = false;
54
106
  beginInstruction = '';
55
- toolNames = [];
107
+ toolNames = []; // Names of user-defined tools this agent may EXECUTE
108
+ /**
109
+ * This agent intends to send MODERATE messages, so its room needs a moderator
110
+ * to route them.
111
+ *
112
+ * For a human-controlled agent it is also what removes the action and target
113
+ * pickers from the room's composer: the player types, the room forces the
114
+ * message to MODERATE, and the moderator decides who hears it and who answers.
115
+ *
116
+ * For an AI agent it is a declaration, not a coercion. An agent emits MODERATE
117
+ * by its own choice — either its perceive schema offers `moderate` as a way to
118
+ * defer the routing decision, or it has no schema at all and answers in prose,
119
+ * which Room.parseAgentResponse converts. An agent that names its own targets
120
+ * keeps doing so.
121
+ */
56
122
  useModerator = false;
57
- promptCacheTTL = 0;
123
+ // Cache keep-alive settings (Anthropic only)
124
+ promptCacheTTL = 0; // The number of minutes to keep the prompt cache
125
+ // State change callback for SSE updates
58
126
  onStateChange = null;
127
+ // Persistence
59
128
  storageDir;
60
- agentStoreService;
129
+ agentStoreService; // Reference to AgentStoreService for self-persistence
130
+ /**
131
+ * @internal Agents are constructed by the framework (AgentStoreService /
132
+ * BaseAiService.createAgent); SDK consumers should obtain them via
133
+ * {@link Briyah} rather than calling this directly.
134
+ */
61
135
  constructor(id, userPaths, configService, agentStoreService, balanceService, artifactService, agentName = '', agentNickname = '', description = '', promptFolder = '', systemInstruction = '', history = [], modelName = '', serviceName = '', aiService, reasoningEffort = null, allowSearch = false, maxOutputTokens = 0, beginInstruction = '', storageDir) {
62
136
  this.agentName = agentName;
137
+ // Auto-generate nickname if not provided
63
138
  this.agentNickname = agentNickname || Agent.generateNickname(agentName);
64
139
  this.description = description;
65
140
  this.promptFolder = promptFolder;
@@ -95,17 +170,33 @@ class Agent {
95
170
  async attachDocument(fileName, fileData) {
96
171
  return await this.aiService.attachDocument(this, fileName, fileData);
97
172
  }
173
+ /**
174
+ * Attaches an artifact to the agent
175
+ * @param artifactId The artifact ID
176
+ */
98
177
  attachArtifact(artifactId) {
99
178
  if (!this.attachedArtifacts.includes(artifactId)) {
100
179
  this.attachedArtifacts.push(artifactId);
101
180
  }
102
181
  }
182
+ /**
183
+ * Detaches an artifact from the agent
184
+ * @param artifactId The artifact ID
185
+ */
103
186
  detachArtifact(artifactId) {
104
187
  this.attachedArtifacts = this.attachedArtifacts.filter((id) => id !== artifactId);
105
188
  }
189
+ /**
190
+ * Gets all attached artifact IDs
191
+ * @returns Array of artifact IDs
192
+ */
106
193
  getAttachedArtifacts() {
107
194
  return [...this.attachedArtifacts];
108
195
  }
196
+ /**
197
+ * Saves the agent to disk via AgentStoreService
198
+ * Called automatically after conversation history changes
199
+ */
109
200
  save() {
110
201
  this.agentStoreService.storeAgent(this);
111
202
  this.notifyStateChange();
@@ -116,9 +207,18 @@ class Agent {
116
207
  async deleteAgent() {
117
208
  this.agentStoreService.removeAgent(this.id);
118
209
  }
210
+ /**
211
+ * Sets the callback to be called when agent state changes
212
+ * Used for SSE updates to push changes to connected clients
213
+ * @param callback Function to call when state changes
214
+ */
119
215
  setOnStateChange(callback) {
120
216
  this.onStateChange = callback;
121
217
  }
218
+ /**
219
+ * Notifies listeners that the agent state has changed
220
+ * Triggers SSE updates if callback is registered
221
+ */
122
222
  notifyStateChange() {
123
223
  if (this.onStateChange) {
124
224
  this.onStateChange();
@@ -129,6 +229,11 @@ class Agent {
129
229
  return true;
130
230
  return message.targets.includes(this.agentNickname);
131
231
  }
232
+ /**
233
+ * Gets formatted messages from the agent's history starting from a specific index
234
+ * @param fromIndex The index to start from (0-based)
235
+ * @returns Array of formatted messages
236
+ */
132
237
  getFormattedMessages(fromIndex = 0) {
133
238
  if (!this.history) {
134
239
  return [];
@@ -137,13 +242,41 @@ class Agent {
137
242
  .slice(fromIndex)
138
243
  .map((message) => this.aiService.formatMessage(message));
139
244
  }
245
+ /**
246
+ * Gets the raw (unformatted) content of every message in the agent's history.
247
+ * @returns Array of message content strings
248
+ */
140
249
  getRawMessages() {
141
250
  if (!this.history) {
142
251
  return [];
143
252
  }
144
253
  return this.history.map((message) => message.content);
145
254
  }
255
+ /**
256
+ * Message fields that are dropped when a message is written into history.
257
+ *
258
+ * History sits in the cached prompt prefix of every agent that holds it, so each
259
+ * of these is paid for on every turn until the message falls out of the window:
260
+ *
261
+ * - `timestamp` — a wall-clock instant. No prompt in the repository reads one, and
262
+ * ordering is already carried by the position in the array.
263
+ * - `index` — the message's position in the room log, which is a storage detail.
264
+ * - `situation` — *current* state, not history. Every agent is handed the live
265
+ * situation in its transient prompt on every turn (`Room.buildTransientPrompt`),
266
+ * so the copies stored here are superseded by definition and, being the longest
267
+ * field on a room leader's messages, the most expensive thing in the window.
268
+ */
146
269
  static HISTORY_OMITTED_FIELDS = ['timestamp', 'index', 'situation'];
270
+ /**
271
+ * Renders a room message as the compact JSON that goes into conversation history.
272
+ *
273
+ * Compact rather than indented, and without the fields above or any field that is
274
+ * empty: an absent `name` and an empty `name` say the same thing to a model, and
275
+ * only one of them costs tokens in every cached prefix that carries the message.
276
+ *
277
+ * @param message The room message to render
278
+ * @returns The message as a single-line JSON string
279
+ */
147
280
  static formatMessageForHistory(message) {
148
281
  const compact = {};
149
282
  for (const [field, value] of Object.entries(message)) {
@@ -169,23 +302,53 @@ class Agent {
169
302
  }
170
303
  this.aiService.addToConversationHistory(this, formattedMessage, fromSelf);
171
304
  }
305
+ /**
306
+ * Marks the current end of history as the start of a task the rolling window
307
+ * must not trim into.
308
+ *
309
+ * A no-op for an agent with no window: there is nothing to protect it from, and
310
+ * a pin on an agent that keeps everything would only be a field to explain. That
311
+ * is what makes it safe to call from a shared path — the Dungeon Master running
312
+ * its own fight keeps its whole campaign either way.
313
+ *
314
+ * Call it *before* the message that starts the task is added to history, so the
315
+ * task's own opening instruction is inside the pin rather than the first thing
316
+ * dropped.
317
+ */
172
318
  pinHistory() {
173
319
  if (!this.maxHistoryMessages)
174
320
  return;
175
321
  this.historyPin = this.history.length;
176
322
  }
323
+ /** How many trailing messages the pin protects from trimming. */
177
324
  pinnedMessageCount() {
178
325
  if (this.historyPin === undefined)
179
326
  return 0;
180
327
  if (this.historyPin > this.history.length) {
328
+ // The history was replaced wholesale under the pin — compaction, or a
329
+ // restore — so it points at a message that no longer exists. Drop it.
330
+ // Clamping to zero instead would look right until history grew back
331
+ // past the old index, at which point a dead pin would silently start
332
+ // widening the window again.
181
333
  this.historyPin = undefined;
182
334
  return 0;
183
335
  }
184
336
  return this.history.length - this.historyPin;
185
337
  }
338
+ /**
339
+ * Trims conversation history to keep only the last N messages if maxHistoryMessages is set
340
+ * Preserves system messages (role: 'developer') at the start of history
341
+ * Used for rolling window history management (e.g., moderator agents)
342
+ *
343
+ * A {@link historyPin} raises the floor: everything since the pin is kept even
344
+ * when that is more than the window allows. The window still applies to whatever
345
+ * came before it, so a specialist handed a second task drops the first.
346
+ * @param threshold Allow history to grow 'threshold' messages past the limit before trimming a 'threshold'-sized chunk of messages at once
347
+ */
186
348
  trimHistoryIfNeeded(threshold = 0) {
187
349
  if (!this.maxHistoryMessages)
188
350
  return;
351
+ // Count system messages at start (role: 'developer')
189
352
  let systemMessageCount = 0;
190
353
  for (let i = 0; i < this.history.length; i++) {
191
354
  if (this.history[i].role === 'developer') {
@@ -198,17 +361,27 @@ class Agent {
198
361
  break;
199
362
  }
200
363
  }
364
+ // Keep system messages + last N conversation messages, or everything since
365
+ // the pin when the task in flight is longer than the window.
201
366
  const keep = Math.max(this.maxHistoryMessages, this.pinnedMessageCount());
202
367
  const conversationMessages = this.history.slice(systemMessageCount);
203
368
  if (conversationMessages.length > keep + threshold) {
204
369
  const keepMessages = conversationMessages.slice(-keep);
205
370
  const removed = conversationMessages.length - keepMessages.length;
206
371
  this.history = [...this.history.slice(0, systemMessageCount), ...keepMessages];
372
+ // The pin is an index, and the messages under it just moved.
207
373
  if (this.historyPin !== undefined) {
208
374
  this.historyPin = Math.max(systemMessageCount, this.historyPin - removed);
209
375
  }
210
376
  }
211
377
  }
378
+ /**
379
+ * Whether `<name>.prompt` resolves for this agent, so a caller can tell an agent
380
+ * that can run a kind of turn from one whose prompt folder has no prompt for it.
381
+ *
382
+ * False when the agent has no AI service or no paths yet — the answer to "could
383
+ * this agent run that turn" is then no, which is what a caller wants to hear.
384
+ */
212
385
  hasPrompt(name) {
213
386
  if (!this.aiService || !this.userPaths)
214
387
  return false;
@@ -233,17 +406,50 @@ class Agent {
233
406
  this.modelName = original;
234
407
  }
235
408
  }
409
+ /**
410
+ * How large a history may grow, in characters, before it is worth compacting.
411
+ *
412
+ * Read per call rather than cached so an operator can retune a long-running
413
+ * server without restarting it. Characters rather than tokens because it is the
414
+ * one measure available without asking a tokenizer, and the threshold only has
415
+ * to be roughly right — four characters to a token is close enough to make
416
+ * 100,000 mean "about 25k tokens".
417
+ *
418
+ * @returns The threshold in characters
419
+ */
236
420
  static compactionThresholdChars() {
237
421
  return Number(process.env.AGENT_COMPACTION_THRESHOLD) || 100000;
238
422
  }
423
+ /**
424
+ * The size of this agent's conversation history in characters.
425
+ * @returns Total characters across every message in history
426
+ */
239
427
  historyChars() {
240
428
  return (this.history ?? []).reduce((sum, m) => sum + (m?.content?.length || 0), 0);
241
429
  }
430
+ /**
431
+ * Whether this agent's history has grown past the compaction threshold.
432
+ *
433
+ * An agent with `maxHistoryMessages` is excluded: a rolling window already
434
+ * bounds it, and the two mechanisms answer different needs. A window is for an
435
+ * agent whose old turns stop mattering — a moderator routing the next message
436
+ * does not need last hour's. Compaction is for one whose past must survive in
437
+ * some form, which is why it costs a model call to write a summary rather than
438
+ * dropping messages off the front.
439
+ *
440
+ * @returns True when compaction is worth a call
441
+ */
242
442
  needsCompaction() {
243
443
  if (this.maxHistoryMessages)
244
444
  return false;
245
445
  return this.historyChars() > Agent.compactionThresholdChars();
246
446
  }
447
+ /**
448
+ * Replace this agent's conversation history with a single summary message.
449
+ * Uses the `compact_agent` prompt, resolved via the standard lookup order:
450
+ * user/<promptFolder> → user/root → common/<promptFolder> → common/root.
451
+ * On failure, the original history is restored.
452
+ */
247
453
  async compact() {
248
454
  const originalHistory = [...(this.history || [])];
249
455
  const originalLength = originalHistory.length;
@@ -286,6 +492,13 @@ class Agent {
286
492
  async textPrompt(prompt, jsonSchema = null, saveResponse = true, promptInstructions = null, cacheMessage = false, maxOutputChars = 0) {
287
493
  return await this.aiService.textPrompt(this, prompt, jsonSchema, saveResponse, promptInstructions, this.aiService.getCacheConfig(this, cacheMessage), maxOutputChars);
288
494
  }
495
+ /**
496
+ * Generates an image from a text prompt.
497
+ * @param prompt Text description of the image
498
+ * @param imageProperties Optional provider-specific image options
499
+ * (e.g. `width`, `height`, `quality`) passed through to the underlying AI service
500
+ * @returns Promise resolving to `{ artifactId }` on success or `{ error }` on failure
501
+ */
289
502
  async generateImage(prompt, imageProperties) {
290
503
  return await this.aiService.generateImage(this, prompt, imageProperties);
291
504
  }
@@ -1,10 +1,28 @@
1
+ /**
2
+ * Writes per-call debug files for AI requests, thinking output, and responses.
3
+ *
4
+ * Enabled when process.env.AI_DEBUG === 'true' (or when aiDebug is set in
5
+ * LoggingOptions, which maps to the same env var via BriyahConfigService).
6
+ *
7
+ * Files are written to:
8
+ * {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_REQUEST.txt
9
+ * {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_THINKING.txt
10
+ * {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_RESPONSE.txt
11
+ *
12
+ * The millisecond-resolution timestamp prefix keeps files sortable chronologically and
13
+ * distinguishes concurrent calls from different agents.
14
+ *
15
+ * Logging errors are swallowed so they never interrupt the main request flow.
16
+ */
1
17
  export declare class AiDebugLogger {
2
18
  static isEnabled(): boolean;
3
19
  private static getLogDir;
4
20
  private static timestamp;
21
+ /** Replace filesystem-unsafe characters and cap length so filenames stay readable. */
5
22
  private static sanitize;
6
23
  private static write;
7
24
  static writeRequest(agentName: string, content: unknown): void;
25
+ /** No-op when content is empty — avoids creating zero-byte THINKING files on non-reasoning models. */
8
26
  static writeThinking(agentName: string, content: string): void;
9
27
  static writeResponse(agentName: string, content: string): void;
10
28
  }
@@ -36,6 +36,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.AiDebugLogger = void 0;
37
37
  const fs = __importStar(require("fs"));
38
38
  const path = __importStar(require("path"));
39
+ /**
40
+ * Writes per-call debug files for AI requests, thinking output, and responses.
41
+ *
42
+ * Enabled when process.env.AI_DEBUG === 'true' (or when aiDebug is set in
43
+ * LoggingOptions, which maps to the same env var via BriyahConfigService).
44
+ *
45
+ * Files are written to:
46
+ * {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_REQUEST.txt
47
+ * {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_THINKING.txt
48
+ * {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_RESPONSE.txt
49
+ *
50
+ * The millisecond-resolution timestamp prefix keeps files sortable chronologically and
51
+ * distinguishes concurrent calls from different agents.
52
+ *
53
+ * Logging errors are swallowed so they never interrupt the main request flow.
54
+ */
39
55
  class AiDebugLogger {
40
56
  static isEnabled() {
41
57
  return process.env.AI_DEBUG === 'true';
@@ -53,6 +69,7 @@ class AiDebugLogger {
53
69
  `_${pad(now.getHours())}-${pad(now.getMinutes())}-${pad(now.getSeconds())}` +
54
70
  `-${pad(now.getMilliseconds(), 3)}`);
55
71
  }
72
+ /** Replace filesystem-unsafe characters and cap length so filenames stay readable. */
56
73
  static sanitize(name) {
57
74
  return name.replace(/[<>:"/\\|?*\s]+/g, '_').substring(0, 80);
58
75
  }
@@ -64,12 +81,14 @@ class AiDebugLogger {
64
81
  fs.writeFileSync(path.join(this.getLogDir(), filename), content, 'utf8');
65
82
  }
66
83
  catch {
84
+ // Never let debug logging break the main flow.
67
85
  }
68
86
  }
69
87
  static writeRequest(agentName, content) {
70
88
  const text = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
71
89
  this.write(agentName, 'REQUEST', text);
72
90
  }
91
+ /** No-op when content is empty — avoids creating zero-byte THINKING files on non-reasoning models. */
73
92
  static writeThinking(agentName, content) {
74
93
  if (!content)
75
94
  return;
@@ -21,6 +21,15 @@ export declare class AiFactoryService {
21
21
  private readonly comfyUiAiService;
22
22
  private readonly selfHostedAiService;
23
23
  constructor(openAiService: OpenAiService, grokAiService: GrokAiService, anthropicAiService: AnthropicAiService, deepSeekAiService: DeepSeekAiService, togetherAiService: TogetherAiService, mockAiService: MockAiService, googleAiService: GoogleAiService, falAiService: FalAiService, comfyUiAiService: ComfyUiAiService, selfHostedAiService: SelfHostedAiService);
24
+ /**
25
+ * Creates an AI service instance based on the service name
26
+ * @param serviceName The name of the service to create (must match getServiceName())
27
+ * @returns The appropriate AI service instance
28
+ */
24
29
  createAiService(serviceName: string): BaseAiService;
30
+ /**
31
+ * Gets all available AI services
32
+ * @returns Array of all AI service instances
33
+ */
25
34
  getAllAiServices(): BaseAiService[];
26
35
  }
@@ -44,6 +44,11 @@ let AiFactoryService = class AiFactoryService {
44
44
  this.comfyUiAiService = comfyUiAiService;
45
45
  this.selfHostedAiService = selfHostedAiService;
46
46
  }
47
+ /**
48
+ * Creates an AI service instance based on the service name
49
+ * @param serviceName The name of the service to create (must match getServiceName())
50
+ * @returns The appropriate AI service instance
51
+ */
47
52
  createAiService(serviceName) {
48
53
  switch (serviceName) {
49
54
  case this.openAiService.getServiceName():
@@ -70,6 +75,10 @@ let AiFactoryService = class AiFactoryService {
70
75
  throw new Error(`Unknown AI service: ${serviceName}`);
71
76
  }
72
77
  }
78
+ /**
79
+ * Gets all available AI services
80
+ * @returns Array of all AI service instances
81
+ */
73
82
  getAllAiServices() {
74
83
  return [
75
84
  this.openAiService,
@@ -1,27 +1,158 @@
1
1
  import { UserPathsService } from '../config/user-paths.service';
2
2
  import { ArtifactMetadata } from '../../../shared/types/app.types';
3
+ /**
4
+ * Service for managing user artifacts (reusable markdown documents)
5
+ * Separate from AttachedFileService which handles agent-specific file uploads
6
+ * and separate from Room artifacts which are agent-generated conversation outputs
7
+ *
8
+ * Reads span two tiers: the user's own artifacts, and the read-only documents
9
+ * shipped by enabled tool packs (see `pack-artifacts.ts`). Writes only ever touch
10
+ * the user's, and a `pack:` id is refused rather than silently ignored.
11
+ */
3
12
  export declare class ArtifactService {
4
13
  private readonly userPaths;
5
14
  private readonly artifactsDir;
15
+ /**
16
+ * Where packs live, highest precedence first: the user's own packs, then the
17
+ * host's. A pack name exists in only one of them, so the order settles a
18
+ * collision rather than layering.
19
+ */
6
20
  private readonly packRoots;
21
+ /**
22
+ * The packs whose documents this user should be offered.
23
+ *
24
+ * A thunk, and defaulting to none, so the many places that build an
25
+ * `ArtifactService` without a pack service keep working — they simply see no
26
+ * pack documents in a listing, which is what an unconfigured user sees anyway.
27
+ * Resolution never consults it.
28
+ */
7
29
  private enabledPacks;
8
30
  constructor(userPaths: UserPathsService, storageDir?: string);
31
+ /**
32
+ * Tells this service which packs the user has enabled.
33
+ *
34
+ * Set after construction because `PackService` and `ArtifactService` are both
35
+ * built per user and neither can be the other's constructor argument.
36
+ *
37
+ * @param enabledPacks A thunk over the user's enabled packs
38
+ */
9
39
  setEnabledPacks(enabledPacks: () => readonly string[]): void;
40
+ /**
41
+ * Guards every write path against a pack document.
42
+ *
43
+ * There is one copy of a shipped document and it is the same for every user,
44
+ * so editing, renaming or deleting one is not a thing a single user may do.
45
+ * Returning rather than throwing keeps the existing "false means it did not
46
+ * happen" contract of the write methods.
47
+ *
48
+ * @returns True when the caller should stop
49
+ */
10
50
  private refuseWriteToPackDocument;
51
+ /**
52
+ * Gets the path to the metadata file
53
+ */
11
54
  private getMetadataPath;
55
+ /**
56
+ * Loads metadata from disk
57
+ */
12
58
  private loadMetadata;
59
+ /**
60
+ * Saves metadata to disk
61
+ */
13
62
  private saveMetadata;
63
+ /**
64
+ * Gets the file path for an artifact
65
+ * @deprecated Use getArtifactFilePath instead for MIME-aware path resolution
66
+ */
14
67
  private getArtifactPath;
68
+ /**
69
+ * Gets the file path for an artifact based on its MIME type
70
+ */
15
71
  private getArtifactFilePath;
72
+ /**
73
+ * Stores a new artifact
74
+ * @param name User-friendly name for the artifact
75
+ * @param content Markdown content
76
+ * @param description Optional description for the artifact
77
+ * @returns The artifactId
78
+ */
16
79
  storeArtifact(name: string, content: string, description?: string): string;
80
+ /**
81
+ * Gets artifact content
82
+ * @param artifactId The artifact ID
83
+ * @returns The content (string for text, Buffer for images), or null if not found
84
+ */
17
85
  getArtifact(artifactId: string): string | Buffer | null;
86
+ /**
87
+ * Lists a pack's document files by name, for a tool that enumerates its own
88
+ * documents rather than being handed them.
89
+ *
90
+ * Reads the pack's `artifacts/` directory rather than its manifest, so an
91
+ * operator can add a document by dropping a file in — see
92
+ * {@link listPackDocumentFiles}. Nothing in the client uses this; it exists for
93
+ * `helpers.packDocuments`.
94
+ * @param pack The pack name
95
+ * @param prefix Keep only file names starting with this
96
+ * @returns Bare `.md` file names, sorted
97
+ */
18
98
  listPackDocumentFiles(pack: string, prefix?: string): string[];
99
+ /**
100
+ * Reads one of a pack's document files by name.
101
+ * @param pack The pack name
102
+ * @param fileName A bare file name from {@link listPackDocumentFiles}
103
+ * @returns The document's text, or null if there is no such file
104
+ */
19
105
  readPackDocumentFile(pack: string, fileName: string): string | null;
106
+ /**
107
+ * Lists all artifacts: the documents shipped by enabled tool packs first, then
108
+ * the user's own.
109
+ *
110
+ * Pack documents lead because they are the same for everyone and the user did
111
+ * not put them there — burying them among their own uploads is how they get
112
+ * missed.
113
+ * @returns Array of artifact metadata
114
+ */
20
115
  listArtifacts(): ArtifactMetadata[];
116
+ /**
117
+ * Gets metadata for a specific artifact
118
+ * @param artifactId The artifact ID
119
+ * @returns The metadata, or null if not found
120
+ */
21
121
  getArtifactMetadata(artifactId: string): ArtifactMetadata | null;
122
+ /**
123
+ * Updates artifact content
124
+ * @param artifactId The artifact ID
125
+ * @param content New content
126
+ * @returns True if successful, false otherwise
127
+ */
22
128
  updateArtifact(artifactId: string, content: string): boolean;
129
+ /**
130
+ * Renames an artifact
131
+ * @param artifactId The artifact ID
132
+ * @param newName New name
133
+ * @returns True if successful, false otherwise
134
+ */
23
135
  renameArtifact(artifactId: string, newName: string): boolean;
136
+ /**
137
+ * Updates an artifact's description in metadata
138
+ * @param artifactId The artifact ID
139
+ * @param description New description
140
+ * @returns True if successful, false otherwise
141
+ */
24
142
  updateArtifactDescription(artifactId: string, description: string): boolean;
143
+ /**
144
+ * Deletes an artifact
145
+ * @param artifactId The artifact ID
146
+ * @returns True if successful, false otherwise
147
+ */
25
148
  deleteArtifact(artifactId: string): boolean;
149
+ /**
150
+ * Stores a new image artifact
151
+ * @param name User-friendly name for the artifact
152
+ * @param imageData Binary image data
153
+ * @param mimeType MIME type of the image (e.g., 'image/png')
154
+ * @param description Optional description for the artifact
155
+ * @returns The artifactId
156
+ */
26
157
  storeImageArtifact(name: string, imageData: Buffer, mimeType: string, description?: string): string;
27
158
  }