briyah 2.0.3 → 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 (371) hide show
  1. package/README.md +43 -7
  2. package/data/common/config/LICENSE-model-prices.md +65 -0
  3. package/data/common/config/model_prices.json +47443 -46295
  4. package/data/common/prompts/narrator/create_story.prompt +2 -0
  5. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
  6. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
  7. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
  8. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
  9. package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
  10. package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
  11. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
  12. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
  13. package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
  14. package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
  15. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
  16. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
  17. package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
  18. package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
  19. package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
  20. package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
  21. package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
  22. package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
  23. package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
  24. package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
  25. package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
  26. package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
  27. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
  28. package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
  29. package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
  30. package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
  31. package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
  32. package/dist-sdk/server/src/ai/agent-factory.js +20 -0
  33. package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
  34. package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
  35. package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
  36. package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
  37. package/dist-sdk/server/src/ai/agent.d.ts +196 -0
  38. package/dist-sdk/server/src/ai/agent.js +224 -11
  39. package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
  40. package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
  41. package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
  42. package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
  43. package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
  44. package/dist-sdk/server/src/ai/artifact.service.js +148 -3
  45. package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
  46. package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
  47. package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
  48. package/dist-sdk/server/src/ai/model_prices.js +91 -5
  49. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
  50. package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
  51. package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
  52. package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
  53. package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
  54. package/dist-sdk/server/src/app/balance-message.service.js +24 -0
  55. package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
  56. package/dist-sdk/server/src/app/balance.module.js +4 -0
  57. package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
  58. package/dist-sdk/server/src/app/balance.service.js +54 -0
  59. package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
  60. package/dist-sdk/server/src/app/stripe.controller.js +35 -0
  61. package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
  62. package/dist-sdk/server/src/app/stripe.service.js +62 -0
  63. package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
  64. package/dist-sdk/server/src/app/transaction.service.js +36 -0
  65. package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
  66. package/dist-sdk/server/src/app/user-service-factory.js +38 -1
  67. package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
  68. package/dist-sdk/server/src/app/user-service-manager.js +43 -0
  69. package/dist-sdk/server/src/app.controller.d.ts +87 -0
  70. package/dist-sdk/server/src/app.controller.js +272 -12
  71. package/dist-sdk/server/src/app.module.js +28 -6
  72. package/dist-sdk/server/src/app.service.d.ts +1661 -0
  73. package/dist-sdk/server/src/app.service.js +1837 -4
  74. package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
  75. package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
  76. package/dist-sdk/server/src/auth/auth.controller.js +46 -0
  77. package/dist-sdk/server/src/auth/auth.module.js +3 -2
  78. package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
  79. package/dist-sdk/server/src/auth/auth.service.js +39 -3
  80. package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
  81. package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
  82. package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
  83. package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
  84. package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
  85. package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
  86. package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
  87. package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
  88. package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
  89. package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
  90. package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
  91. package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
  92. package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
  93. package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
  94. package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
  95. package/dist-sdk/server/src/auth/session.guard.js +8 -0
  96. package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
  97. package/dist-sdk/server/src/auth/twilio.service.js +30 -4
  98. package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
  99. package/dist-sdk/server/src/auth/users.service.js +42 -0
  100. package/dist-sdk/server/src/common/errors.d.ts +20 -0
  101. package/dist-sdk/server/src/common/errors.js +21 -0
  102. package/dist-sdk/server/src/config/env-config.d.ts +7 -0
  103. package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
  104. package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
  105. package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
  106. package/dist-sdk/server/src/config/user-config.service.js +57 -0
  107. package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
  108. package/dist-sdk/server/src/config/user-paths.service.js +67 -0
  109. package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
  110. package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
  111. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
  112. package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
  113. package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
  114. package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
  115. package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
  116. package/dist-sdk/server/src/packs/pack.service.js +98 -1
  117. package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
  118. package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
  119. package/dist-sdk/server/src/room/artifact.d.ts +18 -0
  120. package/dist-sdk/server/src/room/message.d.ts +64 -0
  121. package/dist-sdk/server/src/room/message.js +77 -2
  122. package/dist-sdk/server/src/room/nickname.d.ts +26 -0
  123. package/dist-sdk/server/src/room/nickname.js +26 -0
  124. package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
  125. package/dist-sdk/server/src/room/room-config.d.ts +26 -0
  126. package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
  127. package/dist-sdk/server/src/room/room-factory.js +14 -0
  128. package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
  129. package/dist-sdk/server/src/room/room-message.service.js +28 -0
  130. package/dist-sdk/server/src/room/room-store.service.d.ts +176 -0
  131. package/dist-sdk/server/src/room/room-store.service.js +238 -5
  132. package/dist-sdk/server/src/room/room.d.ts +878 -0
  133. package/dist-sdk/server/src/room/room.js +1291 -23
  134. package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
  135. package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
  136. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
  137. package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
  138. package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
  139. package/dist-sdk/server/src/rpg/rpg.service.js +103 -0
  140. package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
  141. package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
  142. package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
  143. package/dist-sdk/server/src/sdk/briyah.js +285 -7
  144. package/dist-sdk/server/src/sdk/index.js +23 -0
  145. package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
  146. package/dist-sdk/server/src/shared/shared.module.js +13 -5
  147. package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
  148. package/dist-sdk/server/src/story/story-message.service.js +43 -0
  149. package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
  150. package/dist-sdk/server/src/story/story-progress.service.js +23 -0
  151. package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
  152. package/dist-sdk/server/src/story/story-store.service.js +136 -1
  153. package/dist-sdk/server/src/story/story.service.d.ts +398 -0
  154. package/dist-sdk/server/src/story/story.service.js +829 -25
  155. package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
  156. package/dist-sdk/server/src/tools/core/index.js +22 -0
  157. package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
  158. package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
  159. package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
  160. package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
  161. package/dist-sdk/server/src/tools/native-tool.types.d.ts +176 -0
  162. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
  163. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
  164. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
  165. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
  166. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
  167. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
  168. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
  169. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
  170. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
  171. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
  172. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
  173. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
  174. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
  175. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
  176. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
  177. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
  178. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
  179. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
  180. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
  181. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
  182. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
  183. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
  184. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
  185. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
  186. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
  187. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
  188. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
  189. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
  190. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
  191. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
  192. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
  193. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
  194. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
  195. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
  196. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
  197. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
  198. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
  199. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
  200. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
  201. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
  202. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
  203. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
  204. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
  205. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
  206. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
  207. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
  208. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
  209. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
  210. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
  211. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
  212. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
  213. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
  214. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
  215. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
  216. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
  217. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
  218. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
  219. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
  220. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
  221. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
  222. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
  223. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
  224. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
  225. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
  226. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
  227. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
  228. package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
  229. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
  230. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
  231. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
  232. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
  233. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
  234. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
  235. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
  236. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
  237. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
  238. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
  239. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
  240. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
  241. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
  242. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
  243. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
  244. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
  245. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +116 -0
  246. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
  247. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
  248. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
  249. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
  250. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
  251. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
  252. package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
  253. package/dist-sdk/server/src/tools/packs/index.js +66 -0
  254. package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
  255. package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
  256. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
  257. package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
  258. package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
  259. package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
  260. package/dist-sdk/shared/types/app.types.d.ts +285 -13
  261. package/dist-sdk/shared/types/app.types.js +3 -0
  262. package/package.json +167 -168
  263. package/data/common/config/random_words.txt +0 -2241
  264. package/data/common/story_ideas/biblical.json +0 -122
  265. package/data/common/story_ideas/fantasy.json +0 -82
  266. package/data/common/story_ideas/historical_fiction.json +0 -82
  267. package/data/common/story_ideas/science_fiction.json +0 -82
  268. package/docs/.nojekyll +0 -1
  269. package/docs/assets/hierarchy.js +0 -1
  270. package/docs/assets/highlight.css +0 -113
  271. package/docs/assets/icons.js +0 -18
  272. package/docs/assets/icons.svg +0 -1
  273. package/docs/assets/main.js +0 -60
  274. package/docs/assets/navigation.js +0 -1
  275. package/docs/assets/search.js +0 -1
  276. package/docs/assets/style.css +0 -1648
  277. package/docs/classes/Agent.html +0 -801
  278. package/docs/classes/Briyah.html +0 -296
  279. package/docs/classes/BriyahConfigService.html +0 -119
  280. package/docs/classes/NativeToolRegistry.html +0 -166
  281. package/docs/classes/PackInstantiationService.html +0 -157
  282. package/docs/classes/PackService.html +0 -247
  283. package/docs/classes/Room.html +0 -1434
  284. package/docs/classes/RoomMessage.html +0 -290
  285. package/docs/enums/MessageAction.html +0 -136
  286. package/docs/functions/availableToolPacks.html +0 -41
  287. package/docs/functions/buildMarkdown.html +0 -54
  288. package/docs/functions/dnd5eTools.html +0 -44
  289. package/docs/functions/installToolPacks.html +0 -51
  290. package/docs/functions/pageMarker.html +0 -45
  291. package/docs/functions/registerToolPacks.html +0 -54
  292. package/docs/functions/splitMarkdownIntoPages.html +0 -51
  293. package/docs/functions/stripWrappingFence.html +0 -52
  294. package/docs/hierarchy.html +0 -46
  295. package/docs/index.html +0 -595
  296. package/docs/interfaces/AgentCreationOptions.html +0 -125
  297. package/docs/interfaces/AgentInfo.html +0 -218
  298. package/docs/interfaces/AgentMessagesResponse.html +0 -74
  299. package/docs/interfaces/AppService.html +0 -3340
  300. package/docs/interfaces/Artifact.html +0 -95
  301. package/docs/interfaces/ArtifactMetadata.html +0 -112
  302. package/docs/interfaces/ArtifactWriteOptions.html +0 -90
  303. package/docs/interfaces/AttachDocumentResponse.html +0 -62
  304. package/docs/interfaces/BriyahConfigOptions.html +0 -124
  305. package/docs/interfaces/ChapterInfo.html +0 -62
  306. package/docs/interfaces/Character.html +0 -86
  307. package/docs/interfaces/ConversionAgent.html +0 -78
  308. package/docs/interfaces/CreateAgentResponse.html +0 -56
  309. package/docs/interfaces/CreateRoomResponse.html +0 -62
  310. package/docs/interfaces/CreateStoryResponse.html +0 -56
  311. package/docs/interfaces/FileList.html +0 -56
  312. package/docs/interfaces/FileMetadata.html +0 -89
  313. package/docs/interfaces/IConfigService.html +0 -79
  314. package/docs/interfaces/InstantiateModels.html +0 -64
  315. package/docs/interfaces/InstantiateRoomResult.html +0 -70
  316. package/docs/interfaces/LoadedPack.html +0 -131
  317. package/docs/interfaces/LoggingOptions.html +0 -92
  318. package/docs/interfaces/Message.html +0 -84
  319. package/docs/interfaces/ModelChoice.html +0 -73
  320. package/docs/interfaces/ModelInfo.html +0 -74
  321. package/docs/interfaces/NativeToolDefinition.html +0 -107
  322. package/docs/interfaces/PackAgentTemplate.html +0 -101
  323. package/docs/interfaces/PackRoomTemplate.html +0 -108
  324. package/docs/interfaces/PackView.html +0 -172
  325. package/docs/interfaces/PdfConversionOptions.html +0 -102
  326. package/docs/interfaces/PdfConversionResult.html +0 -97
  327. package/docs/interfaces/PdfMarkdownOptions.html +0 -198
  328. package/docs/interfaces/PdfMarkdownResult.html +0 -106
  329. package/docs/interfaces/PdfPageMarkdown.html +0 -94
  330. package/docs/interfaces/PreparedPromptResponse.html +0 -62
  331. package/docs/interfaces/ProcessTextResponse.html +0 -86
  332. package/docs/interfaces/PromptFile.html +0 -70
  333. package/docs/interfaces/PromptFileContent.html +0 -76
  334. package/docs/interfaces/PromptFilesResponse.html +0 -56
  335. package/docs/interfaces/PromptFolder.html +0 -80
  336. package/docs/interfaces/PromptFolderDefaults.html +0 -155
  337. package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
  338. package/docs/interfaces/PromptFoldersResponse.html +0 -56
  339. package/docs/interfaces/RoomDetails.html +0 -151
  340. package/docs/interfaces/RoomErrorUpdate.html +0 -82
  341. package/docs/interfaces/RoomInfo.html +0 -88
  342. package/docs/interfaces/RoomMessageUpdate.html +0 -113
  343. package/docs/interfaces/RoomMessagesResponse.html +0 -62
  344. package/docs/interfaces/SendMessageResult.html +0 -62
  345. package/docs/interfaces/StoryErrorEvent.html +0 -84
  346. package/docs/interfaces/StoryIdea.html +0 -74
  347. package/docs/interfaces/StoryInfo.html +0 -198
  348. package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
  349. package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
  350. package/docs/interfaces/StoryState.html +0 -108
  351. package/docs/interfaces/StoryStateEvent.html +0 -76
  352. package/docs/interfaces/ToolArtifact.html +0 -85
  353. package/docs/interfaces/ToolCaller.html +0 -77
  354. package/docs/interfaces/ToolDefinition.html +0 -80
  355. package/docs/interfaces/ToolHelpers.html +0 -105
  356. package/docs/interfaces/ToolPackDocuments.html +0 -100
  357. package/docs/interfaces/ToolParameter.html +0 -74
  358. package/docs/interfaces/ToolRoomAccess.html +0 -260
  359. package/docs/interfaces/ToolSummary.html +0 -74
  360. package/docs/interfaces/ToolsResponse.html +0 -68
  361. package/docs/interfaces/Transaction.html +0 -104
  362. package/docs/interfaces/TransactionHistoryResponse.html +0 -62
  363. package/docs/modules.html +0 -53
  364. package/docs/types/PackOrigin.html +0 -34
  365. package/docs/types/PromptScope.html +0 -34
  366. package/docs/types/RoomTurnMode.html +0 -42
  367. package/docs/types/RoomUpdate.html +0 -36
  368. package/docs/types/RosterOverrides.html +0 -42
  369. package/docs/types/ToolContext.html +0 -40
  370. package/docs/types/ToolRunResult.html +0 -34
  371. package/src/tools/packs/dnd5e/README.md +0 -867
@@ -1,3 +1,33 @@
1
+ /**
2
+ * The pricing table: the bundled one, with the host's {@link LOCAL_PRICES_FILE}
3
+ * merged over it.
4
+ *
5
+ * A shallow merge keyed by model name, so an overlay entry replaces a bundled one
6
+ * outright rather than being merged field by field. Half an entry is worse than
7
+ * either whole one — a rate paired with another model's token limits is wrong in a
8
+ * way nothing would report.
9
+ *
10
+ * The bundled table must exist; an unreadable one is fatal, because costing every
11
+ * call at zero would bypass balance gating silently. The overlay is optional and
12
+ * its absence is the normal case.
13
+ *
14
+ * Read once per process, like everything else here, so a newly added entry needs a
15
+ * restart before it resolves.
16
+ */
1
17
  export declare function getModelPrices(): any;
18
+ /**
19
+ * Looks up a model entry in model_prices.json. Tries the exact name first,
20
+ * then — if a provider prefix is supplied — `${prefix}/${modelName}` to match
21
+ * the litellm key convention used for providers like `deepseek/...`,
22
+ * `together_ai/...`, `xai/...`, `fal_ai/...`.
23
+ *
24
+ * @returns The model entry, or `null` when the model is not listed.
25
+ */
2
26
  export declare function resolveModelInfo(modelName: string, prefix?: string | null): any | null;
27
+ /**
28
+ * Convenience wrapper around {@link resolveModelInfo} returning `true` when
29
+ * the model is present in model_prices.json, or when the model is listed in
30
+ * image_models.json with a `centsPerImage` configured (so image-only models
31
+ * that bypass token-based pricing are still considered known).
32
+ */
3
33
  export declare function isKnownModel(modelName: string, prefix?: string | null): boolean;
@@ -38,13 +38,60 @@ exports.resolveModelInfo = resolveModelInfo;
38
38
  exports.isKnownModel = isKnownModel;
39
39
  const fs = __importStar(require("fs"));
40
40
  const path = __importStar(require("path"));
41
+ const logger_1 = require("../common/logger");
42
+ // Prices directory is in data/common/config (shared across all users). The table
43
+ // is refreshed by scripts/update-model-prices.js from litellm's default branch:
44
+ // https://github.com/BerriAI/litellm/blob/litellm_internal_staging/model_prices_and_context_window.json
45
+ /**
46
+ * A host's own pricing entries, merged over the bundled table.
47
+ *
48
+ * `model_prices.json` is package-canonical and replaced on every `init()`, so a
49
+ * host cannot keep an edit to it — which used to mean that a model a provider
50
+ * announced today was unusable until Briyah shipped a release, because
51
+ * `BaseAiService` refuses to build an agent for a model it has no price for.
52
+ *
53
+ * This file is never written by seeding, so what a host puts here survives. Two
54
+ * uses: a model the bundled table has not caught up with, and a rate that is not
55
+ * list price. Overriding an existing entry is therefore deliberate rather than an
56
+ * accident to guard against — negotiated pricing has nowhere else to live.
57
+ */
58
+ const LOCAL_PRICES_FILE = 'model_prices.local.json';
59
+ // Lazy-loaded so that BRIYAH_DATA_PATH is read at first use, not at import time.
41
60
  let _modelPrices = null;
42
61
  let _imageModels = null;
62
+ /** The shared config directory, which every file here is read from. */
63
+ function commonConfigDir() {
64
+ const dataDir = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
65
+ return path.join(dataDir, 'common', 'config');
66
+ }
67
+ /**
68
+ * Reads an optional JSON object, treating anything unreadable as absent.
69
+ *
70
+ * Warns rather than throws: these files are the host's, not the package's, and a
71
+ * typo in one should cost them the entries it holds, not the process.
72
+ * @param filePath The file to read
73
+ * @returns The parsed object, or `{}`
74
+ */
75
+ function readOptionalJsonObject(filePath) {
76
+ if (!fs.existsSync(filePath))
77
+ return {};
78
+ try {
79
+ const parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
80
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
81
+ logger_1.logger.warn(`Ignoring ${filePath}: expected a JSON object of model entries`);
82
+ return {};
83
+ }
84
+ return parsed;
85
+ }
86
+ catch (error) {
87
+ logger_1.logger.warn(`Ignoring ${filePath}: ${error.message}`);
88
+ return {};
89
+ }
90
+ }
43
91
  function getImageModels() {
44
92
  if (_imageModels !== null)
45
93
  return _imageModels;
46
- const dataDir = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
47
- const imageModelsPath = path.join(dataDir, 'common', 'config', 'image_models.json');
94
+ const imageModelsPath = path.join(commonConfigDir(), 'image_models.json');
48
95
  if (!fs.existsSync(imageModelsPath)) {
49
96
  _imageModels = [];
50
97
  return _imageModels;
@@ -57,22 +104,53 @@ function getImageModels() {
57
104
  }
58
105
  return _imageModels;
59
106
  }
107
+ /**
108
+ * The pricing table: the bundled one, with the host's {@link LOCAL_PRICES_FILE}
109
+ * merged over it.
110
+ *
111
+ * A shallow merge keyed by model name, so an overlay entry replaces a bundled one
112
+ * outright rather than being merged field by field. Half an entry is worse than
113
+ * either whole one — a rate paired with another model's token limits is wrong in a
114
+ * way nothing would report.
115
+ *
116
+ * The bundled table must exist; an unreadable one is fatal, because costing every
117
+ * call at zero would bypass balance gating silently. The overlay is optional and
118
+ * its absence is the normal case.
119
+ *
120
+ * Read once per process, like everything else here, so a newly added entry needs a
121
+ * restart before it resolves.
122
+ */
60
123
  function getModelPrices() {
61
124
  if (_modelPrices !== null)
62
125
  return _modelPrices;
63
- const dataDir = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
64
- const pricesFilePath = path.join(dataDir, 'common', 'config', 'model_prices.json');
126
+ const configDir = commonConfigDir();
127
+ const pricesFilePath = path.join(configDir, 'model_prices.json');
65
128
  if (!fs.existsSync(pricesFilePath)) {
66
129
  throw new Error(`Model prices file not found at ${pricesFilePath}. Cannot proceed without pricing data.`);
67
130
  }
131
+ let bundled;
68
132
  try {
69
- _modelPrices = JSON.parse(fs.readFileSync(pricesFilePath, 'utf8'));
133
+ bundled = JSON.parse(fs.readFileSync(pricesFilePath, 'utf8'));
70
134
  }
71
135
  catch (error) {
72
136
  throw new Error(`Failed to load model prices from ${pricesFilePath}: ${error}`);
73
137
  }
138
+ const local = readOptionalJsonObject(path.join(configDir, LOCAL_PRICES_FILE));
139
+ const localCount = Object.keys(local).length;
140
+ if (localCount > 0) {
141
+ logger_1.logger.log(`Applied ${localCount} model price entr${localCount === 1 ? 'y' : 'ies'} from ${LOCAL_PRICES_FILE}`);
142
+ }
143
+ _modelPrices = { ...bundled, ...local };
74
144
  return _modelPrices;
75
145
  }
146
+ /**
147
+ * Looks up a model entry in model_prices.json. Tries the exact name first,
148
+ * then — if a provider prefix is supplied — `${prefix}/${modelName}` to match
149
+ * the litellm key convention used for providers like `deepseek/...`,
150
+ * `together_ai/...`, `xai/...`, `fal_ai/...`.
151
+ *
152
+ * @returns The model entry, or `null` when the model is not listed.
153
+ */
76
154
  function resolveModelInfo(modelName, prefix) {
77
155
  if (!modelName)
78
156
  return null;
@@ -86,9 +164,17 @@ function resolveModelInfo(modelName, prefix) {
86
164
  }
87
165
  return null;
88
166
  }
167
+ /**
168
+ * Convenience wrapper around {@link resolveModelInfo} returning `true` when
169
+ * the model is present in model_prices.json, or when the model is listed in
170
+ * image_models.json with a `centsPerImage` configured (so image-only models
171
+ * that bypass token-based pricing are still considered known).
172
+ */
89
173
  function isKnownModel(modelName, prefix) {
90
174
  if (resolveModelInfo(modelName, prefix) !== null)
91
175
  return true;
176
+ // Image models are consolidated entries with `generation` and `editing` blocks,
177
+ // each carrying its own model id and centsPerImage.
92
178
  return getImageModels().some((m) => (m.generation?.model === modelName && m.generation?.centsPerImage != null) ||
93
179
  (m.editing?.model === modelName && m.editing?.centsPerImage != null));
94
180
  }
@@ -1,9 +1,93 @@
1
+ /**
2
+ * Documents shipped by a pack, exposed as read-only artifacts.
3
+ *
4
+ * A pack like `dnd5e` ships reference material its tools deliberately do not
5
+ * cover — combat procedure, class features — which an agent needs as an attached
6
+ * document rather than a tool result. Those files live in
7
+ * `data/packs/<pack>/artifacts/` beside a `manifest.json`, and are surfaced
8
+ * through {@link ArtifactService} so the Artifacts page and the per-agent attach
9
+ * flow treat them like any other artifact.
10
+ *
11
+ * Two properties matter and are the reason this is not a per-user copy:
12
+ *
13
+ * - **The ids are stable.** `pack:dnd5e.class-wizard` is the same string for every
14
+ * user, across restarts and reinstalls. `agent.attachedArtifacts` holds ids and
15
+ * resolves them on every request, so an id that changed would silently drop a
16
+ * document out of an agent's context. Moving these files from
17
+ * `common/artifacts/<pack>/` to `packs/<pack>/artifacts/` deliberately did not
18
+ * change one.
19
+ * - **They are read-only.** There is one copy, so a correction reaches everyone,
20
+ * and nothing has to remember that a user deleted one.
21
+ */
1
22
  import { ArtifactMetadata } from '../../../shared/types/app.types';
23
+ /** Marks an artifact id as belonging to a pack rather than to a user. */
2
24
  export declare const PACK_ARTIFACT_PREFIX = "pack:";
25
+ /** True when the id names a pack document rather than a user artifact. */
3
26
  export declare function isPackArtifactId(artifactId: string): boolean;
27
+ /**
28
+ * Lists the documents of the packs a given user has **enabled**.
29
+ *
30
+ * Gating applies to listing only. {@link getPackArtifact} resolves a document
31
+ * whatever the pack list says, so turning a pack off does not silently strip a
32
+ * document out of an agent that already has it attached.
33
+ *
34
+ * The enabled set is a parameter rather than a module-level lookup because
35
+ * enablement is per user, and this module is shared by every user in the process.
36
+ *
37
+ * @param packRoots Directories holding packs, one subdirectory per pack
38
+ * @param enabledPacks The packs this user has switched on
39
+ * @returns Metadata for every listable pack document, sorted by name
40
+ */
4
41
  export declare function listPackArtifacts(packRoots: readonly string[], enabledPacks: readonly string[]): ArtifactMetadata[];
42
+ /**
43
+ * Reads a pack document's metadata.
44
+ * @param packRoots Directories holding packs, one subdirectory per pack
45
+ * @param artifactId A `pack:`-prefixed id
46
+ * @returns The metadata, or null if no such document ships
47
+ */
5
48
  export declare function getPackArtifactMetadata(packRoots: readonly string[], artifactId: string): ArtifactMetadata | null;
49
+ /**
50
+ * Reads a pack document's content.
51
+ * @param packRoots Directories holding packs, one subdirectory per pack
52
+ * @param artifactId A `pack:`-prefixed id
53
+ * @returns The Markdown, or null if no such document ships
54
+ */
6
55
  export declare function getPackArtifact(packRoots: readonly string[], artifactId: string): string | null;
56
+ /**
57
+ * Lists a pack's document files by name, rather than by manifest entry.
58
+ *
59
+ * The manifest is the listing for *people* — it carries the display name the
60
+ * Artifacts page and the attach dialog show, so a file with no entry is invisible
61
+ * there. This is the listing for *code*, and it deliberately reads the directory
62
+ * instead: a pack whose tools enumerate their own documents lets an operator add
63
+ * one by dropping a file in, with nothing else to edit. The 5e pack's
64
+ * `class-*.md` documents are the case this exists for.
65
+ *
66
+ * Resolved per file rather than per pack, so a user's overlay may replace one
67
+ * document without hiding the rest — the same layering `prompt-resolver.ts` uses,
68
+ * and deliberately not {@link loadAll}'s whole-pack claim.
69
+ *
70
+ * Not gated on pack enablement, for the same reason {@link getPackArtifact} is
71
+ * not: a tool that has been granted must keep working.
72
+ *
73
+ * @param packRoots Directories holding packs, one subdirectory per pack
74
+ * @param pack The pack name
75
+ * @param prefix Keep only file names starting with this, case-insensitively
76
+ * @returns Bare file names, each ending in `.md`, sorted and without duplicates
77
+ */
7
78
  export declare function listPackDocumentFiles(packRoots: readonly string[], pack: string, prefix?: string): string[];
79
+ /**
80
+ * Reads one of a pack's document files by name.
81
+ *
82
+ * The counterpart to {@link listPackDocumentFiles}: what that lists, this reads.
83
+ * Roots are searched in order, so a user's overlay of a document wins over the
84
+ * installed one.
85
+ *
86
+ * @param packRoots Directories holding packs, one subdirectory per pack
87
+ * @param pack The pack name
88
+ * @param fileName A bare file name, as returned by {@link listPackDocumentFiles}
89
+ * @returns The file's text, or null if there is no such document
90
+ */
8
91
  export declare function readPackDocumentFile(packRoots: readonly string[], pack: string, fileName: string): string | null;
92
+ /** Test seam: drops the parsed manifests so a spec can rewrite its fixtures. */
9
93
  export declare function resetPackArtifactCache(): void;
@@ -1,4 +1,25 @@
1
1
  "use strict";
2
+ /**
3
+ * Documents shipped by a pack, exposed as read-only artifacts.
4
+ *
5
+ * A pack like `dnd5e` ships reference material its tools deliberately do not
6
+ * cover — combat procedure, class features — which an agent needs as an attached
7
+ * document rather than a tool result. Those files live in
8
+ * `data/packs/<pack>/artifacts/` beside a `manifest.json`, and are surfaced
9
+ * through {@link ArtifactService} so the Artifacts page and the per-agent attach
10
+ * flow treat them like any other artifact.
11
+ *
12
+ * Two properties matter and are the reason this is not a per-user copy:
13
+ *
14
+ * - **The ids are stable.** `pack:dnd5e.class-wizard` is the same string for every
15
+ * user, across restarts and reinstalls. `agent.attachedArtifacts` holds ids and
16
+ * resolves them on every request, so an id that changed would silently drop a
17
+ * document out of an agent's context. Moving these files from
18
+ * `common/artifacts/<pack>/` to `packs/<pack>/artifacts/` deliberately did not
19
+ * change one.
20
+ * - **They are read-only.** There is one copy, so a correction reaches everyone,
21
+ * and nothing has to remember that a user deleted one.
22
+ */
2
23
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
24
  if (k2 === undefined) k2 = k;
4
25
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -44,13 +65,61 @@ exports.resetPackArtifactCache = resetPackArtifactCache;
44
65
  const fs = __importStar(require("fs"));
45
66
  const path = __importStar(require("path"));
46
67
  const logger_1 = require("../common/logger");
68
+ /** Marks an artifact id as belonging to a pack rather than to a user. */
47
69
  exports.PACK_ARTIFACT_PREFIX = 'pack:';
70
+ /**
71
+ * Separates the pack from the document in an id: `pack:dnd5e.class-wizard`.
72
+ *
73
+ * Deliberately not a slash. An artifact id travels as a path segment on the
74
+ * detach route (`DELETE /api/agents/:agentId/artifacts/:artifactId`), and a slash
75
+ * there splits into an extra segment that matches nothing. Pack names must not
76
+ * contain this character.
77
+ */
48
78
  const PACK_SEPARATOR = '.';
79
+ /**
80
+ * The extension a pack document has. Every shipped document is Markdown — the
81
+ * manifest loader hardcodes `text/markdown` as the mime type — and restricting
82
+ * {@link listPackDocumentFiles} to it keeps an editor's backup copy of a document
83
+ * from listing as a second document.
84
+ */
49
85
  const DOCUMENT_EXTENSION = '.md';
86
+ /**
87
+ * Parsed manifests, keyed by the pack roots they were read from.
88
+ *
89
+ * The files ship with the build and never change while the process runs, so they
90
+ * are read once. Keyed by the roots because tests point at fixtures, and because
91
+ * a host may hand different users different roots.
92
+ */
50
93
  const cache = new Map();
94
+ /** True when the id names a pack document rather than a user artifact. */
51
95
  function isPackArtifactId(artifactId) {
52
96
  return artifactId.startsWith(exports.PACK_ARTIFACT_PREFIX);
53
97
  }
98
+ /**
99
+ * Reads every pack's artifact manifest under the given pack roots.
100
+ *
101
+ * A pack root holds one subdirectory per pack, and each pack keeps its documents
102
+ * in an `artifacts/` subdirectory of its own. **The pack name comes from the pack
103
+ * directory, not from the directory the manifest sits in** — `loadPack` refuses a
104
+ * manifest whose `pack` disagrees with the name it is given, so passing
105
+ * `'artifacts'` would reject every manifest and drop every document with nothing
106
+ * but a warning to show for it.
107
+ *
108
+ * A manifest that is missing, unparseable, or names a file that is not there is
109
+ * skipped with a warning rather than thrown: a bad shipped document must not stop
110
+ * the Artifacts page from listing the user's own.
111
+ *
112
+ * **Layering is per document, not per pack, and that is load-bearing.** A user's
113
+ * pack directory is a copy-on-write mirror holding only what they changed, so it
114
+ * routinely exists holding a single *prompt* and no `artifacts/` directory at all.
115
+ * A root that merely has a directory of the right name must therefore not take the
116
+ * pack over: doing so hides every document the other roots supply, both from the
117
+ * listing and from the agents that resolve one on every request — and nothing
118
+ * reports it, since a document that fails to resolve is simply absent from a
119
+ * prompt. So each root contributes the documents it actually defines, earlier roots
120
+ * winning per id. `prompt-resolver.ts` describes the same mirror-shadows-path model
121
+ * for prompts.
122
+ */
54
123
  function loadAll(packRoots) {
55
124
  const key = packRoots.join(path.delimiter);
56
125
  const cached = cache.get(key);
@@ -66,6 +135,8 @@ function loadAll(packRoots) {
66
135
  continue;
67
136
  const artifactsDir = path.join(root, entry.name, 'artifacts');
68
137
  for (const resolved of loadPack(packRoots, artifactsDir, entry.name)) {
138
+ // First root to define an id wins; later roots fill in the rest,
139
+ // so an overlay may replace one document without hiding the others.
69
140
  if (!documents.has(resolved.metadata.artifactId)) {
70
141
  documents.set(resolved.metadata.artifactId, resolved);
71
142
  }
@@ -75,6 +146,15 @@ function loadAll(packRoots) {
75
146
  cache.set(key, documents);
76
147
  return documents;
77
148
  }
149
+ /**
150
+ * Resolves one manifest's entries against the files they name.
151
+ * @param packRoots Every root, so a document's *file* layers the same way its
152
+ * entry does — an overlaid copy of `class-wizard.md` is the one that is read,
153
+ * whether or not the overlay declares a manifest of its own
154
+ * @param packDir The `artifacts/` directory this manifest sits in
155
+ * @param dirName The pack directory's name, which the manifest must agree with
156
+ * @returns One entry per document that resolved
157
+ */
78
158
  function loadPack(packRoots, packDir, dirName) {
79
159
  const manifestPath = path.join(packDir, 'manifest.json');
80
160
  if (!fs.existsSync(manifestPath)) {
@@ -106,6 +186,8 @@ function loadPack(packRoots, packDir, dirName) {
106
186
  logger_1.logger.warn(`Skipping "${document.id}" in ${manifestPath}: an id may not contain "${PACK_SEPARATOR}"`);
107
187
  continue;
108
188
  }
189
+ // The manifest ships with the build, but a file name is still a path and
190
+ // is treated as one.
109
191
  if (document.file !== path.basename(document.file)) {
110
192
  logger_1.logger.warn(`Skipping "${document.id}" in ${manifestPath}: file must be a bare name`);
111
193
  continue;
@@ -131,8 +213,23 @@ function loadPack(packRoots, packDir, dirName) {
131
213
  },
132
214
  });
133
215
  }
216
+ // The pack name prefixes every id, so this also proves ids are unique overall.
134
217
  return resolved;
135
218
  }
219
+ /**
220
+ * Lists the documents of the packs a given user has **enabled**.
221
+ *
222
+ * Gating applies to listing only. {@link getPackArtifact} resolves a document
223
+ * whatever the pack list says, so turning a pack off does not silently strip a
224
+ * document out of an agent that already has it attached.
225
+ *
226
+ * The enabled set is a parameter rather than a module-level lookup because
227
+ * enablement is per user, and this module is shared by every user in the process.
228
+ *
229
+ * @param packRoots Directories holding packs, one subdirectory per pack
230
+ * @param enabledPacks The packs this user has switched on
231
+ * @returns Metadata for every listable pack document, sorted by name
232
+ */
136
233
  function listPackArtifacts(packRoots, enabledPacks) {
137
234
  const packs = new Set(enabledPacks);
138
235
  return [...loadAll(packRoots).values()]
@@ -140,12 +237,25 @@ function listPackArtifacts(packRoots, enabledPacks) {
140
237
  .map((doc) => doc.metadata)
141
238
  .sort((a, b) => a.name.localeCompare(b.name));
142
239
  }
240
+ /** The pack name out of a `pack:<pack>.<name>` id. */
143
241
  function packOf(artifactId) {
144
242
  return artifactId.slice(exports.PACK_ARTIFACT_PREFIX.length).split(PACK_SEPARATOR)[0];
145
243
  }
244
+ /**
245
+ * Reads a pack document's metadata.
246
+ * @param packRoots Directories holding packs, one subdirectory per pack
247
+ * @param artifactId A `pack:`-prefixed id
248
+ * @returns The metadata, or null if no such document ships
249
+ */
146
250
  function getPackArtifactMetadata(packRoots, artifactId) {
147
251
  return loadAll(packRoots).get(artifactId)?.metadata ?? null;
148
252
  }
253
+ /**
254
+ * Reads a pack document's content.
255
+ * @param packRoots Directories holding packs, one subdirectory per pack
256
+ * @param artifactId A `pack:`-prefixed id
257
+ * @returns The Markdown, or null if no such document ships
258
+ */
149
259
  function getPackArtifact(packRoots, artifactId) {
150
260
  const document = loadAll(packRoots).get(artifactId);
151
261
  if (!document) {
@@ -159,6 +269,28 @@ function getPackArtifact(packRoots, artifactId) {
159
269
  return null;
160
270
  }
161
271
  }
272
+ /**
273
+ * Lists a pack's document files by name, rather than by manifest entry.
274
+ *
275
+ * The manifest is the listing for *people* — it carries the display name the
276
+ * Artifacts page and the attach dialog show, so a file with no entry is invisible
277
+ * there. This is the listing for *code*, and it deliberately reads the directory
278
+ * instead: a pack whose tools enumerate their own documents lets an operator add
279
+ * one by dropping a file in, with nothing else to edit. The 5e pack's
280
+ * `class-*.md` documents are the case this exists for.
281
+ *
282
+ * Resolved per file rather than per pack, so a user's overlay may replace one
283
+ * document without hiding the rest — the same layering `prompt-resolver.ts` uses,
284
+ * and deliberately not {@link loadAll}'s whole-pack claim.
285
+ *
286
+ * Not gated on pack enablement, for the same reason {@link getPackArtifact} is
287
+ * not: a tool that has been granted must keep working.
288
+ *
289
+ * @param packRoots Directories holding packs, one subdirectory per pack
290
+ * @param pack The pack name
291
+ * @param prefix Keep only file names starting with this, case-insensitively
292
+ * @returns Bare file names, each ending in `.md`, sorted and without duplicates
293
+ */
162
294
  function listPackDocumentFiles(packRoots, pack, prefix = '') {
163
295
  if (!isBareName(pack)) {
164
296
  return [];
@@ -176,12 +308,25 @@ function listPackDocumentFiles(packRoots, pack, prefix = '') {
176
308
  const key = name.toLowerCase();
177
309
  if (!key.endsWith(DOCUMENT_EXTENSION) || !key.startsWith(wanted))
178
310
  continue;
311
+ // First root wins, so an overlay's copy of a document does not list twice.
179
312
  if (!found.has(key))
180
313
  found.set(key, name);
181
314
  }
182
315
  }
183
316
  return [...found.values()].sort((a, b) => a.localeCompare(b));
184
317
  }
318
+ /**
319
+ * Reads one of a pack's document files by name.
320
+ *
321
+ * The counterpart to {@link listPackDocumentFiles}: what that lists, this reads.
322
+ * Roots are searched in order, so a user's overlay of a document wins over the
323
+ * installed one.
324
+ *
325
+ * @param packRoots Directories holding packs, one subdirectory per pack
326
+ * @param pack The pack name
327
+ * @param fileName A bare file name, as returned by {@link listPackDocumentFiles}
328
+ * @returns The file's text, or null if there is no such document
329
+ */
185
330
  function readPackDocumentFile(packRoots, pack, fileName) {
186
331
  const filePath = findDocumentFile(packRoots, pack, fileName);
187
332
  if (!filePath) {
@@ -195,6 +340,19 @@ function readPackDocumentFile(packRoots, pack, fileName) {
195
340
  return null;
196
341
  }
197
342
  }
343
+ /**
344
+ * Locates one of a pack's document files, highest-precedence root first.
345
+ *
346
+ * The single place a document's file is resolved, so the manifest tier and the file
347
+ * tier cannot disagree about which copy of `class-wizard.md` is the real one — an
348
+ * agent's attached document and `class_guide`'s reading of the same file would
349
+ * otherwise diverge the moment a user overlaid it.
350
+ *
351
+ * @param packRoots Directories holding packs, one subdirectory per pack
352
+ * @param pack The pack name
353
+ * @param fileName A bare file name
354
+ * @returns The path to read, or null when no root has the file
355
+ */
198
356
  function findDocumentFile(packRoots, pack, fileName) {
199
357
  if (!isBareName(pack) || !isBareName(fileName)) {
200
358
  return null;
@@ -206,6 +364,15 @@ function findDocumentFile(packRoots, pack, fileName) {
206
364
  }
207
365
  return null;
208
366
  }
367
+ /**
368
+ * Whether a name may be joined onto a path as a single component.
369
+ *
370
+ * These two functions take names that reach them from a tool, and therefore
371
+ * ultimately from a model, so a name is checked rather than trusted. `path.basename`
372
+ * settles both traversal and separators in one comparison; the leading-dot rule
373
+ * keeps `.` and `..` out, and on NTFS a colon would be read as the alternate-data-stream
374
+ * separator rather than failing cleanly.
375
+ */
209
376
  function isBareName(name) {
210
377
  return (typeof name === 'string' &&
211
378
  name.length > 0 &&
@@ -213,6 +380,7 @@ function isBareName(name) {
213
380
  !name.includes(':') &&
214
381
  name === path.basename(name));
215
382
  }
383
+ /** Test seam: drops the parsed manifests so a spec can rewrite its fixtures. */
216
384
  function resetPackArtifactCache() {
217
385
  cache.clear();
218
386
  }
@@ -4,10 +4,35 @@ export declare class PublishedAgentsService implements OnModuleInit {
4
4
  private readonly mappingFile;
5
5
  constructor();
6
6
  onModuleInit(): void;
7
+ /**
8
+ * Get the userId for a published agent
9
+ * @param agentId The agent ID to lookup
10
+ * @returns The userId who owns the agent, or undefined if not found
11
+ */
7
12
  getUserId(agentId: string): string | undefined;
13
+ /**
14
+ * Add a published agent to the mapping
15
+ * @param agentId The agent ID
16
+ * @param userId The user who owns the agent
17
+ */
8
18
  addPublishedAgent(agentId: string, userId: string): void;
19
+ /**
20
+ * Remove a published agent from the mapping
21
+ * @param agentId The agent ID to remove
22
+ */
9
23
  removePublishedAgent(agentId: string): void;
24
+ /**
25
+ * Check if an agent is in the published mapping
26
+ * @param agentId The agent ID to check
27
+ * @returns True if the agent is in the mapping
28
+ */
10
29
  isAgentPublished(agentId: string): boolean;
30
+ /**
31
+ * Load the mapping from disk
32
+ */
11
33
  private load;
34
+ /**
35
+ * Save the mapping to disk
36
+ */
12
37
  private save;
13
38
  }
@@ -48,11 +48,13 @@ const fs = __importStar(require("fs"));
48
48
  const path = __importStar(require("path"));
49
49
  const logger_1 = require("../common/logger");
50
50
  let PublishedAgentsService = class PublishedAgentsService {
51
- mapping = new Map();
51
+ mapping = new Map(); // agentId → userId
52
52
  mappingFile;
53
53
  constructor() {
54
+ // Priority: env var > default
54
55
  const dataPath = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
55
56
  const dataDir = path.resolve(dataPath, 'common');
57
+ // Ensure the data/common directory exists
56
58
  if (!fs.existsSync(dataDir)) {
57
59
  fs.mkdirSync(dataDir, { recursive: true });
58
60
  }
@@ -61,26 +63,48 @@ let PublishedAgentsService = class PublishedAgentsService {
61
63
  onModuleInit() {
62
64
  this.load();
63
65
  }
66
+ /**
67
+ * Get the userId for a published agent
68
+ * @param agentId The agent ID to lookup
69
+ * @returns The userId who owns the agent, or undefined if not found
70
+ */
64
71
  getUserId(agentId) {
65
72
  return this.mapping.get(agentId);
66
73
  }
74
+ /**
75
+ * Add a published agent to the mapping
76
+ * @param agentId The agent ID
77
+ * @param userId The user who owns the agent
78
+ */
67
79
  addPublishedAgent(agentId, userId) {
68
80
  this.mapping.set(agentId, userId);
69
81
  this.save();
70
82
  }
83
+ /**
84
+ * Remove a published agent from the mapping
85
+ * @param agentId The agent ID to remove
86
+ */
71
87
  removePublishedAgent(agentId) {
72
88
  this.mapping.delete(agentId);
73
89
  this.save();
74
90
  }
91
+ /**
92
+ * Check if an agent is in the published mapping
93
+ * @param agentId The agent ID to check
94
+ * @returns True if the agent is in the mapping
95
+ */
75
96
  isAgentPublished(agentId) {
76
97
  return this.mapping.has(agentId);
77
98
  }
99
+ /**
100
+ * Load the mapping from disk
101
+ */
78
102
  load() {
79
103
  try {
80
104
  if (!fs.existsSync(this.mappingFile)) {
81
105
  logger_1.logger.log('[PublishedAgentsService] No published agents file found, starting fresh');
82
106
  this.mapping = new Map();
83
- this.save();
107
+ this.save(); // Create initial file
84
108
  return;
85
109
  }
86
110
  const data = fs.readFileSync(this.mappingFile, 'utf-8');
@@ -96,9 +120,12 @@ let PublishedAgentsService = class PublishedAgentsService {
96
120
  logger_1.logger.error('[PublishedAgentsService] Error loading published agents:', error);
97
121
  logger_1.logger.log('[PublishedAgentsService] Starting with empty mapping');
98
122
  this.mapping = new Map();
99
- this.save();
123
+ this.save(); // Create fresh file
100
124
  }
101
125
  }
126
+ /**
127
+ * Save the mapping to disk
128
+ */
102
129
  save() {
103
130
  try {
104
131
  const data = {
@@ -1,8 +1,32 @@
1
1
  import { EventEmitter } from 'events';
2
+ /**
3
+ * Service for managing SSE connections for user balance updates
4
+ * Uses event-driven updates triggered by balance changes (no polling)
5
+ */
2
6
  export declare class BalanceMessageService {
3
7
  private messageEmitters;
8
+ /**
9
+ * Gets or creates a message emitter for a user
10
+ * @param userId The user ID
11
+ * @returns The event emitter for this user
12
+ */
4
13
  getOrCreateEmitter(userId: string): EventEmitter;
14
+ /**
15
+ * Gets the message emitter for a user
16
+ * @param userId The user ID
17
+ * @returns The event emitter or undefined if not found
18
+ */
5
19
  getEmitter(userId: string): EventEmitter | undefined;
20
+ /**
21
+ * Emits a balance update event for a user
22
+ * Called when user's balance changes
23
+ * @param userId The user ID
24
+ * @param balance The updated balance
25
+ */
6
26
  emitUpdate(userId: string, balance: number): void;
27
+ /**
28
+ * Cleans up the message emitter for a user
29
+ * @param userId The user ID
30
+ */
7
31
  cleanup(userId: string): void;
8
32
  }