@hed-hog/core 0.0.222 → 0.0.232
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/ai/ai.controller.d.ts +90 -0
- package/dist/ai/ai.controller.d.ts.map +1 -0
- package/dist/ai/ai.controller.js +119 -0
- package/dist/ai/ai.controller.js.map +1 -0
- package/dist/ai/ai.module.d.ts +3 -0
- package/dist/ai/ai.module.d.ts.map +1 -0
- package/dist/ai/ai.module.js +26 -0
- package/dist/ai/ai.module.js.map +1 -0
- package/dist/ai/ai.service.d.ts +69 -0
- package/dist/ai/ai.service.d.ts.map +1 -0
- package/dist/ai/ai.service.js +394 -0
- package/dist/ai/ai.service.js.map +1 -0
- package/dist/ai/dto/chat-agent.dto.d.ts +4 -0
- package/dist/ai/dto/chat-agent.dto.d.ts.map +1 -0
- package/dist/ai/dto/chat-agent.dto.js +22 -0
- package/dist/ai/dto/chat-agent.dto.js.map +1 -0
- package/dist/ai/dto/chat.dto.d.ts +7 -0
- package/dist/ai/dto/chat.dto.d.ts.map +1 -0
- package/dist/ai/dto/chat.dto.js +38 -0
- package/dist/ai/dto/chat.dto.js.map +1 -0
- package/dist/ai/dto/create-agent.dto.d.ts +7 -0
- package/dist/ai/dto/create-agent.dto.d.ts.map +1 -0
- package/dist/ai/dto/create-agent.dto.js +38 -0
- package/dist/ai/dto/create-agent.dto.js.map +1 -0
- package/dist/ai/dto/update-agent.dto.d.ts +7 -0
- package/dist/ai/dto/update-agent.dto.d.ts.map +1 -0
- package/dist/ai/dto/update-agent.dto.js +38 -0
- package/dist/ai/dto/update-agent.dto.js.map +1 -0
- package/dist/auth/auth.controller.d.ts +2 -2
- package/dist/auth/auth.service.d.ts +7 -7
- package/dist/core.module.d.ts.map +1 -1
- package/dist/core.module.js +3 -0
- package/dist/core.module.js.map +1 -1
- package/dist/file/file.service.d.ts +2 -0
- package/dist/file/file.service.d.ts.map +1 -1
- package/dist/file/file.service.js +17 -2
- package/dist/file/file.service.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/session/session.controller.d.ts +1 -1
- package/dist/session/session.service.d.ts +3 -3
- package/dist/user/user.controller.d.ts +1 -1
- package/dist/user/user.service.d.ts +3 -3
- package/hedhog/data/menu.yaml +17 -3
- package/hedhog/data/route.yaml +64 -0
- package/hedhog/data/setting_group.yaml +33 -1
- package/hedhog/frontend/app/ai_agent/page.tsx.ejs +468 -0
- package/hedhog/table/ai_agent.yaml +24 -0
- package/package.json +5 -5
- package/src/ai/ai.controller.ts +61 -0
- package/src/ai/ai.module.ts +13 -0
- package/src/ai/ai.service.ts +546 -0
- package/src/ai/dto/chat-agent.dto.ts +7 -0
- package/src/ai/dto/chat.dto.ts +20 -0
- package/src/ai/dto/create-agent.dto.ts +20 -0
- package/src/ai/dto/update-agent.dto.ts +20 -0
- package/src/core.module.ts +3 -0
- package/src/file/file.service.ts +34 -8
- package/src/index.ts +1 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AiService = void 0;
|
|
19
|
+
const api_prisma_1 = require("@hed-hog/api-prisma");
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const client_1 = require("@prisma/client");
|
|
22
|
+
const axios_1 = __importDefault(require("axios"));
|
|
23
|
+
const setting_service_1 = require("../setting/setting.service");
|
|
24
|
+
let AiService = class AiService {
|
|
25
|
+
constructor(prismaService, settingService) {
|
|
26
|
+
this.prismaService = prismaService;
|
|
27
|
+
this.settingService = settingService;
|
|
28
|
+
}
|
|
29
|
+
async chat(data) {
|
|
30
|
+
const provider = data.provider || 'openai';
|
|
31
|
+
if (provider === 'openai') {
|
|
32
|
+
const model = data.model || 'gpt-4o-mini';
|
|
33
|
+
const content = await this.chatWithOpenAi({
|
|
34
|
+
message: data.message,
|
|
35
|
+
model,
|
|
36
|
+
systemPrompt: data.systemPrompt,
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
provider,
|
|
40
|
+
model,
|
|
41
|
+
content,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const model = data.model || 'gemini-1.5-flash';
|
|
45
|
+
const content = await this.chatWithGemini({
|
|
46
|
+
message: data.message,
|
|
47
|
+
model,
|
|
48
|
+
systemPrompt: data.systemPrompt,
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
provider,
|
|
52
|
+
model,
|
|
53
|
+
content,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async createAgent(data) {
|
|
57
|
+
var _a;
|
|
58
|
+
const slug = data.slug.trim();
|
|
59
|
+
const provider = data.provider || 'openai';
|
|
60
|
+
const model = data.model || this.getDefaultModel(provider);
|
|
61
|
+
const instructions = ((_a = data.instructions) === null || _a === void 0 ? void 0 : _a.trim()) || null;
|
|
62
|
+
const existing = await this.findAgentBySlug(slug);
|
|
63
|
+
if (existing) {
|
|
64
|
+
return existing;
|
|
65
|
+
}
|
|
66
|
+
let externalAgentId = null;
|
|
67
|
+
if (provider === 'openai') {
|
|
68
|
+
externalAgentId = await this.createOpenAiAssistant({
|
|
69
|
+
slug,
|
|
70
|
+
model,
|
|
71
|
+
instructions,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
await this.prismaService.$executeRaw `
|
|
75
|
+
INSERT INTO ai_agent (slug, provider, model, instructions, external_agent_id)
|
|
76
|
+
VALUES (${slug}, ${provider}, ${model}, ${instructions}, ${externalAgentId})
|
|
77
|
+
`;
|
|
78
|
+
return this.findAgentBySlug(slug);
|
|
79
|
+
}
|
|
80
|
+
async listAgents(paginationParams) {
|
|
81
|
+
var _a;
|
|
82
|
+
const page = Math.max(Number((paginationParams === null || paginationParams === void 0 ? void 0 : paginationParams.page) || 1), 1);
|
|
83
|
+
const pageSize = Math.min(Math.max(Number((paginationParams === null || paginationParams === void 0 ? void 0 : paginationParams.pageSize) || 10), 1), 100);
|
|
84
|
+
const offset = (page - 1) * pageSize;
|
|
85
|
+
const search = String((paginationParams === null || paginationParams === void 0 ? void 0 : paginationParams.search) || '').trim();
|
|
86
|
+
const whereClause = search
|
|
87
|
+
? client_1.Prisma.sql `WHERE LOWER(slug) LIKE LOWER(${`%${search}%`})`
|
|
88
|
+
: client_1.Prisma.empty;
|
|
89
|
+
const data = await this.prismaService.$queryRaw(client_1.Prisma.sql `
|
|
90
|
+
SELECT id, slug, provider, model, instructions, external_agent_id, created_at, updated_at
|
|
91
|
+
FROM ai_agent
|
|
92
|
+
${whereClause}
|
|
93
|
+
ORDER BY id DESC
|
|
94
|
+
LIMIT ${pageSize}
|
|
95
|
+
OFFSET ${offset}
|
|
96
|
+
`);
|
|
97
|
+
const totalResult = await this.prismaService.$queryRaw(client_1.Prisma.sql `
|
|
98
|
+
SELECT COUNT(*) AS total
|
|
99
|
+
FROM ai_agent
|
|
100
|
+
${whereClause}
|
|
101
|
+
`);
|
|
102
|
+
const total = Number(((_a = totalResult === null || totalResult === void 0 ? void 0 : totalResult[0]) === null || _a === void 0 ? void 0 : _a.total) || 0);
|
|
103
|
+
return {
|
|
104
|
+
data,
|
|
105
|
+
total,
|
|
106
|
+
page,
|
|
107
|
+
pageSize,
|
|
108
|
+
totalPages: Math.ceil(total / pageSize),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async getAgentById(agentId) {
|
|
112
|
+
const agent = await this.findAgentById(agentId);
|
|
113
|
+
if (!agent) {
|
|
114
|
+
throw new common_1.NotFoundException(`AI agent with id "${agentId}" was not found.`);
|
|
115
|
+
}
|
|
116
|
+
return agent;
|
|
117
|
+
}
|
|
118
|
+
async updateAgent(agentId, data) {
|
|
119
|
+
var _a, _b, _c, _d, _e, _f;
|
|
120
|
+
const currentAgent = await this.findAgentById(agentId);
|
|
121
|
+
if (!currentAgent) {
|
|
122
|
+
throw new common_1.NotFoundException(`AI agent with id "${agentId}" was not found.`);
|
|
123
|
+
}
|
|
124
|
+
const slug = (_b = (_a = data.slug) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : currentAgent.slug;
|
|
125
|
+
const provider = (_c = data.provider) !== null && _c !== void 0 ? _c : currentAgent.provider;
|
|
126
|
+
const model = (_e = (_d = data.model) !== null && _d !== void 0 ? _d : currentAgent.model) !== null && _e !== void 0 ? _e : this.getDefaultModel(provider);
|
|
127
|
+
const instructions = (_f = data.instructions) !== null && _f !== void 0 ? _f : currentAgent.instructions;
|
|
128
|
+
if (slug !== currentAgent.slug) {
|
|
129
|
+
const existingSlug = await this.findAgentBySlug(slug);
|
|
130
|
+
if (existingSlug && existingSlug.id !== agentId) {
|
|
131
|
+
throw new common_1.BadRequestException(`AI agent with slug "${slug}" already exists.`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let externalAgentId = currentAgent.external_agent_id;
|
|
135
|
+
if (provider !== 'openai') {
|
|
136
|
+
externalAgentId = null;
|
|
137
|
+
}
|
|
138
|
+
else if (!externalAgentId) {
|
|
139
|
+
externalAgentId = await this.createOpenAiAssistant({
|
|
140
|
+
slug,
|
|
141
|
+
model,
|
|
142
|
+
instructions,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
await this.prismaService.$executeRaw `
|
|
146
|
+
UPDATE ai_agent
|
|
147
|
+
SET slug = ${slug},
|
|
148
|
+
provider = ${provider},
|
|
149
|
+
model = ${model},
|
|
150
|
+
instructions = ${instructions},
|
|
151
|
+
external_agent_id = ${externalAgentId},
|
|
152
|
+
updated_at = NOW()
|
|
153
|
+
WHERE id = ${agentId}
|
|
154
|
+
`;
|
|
155
|
+
return this.getAgentById(agentId);
|
|
156
|
+
}
|
|
157
|
+
async deleteAgents({ ids }) {
|
|
158
|
+
const existing = await this.prismaService.$queryRaw(client_1.Prisma.sql `
|
|
159
|
+
SELECT id
|
|
160
|
+
FROM ai_agent
|
|
161
|
+
WHERE id IN (${client_1.Prisma.join(ids)})
|
|
162
|
+
`);
|
|
163
|
+
if (existing.length !== ids.length) {
|
|
164
|
+
const existingIds = existing.map((item) => item.id);
|
|
165
|
+
const missingIds = ids.filter((id) => !existingIds.includes(id));
|
|
166
|
+
throw new common_1.NotFoundException(`AI agents with ids "${missingIds.join(', ')}" were not found.`);
|
|
167
|
+
}
|
|
168
|
+
const deletedCount = await this.prismaService.$executeRaw `
|
|
169
|
+
DELETE FROM ai_agent
|
|
170
|
+
WHERE id IN (${client_1.Prisma.join(ids)})
|
|
171
|
+
`;
|
|
172
|
+
return {
|
|
173
|
+
count: Number(deletedCount || 0),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async chatWithAgent(slug, data) {
|
|
177
|
+
const agent = await this.findAgentBySlug(slug);
|
|
178
|
+
if (!agent) {
|
|
179
|
+
throw new common_1.NotFoundException(`AI agent with slug "${slug}" was not found.`);
|
|
180
|
+
}
|
|
181
|
+
if (agent.provider === 'openai') {
|
|
182
|
+
if (agent.external_agent_id) {
|
|
183
|
+
const content = await this.chatWithOpenAiAssistant(agent.external_agent_id, data.message);
|
|
184
|
+
return {
|
|
185
|
+
slug: agent.slug,
|
|
186
|
+
provider: agent.provider,
|
|
187
|
+
model: agent.model,
|
|
188
|
+
content,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const content = await this.chatWithOpenAi({
|
|
192
|
+
message: data.message,
|
|
193
|
+
model: agent.model || this.getDefaultModel('openai'),
|
|
194
|
+
systemPrompt: agent.instructions || undefined,
|
|
195
|
+
});
|
|
196
|
+
return {
|
|
197
|
+
slug: agent.slug,
|
|
198
|
+
provider: agent.provider,
|
|
199
|
+
model: agent.model,
|
|
200
|
+
content,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const content = await this.chatWithGemini({
|
|
204
|
+
message: data.message,
|
|
205
|
+
model: agent.model || this.getDefaultModel('gemini'),
|
|
206
|
+
systemPrompt: agent.instructions || undefined,
|
|
207
|
+
});
|
|
208
|
+
return {
|
|
209
|
+
slug: agent.slug,
|
|
210
|
+
provider: agent.provider,
|
|
211
|
+
model: agent.model,
|
|
212
|
+
content,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
async getAgentBySlug(slug) {
|
|
216
|
+
const agent = await this.findAgentBySlug(slug);
|
|
217
|
+
if (!agent) {
|
|
218
|
+
throw new common_1.NotFoundException(`AI agent with slug "${slug}" was not found.`);
|
|
219
|
+
}
|
|
220
|
+
return agent;
|
|
221
|
+
}
|
|
222
|
+
async findAgentBySlug(slug) {
|
|
223
|
+
const result = await this.prismaService.$queryRaw `
|
|
224
|
+
SELECT id, slug, provider, model, instructions, external_agent_id, created_at, updated_at
|
|
225
|
+
FROM ai_agent
|
|
226
|
+
WHERE slug = ${slug}
|
|
227
|
+
LIMIT 1
|
|
228
|
+
`;
|
|
229
|
+
return (result === null || result === void 0 ? void 0 : result[0]) || null;
|
|
230
|
+
}
|
|
231
|
+
async findAgentById(id) {
|
|
232
|
+
const result = await this.prismaService.$queryRaw `
|
|
233
|
+
SELECT id, slug, provider, model, instructions, external_agent_id, created_at, updated_at
|
|
234
|
+
FROM ai_agent
|
|
235
|
+
WHERE id = ${id}
|
|
236
|
+
LIMIT 1
|
|
237
|
+
`;
|
|
238
|
+
return (result === null || result === void 0 ? void 0 : result[0]) || null;
|
|
239
|
+
}
|
|
240
|
+
getDefaultModel(provider) {
|
|
241
|
+
if (provider === 'openai') {
|
|
242
|
+
return 'gpt-4o-mini';
|
|
243
|
+
}
|
|
244
|
+
return 'gemini-1.5-flash';
|
|
245
|
+
}
|
|
246
|
+
async getApiKeys() {
|
|
247
|
+
const settings = await this.settingService.getSettingValues([
|
|
248
|
+
'ai-openai-api-key',
|
|
249
|
+
'ai-gemini-api-key',
|
|
250
|
+
]);
|
|
251
|
+
return {
|
|
252
|
+
openai: settings['ai-openai-api-key'],
|
|
253
|
+
gemini: settings['ai-gemini-api-key'],
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
async chatWithOpenAi({ message, model, systemPrompt, }) {
|
|
257
|
+
var _a, _b, _c, _d;
|
|
258
|
+
const { openai } = await this.getApiKeys();
|
|
259
|
+
if (!openai) {
|
|
260
|
+
throw new common_1.BadRequestException('OpenAI API key is not configured (setting "ai-openai-api-key").');
|
|
261
|
+
}
|
|
262
|
+
const messages = [];
|
|
263
|
+
if (systemPrompt) {
|
|
264
|
+
messages.push({ role: 'system', content: systemPrompt });
|
|
265
|
+
}
|
|
266
|
+
messages.push({ role: 'user', content: message });
|
|
267
|
+
const response = await axios_1.default.post('https://api.openai.com/v1/chat/completions', {
|
|
268
|
+
model,
|
|
269
|
+
messages,
|
|
270
|
+
}, {
|
|
271
|
+
headers: {
|
|
272
|
+
Authorization: `Bearer ${openai}`,
|
|
273
|
+
'Content-Type': 'application/json',
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
return ((_d = (_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.choices) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.content) || '';
|
|
277
|
+
}
|
|
278
|
+
async createOpenAiAssistant({ slug, model, instructions, }) {
|
|
279
|
+
var _a;
|
|
280
|
+
const { openai } = await this.getApiKeys();
|
|
281
|
+
if (!openai) {
|
|
282
|
+
throw new common_1.BadRequestException('OpenAI API key is not configured (setting "ai-openai-api-key").');
|
|
283
|
+
}
|
|
284
|
+
const response = await axios_1.default.post('https://api.openai.com/v1/assistants', {
|
|
285
|
+
name: slug,
|
|
286
|
+
model,
|
|
287
|
+
instructions: instructions || `You are the assistant identified by slug ${slug}.`,
|
|
288
|
+
}, {
|
|
289
|
+
headers: {
|
|
290
|
+
Authorization: `Bearer ${openai}`,
|
|
291
|
+
'Content-Type': 'application/json',
|
|
292
|
+
'OpenAI-Beta': 'assistants=v2',
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
const assistantId = (_a = response.data) === null || _a === void 0 ? void 0 : _a.id;
|
|
296
|
+
if (!assistantId) {
|
|
297
|
+
throw new common_1.BadRequestException('OpenAI assistant creation failed.');
|
|
298
|
+
}
|
|
299
|
+
return assistantId;
|
|
300
|
+
}
|
|
301
|
+
async chatWithOpenAiAssistant(assistantId, message) {
|
|
302
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
303
|
+
const { openai } = await this.getApiKeys();
|
|
304
|
+
if (!openai) {
|
|
305
|
+
throw new common_1.BadRequestException('OpenAI API key is not configured (setting "ai-openai-api-key").');
|
|
306
|
+
}
|
|
307
|
+
const threadResponse = await axios_1.default.post('https://api.openai.com/v1/threads', {
|
|
308
|
+
messages: [{ role: 'user', content: message }],
|
|
309
|
+
}, {
|
|
310
|
+
headers: {
|
|
311
|
+
Authorization: `Bearer ${openai}`,
|
|
312
|
+
'Content-Type': 'application/json',
|
|
313
|
+
'OpenAI-Beta': 'assistants=v2',
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
const threadId = (_a = threadResponse.data) === null || _a === void 0 ? void 0 : _a.id;
|
|
317
|
+
if (!threadId) {
|
|
318
|
+
throw new common_1.BadRequestException('OpenAI thread creation failed.');
|
|
319
|
+
}
|
|
320
|
+
const runResponse = await axios_1.default.post(`https://api.openai.com/v1/threads/${threadId}/runs`, {
|
|
321
|
+
assistant_id: assistantId,
|
|
322
|
+
}, {
|
|
323
|
+
headers: {
|
|
324
|
+
Authorization: `Bearer ${openai}`,
|
|
325
|
+
'Content-Type': 'application/json',
|
|
326
|
+
'OpenAI-Beta': 'assistants=v2',
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
const runId = (_b = runResponse.data) === null || _b === void 0 ? void 0 : _b.id;
|
|
330
|
+
if (!runId) {
|
|
331
|
+
throw new common_1.BadRequestException('OpenAI assistant run failed to start.');
|
|
332
|
+
}
|
|
333
|
+
for (let i = 0; i < 30; i++) {
|
|
334
|
+
const runStatusResponse = await axios_1.default.get(`https://api.openai.com/v1/threads/${threadId}/runs/${runId}`, {
|
|
335
|
+
headers: {
|
|
336
|
+
Authorization: `Bearer ${openai}`,
|
|
337
|
+
'OpenAI-Beta': 'assistants=v2',
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
const status = (_c = runStatusResponse.data) === null || _c === void 0 ? void 0 : _c.status;
|
|
341
|
+
if (status === 'completed') {
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
if (['cancelled', 'failed', 'expired'].includes(status)) {
|
|
345
|
+
throw new common_1.BadRequestException(`OpenAI assistant run did not complete successfully (status: ${status}).`);
|
|
346
|
+
}
|
|
347
|
+
await this.sleep(1000);
|
|
348
|
+
}
|
|
349
|
+
const messagesResponse = await axios_1.default.get(`https://api.openai.com/v1/threads/${threadId}/messages`, {
|
|
350
|
+
headers: {
|
|
351
|
+
Authorization: `Bearer ${openai}`,
|
|
352
|
+
'OpenAI-Beta': 'assistants=v2',
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
const assistantMessage = (_e = (_d = messagesResponse.data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.find((item) => item.role === 'assistant');
|
|
356
|
+
const output = (_h = (_g = (_f = assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.content) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.text) === null || _h === void 0 ? void 0 : _h.value;
|
|
357
|
+
return output || '';
|
|
358
|
+
}
|
|
359
|
+
async chatWithGemini({ message, model, systemPrompt, }) {
|
|
360
|
+
var _a, _b, _c, _d;
|
|
361
|
+
const { gemini } = await this.getApiKeys();
|
|
362
|
+
if (!gemini) {
|
|
363
|
+
throw new common_1.BadRequestException('Gemini API key is not configured (setting "ai-gemini-api-key").');
|
|
364
|
+
}
|
|
365
|
+
const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${gemini}`;
|
|
366
|
+
const payload = {
|
|
367
|
+
contents: [{ parts: [{ text: message }] }],
|
|
368
|
+
};
|
|
369
|
+
if (systemPrompt) {
|
|
370
|
+
payload.systemInstruction = {
|
|
371
|
+
parts: [{ text: systemPrompt }],
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const response = await axios_1.default.post(url, payload, {
|
|
375
|
+
headers: {
|
|
376
|
+
'Content-Type': 'application/json',
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
const parts = ((_d = (_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.candidates) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.parts) || [];
|
|
380
|
+
return parts.map((part) => part.text || '').join('');
|
|
381
|
+
}
|
|
382
|
+
async sleep(ms) {
|
|
383
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
exports.AiService = AiService;
|
|
387
|
+
exports.AiService = AiService = __decorate([
|
|
388
|
+
(0, common_1.Injectable)(),
|
|
389
|
+
__param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => api_prisma_1.PrismaService))),
|
|
390
|
+
__param(1, (0, common_1.Inject)((0, common_1.forwardRef)(() => setting_service_1.SettingService))),
|
|
391
|
+
__metadata("design:paramtypes", [api_prisma_1.PrismaService,
|
|
392
|
+
setting_service_1.SettingService])
|
|
393
|
+
], AiService);
|
|
394
|
+
//# sourceMappingURL=ai.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.service.js","sourceRoot":"","sources":["../../src/ai/ai.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,oDAAoD;AACpD,2CAMwB;AACxB,2CAAwC;AACxC,kDAA0B;AAE1B,gEAA4D;AAoBrD,IAAM,SAAS,GAAf,MAAM,SAAS;IACpB,YAEmB,aAA4B,EAE5B,cAA8B;QAF9B,kBAAa,GAAb,aAAa,CAAe;QAE5B,mBAAc,GAAd,cAAc,CAAgB;IAC9C,CAAC;IAEJ,KAAK,CAAC,IAAI,CAAC,IAAa;QACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC;QAE3C,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,aAAa,CAAC;YAC1C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;gBACxC,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,KAAK;gBACL,YAAY,EAAE,IAAI,CAAC,YAAY;aAChC,CAAC,CAAC;YAEH,OAAO;gBACL,QAAQ;gBACR,KAAK;gBACL,OAAO;aACR,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,kBAAkB,CAAC;QAC/C,MAAM,OAAO,GAAG,MAAM,IAAI,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CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5D,CAAC;IAEO,KAAK,CAAC,KAAK,CAAC,EAAU;QAC5B,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AAjgBY,8BAAS;oBAAT,SAAS;IADrB,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,0BAAa,CAAC,CAAC,CAAA;IAEvC,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,gCAAc,CAAC,CAAC,CAAA;qCADT,0BAAa;QAEZ,gCAAc;GALtC,SAAS,CAigBrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-agent.dto.d.ts","sourceRoot":"","sources":["../../../src/ai/dto/chat-agent.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IAGvB,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ChatAgentDTO = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
class ChatAgentDTO {
|
|
15
|
+
}
|
|
16
|
+
exports.ChatAgentDTO = ChatAgentDTO;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsString)(),
|
|
19
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], ChatAgentDTO.prototype, "message", void 0);
|
|
22
|
+
//# sourceMappingURL=chat-agent.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-agent.dto.js","sourceRoot":"","sources":["../../../src/ai/dto/chat-agent.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAuD;AAEvD,MAAa,YAAY;CAIxB;AAJD,oCAIC;AADC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;6CACG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.dto.d.ts","sourceRoot":"","sources":["../../../src/ai/dto/chat.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,OAAO;IAGlB,OAAO,EAAE,MAAM,CAAC;IAKhB,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAI/B,KAAK,CAAC,EAAE,MAAM,CAAC;IAIf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ChatDTO = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
class ChatDTO {
|
|
15
|
+
}
|
|
16
|
+
exports.ChatDTO = ChatDTO;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsString)(),
|
|
19
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], ChatDTO.prototype, "message", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsOptional)(),
|
|
24
|
+
(0, class_validator_1.IsString)(),
|
|
25
|
+
(0, class_validator_1.IsIn)(['openai', 'gemini']),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], ChatDTO.prototype, "provider", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, class_validator_1.IsOptional)(),
|
|
30
|
+
(0, class_validator_1.IsString)(),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], ChatDTO.prototype, "model", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, class_validator_1.IsOptional)(),
|
|
35
|
+
(0, class_validator_1.IsString)(),
|
|
36
|
+
__metadata("design:type", String)
|
|
37
|
+
], ChatDTO.prototype, "systemPrompt", void 0);
|
|
38
|
+
//# sourceMappingURL=chat.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.dto.js","sourceRoot":"","sources":["../../../src/ai/dto/chat.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAyE;AAEzE,MAAa,OAAO;CAiBnB;AAjBD,0BAiBC;AAdC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;wCACG;AAKhB;IAHC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,sBAAI,EAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;;yCACI;AAI/B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;sCACI;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;6CACW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-agent.dto.d.ts","sourceRoot":"","sources":["../../../src/ai/dto/create-agent.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,cAAc;IAGzB,IAAI,EAAE,MAAM,CAAC;IAKb,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAI/B,KAAK,CAAC,EAAE,MAAM,CAAC;IAIf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CreateAgentDTO = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
class CreateAgentDTO {
|
|
15
|
+
}
|
|
16
|
+
exports.CreateAgentDTO = CreateAgentDTO;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsString)(),
|
|
19
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], CreateAgentDTO.prototype, "slug", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsOptional)(),
|
|
24
|
+
(0, class_validator_1.IsString)(),
|
|
25
|
+
(0, class_validator_1.IsIn)(['openai', 'gemini']),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], CreateAgentDTO.prototype, "provider", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, class_validator_1.IsOptional)(),
|
|
30
|
+
(0, class_validator_1.IsString)(),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], CreateAgentDTO.prototype, "model", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, class_validator_1.IsOptional)(),
|
|
35
|
+
(0, class_validator_1.IsString)(),
|
|
36
|
+
__metadata("design:type", String)
|
|
37
|
+
], CreateAgentDTO.prototype, "instructions", void 0);
|
|
38
|
+
//# sourceMappingURL=create-agent.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-agent.dto.js","sourceRoot":"","sources":["../../../src/ai/dto/create-agent.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAyE;AAEzE,MAAa,cAAc;CAiB1B;AAjBD,wCAiBC;AAdC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;4CACA;AAKb;IAHC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,sBAAI,EAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;;gDACI;AAI/B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;6CACI;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-agent.dto.d.ts","sourceRoot":"","sources":["../../../src/ai/dto/update-agent.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,cAAc;IAGzB,IAAI,CAAC,EAAE,MAAM,CAAC;IAKd,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAI/B,KAAK,CAAC,EAAE,MAAM,CAAC;IAIf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UpdateAgentDTO = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
class UpdateAgentDTO {
|
|
15
|
+
}
|
|
16
|
+
exports.UpdateAgentDTO = UpdateAgentDTO;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsOptional)(),
|
|
19
|
+
(0, class_validator_1.IsString)(),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], UpdateAgentDTO.prototype, "slug", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsOptional)(),
|
|
24
|
+
(0, class_validator_1.IsString)(),
|
|
25
|
+
(0, class_validator_1.IsIn)(['openai', 'gemini']),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], UpdateAgentDTO.prototype, "provider", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, class_validator_1.IsOptional)(),
|
|
30
|
+
(0, class_validator_1.IsString)(),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], UpdateAgentDTO.prototype, "model", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, class_validator_1.IsOptional)(),
|
|
35
|
+
(0, class_validator_1.IsString)(),
|
|
36
|
+
__metadata("design:type", String)
|
|
37
|
+
], UpdateAgentDTO.prototype, "instructions", void 0);
|
|
38
|
+
//# sourceMappingURL=update-agent.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-agent.dto.js","sourceRoot":"","sources":["../../../src/ai/dto/update-agent.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA6D;AAE7D,MAAa,cAAc;CAiB1B;AAjBD,wCAiBC;AAdC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;4CACG;AAKd;IAHC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,sBAAI,EAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;;gDACI;AAI/B;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;6CACI;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACW"}
|
|
@@ -63,10 +63,10 @@ export declare class AuthController {
|
|
|
63
63
|
hash: string;
|
|
64
64
|
created_at: Date;
|
|
65
65
|
updated_at: Date;
|
|
66
|
+
ip_address: string;
|
|
66
67
|
user_id: number;
|
|
67
68
|
revoked_at: Date | null;
|
|
68
69
|
expires_at: Date;
|
|
69
|
-
ip_address: string;
|
|
70
70
|
user_agent: string;
|
|
71
71
|
}[];
|
|
72
72
|
} & {
|
|
@@ -172,10 +172,10 @@ export declare class AuthController {
|
|
|
172
172
|
hash: string;
|
|
173
173
|
created_at: Date;
|
|
174
174
|
updated_at: Date;
|
|
175
|
+
ip_address: string;
|
|
175
176
|
user_id: number;
|
|
176
177
|
revoked_at: Date | null;
|
|
177
178
|
expires_at: Date;
|
|
178
|
-
ip_address: string;
|
|
179
179
|
user_agent: string;
|
|
180
180
|
};
|
|
181
181
|
}>;
|