briyah 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/.prettierrc +7 -7
  2. package/README.md +394 -0
  3. package/dist/server/src/ai/LLM/deepseek.service.js +1 -1
  4. package/dist/server/src/room/artifact-store.service.js +4 -4
  5. package/eslint.config.js +29 -29
  6. package/package.json +3 -2
  7. package/dist/ai/LLM/anthropic.module.d.ts +0 -2
  8. package/dist/ai/LLM/anthropic.module.js +0 -21
  9. package/dist/ai/LLM/anthropic.service.d.ts +0 -27
  10. package/dist/ai/LLM/anthropic.service.js +0 -329
  11. package/dist/ai/LLM/base-ai.service.d.ts +0 -45
  12. package/dist/ai/LLM/base-ai.service.js +0 -409
  13. package/dist/ai/LLM/deepseek.module.d.ts +0 -2
  14. package/dist/ai/LLM/deepseek.module.js +0 -21
  15. package/dist/ai/LLM/deepseek.service.d.ts +0 -15
  16. package/dist/ai/LLM/deepseek.service.js +0 -279
  17. package/dist/ai/LLM/fal.module.d.ts +0 -2
  18. package/dist/ai/LLM/fal.module.js +0 -21
  19. package/dist/ai/LLM/fal.service.d.ts +0 -17
  20. package/dist/ai/LLM/fal.service.js +0 -314
  21. package/dist/ai/LLM/googleai.module.d.ts +0 -2
  22. package/dist/ai/LLM/googleai.module.js +0 -21
  23. package/dist/ai/LLM/googleai.service.d.ts +0 -20
  24. package/dist/ai/LLM/googleai.service.js +0 -271
  25. package/dist/ai/LLM/grok.module.d.ts +0 -2
  26. package/dist/ai/LLM/grok.module.js +0 -21
  27. package/dist/ai/LLM/grok.service.d.ts +0 -14
  28. package/dist/ai/LLM/grok.service.js +0 -263
  29. package/dist/ai/LLM/mock.module.d.ts +0 -2
  30. package/dist/ai/LLM/mock.module.js +0 -21
  31. package/dist/ai/LLM/mock.service.d.ts +0 -13
  32. package/dist/ai/LLM/mock.service.js +0 -194
  33. package/dist/ai/LLM/openai.module.d.ts +0 -2
  34. package/dist/ai/LLM/openai.module.js +0 -21
  35. package/dist/ai/LLM/openai.service.d.ts +0 -21
  36. package/dist/ai/LLM/openai.service.js +0 -421
  37. package/dist/ai/LLM/together.module.d.ts +0 -2
  38. package/dist/ai/LLM/together.module.js +0 -21
  39. package/dist/ai/LLM/together.service.d.ts +0 -18
  40. package/dist/ai/LLM/together.service.js +0 -285
  41. package/dist/ai/LLM/vertexai.module.d.ts +0 -2
  42. package/dist/ai/LLM/vertexai.module.js +0 -21
  43. package/dist/ai/LLM/vertexai.service.d.ts +0 -17
  44. package/dist/ai/LLM/vertexai.service.js +0 -323
  45. package/dist/ai/agent-config.d.ts +0 -32
  46. package/dist/ai/agent-config.js +0 -2
  47. package/dist/ai/agent-factory.d.ts +0 -15
  48. package/dist/ai/agent-factory.js +0 -24
  49. package/dist/ai/agent-message.service.d.ts +0 -9
  50. package/dist/ai/agent-message.service.js +0 -56
  51. package/dist/ai/agent-store.module.d.ts +0 -2
  52. package/dist/ai/agent-store.module.js +0 -21
  53. package/dist/ai/agent-store.service.d.ts +0 -31
  54. package/dist/ai/agent-store.service.js +0 -352
  55. package/dist/ai/agent.d.ts +0 -75
  56. package/dist/ai/agent.js +0 -174
  57. package/dist/ai/ai-factory.module.d.ts +0 -2
  58. package/dist/ai/ai-factory.module.js +0 -40
  59. package/dist/ai/ai-factory.service.d.ts +0 -24
  60. package/dist/ai/ai-factory.service.js +0 -94
  61. package/dist/ai/artifact.module.d.ts +0 -2
  62. package/dist/ai/artifact.module.js +0 -22
  63. package/dist/ai/artifact.service.d.ts +0 -21
  64. package/dist/ai/artifact.service.js +0 -239
  65. package/dist/ai/attached-file.module.d.ts +0 -2
  66. package/dist/ai/attached-file.module.js +0 -22
  67. package/dist/ai/attached-file.service.d.ts +0 -35
  68. package/dist/ai/attached-file.service.js +0 -253
  69. package/dist/ai/model_prices.d.ts +0 -2
  70. package/dist/ai/model_prices.js +0 -54
  71. package/dist/ai/published-agents.service.d.ts +0 -13
  72. package/dist/ai/published-agents.service.js +0 -118
  73. package/dist/app/balance-message.service.d.ts +0 -8
  74. package/dist/app/balance-message.service.js +0 -45
  75. package/dist/app/balance.module.d.ts +0 -2
  76. package/dist/app/balance.module.js +0 -20
  77. package/dist/app/balance.service.d.ts +0 -18
  78. package/dist/app/balance.service.js +0 -158
  79. package/dist/app/stripe.controller.d.ts +0 -31
  80. package/dist/app/stripe.controller.js +0 -150
  81. package/dist/app/stripe.module.d.ts +0 -2
  82. package/dist/app/stripe.module.js +0 -22
  83. package/dist/app/stripe.service.d.ts +0 -28
  84. package/dist/app/stripe.service.js +0 -198
  85. package/dist/app/transaction.service.d.ts +0 -15
  86. package/dist/app/transaction.service.js +0 -139
  87. package/dist/app/user-service-factory.d.ts +0 -21
  88. package/dist/app/user-service-factory.js +0 -81
  89. package/dist/app/user-service-manager.d.ts +0 -28
  90. package/dist/app/user-service-manager.js +0 -102
  91. package/dist/app.controller.d.ts +0 -232
  92. package/dist/app.controller.js +0 -2536
  93. package/dist/app.module.d.ts +0 -2
  94. package/dist/app.module.js +0 -45
  95. package/dist/app.service.d.ts +0 -186
  96. package/dist/app.service.js +0 -1334
  97. package/dist/auth/agent-access.decorator.d.ts +0 -2
  98. package/dist/auth/agent-access.decorator.js +0 -10
  99. package/dist/auth/auth.controller.d.ts +0 -38
  100. package/dist/auth/auth.controller.js +0 -356
  101. package/dist/auth/auth.module.d.ts +0 -2
  102. package/dist/auth/auth.module.js +0 -55
  103. package/dist/auth/auth.service.d.ts +0 -14
  104. package/dist/auth/auth.service.js +0 -84
  105. package/dist/auth/dto/bot-login.dto.d.ts +0 -4
  106. package/dist/auth/dto/bot-login.dto.js +0 -2
  107. package/dist/auth/dto/password-reset.dto.d.ts +0 -11
  108. package/dist/auth/dto/password-reset.dto.js +0 -2
  109. package/dist/auth/dto/phone-login.dto.d.ts +0 -8
  110. package/dist/auth/dto/phone-login.dto.js +0 -2
  111. package/dist/auth/dto/phone-verification.dto.d.ts +0 -9
  112. package/dist/auth/dto/phone-verification.dto.js +0 -2
  113. package/dist/auth/jwt-auth.guard.d.ts +0 -13
  114. package/dist/auth/jwt-auth.guard.js +0 -143
  115. package/dist/auth/jwt.strategy.d.ts +0 -17
  116. package/dist/auth/jwt.strategy.js +0 -45
  117. package/dist/auth/phone-validation.service.d.ts +0 -7
  118. package/dist/auth/phone-validation.service.js +0 -50
  119. package/dist/auth/public.decorator.d.ts +0 -2
  120. package/dist/auth/public.decorator.js +0 -7
  121. package/dist/auth/rate-limit.service.d.ts +0 -16
  122. package/dist/auth/rate-limit.service.js +0 -84
  123. package/dist/auth/room-access.decorator.d.ts +0 -2
  124. package/dist/auth/room-access.decorator.js +0 -10
  125. package/dist/auth/scopes.decorator.d.ts +0 -2
  126. package/dist/auth/scopes.decorator.js +0 -7
  127. package/dist/auth/scopes.guard.d.ts +0 -9
  128. package/dist/auth/scopes.guard.js +0 -82
  129. package/dist/auth/session.guard.d.ts +0 -7
  130. package/dist/auth/session.guard.js +0 -55
  131. package/dist/auth/twilio.service.d.ts +0 -15
  132. package/dist/auth/twilio.service.js +0 -139
  133. package/dist/auth/users.service.d.ts +0 -24
  134. package/dist/auth/users.service.js +0 -149
  135. package/dist/common/errors.d.ts +0 -12
  136. package/dist/common/errors.js +0 -43
  137. package/dist/config/configuration.module.d.ts +0 -2
  138. package/dist/config/configuration.module.js +0 -20
  139. package/dist/config/configuration.service.d.ts +0 -26
  140. package/dist/config/configuration.service.js +0 -131
  141. package/dist/main.js +0 -15749
  142. package/dist/room/artifact-store.service.d.ts +0 -15
  143. package/dist/room/artifact-store.service.js +0 -226
  144. package/dist/room/artifact.d.ts +0 -6
  145. package/dist/room/artifact.js +0 -2
  146. package/dist/room/message.d.ts +0 -19
  147. package/dist/room/message.js +0 -70
  148. package/dist/room/published-rooms.service.d.ts +0 -12
  149. package/dist/room/published-rooms.service.js +0 -108
  150. package/dist/room/room-config.d.ts +0 -12
  151. package/dist/room/room-config.js +0 -2
  152. package/dist/room/room-factory.d.ts +0 -7
  153. package/dist/room/room-factory.js +0 -16
  154. package/dist/room/room-message.module.d.ts +0 -2
  155. package/dist/room/room-message.module.js +0 -21
  156. package/dist/room/room-message.service.d.ts +0 -8
  157. package/dist/room/room-message.service.js +0 -44
  158. package/dist/room/room-store.module.d.ts +0 -2
  159. package/dist/room/room-store.module.js +0 -25
  160. package/dist/room/room-store.service.d.ts +0 -38
  161. package/dist/room/room-store.service.js +0 -353
  162. package/dist/room/room.d.ts +0 -107
  163. package/dist/room/room.js +0 -833
  164. package/dist/sdk/briyah-config.d.ts +0 -13
  165. package/dist/sdk/briyah-config.js +0 -32
  166. package/dist/sdk/briyah.d.ts +0 -36
  167. package/dist/sdk/briyah.js +0 -122
  168. package/dist/sdk/index.d.ts +0 -6
  169. package/dist/sdk/index.js +0 -11
  170. package/dist/shared/shared.module.d.ts +0 -2
  171. package/dist/shared/shared.module.js +0 -46
  172. package/dist/story/story-message.service.d.ts +0 -10
  173. package/dist/story/story-message.service.js +0 -57
  174. package/dist/story/story-progress.service.d.ts +0 -8
  175. package/dist/story/story-progress.service.js +0 -44
  176. package/dist/story/story-store.module.d.ts +0 -2
  177. package/dist/story/story-store.module.js +0 -22
  178. package/dist/story/story-store.service.d.ts +0 -23
  179. package/dist/story/story-store.service.js +0 -392
  180. package/dist/story/story.service.d.ts +0 -94
  181. package/dist/story/story.service.js +0 -1797
@@ -1,139 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.TransactionService = void 0;
37
- const fs = __importStar(require("fs"));
38
- const path = __importStar(require("path"));
39
- const zod_1 = require("zod");
40
- class TransactionService {
41
- userId;
42
- configService;
43
- transactionsDir;
44
- constructor(userId, configService) {
45
- this.userId = userId;
46
- this.configService = configService;
47
- const userDataPath = this.configService.getUserDataDir();
48
- this.transactionsDir = path.join(userDataPath, 'transactions');
49
- if (!fs.existsSync(this.transactionsDir)) {
50
- fs.mkdirSync(this.transactionsDir, { recursive: true });
51
- }
52
- }
53
- async recordTransaction(amount, stripePaymentIntentId, status = 'pending') {
54
- const timestamp = Date.now();
55
- const transaction = {
56
- id: (0, zod_1.uuidv4)().toString(),
57
- userId: this.userId,
58
- amount,
59
- currency: 'usd',
60
- stripePaymentIntentId,
61
- status,
62
- createdAt: timestamp,
63
- updatedAt: timestamp,
64
- };
65
- const filename = `${timestamp}-${stripePaymentIntentId}.json`;
66
- const filePath = path.join(this.transactionsDir, filename);
67
- try {
68
- fs.writeFileSync(filePath, JSON.stringify(transaction, null, 2), 'utf-8');
69
- return transaction;
70
- }
71
- catch (error) {
72
- console.error(`Error recording transaction for user ${this.userId}:`, error);
73
- throw error;
74
- }
75
- }
76
- async updateTransactionStatus(paymentIntentId, status) {
77
- try {
78
- const transaction = await this.getTransactionByPaymentIntent(paymentIntentId);
79
- if (!transaction) {
80
- console.error(`Transaction not found for payment intent ${paymentIntentId}`);
81
- return;
82
- }
83
- transaction.status = status;
84
- transaction.updatedAt = Date.now();
85
- const files = fs.readdirSync(this.transactionsDir);
86
- const matchingFile = files.find((file) => file.includes(paymentIntentId));
87
- if (matchingFile) {
88
- const filePath = path.join(this.transactionsDir, matchingFile);
89
- fs.writeFileSync(filePath, JSON.stringify(transaction, null, 2), 'utf-8');
90
- }
91
- }
92
- catch (error) {
93
- console.error(`Error updating transaction status for ${paymentIntentId}:`, error);
94
- throw error;
95
- }
96
- }
97
- async getTransactionByPaymentIntent(paymentIntentId) {
98
- try {
99
- const files = fs.readdirSync(this.transactionsDir);
100
- const matchingFile = files.find((file) => file.includes(paymentIntentId));
101
- if (!matchingFile) {
102
- return null;
103
- }
104
- const filePath = path.join(this.transactionsDir, matchingFile);
105
- const content = fs.readFileSync(filePath, 'utf-8');
106
- return JSON.parse(content);
107
- }
108
- catch (error) {
109
- console.error(`Error getting transaction for payment intent ${paymentIntentId}:`, error);
110
- return null;
111
- }
112
- }
113
- async getTransactions(limit = 50, offset = 0) {
114
- try {
115
- const files = fs.readdirSync(this.transactionsDir);
116
- const transactions = [];
117
- for (const file of files) {
118
- if (!file.endsWith('.json'))
119
- continue;
120
- const filePath = path.join(this.transactionsDir, file);
121
- const content = fs.readFileSync(filePath, 'utf-8');
122
- const transaction = JSON.parse(content);
123
- transactions.push(transaction);
124
- }
125
- transactions.sort((a, b) => b.createdAt - a.createdAt);
126
- const total = transactions.length;
127
- const paginatedTransactions = transactions.slice(offset, offset + limit);
128
- return {
129
- transactions: paginatedTransactions,
130
- total,
131
- };
132
- }
133
- catch (error) {
134
- console.error(`Error getting transactions for user ${this.userId}:`, error);
135
- return { transactions: [], total: 0 };
136
- }
137
- }
138
- }
139
- exports.TransactionService = TransactionService;
@@ -1,21 +0,0 @@
1
- import { AppService } from '../app.service';
2
- import { RoomMessageService } from '../room/room-message.service';
3
- import { AiFactoryService } from '../ai/ai-factory.service';
4
- import { AgentMessageService } from '../ai/agent-message.service';
5
- import { StoryProgressService } from '../story/story-progress.service';
6
- import { StoryMessageService } from '../story/story-message.service';
7
- import { PublishedAgentsService } from '../ai/published-agents.service';
8
- import { PublishedRoomsService } from '../room/published-rooms.service';
9
- import { BalanceMessageService } from './balance-message.service';
10
- export declare class UserServiceFactory {
11
- private readonly aiFactoryService;
12
- private readonly agentMessageService;
13
- private readonly roomMessageService;
14
- private readonly storyProgressService;
15
- private readonly storyMessageService;
16
- private readonly publishedAgentsService;
17
- private readonly publishedRoomsService;
18
- private readonly balanceMessageService;
19
- constructor(aiFactoryService: AiFactoryService, agentMessageService: AgentMessageService, roomMessageService: RoomMessageService, storyProgressService: StoryProgressService, storyMessageService: StoryMessageService, publishedAgentsService: PublishedAgentsService, publishedRoomsService: PublishedRoomsService, balanceMessageService: BalanceMessageService);
20
- createAppService(userId: string): AppService;
21
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UserServiceFactory = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const app_service_1 = require("../app.service");
15
- const configuration_service_1 = require("../config/configuration.service");
16
- const agent_store_service_1 = require("../ai/agent-store.service");
17
- const room_store_service_1 = require("../room/room-store.service");
18
- const artifact_store_service_1 = require("../room/artifact-store.service");
19
- const room_message_service_1 = require("../room/room-message.service");
20
- const story_store_service_1 = require("../story/story-store.service");
21
- const attached_file_service_1 = require("../ai/attached-file.service");
22
- const artifact_service_1 = require("../ai/artifact.service");
23
- const ai_factory_service_1 = require("../ai/ai-factory.service");
24
- const agent_message_service_1 = require("../ai/agent-message.service");
25
- const story_service_1 = require("../story/story.service");
26
- const story_progress_service_1 = require("../story/story-progress.service");
27
- const story_message_service_1 = require("../story/story-message.service");
28
- const published_agents_service_1 = require("../ai/published-agents.service");
29
- const published_rooms_service_1 = require("../room/published-rooms.service");
30
- const balance_service_1 = require("./balance.service");
31
- const balance_message_service_1 = require("./balance-message.service");
32
- const transaction_service_1 = require("./transaction.service");
33
- const agent_factory_1 = require("../ai/agent-factory");
34
- const room_factory_1 = require("../room/room-factory");
35
- let UserServiceFactory = class UserServiceFactory {
36
- aiFactoryService;
37
- agentMessageService;
38
- roomMessageService;
39
- storyProgressService;
40
- storyMessageService;
41
- publishedAgentsService;
42
- publishedRoomsService;
43
- balanceMessageService;
44
- constructor(aiFactoryService, agentMessageService, roomMessageService, storyProgressService, storyMessageService, publishedAgentsService, publishedRoomsService, balanceMessageService) {
45
- this.aiFactoryService = aiFactoryService;
46
- this.agentMessageService = agentMessageService;
47
- this.roomMessageService = roomMessageService;
48
- this.storyProgressService = storyProgressService;
49
- this.storyMessageService = storyMessageService;
50
- this.publishedAgentsService = publishedAgentsService;
51
- this.publishedRoomsService = publishedRoomsService;
52
- this.balanceMessageService = balanceMessageService;
53
- }
54
- createAppService(userId) {
55
- const configService = new configuration_service_1.ConfigurationService(userId);
56
- const balanceService = new balance_service_1.BalanceService(userId, configService, this.balanceMessageService);
57
- const transactionService = new transaction_service_1.TransactionService(userId, configService);
58
- const attachedFileService = new attached_file_service_1.AttachedFileService(configService);
59
- const artifactService = new artifact_service_1.ArtifactService(configService);
60
- const agentStore = new agent_store_service_1.AgentStoreService(this.aiFactoryService, configService, attachedFileService, balanceService, artifactService);
61
- const agentFactory = new agent_factory_1.AgentFactory(this.aiFactoryService, agentStore, configService, balanceService, artifactService);
62
- const artifactStore = new artifact_store_service_1.ArtifactStoreService();
63
- const roomStore = new room_store_service_1.RoomStoreService(configService, agentStore, attachedFileService, artifactStore);
64
- const roomFactory = new room_factory_1.RoomFactory(roomStore);
65
- const storyStore = new story_store_service_1.StoryStoreService(configService, roomStore);
66
- const storyService = new story_service_1.StoryService(storyStore, agentStore, roomStore, this.storyProgressService, this.storyMessageService, configService, agentFactory, roomFactory);
67
- return new app_service_1.AppService(this.aiFactoryService, agentStore, this.agentMessageService, roomStore, this.roomMessageService, configService, attachedFileService, artifactService, storyStore, storyService, this.publishedAgentsService, this.publishedRoomsService, balanceService, this.balanceMessageService, transactionService, agentFactory, roomFactory);
68
- }
69
- };
70
- exports.UserServiceFactory = UserServiceFactory;
71
- exports.UserServiceFactory = UserServiceFactory = __decorate([
72
- (0, common_1.Injectable)(),
73
- __metadata("design:paramtypes", [ai_factory_service_1.AiFactoryService,
74
- agent_message_service_1.AgentMessageService,
75
- room_message_service_1.RoomMessageService,
76
- story_progress_service_1.StoryProgressService,
77
- story_message_service_1.StoryMessageService,
78
- published_agents_service_1.PublishedAgentsService,
79
- published_rooms_service_1.PublishedRoomsService,
80
- balance_message_service_1.BalanceMessageService])
81
- ], UserServiceFactory);
@@ -1,28 +0,0 @@
1
- import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2
- import { ConfigService } from '@nestjs/config';
3
- import { AppService } from '../app.service';
4
- import { UserServiceFactory } from './user-service-factory';
5
- export interface IConfigService {
6
- get<T = string>(key: string, defaultValue?: T): T;
7
- }
8
- export declare class UserServiceManager implements OnModuleInit, OnModuleDestroy {
9
- private readonly userServiceFactory;
10
- private readonly configService;
11
- private userServices;
12
- private cleanupIntervalId;
13
- private readonly cacheTimeoutMinutes;
14
- private readonly cleanupIntervalMinutes;
15
- constructor(userServiceFactory: UserServiceFactory, configService: ConfigService);
16
- onModuleInit(): void;
17
- onModuleDestroy(): void;
18
- getAppService(userId: string): AppService;
19
- removeUserService(userId: string): void;
20
- getCacheStats(): {
21
- cachedUsers: number;
22
- users: {
23
- userId: string;
24
- ageMinutes: number;
25
- }[];
26
- };
27
- private cleanupInactiveUsers;
28
- }
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UserServiceManager = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const config_1 = require("@nestjs/config");
15
- const user_service_factory_1 = require("./user-service-factory");
16
- let UserServiceManager = class UserServiceManager {
17
- userServiceFactory;
18
- configService;
19
- userServices = new Map();
20
- cleanupIntervalId = null;
21
- cacheTimeoutMinutes;
22
- cleanupIntervalMinutes = 5;
23
- constructor(userServiceFactory, configService) {
24
- this.userServiceFactory = userServiceFactory;
25
- this.configService = configService;
26
- this.cacheTimeoutMinutes = parseInt(this.configService.get('USER_SERVICE_CACHE_TIMEOUT_MINUTES', '30'));
27
- }
28
- onModuleInit() {
29
- if (this.cleanupIntervalId) {
30
- return;
31
- }
32
- this.cleanupIntervalId = setInterval(() => this.cleanupInactiveUsers(), this.cleanupIntervalMinutes * 60 * 1000);
33
- }
34
- onModuleDestroy() {
35
- if (this.cleanupIntervalId) {
36
- clearInterval(this.cleanupIntervalId);
37
- this.cleanupIntervalId = null;
38
- this.userServices.clear();
39
- console.log('[UserServiceManager] Shutdown complete');
40
- }
41
- }
42
- getAppService(userId) {
43
- const now = Date.now();
44
- const context = this.userServices.get(userId);
45
- if (context) {
46
- const ageMinutes = (now - context.lastAccessed) / (60 * 1000);
47
- if (ageMinutes < this.cacheTimeoutMinutes) {
48
- context.lastAccessed = now;
49
- return context.appService;
50
- }
51
- else {
52
- console.log(`[UserServiceManager] Cache expired for user ${userId} (${ageMinutes.toFixed(1)}min old)`);
53
- this.userServices.delete(userId);
54
- }
55
- }
56
- const appService = this.userServiceFactory.createAppService(userId);
57
- this.userServices.set(userId, {
58
- appService,
59
- lastAccessed: now,
60
- });
61
- return appService;
62
- }
63
- removeUserService(userId) {
64
- if (this.userServices.delete(userId)) {
65
- console.log(`[UserServiceManager] Manually removed service for user ${userId}`);
66
- }
67
- }
68
- getCacheStats() {
69
- const now = Date.now();
70
- const users = Array.from(this.userServices.entries()).map(([userId, context]) => ({
71
- userId,
72
- ageMinutes: (now - context.lastAccessed) / (60 * 1000),
73
- }));
74
- return {
75
- cachedUsers: this.userServices.size,
76
- users,
77
- };
78
- }
79
- cleanupInactiveUsers() {
80
- const now = Date.now();
81
- const timeoutMs = this.cacheTimeoutMinutes * 60 * 1000;
82
- let removedCount = 0;
83
- for (const [userId, context] of this.userServices.entries()) {
84
- const age = now - context.lastAccessed;
85
- if (age > timeoutMs) {
86
- this.userServices.delete(userId);
87
- removedCount++;
88
- const ageMinutes = age / (60 * 1000);
89
- console.log(`[UserServiceManager] Cleaned up service for user ${userId} (${ageMinutes.toFixed(1)}min inactive)`);
90
- }
91
- }
92
- if (removedCount > 0) {
93
- console.log(`[UserServiceManager] Cleanup complete: removed ${removedCount} inactive user(s), ${this.userServices.size} remaining`);
94
- }
95
- }
96
- };
97
- exports.UserServiceManager = UserServiceManager;
98
- exports.UserServiceManager = UserServiceManager = __decorate([
99
- (0, common_1.Injectable)(),
100
- __metadata("design:paramtypes", [user_service_factory_1.UserServiceFactory,
101
- config_1.ConfigService])
102
- ], UserServiceManager);
@@ -1,232 +0,0 @@
1
- import { MessageEvent } from '@nestjs/common';
2
- import { Request as ExpressRequest, Response } from 'express';
3
- import { Observable } from 'rxjs';
4
- import { UserServiceManager } from './app/user-service-manager';
5
- import { PublishedAgentsService } from './ai/published-agents.service';
6
- import { PublishedRoomsService } from './room/published-rooms.service';
7
- import { AgentInfo, CreateAgentResponse, UpdateAgentRequest, RoomInfo, RoomDetails, CreateRoomResponse, AgentMessagesResponse, RoomMessagesResponse, FileList, PromptFileContent, PromptFoldersResponse, PromptFilesResponse, PromptScope, CreatePromptFolderRequest, CreatePromptFileRequest, UpdatePromptFileRequest, ProcessTextResponse, PreparedPromptResponse, AttachDocumentResponse, StoryInfo, StoryState, Character, ModelInfo, StoryModelDefaults, ChapterInfo, StoryIdea } from './shared/types/app.types';
8
- import { RoomMessage } from './room/message';
9
- export declare class AppController {
10
- private readonly userServiceManager;
11
- private readonly publishedAgentsService;
12
- private readonly publishedRoomsService;
13
- constructor(userServiceManager: UserServiceManager, publishedAgentsService: PublishedAgentsService, publishedRoomsService: PublishedRoomsService);
14
- private getAppService;
15
- listServices(req: ExpressRequest): string[];
16
- listModels(req: ExpressRequest, aiServiceName: string): Promise<ModelInfo[]>;
17
- listImageModels(req: ExpressRequest): Promise<ModelInfo[]>;
18
- listStoryModels(req: ExpressRequest): Promise<ModelInfo[]>;
19
- listStoryModelDefaults(_req: ExpressRequest): StoryModelDefaults;
20
- createAgent(req: ExpressRequest, body: {
21
- aiServiceName: string;
22
- agentName: string;
23
- agentNickname?: string;
24
- description: string;
25
- aiModel: string;
26
- promptName: string;
27
- controlledByHuman?: boolean;
28
- reasoningEffort?: 'low' | 'medium' | 'high' | null;
29
- maxOutputTokens?: number;
30
- beginInstruction?: string;
31
- }): Promise<CreateAgentResponse>;
32
- processText(req: ExpressRequest, agentId: string, body: {
33
- text: string;
34
- }): Promise<ProcessTextResponse>;
35
- attachDocument(req: ExpressRequest, agentId: string, body: {
36
- fileName?: string;
37
- }, file: Express.Multer.File): Promise<AttachDocumentResponse>;
38
- listAttachedFiles(req: ExpressRequest, agentId: string): Promise<FileList>;
39
- getPrompts(req: ExpressRequest, scope?: PromptScope): PromptFoldersResponse;
40
- createPromptFolder(req: ExpressRequest, body: CreatePromptFolderRequest): Promise<void>;
41
- deletePromptFolder(req: ExpressRequest, folderName: string): Promise<void>;
42
- getPromptFiles(req: ExpressRequest, folderName: string): Promise<PromptFilesResponse>;
43
- getPromptFile(req: ExpressRequest, folderName: string, fileName: string): Promise<PromptFileContent>;
44
- createPromptFile(req: ExpressRequest, folderName: string, body: CreatePromptFileRequest): Promise<void>;
45
- updatePromptFile(req: ExpressRequest, folderName: string, fileName: string, body: UpdatePromptFileRequest): Promise<void>;
46
- deletePromptFile(req: ExpressRequest, folderName: string, fileName: string): Promise<void>;
47
- listPromptFolders(req: ExpressRequest): string[];
48
- listPrompts(req: ExpressRequest, agentId: string): string[];
49
- runPreparedPrompt(req: ExpressRequest, agentId: string, promptName: string, body: {
50
- variables?: any;
51
- }): Promise<PreparedPromptResponse>;
52
- listAgents(req: ExpressRequest, published?: string): Promise<AgentInfo[]>;
53
- createRoom(req: ExpressRequest, body: {
54
- roomName: string;
55
- roomGoal: string;
56
- agentIds: string[];
57
- }): Promise<CreateRoomResponse>;
58
- editRoom(req: ExpressRequest, roomId: string, body: {
59
- roomName: string;
60
- roomGoal: string;
61
- baseRoomDir?: string;
62
- agentIds: string[];
63
- }): Promise<void>;
64
- listRooms(req: ExpressRequest): RoomInfo[];
65
- getRoomDetails(req: ExpressRequest, roomId: string): Promise<RoomDetails>;
66
- getAgentDetails(req: ExpressRequest, agentId: string): Promise<AgentInfo>;
67
- getRoomMessages(req: ExpressRequest, roomId: string, fromIndex: string, showThoughts?: string): RoomMessagesResponse;
68
- getAgentMessages(req: ExpressRequest, agentId: string, fromIndex: string): Promise<AgentMessagesResponse>;
69
- getStoryMessages(req: ExpressRequest, storyId: string, fromIndex: string): RoomMessagesResponse;
70
- deleteAgent(req: ExpressRequest, agentId: string): Promise<void>;
71
- publishAgentInstance(req: ExpressRequest, agentId: string, body: {
72
- publishedAgentName: string;
73
- }): Promise<{
74
- instanceId: string;
75
- publicUrl: string;
76
- }>;
77
- getPublishedInstances(req: ExpressRequest, agentId: string): Promise<AgentInfo[]>;
78
- resetPublishedInstance(req: ExpressRequest, instanceId: string): Promise<void>;
79
- deleteRoom(req: ExpressRequest, roomId: string): Promise<void>;
80
- sendRoomMessage(req: ExpressRequest, roomId: string, body: {
81
- content: string;
82
- sender: string;
83
- action?: string;
84
- targets?: string[];
85
- clearQueue?: boolean;
86
- }): Promise<void>;
87
- pauseRoom(req: ExpressRequest, roomId: string): Promise<{
88
- success: boolean;
89
- }>;
90
- resumeRoom(req: ExpressRequest, roomId: string): Promise<{
91
- success: boolean;
92
- }>;
93
- getUserPreferences(req: ExpressRequest): Promise<any>;
94
- saveUserPreferences(req: ExpressRequest, preferences: any): Promise<void>;
95
- listPromptFilesDeprecated(req: ExpressRequest, folderName: string): Promise<FileList>;
96
- getPromptFileDeprecated(req: ExpressRequest, folderName: string, fileName: string): Promise<PromptFileContent>;
97
- savePromptFileDeprecated(req: ExpressRequest, body: {
98
- folderName: string;
99
- fileName: string;
100
- content: string;
101
- fileType: string;
102
- }): Promise<void>;
103
- deletePromptFileDeprecated(req: ExpressRequest, body: {
104
- folderName: string;
105
- fileName: string;
106
- }): Promise<void>;
107
- deletePromptFolderDeprecated(req: ExpressRequest, body: {
108
- folderName: string;
109
- }): Promise<void>;
110
- updateAgent(req: ExpressRequest, agentId: string, updateData: UpdateAgentRequest): Promise<void>;
111
- deleteAttachedFile(req: ExpressRequest, agentId: string, documentId: string): Promise<void>;
112
- reloadAgent(req: ExpressRequest, agentId: string): Promise<void>;
113
- resetRoom(req: ExpressRequest, roomId: string): Promise<void>;
114
- publishRoom(req: ExpressRequest, templateId: string, body: {
115
- publishedName?: string;
116
- }): Promise<{
117
- roomId: string;
118
- }>;
119
- getPublishedRoomInstances(req: ExpressRequest, templateId: string): Promise<RoomInfo[]>;
120
- resetPublishedRoomInstance(req: ExpressRequest, instanceId: string): Promise<void>;
121
- resetStory(req: ExpressRequest, storyId: string): Promise<void>;
122
- getRoomArtifacts(req: ExpressRequest, roomId: string): Promise<{
123
- artifacts: any[];
124
- }>;
125
- publishArtifact(req: ExpressRequest, roomId: string, body: {
126
- name: string;
127
- creator: string;
128
- body: string;
129
- viewers?: string[];
130
- }): Promise<void>;
131
- createPromptFolderDeprecated(req: ExpressRequest, body: {
132
- folderName: string;
133
- }): Promise<void>;
134
- listStories(req: ExpressRequest): StoryInfo[];
135
- listStoryGenres(req: ExpressRequest): string[];
136
- getRandomStoryIdea(req: ExpressRequest): Promise<StoryIdea | null>;
137
- getStoryIdeasByGenre(req: ExpressRequest, genreName: string): Promise<StoryIdea | null>;
138
- createStory(req: ExpressRequest, body: {
139
- name: string;
140
- idea: string;
141
- userCharacterDesc: string;
142
- otherCharactersDesc: string;
143
- storyModel?: string;
144
- isImport?: boolean;
145
- imageModelName?: string;
146
- }): Promise<StoryInfo>;
147
- importStoryZip(req: ExpressRequest, file: Express.Multer.File): Promise<StoryInfo>;
148
- deleteStory(req: ExpressRequest, storyId: string): Promise<void>;
149
- compactStory(req: ExpressRequest, storyId: string): Promise<void>;
150
- progressStory(req: ExpressRequest, storyId: string): Promise<{
151
- chapterIndex: number;
152
- }>;
153
- getStoryState(req: ExpressRequest, storyId: string): Promise<StoryState>;
154
- respondToStory(req: ExpressRequest, storyId: string, body: {
155
- content: string;
156
- }): Promise<void>;
157
- introduceCharacter(req: ExpressRequest, storyId: string, body: {
158
- name: string;
159
- description?: string;
160
- storyModel?: string;
161
- fromNarratorSuggestion?: boolean;
162
- }): Promise<void>;
163
- declineCharacter(req: ExpressRequest, storyId: string, characterName: string): Promise<{
164
- success: boolean;
165
- }>;
166
- deleteCharacter(req: ExpressRequest, storyId: string, characterName: string): Promise<void>;
167
- listChapters(req: ExpressRequest, storyId: string): {
168
- chapters: ChapterInfo[];
169
- };
170
- getChapter(req: ExpressRequest, storyId: string, chapterIndex: string): Promise<{
171
- content: RoomMessage[];
172
- }>;
173
- saveChapter(req: ExpressRequest, storyId: string, chapterIndex: string, body: {
174
- content: string;
175
- }): void;
176
- deleteChapter(req: ExpressRequest, storyId: string, chapterIndex: string): void;
177
- exportStoryMarkdown(req: ExpressRequest, storyId: string, res: Response): Promise<void>;
178
- exportStoryZip(req: ExpressRequest, storyId: string, res: Response): Promise<void>;
179
- listCharacters(req: ExpressRequest, storyId: string): Promise<Character[]>;
180
- getCharacter(req: ExpressRequest, storyId: string, characterName: string): Promise<{
181
- content: string;
182
- }>;
183
- saveCharacter(req: ExpressRequest, storyId: string, characterName: string, body: {
184
- content: string;
185
- }): Promise<void>;
186
- getPlotPlan(req: ExpressRequest, storyId: string): Promise<{
187
- content: string;
188
- }>;
189
- getAgentHistory(req: ExpressRequest, storyId: string, agentId: string): Promise<{
190
- content: string;
191
- }>;
192
- savePlotPlan(req: ExpressRequest, storyId: string, body: {
193
- content: string;
194
- }): Promise<void>;
195
- listStoryArtifacts(req: ExpressRequest, storyId: string): Promise<{
196
- artifacts: any[];
197
- }>;
198
- getStoryArtifact(req: ExpressRequest, storyId: string, artifactId: string, res: Response): Promise<void>;
199
- storyProgress(req: ExpressRequest, storyId: string): Observable<MessageEvent>;
200
- storyMessages(req: ExpressRequest, storyId: string): Observable<MessageEvent>;
201
- agentMessages(req: ExpressRequest, agentId: string): Promise<Observable<MessageEvent>>;
202
- roomMessages(req: ExpressRequest, roomId: string): Promise<Observable<MessageEvent>>;
203
- balanceUpdates(req: ExpressRequest): Observable<MessageEvent>;
204
- getBalance(req: ExpressRequest): Promise<{
205
- balance: number;
206
- }>;
207
- listArtifacts(req: ExpressRequest): Promise<{
208
- artifacts: any[];
209
- }>;
210
- getArtifact(req: ExpressRequest, artifactId: string): Promise<{
211
- content: string;
212
- }>;
213
- createArtifact(req: ExpressRequest, body: {
214
- name: string;
215
- }, file: Express.Multer.File): Promise<{
216
- artifactId: string;
217
- }>;
218
- updateArtifact(req: ExpressRequest, artifactId: string, body: {
219
- content: string;
220
- }): Promise<void>;
221
- renameArtifact(req: ExpressRequest, artifactId: string, body: {
222
- name: string;
223
- }): Promise<void>;
224
- deleteArtifact(req: ExpressRequest, artifactId: string): Promise<void>;
225
- listAgentArtifacts(req: ExpressRequest, agentId: string): Promise<{
226
- artifacts: any[];
227
- }>;
228
- attachArtifactToAgent(req: ExpressRequest, agentId: string, body: {
229
- artifactId: string;
230
- }): Promise<void>;
231
- detachArtifactFromAgent(req: ExpressRequest, agentId: string, artifactId: string): Promise<void>;
232
- }