briyah 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (371) hide show
  1. package/README.md +43 -7
  2. package/data/common/config/LICENSE-model-prices.md +65 -0
  3. package/data/common/config/model_prices.json +47443 -46295
  4. package/data/common/prompts/narrator/create_story.prompt +2 -0
  5. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
  6. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
  7. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
  8. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
  9. package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
  10. package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
  11. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
  12. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
  13. package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
  14. package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
  15. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
  16. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
  17. package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
  18. package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
  19. package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
  20. package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
  21. package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
  22. package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
  23. package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
  24. package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
  25. package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
  26. package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
  27. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
  28. package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
  29. package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
  30. package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
  31. package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
  32. package/dist-sdk/server/src/ai/agent-factory.js +20 -0
  33. package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
  34. package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
  35. package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
  36. package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
  37. package/dist-sdk/server/src/ai/agent.d.ts +196 -0
  38. package/dist-sdk/server/src/ai/agent.js +224 -11
  39. package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
  40. package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
  41. package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
  42. package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
  43. package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
  44. package/dist-sdk/server/src/ai/artifact.service.js +148 -3
  45. package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
  46. package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
  47. package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
  48. package/dist-sdk/server/src/ai/model_prices.js +91 -5
  49. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
  50. package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
  51. package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
  52. package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
  53. package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
  54. package/dist-sdk/server/src/app/balance-message.service.js +24 -0
  55. package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
  56. package/dist-sdk/server/src/app/balance.module.js +4 -0
  57. package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
  58. package/dist-sdk/server/src/app/balance.service.js +54 -0
  59. package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
  60. package/dist-sdk/server/src/app/stripe.controller.js +35 -0
  61. package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
  62. package/dist-sdk/server/src/app/stripe.service.js +62 -0
  63. package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
  64. package/dist-sdk/server/src/app/transaction.service.js +36 -0
  65. package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
  66. package/dist-sdk/server/src/app/user-service-factory.js +38 -1
  67. package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
  68. package/dist-sdk/server/src/app/user-service-manager.js +43 -0
  69. package/dist-sdk/server/src/app.controller.d.ts +87 -0
  70. package/dist-sdk/server/src/app.controller.js +272 -12
  71. package/dist-sdk/server/src/app.module.js +28 -6
  72. package/dist-sdk/server/src/app.service.d.ts +1661 -0
  73. package/dist-sdk/server/src/app.service.js +1837 -4
  74. package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
  75. package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
  76. package/dist-sdk/server/src/auth/auth.controller.js +46 -0
  77. package/dist-sdk/server/src/auth/auth.module.js +3 -2
  78. package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
  79. package/dist-sdk/server/src/auth/auth.service.js +39 -3
  80. package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
  81. package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
  82. package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
  83. package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
  84. package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
  85. package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
  86. package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
  87. package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
  88. package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
  89. package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
  90. package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
  91. package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
  92. package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
  93. package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
  94. package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
  95. package/dist-sdk/server/src/auth/session.guard.js +8 -0
  96. package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
  97. package/dist-sdk/server/src/auth/twilio.service.js +30 -4
  98. package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
  99. package/dist-sdk/server/src/auth/users.service.js +42 -0
  100. package/dist-sdk/server/src/common/errors.d.ts +20 -0
  101. package/dist-sdk/server/src/common/errors.js +21 -0
  102. package/dist-sdk/server/src/config/env-config.d.ts +7 -0
  103. package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
  104. package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
  105. package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
  106. package/dist-sdk/server/src/config/user-config.service.js +57 -0
  107. package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
  108. package/dist-sdk/server/src/config/user-paths.service.js +67 -0
  109. package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
  110. package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
  111. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
  112. package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
  113. package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
  114. package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
  115. package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
  116. package/dist-sdk/server/src/packs/pack.service.js +98 -1
  117. package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
  118. package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
  119. package/dist-sdk/server/src/room/artifact.d.ts +18 -0
  120. package/dist-sdk/server/src/room/message.d.ts +64 -0
  121. package/dist-sdk/server/src/room/message.js +77 -2
  122. package/dist-sdk/server/src/room/nickname.d.ts +26 -0
  123. package/dist-sdk/server/src/room/nickname.js +26 -0
  124. package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
  125. package/dist-sdk/server/src/room/room-config.d.ts +26 -0
  126. package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
  127. package/dist-sdk/server/src/room/room-factory.js +14 -0
  128. package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
  129. package/dist-sdk/server/src/room/room-message.service.js +28 -0
  130. package/dist-sdk/server/src/room/room-store.service.d.ts +176 -0
  131. package/dist-sdk/server/src/room/room-store.service.js +238 -5
  132. package/dist-sdk/server/src/room/room.d.ts +878 -0
  133. package/dist-sdk/server/src/room/room.js +1291 -23
  134. package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
  135. package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
  136. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
  137. package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
  138. package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
  139. package/dist-sdk/server/src/rpg/rpg.service.js +103 -0
  140. package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
  141. package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
  142. package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
  143. package/dist-sdk/server/src/sdk/briyah.js +285 -7
  144. package/dist-sdk/server/src/sdk/index.js +23 -0
  145. package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
  146. package/dist-sdk/server/src/shared/shared.module.js +13 -5
  147. package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
  148. package/dist-sdk/server/src/story/story-message.service.js +43 -0
  149. package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
  150. package/dist-sdk/server/src/story/story-progress.service.js +23 -0
  151. package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
  152. package/dist-sdk/server/src/story/story-store.service.js +136 -1
  153. package/dist-sdk/server/src/story/story.service.d.ts +398 -0
  154. package/dist-sdk/server/src/story/story.service.js +829 -25
  155. package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
  156. package/dist-sdk/server/src/tools/core/index.js +22 -0
  157. package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
  158. package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
  159. package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
  160. package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
  161. package/dist-sdk/server/src/tools/native-tool.types.d.ts +176 -0
  162. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
  163. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
  164. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
  165. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
  166. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
  167. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
  168. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
  169. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
  170. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
  171. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
  172. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
  173. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
  174. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
  175. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
  176. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
  177. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
  178. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
  179. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
  180. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
  181. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
  182. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
  183. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
  184. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
  185. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
  186. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
  187. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
  188. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
  189. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
  190. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
  191. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
  192. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
  193. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
  194. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
  195. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
  196. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
  197. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
  198. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
  199. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
  200. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
  201. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
  202. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
  203. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
  204. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
  205. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
  206. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
  207. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
  208. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
  209. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
  210. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
  211. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
  212. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
  213. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
  214. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
  215. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
  216. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
  217. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
  218. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
  219. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
  220. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
  221. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
  222. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
  223. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
  224. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
  225. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
  226. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
  227. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
  228. package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
  229. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
  230. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
  231. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
  232. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
  233. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
  234. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
  235. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
  236. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
  237. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
  238. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
  239. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
  240. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
  241. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
  242. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
  243. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
  244. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
  245. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +116 -0
  246. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
  247. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
  248. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
  249. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
  250. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
  251. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
  252. package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
  253. package/dist-sdk/server/src/tools/packs/index.js +66 -0
  254. package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
  255. package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
  256. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
  257. package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
  258. package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
  259. package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
  260. package/dist-sdk/shared/types/app.types.d.ts +285 -13
  261. package/dist-sdk/shared/types/app.types.js +3 -0
  262. package/package.json +167 -168
  263. package/data/common/config/random_words.txt +0 -2241
  264. package/data/common/story_ideas/biblical.json +0 -122
  265. package/data/common/story_ideas/fantasy.json +0 -82
  266. package/data/common/story_ideas/historical_fiction.json +0 -82
  267. package/data/common/story_ideas/science_fiction.json +0 -82
  268. package/docs/.nojekyll +0 -1
  269. package/docs/assets/hierarchy.js +0 -1
  270. package/docs/assets/highlight.css +0 -113
  271. package/docs/assets/icons.js +0 -18
  272. package/docs/assets/icons.svg +0 -1
  273. package/docs/assets/main.js +0 -60
  274. package/docs/assets/navigation.js +0 -1
  275. package/docs/assets/search.js +0 -1
  276. package/docs/assets/style.css +0 -1648
  277. package/docs/classes/Agent.html +0 -801
  278. package/docs/classes/Briyah.html +0 -296
  279. package/docs/classes/BriyahConfigService.html +0 -119
  280. package/docs/classes/NativeToolRegistry.html +0 -166
  281. package/docs/classes/PackInstantiationService.html +0 -157
  282. package/docs/classes/PackService.html +0 -247
  283. package/docs/classes/Room.html +0 -1434
  284. package/docs/classes/RoomMessage.html +0 -290
  285. package/docs/enums/MessageAction.html +0 -136
  286. package/docs/functions/availableToolPacks.html +0 -41
  287. package/docs/functions/buildMarkdown.html +0 -54
  288. package/docs/functions/dnd5eTools.html +0 -44
  289. package/docs/functions/installToolPacks.html +0 -51
  290. package/docs/functions/pageMarker.html +0 -45
  291. package/docs/functions/registerToolPacks.html +0 -54
  292. package/docs/functions/splitMarkdownIntoPages.html +0 -51
  293. package/docs/functions/stripWrappingFence.html +0 -52
  294. package/docs/hierarchy.html +0 -46
  295. package/docs/index.html +0 -595
  296. package/docs/interfaces/AgentCreationOptions.html +0 -125
  297. package/docs/interfaces/AgentInfo.html +0 -218
  298. package/docs/interfaces/AgentMessagesResponse.html +0 -74
  299. package/docs/interfaces/AppService.html +0 -3340
  300. package/docs/interfaces/Artifact.html +0 -95
  301. package/docs/interfaces/ArtifactMetadata.html +0 -112
  302. package/docs/interfaces/ArtifactWriteOptions.html +0 -90
  303. package/docs/interfaces/AttachDocumentResponse.html +0 -62
  304. package/docs/interfaces/BriyahConfigOptions.html +0 -124
  305. package/docs/interfaces/ChapterInfo.html +0 -62
  306. package/docs/interfaces/Character.html +0 -86
  307. package/docs/interfaces/ConversionAgent.html +0 -78
  308. package/docs/interfaces/CreateAgentResponse.html +0 -56
  309. package/docs/interfaces/CreateRoomResponse.html +0 -62
  310. package/docs/interfaces/CreateStoryResponse.html +0 -56
  311. package/docs/interfaces/FileList.html +0 -56
  312. package/docs/interfaces/FileMetadata.html +0 -89
  313. package/docs/interfaces/IConfigService.html +0 -79
  314. package/docs/interfaces/InstantiateModels.html +0 -64
  315. package/docs/interfaces/InstantiateRoomResult.html +0 -70
  316. package/docs/interfaces/LoadedPack.html +0 -131
  317. package/docs/interfaces/LoggingOptions.html +0 -92
  318. package/docs/interfaces/Message.html +0 -84
  319. package/docs/interfaces/ModelChoice.html +0 -73
  320. package/docs/interfaces/ModelInfo.html +0 -74
  321. package/docs/interfaces/NativeToolDefinition.html +0 -107
  322. package/docs/interfaces/PackAgentTemplate.html +0 -101
  323. package/docs/interfaces/PackRoomTemplate.html +0 -108
  324. package/docs/interfaces/PackView.html +0 -172
  325. package/docs/interfaces/PdfConversionOptions.html +0 -102
  326. package/docs/interfaces/PdfConversionResult.html +0 -97
  327. package/docs/interfaces/PdfMarkdownOptions.html +0 -198
  328. package/docs/interfaces/PdfMarkdownResult.html +0 -106
  329. package/docs/interfaces/PdfPageMarkdown.html +0 -94
  330. package/docs/interfaces/PreparedPromptResponse.html +0 -62
  331. package/docs/interfaces/ProcessTextResponse.html +0 -86
  332. package/docs/interfaces/PromptFile.html +0 -70
  333. package/docs/interfaces/PromptFileContent.html +0 -76
  334. package/docs/interfaces/PromptFilesResponse.html +0 -56
  335. package/docs/interfaces/PromptFolder.html +0 -80
  336. package/docs/interfaces/PromptFolderDefaults.html +0 -155
  337. package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
  338. package/docs/interfaces/PromptFoldersResponse.html +0 -56
  339. package/docs/interfaces/RoomDetails.html +0 -151
  340. package/docs/interfaces/RoomErrorUpdate.html +0 -82
  341. package/docs/interfaces/RoomInfo.html +0 -88
  342. package/docs/interfaces/RoomMessageUpdate.html +0 -113
  343. package/docs/interfaces/RoomMessagesResponse.html +0 -62
  344. package/docs/interfaces/SendMessageResult.html +0 -62
  345. package/docs/interfaces/StoryErrorEvent.html +0 -84
  346. package/docs/interfaces/StoryIdea.html +0 -74
  347. package/docs/interfaces/StoryInfo.html +0 -198
  348. package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
  349. package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
  350. package/docs/interfaces/StoryState.html +0 -108
  351. package/docs/interfaces/StoryStateEvent.html +0 -76
  352. package/docs/interfaces/ToolArtifact.html +0 -85
  353. package/docs/interfaces/ToolCaller.html +0 -77
  354. package/docs/interfaces/ToolDefinition.html +0 -80
  355. package/docs/interfaces/ToolHelpers.html +0 -105
  356. package/docs/interfaces/ToolPackDocuments.html +0 -100
  357. package/docs/interfaces/ToolParameter.html +0 -74
  358. package/docs/interfaces/ToolRoomAccess.html +0 -260
  359. package/docs/interfaces/ToolSummary.html +0 -74
  360. package/docs/interfaces/ToolsResponse.html +0 -68
  361. package/docs/interfaces/Transaction.html +0 -104
  362. package/docs/interfaces/TransactionHistoryResponse.html +0 -62
  363. package/docs/modules.html +0 -53
  364. package/docs/types/PackOrigin.html +0 -34
  365. package/docs/types/PromptScope.html +0 -34
  366. package/docs/types/RoomTurnMode.html +0 -42
  367. package/docs/types/RoomUpdate.html +0 -36
  368. package/docs/types/RosterOverrides.html +0 -42
  369. package/docs/types/ToolContext.html +0 -40
  370. package/docs/types/ToolRunResult.html +0 -34
  371. package/src/tools/packs/dnd5e/README.md +0 -867
@@ -1,24 +1,122 @@
1
+ /**
2
+ * Packs, as one user sees them.
3
+ *
4
+ * A pack is installed for everybody and enabled per user. Installing is a file
5
+ * copy — the host drops a directory into `<data>/packs/`, or the user creates one
6
+ * of their own under `<data>/user/<id>/packs/`. Enabling is a name in that user's
7
+ * config.
8
+ *
9
+ * ## What a user's pack directory means
10
+ *
11
+ * `user/<id>/packs/<name>/` is one of two things, and which one depends only on
12
+ * whether `packs/<name>/` also exists:
13
+ *
14
+ * - it does — the directory is a **copy-on-write overlay**, holding just the files
15
+ * this user has edited, and the pack itself belongs to the host;
16
+ * - it does not — the directory **is** the pack, and the user owns it.
17
+ *
18
+ * Lookup does not care: the search order is the same either way. Only listing
19
+ * needs the distinction, to decide whether the user may delete it.
20
+ *
21
+ * ## What disabling does
22
+ *
23
+ * It hides. A disabled pack drops out of every listing and out of bare-name prompt
24
+ * resolution, which is what stops a pack claiming a name like `narrator`. It does
25
+ * not stop anything already configured from working: a pack-qualified prompt
26
+ * folder still resolves, an attached document still loads, a granted tool still
27
+ * runs. That mirrors `pack-artifacts.ts`, where listing is gated and resolution is
28
+ * not, and it is why disabling is safe to do casually.
29
+ */
1
30
  import { UserPathsService } from '../config/user-paths.service';
2
31
  import { UserConfigService } from '../config/user-config.service';
3
32
  import { LoadedPack } from './pack-manifest';
33
+ /** A pack and this user's relationship to it. */
4
34
  export interface PackView extends LoadedPack {
5
35
  enabled: boolean;
36
+ /** Tool names the pack wants that the process has not registered. */
6
37
  missingTools: string[];
38
+ /** Packs it names in `requiresPacks` that this user does not have enabled. */
7
39
  missingPacks: string[];
40
+ /** Documents its `artifacts/manifest.json` ships. */
8
41
  documentCount: number;
9
42
  }
10
43
  export declare class PackService {
11
44
  private readonly userPaths;
12
45
  private readonly userConfig;
46
+ /** Native tool names the process has registered, for the missing-tool warning. */
13
47
  private readonly registeredToolNames;
14
- constructor(userPaths: UserPathsService, userConfig: UserConfigService, registeredToolNames: () => readonly string[]);
48
+ constructor(userPaths: UserPathsService, userConfig: UserConfigService,
49
+ /** Native tool names the process has registered, for the missing-tool warning. */
50
+ registeredToolNames: () => readonly string[]);
51
+ /**
52
+ * The packs this user has enabled, as a thunk-friendly snapshot.
53
+ *
54
+ * Filtered to packs that are actually installed, so a name left behind by a
55
+ * pack the host removed does not make the resolver stat a directory that will
56
+ * never exist. The name stays in the config, so reinstalling brings it back.
57
+ *
58
+ * @returns Enabled pack names, sorted
59
+ */
15
60
  enabledPacks(): readonly string[];
61
+ /** Every pack name on disk, host and user, deduped. */
16
62
  installedPackNames(): string[];
63
+ /**
64
+ * Lists every installed pack with this user's view of it.
65
+ * @returns The packs, sorted by title
66
+ */
17
67
  listPacks(): PackView[];
68
+ /**
69
+ * Reads one pack.
70
+ * @param packName The pack name
71
+ * @returns The pack
72
+ * @throws {NotFoundError} If no such pack is installed
73
+ */
18
74
  getPack(packName: string): PackView;
75
+ /**
76
+ * Turns a pack on or off for this user.
77
+ * @param packName The pack to change
78
+ * @param enabled Whether it should be on
79
+ * @throws {NotFoundError} If no such pack is installed
80
+ */
19
81
  setEnabled(packName: string, enabled: boolean): void;
82
+ /**
83
+ * Creates an empty pack owned by this user, and enables it.
84
+ *
85
+ * Enabling is part of creating because a pack the user just made and cannot see
86
+ * is a bug report. Tool code is never part of this: a user pack can grant tools
87
+ * the host has registered, but only the host installs the code.
88
+ *
89
+ * @param packName The new pack's name
90
+ * @param title Optional display name
91
+ * @returns The created pack
92
+ * @throws {ValidationError} If the name is not a legal pack name
93
+ * @throws {OperationFailedError} If a pack of that name already exists
94
+ */
20
95
  createUserPack(packName: string, title?: string): PackView;
96
+ /**
97
+ * Deletes a pack this user owns.
98
+ *
99
+ * Only ever their own directory. Agents and rooms already created from the pack
100
+ * are untouched and stay visible — they carry the pack's *name*, and a name
101
+ * with no pack behind it is treated as visible rather than hidden, so deleting
102
+ * a pack never makes a user's own work disappear.
103
+ *
104
+ * @param packName The pack to delete
105
+ * @throws {NotFoundError} If no such pack is installed
106
+ * @throws {OperationFailedError} If the pack was installed by the host
107
+ */
21
108
  deleteUserPack(packName: string): void;
109
+ /**
110
+ * Whether something stamped with this pack name should be listed.
111
+ *
112
+ * An item with no pack is always visible, and so is one naming a pack that is
113
+ * not installed — otherwise deleting a pack would hide the user's own agents
114
+ * and rooms rather than just the templates they came from.
115
+ *
116
+ * @param packName The pack stamped on the item, if any
117
+ * @returns True when the item should appear in a listing
118
+ */
22
119
  isVisible(packName?: string | null): boolean;
120
+ /** Reads a pack, preferring the user's directory so an overlay reports its own contents. */
23
121
  private load;
24
122
  }
@@ -1,4 +1,33 @@
1
1
  "use strict";
2
+ /**
3
+ * Packs, as one user sees them.
4
+ *
5
+ * A pack is installed for everybody and enabled per user. Installing is a file
6
+ * copy — the host drops a directory into `<data>/packs/`, or the user creates one
7
+ * of their own under `<data>/user/<id>/packs/`. Enabling is a name in that user's
8
+ * config.
9
+ *
10
+ * ## What a user's pack directory means
11
+ *
12
+ * `user/<id>/packs/<name>/` is one of two things, and which one depends only on
13
+ * whether `packs/<name>/` also exists:
14
+ *
15
+ * - it does — the directory is a **copy-on-write overlay**, holding just the files
16
+ * this user has edited, and the pack itself belongs to the host;
17
+ * - it does not — the directory **is** the pack, and the user owns it.
18
+ *
19
+ * Lookup does not care: the search order is the same either way. Only listing
20
+ * needs the distinction, to decide whether the user may delete it.
21
+ *
22
+ * ## What disabling does
23
+ *
24
+ * It hides. A disabled pack drops out of every listing and out of bare-name prompt
25
+ * resolution, which is what stops a pack claiming a name like `narrator`. It does
26
+ * not stop anything already configured from working: a pack-qualified prompt
27
+ * folder still resolves, an attached document still loads, a granted tool still
28
+ * runs. That mirrors `pack-artifacts.ts`, where listing is gated and resolution is
29
+ * not, and it is why disabling is safe to do casually.
30
+ */
2
31
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
32
  if (k2 === undefined) k2 = k;
4
33
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -43,15 +72,27 @@ class PackService {
43
72
  userPaths;
44
73
  userConfig;
45
74
  registeredToolNames;
46
- constructor(userPaths, userConfig, registeredToolNames) {
75
+ constructor(userPaths, userConfig,
76
+ /** Native tool names the process has registered, for the missing-tool warning. */
77
+ registeredToolNames) {
47
78
  this.userPaths = userPaths;
48
79
  this.userConfig = userConfig;
49
80
  this.registeredToolNames = registeredToolNames;
50
81
  }
82
+ /**
83
+ * The packs this user has enabled, as a thunk-friendly snapshot.
84
+ *
85
+ * Filtered to packs that are actually installed, so a name left behind by a
86
+ * pack the host removed does not make the resolver stat a directory that will
87
+ * never exist. The name stays in the config, so reinstalling brings it back.
88
+ *
89
+ * @returns Enabled pack names, sorted
90
+ */
51
91
  enabledPacks() {
52
92
  const installed = new Set(this.installedPackNames());
53
93
  return this.userConfig.enabledPacks().filter((name) => installed.has(name));
54
94
  }
95
+ /** Every pack name on disk, host and user, deduped. */
55
96
  installedPackNames() {
56
97
  const names = new Set([
57
98
  ...subdirectoriesOf(this.userPaths.getPacksDir()),
@@ -59,6 +100,10 @@ class PackService {
59
100
  ]);
60
101
  return [...names].filter(prompt_resolver_1.isValidPackName).sort();
61
102
  }
103
+ /**
104
+ * Lists every installed pack with this user's view of it.
105
+ * @returns The packs, sorted by title
106
+ */
62
107
  listPacks() {
63
108
  const enabled = new Set(this.enabledPacks());
64
109
  return this.installedPackNames()
@@ -66,6 +111,12 @@ class PackService {
66
111
  .filter((pack) => pack !== null)
67
112
  .sort((a, b) => a.title.localeCompare(b.title));
68
113
  }
114
+ /**
115
+ * Reads one pack.
116
+ * @param packName The pack name
117
+ * @returns The pack
118
+ * @throws {NotFoundError} If no such pack is installed
119
+ */
69
120
  getPack(packName) {
70
121
  const pack = this.load(packName, new Set(this.enabledPacks()));
71
122
  if (!pack) {
@@ -73,10 +124,29 @@ class PackService {
73
124
  }
74
125
  return pack;
75
126
  }
127
+ /**
128
+ * Turns a pack on or off for this user.
129
+ * @param packName The pack to change
130
+ * @param enabled Whether it should be on
131
+ * @throws {NotFoundError} If no such pack is installed
132
+ */
76
133
  setEnabled(packName, enabled) {
77
134
  this.getPack(packName);
78
135
  this.userConfig.setPackEnabled(packName, enabled);
79
136
  }
137
+ /**
138
+ * Creates an empty pack owned by this user, and enables it.
139
+ *
140
+ * Enabling is part of creating because a pack the user just made and cannot see
141
+ * is a bug report. Tool code is never part of this: a user pack can grant tools
142
+ * the host has registered, but only the host installs the code.
143
+ *
144
+ * @param packName The new pack's name
145
+ * @param title Optional display name
146
+ * @returns The created pack
147
+ * @throws {ValidationError} If the name is not a legal pack name
148
+ * @throws {OperationFailedError} If a pack of that name already exists
149
+ */
80
150
  createUserPack(packName, title) {
81
151
  if (!(0, prompt_resolver_1.isValidPackName)(packName)) {
82
152
  throw new errors_1.ValidationError(`Invalid pack name "${packName}": use lowercase letters, digits, "_" or "-"`);
@@ -92,6 +162,18 @@ class PackService {
92
162
  this.userConfig.setPackEnabled(packName, true);
93
163
  return this.getPack(packName);
94
164
  }
165
+ /**
166
+ * Deletes a pack this user owns.
167
+ *
168
+ * Only ever their own directory. Agents and rooms already created from the pack
169
+ * are untouched and stay visible — they carry the pack's *name*, and a name
170
+ * with no pack behind it is treated as visible rather than hidden, so deleting
171
+ * a pack never makes a user's own work disappear.
172
+ *
173
+ * @param packName The pack to delete
174
+ * @throws {NotFoundError} If no such pack is installed
175
+ * @throws {OperationFailedError} If the pack was installed by the host
176
+ */
95
177
  deleteUserPack(packName) {
96
178
  const pack = this.getPack(packName);
97
179
  if (pack.origin === 'host') {
@@ -100,6 +182,16 @@ class PackService {
100
182
  fs.rmSync(this.userPaths.getUserPackDir(packName), { recursive: true, force: true });
101
183
  this.userConfig.setPackEnabled(packName, false);
102
184
  }
185
+ /**
186
+ * Whether something stamped with this pack name should be listed.
187
+ *
188
+ * An item with no pack is always visible, and so is one naming a pack that is
189
+ * not installed — otherwise deleting a pack would hide the user's own agents
190
+ * and rooms rather than just the templates they came from.
191
+ *
192
+ * @param packName The pack stamped on the item, if any
193
+ * @returns True when the item should appear in a listing
194
+ */
103
195
  isVisible(packName) {
104
196
  if (!packName)
105
197
  return true;
@@ -107,6 +199,7 @@ class PackService {
107
199
  return true;
108
200
  return this.enabledPacks().includes(packName);
109
201
  }
202
+ /** Reads a pack, preferring the user's directory so an overlay reports its own contents. */
110
203
  load(packName, enabled) {
111
204
  const hostDir = this.userPaths.getPackDir(packName);
112
205
  const userDir = this.userPaths.getUserPackDir(packName);
@@ -115,6 +208,7 @@ class PackService {
115
208
  if (!pack)
116
209
  return null;
117
210
  if (origin === 'host') {
211
+ // An overlay may add prompt folders the host pack does not have.
118
212
  const overlayFolders = subdirectoriesOf(path.join(userDir, pack_manifest_1.PACK_SUBDIR.prompts));
119
213
  pack.promptFolders = [...new Set([...pack.promptFolders, ...overlayFolders])].sort();
120
214
  }
@@ -129,6 +223,7 @@ class PackService {
129
223
  }
130
224
  }
131
225
  exports.PackService = PackService;
226
+ /** How many documents a pack's artifact manifest lists. */
132
227
  function countDocuments(artifactsDir) {
133
228
  const manifest = path.join(artifactsDir, 'manifest.json');
134
229
  if (!fs.existsSync(manifest))
@@ -138,6 +233,8 @@ function countDocuments(artifactsDir) {
138
233
  return Array.isArray(parsed?.documents) ? parsed.documents.length : 0;
139
234
  }
140
235
  catch {
236
+ // readPack already warned about the unparseable file; a count of zero is
237
+ // the honest answer rather than a second log line on every page load.
141
238
  return 0;
142
239
  }
143
240
  }
@@ -3,12 +3,39 @@ export declare class ArtifactStoreService {
3
3
  private readonly ARTIFACT_EXTENSION;
4
4
  private readonly MAX_FILENAME_LENGTH;
5
5
  private readonly UNSAFE_CHARS_REGEX;
6
+ /**
7
+ * Saves an artifact to its own file in the room directory
8
+ * If an artifact with the same name already exists, it will be overwritten
9
+ */
6
10
  saveArtifact(roomId: string, storageDir: string, artifact: Artifact): string;
11
+ /**
12
+ * Loads all artifacts from .artifact files in the room directory
13
+ */
7
14
  loadArtifacts(roomId: string, storageDir: string): Artifact[];
15
+ /**
16
+ * Deletes a specific artifact file by name
17
+ */
8
18
  deleteArtifact(roomId: string, storageDir: string, artifactName: string): boolean;
19
+ /**
20
+ * Deletes all artifact files in a room directory
21
+ */
9
22
  deleteAllArtifacts(roomId: string, storageDir: string): void;
23
+ /**
24
+ * Sanitizes an artifact name for use as a filename
25
+ * Replaces unsafe characters, truncates long names, and handles collisions
26
+ */
10
27
  sanitizeFilename(name: string, roomDir: string): string;
28
+ /**
29
+ * Parses an artifact file and extracts metadata and body
30
+ * Returns null if the file format is invalid
31
+ */
11
32
  parseArtifactFile(content: string): Artifact | null;
33
+ /**
34
+ * Formats an artifact as a file with metadata annotations
35
+ */
12
36
  formatArtifactFile(artifact: Artifact): string;
37
+ /**
38
+ * Gets the full file path for an artifact
39
+ */
13
40
  getArtifactFilePath(roomId: string, storageDir: string, sanitizedName: string): string;
14
41
  }
@@ -48,15 +48,24 @@ let ArtifactStoreService = class ArtifactStoreService {
48
48
  ARTIFACT_EXTENSION = '.artifact';
49
49
  MAX_FILENAME_LENGTH = 200;
50
50
  UNSAFE_CHARS_REGEX = /[<>:"/\\|?*]/g;
51
+ /**
52
+ * Saves an artifact to its own file in the room directory
53
+ * If an artifact with the same name already exists, it will be overwritten
54
+ */
51
55
  saveArtifact(roomId, storageDir, artifact) {
52
56
  const roomDir = path.join(storageDir, roomId);
57
+ // Ensure room directory exists
53
58
  if (!fs.existsSync(roomDir)) {
54
59
  fs.mkdirSync(roomDir, { recursive: true });
55
60
  }
61
+ // Delete any existing artifact with the same name first (to allow updates)
56
62
  this.deleteArtifact(roomId, storageDir, artifact.name);
63
+ // Sanitize the artifact name for use as filename
57
64
  const sanitizedName = this.sanitizeFilename(artifact.name, roomDir);
58
65
  const filePath = this.getArtifactFilePath(roomId, storageDir, sanitizedName);
66
+ // Format the artifact content with metadata annotations
59
67
  const content = this.formatArtifactFile(artifact);
68
+ // Write to file
60
69
  try {
61
70
  fs.writeFileSync(filePath, content, 'utf-8');
62
71
  logger_1.logger.log(`Saved artifact "${artifact.name}" to ${filePath}`);
@@ -67,6 +76,9 @@ let ArtifactStoreService = class ArtifactStoreService {
67
76
  throw error;
68
77
  }
69
78
  }
79
+ /**
80
+ * Loads all artifacts from .artifact files in the room directory
81
+ */
70
82
  loadArtifacts(roomId, storageDir) {
71
83
  const roomDir = path.join(storageDir, roomId);
72
84
  if (!fs.existsSync(roomDir)) {
@@ -99,12 +111,16 @@ let ArtifactStoreService = class ArtifactStoreService {
99
111
  }
100
112
  return artifacts;
101
113
  }
114
+ /**
115
+ * Deletes a specific artifact file by name
116
+ */
102
117
  deleteArtifact(roomId, storageDir, artifactName) {
103
118
  const roomDir = path.join(storageDir, roomId);
104
119
  if (!fs.existsSync(roomDir)) {
105
120
  return false;
106
121
  }
107
122
  try {
123
+ // Find the artifact file by parsing all .artifact files
108
124
  const files = fs.readdirSync(roomDir);
109
125
  const artifactFiles = files.filter((file) => file.endsWith(this.ARTIFACT_EXTENSION));
110
126
  for (const file of artifactFiles) {
@@ -124,6 +140,9 @@ let ArtifactStoreService = class ArtifactStoreService {
124
140
  return false;
125
141
  }
126
142
  }
143
+ /**
144
+ * Deletes all artifact files in a room directory
145
+ */
127
146
  deleteAllArtifacts(roomId, storageDir) {
128
147
  const roomDir = path.join(storageDir, roomId);
129
148
  if (!fs.existsSync(roomDir)) {
@@ -142,45 +161,62 @@ let ArtifactStoreService = class ArtifactStoreService {
142
161
  logger_1.logger.error(`Error deleting artifacts for room ${roomId}: ${error.message}`);
143
162
  }
144
163
  }
164
+ /**
165
+ * Sanitizes an artifact name for use as a filename
166
+ * Replaces unsafe characters, truncates long names, and handles collisions
167
+ */
145
168
  sanitizeFilename(name, roomDir) {
146
169
  if (!name || name.trim().length === 0) {
147
170
  throw new Error('Artifact name cannot be empty');
148
171
  }
172
+ // Trim whitespace and dots from start/end
149
173
  let sanitized = name.trim().replace(/^\.+|\.+$/g, '');
174
+ // Replace unsafe filesystem characters with underscores
150
175
  sanitized = sanitized.replace(this.UNSAFE_CHARS_REGEX, '_');
176
+ // Truncate if too long
151
177
  if (sanitized.length > this.MAX_FILENAME_LENGTH) {
152
178
  sanitized = sanitized.substring(0, this.MAX_FILENAME_LENGTH);
153
179
  }
180
+ // Handle collisions by appending _2, _3, etc.
154
181
  let finalName = sanitized;
155
182
  let counter = 2;
156
183
  while (fs.existsSync(path.join(roomDir, finalName + this.ARTIFACT_EXTENSION))) {
157
184
  finalName = `${sanitized}_${counter}`;
158
185
  counter++;
186
+ // Safety check to prevent infinite loops
159
187
  if (counter > 1000) {
160
188
  throw new Error(`Unable to generate unique filename for artifact "${name}"`);
161
189
  }
162
190
  }
163
191
  return finalName;
164
192
  }
193
+ /**
194
+ * Parses an artifact file and extracts metadata and body
195
+ * Returns null if the file format is invalid
196
+ */
165
197
  parseArtifactFile(content) {
166
198
  const lines = content.split('\n');
167
199
  if (lines.length < 4) {
168
200
  logger_1.logger.error('Invalid artifact file: too few lines');
169
201
  return null;
170
202
  }
203
+ // Parse metadata headers
171
204
  const nameLine = lines[0];
172
205
  const creatorLine = lines[1];
173
206
  const viewersLine = lines[2];
207
+ // Extract name
174
208
  if (!nameLine.startsWith('# name: ')) {
175
209
  logger_1.logger.error('Invalid artifact file: missing or malformed name header');
176
210
  return null;
177
211
  }
178
212
  const name = nameLine.substring('# name: '.length).trim();
213
+ // Extract creator
179
214
  if (!creatorLine.startsWith('# creator: ')) {
180
215
  logger_1.logger.error('Invalid artifact file: missing or malformed creator header');
181
216
  return null;
182
217
  }
183
218
  const creator = creatorLine.substring('# creator: '.length).trim();
219
+ // Extract viewers (optional)
184
220
  let viewers;
185
221
  if (viewersLine.startsWith('# viewers: ')) {
186
222
  const viewersStr = viewersLine.substring('# viewers: '.length).trim();
@@ -191,12 +227,14 @@ let ArtifactStoreService = class ArtifactStoreService {
191
227
  .filter((v) => v.length > 0);
192
228
  }
193
229
  else {
194
- viewers = [creator];
230
+ viewers = [creator]; // Empty viewers list defaults to creator only
195
231
  }
196
232
  }
197
233
  else {
198
- viewers = [creator];
234
+ viewers = [creator]; // Missing viewers line defaults to creator only
199
235
  }
236
+ // An optional `# transient: true` follows the viewers line. Older files
237
+ // have no such line and load as cached artifacts, which is what they were.
200
238
  let bodyStart = 3;
201
239
  let transient = false;
202
240
  if (lines[3] && lines[3].startsWith('# transient: ')) {
@@ -212,10 +250,15 @@ let ArtifactStoreService = class ArtifactStoreService {
212
250
  ...(transient && { transient }),
213
251
  };
214
252
  }
253
+ /**
254
+ * Formats an artifact as a file with metadata annotations
255
+ */
215
256
  formatArtifactFile(artifact) {
216
257
  const viewersStr = artifact.viewers && artifact.viewers.length > 0
217
258
  ? artifact.viewers.join(', ')
218
- : artifact.creator;
259
+ : artifact.creator; // Default to creator if no viewers specified
260
+ // The transient line is written only when set, so an ordinary artifact's
261
+ // file is byte-identical to what earlier versions produced.
219
262
  const transientLine = artifact.transient ? '\n# transient: true' : '';
220
263
  return `# name: ${artifact.name}
221
264
  # creator: ${artifact.creator}
@@ -223,6 +266,9 @@ let ArtifactStoreService = class ArtifactStoreService {
223
266
 
224
267
  ${artifact.body}`;
225
268
  }
269
+ /**
270
+ * Gets the full file path for an artifact
271
+ */
226
272
  getArtifactFilePath(roomId, storageDir, sanitizedName) {
227
273
  return path.join(storageDir, roomId, sanitizedName + this.ARTIFACT_EXTENSION);
228
274
  }
@@ -1,7 +1,25 @@
1
+ /**
2
+ * Represents an artifact created in a room
3
+ */
1
4
  export interface Artifact {
2
5
  name: string;
3
6
  creator: string;
4
7
  body: string;
5
8
  viewers?: string[];
9
+ /**
10
+ * Deliver this artifact in the **transient** prompt rather than the cached one.
11
+ *
12
+ * An ordinary artifact renders into `{{visibleArtifacts}}`, which sits in the
13
+ * cached system block ahead of any attached documents — so every write throws
14
+ * away the cached prefix of every viewer, including their rule documents. A
15
+ * transient artifact is left out of that block and injected into the uncached
16
+ * per-turn prompt instead (see `Room.buildTransientPrompt`), which is also not
17
+ * written to history.
18
+ *
19
+ * The trade is exact: a transient artifact is re-sent in full on every one of
20
+ * its viewers' turns and never cached, so it suits state that is small and
21
+ * changes often — a character sheet whose hit points move every round. An
22
+ * artifact that is large and stable is cheaper left cached.
23
+ */
6
24
  transient?: boolean;
7
25
  }
@@ -1,4 +1,7 @@
1
1
  import { Message, MessageAction } from '../../../shared/types/app.types';
2
+ /**
3
+ * Represents a message exchanged between conversations in a Room
4
+ */
2
5
  export declare class RoomMessage implements Message {
3
6
  sender: string;
4
7
  action: MessageAction;
@@ -9,13 +12,74 @@ export declare class RoomMessage implements Message {
9
12
  situation?: string;
10
13
  changes?: Record<string, any>;
11
14
  index?: number;
15
+ /**
16
+ * On a moderator's routing answer: the action the relayed message should carry
17
+ * in the room, rather than staying a MODERATE.
18
+ *
19
+ * A moderated message with no `relayAs` is stored in every recipient's history
20
+ * as `From: <sender>\n<content>` (see Agent.addToConversationHistory), which is
21
+ * what a story character expects and what a room agent that speaks the JSON
22
+ * protocol does not — half its history would model the wrong output format.
23
+ * Naming an action here makes the relayed message an ordinary room message: the
24
+ * right shape in history, and the right badge in the transcript.
25
+ *
26
+ * Only moderators whose `moderate.json` declares the field can produce it, so a
27
+ * moderator that says nothing keeps the original behaviour.
28
+ */
12
29
  relayAs?: MessageAction;
30
+ /**
31
+ * Creates a new Message
32
+ *
33
+ * **Every name on a message is an `agentNickname`**, never an `agentName`. The
34
+ * nickname is what the room routes by, what an agent writes into `targets`, and
35
+ * what artifact viewers and the room leader are recorded as. `agentName` is a
36
+ * label — it names the role, carries the room's name as a prefix, and nothing
37
+ * resolves it. The parameters here said otherwise for a long time while every
38
+ * caller passed a nickname.
39
+ *
40
+ * @param sender The agentNickname of the agent sending the message
41
+ * @param content The content of the message
42
+ * @param action The action type of the message
43
+ * @param targets Array of agentNicknames that will receive the message
44
+ * @param name Optional name for PUBLISH and EXECUTE actions
45
+ * @param situation Optional situation update to set the current story situation
46
+ */
13
47
  constructor(sender: string, action: MessageAction, content: string, targets?: string[], name?: string, situation?: string);
48
+ /**
49
+ * Gets the sender of the message
50
+ * @returns The agentNickname of the sender
51
+ */
14
52
  getSender(): string;
53
+ /**
54
+ * Gets the action type of the message
55
+ * @returns The message action
56
+ */
15
57
  getAction(): MessageAction;
58
+ /**
59
+ * Gets the content of the message
60
+ * @returns The message content
61
+ */
16
62
  getContent(): string;
63
+ /**
64
+ * Gets the targets of the message
65
+ * @returns Array of agentNicknames of target conversations
66
+ */
17
67
  getTargets(): string[];
68
+ /**
69
+ * Gets the timestamp when the message was created
70
+ * @returns The message timestamp
71
+ */
18
72
  getTimestamp(): Date;
73
+ /**
74
+ * Checks if an agent is a target of this message (intended recipient)
75
+ * @param agentNickname The agentNickname to check
76
+ * @returns True if the conversation is a target, false otherwise
77
+ */
19
78
  isTarget(agentNickname: string): boolean;
79
+ /**
80
+ * Checks if a conversation can hear this message
81
+ * @param agentNickname The agentNickname to check
82
+ * @returns True if the conversation can hear the message, false otherwise
83
+ */
20
84
  canHear(agentNickname: string): boolean;
21
85
  }