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
@@ -18,19 +18,27 @@ let RateLimitService = class RateLimitService {
18
18
  WINDOW_MINUTES = 15;
19
19
  cleanupInterval;
20
20
  constructor() {
21
+ // Auto-cleanup expired entries every hour
21
22
  this.cleanupInterval = setInterval(() => {
22
23
  this.cleanup();
23
24
  }, 60 * 60 * 1000);
24
25
  }
26
+ /**
27
+ * Check if a phone number has exceeded rate limit
28
+ * @param phone - Normalized phone number
29
+ * @returns Object with allowed status and remaining attempts
30
+ */
25
31
  checkRateLimit(phone) {
26
32
  const entry = this.attemptMap.get(phone);
27
33
  if (!entry) {
28
34
  return { allowed: true, remainingAttempts: this.MAX_ATTEMPTS };
29
35
  }
36
+ // Check if the window has expired
30
37
  if (new Date() > entry.resetAt) {
31
38
  this.attemptMap.delete(phone);
32
39
  return { allowed: true, remainingAttempts: this.MAX_ATTEMPTS };
33
40
  }
41
+ // Check if limit exceeded
34
42
  if (entry.count >= this.MAX_ATTEMPTS) {
35
43
  return { allowed: false, remainingAttempts: 0 };
36
44
  }
@@ -39,24 +47,37 @@ let RateLimitService = class RateLimitService {
39
47
  remainingAttempts: this.MAX_ATTEMPTS - entry.count,
40
48
  };
41
49
  }
50
+ /**
51
+ * Record an OTP request attempt
52
+ * @param phone - Normalized phone number
53
+ */
42
54
  recordAttempt(phone) {
43
55
  const entry = this.attemptMap.get(phone);
44
56
  const now = new Date();
45
57
  if (!entry || now > entry.resetAt) {
58
+ // Create new entry with reset window
46
59
  this.attemptMap.set(phone, {
47
60
  count: 1,
48
61
  resetAt: new Date(now.getTime() + this.WINDOW_MINUTES * 60 * 1000),
49
62
  });
50
63
  }
51
64
  else {
65
+ // Increment existing entry
52
66
  entry.count++;
53
67
  }
54
68
  logger_1.logger.log(`Rate limit recorded for ${phone}: ${this.attemptMap.get(phone)?.count}/${this.MAX_ATTEMPTS}`);
55
69
  }
70
+ /**
71
+ * Clear rate limit for a phone number (e.g., after successful verification)
72
+ * @param phone - Normalized phone number
73
+ */
56
74
  clearAttempts(phone) {
57
75
  this.attemptMap.delete(phone);
58
76
  logger_1.logger.log(`Rate limit cleared for ${phone}`);
59
77
  }
78
+ /**
79
+ * Remove expired entries from the map
80
+ */
60
81
  cleanup() {
61
82
  const now = new Date();
62
83
  let cleaned = 0;
@@ -70,6 +91,9 @@ let RateLimitService = class RateLimitService {
70
91
  logger_1.logger.log(`Cleaned up ${cleaned} expired rate limit entries`);
71
92
  }
72
93
  }
94
+ /**
95
+ * Cleanup on service destruction
96
+ */
73
97
  onModuleDestroy() {
74
98
  if (this.cleanupInterval) {
75
99
  clearInterval(this.cleanupInterval);
@@ -1,2 +1,10 @@
1
+ /**
2
+ * Read-only access to published rooms
3
+ * Requires: room:read scope (or user:full)
4
+ */
1
5
  export declare const RoomReadAccess: () => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
6
+ /**
7
+ * Interactive access to published rooms
8
+ * Requires: room:read + room:interact scopes (or user:full)
9
+ */
2
10
  export declare const RoomAccess: () => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -4,7 +4,15 @@ exports.RoomAccess = exports.RoomReadAccess = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const scopes_guard_1 = require("./scopes.guard");
6
6
  const scopes_decorator_1 = require("./scopes.decorator");
7
+ /**
8
+ * Read-only access to published rooms
9
+ * Requires: room:read scope (or user:full)
10
+ */
7
11
  const RoomReadAccess = () => (0, common_1.applyDecorators)((0, common_1.UseGuards)(scopes_guard_1.ScopesGuard), (0, scopes_decorator_1.RequireScopes)('room:read'));
8
12
  exports.RoomReadAccess = RoomReadAccess;
13
+ /**
14
+ * Interactive access to published rooms
15
+ * Requires: room:read + room:interact scopes (or user:full)
16
+ */
9
17
  const RoomAccess = () => (0, common_1.applyDecorators)((0, common_1.UseGuards)(scopes_guard_1.ScopesGuard), (0, scopes_decorator_1.RequireScopes)('room:read', 'room:interact'));
10
18
  exports.RoomAccess = RoomAccess;
@@ -1,2 +1,9 @@
1
1
  export declare const SCOPES_KEY = "scopes";
2
+ /**
3
+ * Decorator to mark endpoints with required scopes
4
+ * @param scopes - Array of required scopes (user must have ALL scopes)
5
+ *
6
+ * Example:
7
+ * @RequireScopes('agent:read', 'agent:interact')
8
+ */
2
9
  export declare const RequireScopes: (...scopes: string[]) => import("@nestjs/common").CustomDecorator<string>;
@@ -3,5 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RequireScopes = exports.SCOPES_KEY = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  exports.SCOPES_KEY = 'scopes';
6
+ /**
7
+ * Decorator to mark endpoints with required scopes
8
+ * @param scopes - Array of required scopes (user must have ALL scopes)
9
+ *
10
+ * Example:
11
+ * @RequireScopes('agent:read', 'agent:interact')
12
+ */
6
13
  const RequireScopes = (...scopes) => (0, common_1.SetMetadata)(exports.SCOPES_KEY, scopes);
7
14
  exports.RequireScopes = RequireScopes;
@@ -1,9 +1,25 @@
1
1
  import { ExecutionContext, CanActivate } from '@nestjs/common';
2
2
  import { Reflector } from '@nestjs/core';
3
+ /**
4
+ * Guard that validates JWT has required scopes
5
+ *
6
+ * Features:
7
+ * - Expects JWT authentication (from JwtAuthGuard)
8
+ * - Checks if user has required scopes from decorator metadata
9
+ * - Special handling for 'user:full' scope (grants all access)
10
+ * - For agent-access tokens, validates agentId matches request
11
+ * - For room-access tokens, validates roomId matches request
12
+ */
3
13
  export declare class ScopesGuard implements CanActivate {
4
14
  private reflector;
5
15
  constructor(reflector: Reflector);
6
16
  canActivate(context: ExecutionContext): Promise<boolean>;
17
+ /**
18
+ * Extract agentId from request (URL params or body)
19
+ */
7
20
  private extractAgentIdFromRequest;
21
+ /**
22
+ * Extract roomId from request (URL params, query params, or body)
23
+ */
8
24
  private extractRoomIdFromRequest;
9
25
  }
@@ -13,6 +13,16 @@ exports.ScopesGuard = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const core_1 = require("@nestjs/core");
15
15
  const scopes_decorator_1 = require("./scopes.decorator");
16
+ /**
17
+ * Guard that validates JWT has required scopes
18
+ *
19
+ * Features:
20
+ * - Expects JWT authentication (from JwtAuthGuard)
21
+ * - Checks if user has required scopes from decorator metadata
22
+ * - Special handling for 'user:full' scope (grants all access)
23
+ * - For agent-access tokens, validates agentId matches request
24
+ * - For room-access tokens, validates roomId matches request
25
+ */
16
26
  let ScopesGuard = class ScopesGuard {
17
27
  reflector;
18
28
  constructor(reflector) {
@@ -20,31 +30,40 @@ let ScopesGuard = class ScopesGuard {
20
30
  }
21
31
  async canActivate(context) {
22
32
  const request = context.switchToHttp().getRequest();
33
+ // User should already be attached by JwtAuthGuard
23
34
  if (!request.user) {
24
35
  return false;
25
36
  }
37
+ // Get required scopes from endpoint metadata
26
38
  const requiredScopes = this.reflector.getAllAndOverride(scopes_decorator_1.SCOPES_KEY, [
27
39
  context.getHandler(),
28
40
  context.getClass(),
29
41
  ]);
42
+ // If no scopes specified, allow access (backward compatibility)
30
43
  if (!requiredScopes || requiredScopes.length === 0) {
31
44
  return true;
32
45
  }
46
+ // Get user from request (populated by JWT strategy)
33
47
  const user = request.user;
48
+ // Check if user has required scopes
34
49
  const userScopes = user.scope || [];
50
+ // Check for 'user:full' which grants access to everything
35
51
  if (userScopes.includes('user:full')) {
36
52
  return true;
37
53
  }
54
+ // Check if user has ALL required scopes
38
55
  const hasAllScopes = requiredScopes.every((scope) => userScopes.includes(scope));
39
56
  if (!hasAllScopes) {
40
57
  throw new common_1.ForbiddenException('Insufficient permissions');
41
58
  }
59
+ // For agent-access tokens, validate agentId matches
42
60
  if (user.type === 'agent-access' && user.agentId) {
43
61
  const agentId = this.extractAgentIdFromRequest(request);
44
62
  if (agentId && agentId !== user.agentId) {
45
63
  throw new common_1.ForbiddenException('Token not valid for this agent');
46
64
  }
47
65
  }
66
+ // For room-access tokens, validate roomId matches
48
67
  if (user.type === 'room-access' && user.roomId) {
49
68
  const roomId = this.extractRoomIdFromRequest(request);
50
69
  if (roomId && roomId !== user.roomId) {
@@ -53,22 +72,33 @@ let ScopesGuard = class ScopesGuard {
53
72
  }
54
73
  return true;
55
74
  }
75
+ /**
76
+ * Extract agentId from request (URL params or body)
77
+ */
56
78
  extractAgentIdFromRequest(request) {
79
+ // Check URL params
57
80
  if (request.params?.agentId) {
58
81
  return request.params.agentId;
59
82
  }
83
+ // Check body
60
84
  if (request.body?.agentId) {
61
85
  return request.body.agentId;
62
86
  }
63
87
  return null;
64
88
  }
89
+ /**
90
+ * Extract roomId from request (URL params, query params, or body)
91
+ */
65
92
  extractRoomIdFromRequest(request) {
93
+ // Check URL params
66
94
  if (request.params?.roomId) {
67
95
  return request.params.roomId;
68
96
  }
97
+ // Check query params
69
98
  if (request.query?.roomId) {
70
99
  return request.query.roomId;
71
100
  }
101
+ // Check body
72
102
  if (request.body?.roomId) {
73
103
  return request.body.roomId;
74
104
  }
@@ -1,5 +1,9 @@
1
1
  import { CanActivate, ExecutionContext } from '@nestjs/common';
2
2
  import { JwtService } from '@nestjs/jwt';
3
+ /**
4
+ * Simple JWT session guard (alternative to JwtAuthGuard)
5
+ * Use this when you only need basic JWT validation without scope checking
6
+ */
3
7
  export declare class SessionGuard implements CanActivate {
4
8
  private jwtService;
5
9
  constructor(jwtService: JwtService);
@@ -12,6 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SessionGuard = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const jwt_1 = require("@nestjs/jwt");
15
+ /**
16
+ * Simple JWT session guard (alternative to JwtAuthGuard)
17
+ * Use this when you only need basic JWT validation without scope checking
18
+ */
15
19
  let SessionGuard = class SessionGuard {
16
20
  jwtService;
17
21
  constructor(jwtService) {
@@ -19,7 +23,9 @@ let SessionGuard = class SessionGuard {
19
23
  }
20
24
  async canActivate(context) {
21
25
  const request = context.switchToHttp().getRequest();
26
+ // Try JWT from HTTP-only cookie first
22
27
  let token = request.cookies?.briyah_jwt;
28
+ // Fall back to Authorization header
23
29
  if (!token) {
24
30
  const authHeader = request.headers.authorization;
25
31
  if (authHeader && authHeader.startsWith('Bearer ')) {
@@ -31,6 +37,7 @@ let SessionGuard = class SessionGuard {
31
37
  }
32
38
  try {
33
39
  const payload = await this.jwtService.verifyAsync(token);
40
+ // Attach user data to request for use in controllers
34
41
  request.user = {
35
42
  sub: payload.sub,
36
43
  userId: payload.sub,
@@ -42,6 +49,7 @@ let SessionGuard = class SessionGuard {
42
49
  roomId: payload.roomId,
43
50
  };
44
51
  return true;
52
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
45
53
  }
46
54
  catch (_error) {
47
55
  return false;
@@ -1,6 +1,16 @@
1
1
  import { ConfigService } from '@nestjs/config';
2
+ /**
3
+ * The resolved answer to "did this code check out?".
4
+ *
5
+ * Deliberately *not* Twilio's response shape. A wrong code comes back from
6
+ * Twilio as HTTP 200 with a `status` of `pending`, so returning the raw body
7
+ * invites a caller to test it for truthiness and let a bad code through — which
8
+ * is exactly what happened. Reading `approved` is the only way to use this.
9
+ */
2
10
  export interface VerificationCheckResult {
11
+ /** True only when Twilio reported the code as approved. */
3
12
  approved: boolean;
13
+ /** Twilio's status, for logging and for telling "wrong" from "expired". */
4
14
  status: string;
5
15
  }
6
16
  export declare class TwilioService {
@@ -12,8 +22,25 @@ export declare class TwilioService {
12
22
  private readonly TWILIO_VERIFY_SID;
13
23
  constructor(configService: ConfigService);
14
24
  sendVerification(to: string, channel?: 'sms' | 'call'): Promise<any>;
25
+ /**
26
+ * Checks a verification code with Twilio.
27
+ * @param to The normalized phone number the code was sent to
28
+ * @param code The code the caller supplied
29
+ * @returns Whether Twilio approved the code, and the status it reported
30
+ * @throws If Twilio cannot be reached or answers with a non-ok status —
31
+ * including the 404 it returns once a verification has expired, been
32
+ * approved already, or hit its check limit
33
+ */
15
34
  checkVerification(to: string, code: string): Promise<VerificationCheckResult>;
16
35
  sendSms(to: string, body: string): Promise<any>;
36
+ /**
37
+ * Check if test mode is enabled
38
+ * Test mode allows bypassing Twilio for testing purposes
39
+ */
17
40
  private isTestMode;
41
+ /**
42
+ * Check if a phone number is a test phone number
43
+ * Test phone numbers use the 555 prefix (reserved for testing)
44
+ */
18
45
  private isTestPhoneNumber;
19
46
  }
@@ -27,16 +27,18 @@ let TwilioService = class TwilioService {
27
27
  this.TWILIO_API_URL = this.configService.get('TWILIO_API_URL');
28
28
  this.TWILIO_PHONE = this.configService.get('TWILIO_PHONE');
29
29
  this.TWILIO_VERIFY_SID = this.configService.get('TWILIO_VERIFY_SID');
30
+ // Security: Prevent test mode in production
30
31
  if (process.env.NODE_ENV === 'production' && process.env.TEST_MODE === 'true') {
31
32
  throw new Error('TEST_MODE cannot be enabled in production environment');
32
33
  }
33
34
  }
34
35
  async sendVerification(to, channel = 'sms') {
36
+ // Test mode: Skip Twilio API call for test phone numbers
35
37
  if (this.isTestMode() && this.isTestPhoneNumber(to)) {
36
38
  logger_1.logger.log(`[TEST MODE] Skipping OTP send for test number: ${to}`);
37
- return { status: 'pending', to: `+1${to}` };
39
+ return { status: 'pending', to: `+1${to}` }; // Mock success response
38
40
  }
39
- const dialPrefix = '+1';
41
+ const dialPrefix = '+1'; // assume US numbers only
40
42
  const toPhone = dialPrefix + to;
41
43
  const url = `https://verify.twilio.com/v2/Services/${this.TWILIO_VERIFY_SID}/Verifications`;
42
44
  const params = new URLSearchParams();
@@ -62,8 +64,19 @@ let TwilioService = class TwilioService {
62
64
  throw new Error(`Failed to send verification: ${error.message}`);
63
65
  }
64
66
  }
67
+ /**
68
+ * Checks a verification code with Twilio.
69
+ * @param to The normalized phone number the code was sent to
70
+ * @param code The code the caller supplied
71
+ * @returns Whether Twilio approved the code, and the status it reported
72
+ * @throws If Twilio cannot be reached or answers with a non-ok status —
73
+ * including the 404 it returns once a verification has expired, been
74
+ * approved already, or hit its check limit
75
+ */
65
76
  async checkVerification(to, code) {
77
+ // Test mode: Accept any 6-digit code for test phone numbers
66
78
  if (this.isTestMode() && this.isTestPhoneNumber(to)) {
79
+ // Validate code format (must be 6 digits)
67
80
  if (code.length === 6 && /^\d{6}$/.test(code)) {
68
81
  logger_1.logger.log(`[TEST MODE] Accepting test code for: ${to}`);
69
82
  return { approved: true, status: 'approved' };
@@ -71,7 +84,7 @@ let TwilioService = class TwilioService {
71
84
  logger_1.logger.log(`[TEST MODE] Rejecting invalid test code format for: ${to}`);
72
85
  return { approved: false, status: 'pending' };
73
86
  }
74
- const dialPrefix = '+1';
87
+ const dialPrefix = '+1'; // assume US numbers only
75
88
  const toPhone = dialPrefix + to;
76
89
  const url = `https://verify.twilio.com/v2/Services/${this.TWILIO_VERIFY_SID}/VerificationCheck`;
77
90
  const params = new URLSearchParams();
@@ -93,14 +106,18 @@ let TwilioService = class TwilioService {
93
106
  }
94
107
  const body = (await response.json());
95
108
  const status = body?.status ?? 'unknown';
109
+ // Approval is read off `status` rather than the legacy `valid` flag,
110
+ // which Twilio's own documentation says to prefer. An unrecognised
111
+ // status therefore fails closed.
96
112
  return { approved: status === 'approved', status };
97
113
  }
98
114
  catch (error) {
99
115
  throw new Error(`Failed to check verification: ${error.message}`);
100
116
  }
101
117
  }
118
+ // Keep the old sendSms method for backward compatibility if needed elsewhere
102
119
  async sendSms(to, body) {
103
- const dialPrefix = '+1';
120
+ const dialPrefix = '+1'; // assume US numbers only
104
121
  const toPhone = dialPrefix + to;
105
122
  const url = `${this.TWILIO_API_URL}/${this.TWILIO_ACCOUNT_SID}/Messages.json`;
106
123
  const params = new URLSearchParams();
@@ -127,10 +144,19 @@ let TwilioService = class TwilioService {
127
144
  throw new Error(`Failed to send SMS: ${error.message}`);
128
145
  }
129
146
  }
147
+ /**
148
+ * Check if test mode is enabled
149
+ * Test mode allows bypassing Twilio for testing purposes
150
+ */
130
151
  isTestMode() {
131
152
  return process.env.TEST_MODE === 'true' || process.env.NODE_ENV === 'test';
132
153
  }
154
+ /**
155
+ * Check if a phone number is a test phone number
156
+ * Test phone numbers use the 555 prefix (reserved for testing)
157
+ */
133
158
  isTestPhoneNumber(phoneNumber) {
159
+ // Normalize phone number (remove +1 prefix if present)
134
160
  const normalized = phoneNumber.replace(/^\+1/, '');
135
161
  return normalized.startsWith('555');
136
162
  }
@@ -13,12 +13,42 @@ export declare class UsersService implements OnModuleInit {
13
13
  private readonly dataDir;
14
14
  constructor();
15
15
  onModuleInit(): void;
16
+ /**
17
+ * Load users from the JSON file
18
+ */
16
19
  loadUsers(): UsersData;
20
+ /**
21
+ * Save users to the JSON file
22
+ */
17
23
  saveUsers(users: UsersData): void;
24
+ /**
25
+ * Generate a new UUID v4 for a user
26
+ * @returns A new UUID v4 string
27
+ */
18
28
  generateUserId(): string;
29
+ /**
30
+ * Create a new user with phone number
31
+ * @param phoneNumber The phone number (normalized 10 digits)
32
+ * @returns The userId if user was created, null if phone is duplicate
33
+ */
19
34
  createUser(phoneNumber: string): string | null;
35
+ /**
36
+ * Find a user by userId
37
+ * @param userId The userId
38
+ * @returns The user object if found, null otherwise
39
+ */
20
40
  findUser(userId: string): User | null;
41
+ /**
42
+ * Delete a user account and associated data
43
+ * @param userId The userId to delete
44
+ * @returns Object with success status and message
45
+ */
21
46
  deleteUser(userId: string): void;
47
+ /**
48
+ * Find a user by phone number
49
+ * @param phoneNumber The phone number (normalized 10 digits)
50
+ * @returns The user object if found, null otherwise
51
+ */
22
52
  findUserByPhone(phoneNumber: string): User | null;
23
53
  }
24
54
  export {};
@@ -58,48 +58,77 @@ let UsersService = class UsersService {
58
58
  this.usersFilePath = path.resolve(usersDir, 'users.json');
59
59
  }
60
60
  onModuleInit() {
61
+ // Ensure users directory exists
61
62
  const usersDir = path.dirname(this.usersFilePath);
62
63
  if (!fs.existsSync(usersDir)) {
63
64
  fs.mkdirSync(usersDir, { recursive: true });
64
65
  }
66
+ // Ensure users.json exists
65
67
  if (!fs.existsSync(this.usersFilePath)) {
66
68
  fs.writeFileSync(this.usersFilePath, JSON.stringify({}), 'utf-8');
67
69
  }
70
+ // Note: No default admin user creation - all users register with phone/OTP
68
71
  logger_1.logger.log('UsersService initialized with phone/OTP authentication');
69
72
  }
73
+ /**
74
+ * Load users from the JSON file
75
+ */
70
76
  loadUsers() {
71
77
  try {
72
78
  const data = fs.readFileSync(this.usersFilePath, 'utf-8');
73
79
  return JSON.parse(data);
80
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
74
81
  }
75
82
  catch (_error) {
76
83
  return {};
77
84
  }
78
85
  }
86
+ /**
87
+ * Save users to the JSON file
88
+ */
79
89
  saveUsers(users) {
80
90
  fs.writeFileSync(this.usersFilePath, JSON.stringify(users, null, 2), 'utf-8');
81
91
  }
92
+ /**
93
+ * Generate a new UUID v4 for a user
94
+ * @returns A new UUID v4 string
95
+ */
82
96
  generateUserId() {
83
97
  return (0, crypto_1.randomUUID)();
84
98
  }
99
+ /**
100
+ * Create a new user with phone number
101
+ * @param phoneNumber The phone number (normalized 10 digits)
102
+ * @returns The userId if user was created, null if phone is duplicate
103
+ */
85
104
  createUser(phoneNumber) {
86
105
  const users = this.loadUsers();
106
+ // Check if phone number already exists
87
107
  if (this.findUserByPhone(phoneNumber)) {
88
108
  return null;
89
109
  }
110
+ // Generate new userId
90
111
  const userId = this.generateUserId();
112
+ // Add user to the data
91
113
  users[userId] = {
92
114
  phoneNumber,
93
115
  phoneVerified: true,
94
116
  createdAt: new Date().toISOString(),
95
117
  };
118
+ // Create user directory
96
119
  const userDir = path.resolve(this.dataDir, 'user', userId);
97
120
  if (!fs.existsSync(userDir)) {
98
121
  fs.mkdirSync(userDir, { recursive: true });
99
122
  }
123
+ // Save to file
100
124
  this.saveUsers(users);
101
125
  return userId;
102
126
  }
127
+ /**
128
+ * Find a user by userId
129
+ * @param userId The userId
130
+ * @returns The user object if found, null otherwise
131
+ */
103
132
  findUser(userId) {
104
133
  const users = this.loadUsers();
105
134
  const userData = users[userId];
@@ -111,13 +140,21 @@ let UsersService = class UsersService {
111
140
  ...userData,
112
141
  };
113
142
  }
143
+ /**
144
+ * Delete a user account and associated data
145
+ * @param userId The userId to delete
146
+ * @returns Object with success status and message
147
+ */
114
148
  deleteUser(userId) {
149
+ // Load users and check existence (idempotent)
115
150
  const users = this.loadUsers();
116
151
  if (!users[userId]) {
117
152
  return;
118
153
  }
154
+ // Remove from users.json
119
155
  delete users[userId];
120
156
  this.saveUsers(users);
157
+ // Delete user directory (best effort)
121
158
  try {
122
159
  const userDir = path.resolve(this.dataDir, 'user', userId);
123
160
  if (fs.existsSync(userDir)) {
@@ -130,6 +167,11 @@ let UsersService = class UsersService {
130
167
  }
131
168
  logger_1.logger.log(`User ${userId} deleted successfully`);
132
169
  }
170
+ /**
171
+ * Find a user by phone number
172
+ * @param phoneNumber The phone number (normalized 10 digits)
173
+ * @returns The user object if found, null otherwise
174
+ */
133
175
  findUserByPhone(phoneNumber) {
134
176
  const users = this.loadUsers();
135
177
  for (const [userId, userData] of Object.entries(users)) {
@@ -1,12 +1,32 @@
1
+ /**
2
+ * Custom error classes for semantic error handling in the application.
3
+ * These errors are thrown by service layer and mapped to HTTP exceptions in controllers.
4
+ */
5
+ /**
6
+ * Thrown when a requested resource (agent, room, story, etc.) is not found.
7
+ * Maps to HTTP 404 Not Found in controllers.
8
+ */
1
9
  export declare class NotFoundError extends Error {
2
10
  constructor(message: string);
3
11
  }
12
+ /**
13
+ * Thrown when input validation fails or invalid data is provided.
14
+ * Maps to HTTP 400 Bad Request in controllers.
15
+ */
4
16
  export declare class ValidationError extends Error {
5
17
  constructor(message: string);
6
18
  }
19
+ /**
20
+ * Thrown when an operation fails due to system/IO errors.
21
+ * Maps to HTTP 500 Internal Server Error in controllers.
22
+ */
7
23
  export declare class OperationFailedError extends Error {
8
24
  constructor(message: string);
9
25
  }
26
+ /**
27
+ * Thrown when user has insufficient balance to perform an AI operation.
28
+ * This error should propagate to the client to trigger a credit purchase flow.
29
+ */
10
30
  export declare class InsufficientBalanceError extends Error {
11
31
  constructor(message: string);
12
32
  }
@@ -1,16 +1,29 @@
1
1
  "use strict";
2
+ /**
3
+ * Custom error classes for semantic error handling in the application.
4
+ * These errors are thrown by service layer and mapped to HTTP exceptions in controllers.
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.InsufficientBalanceError = exports.OperationFailedError = exports.ValidationError = exports.NotFoundError = void 0;
8
+ /**
9
+ * Thrown when a requested resource (agent, room, story, etc.) is not found.
10
+ * Maps to HTTP 404 Not Found in controllers.
11
+ */
4
12
  class NotFoundError extends Error {
5
13
  constructor(message) {
6
14
  super(message);
7
15
  this.name = 'NotFoundError';
16
+ // Maintains proper stack trace for where our error was thrown (V8 only)
8
17
  if (Error.captureStackTrace) {
9
18
  Error.captureStackTrace(this, NotFoundError);
10
19
  }
11
20
  }
12
21
  }
13
22
  exports.NotFoundError = NotFoundError;
23
+ /**
24
+ * Thrown when input validation fails or invalid data is provided.
25
+ * Maps to HTTP 400 Bad Request in controllers.
26
+ */
14
27
  class ValidationError extends Error {
15
28
  constructor(message) {
16
29
  super(message);
@@ -21,6 +34,10 @@ class ValidationError extends Error {
21
34
  }
22
35
  }
23
36
  exports.ValidationError = ValidationError;
37
+ /**
38
+ * Thrown when an operation fails due to system/IO errors.
39
+ * Maps to HTTP 500 Internal Server Error in controllers.
40
+ */
24
41
  class OperationFailedError extends Error {
25
42
  constructor(message) {
26
43
  super(message);
@@ -31,6 +48,10 @@ class OperationFailedError extends Error {
31
48
  }
32
49
  }
33
50
  exports.OperationFailedError = OperationFailedError;
51
+ /**
52
+ * Thrown when user has insufficient balance to perform an AI operation.
53
+ * This error should propagate to the client to trigger a credit purchase flow.
54
+ */
34
55
  class InsufficientBalanceError extends Error {
35
56
  constructor(message) {
36
57
  super(message);
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Minimal interface for environment-variable configuration access.
3
+ *
4
+ * Implemented by both NestJS `ConfigService` (from `@nestjs/config`) and
5
+ * `BriyahConfigService` so consumers can read env-derived settings without
6
+ * coupling to either implementation.
7
+ */
1
8
  export interface IConfigService {
2
9
  get<T = string>(key: string, defaultValue?: T): T;
3
10
  }