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.
- package/dist/server/src/ai/LLM/deepseek.service.js +1 -1
- package/package.json +2 -2
- package/dist/ai/LLM/anthropic.module.d.ts +0 -2
- package/dist/ai/LLM/anthropic.module.js +0 -21
- package/dist/ai/LLM/anthropic.service.d.ts +0 -27
- package/dist/ai/LLM/anthropic.service.js +0 -329
- package/dist/ai/LLM/base-ai.service.d.ts +0 -45
- package/dist/ai/LLM/base-ai.service.js +0 -409
- package/dist/ai/LLM/deepseek.module.d.ts +0 -2
- package/dist/ai/LLM/deepseek.module.js +0 -21
- package/dist/ai/LLM/deepseek.service.d.ts +0 -15
- package/dist/ai/LLM/deepseek.service.js +0 -279
- package/dist/ai/LLM/fal.module.d.ts +0 -2
- package/dist/ai/LLM/fal.module.js +0 -21
- package/dist/ai/LLM/fal.service.d.ts +0 -17
- package/dist/ai/LLM/fal.service.js +0 -314
- package/dist/ai/LLM/googleai.module.d.ts +0 -2
- package/dist/ai/LLM/googleai.module.js +0 -21
- package/dist/ai/LLM/googleai.service.d.ts +0 -20
- package/dist/ai/LLM/googleai.service.js +0 -271
- package/dist/ai/LLM/grok.module.d.ts +0 -2
- package/dist/ai/LLM/grok.module.js +0 -21
- package/dist/ai/LLM/grok.service.d.ts +0 -14
- package/dist/ai/LLM/grok.service.js +0 -263
- package/dist/ai/LLM/mock.module.d.ts +0 -2
- package/dist/ai/LLM/mock.module.js +0 -21
- package/dist/ai/LLM/mock.service.d.ts +0 -13
- package/dist/ai/LLM/mock.service.js +0 -194
- package/dist/ai/LLM/openai.module.d.ts +0 -2
- package/dist/ai/LLM/openai.module.js +0 -21
- package/dist/ai/LLM/openai.service.d.ts +0 -21
- package/dist/ai/LLM/openai.service.js +0 -421
- package/dist/ai/LLM/together.module.d.ts +0 -2
- package/dist/ai/LLM/together.module.js +0 -21
- package/dist/ai/LLM/together.service.d.ts +0 -18
- package/dist/ai/LLM/together.service.js +0 -285
- package/dist/ai/LLM/vertexai.module.d.ts +0 -2
- package/dist/ai/LLM/vertexai.module.js +0 -21
- package/dist/ai/LLM/vertexai.service.d.ts +0 -17
- package/dist/ai/LLM/vertexai.service.js +0 -323
- package/dist/ai/agent-config.d.ts +0 -32
- package/dist/ai/agent-config.js +0 -2
- package/dist/ai/agent-factory.d.ts +0 -15
- package/dist/ai/agent-factory.js +0 -24
- package/dist/ai/agent-message.service.d.ts +0 -9
- package/dist/ai/agent-message.service.js +0 -56
- package/dist/ai/agent-store.module.d.ts +0 -2
- package/dist/ai/agent-store.module.js +0 -21
- package/dist/ai/agent-store.service.d.ts +0 -31
- package/dist/ai/agent-store.service.js +0 -352
- package/dist/ai/agent.d.ts +0 -75
- package/dist/ai/agent.js +0 -174
- package/dist/ai/ai-factory.module.d.ts +0 -2
- package/dist/ai/ai-factory.module.js +0 -40
- package/dist/ai/ai-factory.service.d.ts +0 -24
- package/dist/ai/ai-factory.service.js +0 -94
- package/dist/ai/artifact.module.d.ts +0 -2
- package/dist/ai/artifact.module.js +0 -22
- package/dist/ai/artifact.service.d.ts +0 -21
- package/dist/ai/artifact.service.js +0 -239
- package/dist/ai/attached-file.module.d.ts +0 -2
- package/dist/ai/attached-file.module.js +0 -22
- package/dist/ai/attached-file.service.d.ts +0 -35
- package/dist/ai/attached-file.service.js +0 -253
- package/dist/ai/model_prices.d.ts +0 -2
- package/dist/ai/model_prices.js +0 -54
- package/dist/ai/published-agents.service.d.ts +0 -13
- package/dist/ai/published-agents.service.js +0 -118
- package/dist/app/balance-message.service.d.ts +0 -8
- package/dist/app/balance-message.service.js +0 -45
- package/dist/app/balance.module.d.ts +0 -2
- package/dist/app/balance.module.js +0 -20
- package/dist/app/balance.service.d.ts +0 -18
- package/dist/app/balance.service.js +0 -158
- package/dist/app/stripe.controller.d.ts +0 -31
- package/dist/app/stripe.controller.js +0 -150
- package/dist/app/stripe.module.d.ts +0 -2
- package/dist/app/stripe.module.js +0 -22
- package/dist/app/stripe.service.d.ts +0 -28
- package/dist/app/stripe.service.js +0 -198
- package/dist/app/transaction.service.d.ts +0 -15
- package/dist/app/transaction.service.js +0 -139
- package/dist/app/user-service-factory.d.ts +0 -21
- package/dist/app/user-service-factory.js +0 -81
- package/dist/app/user-service-manager.d.ts +0 -28
- package/dist/app/user-service-manager.js +0 -102
- package/dist/app.controller.d.ts +0 -232
- package/dist/app.controller.js +0 -2536
- package/dist/app.module.d.ts +0 -2
- package/dist/app.module.js +0 -45
- package/dist/app.service.d.ts +0 -186
- package/dist/app.service.js +0 -1334
- package/dist/auth/agent-access.decorator.d.ts +0 -2
- package/dist/auth/agent-access.decorator.js +0 -10
- package/dist/auth/auth.controller.d.ts +0 -38
- package/dist/auth/auth.controller.js +0 -356
- package/dist/auth/auth.module.d.ts +0 -2
- package/dist/auth/auth.module.js +0 -55
- package/dist/auth/auth.service.d.ts +0 -14
- package/dist/auth/auth.service.js +0 -84
- package/dist/auth/dto/bot-login.dto.d.ts +0 -4
- package/dist/auth/dto/bot-login.dto.js +0 -2
- package/dist/auth/dto/password-reset.dto.d.ts +0 -11
- package/dist/auth/dto/password-reset.dto.js +0 -2
- package/dist/auth/dto/phone-login.dto.d.ts +0 -8
- package/dist/auth/dto/phone-login.dto.js +0 -2
- package/dist/auth/dto/phone-verification.dto.d.ts +0 -9
- package/dist/auth/dto/phone-verification.dto.js +0 -2
- package/dist/auth/jwt-auth.guard.d.ts +0 -13
- package/dist/auth/jwt-auth.guard.js +0 -143
- package/dist/auth/jwt.strategy.d.ts +0 -17
- package/dist/auth/jwt.strategy.js +0 -45
- package/dist/auth/phone-validation.service.d.ts +0 -7
- package/dist/auth/phone-validation.service.js +0 -50
- package/dist/auth/public.decorator.d.ts +0 -2
- package/dist/auth/public.decorator.js +0 -7
- package/dist/auth/rate-limit.service.d.ts +0 -16
- package/dist/auth/rate-limit.service.js +0 -84
- package/dist/auth/room-access.decorator.d.ts +0 -2
- package/dist/auth/room-access.decorator.js +0 -10
- package/dist/auth/scopes.decorator.d.ts +0 -2
- package/dist/auth/scopes.decorator.js +0 -7
- package/dist/auth/scopes.guard.d.ts +0 -9
- package/dist/auth/scopes.guard.js +0 -82
- package/dist/auth/session.guard.d.ts +0 -7
- package/dist/auth/session.guard.js +0 -55
- package/dist/auth/twilio.service.d.ts +0 -15
- package/dist/auth/twilio.service.js +0 -139
- package/dist/auth/users.service.d.ts +0 -24
- package/dist/auth/users.service.js +0 -149
- package/dist/common/errors.d.ts +0 -12
- package/dist/common/errors.js +0 -43
- package/dist/config/configuration.module.d.ts +0 -2
- package/dist/config/configuration.module.js +0 -20
- package/dist/config/configuration.service.d.ts +0 -26
- package/dist/config/configuration.service.js +0 -131
- package/dist/main.js +0 -15749
- package/dist/room/artifact-store.service.d.ts +0 -15
- package/dist/room/artifact-store.service.js +0 -226
- package/dist/room/artifact.d.ts +0 -6
- package/dist/room/artifact.js +0 -2
- package/dist/room/message.d.ts +0 -19
- package/dist/room/message.js +0 -70
- package/dist/room/published-rooms.service.d.ts +0 -12
- package/dist/room/published-rooms.service.js +0 -108
- package/dist/room/room-config.d.ts +0 -12
- package/dist/room/room-config.js +0 -2
- package/dist/room/room-factory.d.ts +0 -7
- package/dist/room/room-factory.js +0 -16
- package/dist/room/room-message.module.d.ts +0 -2
- package/dist/room/room-message.module.js +0 -21
- package/dist/room/room-message.service.d.ts +0 -8
- package/dist/room/room-message.service.js +0 -44
- package/dist/room/room-store.module.d.ts +0 -2
- package/dist/room/room-store.module.js +0 -25
- package/dist/room/room-store.service.d.ts +0 -38
- package/dist/room/room-store.service.js +0 -353
- package/dist/room/room.d.ts +0 -107
- package/dist/room/room.js +0 -833
- package/dist/sdk/briyah-config.d.ts +0 -13
- package/dist/sdk/briyah-config.js +0 -32
- package/dist/sdk/briyah.d.ts +0 -36
- package/dist/sdk/briyah.js +0 -122
- package/dist/sdk/index.d.ts +0 -6
- package/dist/sdk/index.js +0 -11
- package/dist/shared/shared.module.d.ts +0 -2
- package/dist/shared/shared.module.js +0 -46
- package/dist/story/story-message.service.d.ts +0 -10
- package/dist/story/story-message.service.js +0 -57
- package/dist/story/story-progress.service.d.ts +0 -8
- package/dist/story/story-progress.service.js +0 -44
- package/dist/story/story-store.module.d.ts +0 -2
- package/dist/story/story-store.module.js +0 -22
- package/dist/story/story-store.service.d.ts +0 -23
- package/dist/story/story-store.service.js +0 -392
- package/dist/story/story.service.d.ts +0 -94
- package/dist/story/story.service.js +0 -1797
|
@@ -1,409 +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.BaseAiService = void 0;
|
|
46
|
-
const common_1 = require("@nestjs/common");
|
|
47
|
-
const agent_1 = require("../agent");
|
|
48
|
-
const path = __importStar(require("path"));
|
|
49
|
-
const fs_1 = require("fs");
|
|
50
|
-
const fs = __importStar(require("fs"));
|
|
51
|
-
const handlebars_1 = require("handlebars");
|
|
52
|
-
const errors_1 = require("../../common/errors");
|
|
53
|
-
let BaseAiService = class BaseAiService {
|
|
54
|
-
modelsCache = null;
|
|
55
|
-
_isAvailable = true;
|
|
56
|
-
constructor() { }
|
|
57
|
-
get isAvailable() {
|
|
58
|
-
return this._isAvailable;
|
|
59
|
-
}
|
|
60
|
-
getServiceName() {
|
|
61
|
-
return '';
|
|
62
|
-
}
|
|
63
|
-
supportsImageGeneration() {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
supportsPromptCaching() {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
getCacheConfig(_agent, _cacheMessage) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
stripQuotes(quotedText) {
|
|
73
|
-
return quotedText.replace(/^['"]+|['"]+$/g, '');
|
|
74
|
-
}
|
|
75
|
-
findPromptFile(agent, fileName, extension) {
|
|
76
|
-
const configService = agent.configService;
|
|
77
|
-
if (!configService) {
|
|
78
|
-
throw new Error('Agent configService is not set');
|
|
79
|
-
}
|
|
80
|
-
const searchPaths = [
|
|
81
|
-
path.join(configService.getUserPromptsDir(), agent.promptFolder, `${fileName}${extension}`),
|
|
82
|
-
path.join(configService.getUserPromptsDir(), `${fileName}${extension}`),
|
|
83
|
-
path.join(configService.getCommonPromptsDir(), agent.promptFolder, `${fileName}${extension}`),
|
|
84
|
-
path.join(configService.getCommonPromptsDir(), `${fileName}${extension}`),
|
|
85
|
-
];
|
|
86
|
-
for (const filePath of searchPaths) {
|
|
87
|
-
if (fs.existsSync(filePath)) {
|
|
88
|
-
return filePath;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
getPreparedPrompt(agent, promptFileName, variables) {
|
|
94
|
-
const preparedFile = this.findPromptFile(agent, promptFileName, '.prompt');
|
|
95
|
-
if (!preparedFile) {
|
|
96
|
-
throw new errors_1.NotFoundError(`Prompt file '${promptFileName}.prompt' not found for agent '${agent.agentName}' (folder: ${agent.promptFolder})`);
|
|
97
|
-
}
|
|
98
|
-
const preparedPrompt = fs.readFileSync(preparedFile).toString('utf8');
|
|
99
|
-
const template = (0, handlebars_1.compile)(preparedPrompt);
|
|
100
|
-
return template(variables);
|
|
101
|
-
}
|
|
102
|
-
getPreparedSchema(agent, promptFileName) {
|
|
103
|
-
const jsonSchemaFile = this.findPromptFile(agent, promptFileName, '.json');
|
|
104
|
-
if (!jsonSchemaFile) {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
let jsonSchemaString = (0, fs_1.readFileSync)(jsonSchemaFile).toString('utf8');
|
|
108
|
-
if (!jsonSchemaString) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
return JSON.parse(jsonSchemaString);
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
console.error(`Error parsing JSON schema from ${jsonSchemaFile}:`, error);
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
async listModels() {
|
|
120
|
-
if (!this.isAvailable) {
|
|
121
|
-
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
122
|
-
}
|
|
123
|
-
if (this.modelsCache) {
|
|
124
|
-
return this.modelsCache;
|
|
125
|
-
}
|
|
126
|
-
try {
|
|
127
|
-
const models = await this.fetchModelsFromApi();
|
|
128
|
-
this.modelsCache = models;
|
|
129
|
-
return models;
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
console.error(`Error fetching models for ${this.getServiceName()}:`, error);
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
async fetchModelsFromApi() {
|
|
137
|
-
throw new Error('fetchModelsFromApi method not implemented in base class');
|
|
138
|
-
}
|
|
139
|
-
createAgent(configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, modelName, storageDir = '') {
|
|
140
|
-
if (!this.isAvailable) {
|
|
141
|
-
throw new Error(`${this.getServiceName()} service is not available. Check API key configuration.`);
|
|
142
|
-
}
|
|
143
|
-
if (!modelName) {
|
|
144
|
-
throw new Error('Model name is required');
|
|
145
|
-
}
|
|
146
|
-
if (!agentName) {
|
|
147
|
-
throw new Error('Agent name is required');
|
|
148
|
-
}
|
|
149
|
-
const tempAgent = { promptFolder, configService };
|
|
150
|
-
const systemInstructionFile = this.findPromptFile(tempAgent, 'system_instruction', '.prompt');
|
|
151
|
-
let systemInstructionPrompt = null;
|
|
152
|
-
if (systemInstructionFile) {
|
|
153
|
-
try {
|
|
154
|
-
systemInstructionPrompt = (0, fs_1.readFileSync)(systemInstructionFile).toString('utf8');
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
console.error(`Error reading system instruction from ${systemInstructionFile}:`, error);
|
|
158
|
-
systemInstructionPrompt = null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const agent = new agent_1.Agent(null, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, systemInstructionPrompt, [], modelName, this.getServiceName(), this, null, false, 0, '', storageDir);
|
|
162
|
-
return agent;
|
|
163
|
-
}
|
|
164
|
-
async textPrompt(agent, prompt, _jsonSchema = null, _saveResponse = true, _promptInstructions = null, _cacheConfig = null, _maxOutputChars = 0) {
|
|
165
|
-
if (!this.isAvailable) {
|
|
166
|
-
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
167
|
-
}
|
|
168
|
-
throw new Error('Method not implemented in base class');
|
|
169
|
-
}
|
|
170
|
-
async generateImage(_agent, _prompt, _width, _height, _quality, _referenceImageArtifactIds, _options) {
|
|
171
|
-
if (!this.isAvailable) {
|
|
172
|
-
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
173
|
-
}
|
|
174
|
-
throw new Error(`generateImage method not implemented for ${this.getServiceName()}`);
|
|
175
|
-
}
|
|
176
|
-
async loadReferenceImages(agent, artifactIds) {
|
|
177
|
-
const images = [];
|
|
178
|
-
for (const artifactId of artifactIds) {
|
|
179
|
-
const imageData = agent.artifactService.getArtifact(artifactId);
|
|
180
|
-
const metadata = agent.artifactService.getArtifactMetadata(artifactId);
|
|
181
|
-
if (imageData && Buffer.isBuffer(imageData) && metadata) {
|
|
182
|
-
const uint8Array = new Uint8Array(imageData);
|
|
183
|
-
const blob = new Blob([uint8Array], {
|
|
184
|
-
type: metadata.mimeType || 'image/png',
|
|
185
|
-
});
|
|
186
|
-
const file = new File([blob], metadata.fileName, {
|
|
187
|
-
type: metadata.mimeType || 'image/png',
|
|
188
|
-
});
|
|
189
|
-
images.push(file);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return images;
|
|
193
|
-
}
|
|
194
|
-
async saveImageAsArtifact(agent, base64Data, prompt) {
|
|
195
|
-
const buffer = Buffer.from(base64Data, 'base64');
|
|
196
|
-
const mimeType = 'image/png';
|
|
197
|
-
const name = prompt.substring(0, 50).trim() + ' (generated)';
|
|
198
|
-
return agent.artifactService.storeImageArtifact(name, buffer, mimeType);
|
|
199
|
-
}
|
|
200
|
-
async preparedPrompt(agent, promptFileName, variables, saveResponse = true, cacheConfig = false, maxOutputChars = 0) {
|
|
201
|
-
if (!this.isAvailable) {
|
|
202
|
-
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
203
|
-
}
|
|
204
|
-
let preparedPrompt = this.getPreparedPrompt(agent, promptFileName, variables);
|
|
205
|
-
let jsonSchema = this.getPreparedSchema(agent, promptFileName);
|
|
206
|
-
return this.textPrompt(agent, preparedPrompt, jsonSchema, saveResponse, null, cacheConfig, maxOutputChars);
|
|
207
|
-
}
|
|
208
|
-
async instructedPrompt(agent, prompt, instructionFileName, variables, saveResponse = true, cacheConfig = null, maxOutputChars = 0) {
|
|
209
|
-
if (!this.isAvailable) {
|
|
210
|
-
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
211
|
-
}
|
|
212
|
-
let promptInstructions = this.getPreparedPrompt(agent, instructionFileName, variables);
|
|
213
|
-
let jsonSchema = this.getPreparedSchema(agent, instructionFileName);
|
|
214
|
-
return this.textPrompt(agent, prompt, jsonSchema, saveResponse, promptInstructions, cacheConfig, maxOutputChars);
|
|
215
|
-
}
|
|
216
|
-
async attachDocument(agent, fileName, fileData) {
|
|
217
|
-
if (!this.isAvailable) {
|
|
218
|
-
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
219
|
-
}
|
|
220
|
-
if (agent === null) {
|
|
221
|
-
throw new Error('Shared document attachment not supported by this service');
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
let ext = fileName.split('.').pop();
|
|
225
|
-
let mimeType = 'application/octet-stream';
|
|
226
|
-
if (ext.toLowerCase() === 'pdf') {
|
|
227
|
-
mimeType = 'application/pdf';
|
|
228
|
-
}
|
|
229
|
-
else if (ext.toLowerCase() === 'txt') {
|
|
230
|
-
mimeType = 'text/plain';
|
|
231
|
-
}
|
|
232
|
-
else if (ext.toLowerCase() === 'md') {
|
|
233
|
-
mimeType = 'text/plain';
|
|
234
|
-
}
|
|
235
|
-
else if (['doc', 'docx'].includes(ext.toLowerCase())) {
|
|
236
|
-
mimeType = 'application/msword';
|
|
237
|
-
}
|
|
238
|
-
else if (['xls', 'xlsx'].includes(ext.toLowerCase())) {
|
|
239
|
-
mimeType = 'application/vnd.ms-excel';
|
|
240
|
-
}
|
|
241
|
-
const fileMetadata = {
|
|
242
|
-
fileName,
|
|
243
|
-
mimeType,
|
|
244
|
-
size: fileData.length,
|
|
245
|
-
uploadDate: new Date().toISOString(),
|
|
246
|
-
serviceMetadata: {
|
|
247
|
-
serviceName: this.getServiceName(),
|
|
248
|
-
fileData: Array.from(fileData),
|
|
249
|
-
},
|
|
250
|
-
};
|
|
251
|
-
const existingFileIndex = agent.attachedFiles.findIndex((f) => f.fileName === fileName);
|
|
252
|
-
if (existingFileIndex >= 0) {
|
|
253
|
-
agent.attachedFiles[existingFileIndex] = {
|
|
254
|
-
...agent.attachedFiles[existingFileIndex],
|
|
255
|
-
...fileMetadata,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
agent.attachedFiles.push(fileMetadata);
|
|
260
|
-
}
|
|
261
|
-
return `Document attached: ${fileName}`;
|
|
262
|
-
}
|
|
263
|
-
catch (error) {
|
|
264
|
-
console.error(`Error attaching document in ${this.getServiceName()} service:`, error);
|
|
265
|
-
throw new Error(`Error attaching document: ${error.message}`);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
async finishAgent(_agent) {
|
|
269
|
-
if (!this.isAvailable) {
|
|
270
|
-
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
addToConversationHistory(agent, message, fromSelf = false, developer = false) {
|
|
274
|
-
if (!agent.history) {
|
|
275
|
-
agent.history = [];
|
|
276
|
-
}
|
|
277
|
-
if (!message)
|
|
278
|
-
return;
|
|
279
|
-
let role = fromSelf ? 'assistant' : 'user';
|
|
280
|
-
if (developer)
|
|
281
|
-
role = 'developer';
|
|
282
|
-
agent.history.push({
|
|
283
|
-
role: role,
|
|
284
|
-
content: message,
|
|
285
|
-
});
|
|
286
|
-
agent.trimHistoryIfNeeded();
|
|
287
|
-
}
|
|
288
|
-
formatMessage(message) {
|
|
289
|
-
if (!message) {
|
|
290
|
-
return 'No message';
|
|
291
|
-
}
|
|
292
|
-
if (message.role && message.content) {
|
|
293
|
-
let content = message.content;
|
|
294
|
-
if (typeof content === 'object') {
|
|
295
|
-
content = JSON.stringify(content, null, 4);
|
|
296
|
-
}
|
|
297
|
-
return `${message.role}: ${content}`;
|
|
298
|
-
}
|
|
299
|
-
return JSON.stringify(message);
|
|
300
|
-
}
|
|
301
|
-
trimResponseText(str) {
|
|
302
|
-
if (!str) {
|
|
303
|
-
return str;
|
|
304
|
-
}
|
|
305
|
-
str = str.replace(/<think>[\s\S]*?<\/think>/gi, '').trim();
|
|
306
|
-
if (str.startsWith('```')) {
|
|
307
|
-
const lines = str.split('\n');
|
|
308
|
-
if (lines.length > 1) {
|
|
309
|
-
str = lines.slice(1).join('\n');
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
str = '';
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
if (str.endsWith('```')) {
|
|
316
|
-
const lines = str.split('\n');
|
|
317
|
-
if (lines.length > 1) {
|
|
318
|
-
str = lines.slice(0, -1).join('\n');
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
str = '';
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return str;
|
|
325
|
-
}
|
|
326
|
-
trimToJson(str) {
|
|
327
|
-
let objectStart = str.indexOf('{');
|
|
328
|
-
let arrayStart = str.indexOf('[');
|
|
329
|
-
let startIndex = -1;
|
|
330
|
-
let endChar = '';
|
|
331
|
-
if (objectStart !== -1 && arrayStart !== -1) {
|
|
332
|
-
if (objectStart < arrayStart) {
|
|
333
|
-
startIndex = objectStart;
|
|
334
|
-
endChar = '}';
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
startIndex = arrayStart;
|
|
338
|
-
endChar = ']';
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
else if (objectStart !== -1) {
|
|
342
|
-
startIndex = objectStart;
|
|
343
|
-
endChar = '}';
|
|
344
|
-
}
|
|
345
|
-
else if (arrayStart !== -1) {
|
|
346
|
-
startIndex = arrayStart;
|
|
347
|
-
endChar = ']';
|
|
348
|
-
}
|
|
349
|
-
if (startIndex !== -1) {
|
|
350
|
-
str = str.substring(startIndex);
|
|
351
|
-
let endIndex = str.lastIndexOf(endChar);
|
|
352
|
-
if (endIndex !== -1) {
|
|
353
|
-
str = str.slice(0, endIndex + 1);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return str;
|
|
357
|
-
}
|
|
358
|
-
sanitizeJsonString(str) {
|
|
359
|
-
let result = '';
|
|
360
|
-
let inString = false;
|
|
361
|
-
let escapeNext = false;
|
|
362
|
-
for (let i = 0; i < str.length; i++) {
|
|
363
|
-
const char = str[i];
|
|
364
|
-
if (escapeNext) {
|
|
365
|
-
if (char === "'") {
|
|
366
|
-
result = result.slice(0, -1) + char;
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
result += char;
|
|
370
|
-
}
|
|
371
|
-
escapeNext = false;
|
|
372
|
-
continue;
|
|
373
|
-
}
|
|
374
|
-
if (char === '\\') {
|
|
375
|
-
result += char;
|
|
376
|
-
escapeNext = true;
|
|
377
|
-
continue;
|
|
378
|
-
}
|
|
379
|
-
if (char === '"') {
|
|
380
|
-
inString = !inString;
|
|
381
|
-
result += char;
|
|
382
|
-
continue;
|
|
383
|
-
}
|
|
384
|
-
if (inString) {
|
|
385
|
-
if (char === '\n') {
|
|
386
|
-
result += '\\n';
|
|
387
|
-
}
|
|
388
|
-
else if (char === '\r') {
|
|
389
|
-
result += '\\r';
|
|
390
|
-
}
|
|
391
|
-
else if (char === '\t') {
|
|
392
|
-
result += '\\t';
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
result += char;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
result += char;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return result;
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
exports.BaseAiService = BaseAiService;
|
|
406
|
-
exports.BaseAiService = BaseAiService = __decorate([
|
|
407
|
-
(0, common_1.Injectable)(),
|
|
408
|
-
__metadata("design:paramtypes", [])
|
|
409
|
-
], BaseAiService);
|
|
@@ -1,21 +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.DeepSeekAiModule = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
const deepseek_service_1 = require("./deepseek.service");
|
|
12
|
-
let DeepSeekAiModule = class DeepSeekAiModule {
|
|
13
|
-
};
|
|
14
|
-
exports.DeepSeekAiModule = DeepSeekAiModule;
|
|
15
|
-
exports.DeepSeekAiModule = DeepSeekAiModule = __decorate([
|
|
16
|
-
(0, common_1.Module)({
|
|
17
|
-
imports: [],
|
|
18
|
-
providers: [deepseek_service_1.DeepSeekAiService],
|
|
19
|
-
exports: [deepseek_service_1.DeepSeekAiService],
|
|
20
|
-
})
|
|
21
|
-
], DeepSeekAiModule);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { createDeepSeek } from '@ai-sdk/deepseek';
|
|
2
|
-
import { Agent } from '../agent';
|
|
3
|
-
import { BaseAiService } from './base-ai.service';
|
|
4
|
-
import { ModelInfo } from '../../shared/types/app.types';
|
|
5
|
-
export declare class DeepSeekAiService extends BaseAiService {
|
|
6
|
-
protected deepseekClient: ReturnType<typeof createDeepSeek>;
|
|
7
|
-
constructor();
|
|
8
|
-
getServiceName(): string;
|
|
9
|
-
fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
10
|
-
addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean): void;
|
|
11
|
-
private jsonSchemaToZod;
|
|
12
|
-
textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
13
|
-
attachDocument(agent: Agent, fileName: string, fileData: Uint8Array): Promise<string>;
|
|
14
|
-
private computeMessageCost;
|
|
15
|
-
}
|