@hed-hog/core 0.0.362 → 0.0.365

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 (185) hide show
  1. package/dist/ai/ai.controller.d.ts +4 -4
  2. package/dist/ai/ai.module.d.ts.map +1 -1
  3. package/dist/ai/ai.module.js +2 -0
  4. package/dist/ai/ai.module.js.map +1 -1
  5. package/dist/ai/ai.service.d.ts +7 -5
  6. package/dist/ai/ai.service.d.ts.map +1 -1
  7. package/dist/ai/ai.service.js +63 -31
  8. package/dist/ai/ai.service.js.map +1 -1
  9. package/dist/ai-instruction/ai-execution.service.d.ts +45 -0
  10. package/dist/ai-instruction/ai-execution.service.d.ts.map +1 -0
  11. package/dist/ai-instruction/ai-execution.service.js +203 -0
  12. package/dist/ai-instruction/ai-execution.service.js.map +1 -0
  13. package/dist/ai-instruction/ai-instruction.controller.d.ts +25 -0
  14. package/dist/ai-instruction/ai-instruction.controller.d.ts.map +1 -0
  15. package/dist/ai-instruction/ai-instruction.controller.js +117 -0
  16. package/dist/ai-instruction/ai-instruction.controller.js.map +1 -0
  17. package/dist/ai-instruction/ai-instruction.module.d.ts +3 -0
  18. package/dist/ai-instruction/ai-instruction.module.d.ts.map +1 -0
  19. package/dist/ai-instruction/ai-instruction.module.js +27 -0
  20. package/dist/ai-instruction/ai-instruction.module.js.map +1 -0
  21. package/dist/ai-instruction/ai-instruction.service.d.ts +38 -0
  22. package/dist/ai-instruction/ai-instruction.service.d.ts.map +1 -0
  23. package/dist/ai-instruction/ai-instruction.service.js +289 -0
  24. package/dist/ai-instruction/ai-instruction.service.js.map +1 -0
  25. package/dist/ai-instruction/ai-prompt-builder.service.d.ts +53 -0
  26. package/dist/ai-instruction/ai-prompt-builder.service.d.ts.map +1 -0
  27. package/dist/ai-instruction/ai-prompt-builder.service.js +132 -0
  28. package/dist/ai-instruction/ai-prompt-builder.service.js.map +1 -0
  29. package/dist/ai-instruction/dto/create-ai-instruction.dto.d.ts +12 -0
  30. package/dist/ai-instruction/dto/create-ai-instruction.dto.d.ts.map +1 -0
  31. package/dist/ai-instruction/dto/create-ai-instruction.dto.js +57 -0
  32. package/dist/ai-instruction/dto/create-ai-instruction.dto.js.map +1 -0
  33. package/dist/ai-instruction/dto/update-ai-instruction.dto.d.ts +10 -0
  34. package/dist/ai-instruction/dto/update-ai-instruction.dto.d.ts.map +1 -0
  35. package/dist/ai-instruction/dto/update-ai-instruction.dto.js +56 -0
  36. package/dist/ai-instruction/dto/update-ai-instruction.dto.js.map +1 -0
  37. package/dist/ai-instruction/types/ai-instruction.types.d.ts +78 -0
  38. package/dist/ai-instruction/types/ai-instruction.types.d.ts.map +1 -0
  39. package/dist/ai-instruction/types/ai-instruction.types.js +3 -0
  40. package/dist/ai-instruction/types/ai-instruction.types.js.map +1 -0
  41. package/dist/auth/auth.controller.d.ts +13 -5
  42. package/dist/auth/auth.controller.d.ts.map +1 -1
  43. package/dist/auth/auth.controller.js +39 -20
  44. package/dist/auth/auth.controller.js.map +1 -1
  45. package/dist/auth/auth.service.d.ts +18 -7
  46. package/dist/auth/auth.service.d.ts.map +1 -1
  47. package/dist/auth/auth.service.js +20 -16
  48. package/dist/auth/auth.service.js.map +1 -1
  49. package/dist/core.module.d.ts.map +1 -1
  50. package/dist/core.module.js +3 -0
  51. package/dist/core.module.js.map +1 -1
  52. package/dist/file/file.service.d.ts +37 -0
  53. package/dist/file/file.service.d.ts.map +1 -1
  54. package/dist/file/file.service.js +94 -4
  55. package/dist/file/file.service.js.map +1 -1
  56. package/dist/file/provider/abstract.provider.d.ts +6 -2
  57. package/dist/file/provider/abstract.provider.d.ts.map +1 -1
  58. package/dist/file/provider/abstract.provider.js.map +1 -1
  59. package/dist/file/provider/azure.provider.d.ts +4 -1
  60. package/dist/file/provider/azure.provider.d.ts.map +1 -1
  61. package/dist/file/provider/azure.provider.js +7 -2
  62. package/dist/file/provider/azure.provider.js.map +1 -1
  63. package/dist/file/provider/gcs.provider.d.ts +4 -1
  64. package/dist/file/provider/gcs.provider.d.ts.map +1 -1
  65. package/dist/file/provider/gcs.provider.js +7 -2
  66. package/dist/file/provider/gcs.provider.js.map +1 -1
  67. package/dist/file/provider/local.provider.d.ts +2 -2
  68. package/dist/file/provider/local.provider.d.ts.map +1 -1
  69. package/dist/file/provider/local.provider.js +7 -2
  70. package/dist/file/provider/local.provider.js.map +1 -1
  71. package/dist/file/provider/s3.provider.d.ts +4 -1
  72. package/dist/file/provider/s3.provider.d.ts.map +1 -1
  73. package/dist/file/provider/s3.provider.js +9 -6
  74. package/dist/file/provider/s3.provider.js.map +1 -1
  75. package/dist/file/provider/spaces.provider.d.ts +4 -1
  76. package/dist/file/provider/spaces.provider.d.ts.map +1 -1
  77. package/dist/file/provider/spaces.provider.js +9 -5
  78. package/dist/file/provider/spaces.provider.js.map +1 -1
  79. package/dist/integration-profile/integration-profile.controller.d.ts +3 -3
  80. package/dist/integration-profile/integration-profile.service.d.ts +3 -3
  81. package/dist/mcp-chat/mcp-chat.controller.d.ts +2 -2
  82. package/dist/mcp-chat/mcp-chat.module.d.ts.map +1 -1
  83. package/dist/mcp-chat/mcp-chat.module.js +2 -0
  84. package/dist/mcp-chat/mcp-chat.module.js.map +1 -1
  85. package/dist/mcp-chat/mcp-chat.service.d.ts +8 -3
  86. package/dist/mcp-chat/mcp-chat.service.d.ts.map +1 -1
  87. package/dist/mcp-chat/mcp-chat.service.js +100 -20
  88. package/dist/mcp-chat/mcp-chat.service.js.map +1 -1
  89. package/dist/notification/notification.service.d.ts +1 -0
  90. package/dist/notification/notification.service.d.ts.map +1 -1
  91. package/dist/notification/notification.service.js +29 -1
  92. package/dist/notification/notification.service.js.map +1 -1
  93. package/dist/oauth/oauth.service.d.ts +1 -0
  94. package/dist/oauth/oauth.service.d.ts.map +1 -1
  95. package/dist/oauth/oauth.service.js +55 -1
  96. package/dist/oauth/oauth.service.js.map +1 -1
  97. package/dist/profile/events/profile-avatar-updated.event.d.ts +7 -0
  98. package/dist/profile/events/profile-avatar-updated.event.d.ts.map +1 -0
  99. package/dist/profile/events/profile-avatar-updated.event.js +12 -0
  100. package/dist/profile/events/profile-avatar-updated.event.js.map +1 -0
  101. package/dist/profile/events/profile-email-changed.event.d.ts +7 -0
  102. package/dist/profile/events/profile-email-changed.event.d.ts.map +1 -0
  103. package/dist/profile/events/profile-email-changed.event.js +12 -0
  104. package/dist/profile/events/profile-email-changed.event.js.map +1 -0
  105. package/dist/profile/events/profile-updated.event.d.ts +7 -0
  106. package/dist/profile/events/profile-updated.event.d.ts.map +1 -0
  107. package/dist/profile/events/profile-updated.event.js +12 -0
  108. package/dist/profile/events/profile-updated.event.js.map +1 -0
  109. package/dist/profile/profile.service.d.ts +3 -1
  110. package/dist/profile/profile.service.d.ts.map +1 -1
  111. package/dist/profile/profile.service.js +28 -17
  112. package/dist/profile/profile.service.js.map +1 -1
  113. package/dist/session/session.controller.d.ts +1 -0
  114. package/dist/session/session.controller.d.ts.map +1 -1
  115. package/dist/session/session.service.d.ts +9 -4
  116. package/dist/session/session.service.d.ts.map +1 -1
  117. package/dist/session/session.service.js +61 -51
  118. package/dist/session/session.service.js.map +1 -1
  119. package/dist/setting/setting.controller.d.ts +5 -5
  120. package/dist/setting/setting.service.d.ts +5 -5
  121. package/dist/setting/setting.service.d.ts.map +1 -1
  122. package/dist/setting/setting.service.js +2 -0
  123. package/dist/setting/setting.service.js.map +1 -1
  124. package/dist/task/task.service.d.ts +8 -11
  125. package/dist/task/task.service.d.ts.map +1 -1
  126. package/dist/task/task.service.js +10 -16
  127. package/dist/task/task.service.js.map +1 -1
  128. package/dist/user/user.controller.d.ts +1 -0
  129. package/dist/user/user.controller.d.ts.map +1 -1
  130. package/dist/user/user.service.d.ts +3 -0
  131. package/dist/user/user.service.d.ts.map +1 -1
  132. package/dist/webhook-integration/webhook-command.registry.d.ts +9 -2
  133. package/dist/webhook-integration/webhook-command.registry.d.ts.map +1 -1
  134. package/dist/webhook-integration/webhook-command.registry.js.map +1 -1
  135. package/dist/webhook-integration/webhook-integration.service.d.ts.map +1 -1
  136. package/dist/webhook-integration/webhook-integration.service.js +13 -4
  137. package/dist/webhook-integration/webhook-integration.service.js.map +1 -1
  138. package/hedhog/data/integration_provider.yaml +17 -0
  139. package/hedhog/data/integration_type.yaml +6 -0
  140. package/hedhog/data/route.yaml +86 -2
  141. package/hedhog/frontend/app/configurations/[slug]/components/setting-field.tsx.ejs +109 -0
  142. package/hedhog/frontend/app/configurations/layout.tsx.ejs +6 -6
  143. package/hedhog/frontend/app/integration/profiles/page.tsx.ejs +169 -14
  144. package/hedhog/frontend/messages/en.json +11 -2
  145. package/hedhog/frontend/messages/pt.json +11 -2
  146. package/hedhog/table/ai_execution.yaml +79 -0
  147. package/hedhog/table/ai_execution_step.yaml +65 -0
  148. package/hedhog/table/ai_instruction.yaml +43 -0
  149. package/hedhog/table/ai_instruction_version.yaml +30 -0
  150. package/hedhog/table/ai_model_pricing.yaml +35 -0
  151. package/hedhog/table/user_session.yaml +2 -0
  152. package/package.json +5 -4
  153. package/src/ai/ai.module.ts +2 -0
  154. package/src/ai/ai.service.ts +64 -31
  155. package/src/ai-instruction/ai-execution.service.ts +244 -0
  156. package/src/ai-instruction/ai-instruction.controller.ts +73 -0
  157. package/src/ai-instruction/ai-instruction.module.ts +14 -0
  158. package/src/ai-instruction/ai-instruction.service.ts +343 -0
  159. package/src/ai-instruction/ai-prompt-builder.service.ts +142 -0
  160. package/src/ai-instruction/dto/create-ai-instruction.dto.ts +36 -0
  161. package/src/ai-instruction/dto/update-ai-instruction.dto.ts +35 -0
  162. package/src/ai-instruction/types/ai-instruction.types.ts +90 -0
  163. package/src/auth/auth.controller.ts +23 -5
  164. package/src/auth/auth.service.ts +26 -15
  165. package/src/core.module.ts +3 -0
  166. package/src/file/file.service.ts +136 -4
  167. package/src/file/provider/abstract.provider.ts +4 -2
  168. package/src/file/provider/azure.provider.ts +6 -3
  169. package/src/file/provider/gcs.provider.ts +5 -3
  170. package/src/file/provider/local.provider.ts +7 -3
  171. package/src/file/provider/s3.provider.ts +8 -6
  172. package/src/file/provider/spaces.provider.ts +8 -7
  173. package/src/mcp-chat/mcp-chat.module.ts +19 -17
  174. package/src/mcp-chat/mcp-chat.service.ts +95 -9
  175. package/src/notification/notification.service.ts +32 -1
  176. package/src/oauth/oauth.service.ts +74 -1
  177. package/src/profile/events/profile-avatar-updated.event.ts +8 -0
  178. package/src/profile/events/profile-email-changed.event.ts +8 -0
  179. package/src/profile/events/profile-updated.event.ts +8 -0
  180. package/src/profile/profile.service.ts +25 -16
  181. package/src/session/session.service.ts +70 -52
  182. package/src/setting/setting.service.ts +10 -8
  183. package/src/task/task.service.ts +10 -16
  184. package/src/webhook-integration/webhook-command.registry.ts +10 -2
  185. package/src/webhook-integration/webhook-integration.service.ts +31 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-execution.service.js","sourceRoot":"","sources":["../../src/ai-instruction/ai-execution.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAoD;AACpD,2CAAwE;AAiCjE,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAM7B,YAEE,MAAsC;QAArB,WAAM,GAAN,MAAM,CAAe;QAPvB,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;QAC7C,iBAAY,GAAG,IAAI,GAAG,EAAgC,CAAC;QAChE,oBAAe,GAAG,CAAC,CAAC;QACX,mBAAc,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,KAAK;IAKpD,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,MAA4B;;QACtC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAuB;;;YAG3D,MAAA,MAAM,CAAC,MAAM,mCAAI,IAAI;YACrB,MAAA,MAAM,CAAC,cAAc,mCAAI,IAAI;YAC7B,MAAA,MAAM,CAAC,OAAO,mCAAI,IAAI;iBACjB,MAA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EO,KAAK,CAAC,gBAAgB;QAC5B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAwB;;OAE/D,CAAC;YACF,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;YAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;gBAC3C,6DAA6D;gBAC7D,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;oBAChC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC;YACD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACpC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;CACF,CAAA;AAjNY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAQR,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,0BAAa,CAAC,CAAC,CAAA;qCACf,0BAAa;GAR7B,kBAAkB,CAiN9B"}
@@ -0,0 +1,25 @@
1
+ import { DeleteDTO } from '../dto/delete.dto';
2
+ import { AiInstructionService } from './ai-instruction.service';
3
+ import { CreateAiInstructionDTO } from './dto/create-ai-instruction.dto';
4
+ import { UpdateAiInstructionDTO } from './dto/update-ai-instruction.dto';
5
+ export declare class AiInstructionController {
6
+ private readonly aiInstructionService;
7
+ constructor(aiInstructionService: AiInstructionService);
8
+ list(paginationParams: any): Promise<{
9
+ data: import("./types/ai-instruction.types").AiInstructionRecord[];
10
+ total: number;
11
+ page: number;
12
+ pageSize: number;
13
+ totalPages: number;
14
+ }>;
15
+ getById(id: number): Promise<import("./types/ai-instruction.types").AiInstructionRecord>;
16
+ getBySlug(slug: string): Promise<import("./types/ai-instruction.types").AiInstructionRecord>;
17
+ create(dto: CreateAiInstructionDTO): Promise<import("./types/ai-instruction.types").AiInstructionRecord>;
18
+ update(id: number, dto: UpdateAiInstructionDTO): Promise<import("./types/ai-instruction.types").AiInstructionRecord>;
19
+ delete(data: DeleteDTO): Promise<{
20
+ count: number;
21
+ }>;
22
+ listVersions(id: number): Promise<unknown>;
23
+ restoreVersion(id: number, version: number): Promise<import("./types/ai-instruction.types").AiInstructionRecord>;
24
+ }
25
+ //# sourceMappingURL=ai-instruction.controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-instruction.controller.d.ts","sourceRoot":"","sources":["../../src/ai-instruction/ai-instruction.controller.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,qBAEa,uBAAuB;IAGhC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;gBAApB,oBAAoB,EAAE,oBAAoB;IAIvD,IAAI,CAAe,gBAAgB,KAAA;;;;;;;IAKnC,OAAO,CAA4B,EAAE,EAAE,MAAM;IAK7C,SAAS,CAAgB,IAAI,EAAE,MAAM;IAKrC,MAAM,CAAS,GAAG,EAAE,sBAAsB;IAK1C,MAAM,CACiB,EAAE,EAAE,MAAM,EAC7B,GAAG,EAAE,sBAAsB;IAM/B,MAAM,CAAS,IAAI,EAAE,SAAS;;;IAK9B,YAAY,CAA4B,EAAE,EAAE,MAAM;IAKlD,cAAc,CACS,EAAE,EAAE,MAAM,EACL,OAAO,EAAE,MAAM;CAIlD"}
@@ -0,0 +1,117 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AiInstructionController = void 0;
16
+ const api_1 = require("@hed-hog/api");
17
+ const api_pagination_1 = require("@hed-hog/api-pagination");
18
+ const common_1 = require("@nestjs/common");
19
+ const delete_dto_1 = require("../dto/delete.dto");
20
+ const ai_instruction_service_1 = require("./ai-instruction.service");
21
+ const create_ai_instruction_dto_1 = require("./dto/create-ai-instruction.dto");
22
+ const update_ai_instruction_dto_1 = require("./dto/update-ai-instruction.dto");
23
+ let AiInstructionController = class AiInstructionController {
24
+ constructor(aiInstructionService) {
25
+ this.aiInstructionService = aiInstructionService;
26
+ }
27
+ async list(paginationParams) {
28
+ return this.aiInstructionService.list(paginationParams);
29
+ }
30
+ async getById(id) {
31
+ return this.aiInstructionService.getById(id);
32
+ }
33
+ async getBySlug(slug) {
34
+ return this.aiInstructionService.getBySlug(slug);
35
+ }
36
+ async create(dto) {
37
+ return this.aiInstructionService.create(dto);
38
+ }
39
+ async update(id, dto) {
40
+ return this.aiInstructionService.update(id, dto);
41
+ }
42
+ async delete(data) {
43
+ return this.aiInstructionService.delete(data);
44
+ }
45
+ async listVersions(id) {
46
+ return this.aiInstructionService.listVersions(id);
47
+ }
48
+ async restoreVersion(id, version) {
49
+ return this.aiInstructionService.restoreVersion(id, version);
50
+ }
51
+ };
52
+ exports.AiInstructionController = AiInstructionController;
53
+ __decorate([
54
+ (0, common_1.Get)(),
55
+ __param(0, (0, api_pagination_1.Pagination)()),
56
+ __metadata("design:type", Function),
57
+ __metadata("design:paramtypes", [Object]),
58
+ __metadata("design:returntype", Promise)
59
+ ], AiInstructionController.prototype, "list", null);
60
+ __decorate([
61
+ (0, common_1.Get)(':id'),
62
+ __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
63
+ __metadata("design:type", Function),
64
+ __metadata("design:paramtypes", [Number]),
65
+ __metadata("design:returntype", Promise)
66
+ ], AiInstructionController.prototype, "getById", null);
67
+ __decorate([
68
+ (0, common_1.Get)('slug/:slug'),
69
+ __param(0, (0, common_1.Param)('slug')),
70
+ __metadata("design:type", Function),
71
+ __metadata("design:paramtypes", [String]),
72
+ __metadata("design:returntype", Promise)
73
+ ], AiInstructionController.prototype, "getBySlug", null);
74
+ __decorate([
75
+ (0, common_1.Post)(),
76
+ __param(0, (0, common_1.Body)()),
77
+ __metadata("design:type", Function),
78
+ __metadata("design:paramtypes", [create_ai_instruction_dto_1.CreateAiInstructionDTO]),
79
+ __metadata("design:returntype", Promise)
80
+ ], AiInstructionController.prototype, "create", null);
81
+ __decorate([
82
+ (0, common_1.Patch)(':id'),
83
+ __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
84
+ __param(1, (0, common_1.Body)()),
85
+ __metadata("design:type", Function),
86
+ __metadata("design:paramtypes", [Number, update_ai_instruction_dto_1.UpdateAiInstructionDTO]),
87
+ __metadata("design:returntype", Promise)
88
+ ], AiInstructionController.prototype, "update", null);
89
+ __decorate([
90
+ (0, common_1.Delete)(),
91
+ __param(0, (0, common_1.Body)()),
92
+ __metadata("design:type", Function),
93
+ __metadata("design:paramtypes", [delete_dto_1.DeleteDTO]),
94
+ __metadata("design:returntype", Promise)
95
+ ], AiInstructionController.prototype, "delete", null);
96
+ __decorate([
97
+ (0, common_1.Get)(':id/versions'),
98
+ __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
99
+ __metadata("design:type", Function),
100
+ __metadata("design:paramtypes", [Number]),
101
+ __metadata("design:returntype", Promise)
102
+ ], AiInstructionController.prototype, "listVersions", null);
103
+ __decorate([
104
+ (0, common_1.Post)(':id/versions/:version/restore'),
105
+ __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
106
+ __param(1, (0, common_1.Param)('version', common_1.ParseIntPipe)),
107
+ __metadata("design:type", Function),
108
+ __metadata("design:paramtypes", [Number, Number]),
109
+ __metadata("design:returntype", Promise)
110
+ ], AiInstructionController.prototype, "restoreVersion", null);
111
+ exports.AiInstructionController = AiInstructionController = __decorate([
112
+ (0, api_1.Role)(),
113
+ (0, common_1.Controller)('ai-instruction'),
114
+ __param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => ai_instruction_service_1.AiInstructionService))),
115
+ __metadata("design:paramtypes", [ai_instruction_service_1.AiInstructionService])
116
+ ], AiInstructionController);
117
+ //# sourceMappingURL=ai-instruction.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-instruction.controller.js","sourceRoot":"","sources":["../../src/ai-instruction/ai-instruction.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sCAAoC;AACpC,4DAAqD;AACrD,2CAWwB;AACxB,kDAA8C;AAC9C,qEAAgE;AAChE,+EAAyE;AACzE,+EAAyE;AAIlE,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAClC,YAEmB,oBAA0C;QAA1C,yBAAoB,GAApB,oBAAoB,CAAsB;IAC1D,CAAC;IAGE,AAAN,KAAK,CAAC,IAAI,CAAe,gBAAgB;QACvC,OAAO,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC1D,CAAC;IAGK,AAAN,KAAK,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AA,aAAI,GAAE;IACO,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,kDAAsB;;qDAE/C;AAGK;IADL,IAAA,cAAK,EAAC,KAAK,CAAC;IAEV,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;IACzB,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,kDAAsB;;qDAGpC;AAGK;IADL,IAAA,eAAM,GAAE;IACK,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAO,sBAAS;;qDAEnC;AAGK;IADL,IAAA,YAAG,EAAC,cAAc,CAAC;IACA,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;;;;2DAE5C;AAGK;IADL,IAAA,aAAI,EAAC,+BAA+B,CAAC;IAEnC,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;IACzB,WAAA,IAAA,cAAK,EAAC,SAAS,EAAE,qBAAY,CAAC,CAAA;;;;6DAGhC;kCAlDU,uBAAuB;IAFnC,IAAA,UAAI,GAAE;IACN,IAAA,mBAAU,EAAC,gBAAgB,CAAC;IAGxB,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,6CAAoB,CAAC,CAAC,CAAA;qCACR,6CAAoB;GAHlD,uBAAuB,CAmDnC"}
@@ -0,0 +1,3 @@
1
+ export declare class AiInstructionModule {
2
+ }
3
+ //# sourceMappingURL=ai-instruction.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-instruction.module.d.ts","sourceRoot":"","sources":["../../src/ai-instruction/ai-instruction.module.ts"],"names":[],"mappings":"AAOA,qBAMa,mBAAmB;CAAG"}
@@ -0,0 +1,27 @@
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.AiInstructionModule = void 0;
10
+ const api_prisma_1 = require("@hed-hog/api-prisma");
11
+ const common_1 = require("@nestjs/common");
12
+ const ai_execution_service_1 = require("./ai-execution.service");
13
+ const ai_instruction_controller_1 = require("./ai-instruction.controller");
14
+ const ai_instruction_service_1 = require("./ai-instruction.service");
15
+ const ai_prompt_builder_service_1 = require("./ai-prompt-builder.service");
16
+ let AiInstructionModule = class AiInstructionModule {
17
+ };
18
+ exports.AiInstructionModule = AiInstructionModule;
19
+ exports.AiInstructionModule = AiInstructionModule = __decorate([
20
+ (0, common_1.Module)({
21
+ imports: [(0, common_1.forwardRef)(() => api_prisma_1.PrismaModule)],
22
+ controllers: [ai_instruction_controller_1.AiInstructionController],
23
+ providers: [ai_instruction_service_1.AiInstructionService, ai_execution_service_1.AiExecutionService, ai_prompt_builder_service_1.AiPromptBuilderService],
24
+ exports: [ai_instruction_service_1.AiInstructionService, ai_execution_service_1.AiExecutionService, ai_prompt_builder_service_1.AiPromptBuilderService],
25
+ })
26
+ ], AiInstructionModule);
27
+ //# sourceMappingURL=ai-instruction.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-instruction.module.js","sourceRoot":"","sources":["../../src/ai-instruction/ai-instruction.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAmD;AACnD,2CAAoD;AACpD,iEAA4D;AAC5D,2EAAsE;AACtE,qEAAgE;AAChE,2EAAqE;AAQ9D,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;CAAG,CAAA;AAAtB,kDAAmB;8BAAnB,mBAAmB;IAN/B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,yBAAY,CAAC,CAAC;QACzC,WAAW,EAAE,CAAC,mDAAuB,CAAC;QACtC,SAAS,EAAE,CAAC,6CAAoB,EAAE,yCAAkB,EAAE,kDAAsB,CAAC;QAC7E,OAAO,EAAE,CAAC,6CAAoB,EAAE,yCAAkB,EAAE,kDAAsB,CAAC;KAC5E,CAAC;GACW,mBAAmB,CAAG"}
@@ -0,0 +1,38 @@
1
+ import { PaginationDTO } from '@hed-hog/api-pagination';
2
+ import { PrismaService } from '@hed-hog/api-prisma';
3
+ import { OnModuleInit } from '@nestjs/common';
4
+ import { DeleteDTO } from '../dto/delete.dto';
5
+ import { CreateAiInstructionDTO } from './dto/create-ai-instruction.dto';
6
+ import { UpdateAiInstructionDTO } from './dto/update-ai-instruction.dto';
7
+ import type { AiInstructionLayer, AiInstructionRecord } from './types/ai-instruction.types';
8
+ export declare class AiInstructionService implements OnModuleInit {
9
+ private readonly prisma;
10
+ private readonly logger;
11
+ private readonly cache;
12
+ constructor(prisma: PrismaService);
13
+ onModuleInit(): Promise<void>;
14
+ getLayer(layer: AiInstructionLayer, moduleSlug?: string): Promise<string>;
15
+ getAgentInstruction(agentSlug: string): Promise<string>;
16
+ invalidateCache(slug?: string): void;
17
+ list(paginationParams: PaginationDTO): Promise<{
18
+ data: AiInstructionRecord[];
19
+ total: number;
20
+ page: number;
21
+ pageSize: number;
22
+ totalPages: number;
23
+ }>;
24
+ getById(id: number): Promise<AiInstructionRecord>;
25
+ getBySlug(slug: string): Promise<AiInstructionRecord>;
26
+ create(dto: CreateAiInstructionDTO, createdById?: number): Promise<AiInstructionRecord>;
27
+ update(id: number, dto: UpdateAiInstructionDTO, updatedById?: number): Promise<AiInstructionRecord>;
28
+ delete({ ids }: DeleteDTO): Promise<{
29
+ count: number;
30
+ }>;
31
+ listVersions(id: number): Promise<unknown>;
32
+ restoreVersion(id: number, version: number, restoredById?: number): Promise<AiInstructionRecord>;
33
+ private findById;
34
+ private findActiveBySlug;
35
+ private findActiveByLayer;
36
+ private saveVersion;
37
+ }
38
+ //# sourceMappingURL=ai-instruction.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-instruction.service.d.ts","sourceRoot":"","sources":["../../src/ai-instruction/ai-instruction.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAU,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAML,YAAY,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;AAWtC,qBACa,oBAAqB,YAAW,YAAY;IAMrD,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyC;IAChE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;gBAIpC,MAAM,EAAE,aAAa;IAGlC,YAAY;IAYZ,QAAQ,CAAC,KAAK,EAAE,kBAAkB,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBzE,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAc7D,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM;IAoBvB,IAAI,CAAC,gBAAgB,EAAE,aAAa;;;;;;;IAmCpC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAMjD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAMrD,MAAM,CAAC,GAAG,EAAE,sBAAsB,EAAE,WAAW,CAAC,EAAE,MAAM;IA6BxD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,sBAAsB,EAAE,WAAW,CAAC,EAAE,MAAM;IAgCpE,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,SAAS;;;IAmBzB,YAAY,CAAC,EAAE,EAAE,MAAM;IAYvB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;YAoCzD,QAAQ;YASR,gBAAgB;YAShB,iBAAiB;YA6BjB,WAAW;CAiB1B"}
@@ -0,0 +1,289 @@
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 AiInstructionService_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.AiInstructionService = void 0;
17
+ const api_prisma_1 = require("@hed-hog/api-prisma");
18
+ const common_1 = require("@nestjs/common");
19
+ const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
20
+ const FALLBACK_SYSTEM_PROMPT = 'You are a helpful assistant with access to tools from the HedHog system. ' +
21
+ "Use the available tools to answer the user's questions accurately. " +
22
+ 'Always respond in the same language the user writes in.';
23
+ let AiInstructionService = AiInstructionService_1 = class AiInstructionService {
24
+ constructor(prisma) {
25
+ this.prisma = prisma;
26
+ this.logger = new common_1.Logger(AiInstructionService_1.name);
27
+ this.cache = new Map();
28
+ }
29
+ async onModuleInit() {
30
+ // Warm up global and product layers on startup
31
+ try {
32
+ await this.getLayer('system');
33
+ await this.getLayer('product');
34
+ }
35
+ catch (_a) {
36
+ // DB may not be ready yet; cache will fill on first request
37
+ }
38
+ }
39
+ // ── Public layer accessors (cached) ──────────────────────────────────────
40
+ async getLayer(layer, moduleSlug) {
41
+ const cacheKey = moduleSlug ? `${layer}:${moduleSlug}` : layer;
42
+ const cached = this.cache.get(cacheKey);
43
+ if (cached && Date.now() - cached.fetchedAt < CACHE_TTL_MS) {
44
+ return cached.content;
45
+ }
46
+ const instruction = await this.findActiveByLayer(layer, moduleSlug);
47
+ if (!instruction) {
48
+ if (layer === 'system') {
49
+ return FALLBACK_SYSTEM_PROMPT;
50
+ }
51
+ return '';
52
+ }
53
+ this.cache.set(cacheKey, { content: instruction.content, fetchedAt: Date.now() });
54
+ return instruction.content;
55
+ }
56
+ async getAgentInstruction(agentSlug) {
57
+ const cacheKey = `agent:${agentSlug}`;
58
+ const cached = this.cache.get(cacheKey);
59
+ if (cached && Date.now() - cached.fetchedAt < CACHE_TTL_MS) {
60
+ return cached.content;
61
+ }
62
+ const instruction = await this.findActiveBySlug(`agent.${agentSlug}`);
63
+ if (!instruction)
64
+ return '';
65
+ this.cache.set(cacheKey, { content: instruction.content, fetchedAt: Date.now() });
66
+ return instruction.content;
67
+ }
68
+ invalidateCache(slug) {
69
+ if (slug) {
70
+ // Cache keys use format "layer" or "layer:identifier"
71
+ // Slugs use format "layer.identifier" (e.g., "module.lms", "agent.admin-support")
72
+ const dotIndex = slug.indexOf('.');
73
+ if (dotIndex === -1) {
74
+ this.cache.delete(slug);
75
+ }
76
+ else {
77
+ const layer = slug.slice(0, dotIndex);
78
+ const identifier = slug.slice(dotIndex + 1);
79
+ this.cache.delete(layer);
80
+ this.cache.delete(`${layer}:${identifier}`);
81
+ }
82
+ }
83
+ else {
84
+ this.cache.clear();
85
+ }
86
+ }
87
+ // ── CRUD ─────────────────────────────────────────────────────────────────
88
+ async list(paginationParams) {
89
+ var _a;
90
+ const page = Math.max(Number((paginationParams === null || paginationParams === void 0 ? void 0 : paginationParams.page) || 1), 1);
91
+ const pageSize = Math.min(Math.max(Number((paginationParams === null || paginationParams === void 0 ? void 0 : paginationParams.pageSize) || 20), 1), 100);
92
+ const offset = (page - 1) * pageSize;
93
+ const search = String((paginationParams === null || paginationParams === void 0 ? void 0 : paginationParams.search) || '').trim();
94
+ const whereClause = search
95
+ ? api_prisma_1.Prisma.sql `WHERE (LOWER(slug) LIKE LOWER(${`%${search}%`}) OR LOWER(name) LIKE LOWER(${`%${search}%`}))`
96
+ : api_prisma_1.Prisma.empty;
97
+ const data = await this.prisma.$queryRaw(api_prisma_1.Prisma.sql `
98
+ SELECT id, slug, layer, name, content, variables_schema, locale, module_slug,
99
+ is_active, version, created_at, updated_at
100
+ FROM ai_instruction
101
+ ${whereClause}
102
+ ORDER BY layer, slug
103
+ LIMIT ${pageSize}
104
+ OFFSET ${offset}
105
+ `);
106
+ const totalResult = await this.prisma.$queryRaw(api_prisma_1.Prisma.sql `
107
+ SELECT COUNT(*) AS total FROM ai_instruction ${whereClause}
108
+ `);
109
+ const total = Number(((_a = totalResult === null || totalResult === void 0 ? void 0 : totalResult[0]) === null || _a === void 0 ? void 0 : _a.total) || 0);
110
+ return {
111
+ data,
112
+ total,
113
+ page,
114
+ pageSize,
115
+ totalPages: Math.ceil(total / pageSize),
116
+ };
117
+ }
118
+ async getById(id) {
119
+ const record = await this.findById(id);
120
+ if (!record)
121
+ throw new common_1.NotFoundException(`AI instruction ${id} not found.`);
122
+ return record;
123
+ }
124
+ async getBySlug(slug) {
125
+ const record = await this.findActiveBySlug(slug);
126
+ if (!record)
127
+ throw new common_1.NotFoundException(`AI instruction "${slug}" not found.`);
128
+ return record;
129
+ }
130
+ async create(dto, createdById) {
131
+ var _a;
132
+ const locale = dto.locale || 'en';
133
+ const isActive = (_a = dto.is_active) !== null && _a !== void 0 ? _a : true;
134
+ await this.prisma.$executeRaw `
135
+ INSERT INTO ai_instruction (slug, layer, name, content, variables_schema, locale, module_slug, is_active, version)
136
+ VALUES (
137
+ ${dto.slug},
138
+ CAST(${dto.layer} AS ai_instruction_layer_enum),
139
+ ${dto.name},
140
+ ${dto.content},
141
+ ${dto.variables_schema ? JSON.stringify(dto.variables_schema) : null}::jsonb,
142
+ ${locale},
143
+ ${dto.module_slug || null},
144
+ ${isActive},
145
+ 1
146
+ )
147
+ `;
148
+ const created = await this.findActiveBySlug(dto.slug);
149
+ // Record version 1
150
+ if (created) {
151
+ await this.saveVersion(created.id, 1, dto.content, 'Initial version', createdById);
152
+ }
153
+ return created;
154
+ }
155
+ async update(id, dto, updatedById) {
156
+ var _a, _b, _c, _d;
157
+ const current = await this.getById(id);
158
+ const newContent = (_a = dto.content) !== null && _a !== void 0 ? _a : current.content;
159
+ const newVersion = dto.content && dto.content !== current.content
160
+ ? current.version + 1
161
+ : current.version;
162
+ await this.prisma.$executeRaw `
163
+ UPDATE ai_instruction
164
+ SET
165
+ name = ${(_b = dto.name) !== null && _b !== void 0 ? _b : current.name},
166
+ content = ${newContent},
167
+ variables_schema = ${dto.variables_schema !== undefined ? JSON.stringify(dto.variables_schema) : current.variables_schema ? JSON.stringify(current.variables_schema) : null}::jsonb,
168
+ locale = ${(_c = dto.locale) !== null && _c !== void 0 ? _c : current.locale},
169
+ module_slug = ${dto.module_slug !== undefined ? dto.module_slug : current.module_slug},
170
+ is_active = ${(_d = dto.is_active) !== null && _d !== void 0 ? _d : current.is_active},
171
+ version = ${newVersion},
172
+ updated_at = NOW()
173
+ WHERE id = ${id}
174
+ `;
175
+ // Save new version if content changed
176
+ if (dto.content && dto.content !== current.content) {
177
+ await this.saveVersion(id, newVersion, newContent, dto.change_note, updatedById);
178
+ }
179
+ this.invalidateCache(current.slug);
180
+ return this.getById(id);
181
+ }
182
+ async delete({ ids }) {
183
+ const existing = await this.prisma.$queryRaw(api_prisma_1.Prisma.sql `
184
+ SELECT id, slug FROM ai_instruction WHERE id IN (${api_prisma_1.Prisma.join(ids)})
185
+ `);
186
+ if (existing.length !== ids.length) {
187
+ const missing = ids.filter((id) => !existing.map((r) => r.id).includes(id));
188
+ throw new common_1.NotFoundException(`AI instructions ${missing.join(', ')} not found.`);
189
+ }
190
+ await this.prisma.$executeRaw `
191
+ DELETE FROM ai_instruction WHERE id IN (${api_prisma_1.Prisma.join(ids)})
192
+ `;
193
+ existing.forEach((r) => this.invalidateCache(r.slug));
194
+ return { count: ids.length };
195
+ }
196
+ async listVersions(id) {
197
+ await this.getById(id);
198
+ return this.prisma.$queryRaw `
199
+ SELECT v.id, v.version, v.content, v.change_note, v.created_at,
200
+ u.name AS created_by_name
201
+ FROM ai_instruction_version v
202
+ LEFT JOIN "user" u ON u.id = v.created_by_id
203
+ WHERE v.instruction_id = ${id}
204
+ ORDER BY v.version DESC
205
+ `;
206
+ }
207
+ async restoreVersion(id, version, restoredById) {
208
+ const versions = await this.prisma.$queryRaw `
209
+ SELECT version, content FROM ai_instruction_version
210
+ WHERE instruction_id = ${id} AND version = ${version}
211
+ LIMIT 1
212
+ `;
213
+ if (!versions.length) {
214
+ throw new common_1.NotFoundException(`Version ${version} not found for instruction ${id}.`);
215
+ }
216
+ const target = versions[0];
217
+ const current = await this.getById(id);
218
+ const newVersion = current.version + 1;
219
+ await this.prisma.$executeRaw `
220
+ UPDATE ai_instruction
221
+ SET content = ${target.content}, version = ${newVersion}, updated_at = NOW()
222
+ WHERE id = ${id}
223
+ `;
224
+ await this.saveVersion(id, newVersion, target.content, `Restored from version ${version}`, restoredById);
225
+ this.invalidateCache(current.slug);
226
+ return this.getById(id);
227
+ }
228
+ // ── Private helpers ───────────────────────────────────────────────────────
229
+ async findById(id) {
230
+ const rows = await this.prisma.$queryRaw `
231
+ SELECT id, slug, layer, name, content, variables_schema, locale, module_slug,
232
+ is_active, version, created_at, updated_at
233
+ FROM ai_instruction WHERE id = ${id} LIMIT 1
234
+ `;
235
+ return (rows === null || rows === void 0 ? void 0 : rows[0]) || null;
236
+ }
237
+ async findActiveBySlug(slug) {
238
+ const rows = await this.prisma.$queryRaw `
239
+ SELECT id, slug, layer, name, content, variables_schema, locale, module_slug,
240
+ is_active, version, created_at, updated_at
241
+ FROM ai_instruction WHERE slug = ${slug} AND is_active = TRUE LIMIT 1
242
+ `;
243
+ return (rows === null || rows === void 0 ? void 0 : rows[0]) || null;
244
+ }
245
+ async findActiveByLayer(layer, moduleSlug) {
246
+ if (moduleSlug) {
247
+ const rows = await this.prisma.$queryRaw `
248
+ SELECT id, slug, layer, name, content, variables_schema, locale, module_slug,
249
+ is_active, version, created_at, updated_at
250
+ FROM ai_instruction
251
+ WHERE layer = CAST(${layer} AS ai_instruction_layer_enum)
252
+ AND module_slug = ${moduleSlug}
253
+ AND is_active = TRUE
254
+ LIMIT 1
255
+ `;
256
+ if (rows === null || rows === void 0 ? void 0 : rows[0])
257
+ return rows[0];
258
+ }
259
+ const rows = await this.prisma.$queryRaw `
260
+ SELECT id, slug, layer, name, content, variables_schema, locale, module_slug,
261
+ is_active, version, created_at, updated_at
262
+ FROM ai_instruction
263
+ WHERE layer = CAST(${layer} AS ai_instruction_layer_enum)
264
+ AND module_slug IS NULL
265
+ AND is_active = TRUE
266
+ LIMIT 1
267
+ `;
268
+ return (rows === null || rows === void 0 ? void 0 : rows[0]) || null;
269
+ }
270
+ async saveVersion(instructionId, version, content, changeNote, createdById) {
271
+ try {
272
+ await this.prisma.$executeRaw `
273
+ INSERT INTO ai_instruction_version (instruction_id, version, content, change_note, created_by_id)
274
+ VALUES (${instructionId}, ${version}, ${content}, ${changeNote || null}, ${createdById || null})
275
+ ON CONFLICT (instruction_id, version) DO NOTHING
276
+ `;
277
+ }
278
+ catch (e) {
279
+ this.logger.warn(`Failed to save version for instruction ${instructionId}: ${e}`);
280
+ }
281
+ }
282
+ };
283
+ exports.AiInstructionService = AiInstructionService;
284
+ exports.AiInstructionService = AiInstructionService = AiInstructionService_1 = __decorate([
285
+ (0, common_1.Injectable)(),
286
+ __param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => api_prisma_1.PrismaService))),
287
+ __metadata("design:paramtypes", [api_prisma_1.PrismaService])
288
+ ], AiInstructionService);
289
+ //# sourceMappingURL=ai-instruction.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-instruction.service.js","sourceRoot":"","sources":["../../src/ai-instruction/ai-instruction.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,oDAA4D;AAC5D,2CAOwB;AAWxB,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAEhD,MAAM,sBAAsB,GAC1B,2EAA2E;IAC3E,qEAAqE;IACrE,yDAAyD,CAAC;AAGrD,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAI/B,YAEE,MAAsC;QAArB,WAAM,GAAN,MAAM,CAAe;QALvB,WAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,CAAC;QAC/C,UAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAKpD,CAAC;IAEJ,KAAK,CAAC,YAAY;QAChB,+CAA+C;QAC/C,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC9B,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QAAC,WAAM,CAAC;YACP,4DAA4D;QAC9D,CAAC;IACH,CAAC;IAED,4EAA4E;IAE5E,KAAK,CAAC,QAAQ,CAAC,KAAyB,EAAE,UAAmB;QAC3D,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,UAAU,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QAE/D,MAAM,MAAM,GAAG,IA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K;8BACJ,UAAU;;;OAGjC,CAAC;YACF,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,CAAC,CAAC;gBAAE,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;QAChC,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAuB;;;;2BAIxC,KAAK;;;;KAI3B,CAAC;QACF,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,CAAC,CAAC,KAAI,IAAI,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,WAAW,CACvB,aAAqB,EACrB,OAAe,EACf,OAAe,EACf,UAAmB,EACnB,WAAoB;QAEpB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAA;;kBAEjB,aAAa,KAAK,OAAO,KAAK,OAAO,KAAK,UAAU,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI;;OAE/F,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,aAAa,KAAK,CAAC,EAAE,CAAC,CAAC;QACpF,CAAC;IACH,CAAC;CACF,CAAA;AA1TY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,0BAAa,CAAC,CAAC,CAAA;qCACf,0BAAa;GAN7B,oBAAoB,CA0ThC"}
@@ -0,0 +1,53 @@
1
+ import { AiInstructionService } from './ai-instruction.service';
2
+ import type { AiPromptBuildContext } from './types/ai-instruction.types';
3
+ export type BuiltPrompt = {
4
+ systemPrompt: string;
5
+ layers: string[];
6
+ layerNames: string[];
7
+ };
8
+ export declare class AiPromptBuilderService {
9
+ private readonly instructionService;
10
+ constructor(instructionService: AiInstructionService);
11
+ /**
12
+ * Composes the system prompt from active layers in priority order.
13
+ * Only includes non-empty layers to minimize tokens.
14
+ *
15
+ * Layers sent:
16
+ * L1 system — always
17
+ * L2 product — always (if configured)
18
+ * L3 module — when moduleSlug is provided
19
+ * L4 agent — when agentSlug is provided
20
+ * runtime — injected by caller at send time (not stored here)
21
+ */
22
+ build(ctx: AiPromptBuildContext): Promise<BuiltPrompt>;
23
+ /**
24
+ * Builds a compact runtime context block (L6) to append to the system prompt.
25
+ * This is NEVER cached — it is generated fresh per request.
26
+ */
27
+ buildRuntimeContext(params: {
28
+ userId?: number;
29
+ locale?: string;
30
+ userRoles?: string[];
31
+ currentDate?: string;
32
+ extraContext?: Record<string, string>;
33
+ }): string;
34
+ /**
35
+ * Builds a compact history summary for older messages to avoid
36
+ * sending full history on every turn.
37
+ *
38
+ * @param messages All conversation messages
39
+ * @param keepLast How many recent messages to keep verbatim
40
+ */
41
+ summarizeHistory(messages: Array<{
42
+ role: string;
43
+ content: string;
44
+ }>, keepLast?: number): Array<{
45
+ role: string;
46
+ content: string;
47
+ }>;
48
+ /**
49
+ * Interpolates {{variable}} placeholders in a template string.
50
+ */
51
+ interpolate(template: string, variables: Record<string, string>): string;
52
+ }
53
+ //# sourceMappingURL=ai-prompt-builder.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-prompt-builder.service.d.ts","sourceRoot":"","sources":["../../src/ai-instruction/ai-prompt-builder.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,qBACa,sBAAsB;IAG/B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;gBAAlB,kBAAkB,EAAE,oBAAoB;IAG3D;;;;;;;;;;OAUG;IACG,KAAK,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IAyC5D;;;OAGG;IACH,mBAAmB,CAAC,MAAM,EAAE;QAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACvC,GAAG,MAAM;IAiBV;;;;;;OAMG;IACH,gBAAgB,CACd,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,EAClD,QAAQ,SAAI,GACX,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IA6B3C;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM;CAGzE"}