briyah 2.0.3 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (391) hide show
  1. package/README.md +55 -8
  2. package/data/common/config/LICENSE-model-prices.md +65 -0
  3. package/data/common/config/markup +1 -1
  4. package/data/common/config/model_prices.json +47443 -46295
  5. package/data/common/config/story_models.json +3 -3
  6. package/data/common/prompts/illustrator/describe_scene.prompt +4 -4
  7. package/data/common/prompts/narrator/create_story.prompt +2 -0
  8. package/data/common/prompts/perceive.prompt +1 -1
  9. package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +1 -1
  10. package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +1 -1
  11. package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +795 -787
  12. package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +2 -1
  13. package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +1 -1
  14. package/data/packs/dnd5e/rooms/campaign.json +18 -15
  15. package/data/packs/dnd5e/rooms/table.json +17 -16
  16. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
  17. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +174 -3
  18. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +194 -3
  19. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +299 -19
  20. package/dist-sdk/server/src/ai/LLM/blank-image.d.ts +36 -0
  21. package/dist-sdk/server/src/ai/LLM/blank-image.js +80 -0
  22. package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
  23. package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
  24. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
  25. package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
  26. package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
  27. package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
  28. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
  29. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +103 -4
  30. package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
  31. package/dist-sdk/server/src/ai/LLM/fal.service.js +56 -2
  32. package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
  33. package/dist-sdk/server/src/ai/LLM/googleai.service.js +43 -2
  34. package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
  35. package/dist-sdk/server/src/ai/LLM/grok.service.js +55 -3
  36. package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
  37. package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
  38. package/dist-sdk/server/src/ai/LLM/openai.service.js +81 -3
  39. package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
  40. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +45 -3
  41. package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
  42. package/dist-sdk/server/src/ai/LLM/together.service.js +61 -3
  43. package/dist-sdk/server/src/ai/agent-config.d.ts +15 -1
  44. package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
  45. package/dist-sdk/server/src/ai/agent-factory.js +20 -0
  46. package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
  47. package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
  48. package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
  49. package/dist-sdk/server/src/ai/agent-store.service.js +166 -7
  50. package/dist-sdk/server/src/ai/agent.d.ts +197 -2
  51. package/dist-sdk/server/src/ai/agent.js +225 -14
  52. package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
  53. package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
  54. package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
  55. package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
  56. package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
  57. package/dist-sdk/server/src/ai/artifact.service.js +148 -3
  58. package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
  59. package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
  60. package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
  61. package/dist-sdk/server/src/ai/model_prices.js +91 -5
  62. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
  63. package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
  64. package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
  65. package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
  66. package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
  67. package/dist-sdk/server/src/app/balance-message.service.js +24 -0
  68. package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
  69. package/dist-sdk/server/src/app/balance.module.js +4 -0
  70. package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
  71. package/dist-sdk/server/src/app/balance.service.js +54 -0
  72. package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
  73. package/dist-sdk/server/src/app/stripe.controller.js +35 -0
  74. package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
  75. package/dist-sdk/server/src/app/stripe.service.js +62 -0
  76. package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
  77. package/dist-sdk/server/src/app/transaction.service.js +36 -0
  78. package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
  79. package/dist-sdk/server/src/app/user-service-factory.js +46 -3
  80. package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
  81. package/dist-sdk/server/src/app/user-service-manager.js +43 -0
  82. package/dist-sdk/server/src/app.controller.d.ts +120 -0
  83. package/dist-sdk/server/src/app.controller.js +365 -14
  84. package/dist-sdk/server/src/app.module.js +28 -6
  85. package/dist-sdk/server/src/app.service.d.ts +1710 -4
  86. package/dist-sdk/server/src/app.service.js +1938 -20
  87. package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
  88. package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
  89. package/dist-sdk/server/src/auth/auth.controller.js +46 -0
  90. package/dist-sdk/server/src/auth/auth.module.js +3 -2
  91. package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
  92. package/dist-sdk/server/src/auth/auth.service.js +39 -3
  93. package/dist-sdk/server/src/auth/jwt-auth.guard.js +44 -0
  94. package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
  95. package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
  96. package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
  97. package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
  98. package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
  99. package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
  100. package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
  101. package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
  102. package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
  103. package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
  104. package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
  105. package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
  106. package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
  107. package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
  108. package/dist-sdk/server/src/auth/session.guard.js +8 -0
  109. package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
  110. package/dist-sdk/server/src/auth/twilio.service.js +30 -4
  111. package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
  112. package/dist-sdk/server/src/auth/users.service.js +42 -0
  113. package/dist-sdk/server/src/common/errors.d.ts +20 -0
  114. package/dist-sdk/server/src/common/errors.js +21 -0
  115. package/dist-sdk/server/src/config/env-config.d.ts +7 -0
  116. package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
  117. package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
  118. package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
  119. package/dist-sdk/server/src/config/user-config.service.js +57 -0
  120. package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
  121. package/dist-sdk/server/src/config/user-paths.service.js +67 -0
  122. package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
  123. package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
  124. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
  125. package/dist-sdk/server/src/packs/pack-instantiation.service.js +104 -0
  126. package/dist-sdk/server/src/packs/pack-manifest.d.ts +114 -0
  127. package/dist-sdk/server/src/packs/pack-manifest.js +69 -0
  128. package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
  129. package/dist-sdk/server/src/packs/pack.service.js +98 -1
  130. package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
  131. package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
  132. package/dist-sdk/server/src/room/artifact.d.ts +18 -0
  133. package/dist-sdk/server/src/room/illustration/illustration.service.d.ts +211 -0
  134. package/dist-sdk/server/src/room/illustration/illustration.service.js +771 -0
  135. package/dist-sdk/server/src/room/illustration/illustration.types.d.ts +101 -0
  136. package/dist-sdk/server/src/room/illustration/illustration.types.js +2 -0
  137. package/dist-sdk/server/src/room/message.d.ts +64 -0
  138. package/dist-sdk/server/src/room/message.js +77 -2
  139. package/dist-sdk/server/src/room/nickname.d.ts +26 -0
  140. package/dist-sdk/server/src/room/nickname.js +26 -0
  141. package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
  142. package/dist-sdk/server/src/room/room-config.d.ts +84 -1
  143. package/dist-sdk/server/src/room/room-config.js +19 -0
  144. package/dist-sdk/server/src/room/room-factory.d.ts +20 -0
  145. package/dist-sdk/server/src/room/room-factory.js +25 -0
  146. package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
  147. package/dist-sdk/server/src/room/room-message.service.js +28 -0
  148. package/dist-sdk/server/src/room/room-store.service.d.ts +184 -0
  149. package/dist-sdk/server/src/room/room-store.service.js +280 -6
  150. package/dist-sdk/server/src/room/room.d.ts +981 -1
  151. package/dist-sdk/server/src/room/room.js +1531 -27
  152. package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
  153. package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
  154. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
  155. package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
  156. package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
  157. package/dist-sdk/server/src/rpg/rpg.service.js +108 -1
  158. package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
  159. package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
  160. package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
  161. package/dist-sdk/server/src/sdk/briyah.js +285 -7
  162. package/dist-sdk/server/src/sdk/index.js +23 -0
  163. package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
  164. package/dist-sdk/server/src/shared/shared.module.js +13 -5
  165. package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
  166. package/dist-sdk/server/src/story/story-message.service.js +43 -0
  167. package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
  168. package/dist-sdk/server/src/story/story-progress.service.js +23 -0
  169. package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
  170. package/dist-sdk/server/src/story/story-store.service.js +136 -1
  171. package/dist-sdk/server/src/story/story.service.d.ts +366 -9
  172. package/dist-sdk/server/src/story/story.service.js +825 -374
  173. package/dist-sdk/server/src/tools/core/illustrate.tool.d.ts +14 -0
  174. package/dist-sdk/server/src/tools/core/illustrate.tool.js +80 -0
  175. package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
  176. package/dist-sdk/server/src/tools/core/index.js +24 -1
  177. package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
  178. package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
  179. package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
  180. package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
  181. package/dist-sdk/server/src/tools/native-tool.types.d.ts +266 -0
  182. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
  183. package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
  184. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
  185. package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
  186. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
  187. package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
  188. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
  189. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
  190. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
  191. package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
  192. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
  193. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
  194. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
  195. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
  196. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
  197. package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
  198. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
  199. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
  200. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
  201. package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
  202. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
  203. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
  204. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
  205. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
  206. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
  207. package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
  208. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
  209. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
  210. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
  211. package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
  212. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
  213. package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
  214. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
  215. package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
  216. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
  217. package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
  218. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
  219. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
  220. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
  221. package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
  222. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
  223. package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
  224. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
  225. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
  226. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
  227. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
  228. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
  229. package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
  230. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
  231. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
  232. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
  233. package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
  234. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
  235. package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
  236. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
  237. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
  238. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
  239. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
  240. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
  241. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
  242. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +201 -0
  243. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +149 -0
  244. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
  245. package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
  246. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
  247. package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
  248. package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
  249. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
  250. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
  251. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
  252. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
  253. package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
  254. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
  255. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
  256. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
  257. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
  258. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
  259. package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
  260. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
  261. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
  262. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +194 -0
  263. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +263 -1
  264. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
  265. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +127 -2
  266. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
  267. package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
  268. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
  269. package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
  270. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
  271. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
  272. package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
  273. package/dist-sdk/server/src/tools/packs/index.js +66 -0
  274. package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
  275. package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
  276. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +107 -3
  277. package/dist-sdk/server/src/tools/tool-execution.service.js +163 -19
  278. package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
  279. package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
  280. package/dist-sdk/shared/types/app.types.d.ts +328 -13
  281. package/dist-sdk/shared/types/app.types.js +18 -1
  282. package/package.json +167 -168
  283. package/data/common/config/random_words.txt +0 -2241
  284. package/data/common/story_ideas/biblical.json +0 -122
  285. package/data/common/story_ideas/fantasy.json +0 -82
  286. package/data/common/story_ideas/historical_fiction.json +0 -82
  287. package/data/common/story_ideas/science_fiction.json +0 -82
  288. package/docs/.nojekyll +0 -1
  289. package/docs/assets/hierarchy.js +0 -1
  290. package/docs/assets/highlight.css +0 -113
  291. package/docs/assets/icons.js +0 -18
  292. package/docs/assets/icons.svg +0 -1
  293. package/docs/assets/main.js +0 -60
  294. package/docs/assets/navigation.js +0 -1
  295. package/docs/assets/search.js +0 -1
  296. package/docs/assets/style.css +0 -1648
  297. package/docs/classes/Agent.html +0 -801
  298. package/docs/classes/Briyah.html +0 -296
  299. package/docs/classes/BriyahConfigService.html +0 -119
  300. package/docs/classes/NativeToolRegistry.html +0 -166
  301. package/docs/classes/PackInstantiationService.html +0 -157
  302. package/docs/classes/PackService.html +0 -247
  303. package/docs/classes/Room.html +0 -1434
  304. package/docs/classes/RoomMessage.html +0 -290
  305. package/docs/enums/MessageAction.html +0 -136
  306. package/docs/functions/availableToolPacks.html +0 -41
  307. package/docs/functions/buildMarkdown.html +0 -54
  308. package/docs/functions/dnd5eTools.html +0 -44
  309. package/docs/functions/installToolPacks.html +0 -51
  310. package/docs/functions/pageMarker.html +0 -45
  311. package/docs/functions/registerToolPacks.html +0 -54
  312. package/docs/functions/splitMarkdownIntoPages.html +0 -51
  313. package/docs/functions/stripWrappingFence.html +0 -52
  314. package/docs/hierarchy.html +0 -46
  315. package/docs/index.html +0 -595
  316. package/docs/interfaces/AgentCreationOptions.html +0 -125
  317. package/docs/interfaces/AgentInfo.html +0 -218
  318. package/docs/interfaces/AgentMessagesResponse.html +0 -74
  319. package/docs/interfaces/AppService.html +0 -3340
  320. package/docs/interfaces/Artifact.html +0 -95
  321. package/docs/interfaces/ArtifactMetadata.html +0 -112
  322. package/docs/interfaces/ArtifactWriteOptions.html +0 -90
  323. package/docs/interfaces/AttachDocumentResponse.html +0 -62
  324. package/docs/interfaces/BriyahConfigOptions.html +0 -124
  325. package/docs/interfaces/ChapterInfo.html +0 -62
  326. package/docs/interfaces/Character.html +0 -86
  327. package/docs/interfaces/ConversionAgent.html +0 -78
  328. package/docs/interfaces/CreateAgentResponse.html +0 -56
  329. package/docs/interfaces/CreateRoomResponse.html +0 -62
  330. package/docs/interfaces/CreateStoryResponse.html +0 -56
  331. package/docs/interfaces/FileList.html +0 -56
  332. package/docs/interfaces/FileMetadata.html +0 -89
  333. package/docs/interfaces/IConfigService.html +0 -79
  334. package/docs/interfaces/InstantiateModels.html +0 -64
  335. package/docs/interfaces/InstantiateRoomResult.html +0 -70
  336. package/docs/interfaces/LoadedPack.html +0 -131
  337. package/docs/interfaces/LoggingOptions.html +0 -92
  338. package/docs/interfaces/Message.html +0 -84
  339. package/docs/interfaces/ModelChoice.html +0 -73
  340. package/docs/interfaces/ModelInfo.html +0 -74
  341. package/docs/interfaces/NativeToolDefinition.html +0 -107
  342. package/docs/interfaces/PackAgentTemplate.html +0 -101
  343. package/docs/interfaces/PackRoomTemplate.html +0 -108
  344. package/docs/interfaces/PackView.html +0 -172
  345. package/docs/interfaces/PdfConversionOptions.html +0 -102
  346. package/docs/interfaces/PdfConversionResult.html +0 -97
  347. package/docs/interfaces/PdfMarkdownOptions.html +0 -198
  348. package/docs/interfaces/PdfMarkdownResult.html +0 -106
  349. package/docs/interfaces/PdfPageMarkdown.html +0 -94
  350. package/docs/interfaces/PreparedPromptResponse.html +0 -62
  351. package/docs/interfaces/ProcessTextResponse.html +0 -86
  352. package/docs/interfaces/PromptFile.html +0 -70
  353. package/docs/interfaces/PromptFileContent.html +0 -76
  354. package/docs/interfaces/PromptFilesResponse.html +0 -56
  355. package/docs/interfaces/PromptFolder.html +0 -80
  356. package/docs/interfaces/PromptFolderDefaults.html +0 -155
  357. package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
  358. package/docs/interfaces/PromptFoldersResponse.html +0 -56
  359. package/docs/interfaces/RoomDetails.html +0 -151
  360. package/docs/interfaces/RoomErrorUpdate.html +0 -82
  361. package/docs/interfaces/RoomInfo.html +0 -88
  362. package/docs/interfaces/RoomMessageUpdate.html +0 -113
  363. package/docs/interfaces/RoomMessagesResponse.html +0 -62
  364. package/docs/interfaces/SendMessageResult.html +0 -62
  365. package/docs/interfaces/StoryErrorEvent.html +0 -84
  366. package/docs/interfaces/StoryIdea.html +0 -74
  367. package/docs/interfaces/StoryInfo.html +0 -198
  368. package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
  369. package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
  370. package/docs/interfaces/StoryState.html +0 -108
  371. package/docs/interfaces/StoryStateEvent.html +0 -76
  372. package/docs/interfaces/ToolArtifact.html +0 -85
  373. package/docs/interfaces/ToolCaller.html +0 -77
  374. package/docs/interfaces/ToolDefinition.html +0 -80
  375. package/docs/interfaces/ToolHelpers.html +0 -105
  376. package/docs/interfaces/ToolPackDocuments.html +0 -100
  377. package/docs/interfaces/ToolParameter.html +0 -74
  378. package/docs/interfaces/ToolRoomAccess.html +0 -260
  379. package/docs/interfaces/ToolSummary.html +0 -74
  380. package/docs/interfaces/ToolsResponse.html +0 -68
  381. package/docs/interfaces/Transaction.html +0 -104
  382. package/docs/interfaces/TransactionHistoryResponse.html +0 -62
  383. package/docs/modules.html +0 -53
  384. package/docs/types/PackOrigin.html +0 -34
  385. package/docs/types/PromptScope.html +0 -34
  386. package/docs/types/RoomTurnMode.html +0 -42
  387. package/docs/types/RoomUpdate.html +0 -36
  388. package/docs/types/RosterOverrides.html +0 -42
  389. package/docs/types/ToolContext.html +0 -40
  390. package/docs/types/ToolRunResult.html +0 -34
  391. package/src/tools/packs/dnd5e/README.md +0 -867
@@ -1,4 +1,18 @@
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
17
  exports.dnd5eTools = void 0;
4
18
  exports.installToolPacks = installToolPacks;
@@ -9,9 +23,33 @@ const dnd5e_1 = require("./dnd5e");
9
23
  Object.defineProperty(exports, "dnd5eTools", { enumerable: true, get: function () { return dnd5e_1.dnd5eTools; } });
10
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
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
+ */
15
53
  function installToolPacks(registry) {
16
54
  const core = (0, core_1.coreTools)().map((tool) => ({ ...tool, group: core_1.CORE_TOOL_GROUP }));
17
55
  registry.registerTools(core);
@@ -21,6 +59,17 @@ function installToolPacks(registry) {
21
59
  ...registerToolPacks(registry, Object.keys(PACKS).join(',')),
22
60
  ];
23
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
+ */
24
73
  function registerToolPacks(registry, packList) {
25
74
  const names = (packList || '')
26
75
  .split(',')
@@ -39,12 +88,29 @@ function registerToolPacks(registry, packList) {
39
88
  }
40
89
  return registered;
41
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
+ */
42
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.
43
108
  const grouped = tools.map((tool) => ({ ...tool, group: name }));
44
109
  registry.registerTools(grouped);
45
110
  logger_1.logger.log(`Registered tool pack "${name}" with ${grouped.length} tools`);
46
111
  return grouped.map((tool) => tool.name);
47
112
  }
113
+ /** The names of the packs that ship with the package. */
48
114
  function availableToolPacks() {
49
115
  return Object.keys(PACKS);
50
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;
@@ -1,24 +1,128 @@
1
1
  import { ToolDefinition, ToolRunResult } from '../../../shared/types/app.types';
2
2
  import { ToolStoreService } from './tool-store.service';
3
3
  import { NativeToolRegistry } from './native-tool-registry.service';
4
- import { NativeToolDefinition, ToolHelpers, ToolContext, ToolPackDocuments, ToolRoomAccess } from './native-tool.types';
4
+ import { NativeToolDefinition, ToolHelpers, ToolContext, ToolIllustration, 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;
14
- runForAgent(name: string, contentJson: string, grantedNames: string[], context?: ToolContext, room?: ToolRoomAccess): Promise<ToolRunResult>;
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
+ */
52
+ runForAgent(name: string, contentJson: string, grantedNames: string[], context?: ToolContext, room?: ToolRoomAccess, illustration?: ToolIllustration): 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
- private static missingRequiredParam;
74
+ /**
75
+ * Checks the LLM-supplied arguments against the declared parameters:
76
+ * required presence first, then any declared `enum`. Returns a ready-to-send
77
+ * error message, or null when the arguments are acceptable.
78
+ *
79
+ * An enum failure names the allowed values, so the agent can correct itself
80
+ * on its next turn rather than guessing again — the same self-correcting
81
+ * contract the rest of runForAgent uses. An omitted optional parameter is
82
+ * not enum-checked; `null` is treated as omitted, since models routinely
83
+ * send it for "not applicable".
84
+ * @param parameters The tool's declared parameters
85
+ * @param args The named arguments the agent supplied
86
+ * @returns An error message, or null when the arguments are acceptable
87
+ */
88
+ private static validateParams;
89
+ /**
90
+ * Runs an invocation with a timeout and an abort-wired fetch helper. Fetches
91
+ * made through helpers.fetch are aborted when the timeout fires.
92
+ * @param name The tool name (for logging)
93
+ * @param toolTimeoutMs The tool's configured timeout, if any
94
+ * @param toolMaxResultChars The tool's configured result budget, if any
95
+ * @param invoke Runs the tool with the provided helpers
96
+ * @param room Access to the calling agent's room, omitted when there is none
97
+ * @returns The tool run result
98
+ */
18
99
  private execute;
19
100
  private getCompiled;
101
+ /**
102
+ * Caps an oversized result while keeping it valid JSON of the same shape.
103
+ *
104
+ * This used to serialize, slice at the budget, and return the resulting
105
+ * string. That handed the agent unparseable half-JSON with the explanation
106
+ * stranded at the end, past the cut — and because the object had become a
107
+ * string it also defeated Room.describeToolResult's `detail`/`summary`
108
+ * lookup, so the room log lost its readable line for exactly the results a
109
+ * person most wanted to read. Instead:
110
+ *
111
+ * - An object keeps its keys. Its longest string properties are clipped, in
112
+ * order, until the whole thing fits, and `_truncated`/`_originalChars`
113
+ * record what happened so the agent can say so or ask for less.
114
+ * - A bare string is clipped in place with the same marker appended.
115
+ * - Anything that cannot be clipped that way — a long array, say — is
116
+ * replaced by a small object saying so, which is at least parseable.
117
+ *
118
+ * @param result The raw tool result
119
+ * @param maxChars The serialized-JSON budget for this tool
120
+ * @returns A result that serializes within budget
121
+ */
20
122
  private static truncateResult;
123
+ /** @returns The native tool definitions registered in this process. */
21
124
  listNativeTools(): NativeToolDefinition[];
125
+ /** @returns Whether user-authored (string) tools may run in this deployment. */
22
126
  get userAuthoredToolsEnabled(): boolean;
23
127
  }
24
128
  export {};