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
@@ -47,6 +47,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
47
47
  var AppController_1;
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
49
  exports.AppController = void 0;
50
+ /// <reference types="multer" />
50
51
  const common_1 = require("@nestjs/common");
51
52
  const platform_express_1 = require("@nestjs/platform-express");
52
53
  const rxjs_1 = require("rxjs");
@@ -60,12 +61,33 @@ const published_rooms_service_1 = require("./room/published-rooms.service");
60
61
  const errors_1 = require("./common/errors");
61
62
  const path = __importStar(require("path"));
62
63
  const logger_1 = require("./common/logger");
64
+ /**
65
+ * How large an uploaded PDF may be, in bytes.
66
+ *
67
+ * Configurable because the ceiling is a judgement about this deployment rather
68
+ * than a property of the format: a scanned book is legitimately hundreds of
69
+ * megabytes. Raise it together with `PDF_CONVERT_CONCURRENCY` — the risk in a
70
+ * large document is not the upload but the conversion behind it, which holds the
71
+ * buffer, a parsed copy, and one extracted page per in-flight conversion in memory
72
+ * at once.
73
+ */
63
74
  const MAX_PDF_UPLOAD_BYTES = Math.max(1, Number(process.env.MAX_PDF_UPLOAD_MB) || 50) * 1024 * 1024;
75
+ /** How large uploaded or pasted Markdown may be, in bytes. */
64
76
  const MAX_MARKDOWN_BYTES = Math.max(1, Number(process.env.MAX_MARKDOWN_UPLOAD_MB) || 10) * 1024 * 1024;
77
+ /** For an error message: bytes as whole megabytes. */
65
78
  function asMegabytes(bytes) {
66
79
  return `${Math.round(bytes / (1024 * 1024))}MB`;
67
80
  }
81
+ /**
82
+ * Multer's own ceiling, applied to every upload route that takes a document.
83
+ *
84
+ * Set to the largest thing any of them accepts, so the per-route check below is
85
+ * what produces the specific message. Its job is to abort the *stream*: multer
86
+ * buffers in memory, so without this the whole file is resident before any handler
87
+ * runs and the check saves nothing. Nest maps `LIMIT_FILE_SIZE` to a 413.
88
+ */
68
89
  const UPLOAD_LIMITS = { limits: { fileSize: Math.max(MAX_PDF_UPLOAD_BYTES, MAX_MARKDOWN_BYTES) } };
90
+ /** Strips a pack down to what a listing needs, leaving its templates behind. */
69
91
  function toPackSummary(pack) {
70
92
  return {
71
93
  pack: pack.name,
@@ -93,24 +115,45 @@ let AppController = AppController_1 = class AppController {
93
115
  this.publishedAgentsService = publishedAgentsService;
94
116
  this.publishedRoomsService = publishedRoomsService;
95
117
  }
118
+ /**
119
+ * Helper method to get the user-specific AppService from the request
120
+ * @param req The Express request object (with authenticated user)
121
+ * @param agentId Optional agent ID for fallback lookup
122
+ * @param roomId Optional room ID for fallback lookup
123
+ * @returns The AppService instance for the authenticated user, agent owner, or room owner
124
+ */
96
125
  getAppService(req, agentId, roomId) {
97
126
  let userId;
98
127
  const authSource = req.user?.authSource;
128
+ // Primary: Get userId from JWT's sub field (works for user, agent-access, and room-access tokens)
99
129
  if (req.user && req.user.sub) {
100
130
  userId = req.user.sub;
101
- }
131
+ // Log header-based access for monitoring
132
+ // if (authSource === 'header') {
133
+ // logger.log(
134
+ // `[AUTH] Header-based access: userId=${userId}, agentId=${agentId}, roomId=${roomId}`,
135
+ // );
136
+ // } else if (authSource === 'sse-url') {
137
+ // logger.log(
138
+ // `[AUTH] SSE URL-based access: userId=${userId}, agentId=${agentId}, roomId=${roomId}`,
139
+ // );
140
+ // }
141
+ }
142
+ // Fallback: Agent-owned resources
102
143
  else if (agentId) {
103
144
  userId = this.publishedAgentsService.getUserId(agentId);
104
145
  if (!userId) {
105
146
  throw new common_1.NotFoundException(`Agent ${agentId} is not published or does not exist`);
106
147
  }
107
148
  }
149
+ // Fallback: Room-owned resources
108
150
  else if (roomId) {
109
151
  userId = this.publishedRoomsService.getUserId(roomId);
110
152
  if (!userId) {
111
153
  throw new common_1.NotFoundException(`Room ${roomId} is not published or does not exist`);
112
154
  }
113
155
  }
156
+ // Last resort fallback
114
157
  else if (req.user && req.user.username) {
115
158
  userId = req.user.username;
116
159
  }
@@ -153,6 +196,11 @@ let AppController = AppController_1 = class AppController {
153
196
  async listStoryModelDefaults(req) {
154
197
  const appService = this.getAppService(req);
155
198
  const imageModels = await appService.listImageModels();
199
+ // Resolve the configured default image-model name against the actual
200
+ // image_models.json options. The dialog's <select> only shows a default
201
+ // when the value exactly matches an option name, so we canonicalize
202
+ // case-insensitively and fall back to the first model when the env value
203
+ // is missing or doesn't match.
156
204
  const resolveImageDefault = (envName) => {
157
205
  const exact = imageModels.find((m) => m.name === envName);
158
206
  if (exact)
@@ -171,12 +219,15 @@ let AppController = AppController_1 = class AppController {
171
219
  };
172
220
  }
173
221
  async createAgent(req, body) {
222
+ // Validate required fields
174
223
  if (!body.aiServiceName || !body.aiModel || !body.agentName) {
175
224
  throw new common_1.BadRequestException('AI service name, AI Model, and agent name are required');
176
225
  }
226
+ // Validate non-empty after trimming
177
227
  if (!body.agentName?.trim()) {
178
228
  throw new common_1.BadRequestException('Agent name cannot be empty');
179
229
  }
230
+ // Validate length limits
180
231
  if (body.agentName.length > 200) {
181
232
  throw new common_1.BadRequestException('Agent name too long');
182
233
  }
@@ -205,6 +256,7 @@ let AppController = AppController_1 = class AppController {
205
256
  }
206
257
  try {
207
258
  const appService = this.getAppService(req, agentId);
259
+ // Verify published for agent-access tokens
208
260
  if (req.user.type === 'agent-access') {
209
261
  const agentDetails = await appService.getAgentDetails(agentId);
210
262
  if (!agentDetails || !agentDetails.isPublished) {
@@ -214,10 +266,12 @@ let AppController = AppController_1 = class AppController {
214
266
  return await appService.processText(agentId, body.text);
215
267
  }
216
268
  catch (error) {
269
+ // Re-throw HTTP exceptions as-is (except NotFoundError which we handle specially)
217
270
  if (error instanceof common_1.ForbiddenException || error instanceof common_1.BadRequestException) {
218
271
  throw error;
219
272
  }
220
273
  logger_1.logger.error(`[${req.user?.sub}] Error processing text for agent ${agentId}:`, error);
274
+ // For NotFoundError, return error message in result field with 201 status
221
275
  if (error instanceof errors_1.NotFoundError) {
222
276
  return {
223
277
  result: `Error: ${error.message}`,
@@ -239,13 +293,16 @@ let AppController = AppController_1 = class AppController {
239
293
  throw new common_1.HttpException(`File too large (max ${asMegabytes(MAX_PDF_UPLOAD_BYTES)})`, common_1.HttpStatus.PAYLOAD_TOO_LARGE);
240
294
  }
241
295
  const appService = this.getAppService(req);
296
+ // Use original filename or default
242
297
  let fileName = file?.originalname || 'attach_file';
243
298
  if (body.fileName && body.fileName !== '') {
244
299
  fileName = body.fileName;
245
300
  }
301
+ // Sanitize filename to prevent path traversal
246
302
  fileName = path.basename(fileName).replace(/[^a-zA-Z0-9._-]/g, '_');
247
303
  try {
248
304
  const result = await appService.attachDocument(agentId, fileName, file.buffer);
305
+ // Return both documentId and filename
249
306
  return {
250
307
  ...result,
251
308
  filename: fileName,
@@ -272,6 +329,7 @@ let AppController = AppController_1 = class AppController {
272
329
  return { files: [] };
273
330
  }
274
331
  }
332
+ // New RESTful prompt endpoints
275
333
  getPrompts(req, scope) {
276
334
  try {
277
335
  const appService = this.getAppService(req);
@@ -337,6 +395,9 @@ let AppController = AppController_1 = class AppController {
337
395
  }
338
396
  catch (error) {
339
397
  logger_1.logger.error(`[${req.user?.sub}] Error reading defaults for prompt folder ${folderName}:`, error);
398
+ // Defaults only pre-fill a form; a folder with none must still be selectable.
399
+ // `exists: false` because the read failed — the dialog should not claim a
400
+ // folder it could not look at is there.
340
401
  return { defaults: {}, exists: false };
341
402
  }
342
403
  }
@@ -416,6 +477,7 @@ let AppController = AppController_1 = class AppController {
416
477
  throw new common_1.HttpException('Failed to delete prompt file', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
417
478
  }
418
479
  }
480
+ // === TOOL ENDPOINTS — user-defined tools agents can EXECUTE ===
419
481
  async getTools(req) {
420
482
  try {
421
483
  const appService = this.getAppService(req);
@@ -482,6 +544,7 @@ let AppController = AppController_1 = class AppController {
482
544
  }
483
545
  }
484
546
  async testTool(req, name, body) {
547
+ // Tool failures are returned in-band ({ok:false,error}) so the UI can render them
485
548
  try {
486
549
  const appService = this.getAppService(req);
487
550
  return await appService.testTool(name, body?.args || {});
@@ -491,6 +554,11 @@ let AppController = AppController_1 = class AppController {
491
554
  return { ok: false, error: error.message || 'Tool test failed' };
492
555
  }
493
556
  }
557
+ // === PACK ENDPOINTS — a domain's prompts, documents, tools, agents and rooms ===
558
+ //
559
+ // A pack is installed for everyone (the host copies a directory into
560
+ // <data>/packs) and enabled per user. Enabling controls what a user is shown
561
+ // and may grant; it does not switch anything already configured off.
494
562
  getPacks(req) {
495
563
  try {
496
564
  const appService = this.getAppService(req);
@@ -614,6 +682,11 @@ let AppController = AppController_1 = class AppController {
614
682
  throw new common_1.HttpException(error.message || 'Failed to build the agent', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
615
683
  }
616
684
  }
685
+ // RPG endpoints
686
+ //
687
+ // A campaign is an ordinary room, so everything but creating and reading one goes
688
+ // through the room routes: DELETE rooms/:roomId removes a campaign and cascades to
689
+ // its published instance, and the party plays through the published-room routes.
617
690
  listRpgModels(req) {
618
691
  try {
619
692
  return this.getAppService(req).rpg.listModels();
@@ -662,6 +735,10 @@ let AppController = AppController_1 = class AppController {
662
735
  throw new common_1.HttpException(error.message || 'Failed to create the campaign', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
663
736
  }
664
737
  }
738
+ /**
739
+ * Gives a campaign a public link again, for one whose instance was deleted by hand.
740
+ * Creation publishes, so this is the repair path rather than the normal one.
741
+ */
665
742
  async republishRpgCampaign(req, campaignId) {
666
743
  try {
667
744
  return await this.getAppService(req).rpg.republishCampaign(campaignId);
@@ -677,6 +754,7 @@ let AppController = AppController_1 = class AppController {
677
754
  throw new common_1.HttpException(error.message || 'Failed to publish the campaign', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
678
755
  }
679
756
  }
757
+ // Deprecated - kept for backwards compatibility
680
758
  listPromptFolders(req) {
681
759
  try {
682
760
  const appService = this.getAppService(req);
@@ -722,9 +800,13 @@ let AppController = AppController_1 = class AppController {
722
800
  async listAgents(req, published, includeRoomAgents) {
723
801
  try {
724
802
  const appService = this.getAppService(req);
803
+ // Support ?published=true query parameter
725
804
  if (published === 'true') {
726
805
  return await appService.listPublishedAgents();
727
806
  }
807
+ // ?includeRoomAgents=true adds the agents that belong to a room, which
808
+ // the room dialog offers as something to copy. They are excluded by
809
+ // default: the agent list a user manages holds only unowned agents.
728
810
  return await appService.listAgents(includeRoomAgents === 'true');
729
811
  }
730
812
  catch (error) {
@@ -732,6 +814,20 @@ let AppController = AppController_1 = class AppController {
732
814
  return [];
733
815
  }
734
816
  }
817
+ /**
818
+ * Validates a request's turnMode so an unrecognized value is a 400 rather
819
+ * than silently becoming 'broadcast'.
820
+ * @param value The raw turnMode from the request body
821
+ * @returns The turn mode, or undefined when the field was omitted
822
+ */
823
+ /**
824
+ * Reads the models an instantiate request supplies.
825
+ *
826
+ * A pack's template names a *role* (`primary` or `economy`), never a model, so
827
+ * the caller has to say what each role means on this deployment. `economy`
828
+ * falls back to `primary` rather than erroring: a caller that offers only one
829
+ * model gets a working room, just not a cheap one.
830
+ */
735
831
  static parseInstantiateModels(body) {
736
832
  if (!body?.aiServiceName || !body?.aiModel) {
737
833
  throw new common_1.BadRequestException('aiServiceName and aiModel are required');
@@ -762,12 +858,16 @@ let AppController = AppController_1 = class AppController {
762
858
  return value;
763
859
  }
764
860
  async createRoom(req, body) {
861
+ // Validate required fields. A room may start empty: the agents that belong
862
+ // to it are created through POST rooms/:roomId/agents once it exists.
765
863
  if (!body.roomName) {
766
864
  throw new common_1.BadRequestException('Room name is required');
767
865
  }
866
+ // Validate non-empty after trimming
768
867
  if (!body.roomName?.trim()) {
769
868
  throw new common_1.BadRequestException('Room name cannot be empty');
770
869
  }
870
+ // Validate length limits
771
871
  if (body.roomName.length > 200) {
772
872
  throw new common_1.BadRequestException('Room name too long');
773
873
  }
@@ -781,6 +881,7 @@ let AppController = AppController_1 = class AppController {
781
881
  if (error instanceof errors_1.ValidationError) {
782
882
  throw new common_1.BadRequestException(error.message);
783
883
  }
884
+ // Return 500 for any errors during room creation (including NotFoundError)
784
885
  throw new common_1.HttpException(error.message || 'Failed to create room', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
785
886
  }
786
887
  }
@@ -801,6 +902,13 @@ let AppController = AppController_1 = class AppController {
801
902
  throw new common_1.HttpException('Failed to edit room', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
802
903
  }
803
904
  }
905
+ /**
906
+ * Creates an agent that belongs to this room and adds it to it.
907
+ *
908
+ * The only way an agent joins a room. `agentName` is the bare name — the room's
909
+ * name is prefixed onto it server-side, so the client never has to assemble it
910
+ * (and cannot end up prefixing it twice).
911
+ */
804
912
  async createRoomAgent(req, roomId, body) {
805
913
  if (!body.aiServiceName || !body.aiModel || !body.agentName?.trim()) {
806
914
  throw new common_1.BadRequestException('AI service name, AI Model, and agent name are required');
@@ -823,6 +931,9 @@ let AppController = AppController_1 = class AppController {
823
931
  throw new common_1.HttpException('Failed to add agent to room', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
824
932
  }
825
933
  }
934
+ /**
935
+ * Removes an agent from a room, deleting it when the room owns it.
936
+ */
826
937
  async removeRoomAgent(req, roomId, agentId) {
827
938
  try {
828
939
  const appService = this.getAppService(req);
@@ -842,6 +953,8 @@ let AppController = AppController_1 = class AppController {
842
953
  async listRooms(req, published) {
843
954
  try {
844
955
  const appService = this.getAppService(req);
956
+ // ?published=true returns the published instances instead, which the
957
+ // default listing excludes. Mirrors GET /api/agents?published=true.
845
958
  if (published === 'true') {
846
959
  return await appService.listPublishedRooms();
847
960
  }
@@ -876,6 +989,7 @@ let AppController = AppController_1 = class AppController {
876
989
  if (!agentDetails) {
877
990
  throw new common_1.NotFoundException('Agent not found');
878
991
  }
992
+ // Verify published for agent-access tokens
879
993
  if (req.user.type === 'agent-access' && !agentDetails.isPublished) {
880
994
  throw new common_1.ForbiddenException('Agent is not published');
881
995
  }
@@ -904,6 +1018,7 @@ let AppController = AppController_1 = class AppController {
904
1018
  async getAgentMessages(req, agentId, fromIndex) {
905
1019
  try {
906
1020
  const appService = this.getAppService(req, agentId);
1021
+ // Verify published for agent-access tokens
907
1022
  if (req.user.type === 'agent-access') {
908
1023
  const agentDetails = await appService.getAgentDetails(agentId);
909
1024
  if (!agentDetails || !agentDetails.isPublished) {
@@ -1031,6 +1146,7 @@ let AppController = AppController_1 = class AppController {
1031
1146
  }
1032
1147
  }
1033
1148
  async sendRoomMessage(req, roomId, body) {
1149
+ // Validate message content
1034
1150
  if (!body.content?.trim()) {
1035
1151
  throw new common_1.BadRequestException('Message content cannot be empty');
1036
1152
  }
@@ -1039,6 +1155,9 @@ let AppController = AppController_1 = class AppController {
1039
1155
  }
1040
1156
  try {
1041
1157
  const appService = this.getAppService(req, undefined, roomId);
1158
+ // Returned rather than discarded: a human's message is rejected when it
1159
+ // is not their turn, and the client needs to say so instead of appearing
1160
+ // to have sent it.
1042
1161
  return await appService.sendRoomMessage(roomId, body.content, body.sender, body.action, body.targets, body.clearQueue || false);
1043
1162
  }
1044
1163
  catch (error) {
@@ -1090,7 +1209,7 @@ let AppController = AppController_1 = class AppController {
1090
1209
  }
1091
1210
  catch (error) {
1092
1211
  logger_1.logger.error(`[${req.user?.sub}] Error getting user preferences:`, error);
1093
- return {};
1212
+ return {}; // Return empty preferences on error
1094
1213
  }
1095
1214
  }
1096
1215
  async saveUserPreferences(req, preferences) {
@@ -1106,6 +1225,7 @@ let AppController = AppController_1 = class AppController {
1106
1225
  throw new common_1.HttpException('Failed to save user preferences', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1107
1226
  }
1108
1227
  }
1228
+ // Deprecated - kept for backwards compatibility
1109
1229
  async listPromptFilesDeprecated(req, folderName) {
1110
1230
  try {
1111
1231
  const appService = this.getAppService(req);
@@ -1116,6 +1236,7 @@ let AppController = AppController_1 = class AppController {
1116
1236
  return { files: [] };
1117
1237
  }
1118
1238
  }
1239
+ // Deprecated - kept for backwards compatibility
1119
1240
  async getPromptFileDeprecated(req, folderName, fileName) {
1120
1241
  try {
1121
1242
  const appService = this.getAppService(req);
@@ -1126,6 +1247,7 @@ let AppController = AppController_1 = class AppController {
1126
1247
  return { content: '' };
1127
1248
  }
1128
1249
  }
1250
+ // Deprecated - kept for backwards compatibility
1129
1251
  async savePromptFileDeprecated(req, body) {
1130
1252
  try {
1131
1253
  const appService = this.getAppService(req);
@@ -1142,6 +1264,7 @@ let AppController = AppController_1 = class AppController {
1142
1264
  throw new common_1.HttpException('Failed to save prompt file', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1143
1265
  }
1144
1266
  }
1267
+ // Deprecated - kept for backwards compatibility
1145
1268
  async deletePromptFileDeprecated(req, body) {
1146
1269
  try {
1147
1270
  const appService = this.getAppService(req);
@@ -1158,6 +1281,7 @@ let AppController = AppController_1 = class AppController {
1158
1281
  throw new common_1.HttpException('Failed to delete prompt file', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1159
1282
  }
1160
1283
  }
1284
+ // Deprecated - kept for backwards compatibility
1161
1285
  async deletePromptFolderDeprecated(req, body) {
1162
1286
  try {
1163
1287
  const appService = this.getAppService(req);
@@ -1174,6 +1298,9 @@ let AppController = AppController_1 = class AppController {
1174
1298
  throw new common_1.HttpException('Failed to delete prompt folder', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1175
1299
  }
1176
1300
  }
1301
+ // Owner-only, unlike the other agent mutations: rewriting an agent's model,
1302
+ // instructions or nickname is configuration, not use, and a published agent's
1303
+ // visitors hold a token that would otherwise reach it.
1177
1304
  async updateAgent(req, agentId, updateData) {
1178
1305
  try {
1179
1306
  const appService = this.getAppService(req);
@@ -1221,6 +1348,7 @@ let AppController = AppController_1 = class AppController {
1221
1348
  }
1222
1349
  try {
1223
1350
  const appService = this.getAppService(req, agentId);
1351
+ // Verify published for agent-access tokens
1224
1352
  if (req.user.type === 'agent-access') {
1225
1353
  const agentDetails = await appService.getAgentDetails(agentId);
1226
1354
  if (!agentDetails || !agentDetails.isPublished) {
@@ -1271,6 +1399,9 @@ let AppController = AppController_1 = class AppController {
1271
1399
  throw new common_1.HttpException('Failed to compact agent conversation', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1272
1400
  }
1273
1401
  }
1402
+ // Reachable from a public room page, so it is scope-guarded: without
1403
+ // @RoomAccess a room-access header for one published room could reset any
1404
+ // other room belonging to that room's owner.
1274
1405
  async resetRoom(req, roomId) {
1275
1406
  if (!roomId) {
1276
1407
  throw new common_1.BadRequestException('Room ID is required');
@@ -1376,7 +1507,7 @@ let AppController = AppController_1 = class AppController {
1376
1507
  }
1377
1508
  catch (error) {
1378
1509
  logger_1.logger.error(`[${req.user?.sub}] Error getting room artifacts for ${roomId}:`, error);
1379
- return { artifacts: [] };
1510
+ return { artifacts: [] }; // Return empty artifacts on error
1380
1511
  }
1381
1512
  }
1382
1513
  async publishArtifact(req, roomId, body) {
@@ -1398,6 +1529,7 @@ let AppController = AppController_1 = class AppController {
1398
1529
  throw new common_1.HttpException('Failed to publish artifact', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1399
1530
  }
1400
1531
  }
1532
+ // Deprecated - kept for backwards compatibility
1401
1533
  async createPromptFolderDeprecated(req, body) {
1402
1534
  if (!body.folderName) {
1403
1535
  throw new common_1.BadRequestException('Folder name is required');
@@ -1421,9 +1553,13 @@ let AppController = AppController_1 = class AppController {
1421
1553
  }
1422
1554
  catch (error) {
1423
1555
  logger_1.logger.error(`[${req.user?.sub}] Error listing stories:`, error);
1424
- return [];
1556
+ return []; // Return empty list on error
1425
1557
  }
1426
1558
  }
1559
+ /**
1560
+ * List all available story genres
1561
+ * GET /api/stories/genres
1562
+ */
1427
1563
  listStoryGenres(req) {
1428
1564
  try {
1429
1565
  const appService = this.getAppService(req);
@@ -1434,6 +1570,10 @@ let AppController = AppController_1 = class AppController {
1434
1570
  return [];
1435
1571
  }
1436
1572
  }
1573
+ /**
1574
+ * Get a random story idea from any random genre
1575
+ * GET /api/stories/genres/random
1576
+ */
1437
1577
  async getRandomStoryIdea(req) {
1438
1578
  try {
1439
1579
  const appService = this.getAppService(req);
@@ -1444,6 +1584,10 @@ let AppController = AppController_1 = class AppController {
1444
1584
  throw new common_1.HttpException('Failed to get random story idea', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1445
1585
  }
1446
1586
  }
1587
+ /**
1588
+ * Get a random story idea from a specific genre
1589
+ * GET /api/stories/genres/:genreName
1590
+ */
1447
1591
  async getStoryIdeasByGenre(req, genreName) {
1448
1592
  try {
1449
1593
  const appService = this.getAppService(req);
@@ -1474,6 +1618,7 @@ let AppController = AppController_1 = class AppController {
1474
1618
  if (!file) {
1475
1619
  throw new common_1.BadRequestException('No file uploaded');
1476
1620
  }
1621
+ // Validate file type
1477
1622
  const allowedMimeTypes = ['application/zip', 'application/x-zip-compressed'];
1478
1623
  if (!allowedMimeTypes.includes(file.mimetype) &&
1479
1624
  !file.originalname.toLowerCase().endsWith('.zip')) {
@@ -1487,6 +1632,7 @@ let AppController = AppController_1 = class AppController {
1487
1632
  }
1488
1633
  catch (error) {
1489
1634
  logger_1.logger.error(`[${req.user?.sub}] Error importing story from zip:`, error);
1635
+ // Return more specific error messages
1490
1636
  if (error.message.includes('Invalid story structure')) {
1491
1637
  throw new common_1.BadRequestException(error.message);
1492
1638
  }
@@ -1531,9 +1677,11 @@ let AppController = AppController_1 = class AppController {
1531
1677
  }
1532
1678
  catch (error) {
1533
1679
  logger_1.logger.error(`[${req.user?.sub}] Error compacting story ${storyId}:`, error);
1680
+ // If it's already an HTTP exception, re-throw it
1534
1681
  if (error instanceof common_1.HttpException) {
1535
1682
  throw error;
1536
1683
  }
1684
+ // Convert other errors to HTTP exceptions
1537
1685
  throw new common_1.HttpException(error.message || 'Failed to compact story', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1538
1686
  }
1539
1687
  }
@@ -1547,9 +1695,11 @@ let AppController = AppController_1 = class AppController {
1547
1695
  }
1548
1696
  catch (error) {
1549
1697
  logger_1.logger.error(`[${req.user?.sub}] Error progressing story ${storyId}:`, error);
1698
+ // If it's already an HTTP exception, re-throw it
1550
1699
  if (error instanceof common_1.HttpException) {
1551
1700
  throw error;
1552
1701
  }
1702
+ // Convert other errors to HTTP exceptions
1553
1703
  throw new common_1.HttpException(error.message || 'Failed to progress story', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1554
1704
  }
1555
1705
  }
@@ -1578,9 +1728,11 @@ let AppController = AppController_1 = class AppController {
1578
1728
  }
1579
1729
  catch (error) {
1580
1730
  logger_1.logger.error(`[${req.user?.sub}] Error responding to story ${storyId}:`, error);
1731
+ // If it's already an HTTP exception, re-throw it
1581
1732
  if (error instanceof common_1.HttpException) {
1582
1733
  throw error;
1583
1734
  }
1735
+ // Convert other errors to HTTP exceptions
1584
1736
  throw new common_1.HttpException(error.message || 'Failed to respond to story', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1585
1737
  }
1586
1738
  }
@@ -1603,7 +1755,8 @@ let AppController = AppController_1 = class AppController {
1603
1755
  }
1604
1756
  try {
1605
1757
  const appService = this.getAppService(req);
1606
- await appService.introduceCharacterToStory(storyId, body.name, body.description || '', body.storyModel, body.fromNarratorSuggestion || false);
1758
+ await appService.introduceCharacterToStory(storyId, body.name, body.description || '', // Default to empty string if not provided
1759
+ body.storyModel, body.fromNarratorSuggestion || false);
1607
1760
  }
1608
1761
  catch (error) {
1609
1762
  logger_1.logger.error(`[${req.user?.sub}] Error introducing character ${body.name} to story ${storyId}:`, error);
@@ -1653,7 +1806,7 @@ let AppController = AppController_1 = class AppController {
1653
1806
  }
1654
1807
  catch (error) {
1655
1808
  logger_1.logger.error(`[${req.user?.sub}] Error listing chapters for story ${storyId}:`, error);
1656
- return { chapters: [] };
1809
+ return { chapters: [] }; // Return empty list on error
1657
1810
  }
1658
1811
  }
1659
1812
  async getChapter(req, storyId, chapterIndex) {
@@ -1710,14 +1863,18 @@ let AppController = AppController_1 = class AppController {
1710
1863
  async exportStoryMarkdown(req, storyId, res) {
1711
1864
  try {
1712
1865
  const appService = this.getAppService(req);
1866
+ // Generate markdown content
1713
1867
  const markdown = await appService.downloadStoryMarkdown(storyId);
1868
+ // Get story name for filename
1714
1869
  const story = await appService.getStoryInfo(storyId);
1715
1870
  if (!story) {
1716
1871
  throw new common_1.NotFoundException(`Story ${storyId} not found`);
1717
1872
  }
1718
1873
  const filename = `${story.name.replace(/[^a-z0-9]/gi, '_')}.md`;
1874
+ // Set headers for file download
1719
1875
  res.setHeader('Content-Type', 'text/markdown');
1720
1876
  res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
1877
+ // Send content
1721
1878
  res.send(markdown);
1722
1879
  }
1723
1880
  catch (error) {
@@ -1728,10 +1885,14 @@ let AppController = AppController_1 = class AppController {
1728
1885
  async exportStoryZip(req, storyId, res) {
1729
1886
  try {
1730
1887
  const appService = this.getAppService(req);
1888
+ // Generate zip stream and filename
1731
1889
  const { stream, filename } = await appService.exportStoryData(storyId);
1890
+ // Set headers for zip file download
1732
1891
  res.setHeader('Content-Type', 'application/zip');
1733
1892
  res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
1893
+ // Pipe the archive stream to the response
1734
1894
  stream.pipe(res);
1895
+ // Handle stream errors
1735
1896
  stream.on('error', (err) => {
1736
1897
  logger_1.logger.error(`[${req.user?.sub}] Stream error during story zip export:`, err);
1737
1898
  if (!res.headersSent) {
@@ -1753,7 +1914,7 @@ let AppController = AppController_1 = class AppController {
1753
1914
  }
1754
1915
  catch (error) {
1755
1916
  logger_1.logger.error(`[${req.user?.sub}] Error listing characters for story ${storyId}:`, error);
1756
- return [];
1917
+ return []; // Return empty list on error
1757
1918
  }
1758
1919
  }
1759
1920
  async getCharacter(req, storyId, characterName) {
@@ -1763,7 +1924,7 @@ let AppController = AppController_1 = class AppController {
1763
1924
  }
1764
1925
  catch (error) {
1765
1926
  logger_1.logger.error(`[${req.user?.sub}] Error getting character ${characterName} for story ${storyId}:`, error);
1766
- return { content: '' };
1927
+ return { content: '' }; // Return empty content on error
1767
1928
  }
1768
1929
  }
1769
1930
  async saveCharacter(req, storyId, characterName, body) {
@@ -1792,7 +1953,7 @@ let AppController = AppController_1 = class AppController {
1792
1953
  }
1793
1954
  catch (error) {
1794
1955
  logger_1.logger.error(`[${req.user?.sub}] Error getting inventory for character ${characterName} in story ${storyId}:`, error);
1795
- return { content: '' };
1956
+ return { content: '' }; // Return empty content on error
1796
1957
  }
1797
1958
  }
1798
1959
  async saveCharacterInventory(req, storyId, characterName, body) {
@@ -1821,7 +1982,7 @@ let AppController = AppController_1 = class AppController {
1821
1982
  }
1822
1983
  catch (error) {
1823
1984
  logger_1.logger.error(`[${req.user?.sub}] Error getting plot plan for story ${storyId}:`, error);
1824
- return { content: '' };
1985
+ return { content: '' }; // Return empty content on error
1825
1986
  }
1826
1987
  }
1827
1988
  async getAgentHistory(req, storyId, agentId) {
@@ -1831,7 +1992,7 @@ let AppController = AppController_1 = class AppController {
1831
1992
  }
1832
1993
  catch (error) {
1833
1994
  logger_1.logger.error(`[${req.user?.sub}] Error getting agent history for ${agentId} in story ${storyId}:`, error);
1834
- return { content: '' };
1995
+ return { content: '' }; // Return empty content on error
1835
1996
  }
1836
1997
  }
1837
1998
  async savePlotPlan(req, storyId, body) {
@@ -1853,6 +2014,9 @@ let AppController = AppController_1 = class AppController {
1853
2014
  throw new common_1.HttpException('Failed to save plot plan', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
1854
2015
  }
1855
2016
  }
2017
+ /**
2018
+ * List artifacts for a story
2019
+ */
1856
2020
  async listStoryArtifacts(req, storyId) {
1857
2021
  try {
1858
2022
  const appService = this.getAppService(req);
@@ -1863,21 +2027,28 @@ let AppController = AppController_1 = class AppController {
1863
2027
  return { artifacts: [] };
1864
2028
  }
1865
2029
  }
2030
+ /**
2031
+ * Get specific story artifact content
2032
+ */
1866
2033
  async getStoryArtifact(req, storyId, artifactId, res) {
1867
2034
  try {
1868
2035
  const appService = this.getAppService(req);
1869
2036
  const storyArtifactService = appService.getStoryArtifactService(storyId);
2037
+ // Get artifact metadata for MIME type
1870
2038
  const allArtifacts = storyArtifactService.listArtifacts();
1871
2039
  const artifactMetadata = allArtifacts.find((a) => a.artifactId === artifactId);
1872
2040
  if (!artifactMetadata) {
1873
2041
  throw new common_1.NotFoundException('Artifact not found');
1874
2042
  }
2043
+ // Get artifact content (string or Buffer)
1875
2044
  const content = appService.getStoryArtifact(storyId, artifactId);
1876
2045
  if (!content) {
1877
2046
  throw new common_1.NotFoundException('Artifact content not found');
1878
2047
  }
2048
+ // Set appropriate content-type
1879
2049
  const mimeType = artifactMetadata.mimeType || 'application/octet-stream';
1880
2050
  res.setHeader('Content-Type', mimeType);
2051
+ // Send content (handles both string and Buffer)
1881
2052
  res.send(content);
1882
2053
  }
1883
2054
  catch (error) {
@@ -1890,12 +2061,14 @@ let AppController = AppController_1 = class AppController {
1890
2061
  }
1891
2062
  storyProgress(req, storyId) {
1892
2063
  const appService = this.getAppService(req);
2064
+ // Validate story exists before establishing SSE connection
1893
2065
  const storyInfo = appService.listStories().find((s) => s.id === storyId);
1894
2066
  if (!storyInfo) {
1895
2067
  throw new common_1.NotFoundException(`Story ${storyId} not found`);
1896
2068
  }
1897
2069
  const emitter = appService.getStoryProgressEmitter(storyId);
1898
2070
  if (!emitter) {
2071
+ // Return an empty observable that completes immediately if no emitter exists
1899
2072
  return new rxjs_1.Observable((subscriber) => {
1900
2073
  subscriber.next({
1901
2074
  data: { step: 'error', message: 'Story progress not found' },
@@ -1909,20 +2082,27 @@ let AppController = AppController_1 = class AppController {
1909
2082
  const userId = req.user?.sub;
1910
2083
  try {
1911
2084
  const appService = this.getAppService(req);
2085
+ // Validate story exists before establishing SSE connection
1912
2086
  const storyInfo = appService.listStories().find((s) => s.id === storyId);
1913
2087
  if (!storyInfo) {
1914
2088
  logger_1.logger.log(`[SSE] Story ${storyId} not found for user ${userId}`);
1915
2089
  throw new common_1.NotFoundException(`Story ${storyId} not found`);
1916
2090
  }
2091
+ // Get or create the emitter for this story
1917
2092
  const emitter = appService.getStoryMessageEmitter(storyId);
1918
2093
  return new rxjs_1.Observable((subscriber) => {
1919
2094
  logger_1.logger.log(`[SSE] Observable subscribed for story ${storyId}`);
2095
+ // Send initial connected message to establish the stream
2096
+ // NestJS will automatically JSON.stringify the data
1920
2097
  subscriber.next({
1921
2098
  data: { type: 'connected', storyId },
1922
2099
  });
2100
+ // Replay any unacknowledged narrator suggestion so late-connecting
2101
+ // clients (tab switches, reconnects, server restarts) don't miss it
1923
2102
  if (storyInfo.pendingSuggestion) {
1924
2103
  subscriber.next({ data: storyInfo.pendingSuggestion });
1925
2104
  }
2105
+ // Listen for all story events and forward them to the SSE stream
1926
2106
  const updateHandler = (data) => {
1927
2107
  subscriber.next({ data });
1928
2108
  };
@@ -1930,6 +2110,7 @@ let AppController = AppController_1 = class AppController {
1930
2110
  emitter.on('suggest-introduce-character', updateHandler);
1931
2111
  emitter.on('suggest-progress-chapter', updateHandler);
1932
2112
  emitter.on('story-error', updateHandler);
2113
+ // Cleanup when client disconnects
1933
2114
  return () => {
1934
2115
  logger_1.logger.log(`[SSE] Cleanup for story ${storyId}`);
1935
2116
  emitter.off('story-state', updateHandler);
@@ -1945,23 +2126,30 @@ let AppController = AppController_1 = class AppController {
1945
2126
  }
1946
2127
  }
1947
2128
  async agentMessages(req, agentId) {
2129
+ // Ensure the state change callback is registered for this agent
2130
+ // This is necessary for agents loaded from disk that don't have callbacks yet
1948
2131
  const appService = this.getAppService(req, agentId);
2132
+ // Validate agent exists before establishing SSE connection
1949
2133
  const agentDetails = await appService.getAgentDetails(agentId);
1950
2134
  if (!agentDetails) {
1951
2135
  throw new common_1.NotFoundException(`Agent ${agentId} not found`);
1952
2136
  }
2137
+ // Verify published for agent-access tokens
1953
2138
  if (req.user.type === 'agent-access') {
1954
2139
  if (!agentDetails.isPublished) {
1955
2140
  throw new common_1.ForbiddenException('Agent is not published');
1956
2141
  }
1957
2142
  }
1958
2143
  appService.ensureAgentStateCallback(agentId);
2144
+ // Get or create the emitter for this agent
1959
2145
  const emitter = appService.getAgentMessageEmitter(agentId);
1960
2146
  return new rxjs_1.Observable((subscriber) => {
2147
+ // Listen for update events
1961
2148
  const updateHandler = (data) => {
1962
2149
  subscriber.next({ data });
1963
2150
  };
1964
2151
  emitter.on('update', updateHandler);
2152
+ // Cleanup when client disconnects
1965
2153
  return () => {
1966
2154
  emitter.off('update', updateHandler);
1967
2155
  };
@@ -1969,6 +2157,7 @@ let AppController = AppController_1 = class AppController {
1969
2157
  }
1970
2158
  async roomMessages(req, roomId) {
1971
2159
  const appService = this.getAppService(req, undefined, roomId);
2160
+ // Validate room exists before establishing SSE connection
1972
2161
  const roomDetails = await appService.getRoomDetails(roomId);
1973
2162
  if (!roomDetails) {
1974
2163
  throw new common_1.NotFoundException(`Room ${roomId} not found`);
@@ -1999,11 +2188,46 @@ let AppController = AppController_1 = class AppController {
1999
2188
  };
2000
2189
  });
2001
2190
  }
2191
+ /**
2192
+ * Get current user balance
2193
+ */
2002
2194
  async getBalance(req) {
2003
2195
  const appService = this.getAppService(req);
2004
2196
  const balance = await appService.getBalance();
2005
2197
  return { balance };
2006
2198
  }
2199
+ /**
2200
+ * Add funds to user balance
2201
+ */
2202
+ // @Post('add-balance')
2203
+ // async addBalance(
2204
+ // @Request() req: ExpressRequest,
2205
+ // @Body() body: { amount: number }
2206
+ // ): Promise<{ balance: number, success: boolean, message: string }> {
2207
+ // const appService = this.getAppService(req);
2208
+ //
2209
+ // // Validate amount
2210
+ // if (!body.amount || body.amount <= 0) {
2211
+ // return {
2212
+ // balance: await appService.getBalance(),
2213
+ // success: false,
2214
+ // message: 'Amount must be positive',
2215
+ // };
2216
+ // }
2217
+ //
2218
+ // await appService.addBalance(body.amount);
2219
+ // const newBalance = await appService.getBalance();
2220
+ //
2221
+ // return {
2222
+ // balance: newBalance,
2223
+ // success: true,
2224
+ // message: `Successfully added $${body.amount.toFixed(2)} to balance`,
2225
+ // };
2226
+ // }
2227
+ // ==================== Artifact Endpoints ====================
2228
+ /**
2229
+ * List all artifacts for the user
2230
+ */
2007
2231
  async listArtifacts(req) {
2008
2232
  try {
2009
2233
  const appService = this.getAppService(req);
@@ -2014,6 +2238,9 @@ let AppController = AppController_1 = class AppController {
2014
2238
  return { artifacts: [] };
2015
2239
  }
2016
2240
  }
2241
+ /**
2242
+ * Get specific artifact content
2243
+ */
2017
2244
  async getArtifact(req, artifactId) {
2018
2245
  try {
2019
2246
  const appService = this.getAppService(req);
@@ -2031,13 +2258,22 @@ let AppController = AppController_1 = class AppController {
2031
2258
  throw new common_1.HttpException('Failed to get artifact', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
2032
2259
  }
2033
2260
  }
2261
+ /**
2262
+ * Create new artifact (upload)
2263
+ */
2034
2264
  async createArtifact(req, body, file) {
2265
+ // Validate name first: it is required either way, and saying so before
2266
+ // complaining about the payload is the more useful order.
2035
2267
  if (!body.name || !body.name.trim()) {
2036
2268
  throw new common_1.BadRequestException('Artifact name is required');
2037
2269
  }
2038
2270
  if (body.name.length > 200) {
2039
2271
  throw new common_1.BadRequestException('Artifact name too long (max 200 characters)');
2040
2272
  }
2273
+ // Markdown supplied directly, with no file involved. The endpoint used to
2274
+ // be multipart-only, which meant an artifact could only come from a file
2275
+ // on disk through a native picker — no pasting a document into the page,
2276
+ // and nothing scriptable.
2041
2277
  if (!file) {
2042
2278
  if (typeof body.content !== 'string' || !body.content.trim()) {
2043
2279
  throw new common_1.BadRequestException('Provide either a .md/.pdf file or a non-empty "content" string');
@@ -2054,10 +2290,13 @@ let AppController = AppController_1 = class AppController {
2054
2290
  throw new common_1.HttpException('Failed to create artifact', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
2055
2291
  }
2056
2292
  }
2293
+ // Determine file extension
2057
2294
  const extension = file.originalname.toLowerCase().split('.').pop();
2295
+ // Validate file type - accept both .md and .pdf
2058
2296
  if (!['md', 'pdf'].includes(extension)) {
2059
2297
  throw new common_1.BadRequestException('Only .md and .pdf files are allowed');
2060
2298
  }
2299
+ // Check file size - different limits for different file types
2061
2300
  const maxSize = extension === 'pdf' ? MAX_PDF_UPLOAD_BYTES : MAX_MARKDOWN_BYTES;
2062
2301
  if (file.size > maxSize) {
2063
2302
  throw new common_1.HttpException(`File too large (max ${asMegabytes(maxSize)})`, common_1.HttpStatus.PAYLOAD_TOO_LARGE);
@@ -2066,22 +2305,28 @@ let AppController = AppController_1 = class AppController {
2066
2305
  const appService = this.getAppService(req);
2067
2306
  let artifactId;
2068
2307
  if (extension === 'md') {
2308
+ // Direct upload for markdown files
2069
2309
  const content = file.buffer.toString('utf8');
2070
2310
  artifactId = appService.createUserArtifact(body.name.trim(), content);
2071
2311
  }
2072
2312
  else {
2313
+ // PDF conversion - create placeholder immediately, convert in background
2073
2314
  artifactId = appService.convertUserArtifact(body.name.trim(), file.buffer);
2074
2315
  }
2075
2316
  return { artifactId };
2076
2317
  }
2077
2318
  catch (error) {
2078
2319
  logger_1.logger.error(`Error creating artifact:`, error);
2320
+ // Provide more specific error message for conversion failures
2079
2321
  if (error.message?.includes('conversion')) {
2080
2322
  throw new common_1.HttpException(`Failed to convert PDF: ${error.message}`, common_1.HttpStatus.INTERNAL_SERVER_ERROR);
2081
2323
  }
2082
2324
  throw new common_1.HttpException('Failed to create artifact', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
2083
2325
  }
2084
2326
  }
2327
+ /**
2328
+ * Update artifact content
2329
+ */
2085
2330
  async updateArtifact(req, artifactId, body) {
2086
2331
  if (!body.content) {
2087
2332
  throw new common_1.BadRequestException('Content is required');
@@ -2101,6 +2346,9 @@ let AppController = AppController_1 = class AppController {
2101
2346
  throw new common_1.HttpException('Failed to update artifact', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
2102
2347
  }
2103
2348
  }
2349
+ /**
2350
+ * Rename artifact
2351
+ */
2104
2352
  async renameArtifact(req, artifactId, body) {
2105
2353
  if (!body.name || !body.name.trim()) {
2106
2354
  throw new common_1.BadRequestException('Name is required');
@@ -2123,6 +2371,9 @@ let AppController = AppController_1 = class AppController {
2123
2371
  throw new common_1.HttpException('Failed to rename artifact', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
2124
2372
  }
2125
2373
  }
2374
+ /**
2375
+ * Delete artifact
2376
+ */
2126
2377
  async deleteArtifact(req, artifactId) {
2127
2378
  try {
2128
2379
  const appService = this.getAppService(req);
@@ -2139,6 +2390,9 @@ let AppController = AppController_1 = class AppController {
2139
2390
  throw new common_1.HttpException('Failed to delete artifact', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
2140
2391
  }
2141
2392
  }
2393
+ /**
2394
+ * List artifacts attached to agent
2395
+ */
2142
2396
  async listAgentArtifacts(req, agentId) {
2143
2397
  try {
2144
2398
  const appService = this.getAppService(req);
@@ -2149,6 +2403,9 @@ let AppController = AppController_1 = class AppController {
2149
2403
  return { artifacts: [] };
2150
2404
  }
2151
2405
  }
2406
+ /**
2407
+ * Attach artifact to agent
2408
+ */
2152
2409
  async attachArtifactToAgent(req, agentId, body) {
2153
2410
  if (!body.artifactId) {
2154
2411
  throw new common_1.BadRequestException('Artifact ID is required');
@@ -2165,6 +2422,9 @@ let AppController = AppController_1 = class AppController {
2165
2422
  throw new common_1.HttpException('Failed to attach artifact', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
2166
2423
  }
2167
2424
  }
2425
+ /**
2426
+ * Detach artifact from agent
2427
+ */
2168
2428
  async detachArtifactFromAgent(req, agentId, artifactId) {
2169
2429
  try {
2170
2430
  const appService = this.getAppService(req);
@@ -2985,7 +3245,7 @@ __decorate([
2985
3245
  (0, common_1.Post)('stories/import'),
2986
3246
  (0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('file', {
2987
3247
  limits: {
2988
- fileSize: 100 * 1024 * 1024,
3248
+ fileSize: 100 * 1024 * 1024, // 100MB limit
2989
3249
  },
2990
3250
  })),
2991
3251
  (0, common_1.HttpCode)(common_1.HttpStatus.CREATED),