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
@@ -1,21 +1,75 @@
1
1
  "use strict";
2
+ /**
3
+ * Built-in tool packs: sets of native tools that ship with Briyah.
4
+ *
5
+ * Registration is process-global, matching how native tools work generally. What
6
+ * used to gate it — `BRIYAH_TOOL_PACKS` — no longer does: a pack's tools are
7
+ * registered at boot and *enablement is per user*, held in their config and
8
+ * applied where tools are listed rather than where they are registered. See
9
+ * `packs/pack.service.ts`.
10
+ *
11
+ * Registering everything is safe because registration alone grants nothing. A
12
+ * tool reaches an agent only through `agent.toolNames`, and
13
+ * `AppService.listNativeToolSummaries` will not offer a tool whose pack the user
14
+ * has not switched on.
15
+ */
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.actsTools = exports.dnd5eTools = void 0;
17
+ exports.dnd5eTools = void 0;
4
18
  exports.installToolPacks = installToolPacks;
5
19
  exports.registerToolPacks = registerToolPacks;
20
+ exports.registerPack = registerPack;
6
21
  exports.availableToolPacks = availableToolPacks;
7
22
  const dnd5e_1 = require("./dnd5e");
8
23
  Object.defineProperty(exports, "dnd5eTools", { enumerable: true, get: function () { return dnd5e_1.dnd5eTools; } });
9
- const acts_1 = require("./acts");
10
- Object.defineProperty(exports, "actsTools", { enumerable: true, get: function () { return acts_1.actsTools; } });
24
+ const core_1 = require("../core");
11
25
  const logger_1 = require("../../common/logger");
26
+ /**
27
+ * The packs that ship with the npm package, by name.
28
+ *
29
+ * Only the bundled ones. A pack this repository runs but does not publish is
30
+ * registered by `main.ts` through {@link registerPack} — `acts` implements a
31
+ * curriculum whose rules, cards and chapter scripts belong to their author, so it
32
+ * is kept out of the package by leaving it out of here.
33
+ *
34
+ * That boundary has to be a static import rather than a directory scan: the server
35
+ * is bundled by webpack into a single `main.js`, so at runtime there is no pack
36
+ * directory to look in, and a computed `require` makes webpack try to bundle every
37
+ * file beside this one. The pack *content* is discovered from `data/packs/`,
38
+ * because content is read at runtime and never bundled.
39
+ */
12
40
  const PACKS = {
13
41
  dnd5e: dnd5e_1.dnd5eTools,
14
- acts: acts_1.actsTools,
15
42
  };
43
+ /**
44
+ * Registers the core tools and every built-in pack's tools.
45
+ *
46
+ * Core first, so a pack that shipped a colliding name would overwrite it loudly
47
+ * through `registerTool`'s warning rather than the other way round. `packs.spec.ts`
48
+ * is what actually stops that happening.
49
+ *
50
+ * @param registry The process-wide native tool registry
51
+ * @returns The names of the tools that were registered
52
+ */
16
53
  function installToolPacks(registry) {
17
- return registerToolPacks(registry, Object.keys(PACKS).join(','));
54
+ const core = (0, core_1.coreTools)().map((tool) => ({ ...tool, group: core_1.CORE_TOOL_GROUP }));
55
+ registry.registerTools(core);
56
+ logger_1.logger.log(`Registered ${core.length} core tools`);
57
+ return [
58
+ ...core.map((tool) => tool.name),
59
+ ...registerToolPacks(registry, Object.keys(PACKS).join(',')),
60
+ ];
18
61
  }
62
+ /**
63
+ * Registers the named tool packs into the native registry.
64
+ *
65
+ * Kept alongside {@link installToolPacks} for an SDK host that wants only some of
66
+ * the built-in packs' tools in its process.
67
+ *
68
+ * @param registry The process-wide native tool registry
69
+ * @param packList A comma-separated list of pack names. Empty or undefined
70
+ * registers nothing.
71
+ * @returns The names of the tools that were registered
72
+ */
19
73
  function registerToolPacks(registry, packList) {
20
74
  const names = (packList || '')
21
75
  .split(',')
@@ -30,13 +84,33 @@ function registerToolPacks(registry, packList) {
30
84
  logger_1.logger.warn(`Unknown tool pack "${name}"; available packs: ${Object.keys(PACKS).join(', ')}`);
31
85
  continue;
32
86
  }
33
- const tools = pack().map((tool) => ({ ...tool, group: name }));
34
- registry.registerTools(tools);
35
- registered.push(...tools.map((tool) => tool.name));
36
- logger_1.logger.log(`Registered tool pack "${name}" with ${tools.length} tools`);
87
+ registered.push(...registerPack(registry, name, pack()));
37
88
  }
38
89
  return registered;
39
90
  }
91
+ /**
92
+ * Registers one pack's tools under a name.
93
+ *
94
+ * For a pack that is not in {@link PACKS}: one this repository runs but does not
95
+ * publish, or one an SDK host wrote itself. `main.ts` registers `acts` this way,
96
+ * and `main.ts` is excluded from the SDK build, so the published package has no
97
+ * path to it at all.
98
+ *
99
+ * @param registry The process-wide native tool registry
100
+ * @param name The pack name, stamped on every tool as its group
101
+ * @param tools The pack's tool definitions
102
+ * @returns The names of the tools that were registered
103
+ */
104
+ function registerPack(registry, name, tools) {
105
+ // Stamp the pack name on every tool so the UI can collapse the pack into
106
+ // one node, and so listing can filter by what the user has enabled. A
107
+ // pack's definitions do not name their own pack.
108
+ const grouped = tools.map((tool) => ({ ...tool, group: name }));
109
+ registry.registerTools(grouped);
110
+ logger_1.logger.log(`Registered tool pack "${name}" with ${grouped.length} tools`);
111
+ return grouped.map((tool) => tool.name);
112
+ }
113
+ /** The names of the packs that ship with the package. */
40
114
  function availableToolPacks() {
41
115
  return Object.keys(PACKS);
42
116
  }
@@ -1,13 +1,108 @@
1
+ /**
2
+ * Argument coercion for tool handlers.
3
+ *
4
+ * Tool arguments arrive from `JSON.parse` of text an LLM wrote, and the only
5
+ * validation Briyah performs is that required parameters are present — there is
6
+ * no type checking and no rejection of extra keys. So a parameter declared
7
+ * `number` routinely arrives as `"3"`, `"+3"` or `" 3 "`, and a parameter
8
+ * declared `string` that is documented as holding JSON arrives about as often as
9
+ * a real object as it does as a string. Every handler runs its arguments through
10
+ * this module before touching them.
11
+ */
12
+ /** Raised when an argument cannot be coerced. Carries a repair hint for the model. */
1
13
  export declare class ArgumentError extends Error {
2
14
  constructor(param: string, received: unknown, expected: string, example?: string);
3
15
  }
16
+ /**
17
+ * Coerces a value to a number, tolerating the string forms an LLM emits.
18
+ * @param value The raw argument value
19
+ * @param param The parameter name, for the error message
20
+ * @param fallback Returned when the value is absent
21
+ * @returns The number
22
+ * @throws {ArgumentError} If the value is present but not numeric
23
+ */
4
24
  export declare function num(value: unknown, param: string, fallback?: number): number;
25
+ /**
26
+ * Coerces a value to an integer, rounding toward zero.
27
+ * @param value The raw argument value
28
+ * @param param The parameter name, for the error message
29
+ * @param fallback Returned when the value is absent
30
+ * @returns The integer
31
+ */
5
32
  export declare function int(value: unknown, param: string, fallback?: number): number;
33
+ /**
34
+ * Coerces a value to a boolean, accepting true/false, "true"/"false",
35
+ * "yes"/"no" and 1/0.
36
+ * @param value The raw argument value
37
+ * @param fallback Returned when the value is absent or unrecognized
38
+ * @returns The boolean
39
+ */
6
40
  export declare function bool(value: unknown, fallback?: boolean): boolean;
41
+ /**
42
+ * Coerces a value to a trimmed string.
43
+ * @param value The raw argument value
44
+ * @param param The parameter name, for the error message
45
+ * @param fallback Returned when the value is absent
46
+ * @returns The trimmed string
47
+ * @throws {ArgumentError} If the value is required and absent
48
+ */
7
49
  export declare function str(value: unknown, param: string, fallback?: string): string;
50
+ /**
51
+ * Splits a delimited list parameter into entries. Semicolons are the documented
52
+ * separator, but commas, newlines and a genuine JSON array are all accepted
53
+ * because models mix them freely.
54
+ * @param value The raw argument value
55
+ * @returns The non-empty trimmed entries, or [] when absent
56
+ */
8
57
  export declare function list(value: unknown): string[];
58
+ /**
59
+ * Reads a parameter documented as holding a JSON object. Accepts either a real
60
+ * object or a JSON string, and tolerates a fenced ```json block around it.
61
+ * @param value The raw argument value
62
+ * @param param The parameter name, for the error message
63
+ * @param example A correct example, quoted back to the model on failure
64
+ * @returns The object, or {} when absent
65
+ * @throws {ArgumentError} If the value is present but is not an object
66
+ */
9
67
  export declare function jsonObject(value: unknown, param: string, example?: string): Record<string, any>;
68
+ /**
69
+ * Reads a parameter documented as holding a JSON array of objects.
70
+ * @param value The raw argument value
71
+ * @param param The parameter name, for the error message
72
+ * @param example A correct example, quoted back to the model on failure
73
+ * @returns The array, or [] when absent
74
+ * @throws {ArgumentError} If the value is present but is not an array
75
+ */
10
76
  export declare function jsonArray(value: unknown, param: string, example?: string): any[];
77
+ /**
78
+ * Normalizes a name for comparison: lowercase, punctuation and extra
79
+ * whitespace removed. Lets "Thalia Emberwood" match "thalia emberwood" and
80
+ * "Healer's Kit" match "healers kit".
81
+ * @param name The name to normalize
82
+ * @returns The comparison key
83
+ */
11
84
  export declare function nameKey(name: string): string;
85
+ /**
86
+ * Finds an entry in a list of known names, matching loosely.
87
+ *
88
+ * Returns the first candidate when several match, which is safe for a short list
89
+ * whose entries are known to be distinct — a party of characters. For a long list
90
+ * where partial names genuinely collide, use {@link matchNames} and report the
91
+ * ambiguity instead of picking silently.
92
+ * @param wanted The name the model supplied
93
+ * @param known The names that exist
94
+ * @returns The matching known name, or undefined
95
+ */
12
96
  export declare function matchName(wanted: string, known: string[]): string | undefined;
97
+ /**
98
+ * Finds every entry that could be what the caller meant, from the most precise
99
+ * tier that produced anything: an exact match, else a shared first word, else a
100
+ * shared prefix in either direction.
101
+ *
102
+ * Tiers do not merge. An exact match never comes back alongside loose ones, so a
103
+ * query for "bandit" resolves cleanly even when "bandit captain" also exists.
104
+ * @param wanted The name the model supplied
105
+ * @param known The names that exist
106
+ * @returns Every candidate in the best matching tier; empty when nothing matches
107
+ */
13
108
  export declare function matchNames(wanted: string, known: string[]): string[];
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ /**
3
+ * Argument coercion for tool handlers.
4
+ *
5
+ * Tool arguments arrive from `JSON.parse` of text an LLM wrote, and the only
6
+ * validation Briyah performs is that required parameters are present — there is
7
+ * no type checking and no rejection of extra keys. So a parameter declared
8
+ * `number` routinely arrives as `"3"`, `"+3"` or `" 3 "`, and a parameter
9
+ * declared `string` that is documented as holding JSON arrives about as often as
10
+ * a real object as it does as a string. Every handler runs its arguments through
11
+ * this module before touching them.
12
+ */
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.ArgumentError = void 0;
4
15
  exports.num = num;
@@ -11,6 +22,7 @@ exports.jsonArray = jsonArray;
11
22
  exports.nameKey = nameKey;
12
23
  exports.matchName = matchName;
13
24
  exports.matchNames = matchNames;
25
+ /** Raised when an argument cannot be coerced. Carries a repair hint for the model. */
14
26
  class ArgumentError extends Error {
15
27
  constructor(param, received, expected, example) {
16
28
  const got = received === undefined ? 'nothing' : JSON.stringify(received);
@@ -20,6 +32,14 @@ class ArgumentError extends Error {
20
32
  }
21
33
  }
22
34
  exports.ArgumentError = ArgumentError;
35
+ /**
36
+ * Coerces a value to a number, tolerating the string forms an LLM emits.
37
+ * @param value The raw argument value
38
+ * @param param The parameter name, for the error message
39
+ * @param fallback Returned when the value is absent
40
+ * @returns The number
41
+ * @throws {ArgumentError} If the value is present but not numeric
42
+ */
23
43
  function num(value, param, fallback) {
24
44
  if (value === undefined || value === null || value === '') {
25
45
  if (fallback !== undefined)
@@ -35,9 +55,23 @@ function num(value, param, fallback) {
35
55
  }
36
56
  throw new ArgumentError(param, value, 'a number', '3');
37
57
  }
58
+ /**
59
+ * Coerces a value to an integer, rounding toward zero.
60
+ * @param value The raw argument value
61
+ * @param param The parameter name, for the error message
62
+ * @param fallback Returned when the value is absent
63
+ * @returns The integer
64
+ */
38
65
  function int(value, param, fallback) {
39
66
  return Math.trunc(num(value, param, fallback));
40
67
  }
68
+ /**
69
+ * Coerces a value to a boolean, accepting true/false, "true"/"false",
70
+ * "yes"/"no" and 1/0.
71
+ * @param value The raw argument value
72
+ * @param fallback Returned when the value is absent or unrecognized
73
+ * @returns The boolean
74
+ */
41
75
  function bool(value, fallback = false) {
42
76
  if (value === undefined || value === null || value === '')
43
77
  return fallback;
@@ -54,6 +88,14 @@ function bool(value, fallback = false) {
54
88
  }
55
89
  return fallback;
56
90
  }
91
+ /**
92
+ * Coerces a value to a trimmed string.
93
+ * @param value The raw argument value
94
+ * @param param The parameter name, for the error message
95
+ * @param fallback Returned when the value is absent
96
+ * @returns The trimmed string
97
+ * @throws {ArgumentError} If the value is required and absent
98
+ */
57
99
  function str(value, param, fallback) {
58
100
  if (value === undefined || value === null) {
59
101
  if (fallback !== undefined)
@@ -66,6 +108,13 @@ function str(value, param, fallback) {
66
108
  return String(value);
67
109
  throw new ArgumentError(param, value, 'a string');
68
110
  }
111
+ /**
112
+ * Splits a delimited list parameter into entries. Semicolons are the documented
113
+ * separator, but commas, newlines and a genuine JSON array are all accepted
114
+ * because models mix them freely.
115
+ * @param value The raw argument value
116
+ * @returns The non-empty trimmed entries, or [] when absent
117
+ */
69
118
  function list(value) {
70
119
  if (value === undefined || value === null || value === '')
71
120
  return [];
@@ -77,6 +126,15 @@ function list(value) {
77
126
  .map((v) => v.trim())
78
127
  .filter((v) => v.length > 0);
79
128
  }
129
+ /**
130
+ * Reads a parameter documented as holding a JSON object. Accepts either a real
131
+ * object or a JSON string, and tolerates a fenced ```json block around it.
132
+ * @param value The raw argument value
133
+ * @param param The parameter name, for the error message
134
+ * @param example A correct example, quoted back to the model on failure
135
+ * @returns The object, or {} when absent
136
+ * @throws {ArgumentError} If the value is present but is not an object
137
+ */
80
138
  function jsonObject(value, param, example) {
81
139
  if (value === undefined || value === null || value === '')
82
140
  return {};
@@ -97,6 +155,14 @@ function jsonObject(value, param, example) {
97
155
  }
98
156
  throw new ArgumentError(param, value, 'a JSON object', example);
99
157
  }
158
+ /**
159
+ * Reads a parameter documented as holding a JSON array of objects.
160
+ * @param value The raw argument value
161
+ * @param param The parameter name, for the error message
162
+ * @param example A correct example, quoted back to the model on failure
163
+ * @returns The array, or [] when absent
164
+ * @throws {ArgumentError} If the value is present but is not an array
165
+ */
100
166
  function jsonArray(value, param, example) {
101
167
  if (value === undefined || value === null || value === '')
102
168
  return [];
@@ -108,6 +174,7 @@ function jsonArray(value, param, example) {
108
174
  const parsed = JSON.parse(cleaned);
109
175
  if (Array.isArray(parsed))
110
176
  return parsed;
177
+ // A single object where a list was asked for is a common near-miss.
111
178
  if (parsed && typeof parsed === 'object')
112
179
  return [parsed];
113
180
  }
@@ -117,11 +184,19 @@ function jsonArray(value, param, example) {
117
184
  }
118
185
  throw new ArgumentError(param, value, 'a JSON array', example);
119
186
  }
187
+ /** Removes a surrounding markdown code fence, which models add unprompted. */
120
188
  function stripCodeFence(text) {
121
189
  const trimmed = text.trim();
122
190
  const fenced = /^```(?:json)?\s*\n?([\s\S]*?)\n?```$/.exec(trimmed);
123
191
  return fenced ? fenced[1].trim() : trimmed;
124
192
  }
193
+ /**
194
+ * Normalizes a name for comparison: lowercase, punctuation and extra
195
+ * whitespace removed. Lets "Thalia Emberwood" match "thalia emberwood" and
196
+ * "Healer's Kit" match "healers kit".
197
+ * @param name The name to normalize
198
+ * @returns The comparison key
199
+ */
125
200
  function nameKey(name) {
126
201
  return name
127
202
  .toLowerCase()
@@ -129,10 +204,32 @@ function nameKey(name) {
129
204
  .replace(/\s+/g, ' ')
130
205
  .trim();
131
206
  }
207
+ /**
208
+ * Finds an entry in a list of known names, matching loosely.
209
+ *
210
+ * Returns the first candidate when several match, which is safe for a short list
211
+ * whose entries are known to be distinct — a party of characters. For a long list
212
+ * where partial names genuinely collide, use {@link matchNames} and report the
213
+ * ambiguity instead of picking silently.
214
+ * @param wanted The name the model supplied
215
+ * @param known The names that exist
216
+ * @returns The matching known name, or undefined
217
+ */
132
218
  function matchName(wanted, known) {
133
219
  const candidates = matchNames(wanted, known);
134
220
  return candidates.length > 0 ? candidates[0] : undefined;
135
221
  }
222
+ /**
223
+ * Finds every entry that could be what the caller meant, from the most precise
224
+ * tier that produced anything: an exact match, else a shared first word, else a
225
+ * shared prefix in either direction.
226
+ *
227
+ * Tiers do not merge. An exact match never comes back alongside loose ones, so a
228
+ * query for "bandit" resolves cleanly even when "bandit captain" also exists.
229
+ * @param wanted The name the model supplied
230
+ * @param known The names that exist
231
+ * @returns Every candidate in the best matching tier; empty when nothing matches
232
+ */
136
233
  function matchNames(wanted, known) {
137
234
  const key = nameKey(wanted);
138
235
  if (!key)
@@ -140,6 +237,7 @@ function matchNames(wanted, known) {
140
237
  const exact = known.filter((k) => nameKey(k) === key);
141
238
  if (exact.length > 0)
142
239
  return exact;
240
+ // First word, so "Thalia" finds "Thalia Emberwood"
143
241
  const firstWord = known.filter((k) => nameKey(k).split(' ')[0] === key.split(' ')[0]);
144
242
  if (firstWord.length > 0)
145
243
  return firstWord;
@@ -3,22 +3,95 @@ import { ToolStoreService } from './tool-store.service';
3
3
  import { NativeToolRegistry } from './native-tool-registry.service';
4
4
  import { NativeToolDefinition, ToolHelpers, ToolContext, ToolPackDocuments, ToolRoomAccess } from './native-tool.types';
5
5
  type CompiledTool = (args: Record<string, any>, helpers: ToolHelpers, context: ToolContext) => Promise<any>;
6
+ /**
7
+ * Executes tools an agent calls with the EXECUTE action. Tools come from two
8
+ * sources, resolved native-first:
9
+ * - Native tools (host-implemented functions in {@link NativeToolRegistry}) —
10
+ * trusted, always available.
11
+ * - User-authored tools (JS-string code in {@link ToolStoreService}) — gated by
12
+ * `allowUserAuthoredTools`; the code is the body of an async function
13
+ * receiving (args, helpers, context).
14
+ *
15
+ * `context` is the host's opaque per-invocation value (see AppService.sendRoomMessage);
16
+ * it is threaded through unchanged and never inspected here.
17
+ */
6
18
  export declare class ToolExecutionService {
7
19
  private readonly toolStore;
8
20
  private readonly nativeRegistry;
9
21
  private readonly allowUserAuthoredTools;
10
22
  private readonly packDocuments?;
11
23
  private compiledCache;
24
+ /**
25
+ * @param toolStore The user's store of user-authored tools
26
+ * @param nativeRegistry The process-wide registry of host-implemented tools
27
+ * @param allowUserAuthoredTools Whether stored JS-string tools may run at all
28
+ * @param packDocuments Read access to installed packs' shipped documents,
29
+ * exposed to every tool as `helpers.packDocuments`. Optional so a unit test
30
+ * can build the service with nothing behind it; a tool that needs it fails
31
+ * with its own message.
32
+ */
12
33
  constructor(toolStore: ToolStoreService, nativeRegistry: NativeToolRegistry, allowUserAuthoredTools?: boolean, packDocuments?: ToolPackDocuments);
34
+ /**
35
+ * Compiles a user-authored tool's code into an async function.
36
+ * Throws SyntaxError on bad code.
37
+ * @param tool The tool definition to compile
38
+ * @returns The compiled async function
39
+ */
13
40
  static compile(tool: ToolDefinition): CompiledTool;
41
+ /**
42
+ * The room-facing entry point: validates the grant, the tool, and the
43
+ * arguments before running. All failures are returned in-band as
44
+ * { ok: false, error } so the calling agent can recover.
45
+ * @param name The tool name from the agent's EXECUTE message
46
+ * @param contentJson The message content: a JSON object of named arguments
47
+ * @param grantedNames The tool names granted to the calling agent
48
+ * @param context The host's opaque per-invocation context
49
+ * @param room Access to the calling agent's room, exposed as helpers.room
50
+ * @returns The tool run result
51
+ */
14
52
  runForAgent(name: string, contentJson: string, grantedNames: string[], context?: ToolContext, room?: ToolRoomAccess): Promise<ToolRunResult>;
53
+ /**
54
+ * Runs a tool for the API test endpoint. Same validation as the agent path,
55
+ * minus the grant check, so the Test panel shows the errors agents would get.
56
+ * There is no room here, so helpers.room is absent and tools that require it
57
+ * fail with their own explanatory message.
58
+ * @param name The tool name
59
+ * @param args Named arguments for the tool
60
+ * @param context Optional opaque context (usually absent for UI tests)
61
+ * @returns The tool run result
62
+ */
15
63
  test(name: string, args: Record<string, any>, context?: ToolContext): Promise<ToolRunResult>;
64
+ /**
65
+ * Resolves a tool (native first, then user-authored), checks required
66
+ * parameters, and runs it.
67
+ * @param name The tool name
68
+ * @param args Named arguments for the tool
69
+ * @param context The host's opaque per-invocation context
70
+ * @param room Access to the calling agent's room, if any
71
+ * @returns The tool run result
72
+ */
16
73
  private runValidated;
17
74
  private static missingRequiredParam;
75
+ /**
76
+ * Runs an invocation with a timeout and an abort-wired fetch helper. Fetches
77
+ * made through helpers.fetch are aborted when the timeout fires.
78
+ * @param name The tool name (for logging)
79
+ * @param toolTimeoutMs The tool's configured timeout, if any
80
+ * @param invoke Runs the tool with the provided helpers
81
+ * @param room Access to the calling agent's room, omitted when there is none
82
+ * @returns The tool run result
83
+ */
18
84
  private execute;
19
85
  private getCompiled;
86
+ /**
87
+ * Caps oversized results so a tool can't blow up the agent's prompt.
88
+ * @param result The raw tool result
89
+ * @returns The result, or a truncated string form when it serializes too large
90
+ */
20
91
  private static truncateResult;
92
+ /** @returns The native tool definitions registered in this process. */
21
93
  listNativeTools(): NativeToolDefinition[];
94
+ /** @returns Whether user-authored (string) tools may run in this deployment. */
22
95
  get userAuthoredToolsEnabled(): boolean;
23
96
  }
24
97
  export {};
@@ -6,21 +6,59 @@ const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
6
6
  const DEFAULT_TIMEOUT_MS = 30_000;
7
7
  const MAX_TIMEOUT_MS = 120_000;
8
8
  const MAX_RESULT_CHARS = 16_384;
9
+ /**
10
+ * Executes tools an agent calls with the EXECUTE action. Tools come from two
11
+ * sources, resolved native-first:
12
+ * - Native tools (host-implemented functions in {@link NativeToolRegistry}) —
13
+ * trusted, always available.
14
+ * - User-authored tools (JS-string code in {@link ToolStoreService}) — gated by
15
+ * `allowUserAuthoredTools`; the code is the body of an async function
16
+ * receiving (args, helpers, context).
17
+ *
18
+ * `context` is the host's opaque per-invocation value (see AppService.sendRoomMessage);
19
+ * it is threaded through unchanged and never inspected here.
20
+ */
9
21
  class ToolExecutionService {
10
22
  toolStore;
11
23
  nativeRegistry;
12
24
  allowUserAuthoredTools;
13
25
  packDocuments;
14
26
  compiledCache = new Map();
27
+ /**
28
+ * @param toolStore The user's store of user-authored tools
29
+ * @param nativeRegistry The process-wide registry of host-implemented tools
30
+ * @param allowUserAuthoredTools Whether stored JS-string tools may run at all
31
+ * @param packDocuments Read access to installed packs' shipped documents,
32
+ * exposed to every tool as `helpers.packDocuments`. Optional so a unit test
33
+ * can build the service with nothing behind it; a tool that needs it fails
34
+ * with its own message.
35
+ */
15
36
  constructor(toolStore, nativeRegistry, allowUserAuthoredTools = false, packDocuments) {
16
37
  this.toolStore = toolStore;
17
38
  this.nativeRegistry = nativeRegistry;
18
39
  this.allowUserAuthoredTools = allowUserAuthoredTools;
19
40
  this.packDocuments = packDocuments;
20
41
  }
42
+ /**
43
+ * Compiles a user-authored tool's code into an async function.
44
+ * Throws SyntaxError on bad code.
45
+ * @param tool The tool definition to compile
46
+ * @returns The compiled async function
47
+ */
21
48
  static compile(tool) {
22
49
  return new AsyncFunction('args', 'helpers', 'context', tool.code);
23
50
  }
51
+ /**
52
+ * The room-facing entry point: validates the grant, the tool, and the
53
+ * arguments before running. All failures are returned in-band as
54
+ * { ok: false, error } so the calling agent can recover.
55
+ * @param name The tool name from the agent's EXECUTE message
56
+ * @param contentJson The message content: a JSON object of named arguments
57
+ * @param grantedNames The tool names granted to the calling agent
58
+ * @param context The host's opaque per-invocation context
59
+ * @param room Access to the calling agent's room, exposed as helpers.room
60
+ * @returns The tool run result
61
+ */
24
62
  async runForAgent(name, contentJson, grantedNames, context, room) {
25
63
  if (!grantedNames.includes(name)) {
26
64
  return { ok: false, error: `Tool "${name}" is not available to you` };
@@ -39,10 +77,30 @@ class ToolExecutionService {
39
77
  }
40
78
  return this.runValidated(name, args, context, room);
41
79
  }
80
+ /**
81
+ * Runs a tool for the API test endpoint. Same validation as the agent path,
82
+ * minus the grant check, so the Test panel shows the errors agents would get.
83
+ * There is no room here, so helpers.room is absent and tools that require it
84
+ * fail with their own explanatory message.
85
+ * @param name The tool name
86
+ * @param args Named arguments for the tool
87
+ * @param context Optional opaque context (usually absent for UI tests)
88
+ * @returns The tool run result
89
+ */
42
90
  async test(name, args, context) {
43
91
  return this.runValidated(name, args || {}, context);
44
92
  }
93
+ /**
94
+ * Resolves a tool (native first, then user-authored), checks required
95
+ * parameters, and runs it.
96
+ * @param name The tool name
97
+ * @param args Named arguments for the tool
98
+ * @param context The host's opaque per-invocation context
99
+ * @param room Access to the calling agent's room, if any
100
+ * @returns The tool run result
101
+ */
45
102
  async runValidated(name, args, context, room) {
103
+ // Native tools take precedence and are always available.
46
104
  const nativeTool = this.nativeRegistry.getTool(name);
47
105
  if (nativeTool) {
48
106
  const missing = ToolExecutionService.missingRequiredParam(nativeTool.parameters, args);
@@ -76,6 +134,15 @@ class ToolExecutionService {
76
134
  }
77
135
  return null;
78
136
  }
137
+ /**
138
+ * Runs an invocation with a timeout and an abort-wired fetch helper. Fetches
139
+ * made through helpers.fetch are aborted when the timeout fires.
140
+ * @param name The tool name (for logging)
141
+ * @param toolTimeoutMs The tool's configured timeout, if any
142
+ * @param invoke Runs the tool with the provided helpers
143
+ * @param room Access to the calling agent's room, omitted when there is none
144
+ * @returns The tool run result
145
+ */
79
146
  async execute(name, toolTimeoutMs, invoke, room) {
80
147
  const timeoutMs = Math.min(toolTimeoutMs || DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS);
81
148
  const controller = new AbortController();
@@ -112,6 +179,11 @@ class ToolExecutionService {
112
179
  this.compiledCache.set(tool.name, { code: tool.code, fn });
113
180
  return fn;
114
181
  }
182
+ /**
183
+ * Caps oversized results so a tool can't blow up the agent's prompt.
184
+ * @param result The raw tool result
185
+ * @returns The result, or a truncated string form when it serializes too large
186
+ */
115
187
  static truncateResult(result) {
116
188
  const serialized = JSON.stringify(result);
117
189
  if (serialized === undefined || serialized.length <= MAX_RESULT_CHARS) {
@@ -119,9 +191,11 @@ class ToolExecutionService {
119
191
  }
120
192
  return `${serialized.slice(0, MAX_RESULT_CHARS)}...(result truncated at ${MAX_RESULT_CHARS} characters)`;
121
193
  }
194
+ /** @returns The native tool definitions registered in this process. */
122
195
  listNativeTools() {
123
196
  return this.nativeRegistry.listTools();
124
197
  }
198
+ /** @returns Whether user-authored (string) tools may run in this deployment. */
125
199
  get userAuthoredToolsEnabled() {
126
200
  return this.allowUserAuthoredTools;
127
201
  }
@@ -1,5 +1,10 @@
1
1
  import { ToolDefinition } from '../../../shared/types/app.types';
2
2
  import { UserPathsService } from '../config/user-paths.service';
3
+ /**
4
+ * A per-user service that stores and retrieves ToolDefinition objects by name.
5
+ * Each tool is stored in its own JSON file named by its (sanitized) tool name.
6
+ * Uses lazy loading - tools are loaded from disk on first access.
7
+ */
3
8
  export declare class ToolStoreService {
4
9
  private readonly userPaths;
5
10
  private tools;
@@ -9,6 +14,12 @@ export declare class ToolStoreService {
9
14
  constructor(userPaths: UserPathsService);
10
15
  listTools(): Promise<ToolDefinition[]>;
11
16
  getTool(name: string): Promise<ToolDefinition | undefined>;
17
+ /**
18
+ * Creates or updates a tool definition.
19
+ * Validates the name and syntax-checks the code so the UI gets immediate feedback.
20
+ * @param tool The tool definition to save
21
+ * @returns The saved tool definition
22
+ */
12
23
  saveTool(tool: ToolDefinition): Promise<ToolDefinition>;
13
24
  deleteTool(name: string): Promise<boolean>;
14
25
  private getToolFilePath;