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,4 +1,19 @@
1
1
  "use strict";
2
+ /**
3
+ * Per-user Briyah settings.
4
+ *
5
+ * Today that is only which packs the user has enabled, but it exists as its own
6
+ * file rather than a field somewhere for two reasons.
7
+ *
8
+ * **It is not `user-preferences.json`.** That file is the host's: its contract
9
+ * says preferences are application-defined and returned as-is, and
10
+ * `saveUserPreferences` writes the whole object. A host storing a theme there
11
+ * would wipe pack enablement on the next save.
12
+ *
13
+ * **It is not on `UserPathsService`.** That resolves paths, and it is faked with
14
+ * bare object literals across the specs — every method added to it has to be
15
+ * added to those fakes too.
16
+ */
2
17
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
18
  if (k2 === undefined) k2 = k;
4
19
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -42,10 +57,23 @@ class UserConfigService {
42
57
  userPaths;
43
58
  cached = null;
44
59
  cachedAtMs = 0;
60
+ /**
61
+ * How long a read is trusted before the file is consulted again.
62
+ *
63
+ * `UserServiceManager` keeps an `AppService` for 30 minutes, so caching for the
64
+ * life of the instance would mean a second tab, another process or the SDK
65
+ * toggling a pack and this one never noticing. A second is long enough to
66
+ * collapse the burst of reads a single page load produces and short enough that
67
+ * nobody sees a stale list.
68
+ */
45
69
  static CACHE_MS = 1_000;
46
70
  constructor(userPaths) {
47
71
  this.userPaths = userPaths;
48
72
  }
73
+ /**
74
+ * Reads this user's settings.
75
+ * @returns The settings, or an empty object when there is no file or it is unreadable
76
+ */
49
77
  get() {
50
78
  const now = Date.now();
51
79
  if (this.cached && now - this.cachedAtMs < UserConfigService.CACHE_MS) {
@@ -55,7 +83,15 @@ class UserConfigService {
55
83
  this.cachedAtMs = now;
56
84
  return this.cached;
57
85
  }
86
+ /**
87
+ * Merges a patch into this user's settings.
88
+ * @param patch The fields to change
89
+ * @returns The settings as they now stand
90
+ */
58
91
  update(patch) {
92
+ // Read through the file rather than the cache: another process may have
93
+ // written since, and losing its change to a stale merge is worse than the
94
+ // extra read.
59
95
  const merged = { ...this.read(), ...patch };
60
96
  fs.mkdirSync(this.userPaths.getUserConfigDir(), { recursive: true });
61
97
  fs.writeFileSync(this.configPath(), JSON.stringify(merged, null, 2), 'utf8');
@@ -63,9 +99,23 @@ class UserConfigService {
63
99
  this.cachedAtMs = Date.now();
64
100
  return merged;
65
101
  }
102
+ /**
103
+ * The packs this user has enabled.
104
+ *
105
+ * Names only — whether a pack of that name is actually installed is the pack
106
+ * registry's business, so a pack that was enabled and then removed from disk
107
+ * stays in the list and comes back if it is reinstalled.
108
+ *
109
+ * @returns The enabled pack names
110
+ */
66
111
  enabledPacks() {
67
112
  return this.get().enabledPacks ?? [];
68
113
  }
114
+ /**
115
+ * Turns one pack on or off, leaving the rest alone.
116
+ * @param packName The pack to change
117
+ * @param enabled Whether it should be on
118
+ */
69
119
  setPackEnabled(packName, enabled) {
70
120
  const current = new Set(this.enabledPacks());
71
121
  if (enabled) {
@@ -79,6 +129,13 @@ class UserConfigService {
79
129
  configPath() {
80
130
  return path.join(this.userPaths.getUserConfigDir(), CONFIG_FILE);
81
131
  }
132
+ /**
133
+ * Reads the file, treating anything unreadable as absent.
134
+ *
135
+ * Throwing here would take down every page that lists a prompt or an artifact,
136
+ * because enablement is consulted on all of them. A corrupt file costs the user
137
+ * their pack selection, which they can set again.
138
+ */
82
139
  read() {
83
140
  const file = this.configPath();
84
141
  if (!fs.existsSync(file)) {
@@ -14,15 +14,76 @@ export declare class UserPathsService {
14
14
  getUploadDir(): string;
15
15
  getUserConfigDir(): string;
16
16
  getCommonConfigDir(): string;
17
+ /**
18
+ * Stores configuration data to a file
19
+ * @param configName The name of the configuration file
20
+ * @param data The data to store
21
+ */
17
22
  store(configName: string, data: string): void;
23
+ /**
24
+ * Loads configuration data from a file
25
+ * @param configName The name of the configuration file
26
+ * @returns The configuration data as a string, or null if the file doesn't exist
27
+ */
18
28
  load(configName: string): string | null;
29
+ /**
30
+ * Checks if a configuration file exists
31
+ * @param configName The name of the configuration file
32
+ * @returns True if the file exists, false otherwise
33
+ */
19
34
  exists(configName: string): boolean;
35
+ /**
36
+ * Gets the common prompts directory (shared across all users)
37
+ * @returns The common prompts directory path
38
+ */
20
39
  getCommonPromptsDir(): string;
40
+ /**
41
+ * Gets the user-specific prompts directory
42
+ * @returns The user prompts directory path
43
+ */
21
44
  getUserPromptsDir(): string;
45
+ /**
46
+ * Gets the user data directory
47
+ * @returns The user data directory path
48
+ */
22
49
  getUserDataDir(): string;
50
+ /**
51
+ * Gets the directory holding installed packs, one subdirectory per pack.
52
+ *
53
+ * Unlike the directories above, the pack directories are **not** created by
54
+ * this constructor. The set of packs is dynamic — a host adds one by copying
55
+ * it in — so there is nothing to pre-create, and this constructor runs once
56
+ * per user-service creation.
57
+ *
58
+ * @returns The installed packs directory path
59
+ */
23
60
  getPacksDir(): string;
61
+ /**
62
+ * Gets one installed pack's directory.
63
+ * @param packName The pack name, already validated by the caller
64
+ * @returns The pack directory path, which may not exist
65
+ */
24
66
  getPackDir(packName: string): string;
67
+ /**
68
+ * Gets the user's own pack directory.
69
+ *
70
+ * Holds two things that need no distinguishing at lookup time: copy-on-write
71
+ * overlays of installed packs, and packs the user created themselves. Which
72
+ * one a subdirectory is depends only on whether {@link getPackDir} exists for
73
+ * the same name, and only the pack listing has to care.
74
+ *
75
+ * @returns The user packs directory path
76
+ */
25
77
  getUserPacksDir(): string;
78
+ /**
79
+ * Gets one of the user's pack directories.
80
+ * @param packName The pack name, already validated by the caller
81
+ * @returns The directory path, which may not exist
82
+ */
26
83
  getUserPackDir(packName: string): string;
84
+ /**
85
+ * Gets the current user ID
86
+ * @returns The user ID from authentication context or 'admin' as fallback
87
+ */
27
88
  getUserId(): string;
28
89
  }
@@ -47,12 +47,16 @@ class UserPathsService {
47
47
  userDataDir;
48
48
  userId;
49
49
  constructor(userId, baseDataPath) {
50
+ // Use the provided userId directly
50
51
  this.userId = userId;
52
+ // Priority: constructor param > env var > default
51
53
  const dataPath = baseDataPath || process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
54
+ // Create the base data directory if it doesn't exist
52
55
  this.dataDir = path.resolve(dataPath);
53
56
  if (!fs.existsSync(this.dataDir)) {
54
57
  fs.mkdirSync(this.dataDir, { recursive: true });
55
58
  }
59
+ // Common directories (shared across all users)
56
60
  const commonDir = path.resolve(this.dataDir, 'common');
57
61
  this.commonConfigDir = path.resolve(commonDir, 'config');
58
62
  if (!fs.existsSync(this.commonConfigDir)) {
@@ -62,6 +66,7 @@ class UserPathsService {
62
66
  if (!fs.existsSync(this.commonPromptsDir)) {
63
67
  fs.mkdirSync(this.commonPromptsDir, { recursive: true });
64
68
  }
69
+ // User-specific directories
65
70
  this.userDataDir = path.resolve(this.dataDir, 'user', this.userId);
66
71
  this.userPromptsDir = path.resolve(this.userDataDir, 'prompts');
67
72
  if (!fs.existsSync(this.userPromptsDir)) {
@@ -75,6 +80,7 @@ class UserPathsService {
75
80
  if (!fs.existsSync(this.userConfigDir)) {
76
81
  fs.mkdirSync(this.userConfigDir, { recursive: true });
77
82
  }
83
+ // For backward compatibility, promptsDir returns user prompts
78
84
  this.promptsDir = this.userPromptsDir;
79
85
  }
80
86
  getDataDir() {
@@ -92,10 +98,20 @@ class UserPathsService {
92
98
  getCommonConfigDir() {
93
99
  return this.commonConfigDir;
94
100
  }
101
+ /**
102
+ * Stores configuration data to a file
103
+ * @param configName The name of the configuration file
104
+ * @param data The data to store
105
+ */
95
106
  store(configName, data) {
96
107
  const configPath = path.join(this.getUserConfigDir(), configName);
97
108
  fs.writeFileSync(configPath, data);
98
109
  }
110
+ /**
111
+ * Loads configuration data from a file
112
+ * @param configName The name of the configuration file
113
+ * @returns The configuration data as a string, or null if the file doesn't exist
114
+ */
99
115
  load(configName) {
100
116
  const configPath = path.join(this.getUserConfigDir(), configName);
101
117
  if (!fs.existsSync(configPath)) {
@@ -103,31 +119,82 @@ class UserPathsService {
103
119
  }
104
120
  return fs.readFileSync(configPath, 'utf8');
105
121
  }
122
+ /**
123
+ * Checks if a configuration file exists
124
+ * @param configName The name of the configuration file
125
+ * @returns True if the file exists, false otherwise
126
+ */
106
127
  exists(configName) {
107
128
  const configPath = path.join(this.getUserConfigDir(), configName);
108
129
  return fs.existsSync(configPath);
109
130
  }
131
+ /**
132
+ * Gets the common prompts directory (shared across all users)
133
+ * @returns The common prompts directory path
134
+ */
110
135
  getCommonPromptsDir() {
111
136
  return this.commonPromptsDir;
112
137
  }
138
+ /**
139
+ * Gets the user-specific prompts directory
140
+ * @returns The user prompts directory path
141
+ */
113
142
  getUserPromptsDir() {
114
143
  return this.userPromptsDir;
115
144
  }
145
+ /**
146
+ * Gets the user data directory
147
+ * @returns The user data directory path
148
+ */
116
149
  getUserDataDir() {
117
150
  return this.userDataDir;
118
151
  }
152
+ /**
153
+ * Gets the directory holding installed packs, one subdirectory per pack.
154
+ *
155
+ * Unlike the directories above, the pack directories are **not** created by
156
+ * this constructor. The set of packs is dynamic — a host adds one by copying
157
+ * it in — so there is nothing to pre-create, and this constructor runs once
158
+ * per user-service creation.
159
+ *
160
+ * @returns The installed packs directory path
161
+ */
119
162
  getPacksDir() {
120
163
  return path.resolve(this.dataDir, 'packs');
121
164
  }
165
+ /**
166
+ * Gets one installed pack's directory.
167
+ * @param packName The pack name, already validated by the caller
168
+ * @returns The pack directory path, which may not exist
169
+ */
122
170
  getPackDir(packName) {
123
171
  return path.resolve(this.getPacksDir(), packName);
124
172
  }
173
+ /**
174
+ * Gets the user's own pack directory.
175
+ *
176
+ * Holds two things that need no distinguishing at lookup time: copy-on-write
177
+ * overlays of installed packs, and packs the user created themselves. Which
178
+ * one a subdirectory is depends only on whether {@link getPackDir} exists for
179
+ * the same name, and only the pack listing has to care.
180
+ *
181
+ * @returns The user packs directory path
182
+ */
125
183
  getUserPacksDir() {
126
184
  return path.resolve(this.userDataDir, 'packs');
127
185
  }
186
+ /**
187
+ * Gets one of the user's pack directories.
188
+ * @param packName The pack name, already validated by the caller
189
+ * @returns The directory path, which may not exist
190
+ */
128
191
  getUserPackDir(packName) {
129
192
  return path.resolve(this.getUserPacksDir(), packName);
130
193
  }
194
+ /**
195
+ * Gets the current user ID
196
+ * @returns The user ID from authentication context or 'admin' as fallback
197
+ */
131
198
  getUserId() {
132
199
  return this.userId;
133
200
  }
@@ -1,43 +1,163 @@
1
+ /**
2
+ * Turning a PDF into Markdown, one page at a time.
3
+ *
4
+ * The machinery only: splitting the document, bounding how many pages are in
5
+ * flight, retrying a page that fails, and assembling the result. Rendering a page
6
+ * is the caller's job — it supplies a {@link RenderPage} that owns the agent, the
7
+ * model and the prompt — so this module has no dependency on AppService and can be
8
+ * tested without an LLM.
9
+ *
10
+ * Three failure modes are handled here because each one was silently losing pages:
11
+ *
12
+ * - **An empty response.** The conversion occasionally returns nothing at all. Left
13
+ * alone the page reaches the reader as a gap with no indication anything was
14
+ * dropped, which is worse than an error.
15
+ * - **A thrown error.** A rate limit is the common one, and it is precisely what a
16
+ * large document provokes by converting every page at once. Retried with backoff.
17
+ * - **A page that never settles.** Raced against a timeout inside the retry, so a
18
+ * stalled page is retried rather than lost.
19
+ *
20
+ * A page that exhausts its attempts does not fail the document. It comes back with
21
+ * empty markdown and an `error`, the assembled Markdown carries a marker where the
22
+ * page should have been, and the caller is told which pages to re-run.
23
+ */
24
+ /** One page's conversion, successful or not. */
1
25
  export interface PdfPageMarkdown {
26
+ /** 1-based, as a reader counts pages. */
2
27
  pageNum: number;
28
+ /** The page's Markdown, or empty when every attempt failed. */
3
29
  markdown: string;
30
+ /** How many attempts it took (or were spent failing). */
4
31
  attempts: number;
32
+ /** Why the page could not be converted. Absent on success. */
5
33
  error?: string;
34
+ /**
35
+ * Every agent the page was attempted with, for cost accounting — one per
36
+ * attempt, because a failed attempt still spent tokens.
37
+ */
6
38
  agents: ConversionAgent[];
7
39
  }
40
+ /**
41
+ * What this module needs of an agent: somewhere to read the cost from. Narrower
42
+ * than `Agent` on purpose, so the module stays testable with a stub.
43
+ */
8
44
  export interface ConversionAgent {
9
45
  totalCost: number;
10
46
  finishAgent(): Promise<void>;
11
47
  }
12
- export type RenderPage = (pageBuffer: Uint8Array, pageNum: number, pageCount: number) => Promise<{
48
+ /** Renders one page of the document to Markdown. Supplied by the caller. */
49
+ export type RenderPage = (
50
+ /** A one-page PDF, ready to attach. */
51
+ pageBuffer: Uint8Array, pageNum: number, pageCount: number) => Promise<{
13
52
  markdown: string;
14
53
  agent?: ConversionAgent;
15
54
  }>;
55
+ /** How a conversion should be run. Every field has an environment-backed default. */
16
56
  export interface PdfConversionOptions {
57
+ /**
58
+ * How many pages may be converted at once.
59
+ *
60
+ * The reason this exists: converting every page concurrently is what a 146-page
61
+ * document did before there was a cap, and the provider rate-limited most of
62
+ * them. Defaults to `PDF_CONVERT_CONCURRENCY` or 20.
63
+ */
17
64
  concurrency?: number;
65
+ /** Attempts per page before giving up. Defaults to `PDF_CONVERT_PAGE_ATTEMPTS` or 3. */
18
66
  attempts?: number;
67
+ /** Per-attempt timeout. Defaults to `PDF_CONVERT_PAGE_TIMEOUT_MS` or 2 minutes. */
19
68
  pageTimeoutMs?: number;
69
+ /** Base delay for the exponential backoff between attempts. Defaults to 1000ms. */
20
70
  retryBackoffMs?: number;
71
+ /** Called as pages complete, for a caller with somewhere to show it. */
21
72
  onProgress?: (message: string) => void;
22
73
  }
74
+ /** A finished conversion. */
23
75
  export interface PdfConversionResult {
24
76
  pages: PdfPageMarkdown[];
77
+ /** Every page concatenated, with `<!-- Page N -->` markers and a header. */
25
78
  markdown: string;
79
+ /** The pages that exhausted their attempts, in order. Empty on a clean run. */
26
80
  failedPages: number[];
27
81
  pageCount: number;
82
+ /** Summed across every page's agent. */
28
83
  totalCost: number;
84
+ /** Every agent created, so a caller can finish them or bill them. */
29
85
  agents: ConversionAgent[];
30
86
  }
87
+ /** The retry policy, resolved from the environment. */
31
88
  export interface ConversionLimits {
32
89
  concurrency: number;
33
90
  attempts: number;
34
91
  pageTimeoutMs: number;
35
92
  backoffMs: number;
36
93
  }
94
+ /**
95
+ * The configured limits, so a caller converting a document whole rather than
96
+ * page-by-page retries on the same policy as this module does.
97
+ *
98
+ * @param overrides Anything the caller wants to pin
99
+ * @returns The resolved limits
100
+ */
37
101
  export declare function conversionLimits(overrides?: PdfConversionOptions): ConversionLimits;
102
+ /**
103
+ * Unwraps a response the model fenced as one ```markdown block.
104
+ *
105
+ * The prompt asks for bare Markdown and mostly gets it, but a page comes back
106
+ * wrapped often enough that the fence markers end up as literal content in the
107
+ * artifact. Only a fence that opens at the very start and closes at the very end is
108
+ * stripped, so a page whose real content is a code block is left alone.
109
+ *
110
+ * @param text The model's response
111
+ * @returns The response with a wrapping fence removed
112
+ */
38
113
  export declare function stripWrappingFence(text: string): string;
114
+ /** The marker written between pages. An HTML comment, so it does not render. */
39
115
  export declare function pageMarker(pageNum: number): string;
116
+ /**
117
+ * Splits a converted document back into its pages on the `<!-- Page N -->` markers.
118
+ *
119
+ * The inverse of {@link buildMarkdown}, and the reason the markers are machine
120
+ * readable at all: re-running the pages that failed means finding them, converting
121
+ * them, and splicing them back.
122
+ *
123
+ * @param markdown A document this module produced, or any Markdown
124
+ * @returns One entry per page; the whole document as page 1 when it carries no markers
125
+ */
40
126
  export declare function splitMarkdownIntoPages(markdown: string): PdfPageMarkdown[];
127
+ /**
128
+ * Assembles the pages into one document.
129
+ *
130
+ * A run that lost pages says so **at the top** as well as in place. An inline
131
+ * marker alone is easy to scroll past in a 146-page transcript, and a reader who
132
+ * does not notice it treats a document with holes in it as complete.
133
+ *
134
+ * @param pages The converted pages, in order
135
+ * @param pageCount How many pages the document had
136
+ * @returns The assembled Markdown
137
+ */
41
138
  export declare function buildMarkdown(pages: readonly PdfPageMarkdown[], pageCount: number): string;
139
+ /**
140
+ * Runs `worker` over `count` items with at most `limit` in flight.
141
+ *
142
+ * A rolling pool rather than sequential batches: a batch barrier makes every
143
+ * finished page in a batch wait on its slowest sibling, which on a document whose
144
+ * pages vary in size is most of the wall clock.
145
+ *
146
+ * `worker` must not reject — a rejection here would abandon the remaining items.
147
+ *
148
+ * @param count How many items there are
149
+ * @param limit Maximum concurrent workers
150
+ * @param worker Receives the item index; must resolve
151
+ * @returns Results in item order
152
+ */
42
153
  export declare function runWithConcurrency<T>(count: number, limit: number, worker: (index: number) => Promise<T>): Promise<T[]>;
154
+ /**
155
+ * Converts every page of a PDF to Markdown.
156
+ *
157
+ * @param pdfBuffer The whole document
158
+ * @param renderPage Converts one page; supplied by the caller
159
+ * @param options Concurrency, attempts, timeout and progress
160
+ * @returns The pages, the assembled Markdown, and what failed
161
+ * @throws If the PDF cannot be parsed at all, or carries no pages
162
+ */
43
163
  export declare function convertPdfToMarkdown(pdfBuffer: Uint8Array, renderPage: RenderPage, options?: PdfConversionOptions): Promise<PdfConversionResult>;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ /**
3
+ * Turning a PDF into Markdown, one page at a time.
4
+ *
5
+ * The machinery only: splitting the document, bounding how many pages are in
6
+ * flight, retrying a page that fails, and assembling the result. Rendering a page
7
+ * is the caller's job — it supplies a {@link RenderPage} that owns the agent, the
8
+ * model and the prompt — so this module has no dependency on AppService and can be
9
+ * tested without an LLM.
10
+ *
11
+ * Three failure modes are handled here because each one was silently losing pages:
12
+ *
13
+ * - **An empty response.** The conversion occasionally returns nothing at all. Left
14
+ * alone the page reaches the reader as a gap with no indication anything was
15
+ * dropped, which is worse than an error.
16
+ * - **A thrown error.** A rate limit is the common one, and it is precisely what a
17
+ * large document provokes by converting every page at once. Retried with backoff.
18
+ * - **A page that never settles.** Raced against a timeout inside the retry, so a
19
+ * stalled page is retried rather than lost.
20
+ *
21
+ * A page that exhausts its attempts does not fail the document. It comes back with
22
+ * empty markdown and an `error`, the assembled Markdown carries a marker where the
23
+ * page should have been, and the caller is told which pages to re-run.
24
+ */
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.conversionLimits = conversionLimits;
4
27
  exports.stripWrappingFence = stripWrappingFence;
@@ -12,10 +35,18 @@ const DEFAULT_CONCURRENCY = 20;
12
35
  const DEFAULT_ATTEMPTS = 3;
13
36
  const DEFAULT_PAGE_TIMEOUT_MS = 2 * 60 * 1000;
14
37
  const DEFAULT_BACKOFF_MS = 1000;
38
+ /** Reads a positive integer from the environment, falling back when unset or unusable. */
15
39
  function envInt(name, fallback) {
16
40
  const parsed = Number(process.env[name]);
17
41
  return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : fallback;
18
42
  }
43
+ /**
44
+ * The configured limits, so a caller converting a document whole rather than
45
+ * page-by-page retries on the same policy as this module does.
46
+ *
47
+ * @param overrides Anything the caller wants to pin
48
+ * @returns The resolved limits
49
+ */
19
50
  function conversionLimits(overrides = {}) {
20
51
  return {
21
52
  concurrency: overrides.concurrency ?? envInt('PDF_CONVERT_CONCURRENCY', DEFAULT_CONCURRENCY),
@@ -24,15 +55,38 @@ function conversionLimits(overrides = {}) {
24
55
  backoffMs: overrides.retryBackoffMs ?? DEFAULT_BACKOFF_MS,
25
56
  };
26
57
  }
58
+ /**
59
+ * Unwraps a response the model fenced as one ```markdown block.
60
+ *
61
+ * The prompt asks for bare Markdown and mostly gets it, but a page comes back
62
+ * wrapped often enough that the fence markers end up as literal content in the
63
+ * artifact. Only a fence that opens at the very start and closes at the very end is
64
+ * stripped, so a page whose real content is a code block is left alone.
65
+ *
66
+ * @param text The model's response
67
+ * @returns The response with a wrapping fence removed
68
+ */
27
69
  function stripWrappingFence(text) {
28
70
  const trimmed = (text || '').trim();
29
71
  const match = /^```[a-zA-Z0-9_-]*\r?\n([\s\S]*?)\r?\n?```$/.exec(trimmed);
30
72
  return match ? match[1].trim() : trimmed;
31
73
  }
74
+ /** The marker written between pages. An HTML comment, so it does not render. */
32
75
  function pageMarker(pageNum) {
33
76
  return `<!-- Page ${pageNum} -->`;
34
77
  }
78
+ /** Header comment prefixes dropped when splitting a document back into pages. */
35
79
  const HEADER_PREFIXES = ['<!-- Document Markdown', '<!-- Converted:', '<!-- Total Pages:'];
80
+ /**
81
+ * Splits a converted document back into its pages on the `<!-- Page N -->` markers.
82
+ *
83
+ * The inverse of {@link buildMarkdown}, and the reason the markers are machine
84
+ * readable at all: re-running the pages that failed means finding them, converting
85
+ * them, and splicing them back.
86
+ *
87
+ * @param markdown A document this module produced, or any Markdown
88
+ * @returns One entry per page; the whole document as page 1 when it carries no markers
89
+ */
36
90
  function splitMarkdownIntoPages(markdown) {
37
91
  const pages = [];
38
92
  const markerPattern = /^<!--\s*Page\s+(\d+)\s*-->$/i;
@@ -60,6 +114,17 @@ function splitMarkdownIntoPages(markdown) {
60
114
  }
61
115
  return pages;
62
116
  }
117
+ /**
118
+ * Assembles the pages into one document.
119
+ *
120
+ * A run that lost pages says so **at the top** as well as in place. An inline
121
+ * marker alone is easy to scroll past in a 146-page transcript, and a reader who
122
+ * does not notice it treats a document with holes in it as complete.
123
+ *
124
+ * @param pages The converted pages, in order
125
+ * @param pageCount How many pages the document had
126
+ * @returns The assembled Markdown
127
+ */
63
128
  function buildMarkdown(pages, pageCount) {
64
129
  const failed = pages.filter((page) => !page.markdown.trim()).map((page) => page.pageNum);
65
130
  const parts = [
@@ -80,6 +145,20 @@ function buildMarkdown(pages, pageCount) {
80
145
  }
81
146
  return parts.join('\n');
82
147
  }
148
+ /**
149
+ * Runs `worker` over `count` items with at most `limit` in flight.
150
+ *
151
+ * A rolling pool rather than sequential batches: a batch barrier makes every
152
+ * finished page in a batch wait on its slowest sibling, which on a document whose
153
+ * pages vary in size is most of the wall clock.
154
+ *
155
+ * `worker` must not reject — a rejection here would abandon the remaining items.
156
+ *
157
+ * @param count How many items there are
158
+ * @param limit Maximum concurrent workers
159
+ * @param worker Receives the item index; must resolve
160
+ * @returns Results in item order
161
+ */
83
162
  async function runWithConcurrency(count, limit, worker) {
84
163
  const results = new Array(count);
85
164
  let next = 0;
@@ -94,6 +173,7 @@ async function runWithConcurrency(count, limit, worker) {
94
173
  await Promise.all(Array.from({ length: Math.max(1, Math.min(limit, count)) }, runner));
95
174
  return results;
96
175
  }
176
+ /** Races a promise against a timeout, clearing the timer either way. */
97
177
  async function withTimeout(work, ms, label) {
98
178
  let timer;
99
179
  const timeout = new Promise((_, reject) => {
@@ -107,6 +187,15 @@ async function withTimeout(work, ms, label) {
107
187
  }
108
188
  }
109
189
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
190
+ /**
191
+ * Converts every page of a PDF to Markdown.
192
+ *
193
+ * @param pdfBuffer The whole document
194
+ * @param renderPage Converts one page; supplied by the caller
195
+ * @param options Concurrency, attempts, timeout and progress
196
+ * @returns The pages, the assembled Markdown, and what failed
197
+ * @throws If the PDF cannot be parsed at all, or carries no pages
198
+ */
110
199
  async function convertPdfToMarkdown(pdfBuffer, renderPage, options = {}) {
111
200
  const pdfDoc = await pdf_lib_1.PDFDocument.load(pdfBuffer);
112
201
  const pageCount = pdfDoc.getPageCount();
@@ -135,6 +224,7 @@ async function convertPdfToMarkdown(pdfBuffer, renderPage, options = {}) {
135
224
  agents,
136
225
  };
137
226
  }
227
+ /** Extracts one page and converts it, retrying an empty response or a thrown error. */
138
228
  async function convertOnePage(pdfDoc, pageIndex, pageCount, renderPage, limits) {
139
229
  const pageNum = pageIndex + 1;
140
230
  let pageBuffer;
@@ -145,6 +235,8 @@ async function convertOnePage(pdfDoc, pageIndex, pageCount, renderPage, limits)
145
235
  pageBuffer = await singlePage.save();
146
236
  }
147
237
  catch (error) {
238
+ // Extraction is local work: if it fails the page is unreadable and no
239
+ // number of LLM calls will change that, so it is not retried.
148
240
  return {
149
241
  pageNum,
150
242
  markdown: '',
@@ -158,6 +250,8 @@ async function convertOnePage(pdfDoc, pageIndex, pageCount, renderPage, limits)
158
250
  for (let attempt = 1; attempt <= limits.attempts; attempt++) {
159
251
  try {
160
252
  const rendered = await withTimeout(renderPage(pageBuffer, pageNum, pageCount), limits.pageTimeoutMs, `page ${pageNum}`);
253
+ // Collected whether or not the attempt worked: a failed attempt still
254
+ // spent tokens, and dropping it would under-report the conversion's cost.
161
255
  if (rendered.agent)
162
256
  agents.push(rendered.agent);
163
257
  const markdown = stripWrappingFence(rendered.markdown);