briyah 2.0.3 → 2.0.5

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 (391) hide show
  1. package/README.md +55 -8
  2. package/data/common/config/LICENSE-model-prices.md +65 -0
  3. package/data/common/config/markup +1 -1
  4. package/data/common/config/model_prices.json +47443 -46295
  5. package/data/common/config/story_models.json +3 -3
  6. package/data/common/prompts/illustrator/describe_scene.prompt +4 -4
  7. package/data/common/prompts/narrator/create_story.prompt +2 -0
  8. package/data/common/prompts/perceive.prompt +1 -1
  9. package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +1 -1
  10. package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +1 -1
  11. package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +795 -787
  12. package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +2 -1
  13. package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +1 -1
  14. package/data/packs/dnd5e/rooms/campaign.json +18 -15
  15. package/data/packs/dnd5e/rooms/table.json +17 -16
  16. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
  17. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +174 -3
  18. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +194 -3
  19. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +299 -19
  20. package/dist-sdk/server/src/ai/LLM/blank-image.d.ts +36 -0
  21. package/dist-sdk/server/src/ai/LLM/blank-image.js +80 -0
  22. package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
  23. package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
  24. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
  25. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
  26. package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
  27. package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
  28. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
  29. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +103 -4
  30. package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
  31. package/dist-sdk/server/src/ai/LLM/fal.service.js +56 -2
  32. package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
  33. package/dist-sdk/server/src/ai/LLM/googleai.service.js +43 -2
  34. package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
  35. package/dist-sdk/server/src/ai/LLM/grok.service.js +55 -3
  36. package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
  37. package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
  38. package/dist-sdk/server/src/ai/LLM/openai.service.js +81 -3
  39. package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
  40. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +45 -3
  41. package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
  42. package/dist-sdk/server/src/ai/LLM/together.service.js +61 -3
  43. package/dist-sdk/server/src/ai/agent-config.d.ts +15 -1
  44. package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
  45. package/dist-sdk/server/src/ai/agent-factory.js +20 -0
  46. package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
  47. package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
  48. package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
  49. package/dist-sdk/server/src/ai/agent-store.service.js +166 -7
  50. package/dist-sdk/server/src/ai/agent.d.ts +197 -2
  51. package/dist-sdk/server/src/ai/agent.js +225 -14
  52. package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
  53. package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
  54. package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
  55. package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
  56. package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
  57. package/dist-sdk/server/src/ai/artifact.service.js +148 -3
  58. package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
  59. package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
  60. package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
  61. package/dist-sdk/server/src/ai/model_prices.js +91 -5
  62. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
  63. package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
  64. package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
  65. package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
  66. package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
  67. package/dist-sdk/server/src/app/balance-message.service.js +24 -0
  68. package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
  69. package/dist-sdk/server/src/app/balance.module.js +4 -0
  70. package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
  71. package/dist-sdk/server/src/app/balance.service.js +54 -0
  72. package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
  73. package/dist-sdk/server/src/app/stripe.controller.js +35 -0
  74. package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
  75. package/dist-sdk/server/src/app/stripe.service.js +62 -0
  76. package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
  77. package/dist-sdk/server/src/app/transaction.service.js +36 -0
  78. package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
  79. package/dist-sdk/server/src/app/user-service-factory.js +46 -3
  80. package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
  81. package/dist-sdk/server/src/app/user-service-manager.js +43 -0
  82. package/dist-sdk/server/src/app.controller.d.ts +120 -0
  83. package/dist-sdk/server/src/app.controller.js +365 -14
  84. package/dist-sdk/server/src/app.module.js +28 -6
  85. package/dist-sdk/server/src/app.service.d.ts +1710 -4
  86. package/dist-sdk/server/src/app.service.js +1938 -20
  87. package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
  88. package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
  89. package/dist-sdk/server/src/auth/auth.controller.js +46 -0
  90. package/dist-sdk/server/src/auth/auth.module.js +3 -2
  91. package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
  92. package/dist-sdk/server/src/auth/auth.service.js +39 -3
  93. package/dist-sdk/server/src/auth/jwt-auth.guard.js +44 -0
  94. package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
  95. package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
  96. package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
  97. package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
  98. package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
  99. package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
  100. package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
  101. package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
  102. package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
  103. package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
  104. package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
  105. package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
  106. package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
  107. package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
  108. package/dist-sdk/server/src/auth/session.guard.js +8 -0
  109. package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
  110. package/dist-sdk/server/src/auth/twilio.service.js +30 -4
  111. package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
  112. package/dist-sdk/server/src/auth/users.service.js +42 -0
  113. package/dist-sdk/server/src/common/errors.d.ts +20 -0
  114. package/dist-sdk/server/src/common/errors.js +21 -0
  115. package/dist-sdk/server/src/config/env-config.d.ts +7 -0
  116. package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
  117. package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
  118. package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
  119. package/dist-sdk/server/src/config/user-config.service.js +57 -0
  120. package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
  121. package/dist-sdk/server/src/config/user-paths.service.js +67 -0
  122. package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
  123. package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
  124. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
  125. package/dist-sdk/server/src/packs/pack-instantiation.service.js +104 -0
  126. package/dist-sdk/server/src/packs/pack-manifest.d.ts +114 -0
  127. package/dist-sdk/server/src/packs/pack-manifest.js +69 -0
  128. package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
  129. package/dist-sdk/server/src/packs/pack.service.js +98 -1
  130. package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
  131. package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
  132. package/dist-sdk/server/src/room/artifact.d.ts +18 -0
  133. package/dist-sdk/server/src/room/illustration/illustration.service.d.ts +211 -0
  134. package/dist-sdk/server/src/room/illustration/illustration.service.js +771 -0
  135. package/dist-sdk/server/src/room/illustration/illustration.types.d.ts +101 -0
  136. package/dist-sdk/server/src/room/illustration/illustration.types.js +2 -0
  137. package/dist-sdk/server/src/room/message.d.ts +64 -0
  138. package/dist-sdk/server/src/room/message.js +77 -2
  139. package/dist-sdk/server/src/room/nickname.d.ts +26 -0
  140. package/dist-sdk/server/src/room/nickname.js +26 -0
  141. package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
  142. package/dist-sdk/server/src/room/room-config.d.ts +84 -1
  143. package/dist-sdk/server/src/room/room-config.js +19 -0
  144. package/dist-sdk/server/src/room/room-factory.d.ts +20 -0
  145. package/dist-sdk/server/src/room/room-factory.js +25 -0
  146. package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
  147. package/dist-sdk/server/src/room/room-message.service.js +28 -0
  148. package/dist-sdk/server/src/room/room-store.service.d.ts +184 -0
  149. package/dist-sdk/server/src/room/room-store.service.js +280 -6
  150. package/dist-sdk/server/src/room/room.d.ts +981 -1
  151. package/dist-sdk/server/src/room/room.js +1531 -27
  152. package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
  153. package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
  154. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
  155. package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
  156. package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
  157. package/dist-sdk/server/src/rpg/rpg.service.js +108 -1
  158. package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
  159. package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
  160. package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
  161. package/dist-sdk/server/src/sdk/briyah.js +285 -7
  162. package/dist-sdk/server/src/sdk/index.js +23 -0
  163. package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
  164. package/dist-sdk/server/src/shared/shared.module.js +13 -5
  165. package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
  166. package/dist-sdk/server/src/story/story-message.service.js +43 -0
  167. package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
  168. package/dist-sdk/server/src/story/story-progress.service.js +23 -0
  169. package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
  170. package/dist-sdk/server/src/story/story-store.service.js +136 -1
  171. package/dist-sdk/server/src/story/story.service.d.ts +366 -9
  172. package/dist-sdk/server/src/story/story.service.js +825 -374
  173. package/dist-sdk/server/src/tools/core/illustrate.tool.d.ts +14 -0
  174. package/dist-sdk/server/src/tools/core/illustrate.tool.js +80 -0
  175. package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
  176. package/dist-sdk/server/src/tools/core/index.js +24 -1
  177. package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
  178. package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
  179. package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
  180. package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
  181. package/dist-sdk/server/src/tools/native-tool.types.d.ts +266 -0
  182. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
  183. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
  184. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
  185. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
  186. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
  187. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
  188. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
  189. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
  190. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
  191. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
  192. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
  193. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
  194. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
  195. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
  196. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
  197. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
  198. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
  199. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
  200. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
  201. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
  202. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
  203. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
  204. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
  205. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
  206. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
  207. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
  208. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
  209. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
  210. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
  211. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
  212. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
  213. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
  214. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
  215. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
  216. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
  217. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
  218. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
  219. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
  220. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
  221. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
  222. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
  223. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
  224. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
  225. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
  226. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
  227. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
  228. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
  229. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
  230. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
  231. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
  232. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
  233. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
  234. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
  235. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
  236. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
  237. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
  238. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
  239. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
  240. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
  241. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
  242. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +201 -0
  243. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +149 -0
  244. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
  245. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
  246. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
  247. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
  248. package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
  249. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
  250. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
  251. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
  252. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
  253. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
  254. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
  255. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
  256. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
  257. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
  258. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
  259. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
  260. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
  261. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
  262. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +194 -0
  263. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +263 -1
  264. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
  265. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +127 -2
  266. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
  267. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
  268. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
  269. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
  270. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
  271. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
  272. package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
  273. package/dist-sdk/server/src/tools/packs/index.js +66 -0
  274. package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
  275. package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
  276. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +107 -3
  277. package/dist-sdk/server/src/tools/tool-execution.service.js +163 -19
  278. package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
  279. package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
  280. package/dist-sdk/shared/types/app.types.d.ts +328 -13
  281. package/dist-sdk/shared/types/app.types.js +18 -1
  282. package/package.json +167 -168
  283. package/data/common/config/random_words.txt +0 -2241
  284. package/data/common/story_ideas/biblical.json +0 -122
  285. package/data/common/story_ideas/fantasy.json +0 -82
  286. package/data/common/story_ideas/historical_fiction.json +0 -82
  287. package/data/common/story_ideas/science_fiction.json +0 -82
  288. package/docs/.nojekyll +0 -1
  289. package/docs/assets/hierarchy.js +0 -1
  290. package/docs/assets/highlight.css +0 -113
  291. package/docs/assets/icons.js +0 -18
  292. package/docs/assets/icons.svg +0 -1
  293. package/docs/assets/main.js +0 -60
  294. package/docs/assets/navigation.js +0 -1
  295. package/docs/assets/search.js +0 -1
  296. package/docs/assets/style.css +0 -1648
  297. package/docs/classes/Agent.html +0 -801
  298. package/docs/classes/Briyah.html +0 -296
  299. package/docs/classes/BriyahConfigService.html +0 -119
  300. package/docs/classes/NativeToolRegistry.html +0 -166
  301. package/docs/classes/PackInstantiationService.html +0 -157
  302. package/docs/classes/PackService.html +0 -247
  303. package/docs/classes/Room.html +0 -1434
  304. package/docs/classes/RoomMessage.html +0 -290
  305. package/docs/enums/MessageAction.html +0 -136
  306. package/docs/functions/availableToolPacks.html +0 -41
  307. package/docs/functions/buildMarkdown.html +0 -54
  308. package/docs/functions/dnd5eTools.html +0 -44
  309. package/docs/functions/installToolPacks.html +0 -51
  310. package/docs/functions/pageMarker.html +0 -45
  311. package/docs/functions/registerToolPacks.html +0 -54
  312. package/docs/functions/splitMarkdownIntoPages.html +0 -51
  313. package/docs/functions/stripWrappingFence.html +0 -52
  314. package/docs/hierarchy.html +0 -46
  315. package/docs/index.html +0 -595
  316. package/docs/interfaces/AgentCreationOptions.html +0 -125
  317. package/docs/interfaces/AgentInfo.html +0 -218
  318. package/docs/interfaces/AgentMessagesResponse.html +0 -74
  319. package/docs/interfaces/AppService.html +0 -3340
  320. package/docs/interfaces/Artifact.html +0 -95
  321. package/docs/interfaces/ArtifactMetadata.html +0 -112
  322. package/docs/interfaces/ArtifactWriteOptions.html +0 -90
  323. package/docs/interfaces/AttachDocumentResponse.html +0 -62
  324. package/docs/interfaces/BriyahConfigOptions.html +0 -124
  325. package/docs/interfaces/ChapterInfo.html +0 -62
  326. package/docs/interfaces/Character.html +0 -86
  327. package/docs/interfaces/ConversionAgent.html +0 -78
  328. package/docs/interfaces/CreateAgentResponse.html +0 -56
  329. package/docs/interfaces/CreateRoomResponse.html +0 -62
  330. package/docs/interfaces/CreateStoryResponse.html +0 -56
  331. package/docs/interfaces/FileList.html +0 -56
  332. package/docs/interfaces/FileMetadata.html +0 -89
  333. package/docs/interfaces/IConfigService.html +0 -79
  334. package/docs/interfaces/InstantiateModels.html +0 -64
  335. package/docs/interfaces/InstantiateRoomResult.html +0 -70
  336. package/docs/interfaces/LoadedPack.html +0 -131
  337. package/docs/interfaces/LoggingOptions.html +0 -92
  338. package/docs/interfaces/Message.html +0 -84
  339. package/docs/interfaces/ModelChoice.html +0 -73
  340. package/docs/interfaces/ModelInfo.html +0 -74
  341. package/docs/interfaces/NativeToolDefinition.html +0 -107
  342. package/docs/interfaces/PackAgentTemplate.html +0 -101
  343. package/docs/interfaces/PackRoomTemplate.html +0 -108
  344. package/docs/interfaces/PackView.html +0 -172
  345. package/docs/interfaces/PdfConversionOptions.html +0 -102
  346. package/docs/interfaces/PdfConversionResult.html +0 -97
  347. package/docs/interfaces/PdfMarkdownOptions.html +0 -198
  348. package/docs/interfaces/PdfMarkdownResult.html +0 -106
  349. package/docs/interfaces/PdfPageMarkdown.html +0 -94
  350. package/docs/interfaces/PreparedPromptResponse.html +0 -62
  351. package/docs/interfaces/ProcessTextResponse.html +0 -86
  352. package/docs/interfaces/PromptFile.html +0 -70
  353. package/docs/interfaces/PromptFileContent.html +0 -76
  354. package/docs/interfaces/PromptFilesResponse.html +0 -56
  355. package/docs/interfaces/PromptFolder.html +0 -80
  356. package/docs/interfaces/PromptFolderDefaults.html +0 -155
  357. package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
  358. package/docs/interfaces/PromptFoldersResponse.html +0 -56
  359. package/docs/interfaces/RoomDetails.html +0 -151
  360. package/docs/interfaces/RoomErrorUpdate.html +0 -82
  361. package/docs/interfaces/RoomInfo.html +0 -88
  362. package/docs/interfaces/RoomMessageUpdate.html +0 -113
  363. package/docs/interfaces/RoomMessagesResponse.html +0 -62
  364. package/docs/interfaces/SendMessageResult.html +0 -62
  365. package/docs/interfaces/StoryErrorEvent.html +0 -84
  366. package/docs/interfaces/StoryIdea.html +0 -74
  367. package/docs/interfaces/StoryInfo.html +0 -198
  368. package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
  369. package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
  370. package/docs/interfaces/StoryState.html +0 -108
  371. package/docs/interfaces/StoryStateEvent.html +0 -76
  372. package/docs/interfaces/ToolArtifact.html +0 -85
  373. package/docs/interfaces/ToolCaller.html +0 -77
  374. package/docs/interfaces/ToolDefinition.html +0 -80
  375. package/docs/interfaces/ToolHelpers.html +0 -105
  376. package/docs/interfaces/ToolPackDocuments.html +0 -100
  377. package/docs/interfaces/ToolParameter.html +0 -74
  378. package/docs/interfaces/ToolRoomAccess.html +0 -260
  379. package/docs/interfaces/ToolSummary.html +0 -74
  380. package/docs/interfaces/ToolsResponse.html +0 -68
  381. package/docs/interfaces/Transaction.html +0 -104
  382. package/docs/interfaces/TransactionHistoryResponse.html +0 -62
  383. package/docs/modules.html +0 -53
  384. package/docs/types/PackOrigin.html +0 -34
  385. package/docs/types/PromptScope.html +0 -34
  386. package/docs/types/RoomTurnMode.html +0 -42
  387. package/docs/types/RoomUpdate.html +0 -36
  388. package/docs/types/RosterOverrides.html +0 -42
  389. package/docs/types/ToolContext.html +0 -40
  390. package/docs/types/ToolRunResult.html +0 -34
  391. package/src/tools/packs/dnd5e/README.md +0 -867
@@ -11,6 +11,7 @@ import { StoryStoreService } from './story/story-store.service';
11
11
  import { StoryService } from './story/story.service';
12
12
  import { UserPathsService } from './config/user-paths.service';
13
13
  import { PackService } from './packs/pack.service';
14
+ import { IllustrationService } from './room/illustration/illustration.service';
14
15
  import { PackInstantiationService } from './packs/pack-instantiation.service';
15
16
  import { RpgService } from './rpg/rpg.service';
16
17
  import { AttachedFileService } from './ai/attached-file.service';
@@ -25,33 +26,82 @@ import { AgentFactory } from './ai/agent-factory';
25
26
  import { RoomFactory } from './room/room-factory';
26
27
  import { EventEmitter } from 'events';
27
28
  import { PdfConversionOptions, PdfConversionResult } from './documents/pdf-conversion';
28
- import { AgentInfo, RoomInfo, RoomDetails, RoomTurnMode, CreateRoomResponse, CreateAgentResponse, CreateRoomAgentRequest, FileList, PromptFileContent, PromptFoldersResponse, PromptFilesResponse, PromptScope, PromptFolderDefaults, PromptFolderDefaultsResponse, ProcessTextResponse, PreparedPromptResponse, AttachDocumentResponse, AgentMessagesResponse, RoomMessagesResponse, SendMessageResult, StoryInfo, StoryState, Character, Transaction, TransactionHistoryResponse, ToolDefinition, ToolSummary, ToolRunResult } from '../../shared/types/app.types';
29
+ import { AgentInfo, RoomInfo, RoomDetails, RoomIllustrationMode, RoomTurnMode, CreateRoomResponse, CreateAgentResponse, CreateRoomAgentRequest, FileList, PromptFileContent, PromptFoldersResponse, PromptFilesResponse, PromptScope, PromptFolderDefaults, PromptFolderDefaultsResponse, ProcessTextResponse, PreparedPromptResponse, AttachDocumentResponse, AgentMessagesResponse, RoomMessagesResponse, SendMessageResult, StoryInfo, StoryState, Character, Transaction, TransactionHistoryResponse, ToolDefinition, ToolSummary, ToolRunResult } from '../../shared/types/app.types';
29
30
  import { RoomMessage } from './room/message';
30
31
  import { ToolStoreService } from './tools/tool-store.service';
31
32
  import { ToolExecutionService } from './tools/tool-execution.service';
33
+ /**
34
+ * Agent settings that {@link AppService.createAgent} takes as an object rather
35
+ * than a positional parameter.
36
+ *
37
+ * The positional list is public SDK surface and stops at ten, so everything since
38
+ * lives here. Each of these is also settable through {@link AppService.updateAgent},
39
+ * which is the point: an agent that needs a tool grant should not have to be
40
+ * created and then edited.
41
+ */
32
42
  export interface AgentCreationOptions {
43
+ /** Enable the provider's web search, where it has one. */
33
44
  allowSearch?: boolean;
45
+ /** Names of tools this agent may run with EXECUTE. */
34
46
  toolNames?: string[];
47
+ /**
48
+ * This agent sends MODERATE messages, so its room needs a moderator. For a
49
+ * human-controlled agent it also removes the action and target pickers from
50
+ * the room's composer. See {@link Agent.useModerator}.
51
+ */
35
52
  useModerator?: boolean;
53
+ /** Notes only this agent sees. */
36
54
  privateContext?: string;
55
+ /** Minutes to keep the prompt cache alive; above 5 selects the 1-hour cache. */
37
56
  promptCacheTTL?: number;
57
+ /** Rolling history window: keep only the last N messages. */
38
58
  maxHistoryMessages?: number;
59
+ /** A cheaper same-service model for mechanical prompts. */
39
60
  smallModelName?: string;
61
+ /**
62
+ * The room this agent exists for. An owned agent is left out of
63
+ * {@link AppService.listAgents} and deleted with its room.
64
+ */
40
65
  ownerRoomId?: string;
41
66
  }
67
+ /**
68
+ * How {@link AppService.convertPdfToMarkdownPages} should run.
69
+ *
70
+ * The limits are inherited from {@link PdfConversionOptions}; everything added
71
+ * here is about *which* agent does the converting and what it is told.
72
+ */
42
73
  export interface PdfMarkdownOptions extends PdfConversionOptions {
74
+ /** Overrides `DOC_CONVERSION_AI_SERVICE`. */
43
75
  aiServiceName?: string;
76
+ /** Overrides `DOC_CONVERSION_AI_MODEL`. */
44
77
  aiModel?: string;
78
+ /**
79
+ * The prompt folder holding the conversion prompt. Defaults to `pdf_converter`.
80
+ *
81
+ * A host with its own transcription prompt points at its own folder — including
82
+ * a pack-qualified one — and keeps Briyah's concurrency, retry and assembly.
83
+ */
45
84
  promptFolder?: string;
85
+ /** The prompt file within that folder. Defaults to `convert_pdf_page`. */
46
86
  promptFile?: string;
87
+ /** Shown in logs and cost reports. Defaults to `PDF Converter`. */
47
88
  agentName?: string;
48
89
  reasoningEffort?: 'low' | 'medium' | 'high' | null;
90
+ /** Noun phrase completing "Convert this page from ___", e.g. `a fleet schedule`. */
49
91
  documentType?: string;
92
+ /** What must survive verbatim, e.g. `chapter and verse numbers`. */
50
93
  fidelityHints?: string;
94
+ /** Plural noun for the document's records, e.g. `vehicle rows`. Adds a don't-drop warning. */
51
95
  rowNoun?: string;
96
+ /** Further Handlebars variables for a caller's own prompt. */
52
97
  variables?: Record<string, unknown>;
98
+ /**
99
+ * Finish each page's agent once it has answered. Defaults to true. Pass false
100
+ * when the caller wants to read costs off the agents and dispose of them itself.
101
+ */
53
102
  finishAgents?: boolean;
54
103
  }
104
+ /** A finished conversion, with the agents typed as Briyah's own. */
55
105
  export interface PdfMarkdownResult extends Omit<PdfConversionResult, 'agents'> {
56
106
  agents: Agent[];
57
107
  }
@@ -76,26 +126,188 @@ export declare class AppService {
76
126
  private readonly toolStore;
77
127
  private readonly toolExecution;
78
128
  private readonly packService;
129
+ private readonly illustration;
79
130
  private aiServices;
80
131
  private readonly userPreferencesFile;
81
- constructor(aiFactoryService: AiFactoryService, agentStore: AgentStoreService, agentMessageService: AgentMessageService, roomStore: RoomStoreService, roomMessageService: RoomMessageService, userPaths: UserPathsService, attachedFileService: AttachedFileService, artifactService: ArtifactService, storyStore: StoryStoreService, storyService: StoryService, publishedAgentsService: PublishedAgentsService, publishedRoomsService: PublishedRoomsService, balanceService: BalanceService, balanceMessageService: BalanceMessageService, transactionService: TransactionService, agentFactory: AgentFactory, roomFactory: RoomFactory, toolStore: ToolStoreService, toolExecution: ToolExecutionService, packService: PackService);
132
+ constructor(aiFactoryService: AiFactoryService, agentStore: AgentStoreService, agentMessageService: AgentMessageService, roomStore: RoomStoreService, roomMessageService: RoomMessageService, userPaths: UserPathsService, attachedFileService: AttachedFileService, artifactService: ArtifactService, storyStore: StoryStoreService, storyService: StoryService, publishedAgentsService: PublishedAgentsService, publishedRoomsService: PublishedRoomsService, balanceService: BalanceService, balanceMessageService: BalanceMessageService, transactionService: TransactionService, agentFactory: AgentFactory, roomFactory: RoomFactory, toolStore: ToolStoreService, toolExecution: ToolExecutionService, packService: PackService, illustration: IllustrationService);
133
+ /** Packs, as this user sees them. */
82
134
  get packs(): PackService;
83
135
  private packInstantiationService?;
136
+ /**
137
+ * Supplies the service that builds agents and rooms from pack templates.
138
+ *
139
+ * Set after construction rather than injected: it drives this service, so it
140
+ * cannot also be one of its constructor arguments.
141
+ */
84
142
  setPackInstantiation(service: PackInstantiationService): void;
143
+ /** Builds agents and rooms from pack templates. */
85
144
  get packInstantiation(): PackInstantiationService;
86
145
  private rpgCampaignService?;
146
+ /**
147
+ * Supplies the service that builds and reads campaigns.
148
+ *
149
+ * Set after construction for the same reason pack instantiation is: it drives
150
+ * this service, so it cannot also be one of its constructor arguments.
151
+ */
87
152
  setRpg(service: RpgService): void;
153
+ /** Campaigns: the streamlined D&D surface, built on packs and published rooms. */
88
154
  get rpg(): RpgService;
155
+ /**
156
+ * The packs this user has enabled, as a thunk.
157
+ *
158
+ * Handed to the prompt resolver and to every agent this service creates. A
159
+ * thunk rather than an array because both outlive a toggle — see
160
+ * {@link Agent.enabledPacks}.
161
+ */
89
162
  readonly enabledPacks: () => readonly string[];
163
+ /**
164
+ * Returns the names of all available AI service providers.
165
+ *
166
+ * Only providers that have a configured API key are included.
167
+ *
168
+ * @returns Array of provider names (e.g. `'Anthropic'`, `'OpenAI'`, `'GoogleAI'`)
169
+ */
90
170
  getAiServiceNames(): string[];
171
+ /**
172
+ * Returns the AI service instance for the given provider name.
173
+ *
174
+ * @internal Returns a framework-level service; SDK consumers should use
175
+ * {@link listAiModels} or higher-level methods rather than handling
176
+ * `BaseAiService` directly.
177
+ * @param serviceName - Provider name as returned by {@link getAiServiceNames}
178
+ * @returns The corresponding AI service instance
179
+ * @throws {Error} If the service name is not recognized
180
+ */
91
181
  getAiServiceFromServiceName(serviceName: string): BaseAiService;
182
+ /**
183
+ * Fetches available models from the specified AI service provider.
184
+ *
185
+ * @param aiServiceName - Provider name as returned by {@link getAiServiceNames}
186
+ * @returns Array of model descriptors including name, description, and service
187
+ */
92
188
  listAiModels(aiServiceName: string): Promise<ModelInfo[]>;
189
+ /**
190
+ * Returns models available for image generation, as configured in
191
+ * `common/config/image_models.json`.
192
+ *
193
+ * @returns Array of model descriptors. Returns an empty array if the config file is missing.
194
+ */
93
195
  listImageModels(): Promise<ImageModelOption[]>;
196
+ /**
197
+ * Returns models available for story generation, as configured in
198
+ * `common/config/story_models.json`.
199
+ *
200
+ * @returns Array of model descriptors. Returns an empty array if the config file is missing.
201
+ */
94
202
  listStoryModels(): Promise<ModelInfo[]>;
203
+ /**
204
+ * Returns the available story genre names.
205
+ *
206
+ * Genres are read from `common/story_ideas/` - each `.json` file corresponds to a genre.
207
+ * Pass a genre name to {@link getRandomStoryIdeaByGenre} to get a story idea.
208
+ *
209
+ * @returns Array of genre names (e.g. `['fantasy', 'sci-fi', 'mystery']`)
210
+ */
95
211
  listStoryGenres(): string[];
212
+ /**
213
+ * Returns a random story idea from the specified genre.
214
+ *
215
+ * @param genreName - Genre name as returned by {@link listStoryGenres} (e.g. `'fantasy'`)
216
+ * @returns A random `StoryIdea` object, or `null` if the genre file is empty
217
+ * @throws {NotFoundError} If the genre does not exist
218
+ * @throws {OperationFailedError} If the genre file cannot be read
219
+ */
96
220
  getRandomStoryIdeaByGenre(genreName: string): StoryIdea | null;
221
+ /**
222
+ * Returns a random story idea from a randomly selected genre.
223
+ *
224
+ * @returns A random `StoryIdea` object, or `null` if no genres/ideas are available
225
+ */
97
226
  getRandomStoryIdea(): StoryIdea | null;
227
+ /**
228
+ * Creates a new AI agent and registers it in memory.
229
+ *
230
+ * The agent is immediately findable by ID but **not** persisted to disk.
231
+ * Call `agent.save()` when you want to write it to storage.
232
+ *
233
+ * @param aiServiceName - Provider name (e.g. `'Anthropic'`, `'OpenAI'`). Use {@link getAiServiceNames} for valid values.
234
+ * @param agentName - Full name of the agent (used in conversation logs and file storage)
235
+ * @param agentNickname - Short display name shown in the UI
236
+ * @param description - Brief description of the agent's role or personality
237
+ * @param aiModel - Model identifier (e.g. `'claude-haiku-4-5'`, `'gpt-4o'`)
238
+ * @param promptName - Prompt folder under `data/prompts/` that provides the agent's system instruction. Defaults to `'default'`.
239
+ * @param controlledByHuman - If `true`, the agent's responses are driven by a human rather than the AI. Defaults to `false`.
240
+ * @param reasoningEffort - Extended-thinking effort level for models that support it (e.g. Claude 3.7 Sonnet, o1/o3). Pass `null` to disable. Defaults to `undefined` (model default).
241
+ * @param maxOutputTokens - Override the model's default maximum output token limit
242
+ * @param beginInstruction - Optional prompt stored with the agent and sent when the host app triggers a "Begin" action (e.g. `'Begin by reading the attached documents and asking the user the first question.'`)
243
+ * @param options - Everything else an agent can be created with: tool grants, private context, prompt cache TTL, search, the history window and the small-model override. Add new settings here rather than as further positional parameters.
244
+ * @returns The newly created {@link Agent} instance
245
+ *
246
+ * @example
247
+ * ```typescript
248
+ * const agent = appService.createAgent(
249
+ * 'Anthropic',
250
+ * 'AI Assistant',
251
+ * 'James',
252
+ * 'A helpful AI assistant',
253
+ * 'claude-haiku-4-5',
254
+ * );
255
+ * if (!agent.id) throw new Error('Agent creation failed');
256
+ * agent.save(); // persist to disk
257
+ * ```
258
+ */
98
259
  createAgent(aiServiceName: string, agentName: string, agentNickname: string, description: string, aiModel: string, promptName?: string, controlledByHuman?: boolean, reasoningEffort?: 'low' | 'medium' | 'high' | null, maxOutputTokens?: number, beginInstruction?: string, options?: AgentCreationOptions): Agent;
260
+ /**
261
+ * Creates an agent from a prompt folder, applying everything that folder declares.
262
+ *
263
+ * A folder's `defaults_config.json` names the role: what it is called, which tools
264
+ * it needs, which documents it carries. {@link createAgent} takes none of that —
265
+ * it takes eleven positional arguments and an options object, and leaves the
266
+ * mapping to the caller. Every caller then writes the same mapping: the web
267
+ * client's create-agent dialog, and every SDK host after it. Hard-coding the
268
+ * result instead is worse, because a pack's tool and document lists change and a
269
+ * transcribed copy does not.
270
+ *
271
+ * Differences from {@link createAgent}, each deliberate:
272
+ *
273
+ * - **It saves.** A convenience constructor that leaves the agent in memory only
274
+ * loses it on restart, which is not what a caller reaching for one expects.
275
+ * - **It attaches the folder's documents**, unless `attachDocuments` is false.
276
+ * {@link PromptFolderDefaults.documentIds} describes them as a pre-tick that
277
+ * stays the user's choice, which is right for a dialog where somebody can untick
278
+ * a box; headless there is nobody to untick, and a character creator without its
279
+ * class documents builds sheets with no spells and no class features.
280
+ * - **It is async**, only because attaching is.
281
+ *
282
+ * @param options.folder Prompt folder name, e.g. `'dungeon_master'`
283
+ * @param options.aiServiceName Provider name, e.g. `'Anthropic'`
284
+ * @param options.aiModel Model id for this agent
285
+ * @param options.overrides Fields to override the folder's declared defaults;
286
+ * the same shape, so `{agentNickname: 'Homer', controlledByHuman: true}` is all
287
+ * a human-controlled player needs
288
+ * @param options.attachDocuments Attach the folder's `documentIds` (default true)
289
+ * @returns The created, saved agent
290
+ * @throws {NotFoundError} If the folder does not exist. Unlike {@link createAgent},
291
+ * which warns and carries on, this refuses: the whole point of the call is the
292
+ * folder's recipe, and a folder that is not there has none — the agent would come
293
+ * out with no tools, no documents and the shared root prompts
294
+ * @throws {Error} If the agent could not be created
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * const dm = await appService.createAgentFromFolder({
299
+ * folder: 'dungeon_master',
300
+ * aiServiceName: 'Anthropic',
301
+ * aiModel: 'claude-sonnet-5',
302
+ * });
303
+ * const you = await appService.createAgentFromFolder({
304
+ * folder: 'dnd_player',
305
+ * aiServiceName: 'Anthropic',
306
+ * aiModel: 'claude-haiku-4-5',
307
+ * overrides: { agentNickname: 'Homer', controlledByHuman: true },
308
+ * });
309
+ * ```
310
+ */
99
311
  createAgentFromFolder(options: {
100
312
  folder: string;
101
313
  aiServiceName: string;
@@ -103,174 +315,1668 @@ export declare class AppService {
103
315
  overrides?: Partial<PromptFolderDefaults>;
104
316
  attachDocuments?: boolean;
105
317
  }): Promise<Agent>;
318
+ /**
319
+ * Sends a text prompt to an agent and returns its response.
320
+ *
321
+ * The exchange is added to the agent's conversation history and persisted to disk.
322
+ *
323
+ * @param agentId - The agent's ID (from {@link createAgent} or {@link listAgents})
324
+ * @param text - The prompt text to send
325
+ * @returns Object containing the agent's reply text (`result`), the latest formatted
326
+ * message, its index in the history, and cumulative token counts and cost
327
+ * @throws {NotFoundError} If no agent with the given ID exists
328
+ *
329
+ * @example
330
+ * ```typescript
331
+ * const result = await appService.processText(agent.id, 'What is the capital of France?');
332
+ * console.log(result.result); // 'Paris'
333
+ * console.log(result.totalCost); // e.g. 0.000023
334
+ * ```
335
+ */
106
336
  processText(agentId: string, text: string): Promise<ProcessTextResponse>;
337
+ /**
338
+ * Attaches a document to an agent so it can reference the file's contents in prompts.
339
+ *
340
+ * The file is stored on disk and uploaded to the AI provider if required
341
+ * (e.g. OpenAI file uploads, Grok file uploads). The agent state is persisted after attachment.
342
+ *
343
+ * @param agentId - The agent's ID
344
+ * @param fileName - File name including extension (e.g. `'report.pdf'`)
345
+ * @param fileData - Raw file bytes as a `Buffer`
346
+ * @returns Object containing a `documentId` that can be used with {@link deleteAttachedFileById}
347
+ * @throws {Error} If no agent with the given ID exists
348
+ */
107
349
  attachDocument(agentId: string, fileName: string, fileData: Buffer): Promise<AttachDocumentResponse>;
350
+ /**
351
+ * Returns every prompt folder name this user can reach.
352
+ *
353
+ * Covers the common and user prompt directories plus the folders of any pack
354
+ * the user has enabled, which appear pack-qualified (`dnd5e:dungeon_master`).
355
+ * A folder in more than one directory appears once.
356
+ *
357
+ * @returns Sorted array of folder names
358
+ */
108
359
  listPromptFolders(): string[];
360
+ /**
361
+ * Returns prompt folder names annotated with where they came from.
362
+ *
363
+ * When the same folder name exists in both the user and common directories the
364
+ * user copy wins and the entry reports `scope: 'user'`. A pack's folder is a
365
+ * separate entry under its qualified name, so a pack shipping a `witness`
366
+ * folder does not collide with a `witness` folder the user wrote.
367
+ *
368
+ * Pack folders are listed only for enabled packs. That is the difference
369
+ * between listing and resolving: a disabled pack's folder still resolves when
370
+ * an agent names it, it just stops being offered.
371
+ *
372
+ * @param scope - Optional filter: `'common'` returns only system-provided folders
373
+ * (including packs', which are read-only in the same way), `'user'` returns only
374
+ * the user's own folders and their pack overlays, omit to return all
375
+ * @returns Object with a `folders` array, sorted by name
376
+ */
109
377
  listPromptFoldersWithScope(scope?: PromptScope): PromptFoldersResponse;
378
+ /**
379
+ * Returns all prepared prompt template names available to a specific agent.
380
+ *
381
+ * Merges prompts from the agent's own prompt folder and the root prompts directory,
382
+ * deduplicating across both. These names can be passed to {@link runPreparedPrompt}.
383
+ *
384
+ * @param agentId - The agent's ID
385
+ * @returns Array of prompt template names (without file extension)
386
+ * @throws {NotFoundError} If no agent with the given ID exists
387
+ */
110
388
  listPrompts(agentId: string): Promise<string[]>;
389
+ /**
390
+ * Executes a named Handlebars prompt template against an agent.
391
+ *
392
+ * The template is loaded from the agent's prompt folder (with the standard 4-level
393
+ * fallback). `variables` are substituted into the template before sending.
394
+ *
395
+ * @param agentId - The agent's ID
396
+ * @param promptName - Template name returned by {@link listPrompts} (without extension)
397
+ * @param variables - Key-value pairs substituted into the template's `{{variable}}` placeholders
398
+ * @returns Object with a `result` string containing the agent's response
399
+ * @throws {NotFoundError} If no agent with the given ID exists
400
+ */
111
401
  runPreparedPrompt(agentId: string, promptName: string, variables?: any): Promise<PreparedPromptResponse>;
402
+ /**
403
+ * Lists all top-level agents belonging to this user.
404
+ *
405
+ * Agents that are owned by a room or story are excluded - use
406
+ * {@link getRoomDetails} or story methods to access those agents.
407
+ *
408
+ * @param includeRoomAgents - Also return the agents owned by a room or story.
409
+ * Only for offering an existing agent as something to copy; the agent list a
410
+ * user manages is the default, unowned one.
411
+ * @returns Array of agent metadata objects
412
+ */
112
413
  listAgents(includeRoomAgents?: boolean): Promise<AgentInfo[]>;
414
+ /**
415
+ * Returns detailed metadata for a specific agent.
416
+ *
417
+ * @param agentId - The agent's ID
418
+ * @returns Agent metadata object, or `null` if no agent with the given ID exists
419
+ */
113
420
  getAgentDetails(agentId: string): Promise<AgentInfo | null>;
421
+ /**
422
+ * Creates a new room and populates it with the specified agents.
423
+ *
424
+ * @param roomName - Display name for the room
425
+ * @param goal - Description of the room's purpose or objective, shared with all agents
426
+ * @param agentIds - IDs of the agents to add to the room. May be empty: a room
427
+ * is created before the agents that belong to it exist, and they are added
428
+ * afterwards with {@link createRoomAgent}.
429
+ * @param roomLeader - Nickname (or name) of the member agent to lead the room.
430
+ * Defaults to the first agent.
431
+ * @param turnMode - `'broadcast'` (default) prompts every agent for each message;
432
+ * `'directed'` prompts only the message's targets. See {@link RoomTurnMode}.
433
+ * @param moderator - Nickname of the agent that places messages the room cannot
434
+ * route mechanically. Only consulted in `'moderated'` mode.
435
+ * @returns Object containing the new `roomId`
436
+ * @throws {NotFoundError} If any agent ID does not exist
437
+ *
438
+ * @example
439
+ * ```typescript
440
+ * const { roomId } = await appService.createRoom(
441
+ * 'Research Session',
442
+ * 'Analyze the provided documents and produce a summary',
443
+ * [analystId, writerAgentId],
444
+ * );
445
+ * ```
446
+ */
447
+ /**
448
+ * Whether a prompt folder provides the `moderate.prompt` a moderator needs.
449
+ *
450
+ * The one definition of "could moderate", shared by the check that refuses a
451
+ * misconfigured room and the {@link AgentInfo.canModerate} the client picks a
452
+ * moderator with. Two definitions would eventually disagree, and the way they
453
+ * would show it is a room offering a moderator the server then rejects.
454
+ */
114
455
  private folderProvidesModeratePrompt;
456
+ /**
457
+ * Whether this agent could be a room's moderator.
458
+ *
459
+ * Both halves matter: moderating means answering a prompt, which a human agent
460
+ * never does, and it means having that prompt to answer.
461
+ */
115
462
  private canAgentModerate;
463
+ /**
464
+ * Why the room cannot moderate, or null when it can.
465
+ *
466
+ * "Can" is deliberately stronger than "a moderator is named". A moderator whose
467
+ * prompt folder has no `moderate.prompt` fails in the worst possible way: the
468
+ * prompt lookup throws, {@link Room} swallows the throw, and the message
469
+ * disappears leaving only a log line. Catching that here is the difference
470
+ * between an error the user can act on and a room that quietly eats messages.
471
+ *
472
+ * @param roster The membership to resolve the moderator against, which is not
473
+ * always the room's current one — an agent being added is checked before it
474
+ * arrives.
475
+ */
116
476
  private describeMissingModerator;
477
+ /**
478
+ * Refuses a configuration in which an agent that sends MODERATE messages has no
479
+ * moderator to route them.
480
+ *
481
+ * Checked when the combination can come into being — creating a room, adding an
482
+ * agent to one, changing a room's moderator, turning the flag on — and never on
483
+ * load, which would make an existing room unopenable rather than fixable.
484
+ *
485
+ * @param arriving An agent not yet in the room, checked as though it were.
486
+ */
117
487
  private assertModeratorAvailable;
118
- createRoom(roomName: string, goal: string, agentIds: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string): Promise<CreateRoomResponse>;
119
- editRoom(roomId: string, roomName: string, goal: string, baseRoomDir?: string, agentIds?: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string, pack?: string): Promise<void>;
488
+ createRoom(roomName: string, goal: string, agentIds: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string, beginInstruction?: string, imageModel?: string, illustrationMode?: RoomIllustrationMode): Promise<CreateRoomResponse>;
489
+ /**
490
+ * Updates the name, goal, and/or agent membership of an existing room.
491
+ *
492
+ * Published room instances cannot be edited - edit the template instead.
493
+ *
494
+ * @param roomId - The room's ID
495
+ * @param roomName - New display name
496
+ * @param goal - New goal description
497
+ * @param baseRoomDir - Optional override for the room's base storage directory
498
+ * @param agentIds - Replacement list of agent IDs (replaces current membership
499
+ * entirely). Omit to leave membership unchanged, which is what the client
500
+ * does: membership is managed through {@link createRoomAgent} and
501
+ * {@link removeRoomAgent}, not by re-sending the roster with every rename.
502
+ * @param roomLeader - Nickname (or name) of the member agent to lead the room.
503
+ * Omit to leave the current leader unchanged.
504
+ * @param turnMode - How the room chooses who responds. Omit to leave unchanged.
505
+ * See {@link RoomTurnMode}.
506
+ * @param moderator - Nickname of the moderator agent. Omit to leave unchanged.
507
+ * @param pack - The pack to file the room under. Empty string clears it.
508
+ * @param beginInstruction - What {@link beginRoom} sends to the leader. Empty
509
+ * string clears it, which withdraws the room's Begin. Omit to leave unchanged.
510
+ * @throws {NotFoundError} If the room does not exist
511
+ * @throws {OperationFailedError} If attempting to edit a published room instance
512
+ */
513
+ editRoom(roomId: string, roomName: string, goal: string, baseRoomDir?: string, agentIds?: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string, pack?: string, beginInstruction?: string, imageModel?: string, illustrationMode?: RoomIllustrationMode): Promise<void>;
514
+ /**
515
+ * Separates a room's name from the bare name of an agent that belongs to it.
516
+ */
120
517
  private static readonly ROOM_AGENT_SEPARATOR;
518
+ /**
519
+ * The stored name of an agent that belongs to a room.
520
+ *
521
+ * Every agent lives inside exactly one room, so an unqualified "Narrator" says
522
+ * nothing about which table it sits at once there are three of them.
523
+ */
121
524
  private static prefixedAgentName;
525
+ /**
526
+ * Strips a room-name prefix from an agent name, leaving the bare name.
527
+ * An agent that does not carry the prefix is returned unchanged.
528
+ */
122
529
  private static bareAgentName;
530
+ /**
531
+ * Re-prefixes the agents a renamed room owns.
532
+ *
533
+ * Only the display name moves. The nickname is what every handoff, target and
534
+ * tool call addresses an agent by, so renaming the room must not touch it.
535
+ */
123
536
  private renameOwnedAgents;
537
+ /**
538
+ * Creates an agent that belongs to a room and adds it to that room.
539
+ *
540
+ * This is the only way an agent joins a room. The agent is owned by it: it is
541
+ * left out of {@link listAgents} and deleted with the room, so a room is a
542
+ * self-contained cast rather than a set of references to a shared pool.
543
+ *
544
+ * `request.agentName` is the bare name. It is stored prefixed with the room's
545
+ * name, while the nickname is derived from the bare name — otherwise every
546
+ * agent in the room would be addressed by the room's first word.
547
+ *
548
+ * @param roomId - The room the agent will belong to
549
+ * @param request - The same fields {@link createAgent} takes
550
+ * @returns Object containing the new `agentId`
551
+ * @throws {NotFoundError} If the room does not exist
552
+ * @throws {OperationFailedError} If the room is a published instance, or another
553
+ * agent in the room already answers to the same nickname
554
+ */
124
555
  createRoomAgent(roomId: string, request: CreateRoomAgentRequest): Promise<CreateAgentResponse>;
556
+ /**
557
+ * Adds an agent to a room, built from a prompt folder's declared defaults.
558
+ *
559
+ * The room-scoped counterpart to {@link createAgentFromFolder}, and the piece a
560
+ * pack's room template is instantiated through. Everything a folder already
561
+ * declares — name, nickname, description, tool grants, documents, cache TTL —
562
+ * comes from its `defaults_config.json`, so a template only has to say what
563
+ * differs.
564
+ *
565
+ * Routed through {@link createRoomAgent} rather than {@link createAgentFromFolder},
566
+ * which does none of what a room member needs: the stored name is prefixed with
567
+ * the room's, the nickname is derived from the bare name, `ownerRoomId` is set,
568
+ * the moderator requirement is checked, and an agent whose nickname collides is
569
+ * removed again instead of being left behind belonging to a room it never joined.
570
+ *
571
+ * @param roomId - The room to add to
572
+ * @param options - The folder to build from, the model to use, and any overrides
573
+ * @returns The new agent's id, its resolved nickname, and any document ids that
574
+ * resolved to nothing — returned rather than swallowed, because a document that
575
+ * silently fails to attach is a capability the agent appears to have and does not
576
+ * @throws {NotFoundError} If the room does not exist, or the folder does not.
577
+ * See {@link createAgentFromFolder} for why a missing folder is fatal here
578
+ * @throws {ValidationError} If the agent needs a moderator the room does not have
579
+ * @throws {OperationFailedError} If the nickname is already taken in the room
580
+ */
125
581
  createRoomAgentFromFolder(roomId: string, options: {
126
582
  folder: string;
127
583
  aiServiceName: string;
128
584
  aiModel: string;
129
585
  smallModelName?: string;
130
586
  overrides?: Partial<PromptFolderDefaults>;
587
+ /** Files the new agent under a pack, so it is listed and hidden with it. */
131
588
  pack?: string;
589
+ /** The pack template's key, when this agent came from one. */
132
590
  packAgentKey?: string;
133
591
  }): Promise<{
134
592
  agentId: string;
135
593
  nickname: string;
136
594
  unresolvedDocumentIds: string[];
137
595
  }>;
596
+ /**
597
+ * Removes an agent from a room, and deletes it if the room owns it.
598
+ *
599
+ * @param roomId - The room's ID
600
+ * @param agentId - The agent's ID
601
+ * @throws {NotFoundError} If the room does not exist, or the agent is not in it
602
+ * @throws {OperationFailedError} If the room is a published instance
603
+ * @throws {ValidationError} If removing the moderator would leave an agent that
604
+ * sends MODERATE messages with nothing to route them
605
+ */
138
606
  removeRoomAgent(roomId: string, agentId: string): Promise<void>;
607
+ /**
608
+ * Lists the rooms this user builds and owns.
609
+ *
610
+ * Published instances are excluded — use {@link getPublishedRoomInstances} for
611
+ * those, which is also how the client reaches them.
612
+ *
613
+ * @returns Array of room summary objects (id, name, goal, agent count)
614
+ */
139
615
  listRooms(): Promise<RoomInfo[]>;
616
+ /**
617
+ * Returns full details for a room, including the metadata of each member agent.
618
+ *
619
+ * @param roomId - The room's ID
620
+ * @returns Room details object, or `null` if no room with the given ID exists
621
+ */
140
622
  getRoomDetails(roomId: string): Promise<RoomDetails | null>;
623
+ /**
624
+ * Returns the raw `Room` object for a given ID.
625
+ *
626
+ * Use {@link getRoomDetails} for a plain metadata object. This method exposes
627
+ * the full `Room` instance, which is useful for advanced operations.
628
+ *
629
+ * @param roomId - The room's ID
630
+ * @returns The `Room` instance, or `null` if not found
631
+ */
141
632
  getRoomById(roomId: string): Promise<Room | null>;
633
+ /**
634
+ * Sets which agent leads the room's conversation and persists the change.
635
+ *
636
+ * The room leader is given conversational authority in the default room
637
+ * prompts (other agents defer to it) and is consulted on adjournment.
638
+ *
639
+ * @param roomId - The room's ID
640
+ * @param agentNickname - Nickname of the member agent to make leader
641
+ * @throws {NotFoundError} If the room does not exist
642
+ */
142
643
  setRoomLeader(roomId: string, agentNickname: string): Promise<void>;
644
+ /**
645
+ * Returns messages from a room's conversation log starting from a given index.
646
+ *
647
+ * Pass the index of the last message you received as `fromIndex` to poll for
648
+ * new messages only.
649
+ *
650
+ * @param roomId - The room's ID
651
+ * @param fromIndex - Zero-based index to start from (default `0` returns all messages)
652
+ * @param includeThoughts - If `true`, includes `'think'` action messages which are
653
+ * normally hidden (agents' internal reasoning). Default `false`.
654
+ * @returns Object with the messages array and total cost across all agents.
655
+ * Returns empty messages with zero cost if the room is not found.
656
+ */
143
657
  getRoomMessages(roomId: string, fromIndex?: number, includeThoughts?: boolean): Promise<RoomMessagesResponse>;
658
+ /**
659
+ * Returns an agent's conversation history starting from a given index.
660
+ *
661
+ * Pass the `messageIndex` from a previous response as `fromIndex` to
662
+ * retrieve only new messages since the last poll.
663
+ *
664
+ * @param agentId - The agent's ID
665
+ * @param fromIndex - Zero-based index to start from (default `0` returns all messages)
666
+ * @returns Object with the messages array and cumulative token/cost totals.
667
+ * Returns empty messages with zero counts if the agent is not found.
668
+ */
144
669
  getAgentMessages(agentId: string, fromIndex?: number): Promise<AgentMessagesResponse>;
670
+ /**
671
+ * Gets messages from a story's room starting from a specific index
672
+ * @param storyId The story ID
673
+ * @param fromIndex The index to start from (0-based)
674
+ * @returns Array of indexed messages and total story cost
675
+ */
145
676
  getStoryMessages(storyId: string, fromIndex: number): Promise<RoomMessagesResponse>;
677
+ /**
678
+ * Adds a message to a room's pending queue to be processed by the agents.
679
+ *
680
+ * **Action values:**
681
+ * - `'moderate'` *(default)* - routes the message through the room's moderator (story rooms only)
682
+ * - `'speak'` - all agents hear the message; `targets` (if provided) restricts which agents may respond
683
+ * - `'whisper'` - only agents listed in `targets` hear the message
684
+ * - `'think'` - inaudible; stays only in the sender's history, not shown to other agents
685
+ * - `'shout'` - overrides all other conversations; all agents hear and respond
686
+ * - `'adjourn'` - signals intent to halt the conversation; the room adjourns once every agent agrees
687
+ *
688
+ * Anything else is sent as `'speak'`. To create an artifact use {@link publishArtifact}
689
+ * rather than this method.
690
+ *
691
+ * @param roomId - The room's ID
692
+ * @param content - The message text (or artifact body when `action` is `'publish'`)
693
+ * @param sender - Display name of the sender (e.g. `'User'`, `'System'`)
694
+ * @param action - Message action type (default `'moderate'`)
695
+ * @param targets - Agent names to receive or respond to the message (behavior varies by action)
696
+ * @param clearQueue - If `true`, clears any pending messages before adding this one. Default `false`.
697
+ * @returns Whether the message was accepted. A human agent's message is rejected
698
+ * (`accepted: false` with a `reason`) when it is not the human's turn to speak.
699
+ * @throws {NotFoundError} If the room does not exist
700
+ *
701
+ * @example
702
+ * ```typescript
703
+ * // Broadcast a message that all agents can respond to
704
+ * await appService.sendRoomMessage(roomId, 'Hello everyone!', 'User', 'speak');
705
+ *
706
+ * // Whisper to a specific agent
707
+ * const result = await appService.sendRoomMessage(roomId, 'Just between us...', 'User', 'whisper', ['James']);
708
+ * if (!result.accepted) {
709
+ * console.log(result.reason); // e.g. "It is James's turn to speak"
710
+ * }
711
+ * ```
712
+ */
146
713
  sendRoomMessage(roomId: string, content: string, sender: string, action?: string, targets?: string[], clearQueue?: boolean, context?: unknown): Promise<SendMessageResult>;
714
+ /**
715
+ * Opens a room by sending its begin instruction to the room leader.
716
+ *
717
+ * A room is pull-driven: an agent is prompted only when a message arrives. So a
718
+ * room nobody has spoken in never moves, however complete its configuration —
719
+ * which for a turn-based table means the leader is waiting to be asked to lead.
720
+ * This is the ask.
721
+ *
722
+ * Sent as `System` rather than as a person, and addressed by `targets` rather
723
+ * than left for the room to place: in `broadcast` mode an untargeted message
724
+ * prompts every agent, which for an opening move is one call per member to
725
+ * decide one reply.
726
+ *
727
+ * The already-begun check is here rather than left to the client because a
728
+ * published room is one link the whole party holds. Two people looking at the
729
+ * same empty transcript both press Begin, and only a check the room makes
730
+ * itself stops the leader being opened twice. `isProcessingInProgress()` is the
731
+ * half of it that covers the window before the first message lands.
732
+ *
733
+ * @param roomId - The room's ID
734
+ * @param context - Opaque host value threaded to any tool the turn invokes
735
+ * @returns Whether the message was accepted, as {@link sendRoomMessage} reports it
736
+ * @throws {NotFoundError} If the room does not exist
737
+ * @throws {ValidationError} If the room has no begin instruction, or no agent to address
738
+ * @throws {OperationFailedError} If the room has already begun
739
+ */
740
+ beginRoom(roomId: string, context?: unknown): Promise<SendMessageResult>;
741
+ /**
742
+ * Pauses message processing in a room.
743
+ *
744
+ * Pending messages remain in the queue. Call {@link resumeRoom} to continue processing.
745
+ *
746
+ * @param roomId - The room's ID
747
+ * @throws {NotFoundError} If the room does not exist
748
+ */
147
749
  pauseRoom(roomId: string): Promise<void>;
750
+ /**
751
+ * Resumes message processing in a room that was previously paused.
752
+ *
753
+ * @param roomId - The room's ID
754
+ * @throws {NotFoundError} If the room does not exist
755
+ */
148
756
  resumeRoom(roomId: string): Promise<void>;
757
+ /**
758
+ * Permanently deletes an agent and all its stored data.
759
+ *
760
+ * If the agent is a published instance, its entry is also removed from the
761
+ * published agents mapping.
762
+ *
763
+ * @param agentId - The agent's ID
764
+ * @throws {NotFoundError} If no agent with the given ID exists
765
+ */
149
766
  deleteAgent(agentId: string): Promise<void>;
767
+ /**
768
+ * Creates a publicly accessible clone of a template agent.
769
+ *
770
+ * The new instance is independent of the template's conversation history.
771
+ * Multiple instances can be created from a single template. Use
772
+ * {@link resetPublishedInstance} to restore an instance to the template's
773
+ * current state.
774
+ *
775
+ * @param templateId - ID of the template agent to clone
776
+ * @param instanceName - Display name for the new instance
777
+ * @returns Object with the new `instanceId` and the `publicUrl` path
778
+ * @throws {NotFoundError} If the template agent does not exist
779
+ * @see {@link getPublishedInstances}
780
+ * @see {@link resetPublishedInstance}
781
+ */
150
782
  publishAgentInstance(templateId: string, instanceName: string): Promise<{
151
783
  instanceId: string;
152
784
  publicUrl: string;
153
785
  }>;
786
+ /**
787
+ * Returns all published instances created from a template agent.
788
+ *
789
+ * @param templateId - ID of the template agent
790
+ * @returns Array of agent metadata objects for each published instance
791
+ * @see {@link publishAgentInstance}
792
+ */
154
793
  getPublishedInstances(templateId: string): Promise<AgentInfo[]>;
794
+ /**
795
+ * Resets a published agent instance to its template's current state.
796
+ *
797
+ * Clears the instance's conversation history and regenerates it from
798
+ * the template agent. Does not affect the template itself.
799
+ *
800
+ * @param instanceId - ID of the published instance to reset
801
+ * @throws {NotFoundError} If the instance does not exist
802
+ * @throws {OperationFailedError} If the agent is not a published instance
803
+ */
155
804
  resetPublishedInstance(instanceId: string): Promise<void>;
805
+ /**
806
+ * Lists all published agent instances belonging to this user.
807
+ *
808
+ * Published agents are clones of template agents that are accessible
809
+ * via the public API (e.g. for end-users to chat with). Agents owned
810
+ * by rooms are excluded from this list.
811
+ *
812
+ * @returns Array of agent metadata objects for all published instances
813
+ * @see {@link publishAgentInstance}
814
+ */
156
815
  listPublishedAgents(): Promise<AgentInfo[]>;
816
+ /**
817
+ * Permanently deletes a room and all its data.
818
+ *
819
+ * If the room is a template, all of its published instances are deleted first.
820
+ * The agents the room owns, its attached files and its published room mapping
821
+ * are also cleaned up.
822
+ *
823
+ * @param roomId - The room's ID
824
+ * @throws {NotFoundError} If the room does not exist
825
+ * @throws {OperationFailedError} If deletion fails
826
+ */
157
827
  deleteRoom(roomId: string): Promise<void>;
828
+ /**
829
+ * Creates a publicly accessible clone of a template room.
830
+ *
831
+ * The instance is a full copy of the template including all agents.
832
+ * Use {@link resetPublishedRoomInstance} to restore it to the template's state.
833
+ *
834
+ * @param templateId - ID of the template room to clone
835
+ * @param publishedName - Display name for the instance (defaults to the template's name)
836
+ * @param userId - The owning user's ID (used for public access mapping)
837
+ * @returns The new instance's room ID
838
+ * @throws {NotFoundError} If the template room does not exist
839
+ */
158
840
  publishRoom(templateId: string, publishedName: string | undefined, userId: string): Promise<string>;
841
+ /**
842
+ * Summarizes a room for a listing.
843
+ *
844
+ * The cost is summed from the room's agents rather than held on the room —
845
+ * the same sum {@link getRoomMessages} reports, so the two never disagree.
846
+ * @param room - The room to summarize
847
+ * @returns The room's summary
848
+ */
159
849
  private static toRoomInfo;
850
+ /**
851
+ * Returns all published instances created from a template room.
852
+ *
853
+ * @param templateId - ID of the template room
854
+ * @returns Array of room summary objects for each published instance
855
+ * @see {@link publishRoom}
856
+ */
160
857
  getPublishedRoomInstances(templateId: string): Promise<RoomInfo[]>;
858
+ /**
859
+ * Lists every published room instance this user owns.
860
+ *
861
+ * The room counterpart to {@link listPublishedAgents}, and the only view of
862
+ * them that is not filtered by which template they came from — a published
863
+ * room is a live public link, and the point of the list is seeing all of them
864
+ * and what they have cost.
865
+ *
866
+ * @returns Array of room summary objects, one per published instance
867
+ */
161
868
  listPublishedRooms(): Promise<RoomInfo[]>;
869
+ /**
870
+ * Resets a published room instance to a clean state.
871
+ *
872
+ * Clears the instance's messages and artifacts, and resets all of its
873
+ * cloned agents to their template state. Does not affect the template room.
874
+ *
875
+ * @param instanceId - ID of the published room instance to reset
876
+ * @throws {NotFoundError} If the instance does not exist
877
+ * @throws {OperationFailedError} If the room is not a published instance
878
+ */
162
879
  resetPublishedRoomInstance(instanceId: string): Promise<void>;
880
+ /**
881
+ * Returns the user's stored preferences object.
882
+ *
883
+ * Preferences are application-defined - Briyah stores and returns them as-is.
884
+ * Returns `{}` if no preferences have been saved yet.
885
+ *
886
+ * @returns The preferences object previously written by {@link saveUserPreferences},
887
+ * or an empty object if none exist
888
+ */
163
889
  getUserPreferences(): any;
890
+ /**
891
+ * Persists the user's preferences object to disk.
892
+ *
893
+ * The shape of `preferences` is application-defined. Pass any serializable object;
894
+ * it will be stored as JSON and returned verbatim by {@link getUserPreferences}.
895
+ *
896
+ * @param preferences - Serializable preferences object to store
897
+ */
164
898
  saveUserPreferences(preferences: any): void;
899
+ /**
900
+ * Returns the names of all prompt files in a folder, merged from both the common
901
+ * and user prompt directories.
902
+ *
903
+ * Pass `'shared'` as `folderName` to list files in the root prompts directory.
904
+ * Files that exist in both directories appear once in the result.
905
+ *
906
+ * @param folderName - Folder to list, or `'shared'` for the root prompts directory
907
+ * @returns Object with a `files` array of base names (no extension), sorted alphabetically
908
+ */
165
909
  listPromptFiles(folderName: string): FileList;
910
+ /**
911
+ * Returns prompt file names in a folder annotated with their origin scope.
912
+ *
913
+ * When the same file name exists in both the common and user directories,
914
+ * the user copy wins and the entry is reported as `scope: 'user'`.
915
+ * Pass `'shared'` as `folderName` to list files in the root prompts directory.
916
+ *
917
+ * @param folderName - Folder to list, or `'shared'` for the root prompts directory
918
+ * @returns Object with a `files` array of `{ name, scope }` entries, sorted alphabetically
919
+ */
166
920
  listPromptFilesWithScope(folderName: string): PromptFilesResponse;
921
+ /**
922
+ * Reads a prompt file, applying the shared lookup order (`prompt-resolver.ts`).
923
+ *
924
+ * For a bare folder that is the historical four levels — `user/{folder}`,
925
+ * `user/root`, `common/{folder}`, `common/root` — plus the folders of any pack
926
+ * this user has enabled. For a pack-qualified folder (`dnd5e:battle_master`) it
927
+ * is the pack's own tiers, then the shared roots.
928
+ *
929
+ * The returned `scope` collapses the four tiers onto the two the client knows:
930
+ * a pack overlay reports `'user'`, a pack's own file reports `'common'`. `pack`
931
+ * and `tier` carry the detail, and are populated even when the reference was
932
+ * bare. Returns `{ content: '' }` if the file does not exist in any location.
933
+ *
934
+ * @param folderName - Prompt folder name, `'shared'` for the root prompts directory,
935
+ * or a pack-qualified name like `dnd5e:dungeon_master`
936
+ * @param fileName - Base name of the prompt file (with or without `.prompt`/`.json` extension)
937
+ * @returns `{ content, scope, pack, tier }` where all but `content` are omitted when not found
938
+ */
167
939
  getPromptFile(folderName: string, fileName: string): PromptFileContent;
940
+ /**
941
+ * Reads a prompt folder's `defaults_config.json` — the agent settings the create-agent
942
+ * form pre-fills when that folder is chosen.
943
+ *
944
+ * Resolved through the same 4-level fallback as any other prompt file, so a user copy
945
+ * overrides the shipped one and a file at the prompts root supplies defaults for every
946
+ * folder that has none of its own.
947
+ *
948
+ * A missing file and an unparseable one both return `{ defaults: {} }`: defaults are a
949
+ * convenience, and a folder must stay usable when its config is broken. Unparseable is
950
+ * logged; missing is not, since most folders have no config at all.
951
+ *
952
+ * Every field is coerced to its declared type and unknown keys are dropped, so a typo
953
+ * in a hand-edited file cannot ride through to the create-agent request.
954
+ *
955
+ * @param folderName - Prompt folder name, or `'shared'` for the root prompts directory
956
+ * @returns The declared defaults, and the scope the file was read from
957
+ */
168
958
  getPromptFolderDefaults(folderName: string): PromptFolderDefaultsResponse;
959
+ /**
960
+ * Whether a prompt folder reference reaches a folder that exists.
961
+ *
962
+ * The check every "build an agent from a folder" path makes before it builds
963
+ * one: a reference that reaches nothing does not fail, it falls back to the
964
+ * shared root prompts and produces a generic conversational agent. A bare name
965
+ * for a pack this user has not enabled counts as not existing, because that is
966
+ * how it will behave.
967
+ *
968
+ * @param folderName - Prompt folder name, bare or `pack:folder`
969
+ * @returns True when the folder exists, or names the prompts root
970
+ */
169
971
  promptFolderExists(folderName: string): boolean;
972
+ /**
973
+ * Refuses a prompt folder that reaches nothing, naming the likely cause.
974
+ *
975
+ * @param folderName - The folder the caller asked for
976
+ * @throws {NotFoundError} If no tier has the folder
977
+ */
170
978
  private requirePromptFolder;
979
+ /**
980
+ * Writes content to a prompt file in the user prompt directory.
981
+ *
982
+ * Always saves to the user directory - common prompt files are never overwritten.
983
+ * If the target folder does not exist it is created automatically.
984
+ * Passing `'shared'` as `folderName` writes to the root user prompts directory.
985
+ *
986
+ * Special case: passing an empty `content` for a `'json'` file deletes the file
987
+ * rather than writing an empty document.
988
+ *
989
+ * @param folderName - Prompt folder name, or `'shared'` for the root user prompts directory
990
+ * @param fileName - Base name of the file (without extension)
991
+ * @param content - File content to write
992
+ * @param fileType - `'prompt'` (writes a `.prompt` file) or `'json'` (writes a `.json` file)
993
+ */
171
994
  savePromptFile(folderName: string, fileName: string, content: string, fileType: string): void;
995
+ /**
996
+ * Deletes a prompt file from the user prompts directory.
997
+ *
998
+ * Removes both the `.prompt` and `.json` variants if they exist.
999
+ * This is a no-op if neither file is present.
1000
+ *
1001
+ * @param folderName - Prompt folder name, or `'shared'` for the root prompts directory
1002
+ * @param fileName - Base name of the file to delete (without extension)
1003
+ */
172
1004
  deletePromptFile(folderName: string, fileName: string): void;
1005
+ /**
1006
+ * Returns all artifacts published in a room.
1007
+ *
1008
+ * Artifacts are collaborative documents created by agents via the `'publish'` action.
1009
+ *
1010
+ * @param roomId - The room's ID
1011
+ * @returns Object with an `artifacts` array. Returns `{ artifacts: [] }` if the room is not found.
1012
+ * @see {@link publishArtifact}
1013
+ */
173
1014
  getRoomArtifacts(roomId: string): Promise<{
174
1015
  artifacts: any[];
175
1016
  }>;
1017
+ /**
1018
+ * Programmatically publishes an artifact to a room.
1019
+ *
1020
+ * This is the imperative equivalent of an agent sending a `'publish'` action message.
1021
+ * Agents in the room can read and reference the artifact in subsequent prompts.
1022
+ *
1023
+ * @param roomId - The room's ID
1024
+ * @param name - Artifact name (unique within the room)
1025
+ * @param creator - Display name of the creator
1026
+ * @param body - The artifact's text content
1027
+ * @param viewers - Agent names that can view this artifact (empty array = all agents)
1028
+ * @throws {NotFoundError} If the room does not exist
1029
+ * @throws {OperationFailedError} If `name` is empty
1030
+ */
176
1031
  publishArtifact(roomId: string, name: string, creator: string, body: string, viewers?: string[]): Promise<void>;
1032
+ /**
1033
+ * Creates a new prompt folder in the user prompts directory.
1034
+ *
1035
+ * An empty `system_instruction.prompt` file is created inside the folder so that
1036
+ * it is immediately usable as a prompt source for agents.
1037
+ *
1038
+ * @param folderName - Name of the folder to create
1039
+ * @throws {OperationFailedError} If a folder with that name already exists
1040
+ */
177
1041
  createPromptFolder(folderName: string): void;
1042
+ /**
1043
+ * Deletes a prompt folder and all its contents from the user prompts directory.
1044
+ *
1045
+ * Only user-owned folders can be deleted; common folders are not affected.
1046
+ *
1047
+ * @param folderName - Name of the folder to delete
1048
+ * @throws {OperationFailedError} If `folderName` is `'shared'`
1049
+ * @throws {NotFoundError} If the folder does not exist in the user prompts directory
1050
+ */
178
1051
  deletePromptFolder(folderName: string): void;
1052
+ /**
1053
+ * Updates one or more properties of an existing agent and persists the changes.
1054
+ *
1055
+ * Only fields that are present in the `updates` object are changed;
1056
+ * omitted fields are left as-is.
1057
+ *
1058
+ * @param agentId - The agent's ID
1059
+ * @param updates - Fields to update:
1060
+ * - `agentNickname` - short display name
1061
+ * - `description` - role or personality description
1062
+ * - `modelName` - model identifier (e.g. `'claude-haiku-4-5'`)
1063
+ * - `reasoningEffort` - `'low' | 'medium' | 'high' | null`
1064
+ * - `isControlledByHuman` - whether a human drives this agent's responses
1065
+ * - `maxOutputTokens` - override the model's default output token limit
1066
+ * - `allowSearch` - enable web search capability (provider must support it)
1067
+ * - `beginInstruction` - prompt sent when the host app triggers a "Begin" action
1068
+ * @throws {NotFoundError} If no agent with the given ID exists
1069
+ */
179
1070
  updateAgent(agentId: string, updates: UpdateAgentRequest): Promise<void>;
1071
+ /**
1072
+ * Renames an agent, and repoints every room that named it.
1073
+ *
1074
+ * The manual counterpart to `ToolRoomAccess.renameAgent`. That one is
1075
+ * synchronous by contract and so fixes only the room it runs in, which is
1076
+ * complete for a room-owned agent; this path reaches an agent shared across
1077
+ * several rooms, where a rename would otherwise leave the other rooms pointing
1078
+ * at a nickname nobody answers to — including their leader, and the `viewers`
1079
+ * of every artifact the agent could read.
1080
+ *
1081
+ * Every room is checked before any is changed. A rename applied to two rooms
1082
+ * and refused by a third would leave the agent named one thing and half its
1083
+ * rooms naming another, which is worse than not renaming at all.
1084
+ *
1085
+ * @param agent The agent to rename
1086
+ * @param newName The new name; the routing nickname is its first word
1087
+ * @throws {ValidationError} If any room it sits in already has that name
1088
+ */
180
1089
  private renameAgentEverywhere;
1090
+ /**
1091
+ * Whether this deployment permits users to author and run their own tools.
1092
+ * Native (host-registered) tools are always available regardless.
1093
+ */
181
1094
  get userAuthoredToolsEnabled(): boolean;
1095
+ /**
1096
+ * Lists user-authored tools (with code). Empty when authoring is disabled.
1097
+ *
1098
+ * @returns Array of user-authored tool definitions
1099
+ */
182
1100
  listTools(): Promise<ToolDefinition[]>;
1101
+ /**
1102
+ * Lists native (host-registered) tools as code-free summaries. These are
1103
+ * grantable to agents but not editable through the API.
1104
+ *
1105
+ * @returns Array of native tool summaries
1106
+ */
1107
+ /**
1108
+ * Keeps grants the client could not have seen when it built its list.
1109
+ *
1110
+ * The edit form sends the whole grant list, and it filters that list against the
1111
+ * tools it was offered. Those are only the tools of the packs this user has
1112
+ * enabled — so opening an agent whose pack is off and pressing Save would send a
1113
+ * list with every one of its grants missing, and the agent would lose them for
1114
+ * good with nothing said.
1115
+ *
1116
+ * The server cannot tell "the user removed it" from "the client never saw it" by
1117
+ * looking at the list, so it looks at the tool instead: a name the user could not
1118
+ * have been offered is kept, and a name they could have been offered is theirs to
1119
+ * remove. A grant for a tool nothing registers at all is also kept, since the
1120
+ * form drops those from its list too.
1121
+ *
1122
+ * @param current The agent's grants before the update
1123
+ * @param requested The grants the client sent
1124
+ * @returns The grants to store
1125
+ */
183
1126
  private preserveHiddenGrants;
1127
+ /**
1128
+ * Native tools this user may grant.
1129
+ *
1130
+ * Filtered to the packs they have enabled. Two kinds are always listed: a tool
1131
+ * with no `group`, registered by the host directly rather than by a pack, and a
1132
+ * **core** tool, which belongs to the engine rather than to a domain and so has
1133
+ * no pack to enable. Filtering core out would hide `rename_agent` from every
1134
+ * user permanently, since `core` never appears in anyone's enabled list.
1135
+ *
1136
+ * Listing only. {@link ToolExecutionService} and `Room.buildAvailableTools`
1137
+ * deliberately do not filter, so disabling a pack hides its tools from the
1138
+ * pickers without stopping an agent that already holds one from calling it.
1139
+ *
1140
+ * @returns Code-free summaries of the grantable native tools
1141
+ */
184
1142
  listNativeToolSummaries(): ToolSummary[];
1143
+ /**
1144
+ * Creates a new user-authored tool.
1145
+ *
1146
+ * @param tool - The tool definition to create
1147
+ * @returns The created tool definition
1148
+ * @throws {OperationFailedError} If authoring is disabled or the name already exists
1149
+ */
185
1150
  createTool(tool: ToolDefinition): Promise<ToolDefinition>;
1151
+ /**
1152
+ * Updates an existing user-authored tool.
1153
+ *
1154
+ * @param name - The tool's name
1155
+ * @param tool - The updated tool definition
1156
+ * @returns The saved tool definition
1157
+ * @throws {NotFoundError} If the tool does not exist
1158
+ * @throws {OperationFailedError} If authoring is disabled
1159
+ */
186
1160
  updateTool(name: string, tool: ToolDefinition): Promise<ToolDefinition>;
1161
+ /**
1162
+ * Deletes a user-authored tool. Agents granted the tool keep the (now dangling)
1163
+ * grant; the room silently drops missing tools from their prompts.
1164
+ *
1165
+ * @param name - The tool's name
1166
+ * @throws {NotFoundError} If the tool does not exist
1167
+ * @throws {OperationFailedError} If authoring is disabled
1168
+ */
187
1169
  deleteTool(name: string): Promise<void>;
188
1170
  private assertUserAuthoringAllowed;
1171
+ /**
1172
+ * Runs a tool with the given arguments for testing from the Tools page.
1173
+ * Failures are returned in-band as `{ ok: false, error }`.
1174
+ *
1175
+ * @param name - The tool's name
1176
+ * @param args - Named arguments for the tool
1177
+ * @returns The tool run result
1178
+ */
189
1179
  testTool(name: string, args: Record<string, any>): Promise<ToolRunResult>;
1180
+ /**
1181
+ * Lists the files currently attached to an agent.
1182
+ *
1183
+ * @param agentId - The agent's ID
1184
+ * @returns Object with a `files` array of file names. Returns `{ files: [] }` if the agent is not found.
1185
+ */
190
1186
  listAttachedFiles(agentId: string): Promise<FileList>;
1187
+ /**
1188
+ * Removes a file from an agent by its file name.
1189
+ *
1190
+ * Deletes the file from storage and updates the agent's metadata.
1191
+ * Use {@link deleteAttachedFileById} if you have the document ID instead.
1192
+ *
1193
+ * @param agentId - The agent's ID
1194
+ * @param fileName - Name of the file to remove (e.g. `'report.pdf'`)
1195
+ * @throws {NotFoundError} If the agent or file is not found
1196
+ */
191
1197
  deleteAttachedFile(agentId: string, fileName: string): Promise<void>;
1198
+ /**
1199
+ * Removes an attached file by its document ID (as returned by {@link attachDocument}).
1200
+ *
1201
+ * Searches all agents to locate the owner, removes the file from storage,
1202
+ * and updates the agent's metadata.
1203
+ *
1204
+ * @param documentId - The `documentId` returned by {@link attachDocument}
1205
+ * @throws {NotFoundError} If no file with the given ID exists
1206
+ * @throws {OperationFailedError} If deletion fails
1207
+ */
192
1208
  deleteAttachedFileById(documentId: string): Promise<void>;
1209
+ /**
1210
+ * Clears an agent's conversation history while preserving its configuration
1211
+ * and re-attaching any previously uploaded files.
1212
+ *
1213
+ * Useful for starting a fresh conversation without recreating the agent.
1214
+ * If the history begins with a summary block (from a prior compaction), only
1215
+ * messages after the summary are cleared.
1216
+ *
1217
+ * @param agentId - The agent's ID
1218
+ * @throws {NotFoundError} If no agent with the given ID exists
1219
+ */
193
1220
  reloadAgent(agentId: string): Promise<void>;
1221
+ /**
1222
+ * Compacts an agent's conversation history into a single summary message.
1223
+ * Uses the `compact_agent` prompt (role folder first, common-root as fallback).
1224
+ *
1225
+ * @param agentId - The agent's ID
1226
+ * @throws {NotFoundError} If no agent with the given ID exists
1227
+ */
194
1228
  compactAgentConversation(agentId: string): Promise<void>;
1229
+ /**
1230
+ * Clears a room's message history and artifacts, and resets all member agents.
1231
+ *
1232
+ * Agent configurations (model, prompt, files) are preserved; only conversation
1233
+ * history and artifacts are removed.
1234
+ *
1235
+ * @param roomId - The room's ID
1236
+ * @throws {NotFoundError} If the room does not exist
1237
+ */
195
1238
  resetRoom(roomId: string): Promise<void>;
1239
+ /**
1240
+ * Resets a story to the beginning while preserving artifacts and the opening scene.
1241
+ *
1242
+ * If a chapter 1 backup exists, agents are restored from it; otherwise their
1243
+ * conversation histories are cleared. The list of declined characters is also cleared.
1244
+ *
1245
+ * @param storyId - The story's ID
1246
+ * @throws {NotFoundError} If the story or its room does not exist
1247
+ */
196
1248
  resetStory(storyId: string): Promise<void>;
1249
+ /**
1250
+ * Reverts the most recent chapter progression for a story. Restores room
1251
+ * messages, artifacts, and agent histories from the previous chapter
1252
+ * backup, then deletes that backup. Only valid when the current chapter
1253
+ * has not been played past the opening scene.
1254
+ *
1255
+ * @param storyId - The story's ID
1256
+ * @throws {NotFoundError} If the story or its room does not exist
1257
+ * @throws {OperationFailedError} If revert is not currently valid
1258
+ */
197
1259
  revertStoryChapter(storyId: string): Promise<void>;
1260
+ /**
1261
+ * Creates a new interactive story with AI-driven characters.
1262
+ *
1263
+ * When this method returns, the story is **immediately playable**: brief character
1264
+ * backgrounds and the opening scene have already been generated. A background job
1265
+ * then generates the detailed plot plan and full character profiles; subscribe to
1266
+ * {@link getStoryProgressEmitter} to be notified when that finishes (`step === 'complete'`),
1267
+ * but there is no need to wait for it before letting the player interact.
1268
+ *
1269
+ * @param name - Display name for the story
1270
+ * @param idea - Brief premise or concept for the story
1271
+ * @param userCharacterDesc - Description of the character the human player will portray
1272
+ * @param otherCharactersDesc - Description of other prominent characters to generate
1273
+ * @param storyModel - Model identifier from `story_models.json` (e.g. `'claude-haiku-4-5'`). Defaults to the configured default.
1274
+ * @param isImport - Set `true` when reconstructing a story from exported data. Default `false`.
1275
+ * @param imageModelName - Optional image model name from image_models.json (supplies both the generation and editing models)
1276
+ * @param skipDetailedPlot - Set `true` to generate a simple plot scenario instead of a detailed plot plan with secrets, twists, and events. Default `false`.
1277
+ * @returns Story metadata including the new `id` - story is ready to play immediately
1278
+ *
1279
+ * @example
1280
+ * ```typescript
1281
+ * // Story is playable as soon as createStory returns
1282
+ * const story = await appService.createStory(
1283
+ * 'The Lost Kingdom',
1284
+ * 'A medieval fantasy adventure',
1285
+ * 'A young knight seeking redemption',
1286
+ * 'A wise wizard and a cunning rogue',
1287
+ * );
1288
+ *
1289
+ * // Optionally listen for background completion (plot plan + detailed profiles)
1290
+ * const emitter = appService.getStoryProgressEmitter(story.id);
1291
+ * emitter?.on('progress', ({ step, message }) => {
1292
+ * if (step === 'complete') console.log('Background setup finished');
1293
+ * });
1294
+ * ```
1295
+ */
198
1296
  createStory(name: string, idea: string, userCharacterDesc: string, otherCharactersDesc: string, illustrateStory: boolean, storyModel?: string, isImport?: boolean, imageModelName?: string, skipDetailedPlot?: boolean): Promise<StoryInfo>;
1297
+ /**
1298
+ * Reconstructs a story from a previously exported zip archive.
1299
+ *
1300
+ * @param zipBuffer - Raw bytes of the zip file produced by {@link exportStoryData}
1301
+ * @returns Story metadata for the newly imported story
1302
+ */
199
1303
  importStoryFromZip(zipBuffer: Buffer): Promise<StoryInfo>;
1304
+ /**
1305
+ * Returns the `EventEmitter` for tracking background story work.
1306
+ *
1307
+ * Subscribe to the `'progress'` event. Each event payload is
1308
+ * `{ step: string, message: string, timestamp: number }`.
1309
+ *
1310
+ * **`step` values emitted after {@link createStory} returns:**
1311
+ *
1312
+ * The story is already playable when `createStory` returns. There is no `'ready'`
1313
+ * step for story creation - the storyId does not exist until `createStory` returns,
1314
+ * so the client cannot subscribe to the progress emitter until after that point.
1315
+ * These steps describe the optional background job (plot plan + detailed profiles)
1316
+ * that continues after the method returns:
1317
+ * - `'start'` - background job has begun
1318
+ * - `'profiles'` - generating detailed character profiles
1319
+ * - `'portraits'` - generating character portrait images (only if an image model is configured)
1320
+ * - `'complete'` - background job finished; detailed profiles and plot plan are now available
1321
+ * - `'error'` - background job failed; `message` contains the error text
1322
+ *
1323
+ * **`step` values emitted during {@link progressStory}:**
1324
+ *
1325
+ * `'ready'` fires just before `progressStory` returns, so the story is playable
1326
+ * as soon as the Promise resolves - no need to separately listen for `'ready'`.
1327
+ * The event is emitted for the benefit of SSE clients that want to update their UI
1328
+ * in real time. After `'ready'`, a background job continues:
1329
+ * - `'opening-scene'` - writing the new chapter's opening scene
1330
+ * - `'chapter-backup'` - saving chapter checkpoint data
1331
+ * - `'ready'` - chapter ready; fired just before `progressStory` resolves
1332
+ * - `'profiles'` - (background) recreating plot plan and character profiles
1333
+ * - `'complete'` - (background) all chapter work done
1334
+ * - `'error'` - progression failed
1335
+ *
1336
+ * The emitter is removed after the terminal step (`'complete'`, `'ready'`, or `'error'`),
1337
+ * so this method returns `undefined` once a terminal step has fired.
1338
+ *
1339
+ * @param storyId - The story's ID
1340
+ * @returns `EventEmitter` emitting `'progress'` events, or `undefined` if already complete
1341
+ */
200
1342
  getStoryProgressEmitter(storyId: string): EventEmitter<[never]>;
1343
+ /**
1344
+ * Returns the `EventEmitter` for real-time story updates.
1345
+ *
1346
+ * The emitter fires four named events. Each payload includes a `timestamp` field.
1347
+ *
1348
+ * ---
1349
+ *
1350
+ * **`'story-state'`** - {@link StoryStateEvent}
1351
+ * Fires after every room turn with the complete updated game state.
1352
+ * ```typescript
1353
+ * emitter.on('story-state', (event: StoryStateEvent) => {
1354
+ * const myTurn = event.state.currentSpeaker === event.state.userAgentName;
1355
+ * });
1356
+ * ```
1357
+ * Use `state.currentSpeaker === state.userAgentName` to detect the player's turn.
1358
+ * Do **not** use `state.humanPrompt` for turn detection - it is a UI display string
1359
+ * (e.g. `"What does Elena do next?"`) present even when it is not the player's turn.
1360
+ *
1361
+ * ---
1362
+ *
1363
+ * **`'suggest-introduce-character'`** - {@link StoryIntroduceCharacterEvent}
1364
+ * Fires when the narrator wants to add a new character. The host app should surface
1365
+ * this to the player before acting.
1366
+ * - **Accept:** call {@link introduceCharacterToStory} with `fromNarratorSuggestion: true`
1367
+ * - **Reject:** call {@link declineCharacter}
1368
+ * ```typescript
1369
+ * emitter.on('suggest-introduce-character', (event: StoryIntroduceCharacterEvent) => {
1370
+ * // event.characterName is the narrator-chosen name
1371
+ * });
1372
+ * ```
1373
+ *
1374
+ * ---
1375
+ *
1376
+ * **`'suggest-progress-chapter'`** - {@link StoryProgressChapterEvent}
1377
+ * Fires when the narrator wants to advance to the next chapter. The host app should
1378
+ * surface this to the player before acting.
1379
+ * - **Accept:** call {@link progressStory}
1380
+ * - **Stay in current chapter:** ignore the event (no rejection call needed)
1381
+ *
1382
+ * ---
1383
+ *
1384
+ * **`'story-error'`** - {@link StoryErrorEvent}
1385
+ * Fires when the story engine encounters a fatal error during room processing.
1386
+ * Named `'story-error'` rather than `'error'` to avoid Node.js throwing an uncaught
1387
+ * exception when no listener is attached to `'error'`.
1388
+ * Check `event.errorType === 'InsufficientBalanceError'` for balance failures.
1389
+ *
1390
+ * ---
1391
+ *
1392
+ * @param storyId - The story's ID
1393
+ * @returns `EventEmitter` emitting `'story-state'`, `'suggest-introduce-character'`,
1394
+ * `'suggest-progress-chapter'`, and `'story-error'` events
1395
+ */
201
1396
  getStoryMessageEmitter(storyId: string): EventEmitter<[never]>;
1397
+ /**
1398
+ * Returns a Node.js `EventEmitter` that fires whenever this agent's state changes
1399
+ * (new message, token count update, etc.).
1400
+ *
1401
+ * Useful for building real-time UIs. Subscribe to the `'update'` event to receive
1402
+ * agent state payloads without polling.
1403
+ *
1404
+ * @param agentId - The agent's ID
1405
+ * @returns `EventEmitter` that emits `'update'` events with agent state payloads
1406
+ *
1407
+ * @example
1408
+ * ```typescript
1409
+ * const emitter = appService.getAgentMessageEmitter(agent.id);
1410
+ * emitter.on('update', (state) => {
1411
+ * console.log('New message:', state.latestMessage);
1412
+ * });
1413
+ * ```
1414
+ */
202
1415
  getAgentMessageEmitter(agentId: string): EventEmitter<[never]>;
1416
+ /**
1417
+ * Ensures the real-time state callback is registered for an agent.
1418
+ *
1419
+ * Normally called automatically by {@link processText} and {@link getAgentMessages}.
1420
+ * Call this explicitly when connecting a new SSE client to an agent that was
1421
+ * loaded from disk (not yet touched in this session).
1422
+ *
1423
+ * @param agentId - The agent's ID
1424
+ */
203
1425
  ensureAgentStateCallback(agentId: string): Promise<void>;
1426
+ /**
1427
+ * Sets up the state change callback for an agent to emit SSE updates
1428
+ * @param agent The agent to set up the callback for
1429
+ */
204
1430
  private setupAgentStateCallback;
1431
+ /**
1432
+ * Returns a Node.js `EventEmitter` that fires whenever a new message arrives in the room.
1433
+ *
1434
+ * Subscribe to the `'update'` event to receive room message payloads in real time
1435
+ * without polling.
1436
+ *
1437
+ * @param roomId - The room's ID
1438
+ * @returns `EventEmitter` that emits `'update'` events with room message payloads
1439
+ */
205
1440
  getRoomMessageEmitter(roomId: string): EventEmitter<[never]>;
1441
+ /**
1442
+ * Returns a Node.js `EventEmitter` that fires whenever the user's balance changes.
1443
+ *
1444
+ * Subscribe to the `'update'` event to push real-time balance updates to a connected
1445
+ * client (e.g. via SSE) without polling.
1446
+ *
1447
+ * @param userId - The user's ID (typically the same ID used with `getAppService`)
1448
+ * @returns `EventEmitter` that emits `'update'` events with the new balance value
1449
+ */
206
1450
  getBalanceMessageEmitter(userId: string): EventEmitter;
1451
+ /**
1452
+ * Ensures the real-time state callback is registered for a room.
1453
+ *
1454
+ * Normally called automatically. Call this explicitly when connecting a new
1455
+ * SSE client to a room that was loaded from disk (not yet touched in this session).
1456
+ *
1457
+ * @param roomId - The room's ID
1458
+ */
207
1459
  ensureRoomStateCallback(roomId: string): Promise<void>;
208
1460
  private setupRoomStateCallback;
1461
+ /**
1462
+ * Lists all stories belonging to this user.
1463
+ *
1464
+ * @returns Array of story metadata objects
1465
+ */
209
1466
  listStories(): StoryInfo[];
1467
+ /**
1468
+ * Resumes any stories that were paused due to insufficient balance.
1469
+ *
1470
+ * Call this after adding balance via {@link addBalance} to allow stories that
1471
+ * stalled mid-processing to continue from where they left off.
1472
+ *
1473
+ * @returns The number of stories that were resumed
1474
+ */
210
1475
  resumePausedStories(): Promise<number>;
1476
+ /**
1477
+ * Permanently deletes a story, its room, all characters, chapters, and artifacts.
1478
+ *
1479
+ * @param storyId - The story's ID
1480
+ */
211
1481
  deleteStory(storyId: string): Promise<void>;
1482
+ /**
1483
+ * Summarizes and compresses agent conversation histories to reduce token usage.
1484
+ *
1485
+ * Uses story-specific prompts: the narrator summarizes plot events,
1486
+ * characters summarize their relationships and experiences. The original
1487
+ * messages are replaced with a compact summary block.
1488
+ *
1489
+ * @param storyId - The story's ID
1490
+ * @returns Object with `success` flag, optional `message`, and compaction `details`
1491
+ */
212
1492
  compactStory(storyId: string): Promise<{
213
1493
  success: boolean;
214
1494
  message?: string;
215
1495
  details?: any;
216
1496
  }>;
1497
+ /**
1498
+ * Advances the story to the next chapter.
1499
+ *
1500
+ * Creates a checkpoint of the current chapter state and rebuilds the opening scene.
1501
+ * The story is **immediately playable when this Promise resolves** - the `'ready'`
1502
+ * progress event fires just before the function returns, so awaiting this call is
1503
+ * sufficient; there is no need to separately wait for the event.
1504
+ *
1505
+ * After the function returns, a background job recreates the plot plan and character
1506
+ * profiles for the new chapter (`'profiles'` --> `'complete'`). Agent
1507
+ * conversation histories are **not** compacted here - each agent compacts
1508
+ * independently on demand when it individually reaches the compaction threshold
1509
+ * (see {@link compactStory} for manual compaction).
1510
+ *
1511
+ * @param storyId - The story's ID
1512
+ * @returns Object with the new `chapterIndex`
1513
+ */
217
1514
  progressStory(storyId: string): Promise<{
218
1515
  chapterIndex: number;
219
1516
  }>;
1517
+ /**
1518
+ * Returns the current runtime state of a story.
1519
+ *
1520
+ * Includes messages, pending message count, processing status, and story metadata.
1521
+ * Useful for restoring UI state after reconnecting.
1522
+ *
1523
+ * @param storyId - The story's ID
1524
+ * @returns Full story state object
1525
+ */
220
1526
  getStoryState(storyId: string): Promise<StoryState>;
1527
+ /**
1528
+ * Returns metadata for a specific story.
1529
+ *
1530
+ * @param storyId - The story's ID
1531
+ * @returns Story metadata, or `undefined` if not found
1532
+ */
221
1533
  getStoryInfo(storyId: string): Promise<StoryInfo | undefined>;
1534
+ /**
1535
+ * Submits the human player's response to the story.
1536
+ *
1537
+ * Adds the content as a player message and triggers the AI characters
1538
+ * to continue the narrative.
1539
+ *
1540
+ * Pass the literal string `'PASS'` (case-insensitive) to skip the player's
1541
+ * turn and let the AI characters continue without player input.
1542
+ *
1543
+ * @param storyId - The story's ID
1544
+ * @param content - The player's message or action, or `'PASS'` to skip the turn
1545
+ */
222
1546
  respondToStory(storyId: string, content: string): Promise<void>;
1547
+ /**
1548
+ * Cancels any pending AI turns and forces the human's turn.
1549
+ *
1550
+ * Drops the room's pending message queue and pauses processing so the
1551
+ * human-controlled agent becomes the current speaker. Any in-flight LLM
1552
+ * calls (perceive or moderator) will discard their responses on return.
1553
+ *
1554
+ * @param storyId - The story's ID
1555
+ */
223
1556
  interruptStory(storyId: string): Promise<void>;
1557
+ /**
1558
+ * Adds a new AI character to an existing story.
1559
+ *
1560
+ * Creates a character agent and integrates it into the story's room.
1561
+ * The character profile is generated by the AI based on the provided description.
1562
+ *
1563
+ * When {@link getStoryMessageEmitter} fires a `'suggestion'` update with
1564
+ * `suggestion.type === 'introduce_character'`, pass `suggestion.characterName` as
1565
+ * `name` and set `fromNarratorSuggestion: true` to accept the suggestion.
1566
+ * To reject it instead, call {@link declineCharacter}.
1567
+ *
1568
+ * @param storyId - The story's ID
1569
+ * @param name - The character's name
1570
+ * @param description - Brief description of the character's personality and role
1571
+ * @param storyModel - Optional model override from `story_models.json`
1572
+ * @param fromNarratorSuggestion - Set `true` when accepting a narrator `'suggestion'` update. Default `false`.
1573
+ */
224
1574
  introduceCharacterToStory(storyId: string, name: string, description: string, storyModel?: string, fromNarratorSuggestion?: boolean): Promise<void>;
1575
+ /**
1576
+ * Records that the player declined a narrator-suggested character introduction.
1577
+ *
1578
+ * Prevents the narrator from suggesting the same character again in this story.
1579
+ *
1580
+ * @param storyId - The story's ID
1581
+ * @param characterName - The character name that was declined
1582
+ */
225
1583
  declineCharacter(storyId: string, characterName: string): Promise<void>;
1584
+ /**
1585
+ * Removes a character's agent from the story while preserving their profile file.
1586
+ *
1587
+ * The character can be reintroduced later via {@link introduceCharacterToStory}
1588
+ * and their profile will be available.
1589
+ *
1590
+ * @param storyId - The story's ID
1591
+ * @param characterName - The character's name
1592
+ */
226
1593
  deleteCharacterFromStory(storyId: string, characterName: string): Promise<void>;
1594
+ /**
1595
+ * Returns all chapter checkpoints for a story.
1596
+ *
1597
+ * Chapters are created by {@link progressStory} and can be read with {@link getChapter}.
1598
+ *
1599
+ * @param storyId - The story's ID
1600
+ * @returns Object with a `chapters` array of chapter info objects
1601
+ */
227
1602
  listChapters(storyId: string): {
228
1603
  chapters: ChapterInfo[];
229
1604
  };
1605
+ /**
1606
+ * Returns the messages from a specific chapter checkpoint.
1607
+ *
1608
+ * @param storyId - The story's ID
1609
+ * @param chapterIndex - The chapter number (1-based, as returned by {@link listChapters})
1610
+ * @returns Array of room messages from that chapter
1611
+ */
230
1612
  getChapter(storyId: string, chapterIndex: number): Promise<RoomMessage[]>;
1613
+ /**
1614
+ * Overwrites the content of a chapter checkpoint.
1615
+ *
1616
+ * @param storyId - The story's ID
1617
+ * @param chapterIndex - The chapter number to overwrite
1618
+ * @param content - The new chapter content
1619
+ * @throws {OperationFailedError} If the chapter cannot be saved
1620
+ */
231
1621
  saveChapter(storyId: string, chapterIndex: number, content: string): void;
1622
+ /**
1623
+ * Deletes a chapter checkpoint from a story.
1624
+ *
1625
+ * @param storyId - The story's ID
1626
+ * @param chapterIndex - The chapter number to delete
1627
+ * @throws {NotFoundError} If the chapter does not exist
1628
+ */
232
1629
  deleteChapter(storyId: string, chapterIndex: number): void;
1630
+ /**
1631
+ * Returns all current characters in a story.
1632
+ *
1633
+ * @param storyId - The story's ID
1634
+ * @returns Array of character objects (derived from the story's room agents)
1635
+ */
233
1636
  listCharacters(storyId: string): Promise<Character[]>;
1637
+ /**
1638
+ * Returns the profile for a specific character.
1639
+ *
1640
+ * @param storyId - The story's ID
1641
+ * @param characterName - The character's name
1642
+ * @returns Object with `content` containing the character profile markdown
1643
+ */
234
1644
  getCharacter(storyId: string, characterName: string): Promise<{
235
1645
  content: string;
236
1646
  }>;
1647
+ /**
1648
+ * Saves a character's profile markdown.
1649
+ *
1650
+ * @param storyId - The story's ID
1651
+ * @param characterName - The character's name
1652
+ * @param content - Markdown content for the character profile
1653
+ */
237
1654
  saveCharacter(storyId: string, characterName: string, content: string): void;
1655
+ /**
1656
+ * Returns the inventory for a specific character.
1657
+ *
1658
+ * @param storyId - The story's ID
1659
+ * @param characterName - The character's name
1660
+ * @returns Object with `content` containing the inventory markdown
1661
+ */
238
1662
  getCharacterInventory(storyId: string, characterName: string): Promise<{
239
1663
  content: string;
240
1664
  }>;
1665
+ /**
1666
+ * Saves a character's inventory markdown.
1667
+ *
1668
+ * @param storyId - The story's ID
1669
+ * @param characterName - The character's name
1670
+ * @param content - Markdown content for the character inventory
1671
+ */
241
1672
  saveCharacterInventory(storyId: string, characterName: string, content: string): Promise<void>;
1673
+ /**
1674
+ * Returns the story's plot plan.
1675
+ *
1676
+ * The plot plan is a room artifact generated by the narrator at story creation
1677
+ * and updated as the story progresses.
1678
+ *
1679
+ * @param storyId - The story's ID
1680
+ * @returns Object with `content` containing the plot plan markdown
1681
+ */
242
1682
  getPlotPlan(storyId: string): Promise<{
243
1683
  content: string;
244
1684
  }>;
1685
+ /**
1686
+ * Generates the full story as a single markdown document.
1687
+ *
1688
+ * Combines all chapters and room messages in narrative order.
1689
+ *
1690
+ * @param storyId - The story's ID
1691
+ * @returns The complete story formatted as markdown text
1692
+ */
245
1693
  downloadStoryMarkdown(storyId: string): Promise<string>;
1694
+ /**
1695
+ * Exports the complete story data as a downloadable zip archive.
1696
+ *
1697
+ * The archive can be re-imported via {@link importStoryFromZip}.
1698
+ *
1699
+ * @param storyId - The story's ID
1700
+ * @returns Object with a `stream` (readable zip stream) and `filename` for the download
1701
+ */
246
1702
  exportStoryData(storyId: string): Promise<{
247
1703
  stream: Readable;
248
1704
  filename: string;
249
1705
  }>;
1706
+ /**
1707
+ * Returns the formatted conversation history for a specific character in a story.
1708
+ *
1709
+ * @param storyId - The story's ID
1710
+ * @param agentId - The character agent's ID
1711
+ * @returns Object with `content` containing the formatted history text
1712
+ */
250
1713
  getAgentHistory(storyId: string, agentId: string): Promise<{
251
1714
  content: string;
252
1715
  }>;
1716
+ /**
1717
+ * Saves the story's plot plan.
1718
+ *
1719
+ * Persists the content as a room artifact via the publish mechanism.
1720
+ *
1721
+ * @param storyId - The story's ID
1722
+ * @param content - The plot plan markdown to save
1723
+ */
253
1724
  savePlotPlan(storyId: string, content: string): Promise<void>;
1725
+ /**
1726
+ * Returns the user's current credit balance in dollars.
1727
+ *
1728
+ * The balance is decremented automatically after each AI call based on token usage
1729
+ * and any configured markup. Calls that would exceed the balance throw
1730
+ * `InsufficientBalanceError` before the request is sent.
1731
+ *
1732
+ * @returns Current balance in dollars
1733
+ */
254
1734
  getBalance(): number;
1735
+ /**
1736
+ * Adds funds to the user's balance.
1737
+ *
1738
+ * Use this to credit a user after a payment is processed by your application.
1739
+ *
1740
+ * @param amount - Dollar amount to add (must be positive)
1741
+ */
255
1742
  addBalance(amount: number): void;
1743
+ /**
1744
+ * Records a new payment transaction.
1745
+ *
1746
+ * Call this when your payment provider confirms a payment has been initiated.
1747
+ * The `paymentId` should be the unique identifier issued by your payment provider
1748
+ * (e.g. a Stripe Payment Intent ID). Use {@link updateTransactionStatus} to update
1749
+ * the status once the provider confirms success or failure.
1750
+ *
1751
+ * @param amount - Dollar amount of the transaction
1752
+ * @param paymentId - Unique payment identifier from your payment provider
1753
+ * @param status - Initial status; defaults to `'pending'`
1754
+ * @returns The created `Transaction` record
1755
+ */
256
1756
  recordTransaction(amount: number, paymentId: string, status?: 'pending' | 'succeeded' | 'failed' | 'cancelled'): Promise<Transaction>;
1757
+ /**
1758
+ * Updates the status of an existing transaction.
1759
+ *
1760
+ * Call this when your payment provider webhook confirms the final outcome of a payment.
1761
+ *
1762
+ * @param paymentId - The payment provider ID used when the transaction was recorded
1763
+ * @param status - New status (`'succeeded'`, `'failed'`, or `'cancelled'`)
1764
+ */
257
1765
  updateTransactionStatus(paymentId: string, status: 'pending' | 'succeeded' | 'failed' | 'cancelled'): Promise<void>;
1766
+ /**
1767
+ * Retrieves a single transaction by its payment provider ID.
1768
+ *
1769
+ * @param paymentId - The payment provider ID used when the transaction was recorded
1770
+ * @returns The matching `Transaction`, or `null` if not found
1771
+ */
258
1772
  getTransactionByPaymentId(paymentId: string): Promise<Transaction | null>;
1773
+ /**
1774
+ * Returns paginated transaction history for this user, sorted newest-first.
1775
+ *
1776
+ * @param limit - Maximum number of records to return (default: 50)
1777
+ * @param offset - Number of records to skip for pagination (default: 0)
1778
+ * @returns Object with a `transactions` array and a `total` count
1779
+ */
259
1780
  getTransactions(limit?: number, offset?: number): Promise<TransactionHistoryResponse>;
1781
+ /**
1782
+ * Returns metadata for all artifacts owned by this user.
1783
+ *
1784
+ * Artifacts are persistent named documents that can be attached to agents
1785
+ * (see {@link attachArtifactToAgent}) or shared with rooms via the `'publish'` action.
1786
+ * Use {@link getUserArtifact} to retrieve the actual content.
1787
+ *
1788
+ * @returns Array of artifact metadata objects (ID, name, creation date, etc.)
1789
+ */
260
1790
  listUserArtifacts(): ArtifactMetadata[];
1791
+ /**
1792
+ * Returns the content of a user artifact.
1793
+ *
1794
+ * Text artifacts are returned as `string`; binary artifacts (e.g. converted PDFs
1795
+ * in intermediate state) may be returned as `Buffer`.
1796
+ *
1797
+ * @param artifactId - The artifact's ID (from {@link listUserArtifacts})
1798
+ * @returns The artifact content, or `null` if no artifact with that ID exists
1799
+ */
261
1800
  getUserArtifact(artifactId: string): string | Buffer | null;
1801
+ /**
1802
+ * Creates a new named artifact and returns its ID.
1803
+ *
1804
+ * The artifact is persisted immediately. Use the returned ID to attach it to
1805
+ * agents ({@link attachArtifactToAgent}) or reference it in room messages.
1806
+ *
1807
+ * @param name - Human-readable display name for the artifact
1808
+ * @param content - Initial text content (typically Markdown)
1809
+ * @returns The new artifact's ID
1810
+ */
262
1811
  createUserArtifact(name: string, content: string): string;
1812
+ /**
1813
+ * Replaces the content of an existing artifact.
1814
+ *
1815
+ * @param artifactId - The artifact's ID (from {@link listUserArtifacts})
1816
+ * @param content - New content to write
1817
+ * @returns `true` on success, `false` if no artifact with that ID exists
1818
+ */
263
1819
  updateUserArtifact(artifactId: string, content: string): boolean;
1820
+ /**
1821
+ * Creates an artifact from a PDF by converting it to Markdown, running the
1822
+ * conversion in the background.
1823
+ *
1824
+ * Returns the artifact ID immediately with placeholder content. The artifact
1825
+ * content is replaced with the converted Markdown when the background job
1826
+ * finishes. If conversion fails, the artifact content is replaced with an
1827
+ * error message.
1828
+ *
1829
+ * Requires the `DOC_CONVERSION_AI_SERVICE` and `DOC_CONVERSION_AI_MODEL`
1830
+ * environment variables to be set to an AI service that supports PDF documents.
1831
+ *
1832
+ * A PDF over ten pages is converted page by page, at most
1833
+ * `PDF_CONVERT_CONCURRENCY` at a time, with each page retried before it is
1834
+ * given up on. A page that is given up on does not fail the document: the
1835
+ * artifact still lands, naming the pages that are missing from it so they can
1836
+ * be re-run. Only a conversion that produces nothing at all replaces the
1837
+ * artifact with an error.
1838
+ *
1839
+ * @param name - Display name for the artifact
1840
+ * @param pdfBuffer - Buffer containing the raw PDF data
1841
+ * @returns The new artifact's ID (content is a placeholder until conversion completes)
1842
+ */
264
1843
  convertUserArtifact(name: string, pdfBuffer: Buffer): string;
1844
+ /**
1845
+ * Converts a PDF to Markdown a page at a time and returns the pages.
1846
+ *
1847
+ * The building block under {@link convertUserArtifact}, public because a host
1848
+ * embedding Briyah usually wants the pages and the cost rather than an
1849
+ * artifact — to extract records from each page, to cache the result under its
1850
+ * own key, or to show progress. Every page is converted by its own throwaway
1851
+ * agent, so nothing accumulates history and pages stay independent.
1852
+ *
1853
+ * Bounded, retried and non-fatal: at most {@link PdfMarkdownOptions.concurrency}
1854
+ * pages are in flight, each page is retried on an empty response, a thrown
1855
+ * error or a timeout, and a page that exhausts its attempts is reported in
1856
+ * `failedPages` rather than failing the document.
1857
+ *
1858
+ * @param pdfBuffer - The raw PDF
1859
+ * @param options - Models, prompt, hints and limits; every field has a default
1860
+ * @returns The pages, the assembled Markdown, what failed, and the cost
1861
+ * @throws {ValidationError} If no conversion service or model is configured
1862
+ *
1863
+ * @example
1864
+ * ```typescript
1865
+ * const result = await appService.convertPdfToMarkdownPages(buffer, {
1866
+ * concurrency: 8,
1867
+ * fidelityHints: 'chapter and verse numbers',
1868
+ * onProgress: (message) => console.log(message),
1869
+ * });
1870
+ * if (result.failedPages.length) console.warn('Re-run pages', result.failedPages);
1871
+ * ```
1872
+ */
265
1873
  convertPdfToMarkdownPages(pdfBuffer: Buffer | Uint8Array, options?: PdfMarkdownOptions): Promise<PdfMarkdownResult>;
1874
+ /**
1875
+ * Converts a whole PDF in one request, for a document short enough that page
1876
+ * continuity is worth more than page-level recovery.
1877
+ *
1878
+ * Retried on the same policy as a page, since an empty response here loses the
1879
+ * entire document rather than one page of it.
1880
+ */
266
1881
  private convertWholePdf;
1882
+ /**
1883
+ * Background conversion process - updates the artifact when complete.
1884
+ *
1885
+ * A document of more than ten pages is converted page-by-page, which is what
1886
+ * makes a partial failure survivable: the artifact still lands, carrying the
1887
+ * pages that converted and naming the ones that did not.
1888
+ *
1889
+ * @param artifactId The artifact ID to update
1890
+ * @param name The artifact name
1891
+ * @param pdfBuffer Buffer containing PDF data
1892
+ */
267
1893
  private convertPdfInBackground;
1894
+ /**
1895
+ * Changes the display name of an artifact.
1896
+ *
1897
+ * @param artifactId - The artifact's ID (from {@link listUserArtifacts})
1898
+ * @param newName - New display name for the artifact
1899
+ * @returns `true` on success, `false` if no artifact with that ID exists
1900
+ */
268
1901
  renameUserArtifact(artifactId: string, newName: string): boolean;
1902
+ /**
1903
+ * Permanently deletes a user artifact.
1904
+ *
1905
+ * Any agents that have the artifact attached will lose access to it after deletion.
1906
+ *
1907
+ * @param artifactId - The artifact's ID (from {@link listUserArtifacts})
1908
+ * @returns `true` on success, `false` if no artifact with that ID exists
1909
+ */
269
1910
  deleteUserArtifact(artifactId: string): boolean;
1911
+ /**
1912
+ * Gets the artifact service for a story
1913
+ * @param storyId The story ID
1914
+ * @returns The story-specific artifact service
1915
+ */
270
1916
  private getStoryArtifactService;
1917
+ /**
1918
+ * Returns all artifacts associated with a story.
1919
+ *
1920
+ * Story artifacts include the plot plan and any documents published by agents
1921
+ * during the narrative.
1922
+ *
1923
+ * @param storyId - The story's ID
1924
+ * @returns Array of artifact metadata objects
1925
+ */
271
1926
  listStoryArtifacts(storyId: string): ArtifactMetadata[];
1927
+ /**
1928
+ * Returns the content of a specific story artifact.
1929
+ *
1930
+ * @param storyId - The story's ID
1931
+ * @param artifactId - The artifact's ID (from {@link listStoryArtifacts})
1932
+ * @returns The artifact content as a string or Buffer, or `null` if not found
1933
+ */
272
1934
  getStoryArtifact(storyId: string, artifactId: string): string | Buffer | null;
1935
+ /**
1936
+ * Returns one of a room's generated images, with the metadata needed to serve
1937
+ * it. Rooms keep their images in their own directory, separate from the
1938
+ * `.artifact` text files, so this does not go through the artifact store.
1939
+ *
1940
+ * @param roomId - The room's ID
1941
+ * @param artifactId - The image's ID, as it appears in the message markdown
1942
+ * @returns The bytes and MIME type, or `null` when there is no such image
1943
+ */
1944
+ getRoomImage(roomId: string, artifactId: string): Promise<{
1945
+ content: string | Buffer;
1946
+ mimeType: string;
1947
+ } | null>;
1948
+ /**
1949
+ * Returns metadata for all artifacts currently attached to an agent.
1950
+ *
1951
+ * Attached artifacts are included in the agent's context on every prompt, allowing
1952
+ * the agent to reference their content. Use {@link attachArtifactToAgent} and
1953
+ * {@link detachArtifactFromAgent} to manage attachments.
1954
+ *
1955
+ * @param agentId - The agent's ID
1956
+ * @returns Array of artifact metadata objects for the agent's attached artifacts
1957
+ * @throws {NotFoundError} If no agent with the given ID exists
1958
+ */
273
1959
  listAgentArtifacts(agentId: string): Promise<ArtifactMetadata[]>;
1960
+ /**
1961
+ * Attaches a user artifact to an agent so the agent can read its content in prompts.
1962
+ *
1963
+ * The attachment is persisted immediately via `agent.save()`. The artifact content
1964
+ * is injected into the agent's context on each subsequent call.
1965
+ *
1966
+ * @param agentId - The agent's ID
1967
+ * @param artifactId - The artifact's ID (from {@link listUserArtifacts})
1968
+ * @throws {NotFoundError} If the agent or artifact does not exist
1969
+ */
274
1970
  attachArtifactToAgent(agentId: string, artifactId: string): Promise<void>;
1971
+ /**
1972
+ * Removes an artifact attachment from an agent.
1973
+ *
1974
+ * The artifact itself is not deleted - only the link between the agent and the artifact
1975
+ * is removed. Changes are persisted immediately via `agent.save()`.
1976
+ *
1977
+ * @param agentId - The agent's ID
1978
+ * @param artifactId - The artifact's ID to detach
1979
+ * @throws {NotFoundError} If no agent with the given ID exists
1980
+ */
275
1981
  detachArtifactFromAgent(agentId: string, artifactId: string): Promise<void>;
276
1982
  }