briyah 1.0.1 → 1.0.3

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 (177) hide show
  1. package/dist/server/src/ai/LLM/deepseek.service.js +1 -1
  2. package/package.json +2 -2
  3. package/dist/ai/LLM/anthropic.module.d.ts +0 -2
  4. package/dist/ai/LLM/anthropic.module.js +0 -21
  5. package/dist/ai/LLM/anthropic.service.d.ts +0 -27
  6. package/dist/ai/LLM/anthropic.service.js +0 -329
  7. package/dist/ai/LLM/base-ai.service.d.ts +0 -45
  8. package/dist/ai/LLM/base-ai.service.js +0 -409
  9. package/dist/ai/LLM/deepseek.module.d.ts +0 -2
  10. package/dist/ai/LLM/deepseek.module.js +0 -21
  11. package/dist/ai/LLM/deepseek.service.d.ts +0 -15
  12. package/dist/ai/LLM/deepseek.service.js +0 -279
  13. package/dist/ai/LLM/fal.module.d.ts +0 -2
  14. package/dist/ai/LLM/fal.module.js +0 -21
  15. package/dist/ai/LLM/fal.service.d.ts +0 -17
  16. package/dist/ai/LLM/fal.service.js +0 -314
  17. package/dist/ai/LLM/googleai.module.d.ts +0 -2
  18. package/dist/ai/LLM/googleai.module.js +0 -21
  19. package/dist/ai/LLM/googleai.service.d.ts +0 -20
  20. package/dist/ai/LLM/googleai.service.js +0 -271
  21. package/dist/ai/LLM/grok.module.d.ts +0 -2
  22. package/dist/ai/LLM/grok.module.js +0 -21
  23. package/dist/ai/LLM/grok.service.d.ts +0 -14
  24. package/dist/ai/LLM/grok.service.js +0 -263
  25. package/dist/ai/LLM/mock.module.d.ts +0 -2
  26. package/dist/ai/LLM/mock.module.js +0 -21
  27. package/dist/ai/LLM/mock.service.d.ts +0 -13
  28. package/dist/ai/LLM/mock.service.js +0 -194
  29. package/dist/ai/LLM/openai.module.d.ts +0 -2
  30. package/dist/ai/LLM/openai.module.js +0 -21
  31. package/dist/ai/LLM/openai.service.d.ts +0 -21
  32. package/dist/ai/LLM/openai.service.js +0 -421
  33. package/dist/ai/LLM/together.module.d.ts +0 -2
  34. package/dist/ai/LLM/together.module.js +0 -21
  35. package/dist/ai/LLM/together.service.d.ts +0 -18
  36. package/dist/ai/LLM/together.service.js +0 -285
  37. package/dist/ai/LLM/vertexai.module.d.ts +0 -2
  38. package/dist/ai/LLM/vertexai.module.js +0 -21
  39. package/dist/ai/LLM/vertexai.service.d.ts +0 -17
  40. package/dist/ai/LLM/vertexai.service.js +0 -323
  41. package/dist/ai/agent-config.d.ts +0 -32
  42. package/dist/ai/agent-config.js +0 -2
  43. package/dist/ai/agent-factory.d.ts +0 -15
  44. package/dist/ai/agent-factory.js +0 -24
  45. package/dist/ai/agent-message.service.d.ts +0 -9
  46. package/dist/ai/agent-message.service.js +0 -56
  47. package/dist/ai/agent-store.module.d.ts +0 -2
  48. package/dist/ai/agent-store.module.js +0 -21
  49. package/dist/ai/agent-store.service.d.ts +0 -31
  50. package/dist/ai/agent-store.service.js +0 -352
  51. package/dist/ai/agent.d.ts +0 -75
  52. package/dist/ai/agent.js +0 -174
  53. package/dist/ai/ai-factory.module.d.ts +0 -2
  54. package/dist/ai/ai-factory.module.js +0 -40
  55. package/dist/ai/ai-factory.service.d.ts +0 -24
  56. package/dist/ai/ai-factory.service.js +0 -94
  57. package/dist/ai/artifact.module.d.ts +0 -2
  58. package/dist/ai/artifact.module.js +0 -22
  59. package/dist/ai/artifact.service.d.ts +0 -21
  60. package/dist/ai/artifact.service.js +0 -239
  61. package/dist/ai/attached-file.module.d.ts +0 -2
  62. package/dist/ai/attached-file.module.js +0 -22
  63. package/dist/ai/attached-file.service.d.ts +0 -35
  64. package/dist/ai/attached-file.service.js +0 -253
  65. package/dist/ai/model_prices.d.ts +0 -2
  66. package/dist/ai/model_prices.js +0 -54
  67. package/dist/ai/published-agents.service.d.ts +0 -13
  68. package/dist/ai/published-agents.service.js +0 -118
  69. package/dist/app/balance-message.service.d.ts +0 -8
  70. package/dist/app/balance-message.service.js +0 -45
  71. package/dist/app/balance.module.d.ts +0 -2
  72. package/dist/app/balance.module.js +0 -20
  73. package/dist/app/balance.service.d.ts +0 -18
  74. package/dist/app/balance.service.js +0 -158
  75. package/dist/app/stripe.controller.d.ts +0 -31
  76. package/dist/app/stripe.controller.js +0 -150
  77. package/dist/app/stripe.module.d.ts +0 -2
  78. package/dist/app/stripe.module.js +0 -22
  79. package/dist/app/stripe.service.d.ts +0 -28
  80. package/dist/app/stripe.service.js +0 -198
  81. package/dist/app/transaction.service.d.ts +0 -15
  82. package/dist/app/transaction.service.js +0 -139
  83. package/dist/app/user-service-factory.d.ts +0 -21
  84. package/dist/app/user-service-factory.js +0 -81
  85. package/dist/app/user-service-manager.d.ts +0 -28
  86. package/dist/app/user-service-manager.js +0 -102
  87. package/dist/app.controller.d.ts +0 -232
  88. package/dist/app.controller.js +0 -2536
  89. package/dist/app.module.d.ts +0 -2
  90. package/dist/app.module.js +0 -45
  91. package/dist/app.service.d.ts +0 -186
  92. package/dist/app.service.js +0 -1334
  93. package/dist/auth/agent-access.decorator.d.ts +0 -2
  94. package/dist/auth/agent-access.decorator.js +0 -10
  95. package/dist/auth/auth.controller.d.ts +0 -38
  96. package/dist/auth/auth.controller.js +0 -356
  97. package/dist/auth/auth.module.d.ts +0 -2
  98. package/dist/auth/auth.module.js +0 -55
  99. package/dist/auth/auth.service.d.ts +0 -14
  100. package/dist/auth/auth.service.js +0 -84
  101. package/dist/auth/dto/bot-login.dto.d.ts +0 -4
  102. package/dist/auth/dto/bot-login.dto.js +0 -2
  103. package/dist/auth/dto/password-reset.dto.d.ts +0 -11
  104. package/dist/auth/dto/password-reset.dto.js +0 -2
  105. package/dist/auth/dto/phone-login.dto.d.ts +0 -8
  106. package/dist/auth/dto/phone-login.dto.js +0 -2
  107. package/dist/auth/dto/phone-verification.dto.d.ts +0 -9
  108. package/dist/auth/dto/phone-verification.dto.js +0 -2
  109. package/dist/auth/jwt-auth.guard.d.ts +0 -13
  110. package/dist/auth/jwt-auth.guard.js +0 -143
  111. package/dist/auth/jwt.strategy.d.ts +0 -17
  112. package/dist/auth/jwt.strategy.js +0 -45
  113. package/dist/auth/phone-validation.service.d.ts +0 -7
  114. package/dist/auth/phone-validation.service.js +0 -50
  115. package/dist/auth/public.decorator.d.ts +0 -2
  116. package/dist/auth/public.decorator.js +0 -7
  117. package/dist/auth/rate-limit.service.d.ts +0 -16
  118. package/dist/auth/rate-limit.service.js +0 -84
  119. package/dist/auth/room-access.decorator.d.ts +0 -2
  120. package/dist/auth/room-access.decorator.js +0 -10
  121. package/dist/auth/scopes.decorator.d.ts +0 -2
  122. package/dist/auth/scopes.decorator.js +0 -7
  123. package/dist/auth/scopes.guard.d.ts +0 -9
  124. package/dist/auth/scopes.guard.js +0 -82
  125. package/dist/auth/session.guard.d.ts +0 -7
  126. package/dist/auth/session.guard.js +0 -55
  127. package/dist/auth/twilio.service.d.ts +0 -15
  128. package/dist/auth/twilio.service.js +0 -139
  129. package/dist/auth/users.service.d.ts +0 -24
  130. package/dist/auth/users.service.js +0 -149
  131. package/dist/common/errors.d.ts +0 -12
  132. package/dist/common/errors.js +0 -43
  133. package/dist/config/configuration.module.d.ts +0 -2
  134. package/dist/config/configuration.module.js +0 -20
  135. package/dist/config/configuration.service.d.ts +0 -26
  136. package/dist/config/configuration.service.js +0 -131
  137. package/dist/main.js +0 -15749
  138. package/dist/room/artifact-store.service.d.ts +0 -15
  139. package/dist/room/artifact-store.service.js +0 -226
  140. package/dist/room/artifact.d.ts +0 -6
  141. package/dist/room/artifact.js +0 -2
  142. package/dist/room/message.d.ts +0 -19
  143. package/dist/room/message.js +0 -70
  144. package/dist/room/published-rooms.service.d.ts +0 -12
  145. package/dist/room/published-rooms.service.js +0 -108
  146. package/dist/room/room-config.d.ts +0 -12
  147. package/dist/room/room-config.js +0 -2
  148. package/dist/room/room-factory.d.ts +0 -7
  149. package/dist/room/room-factory.js +0 -16
  150. package/dist/room/room-message.module.d.ts +0 -2
  151. package/dist/room/room-message.module.js +0 -21
  152. package/dist/room/room-message.service.d.ts +0 -8
  153. package/dist/room/room-message.service.js +0 -44
  154. package/dist/room/room-store.module.d.ts +0 -2
  155. package/dist/room/room-store.module.js +0 -25
  156. package/dist/room/room-store.service.d.ts +0 -38
  157. package/dist/room/room-store.service.js +0 -353
  158. package/dist/room/room.d.ts +0 -107
  159. package/dist/room/room.js +0 -833
  160. package/dist/sdk/briyah-config.d.ts +0 -13
  161. package/dist/sdk/briyah-config.js +0 -32
  162. package/dist/sdk/briyah.d.ts +0 -36
  163. package/dist/sdk/briyah.js +0 -122
  164. package/dist/sdk/index.d.ts +0 -6
  165. package/dist/sdk/index.js +0 -11
  166. package/dist/shared/shared.module.d.ts +0 -2
  167. package/dist/shared/shared.module.js +0 -46
  168. package/dist/story/story-message.service.d.ts +0 -10
  169. package/dist/story/story-message.service.js +0 -57
  170. package/dist/story/story-progress.service.d.ts +0 -8
  171. package/dist/story/story-progress.service.js +0 -44
  172. package/dist/story/story-store.module.d.ts +0 -2
  173. package/dist/story/story-store.module.js +0 -22
  174. package/dist/story/story-store.service.d.ts +0 -23
  175. package/dist/story/story-store.service.js +0 -392
  176. package/dist/story/story.service.d.ts +0 -94
  177. package/dist/story/story.service.js +0 -1797
@@ -1,352 +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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- 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;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
- var __metadata = (this && this.__metadata) || function (k, v) {
42
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.AgentStoreService = void 0;
46
- const common_1 = require("@nestjs/common");
47
- const agent_1 = require("./agent");
48
- const crypto_1 = require("crypto");
49
- const fs = __importStar(require("fs"));
50
- const path = __importStar(require("path"));
51
- const ai_factory_service_1 = require("./ai-factory.service");
52
- const artifact_service_1 = require("./artifact.service");
53
- const configuration_service_1 = require("../config/configuration.service");
54
- const attached_file_service_1 = require("./attached-file.service");
55
- const balance_service_1 = require("../app/balance.service");
56
- let AgentStoreService = class AgentStoreService {
57
- aiFactoryService;
58
- configService;
59
- attachedFileService;
60
- balanceService;
61
- artifactService;
62
- agents = new Map();
63
- defaultStorageDir;
64
- loaded = false;
65
- loadPromise = null;
66
- constructor(aiFactoryService, configService, attachedFileService, balanceService, artifactService) {
67
- this.aiFactoryService = aiFactoryService;
68
- this.configService = configService;
69
- this.attachedFileService = attachedFileService;
70
- this.balanceService = balanceService;
71
- this.artifactService = artifactService;
72
- this.defaultStorageDir = path.join(this.configService.getUserDataDir(), 'agents');
73
- }
74
- getDefaultStorageDir() {
75
- return this.defaultStorageDir;
76
- }
77
- storeAgent(agent, storageDir) {
78
- if (!agent.id) {
79
- agent.id = (0, crypto_1.randomUUID)();
80
- }
81
- this.agents.set(agent.id, agent);
82
- const finalStorageDir = storageDir || agent.storageDir;
83
- this.saveAgentToFile(agent, finalStorageDir);
84
- return agent.id;
85
- }
86
- async getAgent(id) {
87
- await this.ensureLoaded();
88
- return this.agents.get(id);
89
- }
90
- removeAgent(id) {
91
- const agent = this.agents.get(id);
92
- if (!agent) {
93
- return false;
94
- }
95
- if (agent.aiService) {
96
- try {
97
- agent.aiService.finishAgent(agent);
98
- }
99
- catch (error) {
100
- console.error(`Error finishing agent ${id}:`, error);
101
- }
102
- }
103
- this.attachedFileService.deleteAllFiles(agent.id);
104
- const result = this.agents.delete(id);
105
- if (result) {
106
- this.deleteAgentFile(id, agent.storageDir);
107
- }
108
- return result;
109
- }
110
- async getAllAgentIds() {
111
- await this.ensureLoaded();
112
- return Array.from(this.agents.keys());
113
- }
114
- async getAgentCount() {
115
- await this.ensureLoaded();
116
- return this.agents.size;
117
- }
118
- async cloneAgentAsPublished(templateId, publishedName, _userId) {
119
- await this.ensureLoaded();
120
- const template = this.agents.get(templateId);
121
- if (!template) {
122
- throw new Error(`Template agent not found: ${templateId}`);
123
- }
124
- const instanceId = (0, crypto_1.randomUUID)();
125
- const aiService = this.aiFactoryService.createAiService(template.serviceName);
126
- const instance = new agent_1.Agent(instanceId, this.configService, this, this.balanceService, this.artifactService, publishedName, template.agentNickname || template.agentName, template.description, template.promptFolder, template.systemInstruction, [], template.modelName, template.serviceName, aiService, template.reasoningEffort, template.allowSearch, template.maxOutputTokens, template.beginInstruction, this.defaultStorageDir);
127
- instance.templateAgentId = templateId;
128
- instance.isPublished = true;
129
- instance.createdAt = new Date();
130
- instance.totalInputTokens = 0;
131
- instance.totalOutputTokens = 0;
132
- instance.totalCost = 0;
133
- instance.totalMarkup = 0;
134
- instance.attachedFiles = [...template.attachedFiles];
135
- instance.attachedArtifacts = [...template.attachedArtifacts];
136
- instance.maxHistoryMessages = template.maxHistoryMessages;
137
- instance.promptCacheTTL = template.promptCacheTTL;
138
- instance.markupRate = template.markupRate;
139
- this.storeAgent(instance);
140
- return instanceId;
141
- }
142
- async getPublishedInstances(templateId) {
143
- await this.ensureLoaded();
144
- const instances = [];
145
- for (const agent of this.agents.values()) {
146
- if (agent.templateAgentId === templateId) {
147
- instances.push(agent);
148
- }
149
- }
150
- return instances;
151
- }
152
- async resetPublishedInstance(instanceId, templateId) {
153
- await this.ensureLoaded();
154
- const instance = this.agents.get(instanceId);
155
- if (!instance) {
156
- throw new Error(`Instance agent not found: ${instanceId}`);
157
- }
158
- const template = this.agents.get(templateId);
159
- if (!template) {
160
- throw new Error(`Template agent not found: ${templateId}`);
161
- }
162
- if (instance.templateAgentId !== templateId) {
163
- throw new Error(`Instance ${instanceId} does not belong to template ${templateId}`);
164
- }
165
- instance.description = template.description;
166
- instance.agentNickname = template.agentNickname;
167
- instance.promptFolder = template.promptFolder;
168
- instance.systemInstruction = template.systemInstruction;
169
- instance.modelName = template.modelName;
170
- instance.serviceName = template.serviceName;
171
- instance.reasoningEffort = template.reasoningEffort;
172
- instance.allowSearch = template.allowSearch;
173
- instance.maxOutputTokens = template.maxOutputTokens;
174
- instance.attachedFiles = [...template.attachedFiles];
175
- instance.attachedArtifacts = [...template.attachedArtifacts];
176
- instance.beginInstruction = template.beginInstruction;
177
- instance.maxHistoryMessages = template.maxHistoryMessages;
178
- instance.promptCacheTTL = template.promptCacheTTL;
179
- instance.markupRate = template.markupRate;
180
- instance.history = [];
181
- instance.totalInputTokens = 0;
182
- instance.totalOutputTokens = 0;
183
- instance.totalCost = 0;
184
- instance.totalMarkup = 0;
185
- instance.aiService = this.aiFactoryService.createAiService(instance.serviceName);
186
- this.storeAgent(instance);
187
- }
188
- async ensureLoaded() {
189
- if (this.loaded)
190
- return;
191
- if (!this.loadPromise) {
192
- this.loadPromise = this.loadAgentsFromDirectory(this.defaultStorageDir)
193
- .then(() => {
194
- this.loaded = true;
195
- })
196
- .catch((error) => {
197
- this.loadPromise = null;
198
- throw error;
199
- });
200
- }
201
- await this.loadPromise;
202
- }
203
- async loadAgentsFromDirectory(storageDir, artifactService) {
204
- try {
205
- try {
206
- await fs.promises.access(storageDir);
207
- }
208
- catch {
209
- console.log(`Agent storage directory not found: ${storageDir}`);
210
- await fs.promises.mkdir(storageDir, { recursive: true });
211
- return;
212
- }
213
- const allFiles = await fs.promises.readdir(storageDir);
214
- const files = allFiles.filter((file) => file.endsWith('.json'));
215
- console.log(`Loading ${files.length} agents from ${storageDir}`);
216
- for (const file of files) {
217
- try {
218
- const filePath = path.join(storageDir, file);
219
- const fileContent = await fs.promises.readFile(filePath, 'utf-8');
220
- const config = JSON.parse(fileContent);
221
- if (this.agents.has(config.id)) {
222
- console.log(`Agent ${config.agentName} (${config.id}) already loaded, skipping`);
223
- continue;
224
- }
225
- const aiService = this.aiFactoryService.createAiService(config.serviceName);
226
- const finalArtifactService = artifactService || this.artifactService;
227
- const agent = new agent_1.Agent(config.id, this.configService, this, this.balanceService, finalArtifactService, config.agentName, config.agentNickname || config.agentName, config.description, config.promptFolder, config.systemInstruction, config.history || [], config.modelName, config.serviceName, aiService, config.reasoningEffort, config.allowSearch, config.maxOutputTokens, config.beginInstruction || '', storageDir);
228
- agent.createdAt = new Date(config.createdAt);
229
- agent.configService = this.configService;
230
- agent.totalInputTokens = config.totalInputTokens || 0;
231
- agent.totalOutputTokens = config.totalOutputTokens || 0;
232
- agent.totalCost = config.totalCost || 0;
233
- agent.totalMarkup = config.totalMarkup || 0;
234
- agent.markupRate =
235
- config.markupRate ??
236
- (process.env.DEFAULT_MARKUP_RATE
237
- ? parseFloat(process.env.DEFAULT_MARKUP_RATE)
238
- : 2);
239
- agent.isControlledByHuman = config.isControlledByHuman || false;
240
- agent.disableMarkup = config.disableMarkup || false;
241
- agent.disableBalanceCheck = config.disableBalanceCheck || false;
242
- agent.isPublished = config.isPublished || false;
243
- agent.templateAgentId = config.templateAgentId;
244
- agent.ownerRoomId = config.ownerRoomId;
245
- agent.beginInstruction = config.beginInstruction || '';
246
- agent.maxHistoryMessages = config.maxHistoryMessages || undefined;
247
- agent.promptCacheTTL = Number(config.promptCacheTTL) ?? 0;
248
- agent.id = config.id;
249
- this.agents.set(config.id, agent);
250
- if (config.attachedFiles && config.attachedFiles.length > 0) {
251
- agent.attachedFiles = config.attachedFiles;
252
- }
253
- else {
254
- const fileMetadataList = this.attachedFileService.listFileMetadata(agent.id);
255
- agent.attachedFiles = fileMetadataList;
256
- }
257
- for (const metadata of agent.attachedFiles) {
258
- const fileData = this.attachedFileService.getFile(agent.id, metadata.fileId);
259
- if (fileData && metadata.serviceMetadata && agent.fullContextFiles) {
260
- metadata.serviceMetadata.fileData = Array.from(fileData);
261
- console.log(`Restored fileData for ${metadata.fileName} (fullContextFiles=true)`);
262
- }
263
- }
264
- if (config.attachedArtifacts && config.attachedArtifacts.length > 0) {
265
- agent.attachedArtifacts = config.attachedArtifacts;
266
- }
267
- console.log(`Loaded agent: ${config.agentName} (${config.id}) with ${agent.history.length} history items`);
268
- }
269
- catch (error) {
270
- console.error(`Error loading agent from file ${file}:`, error);
271
- }
272
- }
273
- }
274
- catch (error) {
275
- console.error(`Error loading agents from directory ${storageDir}:`, error);
276
- }
277
- }
278
- saveAgentToFile(agent, storageDir) {
279
- try {
280
- if (!fs.existsSync(storageDir)) {
281
- fs.mkdirSync(storageDir, { recursive: true });
282
- }
283
- let attachedFilesWithoutFileData = agent.attachedFiles.map((file) => {
284
- if (file.serviceMetadata?.fileData) {
285
- const { fileData: _fileData, ...serviceMetadataWithoutFileData } = file.serviceMetadata;
286
- return {
287
- ...file,
288
- serviceMetadata: serviceMetadataWithoutFileData,
289
- };
290
- }
291
- return file;
292
- });
293
- const config = {
294
- id: agent.id,
295
- agentName: agent.agentName,
296
- agentNickname: agent.agentNickname,
297
- description: agent.description,
298
- promptFolder: agent.promptFolder,
299
- systemInstruction: agent.systemInstruction,
300
- modelName: agent.modelName,
301
- serviceName: agent.serviceName,
302
- reasoningEffort: agent.reasoningEffort,
303
- allowSearch: agent.allowSearch,
304
- maxOutputTokens: agent.maxOutputTokens,
305
- createdAt: agent.createdAt.toISOString(),
306
- attachedFiles: attachedFilesWithoutFileData,
307
- attachedArtifacts: agent.attachedArtifacts,
308
- history: agent.history,
309
- maxHistoryMessages: agent.maxHistoryMessages,
310
- totalInputTokens: agent.totalInputTokens,
311
- totalOutputTokens: agent.totalOutputTokens,
312
- totalCost: agent.totalCost,
313
- totalMarkup: agent.totalMarkup,
314
- markupRate: agent.markupRate,
315
- disableMarkup: agent.disableMarkup,
316
- disableBalanceCheck: agent.disableBalanceCheck,
317
- isControlledByHuman: agent.isControlledByHuman,
318
- isPublished: agent.isPublished,
319
- templateAgentId: agent.templateAgentId,
320
- beginInstruction: agent.beginInstruction,
321
- promptCacheTTL: agent.promptCacheTTL,
322
- ownerRoomId: agent.ownerRoomId,
323
- };
324
- const filePath = path.join(storageDir, `${agent.id}.json`);
325
- fs.writeFileSync(filePath, JSON.stringify(config, null, 2), 'utf-8');
326
- }
327
- catch (error) {
328
- console.error(`Error saving agent ${agent.id} to file:`, error);
329
- }
330
- }
331
- deleteAgentFile(agentId, storageDir) {
332
- try {
333
- const filePath = path.join(storageDir, `${agentId}.json`);
334
- if (fs.existsSync(filePath)) {
335
- fs.unlinkSync(filePath);
336
- console.log(`Deleted agent file: ${filePath}`);
337
- }
338
- }
339
- catch (error) {
340
- console.error(`Error deleting agent file ${agentId}:`, error);
341
- }
342
- }
343
- };
344
- exports.AgentStoreService = AgentStoreService;
345
- exports.AgentStoreService = AgentStoreService = __decorate([
346
- (0, common_1.Injectable)(),
347
- __metadata("design:paramtypes", [ai_factory_service_1.AiFactoryService,
348
- configuration_service_1.ConfigurationService,
349
- attached_file_service_1.AttachedFileService,
350
- balance_service_1.BalanceService,
351
- artifact_service_1.ArtifactService])
352
- ], AgentStoreService);
@@ -1,75 +0,0 @@
1
- import { OpenAI } from 'openai';
2
- import { Assistant } from 'openai/resources/beta/assistants';
3
- import { VectorStore } from 'openai/resources/vector-stores';
4
- import { Message } from '../shared/types/app.types';
5
- import { BaseAiService } from './LLM/base-ai.service';
6
- import { FileMetadata } from './attached-file.service';
7
- import { ArtifactService } from './artifact.service';
8
- import { ConfigurationService } from '../config/configuration.service';
9
- import { BalanceService } from '../app/balance.service';
10
- import { AgentStoreService } from './agent-store.service';
11
- export declare class Agent {
12
- id?: string;
13
- agentName: string;
14
- agentNickname: string;
15
- history: any[];
16
- fullContextFiles: boolean;
17
- static generateNickname(agentName: string): string;
18
- createdAt: Date;
19
- totalInputTokens: number;
20
- totalOutputTokens: number;
21
- totalCost: number;
22
- totalMarkup: number;
23
- markupRate: number;
24
- disableMarkup: boolean;
25
- disableBalanceCheck: boolean;
26
- isPublished: boolean;
27
- templateAgentId?: string;
28
- ownerRoomId?: string;
29
- openai?: OpenAI;
30
- assistant?: Assistant;
31
- vectorStore?: VectorStore;
32
- aiService: BaseAiService;
33
- artifactService: ArtifactService;
34
- configService: ConfigurationService;
35
- balanceService?: BalanceService;
36
- description: string;
37
- promptFolder: string;
38
- systemInstruction: string;
39
- maxHistoryMessages?: number;
40
- modelName: string;
41
- serviceName: string;
42
- reasoningEffort: 'low' | 'medium' | 'high' | null;
43
- allowSearch: boolean;
44
- maxOutputTokens: number;
45
- attachedFiles: FileMetadata[];
46
- attachedArtifacts: string[];
47
- isControlledByHuman: boolean;
48
- beginInstruction: string;
49
- promptCacheTTL: number;
50
- private onStateChange;
51
- storageDir: string;
52
- private agentStoreService;
53
- constructor(id: string | null, configService: ConfigurationService, agentStoreService: AgentStoreService, balanceService: BalanceService, artifactService: ArtifactService, agentName: string, agentNickname: string, description: string, promptFolder: string, systemInstruction: string, history: any[], modelName: string, serviceName: string, aiService: BaseAiService, reasoningEffort: 'low' | 'medium' | 'high' | null, allowSearch: boolean, maxOutputTokens: number, beginInstruction: string, storageDir: string);
54
- attachDocument(fileName: string, fileData: Uint8Array): Promise<string>;
55
- attachArtifact(artifactId: string): void;
56
- detachArtifact(artifactId: string): void;
57
- getAttachedArtifacts(): string[];
58
- save(): void;
59
- finishAgent(): Promise<void>;
60
- deleteAgent(): Promise<void>;
61
- setOnStateChange(callback: () => void): void;
62
- notifyStateChange(): void;
63
- canRespond(message: Message): boolean;
64
- getFormattedMessages(fromIndex?: number): string[];
65
- getRawMessages(): string[];
66
- addToConversationHistory(message: any, fromSelf?: boolean): void;
67
- trimHistoryIfNeeded(threshold?: number): void;
68
- instructedPrompt(prompt: string, instructionFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
69
- preparedPrompt(promptFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean): Promise<any>;
70
- textPrompt(prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
71
- generateImage(prompt: string, width: number, height: number, quality: string, referenceImageArtifactIds?: string[]): Promise<{
72
- artifactId?: string;
73
- error?: any;
74
- }>;
75
- }
package/dist/ai/agent.js DELETED
@@ -1,174 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Agent = void 0;
4
- const app_types_1 = require("../shared/types/app.types");
5
- const crypto_1 = require("crypto");
6
- class Agent {
7
- id;
8
- agentName;
9
- agentNickname;
10
- history;
11
- fullContextFiles = true;
12
- static generateNickname(agentName) {
13
- const firstName = agentName.trim().split(/\s+/)[0];
14
- return firstName || agentName;
15
- }
16
- createdAt;
17
- totalInputTokens = 0;
18
- totalOutputTokens = 0;
19
- totalCost = 0;
20
- totalMarkup = 0;
21
- markupRate = 2;
22
- disableMarkup = false;
23
- disableBalanceCheck = false;
24
- isPublished = false;
25
- templateAgentId;
26
- ownerRoomId;
27
- openai;
28
- assistant;
29
- vectorStore;
30
- aiService;
31
- artifactService;
32
- configService;
33
- balanceService;
34
- description;
35
- promptFolder;
36
- systemInstruction;
37
- maxHistoryMessages;
38
- modelName;
39
- serviceName;
40
- reasoningEffort;
41
- allowSearch;
42
- maxOutputTokens = 0;
43
- attachedFiles = [];
44
- attachedArtifacts = [];
45
- isControlledByHuman = false;
46
- beginInstruction = '';
47
- promptCacheTTL = 0;
48
- onStateChange = null;
49
- storageDir;
50
- agentStoreService;
51
- constructor(id, configService, agentStoreService, balanceService, artifactService, agentName = '', agentNickname = '', description = '', promptFolder = '', systemInstruction = '', history = [], modelName = '', serviceName = '', aiService, reasoningEffort = null, allowSearch = false, maxOutputTokens = 0, beginInstruction = '', storageDir) {
52
- this.agentName = agentName;
53
- this.agentNickname = agentNickname || Agent.generateNickname(agentName);
54
- this.description = description;
55
- this.promptFolder = promptFolder;
56
- this.systemInstruction = systemInstruction;
57
- this.history = history;
58
- this.openai = null;
59
- this.assistant = null;
60
- this.vectorStore = null;
61
- this.fullContextFiles = true;
62
- this.createdAt = new Date();
63
- this.modelName = modelName;
64
- this.serviceName = serviceName;
65
- this.aiService = aiService;
66
- this.reasoningEffort = reasoningEffort;
67
- this.allowSearch = allowSearch;
68
- this.maxOutputTokens = maxOutputTokens;
69
- this.beginInstruction = beginInstruction;
70
- this.storageDir = storageDir;
71
- this.configService = configService;
72
- this.agentStoreService = agentStoreService;
73
- this.balanceService = balanceService;
74
- this.artifactService = artifactService;
75
- this.id = id ? id : (0, crypto_1.randomUUID)();
76
- }
77
- async attachDocument(fileName, fileData) {
78
- return await this.aiService.attachDocument(this, fileName, fileData);
79
- }
80
- attachArtifact(artifactId) {
81
- if (!this.attachedArtifacts.includes(artifactId)) {
82
- this.attachedArtifacts.push(artifactId);
83
- }
84
- }
85
- detachArtifact(artifactId) {
86
- this.attachedArtifacts = this.attachedArtifacts.filter((id) => id !== artifactId);
87
- }
88
- getAttachedArtifacts() {
89
- return [...this.attachedArtifacts];
90
- }
91
- save() {
92
- this.agentStoreService.storeAgent(this);
93
- this.notifyStateChange();
94
- }
95
- async finishAgent() {
96
- this.agentStoreService.removeAgent(this);
97
- }
98
- async deleteAgent() {
99
- this.agentStoreService.removeAgent(this.id);
100
- }
101
- setOnStateChange(callback) {
102
- this.onStateChange = callback;
103
- }
104
- notifyStateChange() {
105
- if (this.onStateChange) {
106
- this.onStateChange();
107
- }
108
- }
109
- canRespond(message) {
110
- if (!this.isControlledByHuman)
111
- return true;
112
- return message.targets.includes(this.agentNickname);
113
- }
114
- getFormattedMessages(fromIndex = 0) {
115
- if (!this.history) {
116
- return [];
117
- }
118
- return this.history
119
- .slice(fromIndex)
120
- .map((message) => this.aiService.formatMessage(message));
121
- }
122
- getRawMessages() {
123
- if (!this.history) {
124
- return [];
125
- }
126
- return this.history.map((message) => message.content);
127
- }
128
- addToConversationHistory(message, fromSelf = false) {
129
- let formattedMessage = message;
130
- if (typeof message === 'object') {
131
- if (message.action && message.action == app_types_1.MessageAction.MODERATE) {
132
- formattedMessage = `From: ${message.sender}\n${message.content}`;
133
- }
134
- else {
135
- formattedMessage = JSON.stringify(message, null, 2);
136
- }
137
- }
138
- this.aiService.addToConversationHistory(this, formattedMessage, fromSelf);
139
- }
140
- trimHistoryIfNeeded(threshold = 0) {
141
- if (!this.maxHistoryMessages)
142
- return;
143
- let systemMessageCount = 0;
144
- for (let i = 0; i < this.history.length; i++) {
145
- if (this.history[i].role === 'developer') {
146
- systemMessageCount++;
147
- }
148
- else if (this.history[i].content.includes('[CONVERSATION HISTORY SUMMARY]')) {
149
- systemMessageCount++;
150
- }
151
- else {
152
- break;
153
- }
154
- }
155
- const conversationMessages = this.history.slice(systemMessageCount);
156
- if (conversationMessages.length > this.maxHistoryMessages + threshold) {
157
- const keepMessages = conversationMessages.slice(-this.maxHistoryMessages);
158
- this.history = [...this.history.slice(0, systemMessageCount), ...keepMessages];
159
- }
160
- }
161
- async instructedPrompt(prompt, instructionFileName, variables, saveResponse = true, cacheMessage = false, maxOutputChars = 0) {
162
- return await this.aiService.instructedPrompt(this, prompt, instructionFileName, variables, saveResponse, this.aiService.getCacheConfig(this, cacheMessage), maxOutputChars);
163
- }
164
- async preparedPrompt(promptFileName, variables, saveResponse = true, cacheMessage = false) {
165
- return await this.aiService.preparedPrompt(this, promptFileName, variables, saveResponse, this.aiService.getCacheConfig(this, cacheMessage));
166
- }
167
- async textPrompt(prompt, jsonSchema = null, saveResponse = true, promptInstructions = null, cacheMessage = false, maxOutputChars = 0) {
168
- return await this.aiService.textPrompt(this, prompt, jsonSchema, saveResponse, promptInstructions, this.aiService.getCacheConfig(this, cacheMessage), maxOutputChars);
169
- }
170
- async generateImage(prompt, width, height, quality, referenceImageArtifactIds) {
171
- return await this.aiService.generateImage(this, prompt, width, height, quality, referenceImageArtifactIds);
172
- }
173
- }
174
- exports.Agent = Agent;
@@ -1,2 +0,0 @@
1
- export declare class AiFactoryModule {
2
- }
@@ -1,40 +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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AiFactoryModule = void 0;
10
- const common_1 = require("@nestjs/common");
11
- const ai_factory_service_1 = require("./ai-factory.service");
12
- const openai_module_1 = require("./LLM/openai.module");
13
- const grok_module_1 = require("./LLM/grok.module");
14
- const vertexai_module_1 = require("./LLM/vertexai.module");
15
- const anthropic_module_1 = require("./LLM/anthropic.module");
16
- const deepseek_module_1 = require("./LLM/deepseek.module");
17
- const together_module_1 = require("./LLM/together.module");
18
- const mock_module_1 = require("./LLM/mock.module");
19
- const googleai_module_1 = require("./LLM/googleai.module");
20
- const fal_module_1 = require("./LLM/fal.module");
21
- let AiFactoryModule = class AiFactoryModule {
22
- };
23
- exports.AiFactoryModule = AiFactoryModule;
24
- exports.AiFactoryModule = AiFactoryModule = __decorate([
25
- (0, common_1.Module)({
26
- imports: [
27
- openai_module_1.OpenAiModule,
28
- grok_module_1.GrokAiModule,
29
- vertexai_module_1.VertexAiModule,
30
- anthropic_module_1.AnthropicAiModule,
31
- deepseek_module_1.DeepSeekAiModule,
32
- together_module_1.TogetherAiModule,
33
- mock_module_1.MockAiModule,
34
- googleai_module_1.GoogleAiModule,
35
- fal_module_1.FalAiModule,
36
- ],
37
- providers: [ai_factory_service_1.AiFactoryService],
38
- exports: [ai_factory_service_1.AiFactoryService],
39
- })
40
- ], AiFactoryModule);
@@ -1,24 +0,0 @@
1
- import { BaseAiService } from './LLM/base-ai.service';
2
- import { OpenAiService } from './LLM/openai.service';
3
- import { GrokAiService } from './LLM/grok.service';
4
- import { VertexAiService } from './LLM/vertexai.service';
5
- import { AnthropicAiService } from './LLM/anthropic.service';
6
- import { DeepSeekAiService } from './LLM/deepseek.service';
7
- import { TogetherAiService } from './LLM/together.service';
8
- import { MockAiService } from './LLM/mock.service';
9
- import { GoogleAiService } from './LLM/googleai.service';
10
- import { FalAiService } from './LLM/fal.service';
11
- export declare class AiFactoryService {
12
- private readonly openAiService;
13
- private readonly grokAiService;
14
- private readonly vertexAiService;
15
- private readonly anthropicAiService;
16
- private readonly deepSeekAiService;
17
- private readonly togetherAiService;
18
- private readonly mockAiService;
19
- private readonly googleAiService;
20
- private readonly falAiService;
21
- constructor(openAiService: OpenAiService, grokAiService: GrokAiService, vertexAiService: VertexAiService, anthropicAiService: AnthropicAiService, deepSeekAiService: DeepSeekAiService, togetherAiService: TogetherAiService, mockAiService: MockAiService, googleAiService: GoogleAiService, falAiService: FalAiService);
22
- createAiService(serviceName: string): BaseAiService;
23
- getAllAiServices(): BaseAiService[];
24
- }