briyah 1.1.6 → 1.2.0
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.
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +3 -2
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +2 -2
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +3 -2
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +10 -10
- package/dist-sdk/server/src/ai/agent-factory.d.ts +5 -3
- package/dist-sdk/server/src/ai/agent-factory.js +6 -4
- package/dist-sdk/server/src/ai/agent-store.service.d.ts +5 -3
- package/dist-sdk/server/src/ai/agent-store.service.js +15 -15
- package/dist-sdk/server/src/ai/agent.d.ts +5 -3
- package/dist-sdk/server/src/ai/agent.js +10 -1
- package/dist-sdk/server/src/ai/artifact.module.js +2 -2
- package/dist-sdk/server/src/ai/artifact.service.d.ts +3 -3
- package/dist-sdk/server/src/ai/artifact.service.js +6 -6
- package/dist-sdk/server/src/ai/attached-file.module.js +2 -2
- package/dist-sdk/server/src/ai/attached-file.service.d.ts +3 -3
- package/dist-sdk/server/src/ai/attached-file.service.js +6 -6
- package/dist-sdk/server/src/app/balance.service.d.ts +3 -3
- package/dist-sdk/server/src/app/balance.service.js +7 -7
- package/dist-sdk/server/src/app/transaction.service.d.ts +3 -3
- package/dist-sdk/server/src/app/transaction.service.js +4 -4
- package/dist-sdk/server/src/app/user-service-factory.d.ts +3 -1
- package/dist-sdk/server/src/app/user-service-factory.js +18 -14
- package/dist-sdk/server/src/app/user-service-manager.d.ts +1 -3
- package/dist-sdk/server/src/app.service.d.ts +3 -3
- package/dist-sdk/server/src/app.service.js +30 -30
- package/dist-sdk/server/src/config/env-config.d.ts +3 -0
- package/dist-sdk/server/src/config/env-config.js +2 -0
- package/dist-sdk/server/src/config/user-paths.module.d.ts +2 -0
- package/dist-sdk/server/src/config/{configuration.module.js → user-paths.module.js} +8 -8
- package/dist-sdk/server/src/config/{configuration.service.d.ts → user-paths.service.d.ts} +1 -1
- package/dist-sdk/server/src/config/{configuration.service.js → user-paths.service.js} +3 -3
- package/dist-sdk/server/src/room/room-store.module.js +2 -2
- package/dist-sdk/server/src/room/room-store.service.d.ts +3 -3
- package/dist-sdk/server/src/room/room-store.service.js +6 -6
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +2 -1
- package/dist-sdk/server/src/sdk/briyah-config.js +4 -0
- package/dist-sdk/server/src/sdk/briyah.js +1 -1
- package/dist-sdk/server/src/story/story-store.service.d.ts +3 -3
- package/dist-sdk/server/src/story/story-store.service.js +6 -6
- package/dist-sdk/server/src/story/story.service.d.ts +3 -3
- package/dist-sdk/server/src/story/story.service.js +13 -13
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Agent.html +15 -14
- package/docs/classes/Briyah.html +12 -12
- package/docs/classes/BriyahConfigService.html +5 -5
- package/docs/classes/Room.html +24 -24
- package/docs/classes/RoomMessage.html +10 -10
- package/docs/enums/MessageAction.html +3 -3
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +2 -2
- package/docs/interfaces/AgentInfo.html +2 -2
- package/docs/interfaces/AgentMessagesResponse.html +2 -2
- package/docs/interfaces/AppService.html +154 -154
- package/docs/interfaces/Artifact.html +3 -3
- package/docs/interfaces/ArtifactMetadata.html +2 -2
- package/docs/interfaces/AttachDocumentResponse.html +2 -2
- package/docs/interfaces/BriyahConfigOptions.html +9 -6
- package/docs/interfaces/ChapterInfo.html +2 -2
- package/docs/interfaces/Character.html +2 -2
- package/docs/interfaces/CreateAgentResponse.html +2 -2
- package/docs/interfaces/CreateRoomResponse.html +2 -2
- package/docs/interfaces/CreateStoryResponse.html +2 -2
- package/docs/interfaces/FileList.html +2 -2
- package/docs/interfaces/LoggingOptions.html +5 -5
- package/docs/interfaces/Message.html +2 -2
- package/docs/interfaces/ModelInfo.html +2 -2
- package/docs/interfaces/PreparedPromptResponse.html +2 -2
- package/docs/interfaces/ProcessTextResponse.html +2 -2
- package/docs/interfaces/PromptFile.html +2 -2
- package/docs/interfaces/PromptFileContent.html +2 -2
- package/docs/interfaces/PromptFilesResponse.html +2 -2
- package/docs/interfaces/PromptFolder.html +2 -2
- package/docs/interfaces/PromptFoldersResponse.html +2 -2
- package/docs/interfaces/RoomDetails.html +2 -2
- package/docs/interfaces/RoomInfo.html +2 -2
- package/docs/interfaces/RoomMessagesResponse.html +2 -2
- package/docs/interfaces/StoryErrorEvent.html +3 -3
- package/docs/interfaces/StoryIdea.html +2 -2
- package/docs/interfaces/StoryInfo.html +3 -3
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +3 -3
- package/docs/interfaces/StoryProgressChapterEvent.html +3 -3
- package/docs/interfaces/StoryState.html +5 -5
- package/docs/interfaces/StoryStateEvent.html +3 -3
- package/docs/interfaces/Transaction.html +2 -2
- package/docs/interfaces/TransactionHistoryResponse.html +2 -2
- package/docs/modules.html +1 -1
- package/docs/types/PromptScope.html +1 -1
- package/package.json +1 -1
- package/dist-sdk/server/src/config/configuration.module.d.ts +0 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Anthropic } from '@anthropic-ai/sdk';
|
|
2
2
|
import { Agent } from '../agent';
|
|
3
3
|
import { BaseAiService } from './base-ai.service';
|
|
4
|
-
import {
|
|
4
|
+
import { UserPathsService } from '../../config/user-paths.service';
|
|
5
|
+
import { IConfigService } from '../../config/env-config';
|
|
5
6
|
import { AgentStoreService } from '../agent-store.service';
|
|
6
7
|
import { BalanceService } from '../../app/balance.service';
|
|
7
8
|
import { ArtifactService } from '../artifact.service';
|
|
@@ -9,7 +10,7 @@ import { ModelInfo } from '../../../../shared/types/app.types';
|
|
|
9
10
|
export declare class AnthropicAiService extends BaseAiService {
|
|
10
11
|
protected anthropic: Anthropic;
|
|
11
12
|
constructor();
|
|
12
|
-
createAgent(configService:
|
|
13
|
+
createAgent(userPaths: UserPathsService, configService: IConfigService, agentStoreService: AgentStoreService, balanceService: BalanceService, artifactService: ArtifactService, agentName: string, agentNickname: string, description: string, promptFolder: string, modelName: string, storageDir?: string): Agent;
|
|
13
14
|
getServiceName(): string;
|
|
14
15
|
supportsImageGeneration(): boolean;
|
|
15
16
|
supportsPromptCaching(): boolean;
|
|
@@ -38,8 +38,8 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
38
38
|
this._isAvailable = false;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
createAgent(configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, modelName, storageDir = '') {
|
|
42
|
-
let agent = super.createAgent(configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, modelName, storageDir);
|
|
41
|
+
createAgent(userPaths, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, modelName, storageDir = '') {
|
|
42
|
+
let agent = super.createAgent(userPaths, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, modelName, storageDir);
|
|
43
43
|
agent.promptCacheTTL = 5;
|
|
44
44
|
return agent;
|
|
45
45
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Agent } from '../agent';
|
|
2
|
-
import {
|
|
2
|
+
import { UserPathsService } from '../../config/user-paths.service';
|
|
3
|
+
import { IConfigService } from '../../config/env-config';
|
|
3
4
|
import { ArtifactService } from '../artifact.service';
|
|
4
5
|
import { AgentStoreService } from '../agent-store.service';
|
|
5
6
|
import { BalanceService } from '../../app/balance.service';
|
|
@@ -20,7 +21,7 @@ export declare class BaseAiService {
|
|
|
20
21
|
protected getPreparedSchema(agent: Agent, promptFileName: string): any;
|
|
21
22
|
listModels(): Promise<ModelInfo[]>;
|
|
22
23
|
protected fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
23
|
-
createAgent(configService:
|
|
24
|
+
createAgent(userPaths: UserPathsService, configService: IConfigService, agentStoreService: AgentStoreService, balanceService: BalanceService, artifactService: ArtifactService, agentName: string, agentNickname: string, description: string, promptFolder: string, modelName: string, storageDir?: string): Agent;
|
|
24
25
|
textPrompt(agent: Agent, prompt: string, _jsonSchema?: any, _saveResponse?: boolean, _promptInstructions?: string, _cacheConfig?: any, _maxOutputChars?: number): Promise<any>;
|
|
25
26
|
generateImage(_agent: Agent, _prompt: string, _imageProperties?: Record<string, any>): Promise<{
|
|
26
27
|
artifactId?: string;
|
|
@@ -78,15 +78,15 @@ let BaseAiService = class BaseAiService {
|
|
|
78
78
|
return quotedText.replace(/^['"]+|['"]+$/g, '');
|
|
79
79
|
}
|
|
80
80
|
findPromptFile(agent, fileName, extension) {
|
|
81
|
-
const
|
|
82
|
-
if (!
|
|
83
|
-
throw new Error('Agent
|
|
81
|
+
const userPaths = agent.userPaths;
|
|
82
|
+
if (!userPaths) {
|
|
83
|
+
throw new Error('Agent userPaths is not set');
|
|
84
84
|
}
|
|
85
85
|
const searchPaths = [
|
|
86
|
-
path.join(
|
|
87
|
-
path.join(
|
|
88
|
-
path.join(
|
|
89
|
-
path.join(
|
|
86
|
+
path.join(userPaths.getUserPromptsDir(), agent.promptFolder, `${fileName}${extension}`),
|
|
87
|
+
path.join(userPaths.getUserPromptsDir(), `${fileName}${extension}`),
|
|
88
|
+
path.join(userPaths.getCommonPromptsDir(), agent.promptFolder, `${fileName}${extension}`),
|
|
89
|
+
path.join(userPaths.getCommonPromptsDir(), `${fileName}${extension}`),
|
|
90
90
|
];
|
|
91
91
|
for (const filePath of searchPaths) {
|
|
92
92
|
if (fs.existsSync(filePath)) {
|
|
@@ -141,7 +141,7 @@ let BaseAiService = class BaseAiService {
|
|
|
141
141
|
async fetchModelsFromApi() {
|
|
142
142
|
throw new Error('fetchModelsFromApi method not implemented in base class');
|
|
143
143
|
}
|
|
144
|
-
createAgent(configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, modelName, storageDir = '') {
|
|
144
|
+
createAgent(userPaths, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, modelName, storageDir = '') {
|
|
145
145
|
if (!this.isAvailable) {
|
|
146
146
|
throw new Error(`${this.getServiceName()} service is not available. Check API key configuration.`);
|
|
147
147
|
}
|
|
@@ -156,7 +156,7 @@ let BaseAiService = class BaseAiService {
|
|
|
156
156
|
throw new Error(`Model '${modelName}' is not listed in model_prices.json for ${this.getServiceName()}. ` +
|
|
157
157
|
`Add a pricing entry before using this model.`);
|
|
158
158
|
}
|
|
159
|
-
const tempAgent = { promptFolder,
|
|
159
|
+
const tempAgent = { promptFolder, userPaths };
|
|
160
160
|
const systemInstructionFile = this.findPromptFile(tempAgent, 'system_instruction', '.prompt');
|
|
161
161
|
let systemInstructionPrompt = null;
|
|
162
162
|
if (systemInstructionFile) {
|
|
@@ -168,7 +168,7 @@ let BaseAiService = class BaseAiService {
|
|
|
168
168
|
systemInstructionPrompt = null;
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
const agent = new agent_1.Agent(null, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, systemInstructionPrompt, [], modelName, this.getServiceName(), this, null, false, 0, '', storageDir);
|
|
171
|
+
const agent = new agent_1.Agent(null, userPaths, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, systemInstructionPrompt, [], modelName, this.getServiceName(), this, null, false, 0, '', storageDir);
|
|
172
172
|
return agent;
|
|
173
173
|
}
|
|
174
174
|
async textPrompt(agent, prompt, _jsonSchema = null, _saveResponse = true, _promptInstructions = null, _cacheConfig = null, _maxOutputChars = 0) {
|
|
@@ -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 {
|
|
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
|
|
11
|
+
private readonly userPaths;
|
|
11
12
|
private readonly balanceService;
|
|
12
13
|
private readonly artifactService;
|
|
13
|
-
|
|
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
|
-
|
|
7
|
+
userPaths;
|
|
8
8
|
balanceService;
|
|
9
9
|
artifactService;
|
|
10
|
-
|
|
10
|
+
configService;
|
|
11
|
+
constructor(aiFactoryService, agentStoreService, userPaths, balanceService, artifactService, configService) {
|
|
11
12
|
this.aiFactoryService = aiFactoryService;
|
|
12
13
|
this.agentStoreService = agentStoreService;
|
|
13
|
-
this.
|
|
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 {
|
|
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
|
|
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,
|
|
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
|
|
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
|
-
|
|
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,
|
|
68
|
+
constructor(aiFactoryService, userPaths, attachedFileService, balanceService, artifactService, configService) {
|
|
68
69
|
this.aiFactoryService = aiFactoryService;
|
|
69
|
-
this.
|
|
70
|
+
this.userPaths = userPaths;
|
|
70
71
|
this.attachedFileService = attachedFileService;
|
|
71
72
|
this.balanceService = balanceService;
|
|
72
73
|
this.artifactService = artifactService;
|
|
73
|
-
this.
|
|
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.
|
|
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
|
-
|
|
245
|
-
config.markupRate
|
|
246
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
35
|
+
userPaths: UserPathsService;
|
|
36
|
+
configService: IConfigService;
|
|
35
37
|
balanceService?: BalanceService;
|
|
36
38
|
description: string;
|
|
37
39
|
promptFolder: string;
|
|
@@ -52,7 +54,7 @@ export declare class Agent {
|
|
|
52
54
|
private onStateChange;
|
|
53
55
|
storageDir: string;
|
|
54
56
|
private agentStoreService;
|
|
55
|
-
constructor(id: string | null, configService:
|
|
57
|
+
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
58
|
attachDocument(fileName: string, fileData: Uint8Array): Promise<string>;
|
|
57
59
|
attachArtifact(artifactId: string): void;
|
|
58
60
|
detachArtifact(artifactId: string): void;
|
|
@@ -29,6 +29,7 @@ class Agent {
|
|
|
29
29
|
vectorStore;
|
|
30
30
|
aiService;
|
|
31
31
|
artifactService;
|
|
32
|
+
userPaths;
|
|
32
33
|
configService;
|
|
33
34
|
balanceService;
|
|
34
35
|
description;
|
|
@@ -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) {
|
|
@@ -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
|
|
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: [
|
|
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 {
|
|
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
|
|
4
|
+
private readonly userPaths;
|
|
5
5
|
private readonly artifactsDir;
|
|
6
|
-
constructor(
|
|
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
|
|
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
|
-
|
|
53
|
+
userPaths;
|
|
54
54
|
artifactsDir;
|
|
55
|
-
constructor(
|
|
56
|
-
this.
|
|
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.
|
|
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", [
|
|
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
|
|
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: [
|
|
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 {
|
|
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
|
|
17
|
+
private readonly userPaths;
|
|
18
18
|
private readonly attachedFilesDir;
|
|
19
|
-
constructor(
|
|
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
|
|
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
|
-
|
|
53
|
+
userPaths;
|
|
54
54
|
attachedFilesDir;
|
|
55
|
-
constructor(
|
|
56
|
-
this.
|
|
57
|
-
this.attachedFilesDir = this.
|
|
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", [
|
|
253
|
+
__metadata("design:paramtypes", [user_paths_service_1.UserPathsService])
|
|
254
254
|
], AttachedFileService);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
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
|
|
5
|
+
private userPaths;
|
|
6
6
|
private balanceFilePath;
|
|
7
7
|
private markupFilePath;
|
|
8
8
|
private startingBalance;
|
|
9
9
|
private balanceMessageService?;
|
|
10
|
-
constructor(userId: string,
|
|
10
|
+
constructor(userId: string, userPaths: UserPathsService, balanceMessageService?: BalanceMessageService);
|
|
11
11
|
getBalance(): number;
|
|
12
12
|
getMarkup(): number;
|
|
13
13
|
hasSufficientBalance(): boolean;
|
|
@@ -39,14 +39,14 @@ const path = __importStar(require("path"));
|
|
|
39
39
|
const logger_1 = require("../common/logger");
|
|
40
40
|
class BalanceService {
|
|
41
41
|
userId;
|
|
42
|
-
|
|
42
|
+
userPaths;
|
|
43
43
|
balanceFilePath;
|
|
44
44
|
markupFilePath;
|
|
45
45
|
startingBalance;
|
|
46
46
|
balanceMessageService;
|
|
47
|
-
constructor(userId,
|
|
47
|
+
constructor(userId, userPaths, balanceMessageService) {
|
|
48
48
|
this.userId = userId;
|
|
49
|
-
this.
|
|
49
|
+
this.userPaths = userPaths;
|
|
50
50
|
this.balanceMessageService = balanceMessageService;
|
|
51
51
|
if (!process.env.STARTING_BALANCE) {
|
|
52
52
|
throw new Error('STARTING_BALANCE environment variable is required');
|
|
@@ -58,9 +58,9 @@ class BalanceService {
|
|
|
58
58
|
if (this.startingBalance < 0) {
|
|
59
59
|
throw new Error('STARTING_BALANCE must be non-negative');
|
|
60
60
|
}
|
|
61
|
-
const userconfigPath = this.
|
|
61
|
+
const userconfigPath = this.userPaths.getUserConfigDir();
|
|
62
62
|
this.balanceFilePath = path.join(userconfigPath, 'balance');
|
|
63
|
-
const commonConfigPath = this.
|
|
63
|
+
const commonConfigPath = this.userPaths.getCommonConfigDir();
|
|
64
64
|
this.markupFilePath = path.join(commonConfigPath, 'markup');
|
|
65
65
|
}
|
|
66
66
|
getBalance() {
|
|
@@ -128,7 +128,7 @@ class BalanceService {
|
|
|
128
128
|
}
|
|
129
129
|
saveBalance(balance) {
|
|
130
130
|
try {
|
|
131
|
-
const userconfigPath = this.
|
|
131
|
+
const userconfigPath = this.userPaths.getUserConfigDir();
|
|
132
132
|
if (!fs.existsSync(userconfigPath)) {
|
|
133
133
|
fs.mkdirSync(userconfigPath, { recursive: true });
|
|
134
134
|
}
|
|
@@ -144,7 +144,7 @@ class BalanceService {
|
|
|
144
144
|
}
|
|
145
145
|
saveMarkup(markup) {
|
|
146
146
|
try {
|
|
147
|
-
const commonConfigPath = this.
|
|
147
|
+
const commonConfigPath = this.userPaths.getCommonConfigDir();
|
|
148
148
|
if (!fs.existsSync(commonConfigPath)) {
|
|
149
149
|
fs.mkdirSync(commonConfigPath, { recursive: true });
|
|
150
150
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UserPathsService } from '../config/user-paths.service';
|
|
2
2
|
import { Transaction } from '../../../shared/types/app.types';
|
|
3
3
|
export declare class TransactionService {
|
|
4
4
|
private userId;
|
|
5
|
-
private
|
|
5
|
+
private userPaths;
|
|
6
6
|
private transactionsDir;
|
|
7
|
-
constructor(userId: string,
|
|
7
|
+
constructor(userId: string, userPaths: UserPathsService);
|
|
8
8
|
recordTransaction(amount: number, paymentId: string, status?: 'pending' | 'succeeded' | 'failed' | 'cancelled'): Promise<Transaction>;
|
|
9
9
|
updateTransactionStatus(paymentId: string, status: 'pending' | 'succeeded' | 'failed' | 'cancelled'): Promise<void>;
|
|
10
10
|
getTransactionByPaymentId(paymentId: string): Promise<Transaction | null>;
|
|
@@ -40,12 +40,12 @@ const zod_1 = require("zod");
|
|
|
40
40
|
const logger_1 = require("../common/logger");
|
|
41
41
|
class TransactionService {
|
|
42
42
|
userId;
|
|
43
|
-
|
|
43
|
+
userPaths;
|
|
44
44
|
transactionsDir;
|
|
45
|
-
constructor(userId,
|
|
45
|
+
constructor(userId, userPaths) {
|
|
46
46
|
this.userId = userId;
|
|
47
|
-
this.
|
|
48
|
-
const userDataPath = this.
|
|
47
|
+
this.userPaths = userPaths;
|
|
48
|
+
const userDataPath = this.userPaths.getUserDataDir();
|
|
49
49
|
this.transactionsDir = path.join(userDataPath, 'transactions');
|
|
50
50
|
if (!fs.existsSync(this.transactionsDir)) {
|
|
51
51
|
fs.mkdirSync(this.transactionsDir, { recursive: true });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
1
2
|
import { AppService } from '../app.service';
|
|
2
3
|
import { RoomMessageService } from '../room/room-message.service';
|
|
3
4
|
import { AiFactoryService } from '../ai/ai-factory.service';
|
|
@@ -16,6 +17,7 @@ export declare class UserServiceFactory {
|
|
|
16
17
|
private readonly publishedAgentsService;
|
|
17
18
|
private readonly publishedRoomsService;
|
|
18
19
|
private readonly balanceMessageService;
|
|
19
|
-
|
|
20
|
+
private readonly configService;
|
|
21
|
+
constructor(aiFactoryService: AiFactoryService, agentMessageService: AgentMessageService, roomMessageService: RoomMessageService, storyProgressService: StoryProgressService, storyMessageService: StoryMessageService, publishedAgentsService: PublishedAgentsService, publishedRoomsService: PublishedRoomsService, balanceMessageService: BalanceMessageService, configService: ConfigService);
|
|
20
22
|
createAppService(userId: string): AppService;
|
|
21
23
|
}
|