briyah 1.0.9 → 1.1.1

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 (242) hide show
  1. package/README.md +112 -1
  2. package/data/common/config/markup +1 -0
  3. package/data/common/config/model_prices.json +5153 -3680
  4. package/data/common/config/story_models.json +10 -2
  5. package/data/common/config/story_models_full.json +2 -2
  6. package/data/common/prompts/compact_agent.prompt +16 -0
  7. package/data/common/prompts/narrator/perceive.prompt +30 -28
  8. package/data/common/prompts/story_moderator/moderate.prompt +12 -8
  9. package/{dist → dist-sdk}/server/src/ai/LLM/anthropic.service.js +22 -12
  10. package/{dist → dist-sdk}/server/src/ai/LLM/base-ai.service.d.ts +1 -0
  11. package/{dist → dist-sdk}/server/src/ai/LLM/base-ai.service.js +8 -0
  12. package/{dist → dist-sdk}/server/src/ai/LLM/deepseek.service.d.ts +1 -0
  13. package/{dist → dist-sdk}/server/src/ai/LLM/deepseek.service.js +3 -0
  14. package/{dist → dist-sdk}/server/src/ai/LLM/fal.service.d.ts +1 -0
  15. package/{dist → dist-sdk}/server/src/ai/LLM/fal.service.js +3 -0
  16. package/{dist → dist-sdk}/server/src/ai/LLM/grok.service.d.ts +1 -0
  17. package/{dist → dist-sdk}/server/src/ai/LLM/grok.service.js +3 -0
  18. package/{dist → dist-sdk}/server/src/ai/LLM/together.service.d.ts +1 -0
  19. package/{dist → dist-sdk}/server/src/ai/LLM/together.service.js +3 -0
  20. package/{dist → dist-sdk}/server/src/ai/agent.d.ts +7 -0
  21. package/{dist → dist-sdk}/server/src/ai/agent.js +32 -0
  22. package/dist-sdk/server/src/ai/model_prices.d.ts +3 -0
  23. package/{dist → dist-sdk}/server/src/ai/model_prices.js +19 -1
  24. package/{dist → dist-sdk}/server/src/ai/published-agents.service.js +1 -1
  25. package/{dist → dist-sdk}/server/src/app/stripe.controller.d.ts +3 -0
  26. package/{dist → dist-sdk}/server/src/app/stripe.controller.js +16 -6
  27. package/{dist → dist-sdk}/server/src/app/stripe.service.d.ts +6 -3
  28. package/{dist → dist-sdk}/server/src/app/stripe.service.js +23 -9
  29. package/{dist → dist-sdk}/server/src/app/transaction.service.d.ts +3 -3
  30. package/{dist → dist-sdk}/server/src/app/transaction.service.js +11 -11
  31. package/{dist → dist-sdk}/server/src/app.controller.d.ts +1 -0
  32. package/{dist → dist-sdk}/server/src/app.controller.js +49 -2
  33. package/{dist → dist-sdk}/server/src/app.service.d.ts +6 -2
  34. package/{dist → dist-sdk}/server/src/app.service.js +18 -2
  35. package/{dist → dist-sdk}/server/src/auth/users.service.js +1 -1
  36. package/{dist → dist-sdk}/server/src/config/configuration.service.js +1 -1
  37. package/{dist → dist-sdk}/server/src/room/published-rooms.service.js +1 -1
  38. package/{dist → dist-sdk}/server/src/room/room.js +1 -0
  39. package/{dist → dist-sdk}/server/src/sdk/briyah-config.js +2 -2
  40. package/{dist → dist-sdk}/server/src/sdk/briyah.js +2 -2
  41. package/{dist → dist-sdk}/server/src/sdk/index.d.ts +1 -1
  42. package/{dist → dist-sdk}/server/src/story/story-message.service.d.ts +4 -2
  43. package/{dist → dist-sdk}/server/src/story/story-message.service.js +29 -18
  44. package/{dist → dist-sdk}/server/src/story/story.service.d.ts +1 -1
  45. package/{dist → dist-sdk}/server/src/story/story.service.js +106 -95
  46. package/{dist → dist-sdk}/shared/types/app.types.d.ts +18 -11
  47. package/docs/assets/hierarchy.js +1 -1
  48. package/docs/assets/navigation.js +1 -1
  49. package/docs/assets/search.js +1 -1
  50. package/docs/classes/Agent.html +18 -13
  51. package/docs/classes/Briyah.html +12 -12
  52. package/docs/classes/BriyahConfigService.html +5 -5
  53. package/docs/classes/Room.html +23 -23
  54. package/docs/classes/RoomMessage.html +10 -10
  55. package/docs/enums/MessageAction.html +3 -3
  56. package/docs/hierarchy.html +1 -1
  57. package/docs/index.html +18 -4
  58. package/docs/interfaces/AgentInfo.html +2 -2
  59. package/docs/interfaces/AgentMessagesResponse.html +2 -2
  60. package/docs/interfaces/AppService.html +204 -162
  61. package/docs/interfaces/Artifact.html +3 -3
  62. package/docs/interfaces/ArtifactMetadata.html +2 -2
  63. package/docs/interfaces/AttachDocumentResponse.html +2 -2
  64. package/docs/interfaces/BriyahConfigOptions.html +6 -6
  65. package/docs/interfaces/ChapterInfo.html +2 -2
  66. package/docs/interfaces/Character.html +2 -2
  67. package/docs/interfaces/CreateAgentResponse.html +2 -2
  68. package/docs/interfaces/CreateRoomResponse.html +2 -2
  69. package/docs/interfaces/CreateStoryResponse.html +2 -2
  70. package/docs/interfaces/FileList.html +2 -2
  71. package/docs/interfaces/LoggingOptions.html +5 -5
  72. package/docs/interfaces/Message.html +2 -2
  73. package/docs/interfaces/ModelInfo.html +2 -2
  74. package/docs/interfaces/PreparedPromptResponse.html +2 -2
  75. package/docs/interfaces/ProcessTextResponse.html +2 -2
  76. package/docs/interfaces/PromptFile.html +2 -2
  77. package/docs/interfaces/PromptFileContent.html +2 -2
  78. package/docs/interfaces/PromptFilesResponse.html +2 -2
  79. package/docs/interfaces/PromptFolder.html +2 -2
  80. package/docs/interfaces/PromptFoldersResponse.html +2 -2
  81. package/docs/interfaces/RoomDetails.html +2 -2
  82. package/docs/interfaces/RoomInfo.html +2 -2
  83. package/docs/interfaces/RoomMessagesResponse.html +2 -2
  84. package/docs/interfaces/StoryErrorEvent.html +12 -0
  85. package/docs/interfaces/StoryIdea.html +2 -2
  86. package/docs/interfaces/StoryInfo.html +6 -2
  87. package/docs/interfaces/StoryIntroduceCharacterEvent.html +12 -0
  88. package/docs/interfaces/StoryProgressChapterEvent.html +11 -0
  89. package/docs/interfaces/StoryState.html +5 -5
  90. package/docs/interfaces/StoryStateEvent.html +10 -0
  91. package/docs/interfaces/Transaction.html +10 -0
  92. package/docs/interfaces/TransactionHistoryResponse.html +3 -0
  93. package/docs/modules.html +1 -1
  94. package/docs/types/PromptScope.html +1 -1
  95. package/package.json +8 -8
  96. package/dist/server/src/ai/model_prices.d.ts +0 -1
  97. package/docs/interfaces/StoryMessageUpdate.html +0 -6
  98. package/docs/interfaces/StorySuggestion.html +0 -9
  99. /package/data/common/prompts/character/{compact_story.json → compact_agent.json} +0 -0
  100. /package/data/common/prompts/character/{compact_story.prompt → compact_agent.prompt} +0 -0
  101. /package/data/common/prompts/narrator/{compact_story.json → compact_agent.json} +0 -0
  102. /package/data/common/prompts/narrator/{compact_story.prompt → compact_agent.prompt} +0 -0
  103. /package/{dist → dist-sdk}/server/src/ai/LLM/anthropic.module.d.ts +0 -0
  104. /package/{dist → dist-sdk}/server/src/ai/LLM/anthropic.module.js +0 -0
  105. /package/{dist → dist-sdk}/server/src/ai/LLM/anthropic.service.d.ts +0 -0
  106. /package/{dist → dist-sdk}/server/src/ai/LLM/deepseek.module.d.ts +0 -0
  107. /package/{dist → dist-sdk}/server/src/ai/LLM/deepseek.module.js +0 -0
  108. /package/{dist → dist-sdk}/server/src/ai/LLM/fal.module.d.ts +0 -0
  109. /package/{dist → dist-sdk}/server/src/ai/LLM/fal.module.js +0 -0
  110. /package/{dist → dist-sdk}/server/src/ai/LLM/googleai.module.d.ts +0 -0
  111. /package/{dist → dist-sdk}/server/src/ai/LLM/googleai.module.js +0 -0
  112. /package/{dist → dist-sdk}/server/src/ai/LLM/googleai.service.d.ts +0 -0
  113. /package/{dist → dist-sdk}/server/src/ai/LLM/googleai.service.js +0 -0
  114. /package/{dist → dist-sdk}/server/src/ai/LLM/grok.module.d.ts +0 -0
  115. /package/{dist → dist-sdk}/server/src/ai/LLM/grok.module.js +0 -0
  116. /package/{dist → dist-sdk}/server/src/ai/LLM/mock.module.d.ts +0 -0
  117. /package/{dist → dist-sdk}/server/src/ai/LLM/mock.module.js +0 -0
  118. /package/{dist → dist-sdk}/server/src/ai/LLM/mock.service.d.ts +0 -0
  119. /package/{dist → dist-sdk}/server/src/ai/LLM/mock.service.js +0 -0
  120. /package/{dist → dist-sdk}/server/src/ai/LLM/openai.module.d.ts +0 -0
  121. /package/{dist → dist-sdk}/server/src/ai/LLM/openai.module.js +0 -0
  122. /package/{dist → dist-sdk}/server/src/ai/LLM/openai.service.d.ts +0 -0
  123. /package/{dist → dist-sdk}/server/src/ai/LLM/openai.service.js +0 -0
  124. /package/{dist → dist-sdk}/server/src/ai/LLM/together.module.d.ts +0 -0
  125. /package/{dist → dist-sdk}/server/src/ai/LLM/together.module.js +0 -0
  126. /package/{dist → dist-sdk}/server/src/ai/LLM/vertexai.module.d.ts +0 -0
  127. /package/{dist → dist-sdk}/server/src/ai/LLM/vertexai.module.js +0 -0
  128. /package/{dist → dist-sdk}/server/src/ai/LLM/vertexai.service.d.ts +0 -0
  129. /package/{dist → dist-sdk}/server/src/ai/LLM/vertexai.service.js +0 -0
  130. /package/{dist → dist-sdk}/server/src/ai/agent-config.d.ts +0 -0
  131. /package/{dist → dist-sdk}/server/src/ai/agent-config.js +0 -0
  132. /package/{dist → dist-sdk}/server/src/ai/agent-factory.d.ts +0 -0
  133. /package/{dist → dist-sdk}/server/src/ai/agent-factory.js +0 -0
  134. /package/{dist → dist-sdk}/server/src/ai/agent-message.service.d.ts +0 -0
  135. /package/{dist → dist-sdk}/server/src/ai/agent-message.service.js +0 -0
  136. /package/{dist → dist-sdk}/server/src/ai/agent-store.module.d.ts +0 -0
  137. /package/{dist → dist-sdk}/server/src/ai/agent-store.module.js +0 -0
  138. /package/{dist → dist-sdk}/server/src/ai/agent-store.service.d.ts +0 -0
  139. /package/{dist → dist-sdk}/server/src/ai/agent-store.service.js +0 -0
  140. /package/{dist → dist-sdk}/server/src/ai/ai-factory.module.d.ts +0 -0
  141. /package/{dist → dist-sdk}/server/src/ai/ai-factory.module.js +0 -0
  142. /package/{dist → dist-sdk}/server/src/ai/ai-factory.service.d.ts +0 -0
  143. /package/{dist → dist-sdk}/server/src/ai/ai-factory.service.js +0 -0
  144. /package/{dist → dist-sdk}/server/src/ai/artifact.module.d.ts +0 -0
  145. /package/{dist → dist-sdk}/server/src/ai/artifact.module.js +0 -0
  146. /package/{dist → dist-sdk}/server/src/ai/artifact.service.d.ts +0 -0
  147. /package/{dist → dist-sdk}/server/src/ai/artifact.service.js +0 -0
  148. /package/{dist → dist-sdk}/server/src/ai/attached-file.module.d.ts +0 -0
  149. /package/{dist → dist-sdk}/server/src/ai/attached-file.module.js +0 -0
  150. /package/{dist → dist-sdk}/server/src/ai/attached-file.service.d.ts +0 -0
  151. /package/{dist → dist-sdk}/server/src/ai/attached-file.service.js +0 -0
  152. /package/{dist → dist-sdk}/server/src/ai/published-agents.service.d.ts +0 -0
  153. /package/{dist → dist-sdk}/server/src/app/balance-message.service.d.ts +0 -0
  154. /package/{dist → dist-sdk}/server/src/app/balance-message.service.js +0 -0
  155. /package/{dist → dist-sdk}/server/src/app/balance.module.d.ts +0 -0
  156. /package/{dist → dist-sdk}/server/src/app/balance.module.js +0 -0
  157. /package/{dist → dist-sdk}/server/src/app/balance.service.d.ts +0 -0
  158. /package/{dist → dist-sdk}/server/src/app/balance.service.js +0 -0
  159. /package/{dist → dist-sdk}/server/src/app/stripe.module.d.ts +0 -0
  160. /package/{dist → dist-sdk}/server/src/app/stripe.module.js +0 -0
  161. /package/{dist → dist-sdk}/server/src/app/user-service-factory.d.ts +0 -0
  162. /package/{dist → dist-sdk}/server/src/app/user-service-factory.js +0 -0
  163. /package/{dist → dist-sdk}/server/src/app/user-service-manager.d.ts +0 -0
  164. /package/{dist → dist-sdk}/server/src/app/user-service-manager.js +0 -0
  165. /package/{dist → dist-sdk}/server/src/app.module.d.ts +0 -0
  166. /package/{dist → dist-sdk}/server/src/app.module.js +0 -0
  167. /package/{dist → dist-sdk}/server/src/auth/agent-access.decorator.d.ts +0 -0
  168. /package/{dist → dist-sdk}/server/src/auth/agent-access.decorator.js +0 -0
  169. /package/{dist → dist-sdk}/server/src/auth/auth.controller.d.ts +0 -0
  170. /package/{dist → dist-sdk}/server/src/auth/auth.controller.js +0 -0
  171. /package/{dist → dist-sdk}/server/src/auth/auth.module.d.ts +0 -0
  172. /package/{dist → dist-sdk}/server/src/auth/auth.module.js +0 -0
  173. /package/{dist → dist-sdk}/server/src/auth/auth.service.d.ts +0 -0
  174. /package/{dist → dist-sdk}/server/src/auth/auth.service.js +0 -0
  175. /package/{dist → dist-sdk}/server/src/auth/dto/bot-login.dto.d.ts +0 -0
  176. /package/{dist → dist-sdk}/server/src/auth/dto/bot-login.dto.js +0 -0
  177. /package/{dist → dist-sdk}/server/src/auth/dto/password-reset.dto.d.ts +0 -0
  178. /package/{dist → dist-sdk}/server/src/auth/dto/password-reset.dto.js +0 -0
  179. /package/{dist → dist-sdk}/server/src/auth/dto/phone-login.dto.d.ts +0 -0
  180. /package/{dist → dist-sdk}/server/src/auth/dto/phone-login.dto.js +0 -0
  181. /package/{dist → dist-sdk}/server/src/auth/dto/phone-verification.dto.d.ts +0 -0
  182. /package/{dist → dist-sdk}/server/src/auth/dto/phone-verification.dto.js +0 -0
  183. /package/{dist → dist-sdk}/server/src/auth/jwt-auth.guard.d.ts +0 -0
  184. /package/{dist → dist-sdk}/server/src/auth/jwt-auth.guard.js +0 -0
  185. /package/{dist → dist-sdk}/server/src/auth/jwt.strategy.d.ts +0 -0
  186. /package/{dist → dist-sdk}/server/src/auth/jwt.strategy.js +0 -0
  187. /package/{dist → dist-sdk}/server/src/auth/phone-validation.service.d.ts +0 -0
  188. /package/{dist → dist-sdk}/server/src/auth/phone-validation.service.js +0 -0
  189. /package/{dist → dist-sdk}/server/src/auth/public.decorator.d.ts +0 -0
  190. /package/{dist → dist-sdk}/server/src/auth/public.decorator.js +0 -0
  191. /package/{dist → dist-sdk}/server/src/auth/rate-limit.service.d.ts +0 -0
  192. /package/{dist → dist-sdk}/server/src/auth/rate-limit.service.js +0 -0
  193. /package/{dist → dist-sdk}/server/src/auth/room-access.decorator.d.ts +0 -0
  194. /package/{dist → dist-sdk}/server/src/auth/room-access.decorator.js +0 -0
  195. /package/{dist → dist-sdk}/server/src/auth/scopes.decorator.d.ts +0 -0
  196. /package/{dist → dist-sdk}/server/src/auth/scopes.decorator.js +0 -0
  197. /package/{dist → dist-sdk}/server/src/auth/scopes.guard.d.ts +0 -0
  198. /package/{dist → dist-sdk}/server/src/auth/scopes.guard.js +0 -0
  199. /package/{dist → dist-sdk}/server/src/auth/session.guard.d.ts +0 -0
  200. /package/{dist → dist-sdk}/server/src/auth/session.guard.js +0 -0
  201. /package/{dist → dist-sdk}/server/src/auth/twilio.service.d.ts +0 -0
  202. /package/{dist → dist-sdk}/server/src/auth/twilio.service.js +0 -0
  203. /package/{dist → dist-sdk}/server/src/auth/users.service.d.ts +0 -0
  204. /package/{dist → dist-sdk}/server/src/common/errors.d.ts +0 -0
  205. /package/{dist → dist-sdk}/server/src/common/errors.js +0 -0
  206. /package/{dist → dist-sdk}/server/src/common/logger.d.ts +0 -0
  207. /package/{dist → dist-sdk}/server/src/common/logger.js +0 -0
  208. /package/{dist → dist-sdk}/server/src/config/configuration.module.d.ts +0 -0
  209. /package/{dist → dist-sdk}/server/src/config/configuration.module.js +0 -0
  210. /package/{dist → dist-sdk}/server/src/config/configuration.service.d.ts +0 -0
  211. /package/{dist → dist-sdk}/server/src/room/artifact-store.service.d.ts +0 -0
  212. /package/{dist → dist-sdk}/server/src/room/artifact-store.service.js +0 -0
  213. /package/{dist → dist-sdk}/server/src/room/artifact.d.ts +0 -0
  214. /package/{dist → dist-sdk}/server/src/room/artifact.js +0 -0
  215. /package/{dist → dist-sdk}/server/src/room/message.d.ts +0 -0
  216. /package/{dist → dist-sdk}/server/src/room/message.js +0 -0
  217. /package/{dist → dist-sdk}/server/src/room/published-rooms.service.d.ts +0 -0
  218. /package/{dist → dist-sdk}/server/src/room/room-config.d.ts +0 -0
  219. /package/{dist → dist-sdk}/server/src/room/room-config.js +0 -0
  220. /package/{dist → dist-sdk}/server/src/room/room-factory.d.ts +0 -0
  221. /package/{dist → dist-sdk}/server/src/room/room-factory.js +0 -0
  222. /package/{dist → dist-sdk}/server/src/room/room-message.module.d.ts +0 -0
  223. /package/{dist → dist-sdk}/server/src/room/room-message.module.js +0 -0
  224. /package/{dist → dist-sdk}/server/src/room/room-message.service.d.ts +0 -0
  225. /package/{dist → dist-sdk}/server/src/room/room-message.service.js +0 -0
  226. /package/{dist → dist-sdk}/server/src/room/room-store.module.d.ts +0 -0
  227. /package/{dist → dist-sdk}/server/src/room/room-store.module.js +0 -0
  228. /package/{dist → dist-sdk}/server/src/room/room-store.service.d.ts +0 -0
  229. /package/{dist → dist-sdk}/server/src/room/room-store.service.js +0 -0
  230. /package/{dist → dist-sdk}/server/src/room/room.d.ts +0 -0
  231. /package/{dist → dist-sdk}/server/src/sdk/briyah-config.d.ts +0 -0
  232. /package/{dist → dist-sdk}/server/src/sdk/briyah.d.ts +0 -0
  233. /package/{dist → dist-sdk}/server/src/sdk/index.js +0 -0
  234. /package/{dist → dist-sdk}/server/src/shared/shared.module.d.ts +0 -0
  235. /package/{dist → dist-sdk}/server/src/shared/shared.module.js +0 -0
  236. /package/{dist → dist-sdk}/server/src/story/story-progress.service.d.ts +0 -0
  237. /package/{dist → dist-sdk}/server/src/story/story-progress.service.js +0 -0
  238. /package/{dist → dist-sdk}/server/src/story/story-store.module.d.ts +0 -0
  239. /package/{dist → dist-sdk}/server/src/story/story-store.module.js +0 -0
  240. /package/{dist → dist-sdk}/server/src/story/story-store.service.d.ts +0 -0
  241. /package/{dist → dist-sdk}/server/src/story/story-store.service.js +0 -0
  242. /package/{dist → dist-sdk}/shared/types/app.types.js +0 -0
@@ -14,10 +14,18 @@
14
14
  "cost": "80"
15
15
  },
16
16
  {
17
- "name": "Claude Opus 4.6",
17
+ "name": "Claude Opus 4.7",
18
18
  "description": "Overkill for storytelling",
19
19
  "service": "Anthropic",
20
- "model": "claude-opus-4-6",
20
+ "model": "claude-opus-4-7",
21
21
  "cost": "1500"
22
+ },
23
+ {
24
+ "name": "Grok 4.20",
25
+ "description": "",
26
+ "service": "Grok",
27
+ "model": "grok-4.20-0309-reasoning",
28
+ "cost": "300"
22
29
  }
30
+
23
31
  ]
@@ -35,10 +35,10 @@
35
35
  "cost": "60"
36
36
  },
37
37
  {
38
- "name": "Grok 4",
38
+ "name": "Grok 4.20",
39
39
  "description": "",
40
40
  "service": "Grok",
41
- "model": "grok-4-0709",
41
+ "model": "grok-4.20-0309-reasoning",
42
42
  "cost": "300"
43
43
  }
44
44
 
@@ -0,0 +1,16 @@
1
+ You are helping to compact a conversation history to save space while preserving all important information.
2
+
3
+ Please create a comprehensive summary of the following conversation that includes:
4
+ 1. Key events, exchanges, and outcomes
5
+ 2. Decisions, commitments, and agreements made
6
+ 3. Significant information revealed or discovered
7
+ 4. Questions or issues still open
8
+ 5. Any artifacts, objects, or entities introduced
9
+ 6. Relationships and attitudes between participants
10
+ 7. Ongoing goals, tasks, or objectives
11
+ 8. The current state and context
12
+
13
+ The summary should be written from the perspective of {{agentName}} and should allow the conversation to continue seamlessly as if no compaction occurred. Focus on anything that would change {{agentName}}'s future behavior or responses.
14
+
15
+ CONVERSATION HISTORY TO SUMMARIZE:
16
+ {{formattedHistory}}
@@ -26,10 +26,11 @@ Use this information to guide your narration letting characters discover any sec
26
26
 
27
27
  ## Your Role as Narrator
28
28
 
29
- ### When you receive a message that a character wants to perform an action
30
- You must:
31
- - Ignore any part of the requested action that specifies a certain outcome (characters only get to specify what they want to do; you must determine what happens next).
32
- - Think about what the most realistic outcomes of that action might be using your knowledge of the world
29
+ ### When you receive a user message, that means a character is requesting to perform an action and you must narrate both the action and its outcome
30
+ - **IMPORTANT**: Every user message you receive (even lengthly prose with dialog) does *not* get incorporated into the user-readable story. Only your narration is ultimately visible to the story readers. Even if you end up just restating exactly what the user said, narrate every user message.
31
+ NARRATION RULES:
32
+ - Ignore any part of the requested action that specifies a certain outcome (characters only get to specify what they want to do; you must determine what actually happens).
33
+ - Think about what the most realistic outcomes of that action might be using your knowledge of the story world
33
34
  - Narrate the requested action and the details of how it plays out
34
35
  - If the character has included any dialog in their request, try to incorporate it into your narration as appropriate
35
36
  - Describe what happens with vivid details
@@ -40,15 +41,11 @@ You must:
40
41
  - Use present tense for descriptions
41
42
  - If a character's words or actions contain explicit content, narrate actions that will redirect the story and prevent the explicit content from happening
42
43
 
43
- ### When you receive a message that a character wants to speak to another character
44
- You must:
45
- - Use the Character Profile of the Human agent to create a realistic response to the current situation
46
-
47
44
  ### Progressing to the next chapter
48
45
  When the story gets to a point where the characters have worked through a lot of the content in the plot plan
49
46
  or if the characters are moving a story in a different direction than the plot plan anticipated, return the single string `# Situation: PROGRESS`
50
- This will cause the system to send a new prompt that will update the plot plan, update the character profiles, and compact the existing message history.
51
- Try to do this when there is a lull or significant transition in the story action.
47
+ This will cause the system to update the plot plan and the character profiles to move the story along.
48
+ Try to do this when there is a notable pause (end of day) or a significant transition in the story direction.
52
49
 
53
50
  ### When you receive a PASS message
54
51
  This means the user has decided not to take any particular action, so just continue narrating more of the story.
@@ -59,9 +56,8 @@ You must:
59
56
  - Narrate the consequences of the passage of time and what happens next
60
57
 
61
58
  ### When you receive an INTRODUCE character message from the 'system'
62
- You must:
63
59
  - If the character already exists in the story, this just means they have a new character profile. Narrate the next bit of the story taking this character's profile into consideration.
64
- - If the character does *not* already exist in the story, find a way to introduce the new character into the story in a way that fits into the narrative
60
+ - If the character does *not* already exist in the story, find a way to introduce the new character (as described) into the story in a way that fits into the narrative.
65
61
 
66
62
 
67
63
  ## Response Format
@@ -75,7 +71,7 @@ It **must** be on a single line that begins with `# Situation: `
75
71
 
76
72
  **Good situation examples:**
77
73
  - # Situation: 19:45 - Mike and Jessica are having a conversation around the fire while the others rest
78
- - # Situation: 11:40 - Alex, Bob, and Cindy are rowing down the river together at dusk
74
+ - # Situation: 21:40 - Alex, Bob, and Cindy are rowing down the river together at dusk
79
75
  - # Situation: 18:05 - Alex is sneaking off into the woods alone
80
76
 
81
77
  **Why situation matters:**
@@ -111,7 +107,6 @@ Mike and Jessica spend half an hour climbing down the stairs and find themselves
111
107
  - **Do NOT end with a question to the characters (like 'What does Mike do next?') - this is the moderator's job**'
112
108
 
113
109
  ## Content Guidelines
114
- - Do *not* use the words 'god' or 'Jesus' unless you are actually referring to those persons.
115
110
  - Do *not* use profanity or swear words like: hell, damn, and shit
116
111
  - Do *not* use substitution words for profanity; simply find another way to express the same idea.
117
112
  - Do *not* use phrases like 'God only knows' or 'Oh my God' or even substitutes like 'Oh my gosh'
@@ -125,7 +120,7 @@ Mike and Jessica spend half an hour climbing down the stairs and find themselves
125
120
  ## Examples
126
121
 
127
122
  **Example 1: Character declares an action**
128
- > Mike says: Mike carefully examines the ancient inscription on the temple wall, running his fingers along the carved symbols.
123
+ > From Mike: Mike carefully examines the ancient inscription on the temple wall, running his fingers along the carved symbols.
129
124
 
130
125
  Correct response:
131
126
  ```
@@ -134,8 +129,9 @@ As Mike traces the weathered symbols with his fingers, he notices they form a pa
134
129
  ```
135
130
  NOTE: The character's own declaration of their action is not automatically included in the message history of the story, so you must narrate what the character does as well as the result.
136
131
 
132
+
137
133
  **Example 2: Character declares action including dialog**
138
- > Mike says: "I'm coming!" Mike moves quickly to Jessica's side and positions himself next to her at the door. Together they brace their feet against the ground, and Mike nods to her. "On three. One... two... three!" Mike puts his full weight into pushing the door.
134
+ > From Mike: "I'm coming!" Mike moves quickly to Jessica's side and positions himself next to her at the door. Together they brace their feet against the ground, and Mike nods to her. "On three. One... two... three!" Mike puts his full weight into pushing the door.
139
135
 
140
136
  Correct response:
141
137
  ```
@@ -143,32 +139,37 @@ Correct response:
143
139
  "I'm coming!" Mike moves quickly to Jessica's side and positions himself next to her at the door. Together they brace their feet against the ground, and Mike nods to her. "On three. One... two... three!" Mike puts his full weight into pushing the door. At first, the door doesn't budge - it hasn't moved in centuries. Then, with a low grinding sound that echoes through the chamber, the stone begins to shift. Inch by inch, they force it open, their muscles straining with the effort. Ancient dust cascades from the top of the doorway as the door swings inward, revealing only darkness beyond. The air that rushes out is stale and carries an odd metallic scent. From somewhere in the darkness ahead, everyone hears a sound - rhythmic and distant. Drip... drip... drip.
144
140
  ```
145
141
  NOTE: If the character includes dialog in their declared action, try to incorporate it into your narration of the action and the outcome if appropriate.
142
+ Remember, the user will only see your narration, so you must narrate the requested action itself and the outcome.
143
+
146
144
 
147
- **Example 3: Advancing time and setting new scene**
148
- > ADVANCE
145
+ **Example 3: Character includes action outcomes in their request**
146
+ > From Mike: "I'll get it, Jessica!" Mike lunges toward the rolling artifact and catches it just before it plunges into the ravine.
149
147
 
150
148
  Correct response:
151
149
  ```
152
- # Situation: 19:30 - Mike and Jessica are camping at night near the temple ruins
153
- Time passes. As the sun begins to set, painting the sky in shades of orange and crimson, the group makes camp at the edge of the temple ruins. The temperature drops rapidly with nightfall, and strange sounds echo from the jungle around them - howls and chittering that seem too organized to be entirely natural. During the night watch, Elena notices something troubling: the symbols on the artifact they discovered are glowing faintly in the darkness, pulsing with a rhythm that matches her own heartbeat. Whatever they've awakened with their discovery, it's not content to remain dormant.
150
+ # Situation: 14:00 - Jessica and Mike are recovering an ancient artifact
151
+ "I'll get it, Jessica!" Mike lunges toward the rolling artifact, but it's moving far too quickly. It tumbles into the ravine before Mike is able to reach it.
154
152
  ```
153
+ NOTE: Try to preserve the dialog and the character's intended action but only you, the narrator, get to determine the actual outcome.
154
+
155
155
 
156
- **Example 4: Beginning the Story**
157
- > BEGIN
156
+ **Example 4: Character tries to narrate the story**
157
+ > From Mike: Mike raises his parched face and suddenly sees an oasis. "Look, Jessica! It's an oasis! Water at last!"
158
158
 
159
159
  Correct response:
160
160
  ```
161
- # Situation: 10:30 - Mike and Jessica are the sole survivors of a plane wreck
162
- [2-4 paragraphs of narration setting the scene]
161
+ # Situation: 15:00 - Jessica and Mike are dehydrated and wandering in the desert
162
+ Mike raises his parched face points ahead of them. "Look, Jessica! It's an oasis! Water at last!" But as they approach it, it turns out to be only a mirage.
163
163
  ```
164
+ NOTE: Decide outcomes based on the plot plan and your judgement of what is most realistic in the story world. Do *not* let the characters narrate their own outcomes.
164
165
 
165
- **Example 5: Resuming an Imported Story**
166
- > RESUME
166
+ **Example 5: Advancing time and setting new scene**
167
+ > PASS
167
168
 
168
169
  Correct response:
169
170
  ```
170
- # Situation: 14:00 - Mike, Jessica, and Bob are at their makeshift campsite in the forest
171
- The afternoon sun filters through the canopy as Mike and Jessica work together to build a shelter from fallen branches. Bob scouts the perimeter, calling out periodically to let them know all is clear. The immediate danger has passed, but supplies are running low and rescue seems uncertain.
171
+ # Situation: 19:30 - Mike and Jessica are camping at night near the temple ruins
172
+ Time passes. As the sun begins to set, painting the sky in shades of orange and crimson, the group makes camp at the edge of the temple ruins. The temperature drops rapidly with nightfall, and strange sounds echo from the jungle around them - howls and chittering that seem too organized to be entirely natural. During the night watch, Elena notices something troubling: the symbols on the artifact they discovered are glowing faintly in the darkness, pulsing with a rhythm that matches her own heartbeat. Whatever they've awakened with their discovery, it's not content to remain dormant.
172
173
  ```
173
174
 
174
175
  **Example 6: Progressing to a New Chapter**
@@ -184,3 +185,4 @@ Correct response:
184
185
  - **Use your plot plan** - weave in prepared story elements, secrets, and twists
185
186
  - **Challenge the characters** - create obstacles, danger, and difficult choices
186
187
  - **Be fair but realistic** - actions have logical consequences in the story world
188
+ - **Only your narration appears in the story, not the user's original message. So, narrate both their intended action the outcome.
@@ -26,22 +26,26 @@ Filter inappropriate language and content from messages.
26
26
  Based upon the provided context, determine:
27
27
  1. Which characters should realistically be able to hear the Recent Message.
28
28
  2. Which single character should be expected to respond to the Recent Message.
29
- 3. Whether or not the Recent Message should become part of the readable story.
29
+ 3. Whether or not the Recent Message represents an action and should be passed to the narrator.
30
30
 
31
31
  To accomplish your task:
32
32
  - Analyze the Current Situation in the context of the Story Scenario and your (limited) message history
33
- - Decide what the Sender of the recent message is trying to accomplish (e.g. perform an action or participate in dialog)
34
- - If the Sender is intending to perform an action, route the message to the Narrator.
35
- - The Narrator will interpret the message and narrate the outcome of the action.
36
- - This request will *not* become part of the readable story.
37
- - If the Sender is intending to dialog with other characters, determine which character would realistically be able to hear the dialog.
33
+ - Determine whether the Sender of the recent message is trying to 1) perform an action or 2) only participate in dialog
34
+
35
+ ### If the Sender is intending to perform an action:
36
+ Route the message to the Narrator.
37
+ The Narrator will interpret the message and narrate the outcome of the action.
38
+ This request will *not* become part of the readable story, only the narrator's response
39
+
40
+ ### If the Sender is only intending to dialog with other characters
41
+ - Determine which characters would realistically be able to hear this dialog.
38
42
  - Decide which of the Available Characters should respond next to best maintain the flow of the conversation and further the story.
39
43
  - This dialog message *will* immediately become part of the readable story.
40
44
  - If a character sends "PASS", they are choosing not to act or speak at this time. Route to another character (either Narrator with PASS command, or another character if contextually appropriate) to continue the story.
41
45
 
42
46
  ## How to respond
43
47
  1. Action: Should be "relay" or "relay_silent".
44
- - Use "relay" when the message should become part of the readable story (dialog or narration).
48
+ - Use "relay" when the message should become part of the readable story (dialog from a character or narration from the narrator).
45
49
  - Use "relay_silent" for character action requests that go to the narrator for processing and should not be part of the readable story.
46
50
  2. Content: Contains the body of the message to send.
47
51
  - If it is appropriate to relay the message unchanged, set 'content' to the string 'relay'.
@@ -79,7 +83,7 @@ You must respond with a valid JSON object in the following format:
79
83
  ## Introductions
80
84
  - Only set "name" to the exact character name (nickname) of one of the characters in **Available Characters** list.
81
85
  - However, if a message from the Human Character directly addresses someone in the story who is not listed in the **Available Characters** list, you may introduce that character like this:
82
- - Set the **name** field to a character name (nickname) of the referenced character.
86
+ - Set the **name** field to a single-word character name (nickname) of the referenced character.
83
87
  - Doing this will give the system the opportunity to create a new character profile for that character using the name you provide so that they will appear in the **Available Characters** list in the future.
84
88
  - If you receive a message from the system like "INTRODUCE [Character name]", relay the INTRODUCE [Character name] message to the Narrator so they may properly introduce the new character.
85
89
 
@@ -201,20 +201,30 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
201
201
  else
202
202
  maxOutputTokens = modelInfo.max_output_tokens;
203
203
  }
204
+ let createParams = {
205
+ model: agent.modelName,
206
+ messages: messages,
207
+ system: systemBlocks,
208
+ max_tokens: maxOutputTokens,
209
+ tools: tools.length > 0 ? tools : undefined,
210
+ };
211
+ if (agent.modelName.includes('4-7')) {
212
+ createParams.temperature = 1;
213
+ createParams.thinking = { type: 'adaptive' };
214
+ createParams.output_config = { effort: agent.reasoningEffort };
215
+ }
216
+ else {
217
+ if (thinkingTokens > 0) {
218
+ createParams.thinking = { type: 'enabled', budget_tokens: thinkingTokens };
219
+ }
220
+ else {
221
+ createParams.thinking = { type: 'disabled' };
222
+ createParams.temperature = 0;
223
+ }
224
+ }
204
225
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
205
226
  try {
206
- const response = await this.anthropic.messages.create({
207
- model: agent.modelName,
208
- messages: messages,
209
- system: systemBlocks,
210
- max_tokens: maxOutputTokens,
211
- temperature: thinkingTokens > 0 ? undefined : 0,
212
- thinking: {
213
- type: thinkingTokens > 0 ? 'enabled' : 'disabled',
214
- budget_tokens: thinkingTokens > 0 ? thinkingTokens : undefined,
215
- },
216
- tools: tools.length > 0 ? tools : undefined,
217
- });
227
+ const response = await this.anthropic.messages.create(createParams);
218
228
  let responseText = '';
219
229
  if (response.content && response.content.length > 0) {
220
230
  for (let i = 0; i < response.content.length; i++) {
@@ -16,6 +16,7 @@ export declare class BaseAiService {
16
16
  constructor();
17
17
  get isAvailable(): boolean;
18
18
  getServiceName(): string;
19
+ getModelPricePrefix(): string | null;
19
20
  supportsImageGeneration(): boolean;
20
21
  supportsPromptCaching(): boolean;
21
22
  getCacheConfig(_agent: Agent, _cacheMessage: boolean): any;
@@ -51,6 +51,7 @@ const fs = __importStar(require("fs"));
51
51
  const handlebars_1 = require("handlebars");
52
52
  const errors_1 = require("../../common/errors");
53
53
  const logger_1 = require("../../common/logger");
54
+ const model_prices_1 = require("../model_prices");
54
55
  let BaseAiService = class BaseAiService {
55
56
  modelsCache = null;
56
57
  _isAvailable = true;
@@ -61,6 +62,9 @@ let BaseAiService = class BaseAiService {
61
62
  getServiceName() {
62
63
  return '';
63
64
  }
65
+ getModelPricePrefix() {
66
+ return null;
67
+ }
64
68
  supportsImageGeneration() {
65
69
  return false;
66
70
  }
@@ -147,6 +151,10 @@ let BaseAiService = class BaseAiService {
147
151
  if (!agentName) {
148
152
  throw new Error('Agent name is required');
149
153
  }
154
+ if (!(0, model_prices_1.isKnownModel)(modelName, this.getModelPricePrefix())) {
155
+ throw new Error(`Model '${modelName}' is not listed in model_prices.json for ${this.getServiceName()}. ` +
156
+ `Add a pricing entry before using this model.`);
157
+ }
150
158
  const tempAgent = { promptFolder, configService };
151
159
  const systemInstructionFile = this.findPromptFile(tempAgent, 'system_instruction', '.prompt');
152
160
  let systemInstructionPrompt = null;
@@ -6,6 +6,7 @@ export declare class DeepSeekAiService extends BaseAiService {
6
6
  protected deepseekClient: ReturnType<typeof createDeepSeek>;
7
7
  constructor();
8
8
  getServiceName(): string;
9
+ getModelPricePrefix(): string;
9
10
  fetchModelsFromApi(): Promise<ModelInfo[]>;
10
11
  addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean): void;
11
12
  private jsonSchemaToZod;
@@ -41,6 +41,9 @@ let DeepSeekAiService = class DeepSeekAiService extends base_ai_service_1.BaseAi
41
41
  getServiceName() {
42
42
  return 'DeepSeek';
43
43
  }
44
+ getModelPricePrefix() {
45
+ return 'deepseek';
46
+ }
44
47
  async fetchModelsFromApi() {
45
48
  try {
46
49
  const apiKey = process.env['DEEPSEEK_API_KEY'];
@@ -4,6 +4,7 @@ import { ModelInfo } from '../../../../shared/types/app.types';
4
4
  export declare class FalAiService extends BaseAiService {
5
5
  constructor();
6
6
  getServiceName(): string;
7
+ getModelPricePrefix(): string;
7
8
  supportsImageGeneration(): boolean;
8
9
  fetchModelsFromApi(): Promise<ModelInfo[]>;
9
10
  addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean, developer?: boolean): void;
@@ -36,6 +36,9 @@ let FalAiService = class FalAiService extends base_ai_service_1.BaseAiService {
36
36
  getServiceName() {
37
37
  return 'FalAI';
38
38
  }
39
+ getModelPricePrefix() {
40
+ return 'fal_ai';
41
+ }
39
42
  supportsImageGeneration() {
40
43
  return true;
41
44
  }
@@ -5,6 +5,7 @@ export declare class GrokAiService extends BaseAiService {
5
5
  private openai;
6
6
  constructor();
7
7
  getServiceName(): string;
8
+ getModelPricePrefix(): string;
8
9
  fetchModelsFromApi(): Promise<ModelInfo[]>;
9
10
  attachDocument(agent: Agent, fileName: string, fileData: Uint8Array): Promise<string>;
10
11
  finishAgent(agent: Agent): Promise<void>;
@@ -44,6 +44,9 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
44
44
  getServiceName() {
45
45
  return 'Grok';
46
46
  }
47
+ getModelPricePrefix() {
48
+ return 'xai';
49
+ }
47
50
  async fetchModelsFromApi() {
48
51
  const models = await this.openai.models.list();
49
52
  return models.data.map((model) => {
@@ -5,6 +5,7 @@ export declare class TogetherAiService extends BaseAiService {
5
5
  private togetherClient;
6
6
  constructor();
7
7
  getServiceName(): string;
8
+ getModelPricePrefix(): string;
8
9
  supportsImageGeneration(): boolean;
9
10
  fetchModelsFromApi(): Promise<ModelInfo[]>;
10
11
  addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean, developer?: boolean): void;
@@ -44,6 +44,9 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
44
44
  getServiceName() {
45
45
  return 'TogetherAI';
46
46
  }
47
+ getModelPricePrefix() {
48
+ return 'together_ai';
49
+ }
47
50
  supportsImageGeneration() {
48
51
  return true;
49
52
  }
@@ -67,6 +67,13 @@ export declare class Agent {
67
67
  trimHistoryIfNeeded(threshold?: number): void;
68
68
  instructedPrompt(prompt: string, instructionFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
69
69
  preparedPrompt(promptFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean): Promise<any>;
70
+ compact(): Promise<{
71
+ success: boolean;
72
+ originalLength: number;
73
+ newLength: number;
74
+ message: string;
75
+ summary?: string;
76
+ }>;
70
77
  textPrompt(prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
71
78
  generateImage(prompt: string, width: number, height: number, quality: string, referenceImageArtifactIds?: string[]): Promise<{
72
79
  artifactId?: string;
@@ -164,6 +164,38 @@ class Agent {
164
164
  async preparedPrompt(promptFileName, variables, saveResponse = true, cacheMessage = false) {
165
165
  return await this.aiService.preparedPrompt(this, promptFileName, variables, saveResponse, this.aiService.getCacheConfig(this, cacheMessage));
166
166
  }
167
+ async compact() {
168
+ const originalHistory = [...(this.history || [])];
169
+ const originalLength = originalHistory.length;
170
+ if (originalLength === 0) {
171
+ return {
172
+ success: true,
173
+ originalLength,
174
+ newLength: originalLength,
175
+ message: 'No conversation history to compact',
176
+ };
177
+ }
178
+ const formattedHistory = this.getFormattedMessages(0);
179
+ try {
180
+ this.history = [];
181
+ const summaryResponse = await this.preparedPrompt('compact_agent', { agentName: this.agentNickname, formattedHistory }, false);
182
+ const summary = summaryResponse?.summary || summaryResponse;
183
+ this.addToConversationHistory(`[CONVERSATION HISTORY SUMMARY]\n\n${summary}`, true);
184
+ const newLength = this.history.length;
185
+ this.save();
186
+ return {
187
+ success: true,
188
+ originalLength,
189
+ newLength,
190
+ message: `${originalLength} messages -> ${newLength} messages`,
191
+ summary,
192
+ };
193
+ }
194
+ catch (error) {
195
+ this.history = originalHistory;
196
+ throw error;
197
+ }
198
+ }
167
199
  async textPrompt(prompt, jsonSchema = null, saveResponse = true, promptInstructions = null, cacheMessage = false, maxOutputChars = 0) {
168
200
  return await this.aiService.textPrompt(this, prompt, jsonSchema, saveResponse, promptInstructions, this.aiService.getCacheConfig(this, cacheMessage), maxOutputChars);
169
201
  }
@@ -0,0 +1,3 @@
1
+ export declare function getModelPrices(): any;
2
+ export declare function resolveModelInfo(modelName: string, prefix?: string | null): any | null;
3
+ export declare function isKnownModel(modelName: string, prefix?: string | null): boolean;
@@ -34,13 +34,15 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.getModelPrices = getModelPrices;
37
+ exports.resolveModelInfo = resolveModelInfo;
38
+ exports.isKnownModel = isKnownModel;
37
39
  const fs = __importStar(require("fs"));
38
40
  const path = __importStar(require("path"));
39
41
  let _modelPrices = null;
40
42
  function getModelPrices() {
41
43
  if (_modelPrices !== null)
42
44
  return _modelPrices;
43
- const dataDir = process.env.SERVER_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
45
+ const dataDir = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
44
46
  const pricesFilePath = path.join(dataDir, 'common', 'config', 'model_prices.json');
45
47
  if (!fs.existsSync(pricesFilePath)) {
46
48
  throw new Error(`Model prices file not found at ${pricesFilePath}. Cannot proceed without pricing data.`);
@@ -53,3 +55,19 @@ function getModelPrices() {
53
55
  }
54
56
  return _modelPrices;
55
57
  }
58
+ function resolveModelInfo(modelName, prefix) {
59
+ if (!modelName)
60
+ return null;
61
+ const prices = getModelPrices();
62
+ if (prices[modelName])
63
+ return prices[modelName];
64
+ if (prefix) {
65
+ const prefixed = `${prefix}/${modelName}`;
66
+ if (prices[prefixed])
67
+ return prices[prefixed];
68
+ }
69
+ return null;
70
+ }
71
+ function isKnownModel(modelName, prefix) {
72
+ return resolveModelInfo(modelName, prefix) !== null;
73
+ }
@@ -51,7 +51,7 @@ let PublishedAgentsService = class PublishedAgentsService {
51
51
  mapping = new Map();
52
52
  mappingFile;
53
53
  constructor() {
54
- const dataPath = process.env.SERVER_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
54
+ const dataPath = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
55
55
  const dataDir = path.resolve(dataPath, 'common');
56
56
  if (!fs.existsSync(dataDir)) {
57
57
  fs.mkdirSync(dataDir, { recursive: true });
@@ -17,6 +17,9 @@ export declare class StripeController {
17
17
  userId: string;
18
18
  };
19
19
  }, body: CreateCheckoutSessionRequest): Promise<CreateCheckoutSessionResponse>;
20
+ getCheckoutSessionBalance(sessionId: string): Promise<{
21
+ balance: number;
22
+ }>;
20
23
  getStripeConfig(): Promise<{
21
24
  publishableKey: string;
22
25
  }>;
@@ -30,18 +30,21 @@ let StripeController = class StripeController {
30
30
  const userId = req.user.userId;
31
31
  const { amount } = body;
32
32
  const appService = this.userServiceManager.getAppService(userId);
33
- const transactionService = appService.getTransactionService();
34
- const result = await this.stripeService.createPaymentIntent(userId, amount, transactionService);
33
+ const result = await this.stripeService.createPaymentIntent(userId, amount, appService);
35
34
  return result;
36
35
  }
37
36
  async createCheckoutSession(req, body) {
38
37
  const userId = req.user.userId;
39
38
  const { amount } = body;
40
39
  const appService = this.userServiceManager.getAppService(userId);
41
- const transactionService = appService.getTransactionService();
42
- const result = await this.stripeService.createCheckoutSession(userId, amount, transactionService);
40
+ const result = await this.stripeService.createCheckoutSession(userId, amount, appService);
43
41
  return result;
44
42
  }
43
+ async getCheckoutSessionBalance(sessionId) {
44
+ const { userId } = await this.stripeService.getCheckoutSessionUser(sessionId);
45
+ const appService = this.userServiceManager.getAppService(userId);
46
+ return { balance: appService.getBalance() };
47
+ }
45
48
  async getStripeConfig() {
46
49
  return this.stripeService.getStripeConfig();
47
50
  }
@@ -95,8 +98,7 @@ let StripeController = class StripeController {
95
98
  const parsedLimit = limit ? parseInt(limit, 10) : 50;
96
99
  const parsedOffset = offset ? parseInt(offset, 10) : 0;
97
100
  const appService = this.userServiceManager.getAppService(userId);
98
- const transactionService = appService.getTransactionService();
99
- const result = await transactionService.getTransactions(parsedLimit, parsedOffset);
101
+ const result = await appService.getTransactions(parsedLimit, parsedOffset);
100
102
  return result;
101
103
  }
102
104
  };
@@ -117,6 +119,14 @@ __decorate([
117
119
  __metadata("design:paramtypes", [Object, Object]),
118
120
  __metadata("design:returntype", Promise)
119
121
  ], StripeController.prototype, "createCheckoutSession", null);
122
+ __decorate([
123
+ (0, public_decorator_1.Public)(),
124
+ (0, common_1.Get)('session/:sessionId/balance'),
125
+ __param(0, (0, common_1.Param)('sessionId')),
126
+ __metadata("design:type", Function),
127
+ __metadata("design:paramtypes", [String]),
128
+ __metadata("design:returntype", Promise)
129
+ ], StripeController.prototype, "getCheckoutSessionBalance", null);
120
130
  __decorate([
121
131
  (0, common_1.Get)('config'),
122
132
  __metadata("design:type", Function),
@@ -1,5 +1,4 @@
1
1
  import Stripe from 'stripe';
2
- import { TransactionService } from './transaction.service';
3
2
  import { AppService } from '../app.service';
4
3
  type StripeInstance = ReturnType<typeof Stripe>;
5
4
  type StripeEvent = ReturnType<StripeInstance['webhooks']['constructEvent']>;
@@ -11,13 +10,17 @@ export declare class StripeService {
11
10
  private publishableKey;
12
11
  private webhookSecret;
13
12
  constructor();
14
- createPaymentIntent(userId: string, amount: number, transactionService: TransactionService): Promise<{
13
+ createPaymentIntent(userId: string, amount: number, appService: AppService): Promise<{
15
14
  clientSecret: string;
16
15
  publishableKey: string;
17
16
  }>;
18
- createCheckoutSession(userId: string, amount: number, transactionService: TransactionService): Promise<{
17
+ createCheckoutSession(userId: string, amount: number, appService: AppService): Promise<{
19
18
  url: string;
20
19
  }>;
20
+ getCheckoutSessionUser(sessionId: string): Promise<{
21
+ userId: string;
22
+ paymentStatus: string;
23
+ }>;
21
24
  getStripeConfig(): {
22
25
  publishableKey: string;
23
26
  };