briyah 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (477) hide show
  1. package/LICENSE +216 -0
  2. package/README.md +43 -7
  3. package/data/common/config/LICENSE-model-prices.md +65 -0
  4. package/data/common/config/markup +1 -1
  5. package/data/common/config/model_prices.json +47443 -46295
  6. package/data/common/prompts/narrator/create_story.prompt +2 -0
  7. package/data/packs/dnd5e/agents/player.json +11 -11
  8. package/data/packs/dnd5e/prompts/character_creator/defaults_config.json +21 -20
  9. package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +19 -12
  10. package/data/packs/dnd5e/prompts/dnd_player/perceive.prompt +10 -6
  11. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
  12. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
  13. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
  14. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
  15. package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
  16. package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
  17. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
  18. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
  19. package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
  20. package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
  21. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
  22. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
  23. package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
  24. package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
  25. package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
  26. package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
  27. package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
  28. package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
  29. package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
  30. package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
  31. package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
  32. package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
  33. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
  34. package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
  35. package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
  36. package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
  37. package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
  38. package/dist-sdk/server/src/ai/agent-factory.js +20 -0
  39. package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
  40. package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
  41. package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
  42. package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
  43. package/dist-sdk/server/src/ai/agent.d.ts +196 -0
  44. package/dist-sdk/server/src/ai/agent.js +224 -11
  45. package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
  46. package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
  47. package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
  48. package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
  49. package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
  50. package/dist-sdk/server/src/ai/artifact.service.js +148 -3
  51. package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
  52. package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
  53. package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
  54. package/dist-sdk/server/src/ai/model_prices.js +91 -5
  55. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
  56. package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
  57. package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
  58. package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
  59. package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
  60. package/dist-sdk/server/src/app/balance-message.service.js +24 -0
  61. package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
  62. package/dist-sdk/server/src/app/balance.module.js +4 -0
  63. package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
  64. package/dist-sdk/server/src/app/balance.service.js +54 -0
  65. package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
  66. package/dist-sdk/server/src/app/stripe.controller.js +35 -0
  67. package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
  68. package/dist-sdk/server/src/app/stripe.service.js +62 -0
  69. package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
  70. package/dist-sdk/server/src/app/transaction.service.js +36 -0
  71. package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
  72. package/dist-sdk/server/src/app/user-service-factory.js +38 -1
  73. package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
  74. package/dist-sdk/server/src/app/user-service-manager.js +43 -0
  75. package/dist-sdk/server/src/app.controller.d.ts +87 -0
  76. package/dist-sdk/server/src/app.controller.js +272 -12
  77. package/dist-sdk/server/src/app.module.js +28 -6
  78. package/dist-sdk/server/src/app.service.d.ts +1662 -0
  79. package/dist-sdk/server/src/app.service.js +1862 -6
  80. package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
  81. package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
  82. package/dist-sdk/server/src/auth/auth.controller.js +46 -0
  83. package/dist-sdk/server/src/auth/auth.module.js +3 -2
  84. package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
  85. package/dist-sdk/server/src/auth/auth.service.js +39 -3
  86. package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
  87. package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
  88. package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
  89. package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
  90. package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
  91. package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
  92. package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
  93. package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
  94. package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
  95. package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
  96. package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
  97. package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
  98. package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
  99. package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
  100. package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
  101. package/dist-sdk/server/src/auth/session.guard.js +8 -0
  102. package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
  103. package/dist-sdk/server/src/auth/twilio.service.js +30 -4
  104. package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
  105. package/dist-sdk/server/src/auth/users.service.js +42 -0
  106. package/dist-sdk/server/src/common/errors.d.ts +20 -0
  107. package/dist-sdk/server/src/common/errors.js +21 -0
  108. package/dist-sdk/server/src/config/env-config.d.ts +7 -0
  109. package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
  110. package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
  111. package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
  112. package/dist-sdk/server/src/config/user-config.service.js +57 -0
  113. package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
  114. package/dist-sdk/server/src/config/user-paths.service.js +67 -0
  115. package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
  116. package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
  117. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
  118. package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
  119. package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
  120. package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
  121. package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
  122. package/dist-sdk/server/src/packs/pack.service.js +98 -1
  123. package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
  124. package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
  125. package/dist-sdk/server/src/room/artifact.d.ts +18 -0
  126. package/dist-sdk/server/src/room/message.d.ts +64 -0
  127. package/dist-sdk/server/src/room/message.js +77 -2
  128. package/dist-sdk/server/src/room/nickname.d.ts +27 -0
  129. package/dist-sdk/server/src/room/nickname.js +41 -0
  130. package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
  131. package/dist-sdk/server/src/room/room-config.d.ts +26 -0
  132. package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
  133. package/dist-sdk/server/src/room/room-factory.js +14 -0
  134. package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
  135. package/dist-sdk/server/src/room/room-message.service.js +28 -0
  136. package/dist-sdk/server/src/room/room-store.service.d.ts +177 -0
  137. package/dist-sdk/server/src/room/room-store.service.js +242 -5
  138. package/dist-sdk/server/src/room/room.d.ts +906 -1
  139. package/dist-sdk/server/src/room/room.js +1525 -34
  140. package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
  141. package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
  142. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +38 -3
  143. package/dist-sdk/server/src/rpg/rpg-roster.js +49 -49
  144. package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
  145. package/dist-sdk/server/src/rpg/rpg.service.js +108 -5
  146. package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
  147. package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
  148. package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
  149. package/dist-sdk/server/src/sdk/briyah.js +285 -7
  150. package/dist-sdk/server/src/sdk/index.d.ts +0 -1
  151. package/dist-sdk/server/src/sdk/index.js +24 -3
  152. package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
  153. package/dist-sdk/server/src/shared/shared.module.js +13 -5
  154. package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
  155. package/dist-sdk/server/src/story/story-message.service.js +43 -0
  156. package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
  157. package/dist-sdk/server/src/story/story-progress.service.js +23 -0
  158. package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
  159. package/dist-sdk/server/src/story/story-store.service.js +136 -1
  160. package/dist-sdk/server/src/story/story.service.d.ts +398 -0
  161. package/dist-sdk/server/src/story/story.service.js +829 -25
  162. package/dist-sdk/server/src/tools/core/index.d.ts +25 -0
  163. package/dist-sdk/server/src/tools/core/index.js +31 -0
  164. package/dist-sdk/server/src/tools/core/rename.tool.d.ts +10 -0
  165. package/dist-sdk/server/src/tools/core/rename.tool.js +72 -0
  166. package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
  167. package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
  168. package/dist-sdk/server/src/tools/native-tool.types.d.ts +186 -0
  169. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
  170. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
  171. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
  172. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
  173. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
  174. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
  175. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
  176. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
  177. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
  178. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
  179. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
  180. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
  181. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
  182. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
  183. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
  184. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
  185. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
  186. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
  187. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
  188. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
  189. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
  190. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
  191. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
  192. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
  193. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
  194. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
  195. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
  196. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
  197. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
  198. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
  199. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
  200. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
  201. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
  202. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
  203. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
  204. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
  205. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
  206. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
  207. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
  208. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
  209. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
  210. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
  211. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
  212. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
  213. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
  214. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
  215. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
  216. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
  217. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
  218. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
  219. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
  220. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
  221. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
  222. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
  223. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
  224. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
  225. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
  226. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
  227. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
  228. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
  229. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
  230. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
  231. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
  232. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
  233. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
  234. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
  235. package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
  236. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
  237. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
  238. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
  239. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
  240. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
  241. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
  242. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
  243. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
  244. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
  245. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
  246. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
  247. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
  248. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
  249. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
  250. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
  251. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
  252. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +125 -1
  253. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
  254. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
  255. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
  256. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
  257. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
  258. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
  259. package/dist-sdk/server/src/tools/packs/index.d.ts +52 -2
  260. package/dist-sdk/server/src/tools/packs/index.js +83 -9
  261. package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
  262. package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
  263. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
  264. package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
  265. package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
  266. package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
  267. package/dist-sdk/shared/types/app.types.d.ts +285 -14
  268. package/dist-sdk/shared/types/app.types.js +3 -0
  269. package/package.json +167 -139
  270. package/data/common/config/random_words.txt +0 -2241
  271. package/data/common/story_ideas/biblical.json +0 -122
  272. package/data/common/story_ideas/fantasy.json +0 -82
  273. package/data/common/story_ideas/historical_fiction.json +0 -82
  274. package/data/common/story_ideas/science_fiction.json +0 -82
  275. package/data/packs/acts/agents/character-guide.json +0 -6
  276. package/data/packs/acts/agents/discipleship-mentor.json +0 -6
  277. package/data/packs/acts/agents/mentor-coach.json +0 -6
  278. package/data/packs/acts/agents/student.json +0 -13
  279. package/data/packs/acts/agents/table-moderator.json +0 -6
  280. package/data/packs/acts/artifacts/chapter-01-acts-1.md +0 -405
  281. package/data/packs/acts/artifacts/chapter-02-acts-2.md +0 -443
  282. package/data/packs/acts/artifacts/chapter-03-acts-3.md +0 -409
  283. package/data/packs/acts/artifacts/chapter-04-acts-4.md +0 -438
  284. package/data/packs/acts/artifacts/chapter-05-acts-5.md +0 -434
  285. package/data/packs/acts/artifacts/chapter-06-acts-6.md +0 -441
  286. package/data/packs/acts/artifacts/chapter-07-acts-7.md +0 -472
  287. package/data/packs/acts/artifacts/chapter-08-acts-8.md +0 -512
  288. package/data/packs/acts/artifacts/chapter-09-acts-9.md +0 -346
  289. package/data/packs/acts/artifacts/chapter-10-acts-10.md +0 -367
  290. package/data/packs/acts/artifacts/chapter-11-acts-11.md +0 -391
  291. package/data/packs/acts/artifacts/chapter-12-acts-12.md +0 -390
  292. package/data/packs/acts/artifacts/chapter-13-acts-13.md +0 -388
  293. package/data/packs/acts/artifacts/chapter-14-acts-14.md +0 -466
  294. package/data/packs/acts/artifacts/chapter-15-acts-15.md +0 -413
  295. package/data/packs/acts/artifacts/chapter-16-acts-16.md +0 -585
  296. package/data/packs/acts/artifacts/chapter-17-acts-17.md +0 -428
  297. package/data/packs/acts/artifacts/chapter-18-acts-18.md +0 -486
  298. package/data/packs/acts/artifacts/chapter-19-acts-19.md +0 -461
  299. package/data/packs/acts/artifacts/chapter-20-acts-20.md +0 -389
  300. package/data/packs/acts/artifacts/chapter-21-acts-21.md +0 -452
  301. package/data/packs/acts/artifacts/chapter-22-acts-22.md +0 -424
  302. package/data/packs/acts/artifacts/chapter-23-acts-23.md +0 -395
  303. package/data/packs/acts/artifacts/chapter-24-acts-24.md +0 -446
  304. package/data/packs/acts/artifacts/chapter-25-acts-25.md +0 -391
  305. package/data/packs/acts/artifacts/chapter-26-acts-26.md +0 -431
  306. package/data/packs/acts/artifacts/chapter-27-acts-27.md +0 -530
  307. package/data/packs/acts/artifacts/chapter-28-acts-28.md +0 -1871
  308. package/data/packs/acts/artifacts/chapters.manifest.json +0 -170
  309. package/data/packs/acts/artifacts/character_guide-creation.md +0 -112
  310. package/data/packs/acts/artifacts/discipleship_mentor-procedure.md +0 -154
  311. package/data/packs/acts/artifacts/discipleship_mentor-systems.md +0 -72
  312. package/data/packs/acts/artifacts/manifest.json +0 -197
  313. package/data/packs/acts/artifacts/stage-guide.md +0 -94
  314. package/data/packs/acts/pack.json +0 -6
  315. package/data/packs/acts/prompts/acts_player/defaults_config.json +0 -5
  316. package/data/packs/acts/prompts/acts_player/perceive.json +0 -29
  317. package/data/packs/acts/prompts/acts_player/perceive.prompt +0 -87
  318. package/data/packs/acts/prompts/acts_player/system_instruction.prompt +0 -0
  319. package/data/packs/acts/prompts/acts_room_moderator/defaults_config.json +0 -9
  320. package/data/packs/acts/prompts/acts_room_moderator/moderate.json +0 -34
  321. package/data/packs/acts/prompts/acts_room_moderator/moderate.prompt +0 -70
  322. package/data/packs/acts/prompts/acts_room_moderator/system_instruction.prompt +0 -0
  323. package/data/packs/acts/prompts/character_guide/defaults_config.json +0 -18
  324. package/data/packs/acts/prompts/character_guide/perceive.json +0 -29
  325. package/data/packs/acts/prompts/character_guide/perceive.prompt +0 -140
  326. package/data/packs/acts/prompts/character_guide/system_instruction.prompt +0 -0
  327. package/data/packs/acts/prompts/discipleship_mentor/defaults_config.json +0 -23
  328. package/data/packs/acts/prompts/discipleship_mentor/perceive.json +0 -33
  329. package/data/packs/acts/prompts/discipleship_mentor/perceive.prompt +0 -245
  330. package/data/packs/acts/prompts/discipleship_mentor/system_instruction.prompt +0 -0
  331. package/data/packs/acts/prompts/mentor_coach/defaults_config.json +0 -13
  332. package/data/packs/acts/prompts/mentor_coach/perceive.json +0 -29
  333. package/data/packs/acts/prompts/mentor_coach/perceive.prompt +0 -87
  334. package/data/packs/acts/prompts/mentor_coach/system_instruction.prompt +0 -0
  335. package/data/packs/acts/rooms/session.json +0 -14
  336. package/data/packs/acts/rooms/training.json +0 -58
  337. package/dist-sdk/server/src/tools/packs/acts/data/cards.d.ts +0 -53
  338. package/dist-sdk/server/src/tools/packs/acts/data/cards.js +0 -54
  339. package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.d.ts +0 -2
  340. package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.js +0 -185
  341. package/dist-sdk/server/src/tools/packs/acts/data/encounters.d.ts +0 -12
  342. package/dist-sdk/server/src/tools/packs/acts/data/encounters.js +0 -102
  343. package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.d.ts +0 -2
  344. package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.js +0 -196
  345. package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.d.ts +0 -2
  346. package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.js +0 -1311
  347. package/dist-sdk/server/src/tools/packs/acts/engine/cards.d.ts +0 -5
  348. package/dist-sdk/server/src/tools/packs/acts/engine/cards.js +0 -27
  349. package/dist-sdk/server/src/tools/packs/acts/engine/challenge.d.ts +0 -37
  350. package/dist-sdk/server/src/tools/packs/acts/engine/challenge.js +0 -120
  351. package/dist-sdk/server/src/tools/packs/acts/engine/dice.d.ts +0 -20
  352. package/dist-sdk/server/src/tools/packs/acts/engine/dice.js +0 -41
  353. package/dist-sdk/server/src/tools/packs/acts/engine/sheet.d.ts +0 -54
  354. package/dist-sdk/server/src/tools/packs/acts/engine/sheet.js +0 -200
  355. package/dist-sdk/server/src/tools/packs/acts/index.d.ts +0 -2
  356. package/dist-sdk/server/src/tools/packs/acts/index.js +0 -24
  357. package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.d.ts +0 -2
  358. package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.js +0 -184
  359. package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.d.ts +0 -2
  360. package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.js +0 -107
  361. package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.d.ts +0 -3
  362. package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.js +0 -146
  363. package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.d.ts +0 -4
  364. package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.js +0 -241
  365. package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.d.ts +0 -3
  366. package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.js +0 -72
  367. package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.d.ts +0 -2
  368. package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.js +0 -75
  369. package/dist-sdk/server/src/tools/packs/acts/tools/shared.d.ts +0 -20
  370. package/dist-sdk/server/src/tools/packs/acts/tools/shared.js +0 -70
  371. package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.d.ts +0 -4
  372. package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.js +0 -215
  373. package/docs/.nojekyll +0 -1
  374. package/docs/assets/hierarchy.js +0 -1
  375. package/docs/assets/highlight.css +0 -113
  376. package/docs/assets/icons.js +0 -18
  377. package/docs/assets/icons.svg +0 -1
  378. package/docs/assets/main.js +0 -60
  379. package/docs/assets/navigation.js +0 -1
  380. package/docs/assets/search.js +0 -1
  381. package/docs/assets/style.css +0 -1648
  382. package/docs/classes/Agent.html +0 -801
  383. package/docs/classes/Briyah.html +0 -296
  384. package/docs/classes/BriyahConfigService.html +0 -119
  385. package/docs/classes/NativeToolRegistry.html +0 -166
  386. package/docs/classes/PackInstantiationService.html +0 -157
  387. package/docs/classes/PackService.html +0 -247
  388. package/docs/classes/Room.html +0 -1338
  389. package/docs/classes/RoomMessage.html +0 -290
  390. package/docs/enums/MessageAction.html +0 -136
  391. package/docs/functions/actsTools.html +0 -44
  392. package/docs/functions/availableToolPacks.html +0 -41
  393. package/docs/functions/buildMarkdown.html +0 -54
  394. package/docs/functions/dnd5eTools.html +0 -44
  395. package/docs/functions/installToolPacks.html +0 -48
  396. package/docs/functions/pageMarker.html +0 -45
  397. package/docs/functions/registerToolPacks.html +0 -54
  398. package/docs/functions/splitMarkdownIntoPages.html +0 -51
  399. package/docs/functions/stripWrappingFence.html +0 -52
  400. package/docs/hierarchy.html +0 -46
  401. package/docs/index.html +0 -595
  402. package/docs/interfaces/AgentCreationOptions.html +0 -125
  403. package/docs/interfaces/AgentInfo.html +0 -218
  404. package/docs/interfaces/AgentMessagesResponse.html +0 -74
  405. package/docs/interfaces/AppService.html +0 -3337
  406. package/docs/interfaces/Artifact.html +0 -95
  407. package/docs/interfaces/ArtifactMetadata.html +0 -112
  408. package/docs/interfaces/ArtifactWriteOptions.html +0 -90
  409. package/docs/interfaces/AttachDocumentResponse.html +0 -62
  410. package/docs/interfaces/BriyahConfigOptions.html +0 -124
  411. package/docs/interfaces/ChapterInfo.html +0 -62
  412. package/docs/interfaces/Character.html +0 -86
  413. package/docs/interfaces/ConversionAgent.html +0 -78
  414. package/docs/interfaces/CreateAgentResponse.html +0 -56
  415. package/docs/interfaces/CreateRoomResponse.html +0 -62
  416. package/docs/interfaces/CreateStoryResponse.html +0 -56
  417. package/docs/interfaces/FileList.html +0 -56
  418. package/docs/interfaces/FileMetadata.html +0 -89
  419. package/docs/interfaces/IConfigService.html +0 -79
  420. package/docs/interfaces/InstantiateModels.html +0 -64
  421. package/docs/interfaces/InstantiateRoomResult.html +0 -70
  422. package/docs/interfaces/LoadedPack.html +0 -131
  423. package/docs/interfaces/LoggingOptions.html +0 -92
  424. package/docs/interfaces/Message.html +0 -84
  425. package/docs/interfaces/ModelChoice.html +0 -73
  426. package/docs/interfaces/ModelInfo.html +0 -74
  427. package/docs/interfaces/NativeToolDefinition.html +0 -107
  428. package/docs/interfaces/PackAgentTemplate.html +0 -101
  429. package/docs/interfaces/PackRoomTemplate.html +0 -108
  430. package/docs/interfaces/PackView.html +0 -172
  431. package/docs/interfaces/PdfConversionOptions.html +0 -102
  432. package/docs/interfaces/PdfConversionResult.html +0 -97
  433. package/docs/interfaces/PdfMarkdownOptions.html +0 -198
  434. package/docs/interfaces/PdfMarkdownResult.html +0 -106
  435. package/docs/interfaces/PdfPageMarkdown.html +0 -94
  436. package/docs/interfaces/PreparedPromptResponse.html +0 -62
  437. package/docs/interfaces/ProcessTextResponse.html +0 -86
  438. package/docs/interfaces/PromptFile.html +0 -70
  439. package/docs/interfaces/PromptFileContent.html +0 -76
  440. package/docs/interfaces/PromptFilesResponse.html +0 -56
  441. package/docs/interfaces/PromptFolder.html +0 -80
  442. package/docs/interfaces/PromptFolderDefaults.html +0 -155
  443. package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
  444. package/docs/interfaces/PromptFoldersResponse.html +0 -56
  445. package/docs/interfaces/RoomDetails.html +0 -151
  446. package/docs/interfaces/RoomErrorUpdate.html +0 -82
  447. package/docs/interfaces/RoomInfo.html +0 -88
  448. package/docs/interfaces/RoomMessageUpdate.html +0 -113
  449. package/docs/interfaces/RoomMessagesResponse.html +0 -62
  450. package/docs/interfaces/SendMessageResult.html +0 -62
  451. package/docs/interfaces/StoryErrorEvent.html +0 -84
  452. package/docs/interfaces/StoryIdea.html +0 -74
  453. package/docs/interfaces/StoryInfo.html +0 -198
  454. package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
  455. package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
  456. package/docs/interfaces/StoryState.html +0 -108
  457. package/docs/interfaces/StoryStateEvent.html +0 -76
  458. package/docs/interfaces/ToolArtifact.html +0 -85
  459. package/docs/interfaces/ToolCaller.html +0 -77
  460. package/docs/interfaces/ToolDefinition.html +0 -80
  461. package/docs/interfaces/ToolHelpers.html +0 -105
  462. package/docs/interfaces/ToolPackDocuments.html +0 -100
  463. package/docs/interfaces/ToolParameter.html +0 -74
  464. package/docs/interfaces/ToolRoomAccess.html +0 -227
  465. package/docs/interfaces/ToolSummary.html +0 -74
  466. package/docs/interfaces/ToolsResponse.html +0 -68
  467. package/docs/interfaces/Transaction.html +0 -104
  468. package/docs/interfaces/TransactionHistoryResponse.html +0 -62
  469. package/docs/modules.html +0 -53
  470. package/docs/types/PackOrigin.html +0 -34
  471. package/docs/types/PromptScope.html +0 -34
  472. package/docs/types/RoomTurnMode.html +0 -42
  473. package/docs/types/RoomUpdate.html +0 -36
  474. package/docs/types/RosterOverrides.html +0 -42
  475. package/docs/types/ToolContext.html +0 -40
  476. package/docs/types/ToolRunResult.html +0 -34
  477. package/src/tools/packs/dnd5e/README.md +0 -867
@@ -4,10 +4,99 @@ import { RoomMessage } from './message';
4
4
  import { Artifact } from './artifact';
5
5
  import { ToolStoreService } from '../tools/tool-store.service';
6
6
  import { ToolExecutionService } from '../tools/tool-execution.service';
7
+ /** What a rename did, or why it did nothing. */
8
+ export interface RenameResult {
9
+ renamed: boolean;
10
+ /** The nickname the agent had. */
11
+ from?: string;
12
+ /** The nickname it has now. */
13
+ to?: string;
14
+ /** The full name it has now, which may be longer than the nickname. */
15
+ fullName?: string;
16
+ reason?: 'not_found' | 'ambiguous' | 'invalid' | 'unchanged';
17
+ /** For `ambiguous`, the agent the requested name would have collided with. */
18
+ conflictsWith?: string;
19
+ /** How many artifacts had their creator or viewers rewritten. */
20
+ artifactsUpdated?: number;
21
+ }
7
22
  export declare class Room {
23
+ /**
24
+ * Maximum EXECUTE/PUBLISH chain length within a single agent turn.
25
+ *
26
+ * A backstop against an agent looping on its tools forever, not a budget. Five
27
+ * was too tight for anything with real bookkeeping: a single round of combat runs
28
+ * a spell lookup, a resource spend, the attack and damage rolls, the hit point
29
+ * change and then the narration, and a character build runs create, read and
30
+ * patch before the hand-back. Half of one campaign's Dungeon Master turns hit the
31
+ * limit, and hitting it is expensive in its own right — the turn is re-prompted,
32
+ * the work is often redone, and a person has to notice and say "carry on".
33
+ *
34
+ * Raise it with `ROOM_MAX_TOOL_ITERATIONS`. Read per turn so it can be retuned on
35
+ * a running server, and floored at 1 so a nonsense value cannot stop every agent
36
+ * from acting.
37
+ *
38
+ * @returns The number of tool calls an agent may chain in one turn
39
+ */
8
40
  private static maxToolIterations;
41
+ /** What an agent is told when it is prompted again because it still holds the floor. */
9
42
  private static readonly CONTINUE_NOTE;
43
+ /**
44
+ * How many times in a row an agent may be handed the floor back to itself.
45
+ *
46
+ * A self-loop normally means a stuck room, which is why both routing paths broke
47
+ * one unconditionally. But an agent sometimes genuinely still holds the floor: a
48
+ * Battle Master running consecutive monster turns has nobody to address — a
49
+ * monster's turn has no addressee — and when every player character is unconscious
50
+ * there is no player to hand to either. That is exactly where one campaign stalled,
51
+ * needing a person to type "Marshal, continue" seven times in one fight.
52
+ *
53
+ * So the loop is allowed, and bounded. Three is enough for a few rounds of a fight
54
+ * nobody is awake for, and short enough that a genuinely stuck agent is stopped
55
+ * before it costs much. Raise it with `ROOM_MAX_SELF_CONTINUES`.
56
+ *
57
+ * @returns The number of consecutive self-addressed turns permitted
58
+ */
10
59
  private static maxSelfContinues;
60
+ /**
61
+ * How many stalled turns in a row the room may re-route before it gives up.
62
+ *
63
+ * Counted since the last word actually said, not since the room opened: any
64
+ * audible message resets it, so a table that stalls once an hour never runs out.
65
+ * The cap exists for the case where re-routing cannot help — every agent in turn
66
+ * declining the same message — and the room would otherwise pay a moderator call
67
+ * per attempt forever with nobody at the keyboard to stop it.
68
+ *
69
+ * Raise it with `ROOM_MAX_STALL_RECOVERIES`; zero switches recovery off.
70
+ *
71
+ * @returns The number of consecutive recoveries permitted
72
+ */
73
+ private static maxStallRecoveries;
74
+ /**
75
+ * What the moderator is told when it is asked to re-route a stalled message.
76
+ * @param sender Who sent the message nobody answered
77
+ * @param declined Everyone that has already been asked to answer it
78
+ * @returns A note for the moderator's transient prompt
79
+ */
80
+ private static rerouteNote;
81
+ /**
82
+ * What the re-routed agent is told, so it can tell this from being handed a
83
+ * message it has already seen answered.
84
+ * @param sender Who sent the message
85
+ * @param declined Everyone that was asked before it
86
+ * @returns A system note for the agent's history
87
+ */
88
+ private static rerouteHandoffNote;
89
+ /**
90
+ * What the sender is told when its own unanswered message comes back to it.
91
+ *
92
+ * The last resort, and at a game table not a rare one: the leader is usually the
93
+ * one who addressed the wrong agent, so it is both the sender and the fallback.
94
+ * Being told to try again is a real recovery — it is the only agent that knows
95
+ * who the message was meant for.
96
+ * @param declined Everyone that was asked and did not answer
97
+ * @returns A system note for the sender's history
98
+ */
99
+ private static retryHandoffNote;
11
100
  private id;
12
101
  private name;
13
102
  private goal;
@@ -16,6 +105,16 @@ export declare class Room {
16
105
  private roomLeader;
17
106
  private turnMode;
18
107
  private moderator;
108
+ /**
109
+ * Who heard the message the moderator routed last, told to the moderator on its
110
+ * next turn.
111
+ *
112
+ * What makes a conversation with a sub-group hold together: speak to three of six
113
+ * agents, and the follow-up should reach the same three rather than whoever the
114
+ * moderator reconstructs from a 16-message history. Kept in memory only — losing
115
+ * it across a restart costs one turn of continuity, which is not worth persisting
116
+ * for.
117
+ */
19
118
  private lastModeratedAudience;
20
119
  private roomMessages;
21
120
  private pendingMessages;
@@ -26,8 +125,18 @@ export declare class Room {
26
125
  private processingInProgress;
27
126
  private isPaused;
28
127
  private currentSpeaker;
128
+ /** The agent currently keeping the floor by addressing itself, if any. */
29
129
  private selfContinuingAgent;
130
+ /** How many turns in a row {@link selfContinuingAgent} has held it. */
30
131
  private consecutiveSelfContinues;
132
+ /**
133
+ * The last audible message this room asked somebody to answer, and who was
134
+ * asked. Read only by {@link recoverStalledFloor}. In memory only: a restart
135
+ * ends any turn that was in flight, so there is nothing left to re-route.
136
+ */
137
+ private lastDispatch;
138
+ /** Consecutive stalls re-routed since the last word said. See {@link maxStallRecoveries}. */
139
+ private stallRecoveries;
31
140
  private isPublished;
32
141
  private isLoading;
33
142
  private onStateChangeCallbacks;
@@ -37,7 +146,9 @@ export declare class Room {
37
146
  private onSituationUpdate?;
38
147
  private onModeratorResponseCallback?;
39
148
  private templateRoomId;
149
+ /** The pack this room is filed under. See {@link RoomConfig.pack}. */
40
150
  private pack;
151
+ /** The pack template's key, when this room came from one. */
41
152
  private packRoomKey;
42
153
  private storageDir;
43
154
  private roomStoreService;
@@ -58,27 +169,150 @@ export declare class Room {
58
169
  getPaused(): boolean;
59
170
  getTemplateRoomId(): string | undefined;
60
171
  setTemplateRoomId(templateId: string): void;
172
+ /** @returns The pack this room is filed under, or undefined when it is not filed */
61
173
  getPack(): string | undefined;
174
+ /**
175
+ * Files this room under a pack, or clears it.
176
+ * @param pack The pack name; empty or undefined clears it
177
+ */
62
178
  setPack(pack: string | undefined): void;
179
+ /** @returns The pack template's key, when this room came from one */
63
180
  getPackRoomKey(): string | undefined;
64
181
  setPackRoomKey(key: string | undefined): void;
65
182
  clearRoomMessages(): void;
183
+ /**
184
+ * Adds an agent to the room
185
+ * @param agent The agent to add
186
+ * @returns True if the agent was added, false if it was already in the room
187
+ */
66
188
  arrive(agent: Agent): boolean;
67
189
  getAgents(): Agent[];
190
+ /**
191
+ * Replaces all agents in the room with new agents
192
+ * @param newAgents Array of agents to set
193
+ */
68
194
  setAgents(newAgents: Agent[]): void;
69
195
  describeAgentsInRoom(): string;
70
196
  setRoomLeader(agentNickname: string): void;
71
197
  getRoomLeader(): string;
72
198
  getTurnMode(): RoomTurnMode;
199
+ /**
200
+ * Sets how the room chooses who responds to a message. See {@link RoomTurnMode}.
201
+ * @param mode The turn mode; anything unrecognized falls back to 'broadcast'
202
+ */
73
203
  setTurnMode(mode: RoomTurnMode): void;
204
+ /** @returns The configured moderator nickname, or '' when none is set */
74
205
  getModerator(): string;
206
+ /**
207
+ * Names the agent that places messages the room cannot route mechanically.
208
+ * @param agentNickname The moderator's nickname; empty clears it
209
+ */
75
210
  setModerator(agentNickname: string): void;
76
211
  getAgentCount(): number;
77
212
  ready(): void;
78
213
  getCurrentSpeaker(): string | null;
79
214
  setCurrentSpeaker(agentNickname: string | null): void;
80
215
  isAgentsTurn(agentNickname: string): boolean;
216
+ /**
217
+ * Ends the room's turn: drops the processing lock, settles who holds the floor,
218
+ * and optionally keeps draining the queue.
219
+ *
220
+ * Every path that finishes a turn goes through here. It used to be open-coded
221
+ * at fifteen sites, and the omissions were the bug: the main responder loop
222
+ * released the lock without giving up the floor, so any turn that ended without
223
+ * producing a message pinned the floor to an agent forever and the human could
224
+ * never speak again. Two more sites had the same gap.
225
+ *
226
+ * The invariant it exists to hold: **once no turn is in flight, the floor is
227
+ * either nobody's or the human's.** An AI agent holding it with nothing running
228
+ * is a dead room.
229
+ *
230
+ * In a directed room that invariant is only half of it. The floor being nobody's
231
+ * with nothing queued is a dead room too, because in directed mode the floor is a
232
+ * baton: one agent is prompted, and the room only moves on if that agent's turn
233
+ * produces an audible message. {@link recoverStalledFloor} closes that half, and
234
+ * runs here so that every path ending a turn is covered rather than the handful
235
+ * anyone thought to guard.
236
+ * @param floor Who holds the floor now — see {@link FloorHandover}
237
+ * @param opts.drain True to keep processing anything queued
238
+ */
81
239
  private endTurn;
240
+ /**
241
+ * Puts the floor back in somebody's hands when a directed turn ended without a
242
+ * word said.
243
+ *
244
+ * The stall this exists for: a message is addressed to the wrong agent, that
245
+ * agent answers with a `think` — reasonably, since the message was not for it —
246
+ * and a thought prompts nobody. The turn ends, the floor is released, the queue
247
+ * is empty and the room sits there. A `think` is only the commonest way in; a
248
+ * turn that fails, returns nothing, or spends itself on tool calls leaves the
249
+ * room in exactly the same state, which is why this guards the state rather than
250
+ * the action that produced it.
251
+ *
252
+ * **In a directed room, an empty queue with the floor held by nobody is always a
253
+ * stall.** A message meant for a person hands them the floor by name, so a
254
+ * released floor is never "waiting for the human" — it is nobody's turn at all.
255
+ *
256
+ * Recovery is the moderator's existing job: it is handed the unanswered message
257
+ * and asked who should have answered it. Nothing about the stall reaches the
258
+ * transcript — the message has already been logged and heard once, and a second
259
+ * copy of it, or a note about the plumbing, is not part of the story.
260
+ *
261
+ * Needs a moderator that was actually configured. {@link getModeratorAgent} falls
262
+ * back to the first non-player agent, which at a game table is the Dungeon Master
263
+ * — asking it to route its own unanswered message is the confusion this is
264
+ * supposed to end, so a room without a moderator keeps the old behaviour and
265
+ * waits for a person.
266
+ */
267
+ private recoverStalledFloor;
268
+ /**
269
+ * The moderator this room was configured with, and only that one.
270
+ *
271
+ * Unlike {@link getModeratorAgent} there is no fallback: a caller that needs a
272
+ * genuine moderator would rather have none than the room leader.
273
+ * @returns The configured moderator agent, or undefined
274
+ */
275
+ private configuredModerator;
276
+ /**
277
+ * Asks the moderator who should have answered a message nobody did, then gives
278
+ * that agent the floor.
279
+ *
280
+ * The message itself is not re-logged and not re-delivered: everyone who could
281
+ * hear it already did, on its first pass. Only the chosen agent is touched, with
282
+ * a note saying why it is being asked — without one it cannot tell this from
283
+ * being handed something it has already watched somebody else answer.
284
+ * @param dispatch The unanswered message and everyone already asked
285
+ * @param moderator The room's configured moderator
286
+ */
287
+ private rerouteStalledTurn;
288
+ /**
289
+ * Picks the agent a re-routed message goes to.
290
+ *
291
+ * Three candidates, in order: whoever the moderator named, the room leader — the
292
+ * same contract {@link handleModeratorResponse} works to — and finally the sender
293
+ * itself, told to try again. Everyone that has already declined the message is
294
+ * skipped at each step, and so is the moderator, which never answers.
295
+ *
296
+ * The sender is last rather than excluded because at a game table it is usually
297
+ * also the leader: the Dungeon Master addresses the wrong player far more often
298
+ * than anyone else does, so excluding it would leave the commonest stall with
299
+ * nowhere to go.
300
+ * @param named The nickname the moderator answered with, if any
301
+ * @param dispatch The unanswered message and everyone already asked
302
+ * @param moderator The moderator that was consulted
303
+ * @returns The agent to give the floor to, or undefined if there is nobody left
304
+ */
305
+ private resolveRerouteResponder;
306
+ /**
307
+ * Files an agent's response from a turn that has just ended.
308
+ *
309
+ * A thought is nobody's message but its own, so it is logged and goes no further.
310
+ * A shout jumps the queue. Anything else joins the back of it — and, being an
311
+ * audible message, is the room making progress, which is what ends a run of
312
+ * stall recoveries.
313
+ * @param message The response, or null if the turn produced nothing
314
+ */
315
+ private queueAgentResponse;
82
316
  getRoomMessageStats(): {
83
317
  numMessages: number;
84
318
  numChars: number;
@@ -91,44 +325,454 @@ export declare class Room {
91
325
  addRoomMessages(messages: RoomMessage[]): void;
92
326
  getCreatedAt(): Date;
93
327
  setCreatedAt(date: Date): void;
328
+ /**
329
+ * Gets all artifacts in the room
330
+ * @returns Array of artifacts
331
+ */
94
332
  getArtifacts(): Artifact[];
333
+ /**
334
+ * Renames an agent, and everything in this room that named it.
335
+ *
336
+ * A room routes by nickname and nothing else, so an agent whose character is
337
+ * called something different gives every other agent two names for one person.
338
+ * The Dungeon Master addresses the character, the room has never heard of them,
339
+ * and the message falls through to the moderator — see
340
+ * {@link namesNobodyInADirectedRoom}, which exists to catch exactly that and
341
+ * once absorbed about a quarter of a campaign's calls. This is the fix that
342
+ * makes the workaround unnecessary: give the agent the character's name.
343
+ *
344
+ * Expensive in the same way {@link ToolRoomAccess.setDescription} is, and for
345
+ * the same reason: the roster sits in every agent's *cached* prompt prefix, so
346
+ * a rename throws away the whole room's cache. Character creation is the moment
347
+ * for it, because play has not started; mid-scene it is a real cost.
348
+ *
349
+ * **History is deliberately not rewritten.** Past messages are a record of what
350
+ * was said, and rewriting them would mean parsing and re-serializing every
351
+ * entry, with compaction summaries reachable only by regex. Instead every agent
352
+ * is told, once, that the name changed — which is what lets them reconcile a
353
+ * roster that says `Leah` with a history that says `StudentOne`.
354
+ *
355
+ * @param from The agent to rename, matched the way messages are routed
356
+ * @param to The new name — a character name, which may be longer than a nickname
357
+ * @returns What happened, including the reason when nothing did
358
+ */
359
+ renameAgent(from: string, to: string): RenameResult;
360
+ /**
361
+ * The agent this room would refuse to rename to `nickname`, if any.
362
+ *
363
+ * Separate from {@link renameAgent} so a caller renaming an agent that sits in
364
+ * more than one room can check them all before changing anything — a rename
365
+ * applied to two rooms and refused by a third would leave the agent named one
366
+ * thing and half the rooms pointing at another.
367
+ *
368
+ * @param agent The agent being renamed, excluded from its own check
369
+ * @param nickname The nickname it would take
370
+ * @returns The conflicting agent's nickname, or undefined
371
+ */
372
+ conflictingNickname(agent: Agent, nickname: string): string | undefined;
373
+ /**
374
+ * Repoints everything in *this room* that named an agent, and tells the room.
375
+ *
376
+ * The room-side half of a rename, split out because an agent may sit in more
377
+ * than one room while its own record is only mutated once. {@link renameAgent}
378
+ * is this plus the agent itself.
379
+ *
380
+ * @param previous The nickname being replaced
381
+ * @param nickname The nickname replacing it
382
+ * @returns How many artifacts changed
383
+ */
384
+ repointNickname(previous: string, nickname: string): number;
385
+ /**
386
+ * Repoints every artifact that named the old nickname.
387
+ *
388
+ * `viewers` is the one that fails silently: an artifact keeps working, the agent
389
+ * simply stops being able to see it, so a player loses their own character sheet
390
+ * with nothing logged. `creator` decides attribution and counts as a viewer.
391
+ *
392
+ * @param previous The nickname being replaced
393
+ * @param nickname The nickname replacing it
394
+ * @returns How many artifacts changed
395
+ */
396
+ private renameInArtifacts;
397
+ /**
398
+ * Tells every agent in the room that a name changed.
399
+ *
400
+ * One line each, and the reason the history can be left alone: without it an
401
+ * agent reads `Leah` in the roster and `StudentOne` in its own history with
402
+ * nothing joining the two, which is the confusion the rename exists to remove.
403
+ * The renamed agent is told as well — it is the one most likely to be unsure
404
+ * what it is called.
405
+ */
406
+ private announceRename;
407
+ /**
408
+ * Checks if the room is currently adjourned
409
+ * @returns True if the room is adjourned, false otherwise
410
+ */
95
411
  isRoomAdjourned(): boolean;
412
+ /**
413
+ * Sets the room's artifacts (used when loading from storage)
414
+ * @param artifacts Array of artifacts to set
415
+ */
96
416
  setArtifacts(artifacts: Artifact[]): void;
417
+ /**
418
+ * Whether a message names recipients but none of them is in this room.
419
+ *
420
+ * Only asked of a directed room, where a message is answered by the one agent it
421
+ * names. `selectResponders` cannot place such a message: no target matches, and
422
+ * the leader is skipped when it is the sender — which it is whenever the leader
423
+ * is the one who misnamed someone. What is left is a fallback that widens to
424
+ * *every* other agent, and a directed room exists precisely to avoid that. One
425
+ * campaign spent about a quarter of its calls there, because the Dungeon Master
426
+ * addressed a player by their character's name rather than the nickname the room
427
+ * knows them by.
428
+ *
429
+ * Moderating instead costs one cheap call and is the moderator's documented job:
430
+ * a message that "did not name a recipient the room could use" is routed from its
431
+ * content. A misnamed target is usually a non-player character anyway, and the
432
+ * moderator already knows to hand those to the room leader.
433
+ *
434
+ * @param action The message's normalized action
435
+ * @param targets The names the message was addressed to
436
+ * @returns True when the room should moderate rather than guess
437
+ */
97
438
  private namesNobodyInADirectedRoom;
439
+ /**
440
+ * Parses AI response into RoomMessage object (private helper moved from Agent)
441
+ * @param agent The agent that made the response
442
+ * @param response Raw AI response object
443
+ * @returns Parsed RoomMessage object
444
+ */
98
445
  private parseAgentResponse;
446
+ /**
447
+ * Extracts an opaque "preamble" block from the top of an agent response.
448
+ *
449
+ * A preamble is one or more consecutive `<tag>value</tag>` lines at the
450
+ * very start of the response, terminated by a blank line or non-tag
451
+ * content. The captured preamble is the verbatim text of those tag
452
+ * lines, suitable for downstream parsing by whoever owns the semantic
453
+ * interpretation (e.g. the story service for narrator responses).
454
+ *
455
+ * The Room itself never parses the preamble's contents. It just hands
456
+ * the text to the situation callback so callers (story, debate, etc.)
457
+ * can interpret it however they want.
458
+ */
99
459
  static extractPreamble(response: string): {
100
460
  preamble: string;
101
461
  content: string;
102
462
  } | null;
463
+ /**
464
+ * Maps an arbitrary action string to a MessageAction enum value,
465
+ * accepting any casing. Returns undefined if the value doesn't correspond
466
+ * to a known action.
467
+ */
103
468
  private static coerceMessageAction;
469
+ /**
470
+ * Determines which character agents are part of a message's audience, so a
471
+ * perceiving agent can be shown (in the transient situation message) the
472
+ * descriptions of only the characters it is currently interacting with.
473
+ *
474
+ * The audience is taken from the message's `targets` (the moderator fills these
475
+ * with every agent who can hear the message) plus the message sender. Only
476
+ * character agents (promptFolder === 'character') are returned; the narrator,
477
+ * moderator and other support agents are excluded. The perceiving agent is never
478
+ * included in its own list. When a message has no explicit targets (e.g. a plain
479
+ * SPEAK broadcast in a non-story room) every character who can hear it is included.
480
+ *
481
+ * @param perceivingAgent The agent that will receive these descriptions
482
+ * @param message The message being perceived
483
+ * @returns Character agents in the message's audience, excluding the perceiver
484
+ */
104
485
  private getPresentCharacters;
486
+ /**
487
+ * Builds a digest of the other agents' private context (in stories, their
488
+ * inventory and conditions), for the oversight agents — the moderator and the room
489
+ * leader (the Narrator in stories) — who need to keep the world consistent. Other
490
+ * agents never see this; each only sees its own private context. The leader's own
491
+ * context is left out, since it already receives that directly. Returns an
492
+ * empty string when nobody else has any private context.
493
+ *
494
+ * @returns A markdown block of per-agent private context, or '' if none
495
+ */
105
496
  private buildCharacterPrivateContextDigest;
497
+ /**
498
+ * Builds the descriptors of the tools granted to an agent, for rendering into
499
+ * its perceive prompt. Tool code is never exposed — only name, description and
500
+ * parameters. Tools that were deleted after being granted are silently dropped.
501
+ * @param agent The agent whose granted tools to describe
502
+ * @returns Array of tool descriptors (empty when the agent has no usable tools)
503
+ */
106
504
  private buildAvailableTools;
505
+ /**
506
+ * Renders an artifact for a prompt, dropping any ```briyah-state fenced
507
+ * block.
508
+ *
509
+ * That fence is the convention for machine state an artifact carries for the
510
+ * tools that maintain it — a character sheet keeps its whole state object
511
+ * there, below the human-readable summary. Tools read the artifact directly
512
+ * and are unaffected; a model never needs it, and pasting a page of raw JSON
513
+ * into a prompt full of JSON is how a small model loses track of which JSON
514
+ * it is supposed to be producing.
515
+ *
516
+ * An unterminated fence drops everything after it, which is the right
517
+ * reading: whatever follows an opening state fence is state too.
518
+ * @param artifact The artifact to render
519
+ * @returns The prompt-facing text
520
+ */
107
521
  private static renderArtifactForPrompt;
522
+ /**
523
+ * Builds the Handlebars variables for an agent's perceive prompt,
524
+ * including artifacts and the agent's granted tools.
525
+ * @param agent The agent generating a response
526
+ * @returns The prompt variables
527
+ */
108
528
  private buildPerceiveVariables;
529
+ /**
530
+ * The names of the artifacts an agent cannot read.
531
+ *
532
+ * Volatile by nature: it changes whenever *any* artifact anywhere in the room is
533
+ * created or deleted, for every agent that cannot read the new one. That put it in
534
+ * the wrong half of the prompt for a long time. `transient` protects an artifact's
535
+ * contents and nothing protected the roster, so placing four monsters at the start
536
+ * of a fight rewrote this string for eight of nine agents and invalidated all eight
537
+ * cached prefixes. Measured across one session it was 41.7% of the entire
538
+ * cache-creation spend — and the Battle Master, the one agent that *could* read the
539
+ * new artifacts, was the only one the fight cost nothing.
540
+ *
541
+ * Measured against what the agent can *read*, not against the cached block: a
542
+ * transient artifact arrives in the per-turn prompt, so naming it here as one the
543
+ * agent cannot see would be a lie.
544
+ * @param nickname The agent the list is for
545
+ * @returns A comma-separated list, or '' when the agent can read everything
546
+ */
109
547
  private invisibleArtifactNames;
548
+ /**
549
+ * Builds the transient (uncached) prompt message for an agent. It is sent
550
+ * uncached and is not saved to the agent's history, which makes it the right
551
+ * place to inject context that changes frequently, so a change never
552
+ * invalidates the cached prompt instructions:
553
+ * - the descriptions of the characters present in this message's audience
554
+ * (each character sees how the others currently look without leaking
555
+ * details about characters who are elsewhere), and
556
+ * - the perceiving agent's own private context (e.g. its story inventory
557
+ * and conditions), which only that agent may see.
558
+ * The in-story time and situation text lead the transient prompt; the time
559
+ * is on its own labeled line (see buildSituationHeader).
560
+ * @param agent The agent that will receive this prompt
561
+ * @param message The message being perceived, or null for follow-up prompts
562
+ * within the same turn (e.g. after a tool result), where there is no new
563
+ * message audience to describe
564
+ * @returns The transient prompt, or null if there is nothing to inject
565
+ */
110
566
  private buildTransientPrompt;
567
+ /**
568
+ * Sends a single perceive prompt to an agent and parses the response.
569
+ * The raw response is added to the agent's history. InsufficientBalanceError
570
+ * (and any other error) propagates to the caller.
571
+ * @param agent The agent generating a response
572
+ * @param transientPrompt The uncached prompt message (see buildTransientPrompt)
573
+ * @param variables The Handlebars variables (see buildPerceiveVariables)
574
+ * @returns The agent's parsed response
575
+ */
111
576
  private promptAgentOnce;
577
+ /**
578
+ * Runs an agent's full turn: an initial response to the heard message,
579
+ * followed by a private research loop. EXECUTE and PUBLISH responses are
580
+ * handled here — the tool result (or publish confirmation) is fed back into
581
+ * the agent's history and the agent is re-prompted — until the agent emits
582
+ * an audible action or the iteration cap is hit. The room's processing lock
583
+ * is held by the caller for the duration, so other agents wait.
584
+ * @param agent The agent taking its turn
585
+ * @param heardMessage The message that triggered this turn (already in the
586
+ * agent's history), or null when the trigger was fed to the history
587
+ * directly (e.g. commission deliverables)
588
+ * @param opts inCommission: the agent is a commission target; nested
589
+ * commissions are rejected and DELIVER is the expected terminal action
590
+ * @returns The agent's final audible message, or null if the room was
591
+ * paused/adjourned mid-turn
592
+ */
112
593
  private runAgentTurn;
594
+ /**
595
+ * Runs a tool for an agent's EXECUTE message and returns the feedback string
596
+ * to add to the agent's history. Also logs a TOOL notice to the room so
597
+ * humans watching (with thoughts visible) can see the activity.
598
+ * @param agent The agent that issued the EXECUTE
599
+ * @param message The EXECUTE message (name = tool name, content = JSON args)
600
+ * @returns The feedback string for the agent's history
601
+ */
113
602
  private executeToolForAgent;
603
+ /**
604
+ * How much of a result a TOOL notice shows.
605
+ *
606
+ * Generous because the result is the half a person needs when something has gone
607
+ * wrong, and a clipped one hides whether a call that reported success actually
608
+ * changed anything.
609
+ *
610
+ * Most results never reach this: {@link describeToolResult} prefers a result's own
611
+ * `detail` or `summary` one-liner, and the 5e tools all write one. It binds on the
612
+ * results that have neither, which are the raw ones worth reading in full.
613
+ */
114
614
  private static readonly TOOL_LOG_PREVIEW;
615
+ /**
616
+ * How much of an EXECUTE's arguments the room's TOOL notice keeps.
617
+ *
618
+ * Far longer than the result's allowance because the arguments are the half a
619
+ * person actually reads — what the agent asked the tool to do — and at 200
620
+ * characters a `create_sheet` call was cut off inside its own spec, showing the
621
+ * character's race and nothing after it. The bound is a sanity limit rather than
622
+ * a budget: arguments are written by a model, so they are already short.
623
+ *
624
+ * A TOOL notice is heard by nobody and never enters an agent's history
625
+ * (`RoomMessage.canHear` refuses TOOL), so none of this costs a token. It costs
626
+ * bytes in the room log and on the update stream, which is the right trade for
627
+ * being able to see what was run.
628
+ */
115
629
  private static readonly TOOL_LOG_ARGS_PREVIEW;
630
+ /** Clips a preview so one tool call cannot fill the transcript. */
116
631
  private static previewForToolLog;
632
+ /**
633
+ * Summarizes a successful tool result for the room log.
634
+ *
635
+ * `ok` on its own hid the only part anyone watching wanted: a check that
636
+ * rolled 11 against DC 13 and failed was logged exactly like one that passed.
637
+ * A result carrying its own one-line summary — `detail` or `summary`, the two
638
+ * the 5e tools already write — is quoted; anything else is shown as a clipped
639
+ * JSON preview, which at least says what came back.
640
+ *
641
+ * Deliberately no knowledge of any particular tool: these are conventional
642
+ * field names, and a tool that uses neither still reads better than 'ok'.
643
+ *
644
+ * A TOOL notice is heard by nobody and never enters an agent's history, so
645
+ * none of this costs a token — it is purely for the person reading the room.
646
+ * @param value The `result` of a successful run
647
+ * @returns A single line for the notice
648
+ */
117
649
  private static describeToolResult;
650
+ /**
651
+ * Builds the room access a tool receives as `helpers.room`, scoped to the
652
+ * agent that invoked it. Deliberately a closure rather than a class holding
653
+ * a Room reference: {@link ToolRoomAccess} is part of the tool-facing
654
+ * contract, and importing Room into it would pull the whole room graph into
655
+ * the SDK's public types.
656
+ *
657
+ * The wrapper is not a pass-through to publishArtifact — it corrects three
658
+ * behaviors that are right for an agent's PUBLISH but wrong for a tool:
659
+ * publishArtifact credits the artifact to whoever wrote last, treats an
660
+ * empty viewers list as creator-only, and deletes on an empty body.
661
+ * @param agent The agent whose EXECUTE triggered the tool call
662
+ * @returns The room accessor handed to the tool
663
+ */
118
664
  private buildToolRoomAccess;
665
+ /**
666
+ * Gets AI response for an agent (private helper moved from Agent).
667
+ * Thin callback adapter around runAgentTurn: the callback does not fire
668
+ * until the agent's whole turn (including any tool research loop) is done,
669
+ * which is what holds the room's processing lock for the duration.
670
+ * @param agent The agent generating response
671
+ * @param message The message the agent is responding to
672
+ * @param onResponse Callback with AI response
673
+ */
119
674
  private getAgentAiResponse;
675
+ /**
676
+ * Summarises an agent's history when it has outgrown the compaction threshold.
677
+ *
678
+ * Called at the end of a turn rather than the start of one, which is the only
679
+ * safe point: the turn's tool chain feeds results back into history and
680
+ * re-prompts, so compacting part-way through would summarise away the tool call
681
+ * whose result the agent is waiting on. By the time the turn returns, its own
682
+ * response is already in history and the summary can cover it.
683
+ *
684
+ * It also runs *before* `onResponse`, which is what releases the room to process
685
+ * the next message. Compacting afterwards would rewrite this agent's history
686
+ * while the following turn was reading it.
687
+ *
688
+ * A failed summary is logged and swallowed. The agent keeps a too-long history
689
+ * and the campaign carries on, which is strictly better than ending a turn that
690
+ * already produced a good answer because a bookkeeping call failed.
691
+ *
692
+ * @param agent The agent whose turn has just finished
693
+ */
120
694
  private compactIfOversized;
695
+ /**
696
+ * Delivers a message into an agent's history without asking it to respond.
697
+ * Split out of {@link perceive} so agents that are not responding this turn
698
+ * still stay in sync with the conversation at no LLM cost. Callers that are
699
+ * not counting this agent in their outstanding-response tally must use this
700
+ * rather than `perceive`, which always invokes its callback.
701
+ * @param agent The agent receiving the message
702
+ * @param message The message being delivered
703
+ * @returns True if the agent could hear the message and it was recorded
704
+ */
121
705
  private hear;
706
+ /**
707
+ * Allows an agent to perceive messages and generate a response (moved from Agent)
708
+ * @param agent The agent that is perceiving
709
+ * @param message
710
+ * @param onResponse Callback with agent's response or null
711
+ */
122
712
  perceive(agent: Agent, message: RoomMessage, onResponse: (message: RoomMessage | null) => void, opts?: {
123
713
  continuing?: boolean;
124
714
  }): void;
125
- moderate(moderatorAgent: Agent, message: RoomMessage, onResponse: (message: RoomMessage | null) => void): Promise<void>;
715
+ /**
716
+ * Moderator agent evaluates and routes a message (moved from Agent)
717
+ * @param moderatorAgent The moderator agent
718
+ * @param message RoomMessage to moderate
719
+ * @param onResponse Callback with routing decision
720
+ * @param opts.note Extra instruction for this one routing decision, put in the
721
+ * transient prompt so it never enters the moderator's cached prefix
722
+ */
723
+ moderate(moderatorAgent: Agent, message: RoomMessage, onResponse: (message: RoomMessage | null) => void, opts?: {
724
+ note?: string;
725
+ }): Promise<void>;
726
+ /**
727
+ * Handles insufficient balance errors by pausing the conversation
728
+ * @param error The insufficient balance error
729
+ * @param onResponse Optional callback to call with null
730
+ */
126
731
  private handleInsufficientBalance;
732
+ /**
733
+ * Gets an artifact by name
734
+ * @param name The name of the artifact
735
+ * @returns The artifact or undefined if not found
736
+ */
127
737
  findArtifact(name: string): Artifact | undefined;
738
+ /**
739
+ * Creates or updates an artifact with PUBLISH action
740
+ * If body is empty, deletes the artifact instead
741
+ * @param name The name of the artifact
742
+ * @param creator The name of the agent who created it
743
+ * @param body The content of the artifact (empty body will delete the artifact)
744
+ * @param viewers Array of agent names who can view the artifact
745
+ * @returns The created or updated artifact, or null if deleted
746
+ */
128
747
  publishArtifact(name: string, creator: string, body: string, viewers?: string[], transient?: boolean): Artifact | null;
748
+ /**
749
+ * Deletes an artifact from the room
750
+ * @param name The name of the artifact to delete
751
+ * @returns True if the artifact was found and deleted, false otherwise
752
+ */
129
753
  deleteArtifact(name: string): boolean;
754
+ /**
755
+ * Gets the artifacts an agent may read, transient ones included.
756
+ * @param agentNickname The name of the agent
757
+ * @returns Array of artifacts readable by the agent
758
+ */
130
759
  private getReadableArtifacts;
760
+ /**
761
+ * Gets the artifacts rendered into an agent's **cached** prompt block.
762
+ *
763
+ * Transient artifacts are deliberately excluded: they go in the per-turn
764
+ * prompt instead (see `buildTransientPrompt`), which is the whole point of
765
+ * marking one transient. They are still readable — `getTransientArtifacts`
766
+ * returns them, and a tool reads any artifact regardless.
767
+ * @param agentNickname The name of the agent
768
+ * @returns Array of artifacts visible to the agent
769
+ */
131
770
  getVisibleArtifacts(agentNickname: string): Artifact[];
771
+ /**
772
+ * Gets the artifacts delivered to an agent in the uncached per-turn prompt.
773
+ * @param agentNickname The name of the agent
774
+ * @returns Array of transient artifacts readable by the agent
775
+ */
132
776
  getTransientArtifacts(agentNickname: string): Artifact[];
133
777
  getId(): string;
134
778
  setId(id: string): void;
@@ -136,49 +780,310 @@ export declare class Room {
136
780
  setStorageDir(dir: string): void;
137
781
  getRoomStoreService(): any;
138
782
  setRoomStoreService(service: any): void;
783
+ /**
784
+ * @internal Injects the user-scoped tool services so agents in this room can
785
+ * EXECUTE user-defined tools. Called by RoomStoreService and RoomFactory at
786
+ * every Room construction site; SDK consumers never call this directly.
787
+ * @param toolStore The user's tool store
788
+ * @param toolExecution The user's tool execution service
789
+ */
139
790
  setToolServices(toolStore: ToolStoreService, toolExecution: ToolExecutionService): void;
791
+ /**
792
+ * Saves messages incrementally to disk
793
+ * @param messages The new messages to append
794
+ */
140
795
  saveMessages(messages: RoomMessage[]): void;
796
+ /**
797
+ * Saves the room metadata to disk
798
+ */
141
799
  saveMetadata(): string;
800
+ /**
801
+ * Registers a state-change listener under a stable key. Each key holds at most
802
+ * one listener — re-registering with the same key replaces its callback.
803
+ * Different keys can coexist so multiple subsystems (e.g. the rooms SSE endpoint
804
+ * and the story service) both receive notifications without clobbering each other.
805
+ * @param key Stable identifier for the subsystem (e.g. 'app-service', 'story')
806
+ * @param callback Function to call on state changes
807
+ */
142
808
  setOnStateChange(key: string, callback: () => void): void;
809
+ /**
810
+ * Removes a previously-registered state-change listener.
811
+ * @param key The key passed to {@link setOnStateChange}
812
+ */
143
813
  removeOnStateChange(key: string): void;
144
814
  notifyStateChange(): void;
815
+ /**
816
+ * Subscribes to errors raised while running a turn.
817
+ *
818
+ * Keyed like {@link setOnStateChange}, and for the same reason: more than one
819
+ * thing wants to hear about a failed turn. A single-callback setter meant the
820
+ * last caller silently replaced the first — the SDK's bridge onto the room's
821
+ * update stream and a story's own handler could not both exist, and whichever
822
+ * registered second won without any sign that it had taken the other's place.
823
+ *
824
+ * @param key Identifies the subscriber; registering the same key twice replaces it
825
+ * @param callback Function to call on errors
826
+ */
145
827
  setOnError(key: string, callback: (error: Error) => void): void;
828
+ /**
829
+ * Stops delivering errors to a subscriber.
830
+ * @param key The key it registered with
831
+ */
146
832
  clearOnError(key: string): void;
147
833
  private notifyError;
834
+ /**
835
+ * Every human-controlled agent in the room, in arrival order.
836
+ *
837
+ * A room may have more than one: several people can share a browser, and one
838
+ * person can play several characters. Code that genuinely needs a single human
839
+ * uses {@link getDefaultHumanAgent} — but anything reacting to a *message* must
840
+ * resolve the human from its sender, because the sender is rarely the default.
841
+ */
148
842
  getHumanAgents(): Agent[];
843
+ /**
844
+ * Names as a prompt reads them aloud: `Rhys`, `Rhys and Mira`, `Rhys, Mira and Tor`.
845
+ *
846
+ * Handlebars has no `join`, and this codebase registers no helpers, so a template
847
+ * wanting a list inline has to either be handed one or spell out an `{{#each}}`
848
+ * with `{{#unless @last}}`. Handing it over is the difference between a prompt
849
+ * that reads like a sentence and one every author gets subtly wrong — which is
850
+ * how a table with two players came to have prompts that only ever named one.
851
+ * @param names The names to list, in order
852
+ * @returns The joined phrase, or an empty string for no names
853
+ */
149
854
  private static listNames;
855
+ /**
856
+ * The human the room falls back to when it has to pick one, which is whoever
857
+ * arrived first. Used to open the conversation and to attribute a message that
858
+ * arrives with no sender. Which one it is carries no meaning.
859
+ */
150
860
  getDefaultHumanAgent(): Agent | undefined;
861
+ /**
862
+ * The human-controlled agent a sender name refers to, matched the same way
863
+ * message targets are, or undefined when no human answers to that name.
864
+ */
151
865
  getHumanAgentByName(sender: string): Agent | undefined;
866
+ /** True when `nickname` names a human-controlled agent in this room. */
152
867
  isHumanNickname(nickname: string | null): boolean;
868
+ /**
869
+ * True when a message is the players talking among themselves: a whisper whose
870
+ * every target is a human-controlled agent.
871
+ *
872
+ * Such a message cannot reach the game. `canHear` restricts a whisper to its
873
+ * targets, so no AI agent hears it; every target is human, so no agent is
874
+ * prompted and nothing is spent. That is what lets the room take one **out of
875
+ * turn** and leave the floor untouched — the players get to chat across the
876
+ * table while an agent is mid-turn, and it still shows up in the transcript for
877
+ * everyone at the table to read.
878
+ */
153
879
  isPlayerAside(message: RoomMessage): boolean;
880
+ /**
881
+ * Gets the name of the default human-controlled agent
882
+ * @returns The human agent's name or empty string if not found
883
+ */
154
884
  getHumanAgentName(): string;
885
+ /**
886
+ * Gets the agent that places messages the room cannot route mechanically.
887
+ *
888
+ * Prefers the configured {@link setModerator} nickname. The fallback to the
889
+ * first agent is how story rooms have always chosen theirs — the narrator is
890
+ * added first — and is kept so they keep working, but it is a guess: in any
891
+ * other room the first agent is whoever happened to be added first and has no
892
+ * `moderate.prompt` at all. Name one explicitly.
893
+ *
894
+ * The fallback prefers an agent that actually has a `moderate.prompt`, because
895
+ * one that does not fails in the worst way available: the prompt lookup throws,
896
+ * the throw is swallowed, and the message disappears. Arrival order is only
897
+ * consulted when nobody in the room can moderate, which keeps a room that was
898
+ * working before this preference existed working now.
899
+ * @returns The moderator agent or undefined if the room is empty
900
+ */
155
901
  getModeratorAgent(): Agent | undefined;
902
+ /**
903
+ * Gets the current story situation
904
+ * @returns The current situation string
905
+ */
156
906
  getSituation(): string;
907
+ /**
908
+ * Gets the current in-story time (24-hour "HH:MM"), stored separately from the
909
+ * situation text.
910
+ * @returns The current time string, or '' if none is set
911
+ */
157
912
  getSituationTime(): string;
913
+ /**
914
+ * Sets the current in-story time (24-hour "HH:MM").
915
+ * @param time The time string to set
916
+ */
158
917
  setSituationTime(time: string): void;
918
+ /**
919
+ * Builds the situation header shared by every agent's transient prompt: the
920
+ * in-story time on its own labeled line (flagged as a 24-hour clock so a character
921
+ * doesn't misread "10:30" as 10:30 PM), followed by the situation text. Either
922
+ * line is omitted when its value is empty.
923
+ *
924
+ * @returns The time and situation lines, or '' if both are empty
925
+ */
159
926
  private buildSituationHeader;
927
+ /**
928
+ * Sets the current story situation
929
+ * @param situation The situation string to set
930
+ */
160
931
  setSituation(situation: string): void;
932
+ /**
933
+ * Sets a callback to be invoked whenever situation changes
934
+ * @param callback Function to call with new situation
935
+ */
161
936
  setOnSituationUpdate(callback: (situation: string, messageBody?: string) => void | Promise<void>): void;
162
937
  setOnModeratorResponse(callback: (message: RoomMessage) => void): void;
938
+ /**
939
+ * Handles situation update from an agent message
940
+ * Updates internal state and notifies callback
941
+ * @param situation The new situation string
942
+ * @param messageBody Body of the message that produced this situation, for
943
+ * consumers that need the triggering message but can't read it from the
944
+ * room yet (it may not be logged at the time the callback fires).
945
+ */
163
946
  private handleSituationUpdate;
164
947
  handlePublishMessages(messages: RoomMessage[]): void;
165
948
  handleAdjournMessages(messages: RoomMessage[]): void;
166
949
  addPendingMessage(message: RoomMessage, clearQueue?: boolean, context?: unknown): SendMessageResult;
167
950
  isProcessingInProgress(): boolean;
951
+ /**
952
+ * True when the room is idle pending input from the human-controlled agent.
953
+ *
954
+ * This is distinct from `isProcessingInProgress()`: after an agent addresses
955
+ * the human, the room intentionally leaves processing "in progress" while it
956
+ * waits for the human's reply (the human's perceive never fires a response
957
+ * callback). Hosts should use this flag — not `processingInProgress` — to
958
+ * decide whether to show a typing indicator.
959
+ */
168
960
  isWaitingForHuman(): boolean;
169
961
  pause(): void;
170
962
  resume(): void;
171
963
  interrupt(): void;
172
964
  checkAgentNicknameMatch(existingNickname: string, targetNickname: string): boolean;
965
+ /**
966
+ * Hands a moderated message to one recipient in the shape that recipient needs.
967
+ *
968
+ * An AI agent gets the message itself, so a room whose agents answer in the JSON
969
+ * protocol sees moderated messages in the same shape as every other one — half a
970
+ * history in plain prose models the wrong output format, and a prose reply is
971
+ * silently absorbed by parseAgentResponse rather than corrected, so the drift has
972
+ * no back pressure.
973
+ *
974
+ * A human gets the readable form. Nothing prompts a human agent, so its history
975
+ * is a record rather than a set of examples, and JSON is the wrong thing to keep.
976
+ *
977
+ * With no `relayAs` the two branches produce identical text, which is why story
978
+ * rooms are unaffected by this distinction.
979
+ */
173
980
  private deliverModerated;
981
+ /**
982
+ * Handles the moderator's routing response for a single message
983
+ * @param moderatorMessage The routing response from the moderator
984
+ * @param originalMessage The original message that needed routing
985
+ */
174
986
  private handleModeratorResponse;
987
+ /**
988
+ * Runs one commissioned agent's research turn and normalizes the result into
989
+ * a DELIVER message. If the agent's terminal action isn't DELIVER it gets one
990
+ * corrective re-prompt; a still-wrong action is coerced into a DELIVER so the
991
+ * commissioner is never starved. Errors become a synthetic error DELIVER.
992
+ * @param agent The commissioned agent
993
+ * @param commission The COMMISSION message (already in the agent's history)
994
+ * @returns The DELIVER message, or null if the room was paused/adjourned
995
+ */
175
996
  private runDeliverTurn;
997
+ /**
998
+ * Orchestrates a COMMISSION message. Called from processPendingMessages with
999
+ * the processing lock held; the lock stays held until the commissioner has
1000
+ * responded to the aggregated deliverables (or the room pauses/adjourns).
1001
+ *
1002
+ * Flow: every agent hears the commission (it is public, like SPEAK) → each AI
1003
+ * target concurrently runs its own research turn ending in a DELIVER → the
1004
+ * DELIVERs are logged and heard by the room → the commissioner receives the
1005
+ * concatenated deliverables and responds, re-entering normal processing.
1006
+ *
1007
+ * Human-controlled targets are skipped (waiting on a human while the lock is
1008
+ * held would deadlock the room) and noted in the aggregate. Nothing about an
1009
+ * in-flight commission is persisted: a server restart kills it, leaving only
1010
+ * the already-logged messages.
1011
+ * @param msg The COMMISSION message (already added to the room log)
1012
+ */
176
1013
  private handleCommissionMessage;
1014
+ /**
1015
+ * Delivers a system note (commission results or failure) to the commissioner,
1016
+ * lets it respond, queues that response, and releases the processing lock.
1017
+ * A human or missing commissioner just gets the note; the room then waits
1018
+ * for their next message as usual.
1019
+ * @param commissioner The commissioning agent, if found
1020
+ * @param note The system note to add to the commissioner's history
1021
+ */
177
1022
  private respondToCommissioner;
178
1023
  private processPendingMessages;
1024
+ /**
1025
+ * Protects a specialist's history when the room leader hands it a task.
1026
+ *
1027
+ * A specialist runs on a short rolling window so it does not carry the last job
1028
+ * into the next one. That window is wrong *within* a job: a whole encounter or a
1029
+ * whole character interview can run longer than the window is wide. Pinning at
1030
+ * the handoff keeps everything from that message on, while the window still
1031
+ * drops what came before — so the second job forgets the first, and neither
1032
+ * forgets itself.
1033
+ *
1034
+ * Three conditions, all needed:
1035
+ *
1036
+ * - **the sender is the room leader**, because a handoff is the leader delegating;
1037
+ * - **the message names this agent**, so a general announcement is not a new task
1038
+ * and cannot re-pin one already running;
1039
+ * - **the agent has a window**, which makes this a no-op for everyone else. The
1040
+ * Dungeon Master keeps its whole campaign whether or not this runs.
1041
+ *
1042
+ * Called *before* {@link perceive}, so the handoff instruction itself is inside
1043
+ * the pin rather than the first casualty of the next trim.
1044
+ *
1045
+ * There is no unpin. Re-pinning ends the previous pin, so an abandoned task is
1046
+ * reclaimed by the next one and the worst a stale pin does is keep more history
1047
+ * than intended.
1048
+ * @param agent The agent about to be prompted
1049
+ * @param message The message being dispatched to it
1050
+ */
179
1051
  private pinHistoryOnHandoff;
1052
+ /**
1053
+ * Decides which agents are asked to respond to a message.
1054
+ *
1055
+ * In 'broadcast' mode every agent responds and {@link filterConcurrentMessages}
1056
+ * later keeps one reply, discarding the rest. In 'directed' mode exactly one
1057
+ * agent responds — the first target that resolves to an agent, or the room
1058
+ * leader when no target does — so a leader agent controls the order of play
1059
+ * and no work is paid for and thrown away. Agents that are not selected still
1060
+ * receive the message through {@link hear}.
1061
+ *
1062
+ * The sender is never selected: a self-loop would have the agent answer
1063
+ * itself and stall the room. If neither a target nor the leader resolves to
1064
+ * someone other than the sender, this widens to everyone else who can hear
1065
+ * the message, so a misaddressed message still gets a reply from somebody.
1066
+ * @param message The message being processed
1067
+ * @returns The agents to prompt, in the order they should be dispatched
1068
+ */
1069
+ /**
1070
+ * Whether an agent that has addressed itself may keep the floor.
1071
+ *
1072
+ * Counts consecutive turns rather than total ones: a run ends the moment anyone
1073
+ * else takes the floor, so an agent that legitimately keeps it twice during one
1074
+ * fight and twice more during the next is never penalised for the first pair.
1075
+ * @param sender The agent asking to answer itself
1076
+ * @returns True when it keeps the floor, false when the run has gone on too long
1077
+ */
180
1078
  private mayContinueAlone;
1079
+ /** Ends a self-continue run, because the floor has gone to somebody else. */
181
1080
  private clearSelfContinue;
182
1081
  private selectResponders;
1082
+ /**
1083
+ * Filters concurrent messages to ensure only one message is processed
1084
+ * Priority: SHOUT > SPEAK > WHISPER, then by agent order in room
1085
+ * @param messages Array of messages to filter
1086
+ * @returns Single message (or original if <= 1)
1087
+ */
183
1088
  private filterConcurrentMessages;
184
1089
  }