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
@@ -54,6 +54,12 @@ const user_paths_service_1 = require("../config/user-paths.service");
54
54
  const attached_file_service_1 = require("./attached-file.service");
55
55
  const balance_service_1 = require("../app/balance.service");
56
56
  const logger_1 = require("../common/logger");
57
+ /**
58
+ * A service that stores and retrieves Agent objects by ID
59
+ * Each agent is stored in its own JSON file named by its GUID
60
+ * Supports configurable storage directories (e.g., for story-specific agents)
61
+ * Uses lazy loading - agents are loaded from disk on first access
62
+ */
57
63
  let AgentStoreService = class AgentStoreService {
58
64
  aiFactoryService;
59
65
  userPaths;
@@ -72,67 +78,124 @@ let AgentStoreService = class AgentStoreService {
72
78
  this.balanceService = balanceService;
73
79
  this.artifactService = artifactService;
74
80
  this.configService = configService;
81
+ // Default storage directory for non-story agents
75
82
  this.defaultStorageDir = path.join(this.userPaths.getUserDataDir(), 'agents');
83
+ // Agents will be loaded lazily on first access via ensureLoaded()
76
84
  }
85
+ /**
86
+ * Gets the default storage directory for agents
87
+ * @returns The default storage directory path
88
+ */
77
89
  getDefaultStorageDir() {
78
90
  return this.defaultStorageDir;
79
91
  }
92
+ /**
93
+ * Registers an agent in the in-memory store without writing to disk.
94
+ * Use this when creating a new agent that the user hasn't explicitly saved yet.
95
+ * Call agent.save() later to persist it.
96
+ * @param agent The agent to register
97
+ */
80
98
  registerAgent(agent) {
81
99
  if (!agent.id) {
82
100
  agent.id = (0, crypto_1.randomUUID)();
83
101
  }
84
102
  this.agents.set(agent.id, agent);
85
103
  }
104
+ /**
105
+ * Stores an agent and returns its unique ID
106
+ * @param agent The agent to store
107
+ * @param storageDir Optional custom storage directory (defaults to server/data/agents)
108
+ * @returns The unique ID for the agent
109
+ */
86
110
  storeAgent(agent, storageDir) {
111
+ // If agent doesn't have an ID, generate one
87
112
  if (!agent.id) {
88
113
  agent.id = (0, crypto_1.randomUUID)();
89
114
  }
90
115
  this.agents.set(agent.id, agent);
116
+ // Save the agent to its individual file
91
117
  const finalStorageDir = storageDir || agent.storageDir;
92
118
  this.saveAgentToFile(agent, finalStorageDir);
93
119
  return agent.id;
94
120
  }
121
+ /**
122
+ * Retrieves an agent by its ID
123
+ * @param id The agent ID
124
+ * @returns The agent, or undefined if not found
125
+ */
95
126
  async getAgent(id) {
96
127
  await this.ensureLoaded();
97
128
  return this.agents.get(id);
98
129
  }
130
+ /**
131
+ * Removes an agent from the store and deletes its file
132
+ * @param id The agent ID
133
+ * @returns True if the agent was found and removed, false otherwise
134
+ */
99
135
  removeAgent(id) {
100
136
  const agent = this.agents.get(id);
101
137
  if (!agent) {
102
138
  return false;
103
139
  }
140
+ // Call finishAgent on the AI service if available
104
141
  if (agent.aiService) {
105
142
  try {
106
143
  agent.aiService.finishAgent(agent);
107
144
  }
108
145
  catch (error) {
109
146
  logger_1.logger.error(`Error finishing agent ${id}:`, error);
147
+ // Continue with deletion even if finishAgent fails
110
148
  }
111
149
  }
112
150
  this.attachedFileService.deleteAllFiles(agent.id);
151
+ // Remove the agent from the store
113
152
  const result = this.agents.delete(id);
153
+ // Delete the agent's file
114
154
  if (result) {
115
155
  this.deleteAgentFile(id, agent.storageDir);
116
156
  }
117
157
  return result;
118
158
  }
159
+ /**
160
+ * Gets all agent IDs from the in-memory store
161
+ * @returns Array of agent IDs
162
+ */
119
163
  async getAllAgentIds() {
120
164
  await this.ensureLoaded();
121
165
  return Array.from(this.agents.keys());
122
166
  }
167
+ /**
168
+ * Gets the number of agents in the store
169
+ * @returns The number of agents
170
+ */
123
171
  async getAgentCount() {
124
172
  await this.ensureLoaded();
125
173
  return this.agents.size;
126
174
  }
127
- async cloneAgentAsPublished(templateId, publishedName, _userId) {
175
+ /**
176
+ * Clones an agent as a published instance with a new name
177
+ * @param templateId The ID of the template agent to clone
178
+ * @param publishedName The name for the published instance
179
+ * @param userId The user ID (for tracking purposes)
180
+ * @returns The ID of the newly created published instance
181
+ */
182
+ async cloneAgentAsPublished(templateId, publishedName,
183
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
184
+ _userId) {
128
185
  await this.ensureLoaded();
129
186
  const template = this.agents.get(templateId);
130
187
  if (!template) {
131
188
  throw new Error(`Template agent not found: ${templateId}`);
132
189
  }
190
+ // Generate new ID for the instance
133
191
  const instanceId = (0, crypto_1.randomUUID)();
192
+ // Get the AI service for the new instance
134
193
  const aiService = this.aiFactoryService.createAiService(template.serviceName);
135
- const instance = new agent_1.Agent(instanceId, this.userPaths, this.configService, this, this.balanceService, this.artifactService, publishedName, template.agentNickname || template.agentName, template.description, template.promptFolder, template.systemInstruction, [], template.modelName, template.serviceName, aiService, template.reasoningEffort, template.allowSearch, template.maxOutputTokens, template.beginInstruction, this.defaultStorageDir);
194
+ // Create new agent with copied properties
195
+ const instance = new agent_1.Agent(instanceId, this.userPaths, this.configService, this, this.balanceService, this.artifactService, publishedName, // New name for the instance
196
+ template.agentNickname || template.agentName, template.description, template.promptFolder, template.systemInstruction, [], // Empty history for new instance
197
+ template.modelName, template.serviceName, aiService, template.reasoningEffort, template.allowSearch, template.maxOutputTokens, template.beginInstruction, this.defaultStorageDir);
198
+ // Set instance-specific properties
136
199
  instance.templateAgentId = templateId;
137
200
  instance.isPublished = true;
138
201
  instance.createdAt = new Date();
@@ -140,6 +203,7 @@ let AgentStoreService = class AgentStoreService {
140
203
  instance.totalOutputTokens = 0;
141
204
  instance.totalCost = 0;
142
205
  instance.totalMarkup = 0;
206
+ // Copy attached files and artifacts metadata
143
207
  instance.privateContext = template.privateContext;
144
208
  instance.attachedFiles = [...template.attachedFiles];
145
209
  instance.attachedArtifacts = [...template.attachedArtifacts];
@@ -149,12 +213,24 @@ let AgentStoreService = class AgentStoreService {
149
213
  instance.smallModelName = template.smallModelName;
150
214
  instance.toolNames = [...template.toolNames];
151
215
  instance.useModerator = template.useModerator;
216
+ // The human player must survive publishing: a published room's whole point
217
+ // is that its visitor plays this agent. Without the flag the room has no
218
+ // human, so it never yields the floor and the visitor's messages arrive as
219
+ // 'system' rather than under their character's name.
152
220
  instance.isControlledByHuman = template.isControlledByHuman;
221
+ // A published copy of a pack's agent stays filed under that pack, so it is
222
+ // listed and hidden alongside the template it came from.
153
223
  instance.pack = template.pack;
154
224
  instance.packAgentKey = template.packAgentKey;
225
+ // Store the new instance
155
226
  this.storeAgent(instance);
156
227
  return instanceId;
157
228
  }
229
+ /**
230
+ * Gets all published instances of a template agent
231
+ * @param templateId The ID of the template agent
232
+ * @returns Array of published instances
233
+ */
158
234
  async getPublishedInstances(templateId) {
159
235
  await this.ensureLoaded();
160
236
  const instances = [];
@@ -165,6 +241,13 @@ let AgentStoreService = class AgentStoreService {
165
241
  }
166
242
  return instances;
167
243
  }
244
+ /**
245
+ * Resets a published instance to match its template's current properties
246
+ * Preserves the instance ID, name, creation date and usage totals
247
+ * Clears conversation history
248
+ * @param instanceId The ID of the instance to reset
249
+ * @param templateId The ID of the template agent
250
+ */
168
251
  async resetPublishedInstance(instanceId, templateId) {
169
252
  await this.ensureLoaded();
170
253
  const instance = this.agents.get(instanceId);
@@ -175,9 +258,11 @@ let AgentStoreService = class AgentStoreService {
175
258
  if (!template) {
176
259
  throw new Error(`Template agent not found: ${templateId}`);
177
260
  }
261
+ // Validate that this instance belongs to this template
178
262
  if (instance.templateAgentId !== templateId) {
179
263
  throw new Error(`Instance ${instanceId} does not belong to template ${templateId}`);
180
264
  }
265
+ // Update properties from template
181
266
  instance.description = template.description;
182
267
  instance.privateContext = template.privateContext;
183
268
  instance.agentNickname = template.agentNickname;
@@ -197,13 +282,28 @@ let AgentStoreService = class AgentStoreService {
197
282
  instance.markupRate = template.markupRate;
198
283
  instance.toolNames = [...template.toolNames];
199
284
  instance.useModerator = template.useModerator;
285
+ // Kept in step with the template for the same reason the clone copies it.
200
286
  instance.isControlledByHuman = template.isControlledByHuman;
201
287
  instance.pack = template.pack;
202
288
  instance.packAgentKey = template.packAgentKey;
289
+ // Clear the conversation, but not what it cost.
290
+ //
291
+ // A reset is about the instance's state, not its accounting: the money was
292
+ // spent and the user was billed for it, so zeroing the totals here made a
293
+ // published agent look free and lost the only record of what it had run up.
294
+ // The counters start at zero on the clone, which is where they belong —
295
+ // that instance really has spent nothing yet.
203
296
  instance.history = [];
297
+ // Update AI service reference (in case serviceName changed)
204
298
  instance.aiService = this.aiFactoryService.createAiService(instance.serviceName);
299
+ // Save the updated instance
205
300
  this.storeAgent(instance);
206
301
  }
302
+ /**
303
+ * Ensures default agents are loaded from disk (lazy loading)
304
+ * Only loads once - subsequent calls are no-op
305
+ * Uses promise memoization to prevent concurrent loads
306
+ */
207
307
  async ensureLoaded() {
208
308
  if (this.loaded)
209
309
  return;
@@ -213,14 +313,21 @@ let AgentStoreService = class AgentStoreService {
213
313
  this.loaded = true;
214
314
  })
215
315
  .catch((error) => {
216
- this.loadPromise = null;
316
+ this.loadPromise = null; // Allow retry on error
217
317
  throw error;
218
318
  });
219
319
  }
220
320
  await this.loadPromise;
221
321
  }
322
+ /**
323
+ * Loads agents from a specific directory
324
+ * Used for loading story-specific agents
325
+ * @param storageDir The directory to load agents from
326
+ * @param artifactService Optional artifact service (for story-specific artifacts)
327
+ */
222
328
  async loadAgentsFromDirectory(storageDir, artifactService) {
223
329
  try {
330
+ // Check if directory exists
224
331
  try {
225
332
  await fs.promises.access(storageDir);
226
333
  }
@@ -229,64 +336,103 @@ let AgentStoreService = class AgentStoreService {
229
336
  await fs.promises.mkdir(storageDir, { recursive: true });
230
337
  return;
231
338
  }
339
+ // Read all .json files from the directory
232
340
  const allFiles = await fs.promises.readdir(storageDir);
233
341
  const files = allFiles.filter((file) => file.endsWith('.json'));
234
342
  logger_1.logger.log(`Loading ${files.length} agents from ${storageDir}`);
343
+ // Load each agent file
235
344
  for (const file of files) {
236
345
  try {
237
346
  const filePath = path.join(storageDir, file);
238
347
  const fileContent = await fs.promises.readFile(filePath, 'utf-8');
239
348
  const config = JSON.parse(fileContent);
349
+ // Check if agent already exists in store (prevents duplicate loading)
240
350
  if (this.agents.has(config.id)) {
241
351
  logger_1.logger.log(`Agent ${config.agentName} (${config.id}) already loaded, skipping`);
242
352
  continue;
243
353
  }
354
+ // Get the AI service for this agent
244
355
  const aiService = this.aiFactoryService.createAiService(config.serviceName);
356
+ // Use provided artifact service or fall back to default
245
357
  const finalArtifactService = artifactService || this.artifactService;
246
- const agent = new agent_1.Agent(config.id, this.userPaths, this.configService, this, this.balanceService, finalArtifactService, config.agentName, config.agentNickname || config.agentName, config.description, config.promptFolder, config.systemInstruction, config.history || [], config.modelName, config.serviceName, aiService, config.reasoningEffort, config.allowSearch, config.maxOutputTokens, config.beginInstruction || '', storageDir);
358
+ // Create a new agent with the saved configuration, including history
359
+ const agent = new agent_1.Agent(config.id, this.userPaths, this.configService, this, this.balanceService, finalArtifactService, config.agentName, config.agentNickname || config.agentName, config.description, config.promptFolder, config.systemInstruction, config.history || [], // Restore history or use empty array
360
+ config.modelName, config.serviceName, aiService, config.reasoningEffort, config.allowSearch, config.maxOutputTokens, config.beginInstruction || '', storageDir);
361
+ // Restore agent-private context (e.g. story inventory)
247
362
  agent.privateContext = config.privateContext || '';
363
+ // Set the creation date
248
364
  agent.createdAt = new Date(config.createdAt);
365
+ // Set the user paths service reference
249
366
  agent.userPaths = this.userPaths;
367
+ // Restore the optional same-service small model used for mechanical prompts
250
368
  agent.smallModelName = config.smallModelName;
369
+ // Restore token counts and cost
251
370
  agent.totalInputTokens = config.totalInputTokens || 0;
252
371
  agent.totalOutputTokens = config.totalOutputTokens || 0;
253
372
  agent.totalCost = config.totalCost || 0;
254
373
  agent.totalMarkup = config.totalMarkup || 0;
374
+ // Load markupRate from saved config; if absent, the Agent
375
+ // constructor already applied the DEFAULT_MARKUP_RATE default.
255
376
  if (config.markupRate !== undefined) {
256
377
  agent.markupRate = config.markupRate;
257
378
  }
379
+ // Restore human control flag
258
380
  agent.isControlledByHuman = config.isControlledByHuman || false;
381
+ // Restore markup and balance check flags
259
382
  agent.disableMarkup = config.disableMarkup || false;
260
383
  agent.disableBalanceCheck = config.disableBalanceCheck || false;
384
+ // Restore publication status
261
385
  agent.isPublished = config.isPublished || false;
386
+ // Restore template agent ID (for published instances)
262
387
  agent.templateAgentId = config.templateAgentId;
388
+ // Restore room ownership (for agents cloned as part of published rooms)
263
389
  agent.ownerRoomId = config.ownerRoomId;
390
+ // Restore which pack the agent is filed under
264
391
  agent.pack = config.pack;
265
392
  agent.packAgentKey = config.packAgentKey;
393
+ // Restore begin instruction
266
394
  agent.beginInstruction = config.beginInstruction || '';
267
395
  agent.maxHistoryMessages = config.maxHistoryMessages || undefined;
396
+ // Restore cache keep-alive settings
268
397
  agent.promptCacheTTL = Number(config.promptCacheTTL) ?? 0;
398
+ // Restore tool grants
269
399
  agent.toolNames = config.toolNames || [];
400
+ // Restore the moderated-messaging declaration
270
401
  agent.useModerator = config.useModerator || false;
402
+ // Store the agent with its original ID
271
403
  agent.id = config.id;
272
404
  this.agents.set(config.id, agent);
405
+ // Note: Identity is now handled in textPrompt, not during agent creation
406
+ // Use file metadata from config if available (preserves serviceMetadata)
407
+ // Otherwise fall back to AttachedFileService
273
408
  if (config.attachedFiles && config.attachedFiles.length > 0) {
274
409
  agent.attachedFiles = config.attachedFiles;
275
410
  }
276
411
  else {
412
+ // Fallback: Load file metadata from AttachedFileService
277
413
  const fileMetadataList = this.attachedFileService.listFileMetadata(agent.id);
278
414
  agent.attachedFiles = fileMetadataList;
279
415
  }
416
+ // Restore file data to serviceMetadata for agents using fullContextFiles
417
+ // When fullContextFiles is true, files are included directly in prompts
418
+ // When false, files are stored in vector stores (OpenAI) or similar
280
419
  for (const metadata of agent.attachedFiles) {
281
420
  const fileData = this.attachedFileService.getFile(agent.id, metadata.fileId);
282
421
  if (fileData && metadata.serviceMetadata && agent.fullContextFiles) {
422
+ // Restore fileData for agents that include files directly in prompts
283
423
  metadata.serviceMetadata.fileData = Array.from(fileData);
284
424
  logger_1.logger.log(`Restored fileData for ${metadata.fileName} (fullContextFiles=true)`);
285
425
  }
426
+ // If fullContextFiles is false, the service uses remote storage (vector stores, etc.)
427
+ // The resourceId or similar should already be in serviceMetadata from saved config
286
428
  }
429
+ // Restore attached artifacts
287
430
  if (config.attachedArtifacts && config.attachedArtifacts.length > 0) {
288
431
  agent.attachedArtifacts = config.attachedArtifacts;
289
432
  }
433
+ // Debug, not log: this fires once per agent in the user's whole
434
+ // library, so a table of nine agents produced fifty-one lines and
435
+ // buried the boot sequence. The count is logged once below.
290
436
  logger_1.logger.debug(`Loaded agent: ${config.agentName} (${config.id}) with ${agent.history.length} history items`);
291
437
  }
292
438
  catch (error) {
@@ -298,13 +444,23 @@ let AgentStoreService = class AgentStoreService {
298
444
  logger_1.logger.error(`Error loading agents from directory ${storageDir}:`, error);
299
445
  }
300
446
  }
447
+ /**
448
+ * Saves a single agent to its own JSON file
449
+ * @param agent The agent to save
450
+ * @param storageDir The directory to save the agent in
451
+ */
301
452
  saveAgentToFile(agent, storageDir) {
302
453
  try {
454
+ // Ensure the directory exists
303
455
  if (!fs.existsSync(storageDir)) {
304
456
  fs.mkdirSync(storageDir, { recursive: true });
305
457
  }
458
+ // Create a copy of attachedFiles without the fileData property
459
+ // (fileData is already stored in the upload folder)
306
460
  let attachedFilesWithoutFileData = agent.attachedFiles.map((file) => {
307
461
  if (file.serviceMetadata?.fileData) {
462
+ // Create a copy without fileData
463
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
308
464
  const { fileData: _fileData, ...serviceMetadataWithoutFileData } = file.serviceMetadata;
309
465
  return {
310
466
  ...file,
@@ -344,7 +500,7 @@ let AgentStoreService = class AgentStoreService {
344
500
  templateAgentId: agent.templateAgentId,
345
501
  beginInstruction: agent.beginInstruction,
346
502
  promptCacheTTL: agent.promptCacheTTL,
347
- ownerRoomId: agent.ownerRoomId,
503
+ ownerRoomId: agent.ownerRoomId, // NEW: Persist room ownership
348
504
  toolNames: agent.toolNames,
349
505
  useModerator: agent.useModerator,
350
506
  pack: agent.pack,
@@ -357,6 +513,11 @@ let AgentStoreService = class AgentStoreService {
357
513
  logger_1.logger.error(`Error saving agent ${agent.id} to file:`, error);
358
514
  }
359
515
  }
516
+ /**
517
+ * Deletes an agent's JSON file
518
+ * @param agentId The agent ID
519
+ * @param storageDir The directory containing the agent file
520
+ */
360
521
  deleteAgentFile(agentId, storageDir) {
361
522
  try {
362
523
  const filePath = path.join(storageDir, `${agentId}.json`);
@@ -15,6 +15,11 @@ export declare class Agent {
15
15
  agentNickname: string;
16
16
  history: any[];
17
17
  fullContextFiles: boolean;
18
+ /**
19
+ * Generates a nickname from an agent name by taking the first word
20
+ * @param agentName The full agent name
21
+ * @returns The first word as nickname, or the full name if empty
22
+ */
18
23
  static generateNickname(agentName: string): string;
19
24
  createdAt: Date;
20
25
  totalInputTokens: number;
@@ -27,22 +32,65 @@ export declare class Agent {
27
32
  isPublished: boolean;
28
33
  templateAgentId?: string;
29
34
  ownerRoomId?: string;
35
+ /** The pack this agent is filed under. See {@link AgentConfig.pack}. */
30
36
  pack?: string;
37
+ /** The pack template's key, when this agent came from one. */
31
38
  packAgentKey?: string;
32
39
  openai?: OpenAI;
33
40
  assistant?: Assistant;
34
41
  vectorStore?: VectorStore;
42
+ /** @internal Direct reference to the AI service */
35
43
  aiService: BaseAiService;
44
+ /** @internal Reference to ArtifactService for retrieving artifact content */
36
45
  artifactService: ArtifactService;
46
+ /** @internal Reference to user-specific filesystem paths */
37
47
  userPaths: UserPathsService;
48
+ /** @internal Reference to environment-variable configuration */
38
49
  configService: IConfigService;
50
+ /** @internal Reference to balance service for cost tracking and limits */
39
51
  balanceService?: BalanceService;
40
52
  description: string;
53
+ /**
54
+ * Private, agent-specific context that is visible only to this agent — never to
55
+ * other agents. Injected into the agent's transient (uncached) prompt message
56
+ * rather than the cached system instructions, so it can change frequently without
57
+ * invalidating the prompt cache. In stories this holds the character's inventory
58
+ * and conditions; contrast with {@link description}, which is the public
59
+ * appearance every other agent can see.
60
+ */
41
61
  privateContext: string;
42
62
  promptFolder: string;
63
+ /**
64
+ * The packs the owning user has enabled, consulted only when
65
+ * {@link promptFolder} is a bare name — a pack-qualified one always resolves.
66
+ *
67
+ * A thunk rather than an array because an agent outlives a toggle: the user
68
+ * can enable a pack while this instance is cached, and a snapshot taken at
69
+ * construction would need invalidating across every cached agent, room and
70
+ * service. Reading through the thunk means there is nothing to invalidate.
71
+ *
72
+ * Absent means "scan no packs", which is exactly the behaviour from before
73
+ * packs existed. Deliberately not in `AgentConfig` — it belongs to the user,
74
+ * not the agent, and persisting it would freeze a copy of the enabled set.
75
+ */
43
76
  enabledPacks?: () => readonly string[];
44
77
  systemInstruction: string;
45
78
  maxHistoryMessages?: number;
79
+ /**
80
+ * Index into {@link history} below which the rolling window may trim, and at or
81
+ * above which it may not. Protects a task that must survive intact from an agent
82
+ * whose window is deliberately short.
83
+ *
84
+ * **Deliberately not in `AgentConfig` and never saved.** `maxHistoryMessages` is
85
+ * operator configuration; this is transient state about the task in flight, and
86
+ * persisting it would leave an agent looking as though its window had been
87
+ * changed by hand. A restart clears it, costing at most the protection on one
88
+ * task in progress.
89
+ *
90
+ * It also needs no clearing. Re-pinning ends the previous pin, so an abandoned
91
+ * task is reclaimed the next time one starts, and the worst a stale pin can do is
92
+ * keep more history than intended — never drop any.
93
+ */
46
94
  historyPin?: number;
47
95
  modelName: string;
48
96
  smallModelName?: string;
@@ -55,37 +103,178 @@ export declare class Agent {
55
103
  isControlledByHuman: boolean;
56
104
  beginInstruction: string;
57
105
  toolNames: string[];
106
+ /**
107
+ * This agent intends to send MODERATE messages, so its room needs a moderator
108
+ * to route them.
109
+ *
110
+ * For a human-controlled agent it is also what removes the action and target
111
+ * pickers from the room's composer: the player types, the room forces the
112
+ * message to MODERATE, and the moderator decides who hears it and who answers.
113
+ *
114
+ * For an AI agent it is a declaration, not a coercion. An agent emits MODERATE
115
+ * by its own choice — either its perceive schema offers `moderate` as a way to
116
+ * defer the routing decision, or it has no schema at all and answers in prose,
117
+ * which Room.parseAgentResponse converts. An agent that names its own targets
118
+ * keeps doing so.
119
+ */
58
120
  useModerator: boolean;
59
121
  promptCacheTTL: number;
60
122
  private onStateChange;
61
123
  storageDir: string;
62
124
  private agentStoreService;
125
+ /**
126
+ * @internal Agents are constructed by the framework (AgentStoreService /
127
+ * BaseAiService.createAgent); SDK consumers should obtain them via
128
+ * {@link Briyah} rather than calling this directly.
129
+ */
63
130
  constructor(id: string | null, userPaths: UserPathsService, configService: IConfigService, agentStoreService: AgentStoreService, balanceService: BalanceService, artifactService: ArtifactService, agentName: string, agentNickname: string, description: string, promptFolder: string, systemInstruction: string, history: any[], modelName: string, serviceName: string, aiService: BaseAiService, reasoningEffort: 'low' | 'medium' | 'high' | null, allowSearch: boolean, maxOutputTokens: number, beginInstruction: string, storageDir: string);
64
131
  attachDocument(fileName: string, fileData: Uint8Array): Promise<string>;
132
+ /**
133
+ * Attaches an artifact to the agent
134
+ * @param artifactId The artifact ID
135
+ */
65
136
  attachArtifact(artifactId: string): void;
137
+ /**
138
+ * Detaches an artifact from the agent
139
+ * @param artifactId The artifact ID
140
+ */
66
141
  detachArtifact(artifactId: string): void;
142
+ /**
143
+ * Gets all attached artifact IDs
144
+ * @returns Array of artifact IDs
145
+ */
67
146
  getAttachedArtifacts(): string[];
147
+ /**
148
+ * Saves the agent to disk via AgentStoreService
149
+ * Called automatically after conversation history changes
150
+ */
68
151
  save(): void;
69
152
  finishAgent(): Promise<void>;
70
153
  deleteAgent(): Promise<void>;
154
+ /**
155
+ * Sets the callback to be called when agent state changes
156
+ * Used for SSE updates to push changes to connected clients
157
+ * @param callback Function to call when state changes
158
+ */
71
159
  setOnStateChange(callback: () => void): void;
160
+ /**
161
+ * Notifies listeners that the agent state has changed
162
+ * Triggers SSE updates if callback is registered
163
+ */
72
164
  notifyStateChange(): void;
73
165
  canRespond(message: Message): boolean;
166
+ /**
167
+ * Gets formatted messages from the agent's history starting from a specific index
168
+ * @param fromIndex The index to start from (0-based)
169
+ * @returns Array of formatted messages
170
+ */
74
171
  getFormattedMessages(fromIndex?: number): string[];
172
+ /**
173
+ * Gets the raw (unformatted) content of every message in the agent's history.
174
+ * @returns Array of message content strings
175
+ */
75
176
  getRawMessages(): string[];
177
+ /**
178
+ * Message fields that are dropped when a message is written into history.
179
+ *
180
+ * History sits in the cached prompt prefix of every agent that holds it, so each
181
+ * of these is paid for on every turn until the message falls out of the window:
182
+ *
183
+ * - `timestamp` — a wall-clock instant. No prompt in the repository reads one, and
184
+ * ordering is already carried by the position in the array.
185
+ * - `index` — the message's position in the room log, which is a storage detail.
186
+ * - `situation` — *current* state, not history. Every agent is handed the live
187
+ * situation in its transient prompt on every turn (`Room.buildTransientPrompt`),
188
+ * so the copies stored here are superseded by definition and, being the longest
189
+ * field on a room leader's messages, the most expensive thing in the window.
190
+ */
76
191
  private static readonly HISTORY_OMITTED_FIELDS;
192
+ /**
193
+ * Renders a room message as the compact JSON that goes into conversation history.
194
+ *
195
+ * Compact rather than indented, and without the fields above or any field that is
196
+ * empty: an absent `name` and an empty `name` say the same thing to a model, and
197
+ * only one of them costs tokens in every cached prefix that carries the message.
198
+ *
199
+ * @param message The room message to render
200
+ * @returns The message as a single-line JSON string
201
+ */
77
202
  private static formatMessageForHistory;
78
203
  addToConversationHistory(message: any, fromSelf?: boolean): void;
204
+ /**
205
+ * Marks the current end of history as the start of a task the rolling window
206
+ * must not trim into.
207
+ *
208
+ * A no-op for an agent with no window: there is nothing to protect it from, and
209
+ * a pin on an agent that keeps everything would only be a field to explain. That
210
+ * is what makes it safe to call from a shared path — the Dungeon Master running
211
+ * its own fight keeps its whole campaign either way.
212
+ *
213
+ * Call it *before* the message that starts the task is added to history, so the
214
+ * task's own opening instruction is inside the pin rather than the first thing
215
+ * dropped.
216
+ */
79
217
  pinHistory(): void;
218
+ /** How many trailing messages the pin protects from trimming. */
80
219
  private pinnedMessageCount;
220
+ /**
221
+ * Trims conversation history to keep only the last N messages if maxHistoryMessages is set
222
+ * Preserves system messages (role: 'developer') at the start of history
223
+ * Used for rolling window history management (e.g., moderator agents)
224
+ *
225
+ * A {@link historyPin} raises the floor: everything since the pin is kept even
226
+ * when that is more than the window allows. The window still applies to whatever
227
+ * came before it, so a specialist handed a second task drops the first.
228
+ * @param threshold Allow history to grow 'threshold' messages past the limit before trimming a 'threshold'-sized chunk of messages at once
229
+ */
81
230
  trimHistoryIfNeeded(threshold?: number): void;
231
+ /**
232
+ * Whether `<name>.prompt` resolves for this agent, so a caller can tell an agent
233
+ * that can run a kind of turn from one whose prompt folder has no prompt for it.
234
+ *
235
+ * False when the agent has no AI service or no paths yet — the answer to "could
236
+ * this agent run that turn" is then no, which is what a caller wants to hear.
237
+ */
82
238
  hasPrompt(name: string): boolean;
83
239
  instructedPrompt(prompt: string, instructionFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
84
240
  preparedPrompt(promptFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean): Promise<any>;
85
241
  withSmallModel<T>(fn: () => Promise<T>): Promise<T>;
242
+ /**
243
+ * How large a history may grow, in characters, before it is worth compacting.
244
+ *
245
+ * Read per call rather than cached so an operator can retune a long-running
246
+ * server without restarting it. Characters rather than tokens because it is the
247
+ * one measure available without asking a tokenizer, and the threshold only has
248
+ * to be roughly right — four characters to a token is close enough to make
249
+ * 100,000 mean "about 25k tokens".
250
+ *
251
+ * @returns The threshold in characters
252
+ */
86
253
  static compactionThresholdChars(): number;
254
+ /**
255
+ * The size of this agent's conversation history in characters.
256
+ * @returns Total characters across every message in history
257
+ */
87
258
  historyChars(): number;
259
+ /**
260
+ * Whether this agent's history has grown past the compaction threshold.
261
+ *
262
+ * An agent with `maxHistoryMessages` is excluded: a rolling window already
263
+ * bounds it, and the two mechanisms answer different needs. A window is for an
264
+ * agent whose old turns stop mattering — a moderator routing the next message
265
+ * does not need last hour's. Compaction is for one whose past must survive in
266
+ * some form, which is why it costs a model call to write a summary rather than
267
+ * dropping messages off the front.
268
+ *
269
+ * @returns True when compaction is worth a call
270
+ */
88
271
  needsCompaction(): boolean;
272
+ /**
273
+ * Replace this agent's conversation history with a single summary message.
274
+ * Uses the `compact_agent` prompt, resolved via the standard lookup order:
275
+ * user/<promptFolder> → user/root → common/<promptFolder> → common/root.
276
+ * On failure, the original history is restored.
277
+ */
89
278
  compact(): Promise<{
90
279
  success: boolean;
91
280
  originalLength: number;
@@ -96,6 +285,13 @@ export declare class Agent {
96
285
  summary?: string;
97
286
  }>;
98
287
  textPrompt(prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
288
+ /**
289
+ * Generates an image from a text prompt.
290
+ * @param prompt Text description of the image
291
+ * @param imageProperties Optional provider-specific image options
292
+ * (e.g. `width`, `height`, `quality`) passed through to the underlying AI service
293
+ * @returns Promise resolving to `{ artifactId }` on success or `{ error }` on failure
294
+ */
99
295
  generateImage(prompt: string, imageProperties?: Record<string, any>): Promise<{
100
296
  artifactId?: string;
101
297
  error?: any;