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
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * Recognizing the frame an image model returns when it has refused.
4
+ *
5
+ * A refusal usually arrives as a perfectly successful response carrying a uniformly
6
+ * black picture rather than as an error, so nothing upstream of the pixels can tell
7
+ * it apart from a drawing. Stored, it replaces the likeness it was meant to redraw —
8
+ * `IllustrationService.updatePortrait` deletes the old portrait once the new one is
9
+ * in hand — and the original is gone for good.
10
+ *
11
+ * The test is the compressed size rather than the pixels, because both PNG's deflate
12
+ * and JPEG's DCT crush a flat frame to almost nothing. Measured at 1024x1024, in
13
+ * bytes per pixel:
14
+ *
15
+ * solid colour 0.003
16
+ * smooth gradient 0.11 the flattest thing a model actually draws
17
+ * photographic detail 1.0 - 3.0
18
+ *
19
+ * So the two cases are more than an order of magnitude apart on either side of the
20
+ * threshold below, and deciding between them needs no decoder and no dependency.
21
+ *
22
+ * The limits are worth knowing. A refusal that is not flat — a placeholder graphic,
23
+ * a frame of noise — reads as a picture; those are not what the models in use here
24
+ * return, and guessing at them would cost real drawings. In the other direction a
25
+ * genuinely flat synthetic image, two blocks of colour or a shape on a plain ground,
26
+ * reads as blank, which is why this is applied to generated illustration output and
27
+ * not to anything a person uploads.
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.BlankImageError = void 0;
31
+ exports.isBlankImage = isBlankImage;
32
+ /** PNG's 8-byte file signature. */
33
+ const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
34
+ /** Compressed bytes per pixel below which a frame holds no picture. */
35
+ const MIN_BYTES_PER_PIXEL = 0.02;
36
+ /**
37
+ * The floor applied when the dimensions cannot be read, which today means anything
38
+ * that is not a PNG. Every entry in image_models.json generates at 1024x1024 or
39
+ * larger, and the most aggressive JPEG of a face at that size is still several times
40
+ * this. It is deliberately not applied to PNGs, whose dimensions are there to be
41
+ * read: a small PNG that really is a picture is under the floor honestly.
42
+ */
43
+ const MIN_IMAGE_BYTES = 20_000;
44
+ /** Thrown instead of storing a frame that carries no picture. */
45
+ class BlankImageError extends Error {
46
+ constructor(message) {
47
+ super(message);
48
+ this.name = 'BlankImageError';
49
+ if (Error.captureStackTrace) {
50
+ Error.captureStackTrace(this, BlankImageError);
51
+ }
52
+ }
53
+ }
54
+ exports.BlankImageError = BlankImageError;
55
+ /** Width and height out of a PNG's IHDR chunk, or null for anything else. */
56
+ function readPngDimensions(image) {
57
+ // The 8-byte signature, a 4-byte chunk length, 'IHDR', then width and height.
58
+ if (image.length < 24)
59
+ return null;
60
+ if (!image.subarray(0, 8).equals(PNG_SIGNATURE))
61
+ return null;
62
+ if (image.subarray(12, 16).toString('ascii') !== 'IHDR')
63
+ return null;
64
+ return { width: image.readUInt32BE(16), height: image.readUInt32BE(20) };
65
+ }
66
+ /**
67
+ * Whether these bytes are a blank frame rather than a picture.
68
+ * @param image The decoded image bytes
69
+ */
70
+ function isBlankImage(image) {
71
+ if (!image || image.length === 0)
72
+ return true;
73
+ const dimensions = readPngDimensions(image);
74
+ if (!dimensions)
75
+ return image.length < MIN_IMAGE_BYTES;
76
+ const pixels = dimensions.width * dimensions.height;
77
+ if (pixels <= 0)
78
+ return true;
79
+ return image.length / pixels < MIN_BYTES_PER_PIXEL;
80
+ }
@@ -1,7 +1,11 @@
1
1
  export interface ComfyUiClientOptions {
2
+ /** Base URL of the ComfyUI server, without a trailing slash (e.g. http://gpu-box:8188) */
2
3
  baseUrl: string;
4
+ /** Extra headers merged into every request (e.g. reverse-proxy basic auth) */
3
5
  extraHeaders?: Record<string, string>;
6
+ /** Total time to wait for a queued prompt to complete, in ms (queue wait + generation) */
4
7
  timeoutMs?: number;
8
+ /** Interval between /history polls, in ms */
5
9
  pollIntervalMs?: number;
6
10
  }
7
11
  export interface ComfyUiImageRef {
@@ -9,6 +13,11 @@ export interface ComfyUiImageRef {
9
13
  subfolder: string;
10
14
  type: string;
11
15
  }
16
+ /**
17
+ * Minimal HTTP client for the ComfyUI server API. Plain class (not a Nest
18
+ * service) so it can be constructed and unit-tested without DI. Uses the
19
+ * global fetch/FormData available in Node 18+.
20
+ */
12
21
  export declare class ComfyUiClient {
13
22
  private readonly baseUrl;
14
23
  private readonly extraHeaders;
@@ -16,13 +25,30 @@ export declare class ComfyUiClient {
16
25
  private readonly pollIntervalMs;
17
26
  private readonly clientId;
18
27
  constructor(options: ComfyUiClientOptions);
28
+ /**
29
+ * Checks whether the ComfyUI server responds. Intended for diagnostics and
30
+ * tests; generation paths surface their own errors.
31
+ */
19
32
  checkReachable(): Promise<boolean>;
33
+ /**
34
+ * Uploads an image to the ComfyUI input folder.
35
+ * @returns The server-side name (and subfolder) to reference in a LoadImage node
36
+ */
20
37
  uploadImage(data: Buffer, filename: string): Promise<{
21
38
  name: string;
22
39
  subfolder: string;
23
40
  }>;
41
+ /**
42
+ * Queues a workflow (API-format graph) for execution.
43
+ * @returns The prompt id to poll for completion
44
+ */
24
45
  queuePrompt(workflow: Record<string, any>): Promise<string>;
46
+ /**
47
+ * Polls /history until the prompt completes, fails, or the timeout elapses.
48
+ * @returns The first output image reference from the completed workflow
49
+ */
25
50
  waitForCompletion(promptId: string): Promise<ComfyUiImageRef>;
51
+ /** Downloads a generated image. */
26
52
  fetchOutput(ref: ComfyUiImageRef): Promise<Buffer>;
27
53
  private findFirstOutputImage;
28
54
  private extractErrorMessages;
@@ -5,6 +5,11 @@ const crypto_1 = require("crypto");
5
5
  const logger_1 = require("../../common/logger");
6
6
  const DEFAULT_TIMEOUT_MS = 600_000;
7
7
  const DEFAULT_POLL_INTERVAL_MS = 2_000;
8
+ /**
9
+ * Minimal HTTP client for the ComfyUI server API. Plain class (not a Nest
10
+ * service) so it can be constructed and unit-tested without DI. Uses the
11
+ * global fetch/FormData available in Node 18+.
12
+ */
8
13
  class ComfyUiClient {
9
14
  baseUrl;
10
15
  extraHeaders;
@@ -18,6 +23,10 @@ class ComfyUiClient {
18
23
  this.pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
19
24
  this.clientId = (0, crypto_1.randomUUID)();
20
25
  }
26
+ /**
27
+ * Checks whether the ComfyUI server responds. Intended for diagnostics and
28
+ * tests; generation paths surface their own errors.
29
+ */
21
30
  async checkReachable() {
22
31
  try {
23
32
  const response = await fetch(`${this.baseUrl}/system_stats`, {
@@ -30,6 +39,10 @@ class ComfyUiClient {
30
39
  return false;
31
40
  }
32
41
  }
42
+ /**
43
+ * Uploads an image to the ComfyUI input folder.
44
+ * @returns The server-side name (and subfolder) to reference in a LoadImage node
45
+ */
33
46
  async uploadImage(data, filename) {
34
47
  const form = new FormData();
35
48
  form.append('image', new Blob([new Uint8Array(data)], { type: 'image/png' }), filename);
@@ -45,6 +58,10 @@ class ComfyUiClient {
45
58
  const result = await response.json();
46
59
  return { name: result.name ?? filename, subfolder: result.subfolder ?? '' };
47
60
  }
61
+ /**
62
+ * Queues a workflow (API-format graph) for execution.
63
+ * @returns The prompt id to poll for completion
64
+ */
48
65
  async queuePrompt(workflow) {
49
66
  const response = await fetch(`${this.baseUrl}/prompt`, {
50
67
  method: 'POST',
@@ -52,11 +69,13 @@ class ComfyUiClient {
52
69
  body: JSON.stringify({ prompt: workflow, client_id: this.clientId }),
53
70
  });
54
71
  if (!response.ok) {
72
+ // ComfyUI returns validation errors as JSON with node-level details
55
73
  let detail = '';
56
74
  try {
57
75
  detail = JSON.stringify(await response.json());
58
76
  }
59
77
  catch {
78
+ /* body was not JSON */
60
79
  }
61
80
  throw new Error(`ComfyUI rejected the workflow: ${response.status} ${response.statusText}${detail ? ` — ${detail}` : ''}`);
62
81
  }
@@ -66,6 +85,10 @@ class ComfyUiClient {
66
85
  }
67
86
  return result.prompt_id;
68
87
  }
88
+ /**
89
+ * Polls /history until the prompt completes, fails, or the timeout elapses.
90
+ * @returns The first output image reference from the completed workflow
91
+ */
69
92
  async waitForCompletion(promptId) {
70
93
  const deadline = Date.now() + this.timeoutMs;
71
94
  while (Date.now() < deadline) {
@@ -85,6 +108,7 @@ class ComfyUiClient {
85
108
  const image = this.findFirstOutputImage(entry);
86
109
  if (image)
87
110
  return image;
111
+ // Entry exists with success status but no image output — malformed workflow
88
112
  if (statusStr === 'success' || entry.status?.completed) {
89
113
  throw new Error('ComfyUI workflow completed but produced no image output. ' +
90
114
  'Check that the workflow template ends in a SaveImage node.');
@@ -95,6 +119,7 @@ class ComfyUiClient {
95
119
  throw new Error(`ComfyUI generation timed out after ${Math.round(this.timeoutMs / 1000)}s. ` +
96
120
  'This includes queue wait and model cold-start; raise COMFYUI_TIMEOUT_MS if the server is just slow.');
97
121
  }
122
+ /** Downloads a generated image. */
98
123
  async fetchOutput(ref) {
99
124
  const params = new URLSearchParams({
100
125
  filename: ref.filename,
@@ -11,9 +11,63 @@ export interface WorkflowValues {
11
11
  height: number;
12
12
  refImage?: string;
13
13
  }
14
+ /**
15
+ * Directory holding the shipped workflow templates. Lives under
16
+ * common/config so it is covered by the SDK's seedCommonData() copy of the
17
+ * config subdir. Reads BRIYAH_DATA_PATH directly (same convention as
18
+ * model_prices.ts) because listing happens with no user context.
19
+ */
14
20
  export declare function getCommonWorkflowsDir(): string;
21
+ /**
22
+ * Resolves a workflow template file for a pair name and variant, checking the
23
+ * user's override directory first, then the common directory.
24
+ * @returns Full path to the template file, or null when neither exists
25
+ */
15
26
  export declare function resolveWorkflowFile(pairName: string, variant: WorkflowVariant, userPaths?: UserPathsService): string | null;
27
+ /**
28
+ * Scans the common workflows directory for template pairs. A pair is any base
29
+ * name with at least one of `<name>.t2i.json` / `<name>.edit.json`.
30
+ * User-directory-only pairs are not listed (there is no user context at
31
+ * model-list time) but still resolve at generation time.
32
+ */
16
33
  export declare function listWorkflowPairs(): WorkflowPair[];
34
+ /**
35
+ * Loads and parses a workflow template file.
36
+ * @throws When the file cannot be read or parsed
37
+ */
17
38
  export declare function loadWorkflowTemplate(filePath: string): any;
39
+ /**
40
+ * Substitutes placeholder tokens in a parsed workflow template.
41
+ *
42
+ * Token semantics:
43
+ * - A string value that is exactly "{{seed}}", "{{width}}" or "{{height}}" is
44
+ * replaced with the corresponding number (ComfyUI validates input types).
45
+ * - A string value that is exactly "{{ref_image}}" is replaced with the
46
+ * uploaded reference filename.
47
+ * - Any other string has "{{prompt}}" (and "{{ref_image}}") occurrences
48
+ * substring-replaced, so templates may wrap the prompt, e.g.
49
+ * "masterpiece, {{prompt}}, cinematic".
50
+ *
51
+ * Unrecognized {{...}} tokens are warned about but left in place — ComfyUI's
52
+ * own validation will surface them if they matter.
53
+ *
54
+ * @returns A patched deep copy; the input object is not modified
55
+ */
18
56
  export declare function patchWorkflow(templateJson: any, values: WorkflowValues): any;
57
+ /**
58
+ * Extends an edit workflow with additional reference images by chaining
59
+ * ReferenceLatent nodes — the ComfyUI analog of the hosted Kontext multi
60
+ * endpoints, where the model conditions on each reference separately.
61
+ *
62
+ * Convention required of the template: exactly one ReferenceLatent node,
63
+ * whose latent comes from a VAEEncode fed (possibly via single-image
64
+ * processing nodes like FluxKontextImageScale) by a LoadImage. For each
65
+ * extra reference the LoadImage→...→VAEEncode chain is cloned and a new
66
+ * ReferenceLatent is appended to the conditioning chain; consumers of the
67
+ * original ReferenceLatent output are rewired to the last one.
68
+ *
69
+ * @param workflow A patched workflow (first reference already in place)
70
+ * @param extraRefImages Uploaded filenames for references 2..N, in order
71
+ * @returns A modified deep copy; the input workflow is not changed
72
+ */
19
73
  export declare function chainReferenceImages(workflow: any, extraRefImages: string[]): any;
@@ -43,6 +43,12 @@ const fs = __importStar(require("fs"));
43
43
  const path = __importStar(require("path"));
44
44
  const logger_1 = require("../../common/logger");
45
45
  const WORKFLOWS_SUBDIR = 'comfyui-workflows';
46
+ /**
47
+ * Directory holding the shipped workflow templates. Lives under
48
+ * common/config so it is covered by the SDK's seedCommonData() copy of the
49
+ * config subdir. Reads BRIYAH_DATA_PATH directly (same convention as
50
+ * model_prices.ts) because listing happens with no user context.
51
+ */
46
52
  function getCommonWorkflowsDir() {
47
53
  const dataDir = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
48
54
  return path.join(dataDir, 'common', 'config', WORKFLOWS_SUBDIR);
@@ -50,6 +56,11 @@ function getCommonWorkflowsDir() {
50
56
  function getUserWorkflowsDir(userPaths) {
51
57
  return path.join(userPaths.getUserDataDir(), WORKFLOWS_SUBDIR);
52
58
  }
59
+ /**
60
+ * Resolves a workflow template file for a pair name and variant, checking the
61
+ * user's override directory first, then the common directory.
62
+ * @returns Full path to the template file, or null when neither exists
63
+ */
53
64
  function resolveWorkflowFile(pairName, variant, userPaths) {
54
65
  const fileName = `${pairName}.${variant}.json`;
55
66
  const searchPaths = [];
@@ -64,6 +75,12 @@ function resolveWorkflowFile(pairName, variant, userPaths) {
64
75
  }
65
76
  return null;
66
77
  }
78
+ /**
79
+ * Scans the common workflows directory for template pairs. A pair is any base
80
+ * name with at least one of `<name>.t2i.json` / `<name>.edit.json`.
81
+ * User-directory-only pairs are not listed (there is no user context at
82
+ * model-list time) but still resolve at generation time.
83
+ */
67
84
  function listWorkflowPairs() {
68
85
  const dir = getCommonWorkflowsDir();
69
86
  if (!fs.existsSync(dir)) {
@@ -83,10 +100,31 @@ function listWorkflowPairs() {
83
100
  .map(([name, variants]) => ({ name, variants: [...variants] }))
84
101
  .sort((a, b) => a.name.localeCompare(b.name));
85
102
  }
103
+ /**
104
+ * Loads and parses a workflow template file.
105
+ * @throws When the file cannot be read or parsed
106
+ */
86
107
  function loadWorkflowTemplate(filePath) {
87
108
  const raw = fs.readFileSync(filePath, 'utf8');
88
109
  return JSON.parse(raw);
89
110
  }
111
+ /**
112
+ * Substitutes placeholder tokens in a parsed workflow template.
113
+ *
114
+ * Token semantics:
115
+ * - A string value that is exactly "{{seed}}", "{{width}}" or "{{height}}" is
116
+ * replaced with the corresponding number (ComfyUI validates input types).
117
+ * - A string value that is exactly "{{ref_image}}" is replaced with the
118
+ * uploaded reference filename.
119
+ * - Any other string has "{{prompt}}" (and "{{ref_image}}") occurrences
120
+ * substring-replaced, so templates may wrap the prompt, e.g.
121
+ * "masterpiece, {{prompt}}, cinematic".
122
+ *
123
+ * Unrecognized {{...}} tokens are warned about but left in place — ComfyUI's
124
+ * own validation will surface them if they matter.
125
+ *
126
+ * @returns A patched deep copy; the input object is not modified
127
+ */
90
128
  function patchWorkflow(templateJson, values) {
91
129
  const numericTokens = {
92
130
  '{{seed}}': values.seed,
@@ -126,6 +164,22 @@ function patchWorkflow(templateJson, values) {
126
164
  }
127
165
  return patched;
128
166
  }
167
+ /**
168
+ * Extends an edit workflow with additional reference images by chaining
169
+ * ReferenceLatent nodes — the ComfyUI analog of the hosted Kontext multi
170
+ * endpoints, where the model conditions on each reference separately.
171
+ *
172
+ * Convention required of the template: exactly one ReferenceLatent node,
173
+ * whose latent comes from a VAEEncode fed (possibly via single-image
174
+ * processing nodes like FluxKontextImageScale) by a LoadImage. For each
175
+ * extra reference the LoadImage→...→VAEEncode chain is cloned and a new
176
+ * ReferenceLatent is appended to the conditioning chain; consumers of the
177
+ * original ReferenceLatent output are rewired to the last one.
178
+ *
179
+ * @param workflow A patched workflow (first reference already in place)
180
+ * @param extraRefImages Uploaded filenames for references 2..N, in order
181
+ * @returns A modified deep copy; the input workflow is not changed
182
+ */
129
183
  function chainReferenceImages(workflow, extraRefImages) {
130
184
  if (extraRefImages.length === 0)
131
185
  return workflow;
@@ -146,6 +200,8 @@ function chainReferenceImages(workflow, extraRefImages) {
146
200
  throw new Error(`Expected the ReferenceLatent latent input to come from a VAEEncode node, ` +
147
201
  `found '${vaeEncode?.class_type}'.`);
148
202
  }
203
+ // Walk from VAEEncode.pixels back to the LoadImage, collecting any
204
+ // single-image processing nodes in between (e.g. FluxKontextImageScale).
149
205
  const middleChain = [];
150
206
  let cursor = String(vaeEncode.inputs.pixels?.[0]);
151
207
  while (result[cursor] && result[cursor].class_type !== 'LoadImage') {
@@ -160,7 +216,8 @@ function chainReferenceImages(workflow, extraRefImages) {
160
216
  if (!result[cursor]) {
161
217
  throw new Error('Could not find the LoadImage node feeding the ReferenceLatent chain.');
162
218
  }
163
- middleChain.reverse();
219
+ middleChain.reverse(); // now ordered LoadImage side → VAEEncode side
220
+ // Snapshot consumers of the original ReferenceLatent output before adding clones
164
221
  const consumers = [];
165
222
  for (const nodeId of Object.keys(result)) {
166
223
  const inputs = result[nodeId].inputs ?? {};
@@ -196,6 +253,7 @@ function chainReferenceImages(workflow, extraRefImages) {
196
253
  };
197
254
  lastRefLatentId = newRefLatentId;
198
255
  }
256
+ // Rewire the original consumers to the end of the chain
199
257
  for (const { nodeId, inputKey } of consumers) {
200
258
  result[nodeId].inputs[inputKey] = [lastRefLatentId, 0];
201
259
  }
@@ -7,8 +7,17 @@ export declare class ComfyUiAiService extends BaseAiService {
7
7
  getServiceName(): string;
8
8
  supportsImageGeneration(): boolean;
9
9
  requiresKnownModel(): boolean;
10
+ /**
11
+ * Model names are workflow-template pair names discovered on disk (one
12
+ * ModelInfo per `<name>.t2i.json`/`<name>.edit.json` pair in the common
13
+ * workflows directory). The ComfyUI server itself is not queried.
14
+ */
10
15
  fetchModelsFromApi(): Promise<ModelInfo[]>;
11
- textPrompt(_agent: Agent, _prompt: string, _jsonSchema?: any, _saveResponse?: boolean, _promptInstructions?: string, _cacheConfig?: any, _maxOutputChars?: number): Promise<any>;
16
+ textPrompt(_agent: Agent, _prompt: string, _jsonSchema?: any, // eslint-disable-line @typescript-eslint/no-unused-vars
17
+ _saveResponse?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars
18
+ _promptInstructions?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
19
+ _cacheConfig?: any, // eslint-disable-line @typescript-eslint/no-unused-vars
20
+ _maxOutputChars?: number): Promise<any>;
12
21
  generateImage(agent: Agent, prompt: string, imageProperties?: Record<string, any>): Promise<{
13
22
  artifactId?: string;
14
23
  error?: any;
@@ -17,10 +26,21 @@ export declare class ComfyUiAiService extends BaseAiService {
17
26
  artifactId?: string;
18
27
  error?: any;
19
28
  }>;
29
+ /**
30
+ * Balance gate, applied only when the image actually costs something.
31
+ * Self-hosted generation ships with centsPerImage 0 and stays usable at
32
+ * zero balance.
33
+ */
20
34
  private checkBalance;
21
35
  private prepareWorkflow;
22
36
  private runWorkflow;
23
37
  private computeImageCost;
38
+ /**
39
+ * Loads reference artifacts as buffers, failing loudly on any missing or
40
+ * non-image artifact. The base loadReferenceImages() silently drops
41
+ * missing entries, which would break the positional Image-N contract the
42
+ * story prompts rely on.
43
+ */
24
44
  private loadReferenceBuffers;
25
45
  private buildMultiRefPreamble;
26
46
  }
@@ -59,6 +59,11 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
59
59
  requiresKnownModel() {
60
60
  return false;
61
61
  }
62
+ /**
63
+ * Model names are workflow-template pair names discovered on disk (one
64
+ * ModelInfo per `<name>.t2i.json`/`<name>.edit.json` pair in the common
65
+ * workflows directory). The ComfyUI server itself is not queried.
66
+ */
62
67
  async fetchModelsFromApi() {
63
68
  return (0, comfyui_workflow_1.listWorkflowPairs)().map((pair) => ({
64
69
  name: pair.name,
@@ -67,7 +72,11 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
67
72
  service: 'ComfyUI',
68
73
  }));
69
74
  }
70
- async textPrompt(_agent, _prompt, _jsonSchema = null, _saveResponse = true, _promptInstructions = null, _cacheConfig = null, _maxOutputChars = 0) {
75
+ async textPrompt(_agent, _prompt, _jsonSchema = null, // eslint-disable-line @typescript-eslint/no-unused-vars
76
+ _saveResponse = true, // eslint-disable-line @typescript-eslint/no-unused-vars
77
+ _promptInstructions = null, // eslint-disable-line @typescript-eslint/no-unused-vars
78
+ _cacheConfig = null, // eslint-disable-line @typescript-eslint/no-unused-vars
79
+ _maxOutputChars = 0) {
71
80
  throw new Error('ComfyUI agents are image-generation only. Use generateImage/editImage, ' +
72
81
  'or choose a text provider for chat agents.');
73
82
  }
@@ -103,6 +112,10 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
103
112
  if (balanceError)
104
113
  throw balanceError;
105
114
  const references = this.loadReferenceBuffers(agent, referenceImageArtifactIds);
115
+ // Each reference is uploaded and conditioned on separately via a
116
+ // chained ReferenceLatent node — the ComfyUI analog of the hosted
117
+ // Kontext multi-image endpoints. Order is preserved so the
118
+ // prompt's "Image k" references map to the k-th upload.
106
119
  const refImages = [];
107
120
  for (const reference of references) {
108
121
  const uploaded = await this.client.uploadImage(reference.buffer, `briyah-ref-${(0, crypto_1.randomUUID)()}.png`);
@@ -129,6 +142,11 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
129
142
  return { error };
130
143
  }
131
144
  }
145
+ /**
146
+ * Balance gate, applied only when the image actually costs something.
147
+ * Self-hosted generation ships with centsPerImage 0 and stays usable at
148
+ * zero balance.
149
+ */
132
150
  checkBalance(agent, centsPerImage) {
133
151
  if (!centsPerImage || centsPerImage <= 0)
134
152
  return null;
@@ -166,6 +184,12 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
166
184
  agent.balanceService.decrementBalance(cost, 0);
167
185
  }
168
186
  }
187
+ /**
188
+ * Loads reference artifacts as buffers, failing loudly on any missing or
189
+ * non-image artifact. The base loadReferenceImages() silently drops
190
+ * missing entries, which would break the positional Image-N contract the
191
+ * story prompts rely on.
192
+ */
169
193
  loadReferenceBuffers(agent, artifactIds) {
170
194
  const references = [];
171
195
  for (const artifactId of artifactIds) {
@@ -8,10 +8,62 @@ export declare class DeepSeekAiService extends BaseAiService {
8
8
  getServiceName(): string;
9
9
  getModelPricePrefix(): string;
10
10
  fetchModelsFromApi(): Promise<ModelInfo[]>;
11
+ /**
12
+ * Adds a message to the agent history in the DeepSeek format
13
+ * @param agent The agent to add the message to
14
+ * @param message The formatted message to add
15
+ * @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
16
+ */
11
17
  addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean): void;
18
+ /**
19
+ * Salvages a response the schema rejected but Briyah can still use.
20
+ *
21
+ * This service is the only one that *validates* against the prompt's JSON
22
+ * schema: `generateObject` converts it to Zod and throws
23
+ * `AI_NoObjectGeneratedError` on any mismatch. Every other provider does a
24
+ * lenient `JSON.parse`, so a response that merely omits a field reaches
25
+ * `Room.parseAgentResponse` — which is itself defensive, requiring `name` only
26
+ * for an EXECUTE and moderating anything it cannot read.
27
+ *
28
+ * The schemas therefore claim fields are required that Briyah does not require —
29
+ * `name` has to stay in `required` because OpenAI rejects a schema whose
30
+ * `required` omits any property. A response that merely leaves one out is
31
+ * perfectly usable, and discarding it loses the agent's whole turn.
32
+ *
33
+ * So a validation failure is downgraded to a warning and the unvalidated object
34
+ * is used. A response that is not JSON at all still throws — `value` is absent
35
+ * and the text will not parse, which is a genuinely unusable answer rather than
36
+ * a strict-schema quibble.
37
+ * @param agent The agent whose turn this was, for the log line
38
+ * @param error The error `generateObject` threw
39
+ * @returns The salvaged object and the usage to bill, or null to rethrow
40
+ */
12
41
  private recoverUnvalidatedObject;
42
+ /**
43
+ * The most specific message inside a validation failure's cause chain.
44
+ *
45
+ * `AI_NoObjectGeneratedError` wraps `AI_TypeValidationError` wraps `ZodError`,
46
+ * and only the innermost one says which field was wrong — which is the whole
47
+ * value of the log line.
48
+ * @param error The thrown error
49
+ * @returns A one-line description, truncated
50
+ */
13
51
  private static describeValidationFailure;
14
52
  textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
53
+ /**
54
+ * Attaches a document to the agent or as a shared document
55
+ * @param agent The agent context (null for shared documents)
56
+ * @param fileName The name of the file
57
+ * @param fileData The file data as a Uint8Array
58
+ * @returns Promise with the result
59
+ */
15
60
  attachDocument(agent: Agent, fileName: string, fileData: Uint8Array): Promise<string>;
61
+ /**
62
+ * Compute the cost of a message with markup and cache-aware pricing for DeepSeek
63
+ * DeepSeek provides a 74-75% discount on cached tokens (no cache creation charge)
64
+ * Handles model name lookup with deepseek/ prefix if needed
65
+ * @param agent The agent making the request
66
+ * @param usage Usage object from the API response
67
+ */
16
68
  private computeMessageCost;
17
69
  }