briyah 1.1.8 → 1.2.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 (116) hide show
  1. package/data/common/config/markup +1 -1
  2. package/data/common/config/model_prices.json +3775 -653
  3. package/data/common/prompts/character/create_character.json +33 -29
  4. package/data/common/prompts/character/create_character.prompt +13 -2
  5. package/data/common/prompts/character/create_user_character.json +32 -28
  6. package/data/common/prompts/character/create_user_character.prompt +13 -2
  7. package/data/common/prompts/character/progress_character.json +22 -18
  8. package/data/common/prompts/character/progress_character.prompt +6 -2
  9. package/data/common/prompts/illustrator/describe_character.prompt +31 -0
  10. package/data/common/prompts/illustrator/describe_scene.json +19 -1
  11. package/data/common/prompts/illustrator/describe_scene.prompt +2 -1
  12. package/data/common/prompts/narrator/perceive.prompt +96 -35
  13. package/data/common/prompts/story_moderator/moderate.json +33 -7
  14. package/data/common/prompts/story_moderator/moderate.prompt +166 -20
  15. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +5 -2
  16. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +27 -15
  17. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +6 -2
  18. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +20 -10
  19. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +10 -0
  20. package/dist-sdk/server/src/ai/LLM/googleai.service.js +11 -8
  21. package/dist-sdk/server/src/ai/LLM/grok.service.js +8 -5
  22. package/dist-sdk/server/src/ai/LLM/openai.service.js +12 -11
  23. package/dist-sdk/server/src/ai/LLM/together.service.js +9 -6
  24. package/dist-sdk/server/src/ai/agent-factory.d.ts +5 -3
  25. package/dist-sdk/server/src/ai/agent-factory.js +6 -4
  26. package/dist-sdk/server/src/ai/agent-store.service.d.ts +5 -3
  27. package/dist-sdk/server/src/ai/agent-store.service.js +15 -15
  28. package/dist-sdk/server/src/ai/agent.d.ts +9 -6
  29. package/dist-sdk/server/src/ai/agent.js +22 -6
  30. package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +10 -0
  31. package/dist-sdk/server/src/ai/ai-debug-logger.js +82 -0
  32. package/dist-sdk/server/src/ai/artifact.module.js +2 -2
  33. package/dist-sdk/server/src/ai/artifact.service.d.ts +3 -3
  34. package/dist-sdk/server/src/ai/artifact.service.js +6 -6
  35. package/dist-sdk/server/src/ai/attached-file.module.js +2 -2
  36. package/dist-sdk/server/src/ai/attached-file.service.d.ts +3 -3
  37. package/dist-sdk/server/src/ai/attached-file.service.js +6 -6
  38. package/dist-sdk/server/src/app/balance.service.d.ts +3 -3
  39. package/dist-sdk/server/src/app/balance.service.js +7 -7
  40. package/dist-sdk/server/src/app/transaction.service.d.ts +3 -3
  41. package/dist-sdk/server/src/app/transaction.service.js +4 -4
  42. package/dist-sdk/server/src/app/user-service-factory.d.ts +3 -1
  43. package/dist-sdk/server/src/app/user-service-factory.js +18 -14
  44. package/dist-sdk/server/src/app/user-service-manager.d.ts +1 -3
  45. package/dist-sdk/server/src/app.service.d.ts +3 -3
  46. package/dist-sdk/server/src/app.service.js +30 -30
  47. package/dist-sdk/server/src/config/env-config.d.ts +3 -0
  48. package/dist-sdk/server/src/config/env-config.js +2 -0
  49. package/dist-sdk/server/src/config/user-paths.module.d.ts +2 -0
  50. package/dist-sdk/server/src/config/{configuration.module.js → user-paths.module.js} +8 -8
  51. package/dist-sdk/server/src/config/{configuration.service.d.ts → user-paths.service.d.ts} +1 -1
  52. package/dist-sdk/server/src/config/{configuration.service.js → user-paths.service.js} +3 -3
  53. package/dist-sdk/server/src/room/message.d.ts +1 -1
  54. package/dist-sdk/server/src/room/message.js +1 -1
  55. package/dist-sdk/server/src/room/room-store.module.js +2 -2
  56. package/dist-sdk/server/src/room/room-store.service.d.ts +3 -3
  57. package/dist-sdk/server/src/room/room-store.service.js +6 -6
  58. package/dist-sdk/server/src/room/room.d.ts +1 -0
  59. package/dist-sdk/server/src/room/room.js +43 -19
  60. package/dist-sdk/server/src/sdk/briyah-config.d.ts +2 -1
  61. package/dist-sdk/server/src/sdk/briyah-config.js +4 -0
  62. package/dist-sdk/server/src/sdk/briyah.js +1 -1
  63. package/dist-sdk/server/src/story/story-store.service.d.ts +3 -3
  64. package/dist-sdk/server/src/story/story-store.service.js +6 -6
  65. package/dist-sdk/server/src/story/story.service.d.ts +10 -3
  66. package/dist-sdk/server/src/story/story.service.js +233 -99
  67. package/dist-sdk/shared/types/app.types.d.ts +1 -0
  68. package/docs/assets/hierarchy.js +1 -1
  69. package/docs/assets/search.js +1 -1
  70. package/docs/classes/Agent.html +16 -16
  71. package/docs/classes/Briyah.html +12 -12
  72. package/docs/classes/BriyahConfigService.html +5 -5
  73. package/docs/classes/Room.html +24 -24
  74. package/docs/classes/RoomMessage.html +11 -11
  75. package/docs/enums/MessageAction.html +3 -3
  76. package/docs/hierarchy.html +1 -1
  77. package/docs/index.html +2 -2
  78. package/docs/interfaces/AgentInfo.html +2 -2
  79. package/docs/interfaces/AgentMessagesResponse.html +2 -2
  80. package/docs/interfaces/AppService.html +154 -154
  81. package/docs/interfaces/Artifact.html +3 -3
  82. package/docs/interfaces/ArtifactMetadata.html +2 -2
  83. package/docs/interfaces/AttachDocumentResponse.html +2 -2
  84. package/docs/interfaces/BriyahConfigOptions.html +7 -7
  85. package/docs/interfaces/ChapterInfo.html +2 -2
  86. package/docs/interfaces/Character.html +2 -2
  87. package/docs/interfaces/CreateAgentResponse.html +2 -2
  88. package/docs/interfaces/CreateRoomResponse.html +2 -2
  89. package/docs/interfaces/CreateStoryResponse.html +2 -2
  90. package/docs/interfaces/FileList.html +2 -2
  91. package/docs/interfaces/LoggingOptions.html +10 -6
  92. package/docs/interfaces/Message.html +2 -2
  93. package/docs/interfaces/ModelInfo.html +2 -2
  94. package/docs/interfaces/PreparedPromptResponse.html +2 -2
  95. package/docs/interfaces/ProcessTextResponse.html +2 -2
  96. package/docs/interfaces/PromptFile.html +2 -2
  97. package/docs/interfaces/PromptFileContent.html +2 -2
  98. package/docs/interfaces/PromptFilesResponse.html +2 -2
  99. package/docs/interfaces/PromptFolder.html +2 -2
  100. package/docs/interfaces/PromptFoldersResponse.html +2 -2
  101. package/docs/interfaces/RoomDetails.html +2 -2
  102. package/docs/interfaces/RoomInfo.html +2 -2
  103. package/docs/interfaces/RoomMessagesResponse.html +2 -2
  104. package/docs/interfaces/StoryErrorEvent.html +3 -3
  105. package/docs/interfaces/StoryIdea.html +2 -2
  106. package/docs/interfaces/StoryInfo.html +3 -3
  107. package/docs/interfaces/StoryIntroduceCharacterEvent.html +3 -3
  108. package/docs/interfaces/StoryProgressChapterEvent.html +3 -3
  109. package/docs/interfaces/StoryState.html +5 -5
  110. package/docs/interfaces/StoryStateEvent.html +3 -3
  111. package/docs/interfaces/Transaction.html +2 -2
  112. package/docs/interfaces/TransactionHistoryResponse.html +2 -2
  113. package/docs/modules.html +1 -1
  114. package/docs/types/PromptScope.html +1 -1
  115. package/package.json +2 -1
  116. package/dist-sdk/server/src/config/configuration.module.d.ts +0 -2
@@ -161,20 +161,20 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
161
161
  type: 'text',
162
162
  };
163
163
  let instructions = promptInstructions || agent.systemInstruction;
164
+ const requestParams = {
165
+ model: agent.modelName,
166
+ reasoning: { effort: agent.reasoningEffort },
167
+ input: messages,
168
+ instructions: instructions,
169
+ store: false,
170
+ text: { format: format },
171
+ tools: tools,
172
+ };
173
+ this.debugLogRequest(agent.agentName, requestParams);
164
174
  let response = null;
165
175
  let responseText;
166
176
  try {
167
- response = await this.openai.responses.create({
168
- model: agent.modelName,
169
- reasoning: { effort: agent.reasoningEffort },
170
- input: messages,
171
- instructions: instructions,
172
- store: false,
173
- text: {
174
- format: format,
175
- },
176
- tools: tools,
177
- });
177
+ response = await this.openai.responses.create(requestParams);
178
178
  if (jsonSchema) {
179
179
  responseText = this.trimToJson(response.output_text);
180
180
  responseText = this.sanitizeJsonString(responseText);
@@ -182,6 +182,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
182
182
  else {
183
183
  responseText = response.output_text;
184
184
  }
185
+ this.debugLogResponse(agent.agentName, responseText);
185
186
  if (response.usage) {
186
187
  this.computeMessageCost(agent, response.usage);
187
188
  }
@@ -120,14 +120,16 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
120
120
  },
121
121
  }
122
122
  : undefined;
123
+ const requestParams = {
124
+ model: agent.modelName,
125
+ messages: messages,
126
+ temperature: 0,
127
+ response_format: responseFormat,
128
+ };
129
+ this.debugLogRequest(agent.agentName, requestParams);
123
130
  let responseText;
124
131
  try {
125
- const response = await this.togetherClient.chat.completions.create({
126
- model: agent.modelName,
127
- messages: messages,
128
- temperature: 0,
129
- response_format: responseFormat,
130
- });
132
+ const response = await this.togetherClient.chat.completions.create(requestParams);
131
133
  if (response.choices && response.choices[0]?.message?.content) {
132
134
  responseText = response.choices[0].message.content;
133
135
  }
@@ -141,6 +143,7 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
141
143
  else {
142
144
  responseText = this.trimResponseText(responseText);
143
145
  }
146
+ this.debugLogResponse(agent.agentName, responseText);
144
147
  if (response.usage) {
145
148
  this.computeMessageCost(agent, response.usage);
146
149
  }
@@ -1,15 +1,17 @@
1
1
  import { AiFactoryService } from './ai-factory.service';
2
2
  import { AgentStoreService } from './agent-store.service';
3
3
  import { ArtifactService } from './artifact.service';
4
- import { ConfigurationService } from '../config/configuration.service';
4
+ import { UserPathsService } from '../config/user-paths.service';
5
+ import { IConfigService } from '../config/env-config';
5
6
  import { BalanceService } from '../app/balance.service';
6
7
  import { Agent } from './agent';
7
8
  export declare class AgentFactory {
8
9
  private readonly aiFactoryService;
9
10
  private readonly agentStoreService;
10
- private readonly configService;
11
+ private readonly userPaths;
11
12
  private readonly balanceService;
12
13
  private readonly artifactService;
13
- constructor(aiFactoryService: AiFactoryService, agentStoreService: AgentStoreService, configService: ConfigurationService, balanceService: BalanceService, artifactService: ArtifactService);
14
+ private readonly configService;
15
+ constructor(aiFactoryService: AiFactoryService, agentStoreService: AgentStoreService, userPaths: UserPathsService, balanceService: BalanceService, artifactService: ArtifactService, configService: IConfigService);
14
16
  createAgent(aiServiceName: string, agentName: string, agentNickname: string, description: string, promptFolder: string, modelName: string, storageDir?: string, artifactService?: ArtifactService): Agent;
15
17
  }
@@ -4,21 +4,23 @@ exports.AgentFactory = void 0;
4
4
  class AgentFactory {
5
5
  aiFactoryService;
6
6
  agentStoreService;
7
- configService;
7
+ userPaths;
8
8
  balanceService;
9
9
  artifactService;
10
- constructor(aiFactoryService, agentStoreService, configService, balanceService, artifactService) {
10
+ configService;
11
+ constructor(aiFactoryService, agentStoreService, userPaths, balanceService, artifactService, configService) {
11
12
  this.aiFactoryService = aiFactoryService;
12
13
  this.agentStoreService = agentStoreService;
13
- this.configService = configService;
14
+ this.userPaths = userPaths;
14
15
  this.balanceService = balanceService;
15
16
  this.artifactService = artifactService;
17
+ this.configService = configService;
16
18
  }
17
19
  createAgent(aiServiceName, agentName, agentNickname, description, promptFolder, modelName, storageDir = '', artifactService) {
18
20
  const aiService = this.aiFactoryService.createAiService(aiServiceName);
19
21
  const finalStorageDir = storageDir || this.agentStoreService.getDefaultStorageDir();
20
22
  const finalArtifactService = artifactService || this.artifactService;
21
- return aiService.createAgent(this.configService, this.agentStoreService, this.balanceService, finalArtifactService, agentName, agentNickname, description, promptFolder, modelName, finalStorageDir);
23
+ return aiService.createAgent(this.userPaths, this.configService, this.agentStoreService, this.balanceService, finalArtifactService, agentName, agentNickname, description, promptFolder, modelName, finalStorageDir);
22
24
  }
23
25
  }
24
26
  exports.AgentFactory = AgentFactory;
@@ -1,20 +1,22 @@
1
1
  import { Agent } from './agent';
2
2
  import { AiFactoryService } from './ai-factory.service';
3
3
  import { ArtifactService } from './artifact.service';
4
- import { ConfigurationService } from '../config/configuration.service';
4
+ import { UserPathsService } from '../config/user-paths.service';
5
+ import { IConfigService } from '../config/env-config';
5
6
  import { AttachedFileService } from './attached-file.service';
6
7
  import { BalanceService } from '../app/balance.service';
7
8
  export declare class AgentStoreService {
8
9
  private readonly aiFactoryService;
9
- private readonly configService;
10
+ private readonly userPaths;
10
11
  private readonly attachedFileService;
11
12
  private readonly balanceService;
12
13
  private readonly artifactService;
14
+ private readonly configService;
13
15
  private agents;
14
16
  private readonly defaultStorageDir;
15
17
  private loaded;
16
18
  private loadPromise;
17
- constructor(aiFactoryService: AiFactoryService, configService: ConfigurationService, attachedFileService: AttachedFileService, balanceService: BalanceService, artifactService: ArtifactService);
19
+ constructor(aiFactoryService: AiFactoryService, userPaths: UserPathsService, attachedFileService: AttachedFileService, balanceService: BalanceService, artifactService: ArtifactService, configService: IConfigService);
18
20
  getDefaultStorageDir(): string;
19
21
  registerAgent(agent: Agent): void;
20
22
  storeAgent(agent: Agent, storageDir?: string): string;
@@ -50,27 +50,29 @@ const fs = __importStar(require("fs"));
50
50
  const path = __importStar(require("path"));
51
51
  const ai_factory_service_1 = require("./ai-factory.service");
52
52
  const artifact_service_1 = require("./artifact.service");
53
- const configuration_service_1 = require("../config/configuration.service");
53
+ const user_paths_service_1 = require("../config/user-paths.service");
54
54
  const attached_file_service_1 = require("./attached-file.service");
55
55
  const balance_service_1 = require("../app/balance.service");
56
56
  const logger_1 = require("../common/logger");
57
57
  let AgentStoreService = class AgentStoreService {
58
58
  aiFactoryService;
59
- configService;
59
+ userPaths;
60
60
  attachedFileService;
61
61
  balanceService;
62
62
  artifactService;
63
+ configService;
63
64
  agents = new Map();
64
65
  defaultStorageDir;
65
66
  loaded = false;
66
67
  loadPromise = null;
67
- constructor(aiFactoryService, configService, attachedFileService, balanceService, artifactService) {
68
+ constructor(aiFactoryService, userPaths, attachedFileService, balanceService, artifactService, configService) {
68
69
  this.aiFactoryService = aiFactoryService;
69
- this.configService = configService;
70
+ this.userPaths = userPaths;
70
71
  this.attachedFileService = attachedFileService;
71
72
  this.balanceService = balanceService;
72
73
  this.artifactService = artifactService;
73
- this.defaultStorageDir = path.join(this.configService.getUserDataDir(), 'agents');
74
+ this.configService = configService;
75
+ this.defaultStorageDir = path.join(this.userPaths.getUserDataDir(), 'agents');
74
76
  }
75
77
  getDefaultStorageDir() {
76
78
  return this.defaultStorageDir;
@@ -130,7 +132,7 @@ let AgentStoreService = class AgentStoreService {
130
132
  }
131
133
  const instanceId = (0, crypto_1.randomUUID)();
132
134
  const aiService = this.aiFactoryService.createAiService(template.serviceName);
133
- 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);
135
+ const instance = new agent_1.Agent(instanceId, this.userPaths, 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);
134
136
  instance.templateAgentId = templateId;
135
137
  instance.isPublished = true;
136
138
  instance.createdAt = new Date();
@@ -233,19 +235,17 @@ let AgentStoreService = class AgentStoreService {
233
235
  }
234
236
  const aiService = this.aiFactoryService.createAiService(config.serviceName);
235
237
  const finalArtifactService = artifactService || this.artifactService;
236
- 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);
238
+ const agent = new agent_1.Agent(config.id, this.userPaths, 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);
237
239
  agent.createdAt = new Date(config.createdAt);
238
- agent.configService = this.configService;
240
+ agent.userPaths = this.userPaths;
239
241
  agent.smallModelName = config.smallModelName;
240
242
  agent.totalInputTokens = config.totalInputTokens || 0;
241
243
  agent.totalOutputTokens = config.totalOutputTokens || 0;
242
244
  agent.totalCost = config.totalCost || 0;
243
245
  agent.totalMarkup = config.totalMarkup || 0;
244
- agent.markupRate =
245
- config.markupRate ??
246
- (process.env.DEFAULT_MARKUP_RATE
247
- ? parseFloat(process.env.DEFAULT_MARKUP_RATE)
248
- : 2);
246
+ if (config.markupRate !== undefined) {
247
+ agent.markupRate = config.markupRate;
248
+ }
249
249
  agent.isControlledByHuman = config.isControlledByHuman || false;
250
250
  agent.disableMarkup = config.disableMarkup || false;
251
251
  agent.disableBalanceCheck = config.disableBalanceCheck || false;
@@ -356,8 +356,8 @@ exports.AgentStoreService = AgentStoreService;
356
356
  exports.AgentStoreService = AgentStoreService = __decorate([
357
357
  (0, common_1.Injectable)(),
358
358
  __metadata("design:paramtypes", [ai_factory_service_1.AiFactoryService,
359
- configuration_service_1.ConfigurationService,
359
+ user_paths_service_1.UserPathsService,
360
360
  attached_file_service_1.AttachedFileService,
361
361
  balance_service_1.BalanceService,
362
- artifact_service_1.ArtifactService])
362
+ artifact_service_1.ArtifactService, Object])
363
363
  ], AgentStoreService);
@@ -5,7 +5,8 @@ import { Message } from '../../../shared/types/app.types';
5
5
  import { BaseAiService } from './LLM/base-ai.service';
6
6
  import { FileMetadata } from './attached-file.service';
7
7
  import { ArtifactService } from './artifact.service';
8
- import { ConfigurationService } from '../config/configuration.service';
8
+ import { UserPathsService } from '../config/user-paths.service';
9
+ import { IConfigService } from '../config/env-config';
9
10
  import { BalanceService } from '../app/balance.service';
10
11
  import { AgentStoreService } from './agent-store.service';
11
12
  export declare class Agent {
@@ -31,7 +32,8 @@ export declare class Agent {
31
32
  vectorStore?: VectorStore;
32
33
  aiService: BaseAiService;
33
34
  artifactService: ArtifactService;
34
- configService: ConfigurationService;
35
+ userPaths: UserPathsService;
36
+ configService: IConfigService;
35
37
  balanceService?: BalanceService;
36
38
  description: string;
37
39
  promptFolder: string;
@@ -40,7 +42,6 @@ export declare class Agent {
40
42
  modelName: string;
41
43
  smallModelName?: string;
42
44
  serviceName: string;
43
- imageProperties?: Record<string, any>;
44
45
  reasoningEffort: 'low' | 'medium' | 'high' | null;
45
46
  allowSearch: boolean;
46
47
  maxOutputTokens: number;
@@ -52,7 +53,7 @@ export declare class Agent {
52
53
  private onStateChange;
53
54
  storageDir: string;
54
55
  private agentStoreService;
55
- 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);
56
+ constructor(id: string | null, userPaths: UserPathsService, configService: IConfigService, 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);
56
57
  attachDocument(fileName: string, fileData: Uint8Array): Promise<string>;
57
58
  attachArtifact(artifactId: string): void;
58
59
  detachArtifact(artifactId: string): void;
@@ -74,15 +75,17 @@ export declare class Agent {
74
75
  success: boolean;
75
76
  originalLength: number;
76
77
  newLength: number;
78
+ originalChars: number;
79
+ newChars: number;
77
80
  message: string;
78
81
  summary?: string;
79
82
  }>;
80
83
  textPrompt(prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
81
- generateImage(prompt: string): Promise<{
84
+ generateImage(prompt: string, imageProperties?: Record<string, any>): Promise<{
82
85
  artifactId?: string;
83
86
  error?: any;
84
87
  }>;
85
- editImage(prompt: string, referenceImageArtifactIds?: string[]): Promise<{
88
+ editImage(prompt: string, imageProperties?: Record<string, any>, referenceImageArtifactIds?: string[]): Promise<{
86
89
  artifactId?: string;
87
90
  error?: any;
88
91
  }>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Agent = void 0;
4
4
  const app_types_1 = require("../../../shared/types/app.types");
5
+ const logger_1 = require("../common/logger");
5
6
  const crypto_1 = require("crypto");
6
7
  class Agent {
7
8
  id;
@@ -29,6 +30,7 @@ class Agent {
29
30
  vectorStore;
30
31
  aiService;
31
32
  artifactService;
33
+ userPaths;
32
34
  configService;
33
35
  balanceService;
34
36
  description;
@@ -38,7 +40,6 @@ class Agent {
38
40
  modelName;
39
41
  smallModelName;
40
42
  serviceName;
41
- imageProperties;
42
43
  reasoningEffort;
43
44
  allowSearch;
44
45
  maxOutputTokens = 0;
@@ -50,7 +51,7 @@ class Agent {
50
51
  onStateChange = null;
51
52
  storageDir;
52
53
  agentStoreService;
53
- constructor(id, configService, agentStoreService, balanceService, artifactService, agentName = '', agentNickname = '', description = '', promptFolder = '', systemInstruction = '', history = [], modelName = '', serviceName = '', aiService, reasoningEffort = null, allowSearch = false, maxOutputTokens = 0, beginInstruction = '', storageDir) {
54
+ constructor(id, userPaths, configService, agentStoreService, balanceService, artifactService, agentName = '', agentNickname = '', description = '', promptFolder = '', systemInstruction = '', history = [], modelName = '', serviceName = '', aiService, reasoningEffort = null, allowSearch = false, maxOutputTokens = 0, beginInstruction = '', storageDir) {
54
55
  this.agentName = agentName;
55
56
  this.agentNickname = agentNickname || Agent.generateNickname(agentName);
56
57
  this.description = description;
@@ -70,10 +71,18 @@ class Agent {
70
71
  this.maxOutputTokens = maxOutputTokens;
71
72
  this.beginInstruction = beginInstruction;
72
73
  this.storageDir = storageDir;
74
+ this.userPaths = userPaths;
73
75
  this.configService = configService;
74
76
  this.agentStoreService = agentStoreService;
75
77
  this.balanceService = balanceService;
76
78
  this.artifactService = artifactService;
79
+ const configuredMarkupRate = configService?.get('DEFAULT_MARKUP_RATE');
80
+ if (configuredMarkupRate !== undefined && configuredMarkupRate !== null) {
81
+ const parsed = parseFloat(String(configuredMarkupRate));
82
+ if (!isNaN(parsed)) {
83
+ this.markupRate = parsed;
84
+ }
85
+ }
77
86
  this.id = id ? id : (0, crypto_1.randomUUID)();
78
87
  }
79
88
  async attachDocument(fileName, fileData) {
@@ -182,11 +191,14 @@ class Agent {
182
191
  async compact() {
183
192
  const originalHistory = [...(this.history || [])];
184
193
  const originalLength = originalHistory.length;
194
+ const originalChars = originalHistory.reduce((sum, m) => sum + (m?.content?.length || 0), 0);
185
195
  if (originalLength === 0) {
186
196
  return {
187
197
  success: true,
188
198
  originalLength,
189
199
  newLength: originalLength,
200
+ originalChars,
201
+ newChars: 0,
190
202
  message: 'No conversation history to compact',
191
203
  };
192
204
  }
@@ -197,11 +209,15 @@ class Agent {
197
209
  const summary = summaryResponse?.summary || summaryResponse;
198
210
  this.addToConversationHistory(`[CONVERSATION HISTORY SUMMARY]\n\n${summary}`, true);
199
211
  const newLength = this.history.length;
212
+ const newChars = this.history.reduce((sum, m) => sum + (m?.content?.length || 0), 0);
213
+ logger_1.logger.log(`Compacted ${this.agentName}: ${originalChars} -> ${newChars} characters (${originalLength} -> ${newLength} messages)`);
200
214
  this.save();
201
215
  return {
202
216
  success: true,
203
217
  originalLength,
204
218
  newLength,
219
+ originalChars,
220
+ newChars,
205
221
  message: `${originalLength} messages -> ${newLength} messages`,
206
222
  summary,
207
223
  };
@@ -214,11 +230,11 @@ class Agent {
214
230
  async textPrompt(prompt, jsonSchema = null, saveResponse = true, promptInstructions = null, cacheMessage = false, maxOutputChars = 0) {
215
231
  return await this.aiService.textPrompt(this, prompt, jsonSchema, saveResponse, promptInstructions, this.aiService.getCacheConfig(this, cacheMessage), maxOutputChars);
216
232
  }
217
- async generateImage(prompt) {
218
- return await this.aiService.generateImage(this, prompt, this.imageProperties);
233
+ async generateImage(prompt, imageProperties) {
234
+ return await this.aiService.generateImage(this, prompt, imageProperties);
219
235
  }
220
- async editImage(prompt, referenceImageArtifactIds) {
221
- return await this.aiService.editImage(this, prompt, this.imageProperties, referenceImageArtifactIds);
236
+ async editImage(prompt, imageProperties, referenceImageArtifactIds) {
237
+ return await this.aiService.editImage(this, prompt, imageProperties, referenceImageArtifactIds);
222
238
  }
223
239
  }
224
240
  exports.Agent = Agent;
@@ -0,0 +1,10 @@
1
+ export declare class AiDebugLogger {
2
+ static isEnabled(): boolean;
3
+ private static getLogDir;
4
+ private static timestamp;
5
+ private static sanitize;
6
+ private static write;
7
+ static writeRequest(agentName: string, content: unknown): void;
8
+ static writeThinking(agentName: string, content: string): void;
9
+ static writeResponse(agentName: string, content: string): void;
10
+ }
@@ -0,0 +1,82 @@
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.AiDebugLogger = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ class AiDebugLogger {
40
+ static isEnabled() {
41
+ return process.env.AI_DEBUG === 'true';
42
+ }
43
+ static getLogDir() {
44
+ const dataPath = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'server', 'data');
45
+ const dir = path.resolve(dataPath, 'logs', 'ai-debug');
46
+ fs.mkdirSync(dir, { recursive: true });
47
+ return dir;
48
+ }
49
+ static timestamp() {
50
+ const now = new Date();
51
+ const pad = (n, len = 2) => String(n).padStart(len, '0');
52
+ return (`${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}` +
53
+ `_${pad(now.getHours())}-${pad(now.getMinutes())}-${pad(now.getSeconds())}` +
54
+ `-${pad(now.getMilliseconds(), 3)}`);
55
+ }
56
+ static sanitize(name) {
57
+ return name.replace(/[<>:"/\\|?*\s]+/g, '_').substring(0, 80);
58
+ }
59
+ static write(agentName, suffix, content) {
60
+ if (!this.isEnabled())
61
+ return;
62
+ try {
63
+ const filename = `${this.timestamp()}_${this.sanitize(agentName)}_${suffix}.txt`;
64
+ fs.writeFileSync(path.join(this.getLogDir(), filename), content, 'utf8');
65
+ }
66
+ catch {
67
+ }
68
+ }
69
+ static writeRequest(agentName, content) {
70
+ const text = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
71
+ this.write(agentName, 'REQUEST', text);
72
+ }
73
+ static writeThinking(agentName, content) {
74
+ if (!content)
75
+ return;
76
+ this.write(agentName, 'THINKING', content);
77
+ }
78
+ static writeResponse(agentName, content) {
79
+ this.write(agentName, 'RESPONSE', content ?? '');
80
+ }
81
+ }
82
+ exports.AiDebugLogger = AiDebugLogger;
@@ -9,13 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.ArtifactModule = void 0;
10
10
  const common_1 = require("@nestjs/common");
11
11
  const artifact_service_1 = require("./artifact.service");
12
- const configuration_module_1 = require("../config/configuration.module");
12
+ const user_paths_module_1 = require("../config/user-paths.module");
13
13
  let ArtifactModule = class ArtifactModule {
14
14
  };
15
15
  exports.ArtifactModule = ArtifactModule;
16
16
  exports.ArtifactModule = ArtifactModule = __decorate([
17
17
  (0, common_1.Module)({
18
- imports: [configuration_module_1.ConfigurationModule],
18
+ imports: [user_paths_module_1.UserPathsModule],
19
19
  providers: [artifact_service_1.ArtifactService],
20
20
  exports: [artifact_service_1.ArtifactService],
21
21
  })
@@ -1,9 +1,9 @@
1
- import { ConfigurationService } from '../config/configuration.service';
1
+ import { UserPathsService } from '../config/user-paths.service';
2
2
  import { ArtifactMetadata } from '../../../shared/types/app.types';
3
3
  export declare class ArtifactService {
4
- private readonly configService;
4
+ private readonly userPaths;
5
5
  private readonly artifactsDir;
6
- constructor(configService: ConfigurationService, storageDir?: string);
6
+ constructor(userPaths: UserPathsService, storageDir?: string);
7
7
  private getMetadataPath;
8
8
  private loadMetadata;
9
9
  private saveMetadata;
@@ -47,18 +47,18 @@ const common_1 = require("@nestjs/common");
47
47
  const fs = __importStar(require("fs"));
48
48
  const path = __importStar(require("path"));
49
49
  const crypto_1 = require("crypto");
50
- const configuration_service_1 = require("../config/configuration.service");
50
+ const user_paths_service_1 = require("../config/user-paths.service");
51
51
  const logger_1 = require("../common/logger");
52
52
  let ArtifactService = class ArtifactService {
53
- configService;
53
+ userPaths;
54
54
  artifactsDir;
55
- constructor(configService, storageDir) {
56
- this.configService = configService;
55
+ constructor(userPaths, storageDir) {
56
+ this.userPaths = userPaths;
57
57
  if (storageDir) {
58
58
  this.artifactsDir = storageDir;
59
59
  }
60
60
  else {
61
- const userDataDir = this.configService.getUserDataDir();
61
+ const userDataDir = this.userPaths.getUserDataDir();
62
62
  this.artifactsDir = path.join(userDataDir, 'artifacts');
63
63
  }
64
64
  if (!fs.existsSync(this.artifactsDir)) {
@@ -236,5 +236,5 @@ let ArtifactService = class ArtifactService {
236
236
  exports.ArtifactService = ArtifactService;
237
237
  exports.ArtifactService = ArtifactService = __decorate([
238
238
  (0, common_1.Injectable)(),
239
- __metadata("design:paramtypes", [configuration_service_1.ConfigurationService, String])
239
+ __metadata("design:paramtypes", [user_paths_service_1.UserPathsService, String])
240
240
  ], ArtifactService);
@@ -9,13 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.AttachedFileModule = void 0;
10
10
  const common_1 = require("@nestjs/common");
11
11
  const attached_file_service_1 = require("./attached-file.service");
12
- const configuration_module_1 = require("../config/configuration.module");
12
+ const user_paths_module_1 = require("../config/user-paths.module");
13
13
  let AttachedFileModule = class AttachedFileModule {
14
14
  };
15
15
  exports.AttachedFileModule = AttachedFileModule;
16
16
  exports.AttachedFileModule = AttachedFileModule = __decorate([
17
17
  (0, common_1.Module)({
18
- imports: [configuration_module_1.ConfigurationModule],
18
+ imports: [user_paths_module_1.UserPathsModule],
19
19
  providers: [attached_file_service_1.AttachedFileService],
20
20
  exports: [attached_file_service_1.AttachedFileService],
21
21
  })
@@ -1,4 +1,4 @@
1
- import { ConfigurationService } from '../config/configuration.service';
1
+ import { UserPathsService } from '../config/user-paths.service';
2
2
  export interface FileMetadata {
3
3
  fileName: string;
4
4
  fileId: string;
@@ -14,9 +14,9 @@ export interface FileMetadata {
14
14
  };
15
15
  }
16
16
  export declare class AttachedFileService {
17
- private readonly configService;
17
+ private readonly userPaths;
18
18
  private readonly attachedFilesDir;
19
- constructor(configService: ConfigurationService);
19
+ constructor(userPaths: UserPathsService);
20
20
  private getMetadataPath;
21
21
  storeFile(ownerId: string, fileName: string, fileData: Uint8Array, additionalMetadata?: Partial<FileMetadata>): string;
22
22
  getFile(ownerId: string, fileId: string): Uint8Array | null;
@@ -47,14 +47,14 @@ const common_1 = require("@nestjs/common");
47
47
  const fs = __importStar(require("fs"));
48
48
  const path = __importStar(require("path"));
49
49
  const crypto_1 = require("crypto");
50
- const configuration_service_1 = require("../config/configuration.service");
50
+ const user_paths_service_1 = require("../config/user-paths.service");
51
51
  const logger_1 = require("../common/logger");
52
52
  let AttachedFileService = class AttachedFileService {
53
- configService;
53
+ userPaths;
54
54
  attachedFilesDir;
55
- constructor(configService) {
56
- this.configService = configService;
57
- this.attachedFilesDir = this.configService.getUploadDir();
55
+ constructor(userPaths) {
56
+ this.userPaths = userPaths;
57
+ this.attachedFilesDir = this.userPaths.getUploadDir();
58
58
  if (!fs.existsSync(this.attachedFilesDir)) {
59
59
  fs.mkdirSync(this.attachedFilesDir, { recursive: true });
60
60
  }
@@ -250,5 +250,5 @@ let AttachedFileService = class AttachedFileService {
250
250
  exports.AttachedFileService = AttachedFileService;
251
251
  exports.AttachedFileService = AttachedFileService = __decorate([
252
252
  (0, common_1.Injectable)(),
253
- __metadata("design:paramtypes", [configuration_service_1.ConfigurationService])
253
+ __metadata("design:paramtypes", [user_paths_service_1.UserPathsService])
254
254
  ], AttachedFileService);
@@ -1,13 +1,13 @@
1
- import { ConfigurationService } from '../config/configuration.service';
1
+ import { UserPathsService } from '../config/user-paths.service';
2
2
  import { BalanceMessageService } from './balance-message.service';
3
3
  export declare class BalanceService {
4
4
  private userId;
5
- private configService;
5
+ private userPaths;
6
6
  private balanceFilePath;
7
7
  private markupFilePath;
8
8
  private startingBalance;
9
9
  private balanceMessageService?;
10
- constructor(userId: string, configService: ConfigurationService, balanceMessageService?: BalanceMessageService);
10
+ constructor(userId: string, userPaths: UserPathsService, balanceMessageService?: BalanceMessageService);
11
11
  getBalance(): number;
12
12
  getMarkup(): number;
13
13
  hasSufficientBalance(): boolean;