@hed-hog/core 0.0.327 → 0.0.329

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/ai/ai.service.d.ts +1 -1
  2. package/dist/auth/auth.controller.d.ts +2 -2
  3. package/dist/auth/auth.service.d.ts +2 -2
  4. package/dist/core/system.controller.d.ts +1 -1
  5. package/dist/core/system.service.d.ts +1 -1
  6. package/dist/core.module.d.ts.map +1 -1
  7. package/dist/core.module.js +4 -0
  8. package/dist/core.module.js.map +1 -1
  9. package/dist/dashboard/dashboard/dashboard.controller.d.ts +21 -21
  10. package/dist/dashboard/dashboard/dashboard.service.d.ts +21 -21
  11. package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts +11 -11
  12. package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts +11 -11
  13. package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.d.ts +5 -5
  14. package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.d.ts +5 -5
  15. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +4 -4
  16. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +4 -4
  17. package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts +4 -4
  18. package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts +4 -4
  19. package/dist/dashboard/dashboard-role/dashboard-role.controller.d.ts +3 -3
  20. package/dist/dashboard/dashboard-role/dashboard-role.service.d.ts +3 -3
  21. package/dist/file/file.controller.d.ts +6 -6
  22. package/dist/file/file.service.d.ts +12 -12
  23. package/dist/index.d.ts +5 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +6 -0
  26. package/dist/index.js.map +1 -1
  27. package/dist/mail/mail.controller.d.ts +2 -2
  28. package/dist/mail/mail.service.d.ts +2 -2
  29. package/dist/mail-sent/mail-sent.controller.d.ts +3 -3
  30. package/dist/mail-sent/mail-sent.service.d.ts +3 -3
  31. package/dist/mcp/decorators/mcp-tool.decorator.d.ts +4 -0
  32. package/dist/mcp/decorators/mcp-tool.decorator.d.ts.map +1 -0
  33. package/dist/mcp/decorators/mcp-tool.decorator.js +8 -0
  34. package/dist/mcp/decorators/mcp-tool.decorator.js.map +1 -0
  35. package/dist/mcp/guards/mcp-auth.guard.d.ts +9 -0
  36. package/dist/mcp/guards/mcp-auth.guard.d.ts.map +1 -0
  37. package/dist/mcp/guards/mcp-auth.guard.js +41 -0
  38. package/dist/mcp/guards/mcp-auth.guard.js.map +1 -0
  39. package/dist/mcp/guards/mcp-permission.guard.d.ts +8 -0
  40. package/dist/mcp/guards/mcp-permission.guard.d.ts.map +1 -0
  41. package/dist/mcp/guards/mcp-permission.guard.js +57 -0
  42. package/dist/mcp/guards/mcp-permission.guard.js.map +1 -0
  43. package/dist/mcp/interfaces/mcp-tool-definition.interface.d.ts +7 -0
  44. package/dist/mcp/interfaces/mcp-tool-definition.interface.d.ts.map +1 -0
  45. package/dist/mcp/interfaces/mcp-tool-definition.interface.js +3 -0
  46. package/dist/mcp/interfaces/mcp-tool-definition.interface.js.map +1 -0
  47. package/dist/mcp/mcp-audit.service.d.ts +17 -0
  48. package/dist/mcp/mcp-audit.service.d.ts.map +1 -0
  49. package/dist/mcp/mcp-audit.service.js +46 -0
  50. package/dist/mcp/mcp-audit.service.js.map +1 -0
  51. package/dist/mcp/mcp-registry.service.d.ts +21 -0
  52. package/dist/mcp/mcp-registry.service.d.ts.map +1 -0
  53. package/dist/mcp/mcp-registry.service.js +69 -0
  54. package/dist/mcp/mcp-registry.service.js.map +1 -0
  55. package/dist/mcp/mcp-server.service.d.ts +12 -0
  56. package/dist/mcp/mcp-server.service.d.ts.map +1 -0
  57. package/dist/mcp/mcp-server.service.js +94 -0
  58. package/dist/mcp/mcp-server.service.js.map +1 -0
  59. package/dist/mcp/mcp.controller.d.ts +8 -0
  60. package/dist/mcp/mcp.controller.d.ts.map +1 -0
  61. package/dist/mcp/mcp.controller.js +54 -0
  62. package/dist/mcp/mcp.controller.js.map +1 -0
  63. package/dist/mcp/mcp.module.d.ts +3 -0
  64. package/dist/mcp/mcp.module.d.ts.map +1 -0
  65. package/dist/mcp/mcp.module.js +49 -0
  66. package/dist/mcp/mcp.module.js.map +1 -0
  67. package/dist/mcp/tools/core-settings.mcp-tools.d.ts +12 -0
  68. package/dist/mcp/tools/core-settings.mcp-tools.d.ts.map +1 -0
  69. package/dist/mcp/tools/core-settings.mcp-tools.js +66 -0
  70. package/dist/mcp/tools/core-settings.mcp-tools.js.map +1 -0
  71. package/dist/mcp/tools/core-users.mcp-tools.d.ts +55 -0
  72. package/dist/mcp/tools/core-users.mcp-tools.d.ts.map +1 -0
  73. package/dist/mcp/tools/core-users.mcp-tools.js +295 -0
  74. package/dist/mcp/tools/core-users.mcp-tools.js.map +1 -0
  75. package/dist/mcp/types/mcp-context.type.d.ts +7 -0
  76. package/dist/mcp/types/mcp-context.type.d.ts.map +1 -0
  77. package/dist/mcp/types/mcp-context.type.js +3 -0
  78. package/dist/mcp/types/mcp-context.type.js.map +1 -0
  79. package/dist/mcp-chat/dto/create-conversation.dto.d.ts +4 -0
  80. package/dist/mcp-chat/dto/create-conversation.dto.d.ts.map +1 -0
  81. package/dist/mcp-chat/dto/create-conversation.dto.js +22 -0
  82. package/dist/mcp-chat/dto/create-conversation.dto.js.map +1 -0
  83. package/dist/mcp-chat/dto/send-message.dto.d.ts +4 -0
  84. package/dist/mcp-chat/dto/send-message.dto.d.ts.map +1 -0
  85. package/dist/mcp-chat/dto/send-message.dto.js +22 -0
  86. package/dist/mcp-chat/dto/send-message.dto.js.map +1 -0
  87. package/dist/mcp-chat/mcp-chat.controller.d.ts +55 -0
  88. package/dist/mcp-chat/mcp-chat.controller.d.ts.map +1 -0
  89. package/dist/mcp-chat/mcp-chat.controller.js +90 -0
  90. package/dist/mcp-chat/mcp-chat.controller.js.map +1 -0
  91. package/dist/mcp-chat/mcp-chat.module.d.ts +3 -0
  92. package/dist/mcp-chat/mcp-chat.module.d.ts.map +1 -0
  93. package/dist/mcp-chat/mcp-chat.module.js +30 -0
  94. package/dist/mcp-chat/mcp-chat.module.js.map +1 -0
  95. package/dist/mcp-chat/mcp-chat.service.d.ts +50 -0
  96. package/dist/mcp-chat/mcp-chat.service.d.ts.map +1 -0
  97. package/dist/mcp-chat/mcp-chat.service.js +290 -0
  98. package/dist/mcp-chat/mcp-chat.service.js.map +1 -0
  99. package/dist/menu/menu.controller.d.ts +3 -3
  100. package/dist/menu/menu.service.d.ts +3 -3
  101. package/dist/profile/profile.controller.d.ts +2 -2
  102. package/dist/profile/profile.service.d.ts +2 -2
  103. package/dist/route/dto/create.dto.d.ts +6 -2
  104. package/dist/route/dto/create.dto.d.ts.map +1 -1
  105. package/dist/route/dto/create.dto.js +19 -1
  106. package/dist/route/dto/create.dto.js.map +1 -1
  107. package/dist/route/dto/update.dto.d.ts +4 -0
  108. package/dist/route/dto/update.dto.d.ts.map +1 -1
  109. package/dist/route/dto/update.dto.js +19 -3
  110. package/dist/route/dto/update.dto.js.map +1 -1
  111. package/dist/route/route.service.d.ts +1 -1
  112. package/dist/route/route.service.d.ts.map +1 -1
  113. package/dist/route/route.service.js +18 -11
  114. package/dist/route/route.service.js.map +1 -1
  115. package/dist/setting/setting.controller.d.ts +5 -5
  116. package/dist/setting/setting.service.d.ts +5 -5
  117. package/dist/user/user.controller.d.ts +3 -3
  118. package/dist/user/user.service.d.ts +6 -6
  119. package/hedhog/data/menu.yaml +40 -26
  120. package/hedhog/data/route.yaml +575 -152
  121. package/hedhog/data/setting_group.yaml +1 -1
  122. package/hedhog/frontend/app/configurations/[slug]/page.tsx.ejs +8 -1
  123. package/hedhog/frontend/app/configurations/layout.tsx.ejs +152 -34
  124. package/hedhog/frontend/app/mcp_chat/page.tsx.ejs +574 -0
  125. package/hedhog/frontend/messages/en.json +17 -0
  126. package/hedhog/frontend/messages/pt.json +17 -0
  127. package/hedhog/table/mcp_conversation.yaml +12 -0
  128. package/hedhog/table/mcp_conversation_message.yaml +23 -0
  129. package/hedhog/table/mcp_tool_call_log.yaml +22 -0
  130. package/hedhog/table/route.yaml +33 -22
  131. package/package.json +5 -4
  132. package/src/core.module.ts +14 -10
  133. package/src/index.ts +17 -10
  134. package/src/mcp/decorators/mcp-tool.decorator.ts +7 -0
  135. package/src/mcp/guards/mcp-auth.guard.ts +32 -0
  136. package/src/mcp/guards/mcp-permission.guard.ts +51 -0
  137. package/src/mcp/interfaces/mcp-tool-definition.interface.ts +6 -0
  138. package/src/mcp/mcp-audit.service.ts +36 -0
  139. package/src/mcp/mcp-registry.service.ts +69 -0
  140. package/src/mcp/mcp-server.service.ts +87 -0
  141. package/src/mcp/mcp.controller.ts +30 -0
  142. package/src/mcp/mcp.module.ts +36 -0
  143. package/src/mcp/tools/core-settings.mcp-tools.ts +53 -0
  144. package/src/mcp/tools/core-users.mcp-tools.ts +267 -0
  145. package/src/mcp/types/mcp-context.type.ts +6 -0
  146. package/src/mcp-chat/dto/create-conversation.dto.ts +7 -0
  147. package/src/mcp-chat/dto/send-message.dto.ts +7 -0
  148. package/src/mcp-chat/mcp-chat.controller.ts +60 -0
  149. package/src/mcp-chat/mcp-chat.module.ts +17 -0
  150. package/src/mcp-chat/mcp-chat.service.ts +332 -0
  151. package/src/route/dto/create.dto.ts +32 -14
  152. package/src/route/dto/update.dto.ts +31 -16
  153. package/src/route/route.service.ts +23 -12
@@ -0,0 +1,30 @@
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.McpChatModule = void 0;
10
+ const api_prisma_1 = require("@hed-hog/api-prisma");
11
+ const common_1 = require("@nestjs/common");
12
+ const mcp_module_1 = require("../mcp/mcp.module");
13
+ const setting_module_1 = require("../setting/setting.module");
14
+ const mcp_chat_controller_1 = require("./mcp-chat.controller");
15
+ const mcp_chat_service_1 = require("./mcp-chat.service");
16
+ let McpChatModule = class McpChatModule {
17
+ };
18
+ exports.McpChatModule = McpChatModule;
19
+ exports.McpChatModule = McpChatModule = __decorate([
20
+ (0, common_1.Module)({
21
+ imports: [
22
+ (0, common_1.forwardRef)(() => api_prisma_1.PrismaModule),
23
+ (0, common_1.forwardRef)(() => setting_module_1.SettingModule),
24
+ (0, common_1.forwardRef)(() => mcp_module_1.McpModule),
25
+ ],
26
+ controllers: [mcp_chat_controller_1.McpChatController],
27
+ providers: [mcp_chat_service_1.McpChatService],
28
+ })
29
+ ], McpChatModule);
30
+ //# sourceMappingURL=mcp-chat.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-chat.module.js","sourceRoot":"","sources":["../../src/mcp-chat/mcp-chat.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAmD;AACnD,2CAAoD;AACpD,kDAA8C;AAC9C,8DAA0D;AAC1D,+DAA0D;AAC1D,yDAAoD;AAW7C,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IATzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,yBAAY,CAAC;YAC9B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,8BAAa,CAAC;YAC/B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,sBAAS,CAAC;SAC5B;QACD,WAAW,EAAE,CAAC,uCAAiB,CAAC;QAChC,SAAS,EAAE,CAAC,iCAAc,CAAC;KAC5B,CAAC;GACW,aAAa,CAAG"}
@@ -0,0 +1,50 @@
1
+ import { PrismaService } from '@hed-hog/api-prisma';
2
+ import { SettingService } from '../setting/setting.service';
3
+ import { McpRegistryService } from '../mcp/mcp-registry.service';
4
+ import { CreateConversationDTO } from './dto/create-conversation.dto';
5
+ export declare class McpChatService {
6
+ private readonly prisma;
7
+ private readonly setting;
8
+ private readonly registry;
9
+ constructor(prisma: PrismaService, setting: SettingService, registry: McpRegistryService);
10
+ listConversations(userId: number): Promise<{
11
+ id: number;
12
+ title: string;
13
+ created_at: Date;
14
+ updated_at: Date;
15
+ }[]>;
16
+ createConversation(userId: number, dto: CreateConversationDTO): Promise<{
17
+ id: number;
18
+ title: string | null;
19
+ created_at: Date;
20
+ updated_at: Date;
21
+ user_id: number;
22
+ }>;
23
+ deleteConversations(userId: number, ids: number[]): Promise<{
24
+ count: number;
25
+ }>;
26
+ getMessages(conversationId: number, userId: number): Promise<{
27
+ id: number;
28
+ content: string;
29
+ role: import("@prisma/client").$Enums.mcp_conversation_message_role_422a6ea954_enum;
30
+ created_at: Date;
31
+ updated_at: Date;
32
+ conversation_id: number;
33
+ tool_name: string | null;
34
+ tool_call_id: string | null;
35
+ }[]>;
36
+ sendMessage(conversationId: number, userId: number, locale: string, message: string): Promise<{
37
+ id: number;
38
+ content: string;
39
+ role: import("@prisma/client").$Enums.mcp_conversation_message_role_422a6ea954_enum;
40
+ created_at: Date;
41
+ updated_at: Date;
42
+ conversation_id: number;
43
+ tool_name: string | null;
44
+ tool_call_id: string | null;
45
+ }[]>;
46
+ private toOpenAiMessages;
47
+ private assertOwnership;
48
+ private getOpenAiKey;
49
+ }
50
+ //# sourceMappingURL=mcp-chat.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-chat.service.d.ts","sourceRoot":"","sources":["../../src/mcp-chat/mcp-chat.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAYpD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAsBtE,qBACa,cAAc;IAGvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAJR,MAAM,EAAE,aAAa,EAErB,OAAO,EAAE,cAAc,EAEvB,QAAQ,EAAE,kBAAkB;IAGzC,iBAAiB,CAAC,MAAM,EAAE,MAAM;;;;;;IAQhC,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,qBAAqB;;;;;;;IAS7D,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;;;IAOjD,WAAW,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;IAQlD,WAAW,CACf,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM;;;;;;;;;;IAsLjB,OAAO,CAAC,gBAAgB;YA0CV,eAAe;YAaf,YAAY;CAU3B"}
@@ -0,0 +1,290 @@
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.McpChatService = void 0;
19
+ const api_prisma_1 = require("@hed-hog/api-prisma");
20
+ const common_1 = require("@nestjs/common");
21
+ const axios_1 = __importDefault(require("axios"));
22
+ const setting_service_1 = require("../setting/setting.service");
23
+ const mcp_registry_service_1 = require("../mcp/mcp-registry.service");
24
+ const SYSTEM_PROMPT = 'You are a helpful assistant with access to tools from the HedHog system. ' +
25
+ 'Use the available tools to answer the user\'s questions accurately. ' +
26
+ 'Always respond in the same language the user writes in.';
27
+ const sanitize = (n) => n.replace(/\./g, '__');
28
+ const restore = (n) => n.replace(/__/g, '.');
29
+ let McpChatService = class McpChatService {
30
+ constructor(prisma, setting, registry) {
31
+ this.prisma = prisma;
32
+ this.setting = setting;
33
+ this.registry = registry;
34
+ }
35
+ async listConversations(userId) {
36
+ return this.prisma.mcp_conversation.findMany({
37
+ where: { user_id: userId },
38
+ orderBy: { created_at: 'desc' },
39
+ select: { id: true, title: true, created_at: true, updated_at: true },
40
+ });
41
+ }
42
+ async createConversation(userId, dto) {
43
+ var _a;
44
+ return this.prisma.mcp_conversation.create({
45
+ data: {
46
+ user_id: userId,
47
+ title: (_a = dto.title) !== null && _a !== void 0 ? _a : null,
48
+ },
49
+ });
50
+ }
51
+ async deleteConversations(userId, ids) {
52
+ await this.prisma.mcp_conversation.deleteMany({
53
+ where: { id: { in: ids }, user_id: userId },
54
+ });
55
+ return { count: ids.length };
56
+ }
57
+ async getMessages(conversationId, userId) {
58
+ await this.assertOwnership(conversationId, userId);
59
+ return this.prisma.mcp_conversation_message.findMany({
60
+ where: { conversation_id: conversationId },
61
+ orderBy: { created_at: 'asc' },
62
+ });
63
+ }
64
+ async sendMessage(conversationId, userId, locale, message) {
65
+ var _a, _b, _c, _d, _e, _f, _g, _h;
66
+ await this.assertOwnership(conversationId, userId);
67
+ const apiKey = await this.getOpenAiKey();
68
+ // Save user message
69
+ await this.prisma.mcp_conversation_message.create({
70
+ data: {
71
+ conversation_id: conversationId,
72
+ role: 'user',
73
+ content: message,
74
+ },
75
+ });
76
+ // Auto-set title on first message
77
+ const conv = await this.prisma.mcp_conversation.findUnique({
78
+ where: { id: conversationId },
79
+ });
80
+ if (!conv.title) {
81
+ await this.prisma.mcp_conversation.update({
82
+ where: { id: conversationId },
83
+ data: { title: message.slice(0, 60) },
84
+ });
85
+ }
86
+ // Build OpenAI messages from history
87
+ const history = await this.prisma.mcp_conversation_message.findMany({
88
+ where: { conversation_id: conversationId },
89
+ orderBy: { created_at: 'asc' },
90
+ });
91
+ const openAiMessages = [
92
+ { role: 'system', content: SYSTEM_PROMPT },
93
+ ...this.toOpenAiMessages(history),
94
+ ];
95
+ // Build tool definitions
96
+ const tools = this.registry.getAll().map((entry) => {
97
+ var _a;
98
+ return ({
99
+ type: 'function',
100
+ function: {
101
+ name: sanitize(entry.definition.name),
102
+ description: entry.definition.description,
103
+ parameters: (_a = entry.definition.inputSchema) !== null && _a !== void 0 ? _a : {
104
+ type: 'object',
105
+ properties: {},
106
+ },
107
+ },
108
+ });
109
+ });
110
+ // Tool-calling loop
111
+ let maxIterations = 10;
112
+ while (maxIterations-- > 0) {
113
+ let response;
114
+ try {
115
+ response = await axios_1.default.post('https://api.openai.com/v1/chat/completions', {
116
+ model: 'gpt-4o-mini',
117
+ messages: openAiMessages,
118
+ tools: tools.length > 0 ? tools : undefined,
119
+ tool_choice: tools.length > 0 ? 'auto' : undefined,
120
+ }, {
121
+ headers: {
122
+ Authorization: `Bearer ${apiKey}`,
123
+ 'Content-Type': 'application/json',
124
+ },
125
+ });
126
+ }
127
+ catch (err) {
128
+ const status = (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.status;
129
+ const errBody = (_c = (_b = err === null || err === void 0 ? void 0 : err.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error;
130
+ if (status === 429) {
131
+ throw new common_1.HttpException((_d = errBody === null || errBody === void 0 ? void 0 : errBody.message) !== null && _d !== void 0 ? _d : 'OpenAI rate limit exceeded. Please try again later.', common_1.HttpStatus.TOO_MANY_REQUESTS);
132
+ }
133
+ if (status === 401) {
134
+ throw new common_1.BadRequestException('Invalid OpenAI API key.');
135
+ }
136
+ throw new common_1.HttpException((_e = errBody === null || errBody === void 0 ? void 0 : errBody.message) !== null && _e !== void 0 ? _e : 'OpenAI API error.', status !== null && status !== void 0 ? status : common_1.HttpStatus.BAD_GATEWAY);
137
+ }
138
+ const choice = (_g = (_f = response.data) === null || _f === void 0 ? void 0 : _f.choices) === null || _g === void 0 ? void 0 : _g[0];
139
+ const assistantMsg = choice === null || choice === void 0 ? void 0 : choice.message;
140
+ if ((_h = assistantMsg === null || assistantMsg === void 0 ? void 0 : assistantMsg.tool_calls) === null || _h === void 0 ? void 0 : _h.length) {
141
+ // Add assistant tool-call message to context
142
+ openAiMessages.push({
143
+ role: 'assistant',
144
+ content: null,
145
+ tool_calls: assistantMsg.tool_calls,
146
+ });
147
+ // Execute each tool call
148
+ for (const toolCall of assistantMsg.tool_calls) {
149
+ const originalName = restore(toolCall.function.name);
150
+ const argsJson = toolCall.function.arguments;
151
+ let args = {};
152
+ try {
153
+ args = JSON.parse(argsJson);
154
+ }
155
+ catch (_j) {
156
+ args = {};
157
+ }
158
+ // Persist tool_call message
159
+ await this.prisma.mcp_conversation_message.create({
160
+ data: {
161
+ conversation_id: conversationId,
162
+ role: 'tool_call',
163
+ content: argsJson,
164
+ tool_name: originalName,
165
+ tool_call_id: toolCall.id,
166
+ },
167
+ });
168
+ // Execute the tool
169
+ let resultContent;
170
+ const entry = this.registry.get(originalName);
171
+ if (entry) {
172
+ const context = {
173
+ userId,
174
+ sessionId: '',
175
+ locale,
176
+ toolName: originalName,
177
+ };
178
+ try {
179
+ const result = await entry.handler(args, context);
180
+ resultContent = JSON.stringify(result);
181
+ }
182
+ catch (e) {
183
+ resultContent = JSON.stringify({ error: e.message });
184
+ }
185
+ }
186
+ else {
187
+ resultContent = JSON.stringify({ error: `Tool '${originalName}' not found` });
188
+ }
189
+ // Persist tool_result message
190
+ await this.prisma.mcp_conversation_message.create({
191
+ data: {
192
+ conversation_id: conversationId,
193
+ role: 'tool_result',
194
+ content: resultContent,
195
+ tool_name: originalName,
196
+ tool_call_id: toolCall.id,
197
+ },
198
+ });
199
+ // Add tool result to context for next iteration
200
+ openAiMessages.push({
201
+ role: 'tool',
202
+ tool_call_id: toolCall.id,
203
+ content: resultContent,
204
+ });
205
+ }
206
+ continue; // next iteration with tool results
207
+ }
208
+ // Final assistant response
209
+ const finalContent = (assistantMsg === null || assistantMsg === void 0 ? void 0 : assistantMsg.content) || '';
210
+ await this.prisma.mcp_conversation_message.create({
211
+ data: {
212
+ conversation_id: conversationId,
213
+ role: 'assistant',
214
+ content: finalContent,
215
+ },
216
+ });
217
+ return this.prisma.mcp_conversation_message.findMany({
218
+ where: { conversation_id: conversationId },
219
+ orderBy: { created_at: 'asc' },
220
+ });
221
+ }
222
+ throw new common_1.BadRequestException('Maximum tool call iterations exceeded.');
223
+ }
224
+ toOpenAiMessages(history) {
225
+ const messages = [];
226
+ const toolCallMap = new Map(); // tool_call_id → sanitized name
227
+ for (const msg of history) {
228
+ if (msg.role === 'user') {
229
+ messages.push({ role: 'user', content: msg.content });
230
+ }
231
+ else if (msg.role === 'assistant') {
232
+ messages.push({ role: 'assistant', content: msg.content });
233
+ }
234
+ else if (msg.role === 'tool_call' && msg.tool_call_id && msg.tool_name) {
235
+ const sanitizedName = sanitize(msg.tool_name);
236
+ toolCallMap.set(msg.tool_call_id, sanitizedName);
237
+ messages.push({
238
+ role: 'assistant',
239
+ content: null,
240
+ tool_calls: [
241
+ {
242
+ id: msg.tool_call_id,
243
+ type: 'function',
244
+ function: { name: sanitizedName, arguments: msg.content },
245
+ },
246
+ ],
247
+ });
248
+ }
249
+ else if (msg.role === 'tool_result' && msg.tool_call_id) {
250
+ messages.push({
251
+ role: 'tool',
252
+ tool_call_id: msg.tool_call_id,
253
+ content: msg.content,
254
+ });
255
+ }
256
+ }
257
+ return messages;
258
+ }
259
+ async assertOwnership(conversationId, userId) {
260
+ const conv = await this.prisma.mcp_conversation.findUnique({
261
+ where: { id: conversationId },
262
+ select: { user_id: true },
263
+ });
264
+ if (!conv) {
265
+ throw new common_1.NotFoundException(`Conversation ${conversationId} not found.`);
266
+ }
267
+ if (conv.user_id !== userId) {
268
+ throw new common_1.ForbiddenException('Access denied to this conversation.');
269
+ }
270
+ }
271
+ async getOpenAiKey() {
272
+ const settings = await this.setting.getSettingValues(['ai-openai-api-key']);
273
+ const key = settings['ai-openai-api-key'];
274
+ if (!key) {
275
+ throw new common_1.BadRequestException('OpenAI API key is not configured (setting "ai-openai-api-key").');
276
+ }
277
+ return key;
278
+ }
279
+ };
280
+ exports.McpChatService = McpChatService;
281
+ exports.McpChatService = McpChatService = __decorate([
282
+ (0, common_1.Injectable)(),
283
+ __param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => api_prisma_1.PrismaService))),
284
+ __param(1, (0, common_1.Inject)((0, common_1.forwardRef)(() => setting_service_1.SettingService))),
285
+ __param(2, (0, common_1.Inject)((0, common_1.forwardRef)(() => mcp_registry_service_1.McpRegistryService))),
286
+ __metadata("design:paramtypes", [api_prisma_1.PrismaService,
287
+ setting_service_1.SettingService,
288
+ mcp_registry_service_1.McpRegistryService])
289
+ ], McpChatService);
290
+ //# sourceMappingURL=mcp-chat.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-chat.service.js","sourceRoot":"","sources":["../../src/mcp-chat/mcp-chat.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oDAAoD;AACpD,2CASwB;AACxB,kDAA0B;AAC1B,gEAA4D;AAE5D,sEAAiE;AAejE,MAAM,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eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,gCAAc,CAAC,CAAC,CAAA;IAExC,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,yCAAkB,CAAC,CAAC,CAAA;qCAHpB,0BAAa;QAEZ,gCAAc;QAEb,yCAAkB;GAPpC,cAAc,CAqS1B"}
@@ -50,33 +50,33 @@ export declare class MenuController {
50
50
  })[];
51
51
  } & {
52
52
  id: number;
53
+ url: string | null;
53
54
  order: number;
54
55
  created_at: Date;
55
56
  updated_at: Date;
56
57
  slug: string;
57
58
  icon: string;
58
- url: string | null;
59
59
  menu_id: number | null;
60
60
  }>;
61
61
  create(locale: any, data: CreateDTO): Promise<{
62
62
  id: number;
63
+ url: string | null;
63
64
  order: number;
64
65
  created_at: Date;
65
66
  updated_at: Date;
66
67
  slug: string;
67
68
  icon: string;
68
- url: string | null;
69
69
  menu_id: number | null;
70
70
  }>;
71
71
  updateOrder(locale: any, data: OrderDTO): Promise<void>;
72
72
  update(locale: any, menuId: number, data: UpdateDTO): Promise<{
73
73
  id: number;
74
+ url: string | null;
74
75
  order: number;
75
76
  created_at: Date;
76
77
  updated_at: Date;
77
78
  slug: string;
78
79
  icon: string;
79
- url: string | null;
80
80
  menu_id: number | null;
81
81
  }>;
82
82
  delete(locale: any, data: DeleteDTO): Promise<{
@@ -64,22 +64,22 @@ export declare class MenuService {
64
64
  })[];
65
65
  } & {
66
66
  id: number;
67
+ url: string | null;
67
68
  order: number;
68
69
  created_at: Date;
69
70
  updated_at: Date;
70
71
  slug: string;
71
72
  icon: string;
72
- url: string | null;
73
73
  menu_id: number | null;
74
74
  }>;
75
75
  create(_locale: string, { slug, url, icon, order, menu_id, locale }: CreateDTO): Promise<{
76
76
  id: number;
77
+ url: string | null;
77
78
  order: number;
78
79
  created_at: Date;
79
80
  updated_at: Date;
80
81
  slug: string;
81
82
  icon: string;
82
- url: string | null;
83
83
  menu_id: number | null;
84
84
  }>;
85
85
  update(locale: string, { id, data }: {
@@ -87,12 +87,12 @@ export declare class MenuService {
87
87
  data: UpdateDTO;
88
88
  }): Promise<{
89
89
  id: number;
90
+ url: string | null;
90
91
  order: number;
91
92
  created_at: Date;
92
93
  updated_at: Date;
93
94
  slug: string;
94
95
  icon: string;
95
- url: string | null;
96
96
  menu_id: number | null;
97
97
  }>;
98
98
  delete(locale: string, { ids }: DeleteDTO): Promise<{
@@ -104,9 +104,9 @@ export declare class ProfileController {
104
104
  getEmailIdentifier({ id }: {
105
105
  id: any;
106
106
  }): Promise<{
107
- value: string;
108
107
  type: import("@prisma/client").$Enums.user_identifier_type_e66d505520_enum;
109
108
  id: number;
109
+ value: string;
110
110
  created_at: Date;
111
111
  updated_at: Date;
112
112
  user_id: number;
@@ -136,9 +136,9 @@ export declare class ProfileController {
136
136
  }): Promise<({
137
137
  user_mfa_email: {
138
138
  id: number;
139
+ email: string;
139
140
  created_at: Date;
140
141
  updated_at: Date;
141
- email: string;
142
142
  user_mfa_id: number;
143
143
  }[];
144
144
  user_mfa_totp: {
@@ -45,9 +45,9 @@ export declare class ProfileService {
45
45
  challengeId: number;
46
46
  }>;
47
47
  getEmailIdentifier(userId: number): Promise<{
48
- value: string;
49
48
  type: import("@prisma/client").$Enums.user_identifier_type_e66d505520_enum;
50
49
  id: number;
50
+ value: string;
51
51
  created_at: Date;
52
52
  updated_at: Date;
53
53
  user_id: number;
@@ -68,9 +68,9 @@ export declare class ProfileService {
68
68
  getMFAMethods(userId: number): Promise<({
69
69
  user_mfa_email: {
70
70
  id: number;
71
+ email: string;
71
72
  created_at: Date;
72
73
  updated_at: Date;
73
- email: string;
74
74
  user_mfa_id: number;
75
75
  }[];
76
76
  user_mfa_totp: {
@@ -1,6 +1,10 @@
1
1
  import { HttpMethod } from '../../types/http-method';
2
+ export type RouteType = 'HTTP' | 'MCP';
2
3
  export declare class CreateDTO {
3
- url: string;
4
- method: HttpMethod;
4
+ url?: string;
5
+ method?: HttpMethod;
6
+ type?: RouteType;
7
+ tool_name?: string;
8
+ name?: string;
5
9
  }
6
10
  //# sourceMappingURL=create.dto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.dto.d.ts","sourceRoot":"","sources":["../../../src/route/dto/create.dto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,qBAAa,SAAS;IAEpB,GAAG,EAAE,MAAM,CAAC;IAMZ,MAAM,EAAE,UAAU,CAAC;CACpB"}
1
+ {"version":3,"file":"create.dto.d.ts","sourceRoot":"","sources":["../../../src/route/dto/create.dto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,KAAK,CAAC;AAIvC,qBAAa,SAAS;IAGpB,GAAG,CAAC,EAAE,MAAM,CAAC;IAOb,MAAM,CAAC,EAAE,UAAU,CAAC;IAIpB,IAAI,CAAC,EAAE,SAAS,CAAC;IAIjB,SAAS,CAAC,EAAE,MAAM,CAAC;IAInB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
@@ -12,18 +12,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CreateDTO = void 0;
13
13
  const api_locale_1 = require("@hed-hog/api-locale");
14
14
  const class_validator_1 = require("class-validator");
15
+ const HTTP_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];
15
16
  class CreateDTO {
16
17
  }
17
18
  exports.CreateDTO = CreateDTO;
18
19
  __decorate([
20
+ (0, class_validator_1.IsOptional)(),
19
21
  (0, class_validator_1.IsString)({ message: (args) => (0, api_locale_1.getLocaleText)('validation.urlMustBeString', args.value) }),
20
22
  __metadata("design:type", String)
21
23
  ], CreateDTO.prototype, "url", void 0);
22
24
  __decorate([
25
+ (0, class_validator_1.IsOptional)(),
23
26
  (0, class_validator_1.IsString)({ message: (args) => (0, api_locale_1.getLocaleText)('validation.methodMustBeString', args.value) }),
24
- (0, class_validator_1.IsIn)(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'], {
27
+ (0, class_validator_1.IsIn)(HTTP_METHODS, {
25
28
  message: (args) => (0, api_locale_1.getLocaleText)('validation.methodMustBeValid', args.value),
26
29
  }),
27
30
  __metadata("design:type", String)
28
31
  ], CreateDTO.prototype, "method", void 0);
32
+ __decorate([
33
+ (0, class_validator_1.IsOptional)(),
34
+ (0, class_validator_1.IsIn)(['HTTP', 'MCP']),
35
+ __metadata("design:type", String)
36
+ ], CreateDTO.prototype, "type", void 0);
37
+ __decorate([
38
+ (0, class_validator_1.IsOptional)(),
39
+ (0, class_validator_1.IsString)(),
40
+ __metadata("design:type", String)
41
+ ], CreateDTO.prototype, "tool_name", void 0);
42
+ __decorate([
43
+ (0, class_validator_1.IsOptional)(),
44
+ (0, class_validator_1.IsString)(),
45
+ __metadata("design:type", String)
46
+ ], CreateDTO.prototype, "name", void 0);
29
47
  //# sourceMappingURL=create.dto.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.dto.js","sourceRoot":"","sources":["../../../src/route/dto/create.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAoD;AACpD,qDAAiD;AAGjD,MAAa,SAAS;CASrB;AATD,8BASC;AAPC;IADC,IAAA,0BAAQ,EAAC,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,0BAAa,EAAC,4BAA4B,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;;sCAC7E;AAMZ;IAJC,IAAA,0BAAQ,EAAC,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,0BAAa,EAAC,+BAA+B,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;IAC3F,IAAA,sBAAI,EAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,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ethod } from '../../types/http-method';
2
+ import { RouteType } from './create.dto';
2
3
  export declare class UpdateDTO {
3
4
  url?: string;
4
5
  method?: HttpMethod;
6
+ type?: RouteType;
7
+ tool_name?: string;
8
+ name?: string;
5
9
  }
6
10
  //# sourceMappingURL=update.dto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"update.dto.d.ts","sourceRoot":"","sources":["../../../src/route/dto/update.dto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,qBAAa,SAAS;IAGpB,GAAG,CAAC,EAAE,MAAM,CAAC;IAOb,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB"}
1
+ {"version":3,"file":"update.dto.d.ts","sourceRoot":"","sources":["../../../src/route/dto/update.dto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,qBAAa,SAAS;IAGpB,GAAG,CAAC,EAAE,MAAM,CAAC;IAOb,MAAM,CAAC,EAAE,UAAU,CAAC;IAIpB,IAAI,CAAC,EAAE,SAAS,CAAC;IAIjB,SAAS,CAAC,EAAE,MAAM,CAAC;IAInB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
@@ -12,20 +12,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.UpdateDTO = void 0;
13
13
  const api_locale_1 = require("@hed-hog/api-locale");
14
14
  const class_validator_1 = require("class-validator");
15
+ const HTTP_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];
15
16
  class UpdateDTO {
16
17
  }
17
18
  exports.UpdateDTO = UpdateDTO;
18
19
  __decorate([
19
- (0, class_validator_1.IsString)({ message: (args) => (0, api_locale_1.getLocaleText)('validation.urlMustBeString', args.value) }),
20
20
  (0, class_validator_1.IsOptional)(),
21
+ (0, class_validator_1.IsString)({ message: (args) => (0, api_locale_1.getLocaleText)('validation.urlMustBeString', args.value) }),
21
22
  __metadata("design:type", String)
22
23
  ], UpdateDTO.prototype, "url", void 0);
23
24
  __decorate([
24
- (0, class_validator_1.IsString)({ message: (args) => (0, api_locale_1.getLocaleText)('validation.methodMustBeString', args.value) }),
25
25
  (0, class_validator_1.IsOptional)(),
26
- (0, class_validator_1.IsIn)(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'], {
26
+ (0, class_validator_1.IsString)({ message: (args) => (0, api_locale_1.getLocaleText)('validation.methodMustBeString', args.value) }),
27
+ (0, class_validator_1.IsIn)(HTTP_METHODS, {
27
28
  message: (args) => (0, api_locale_1.getLocaleText)('validation.methodMustBeValid', args.value),
28
29
  }),
29
30
  __metadata("design:type", String)
30
31
  ], UpdateDTO.prototype, "method", void 0);
32
+ __decorate([
33
+ (0, class_validator_1.IsOptional)(),
34
+ (0, class_validator_1.IsIn)(['HTTP', 'MCP']),
35
+ __metadata("design:type", String)
36
+ ], UpdateDTO.prototype, "type", void 0);
37
+ __decorate([
38
+ (0, class_validator_1.IsOptional)(),
39
+ (0, class_validator_1.IsString)(),
40
+ __metadata("design:type", String)
41
+ ], UpdateDTO.prototype, "tool_name", void 0);
42
+ __decorate([
43
+ (0, class_validator_1.IsOptional)(),
44
+ (0, class_validator_1.IsString)(),
45
+ __metadata("design:type", String)
46
+ ], UpdateDTO.prototype, "name", void 0);
31
47
  //# sourceMappingURL=update.dto.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"update.dto.js","sourceRoot":"","sources":["../../../src/route/dto/update.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAoD;AACpD,qDAA6D;AAG7D,MAAa,SAAS;CAWrB;AAXD,8BAWC;AARC;IAFC,IAAA,0BAAQ,EAAC,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,0BAAa,EAAC,4BAA4B,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,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