@carlonicora/nestjs-neo4jsonapi 1.110.3 → 1.112.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dist/agents/graph/tools/describe-entity.tool.d.ts +1 -1
  2. package/dist/agents/graph/tools/describe-entity.tool.d.ts.map +1 -1
  3. package/dist/agents/graph/tools/describe-entity.tool.js +2 -1
  4. package/dist/agents/graph/tools/describe-entity.tool.js.map +1 -1
  5. package/dist/agents/graph/tools/read-entity.tool.d.ts +1 -1
  6. package/dist/agents/graph/tools/read-entity.tool.d.ts.map +1 -1
  7. package/dist/agents/graph/tools/read-entity.tool.js +2 -1
  8. package/dist/agents/graph/tools/read-entity.tool.js.map +1 -1
  9. package/dist/agents/graph/tools/resolve-entity.tool.d.ts +1 -1
  10. package/dist/agents/graph/tools/resolve-entity.tool.d.ts.map +1 -1
  11. package/dist/agents/graph/tools/resolve-entity.tool.js +2 -1
  12. package/dist/agents/graph/tools/resolve-entity.tool.js.map +1 -1
  13. package/dist/agents/graph/tools/search-entities.tool.d.ts +1 -1
  14. package/dist/agents/graph/tools/search-entities.tool.d.ts.map +1 -1
  15. package/dist/agents/graph/tools/search-entities.tool.js +2 -1
  16. package/dist/agents/graph/tools/search-entities.tool.js.map +1 -1
  17. package/dist/agents/graph/tools/traverse.tool.d.ts +1 -1
  18. package/dist/agents/graph/tools/traverse.tool.d.ts.map +1 -1
  19. package/dist/agents/graph/tools/traverse.tool.js +2 -1
  20. package/dist/agents/graph/tools/traverse.tool.js.map +1 -1
  21. package/dist/agents/operator/tools/search-documents.tool.d.ts +1 -1
  22. package/dist/agents/operator/tools/search-documents.tool.d.ts.map +1 -1
  23. package/dist/agents/operator/tools/search-documents.tool.js +2 -1
  24. package/dist/agents/operator/tools/search-documents.tool.js.map +1 -1
  25. package/dist/bootstrap/app.module.factory.d.ts.map +1 -1
  26. package/dist/bootstrap/app.module.factory.js +3 -0
  27. package/dist/bootstrap/app.module.factory.js.map +1 -1
  28. package/dist/bootstrap/bootstrap.options.d.ts +2 -0
  29. package/dist/bootstrap/bootstrap.options.d.ts.map +1 -1
  30. package/dist/config/base.config.d.ts.map +1 -1
  31. package/dist/config/base.config.js +15 -0
  32. package/dist/config/base.config.js.map +1 -1
  33. package/dist/config/interfaces/base.config.interface.d.ts +2 -0
  34. package/dist/config/interfaces/base.config.interface.d.ts.map +1 -1
  35. package/dist/config/interfaces/config.ai.interface.d.ts +29 -0
  36. package/dist/config/interfaces/config.ai.interface.d.ts.map +1 -1
  37. package/dist/config/interfaces/config.mcp.interface.d.ts +34 -0
  38. package/dist/config/interfaces/config.mcp.interface.d.ts.map +1 -0
  39. package/dist/config/interfaces/config.mcp.interface.js +3 -0
  40. package/dist/config/interfaces/config.mcp.interface.js.map +1 -0
  41. package/dist/config/interfaces/index.d.ts +1 -0
  42. package/dist/config/interfaces/index.d.ts.map +1 -1
  43. package/dist/config/interfaces/index.js +1 -0
  44. package/dist/config/interfaces/index.js.map +1 -1
  45. package/dist/core/llm/services/llm.service.d.ts +52 -0
  46. package/dist/core/llm/services/llm.service.d.ts.map +1 -1
  47. package/dist/core/llm/services/llm.service.js +163 -10
  48. package/dist/core/llm/services/llm.service.js.map +1 -1
  49. package/dist/core/llm/services/model.service.d.ts +2 -0
  50. package/dist/core/llm/services/model.service.d.ts.map +1 -1
  51. package/dist/core/llm/services/model.service.js +7 -0
  52. package/dist/core/llm/services/model.service.js.map +1 -1
  53. package/dist/foundations/oauth/constants/oauth.scopes.d.ts +2 -0
  54. package/dist/foundations/oauth/constants/oauth.scopes.d.ts.map +1 -1
  55. package/dist/foundations/oauth/constants/oauth.scopes.js +4 -0
  56. package/dist/foundations/oauth/constants/oauth.scopes.js.map +1 -1
  57. package/dist/foundations/oauth/controllers/index.d.ts +2 -0
  58. package/dist/foundations/oauth/controllers/index.d.ts.map +1 -1
  59. package/dist/foundations/oauth/controllers/index.js +2 -0
  60. package/dist/foundations/oauth/controllers/index.js.map +1 -1
  61. package/dist/foundations/oauth/controllers/oauth.discovery.controller.d.ts +46 -0
  62. package/dist/foundations/oauth/controllers/oauth.discovery.controller.d.ts.map +1 -0
  63. package/dist/foundations/oauth/controllers/oauth.discovery.controller.js +102 -0
  64. package/dist/foundations/oauth/controllers/oauth.discovery.controller.js.map +1 -0
  65. package/dist/foundations/oauth/controllers/oauth.registration.controller.d.ts +36 -0
  66. package/dist/foundations/oauth/controllers/oauth.registration.controller.d.ts.map +1 -0
  67. package/dist/foundations/oauth/controllers/oauth.registration.controller.js +81 -0
  68. package/dist/foundations/oauth/controllers/oauth.registration.controller.js.map +1 -0
  69. package/dist/foundations/oauth/dtos/index.d.ts +1 -0
  70. package/dist/foundations/oauth/dtos/index.d.ts.map +1 -1
  71. package/dist/foundations/oauth/dtos/index.js +1 -0
  72. package/dist/foundations/oauth/dtos/index.js.map +1 -1
  73. package/dist/foundations/oauth/dtos/oauth.register.dto.d.ts +14 -0
  74. package/dist/foundations/oauth/dtos/oauth.register.dto.d.ts.map +1 -0
  75. package/dist/foundations/oauth/dtos/oauth.register.dto.js +49 -0
  76. package/dist/foundations/oauth/dtos/oauth.register.dto.js.map +1 -0
  77. package/dist/foundations/oauth/index.d.ts +1 -0
  78. package/dist/foundations/oauth/index.d.ts.map +1 -1
  79. package/dist/foundations/oauth/index.js +3 -1
  80. package/dist/foundations/oauth/index.js.map +1 -1
  81. package/dist/foundations/oauth/oauth.module.d.ts +3 -1
  82. package/dist/foundations/oauth/oauth.module.d.ts.map +1 -1
  83. package/dist/foundations/oauth/oauth.module.js +12 -2
  84. package/dist/foundations/oauth/oauth.module.js.map +1 -1
  85. package/dist/foundations/oauth/repositories/oauth.repository.d.ts +2 -1
  86. package/dist/foundations/oauth/repositories/oauth.repository.d.ts.map +1 -1
  87. package/dist/foundations/oauth/repositories/oauth.repository.js +16 -34
  88. package/dist/foundations/oauth/repositories/oauth.repository.js.map +1 -1
  89. package/dist/foundations/oauth/services/oauth.client.service.d.ts +2 -1
  90. package/dist/foundations/oauth/services/oauth.client.service.d.ts.map +1 -1
  91. package/dist/foundations/oauth/services/oauth.client.service.js.map +1 -1
  92. package/dist/foundations/rbac/index.d.ts +4 -0
  93. package/dist/foundations/rbac/index.d.ts.map +1 -1
  94. package/dist/foundations/rbac/index.js +7 -1
  95. package/dist/foundations/rbac/index.js.map +1 -1
  96. package/dist/foundations/rbac/rbac-permission.module.d.ts +14 -0
  97. package/dist/foundations/rbac/rbac-permission.module.d.ts.map +1 -0
  98. package/dist/foundations/rbac/rbac-permission.module.js +33 -0
  99. package/dist/foundations/rbac/rbac-permission.module.js.map +1 -0
  100. package/dist/foundations/rbac/repositories/rbac-permission.repository.d.ts +31 -0
  101. package/dist/foundations/rbac/repositories/rbac-permission.repository.d.ts.map +1 -0
  102. package/dist/foundations/rbac/repositories/rbac-permission.repository.js +80 -0
  103. package/dist/foundations/rbac/repositories/rbac-permission.repository.js.map +1 -0
  104. package/dist/foundations/rbac/services/rbac-permission.service.d.ts +31 -0
  105. package/dist/foundations/rbac/services/rbac-permission.service.d.ts.map +1 -0
  106. package/dist/foundations/rbac/services/rbac-permission.service.js +41 -0
  107. package/dist/foundations/rbac/services/rbac-permission.service.js.map +1 -0
  108. package/dist/index.d.ts +1 -0
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +2 -0
  111. package/dist/index.js.map +1 -1
  112. package/dist/mcp/controllers/mcp.controller.d.ts +34 -0
  113. package/dist/mcp/controllers/mcp.controller.d.ts.map +1 -0
  114. package/dist/mcp/controllers/mcp.controller.js +108 -0
  115. package/dist/mcp/controllers/mcp.controller.js.map +1 -0
  116. package/dist/mcp/filters/mcp.auth.filter.d.ts +21 -0
  117. package/dist/mcp/filters/mcp.auth.filter.d.ts.map +1 -0
  118. package/dist/mcp/filters/mcp.auth.filter.js +52 -0
  119. package/dist/mcp/filters/mcp.auth.filter.js.map +1 -0
  120. package/dist/mcp/index.d.ts +4 -0
  121. package/dist/mcp/index.d.ts.map +1 -0
  122. package/dist/mcp/index.js +11 -0
  123. package/dist/mcp/index.js.map +1 -0
  124. package/dist/mcp/interfaces/mcp.tool.interface.d.ts +37 -0
  125. package/dist/mcp/interfaces/mcp.tool.interface.d.ts.map +1 -0
  126. package/dist/mcp/interfaces/mcp.tool.interface.js +6 -0
  127. package/dist/mcp/interfaces/mcp.tool.interface.js.map +1 -0
  128. package/dist/mcp/mcp.module.d.ts +23 -0
  129. package/dist/mcp/mcp.module.d.ts.map +1 -0
  130. package/dist/mcp/mcp.module.js +59 -0
  131. package/dist/mcp/mcp.module.js.map +1 -0
  132. package/dist/mcp/services/mcp.entity.write.service.d.ts +79 -0
  133. package/dist/mcp/services/mcp.entity.write.service.d.ts.map +1 -0
  134. package/dist/mcp/services/mcp.entity.write.service.js +270 -0
  135. package/dist/mcp/services/mcp.entity.write.service.js.map +1 -0
  136. package/dist/mcp/services/mcp.errors.d.ts +24 -0
  137. package/dist/mcp/services/mcp.errors.d.ts.map +1 -0
  138. package/dist/mcp/services/mcp.errors.js +50 -0
  139. package/dist/mcp/services/mcp.errors.js.map +1 -0
  140. package/dist/mcp/services/mcp.generic.tools.service.d.ts +26 -0
  141. package/dist/mcp/services/mcp.generic.tools.service.d.ts.map +1 -0
  142. package/dist/mcp/services/mcp.generic.tools.service.js +108 -0
  143. package/dist/mcp/services/mcp.generic.tools.service.js.map +1 -0
  144. package/dist/mcp/services/mcp.promoted.tools.factory.d.ts +58 -0
  145. package/dist/mcp/services/mcp.promoted.tools.factory.d.ts.map +1 -0
  146. package/dist/mcp/services/mcp.promoted.tools.factory.js +260 -0
  147. package/dist/mcp/services/mcp.promoted.tools.factory.js.map +1 -0
  148. package/dist/mcp/services/mcp.server.factory.d.ts +24 -0
  149. package/dist/mcp/services/mcp.server.factory.d.ts.map +1 -0
  150. package/dist/mcp/services/mcp.server.factory.js +60 -0
  151. package/dist/mcp/services/mcp.server.factory.js.map +1 -0
  152. package/dist/mcp/services/mcp.tool.registry.d.ts +21 -0
  153. package/dist/mcp/services/mcp.tool.registry.d.ts.map +1 -0
  154. package/dist/mcp/services/mcp.tool.registry.js +72 -0
  155. package/dist/mcp/services/mcp.tool.registry.js.map +1 -0
  156. package/package.json +17 -12
@@ -0,0 +1,59 @@
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.McpModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const agents_modules_1 = require("../agents/agents.modules");
12
+ const search_documents_tool_1 = require("../agents/operator/tools/search-documents.tool");
13
+ const oauth_module_1 = require("../foundations/oauth/oauth.module");
14
+ const rbac_permission_module_1 = require("../foundations/rbac/rbac-permission.module");
15
+ const mcp_controller_1 = require("./controllers/mcp.controller");
16
+ const mcp_entity_write_service_1 = require("./services/mcp.entity.write.service");
17
+ const mcp_generic_tools_service_1 = require("./services/mcp.generic.tools.service");
18
+ const mcp_promoted_tools_factory_1 = require("./services/mcp.promoted.tools.factory");
19
+ const mcp_server_factory_1 = require("./services/mcp.server.factory");
20
+ const mcp_tool_registry_1 = require("./services/mcp.tool.registry");
21
+ /**
22
+ * MCP (Model Context Protocol) server module.
23
+ *
24
+ * Mounted by the bootstrap gate (`BootstrapOptions.mcp === true`) and served
25
+ * at `POST /mcp`, OAuth-authenticated and RBAC-gated. Exports McpToolRegistry
26
+ * so consuming apps can contribute additional tools via the MCP_TOOLS token.
27
+ *
28
+ * Module wiring notes:
29
+ * - `RbacPermissionModule` supplies RbacPermissionService (the RbacModule
30
+ * proper is a config-requiring dynamic module and cannot be imported here).
31
+ * - Audit is NOT wired here: AbstractService.create/put audits internally when
32
+ * the concrete entity service injects AuditService, so MCP writes audit
33
+ * exactly like HTTP writes.
34
+ * - `SearchDocumentsTool` is provided locally: OperatorModule declares but
35
+ * does not export it, and importing OperatorModule would drag in its
36
+ * forwardRef(AssistantModule) cycle. Its dependencies (ToolFactory,
37
+ * ContextualiserService) are exported by AgentsModule's inner modules.
38
+ * - EntityServiceRegistry, Neo4jService, ClsService and ConfigService resolve
39
+ * through the global core/cls/config modules.
40
+ */
41
+ let McpModule = class McpModule {
42
+ };
43
+ exports.McpModule = McpModule;
44
+ exports.McpModule = McpModule = __decorate([
45
+ (0, common_1.Module)({
46
+ imports: [oauth_module_1.OAuthModule, rbac_permission_module_1.RbacPermissionModule, agents_modules_1.AgentsModule],
47
+ controllers: [mcp_controller_1.McpController],
48
+ providers: [
49
+ mcp_server_factory_1.McpServerFactory,
50
+ mcp_tool_registry_1.McpToolRegistry,
51
+ mcp_generic_tools_service_1.McpGenericToolsService,
52
+ mcp_entity_write_service_1.McpEntityWriteService,
53
+ mcp_promoted_tools_factory_1.McpPromotedToolsFactory,
54
+ search_documents_tool_1.SearchDocumentsTool,
55
+ ],
56
+ exports: [mcp_tool_registry_1.McpToolRegistry],
57
+ })
58
+ ], McpModule);
59
+ //# sourceMappingURL=mcp.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.module.js","sourceRoot":"","sources":["../../src/mcp/mcp.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,6DAAwD;AACxD,0FAAqF;AACrF,oEAAgE;AAChE,uFAAkF;AAClF,iEAA6D;AAC7D,kFAA4E;AAC5E,oFAA8E;AAC9E,sFAAgF;AAChF,sEAAiE;AACjE,oEAA+D;AAE/D;;;;;;;;;;;;;;;;;;;GAmBG;AAcI,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,8BAAS;oBAAT,SAAS;IAbrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,0BAAW,EAAE,6CAAoB,EAAE,6BAAY,CAAC;QAC1D,WAAW,EAAE,CAAC,8BAAa,CAAC;QAC5B,SAAS,EAAE;YACT,qCAAgB;YAChB,mCAAe;YACf,kDAAsB;YACtB,gDAAqB;YACrB,oDAAuB;YACvB,2CAAmB;SACpB;QACD,OAAO,EAAE,CAAC,mCAAe,CAAC;KAC3B,CAAC;GACW,SAAS,CAAG"}
@@ -0,0 +1,79 @@
1
+ import { GraphCatalogService } from "../../agents/graph/services/graph.catalog.service";
2
+ import { EntityServiceRegistry } from "../../common/registries/entity.service.registry";
3
+ import { RbacPermissionService } from "../../foundations/rbac/services/rbac-permission.service";
4
+ import type { McpToolDefinition, McpToolResult, McpUserContext } from "../interfaces/mcp.tool.interface";
5
+ /**
6
+ * MCP write executors (C4): create/update entities and add/remove to-many
7
+ * relationship items for any JSON:API type registered in EntityServiceRegistry.
8
+ *
9
+ * Every write is gated by the catalog (type visible to the user's modules) and
10
+ * RBAC (`create`/`update` permission on the entity's module), dispatched through
11
+ * the framework's `AbstractService.*FromDTO` path (never hand-built JSON:API
12
+ * beyond the `JsonApiDTOData` framework type). Audit is NOT performed here:
13
+ * `AbstractService.create/put` audits internally when the concrete entity
14
+ * service injects AuditService, so MCP writes audit exactly like HTTP writes.
15
+ */
16
+ export declare class McpEntityWriteService {
17
+ private readonly registry;
18
+ private readonly catalog;
19
+ private readonly rbac;
20
+ constructor(registry: EntityServiceRegistry, catalog: GraphCatalogService, rbac: RbacPermissionService);
21
+ /**
22
+ * The four write McpToolDefinitions (all `readOnly: false`) with hand-written
23
+ * JSON Schemas matching the C4 method params. Consumed by McpGenericToolsService.
24
+ */
25
+ buildTools(_ctx: McpUserContext): McpToolDefinition[];
26
+ /** Create a new entity of the given type. RBAC action: `create`. */
27
+ createEntity(params: {
28
+ type: string;
29
+ attributes: Record<string, unknown>;
30
+ relationships?: Record<string, {
31
+ data: Array<{
32
+ type: string;
33
+ id: string;
34
+ }>;
35
+ }>;
36
+ }, ctx: McpUserContext): Promise<McpToolResult>;
37
+ /**
38
+ * Update an existing entity. RBAC action: `update`.
39
+ *
40
+ * PATCH semantics via `patchFromDTO` — only the provided attributes change.
41
+ * Deliberately NOT `putFromDTO`: the framework's PUT maps every descriptor
42
+ * relationship and treats the ones absent from the DTO as "delete all
43
+ * edges". The HTTP path is safe because the frontend model always sends the
44
+ * complete relationship set on PUT, but an MCP caller sends attributes only —
45
+ * a PUT here would silently strip every mutable relationship off the record.
46
+ */
47
+ updateEntity(params: {
48
+ type: string;
49
+ id: string;
50
+ attributes: Record<string, unknown>;
51
+ }, ctx: McpUserContext): Promise<McpToolResult>;
52
+ /** Add items to a to-many relationship. RBAC action: `update`. */
53
+ addRelationship(params: {
54
+ type: string;
55
+ id: string;
56
+ relationship: string;
57
+ relatedType: string;
58
+ relatedIds: string[];
59
+ }, ctx: McpUserContext): Promise<McpToolResult>;
60
+ /** Remove items from a to-many relationship. RBAC action: `update`. */
61
+ removeRelationship(params: {
62
+ type: string;
63
+ id: string;
64
+ relationship: string;
65
+ relatedType: string;
66
+ relatedIds: string[];
67
+ }, ctx: McpUserContext): Promise<McpToolResult>;
68
+ /**
69
+ * Shared gate: catalog visibility (unknown_type), RBAC (forbidden), and
70
+ * service registration (unknown_type).
71
+ */
72
+ private gate;
73
+ /**
74
+ * Rejects attribute keys that are not in the entity's catalog field list.
75
+ * Catalog fields are a CatalogField[] array — keys are the `name` property.
76
+ */
77
+ private unknownAttributes;
78
+ }
79
+ //# sourceMappingURL=mcp.entity.write.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.entity.write.service.d.ts","sourceRoot":"","sources":["../../../src/mcp/services/mcp.entity.write.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAExF,OAAO,E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M,EAAE,CAAA;KAAE,EACrG,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC,aAAa,CAAC;IAiBzB,uEAAuE;IACjE,kBAAkB,CACtB,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE,EACrG,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC,aAAa,CAAC;IAiBzB;;;OAGG;YACW,IAAI;IA0BlB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;CAW1B"}
@@ -0,0 +1,270 @@
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.McpEntityWriteService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const node_crypto_1 = require("node:crypto");
15
+ const graph_catalog_service_1 = require("../../agents/graph/services/graph.catalog.service");
16
+ const entity_service_registry_1 = require("../../common/registries/entity.service.registry");
17
+ const rbac_permission_service_1 = require("../../foundations/rbac/services/rbac-permission.service");
18
+ const mcp_errors_1 = require("./mcp.errors");
19
+ const UPDATE_SEMANTICS = "Partial update: only the attributes you provide are changed; omitted attributes and all relationships are left untouched. Use add_relationship/remove_relationship to change relationships.";
20
+ /**
21
+ * MCP write executors (C4): create/update entities and add/remove to-many
22
+ * relationship items for any JSON:API type registered in EntityServiceRegistry.
23
+ *
24
+ * Every write is gated by the catalog (type visible to the user's modules) and
25
+ * RBAC (`create`/`update` permission on the entity's module), dispatched through
26
+ * the framework's `AbstractService.*FromDTO` path (never hand-built JSON:API
27
+ * beyond the `JsonApiDTOData` framework type). Audit is NOT performed here:
28
+ * `AbstractService.create/put` audits internally when the concrete entity
29
+ * service injects AuditService, so MCP writes audit exactly like HTTP writes.
30
+ */
31
+ let McpEntityWriteService = class McpEntityWriteService {
32
+ constructor(registry, catalog, rbac) {
33
+ this.registry = registry;
34
+ this.catalog = catalog;
35
+ this.rbac = rbac;
36
+ }
37
+ /**
38
+ * The four write McpToolDefinitions (all `readOnly: false`) with hand-written
39
+ * JSON Schemas matching the C4 method params. Consumed by McpGenericToolsService.
40
+ */
41
+ buildTools(_ctx) {
42
+ const typeProperty = {
43
+ type: "string",
44
+ description: 'JSON:API entity type (plural, e.g. "orders"). Call describe_entity first for the field list.',
45
+ };
46
+ const idProperty = { type: "string", description: "The id of the target record." };
47
+ return [
48
+ {
49
+ name: "create_entity",
50
+ description: "Create a new record of the given JSON:API entity type. " +
51
+ "Call describe_entity first to learn the valid attributes and relationships.",
52
+ inputSchema: {
53
+ type: "object",
54
+ properties: {
55
+ type: typeProperty,
56
+ attributes: {
57
+ type: "object",
58
+ description: "Attribute values keyed by field name (see describe_entity).",
59
+ },
60
+ relationships: {
61
+ type: "object",
62
+ description: "Optional JSON:API relationships keyed by relationship name.",
63
+ additionalProperties: {
64
+ type: "object",
65
+ properties: {
66
+ data: {
67
+ type: "array",
68
+ items: {
69
+ type: "object",
70
+ properties: { type: { type: "string" }, id: { type: "string" } },
71
+ required: ["type", "id"],
72
+ },
73
+ },
74
+ },
75
+ required: ["data"],
76
+ },
77
+ },
78
+ },
79
+ required: ["type", "attributes"],
80
+ },
81
+ readOnly: false,
82
+ execute: (input, ctx) => this.createEntity(input, ctx),
83
+ },
84
+ {
85
+ name: "update_entity",
86
+ description: `Update an existing record. ${UPDATE_SEMANTICS}`,
87
+ inputSchema: {
88
+ type: "object",
89
+ properties: {
90
+ type: typeProperty,
91
+ id: idProperty,
92
+ attributes: {
93
+ type: "object",
94
+ description: `The attribute values to change. ${UPDATE_SEMANTICS}`,
95
+ },
96
+ },
97
+ required: ["type", "id", "attributes"],
98
+ },
99
+ readOnly: false,
100
+ execute: (input, ctx) => this.updateEntity(input, ctx),
101
+ },
102
+ {
103
+ name: "add_relationship",
104
+ description: "Add one or more related records to a to-many relationship of an existing record. " +
105
+ "Call describe_entity first for the relationship names.",
106
+ inputSchema: {
107
+ type: "object",
108
+ properties: {
109
+ type: typeProperty,
110
+ id: idProperty,
111
+ relationship: { type: "string", description: "Relationship name on the entity (see describe_entity)." },
112
+ relatedType: { type: "string", description: "JSON:API type of the related records." },
113
+ relatedIds: { type: "array", items: { type: "string" }, minItems: 1 },
114
+ },
115
+ required: ["type", "id", "relationship", "relatedType", "relatedIds"],
116
+ },
117
+ readOnly: false,
118
+ execute: (input, ctx) => this.addRelationship(input, ctx),
119
+ },
120
+ {
121
+ name: "remove_relationship",
122
+ description: "Remove one or more related records from a to-many relationship of an existing record.",
123
+ inputSchema: {
124
+ type: "object",
125
+ properties: {
126
+ type: typeProperty,
127
+ id: idProperty,
128
+ relationship: { type: "string", description: "Relationship name on the entity (see describe_entity)." },
129
+ relatedType: { type: "string", description: "JSON:API type of the related records." },
130
+ relatedIds: { type: "array", items: { type: "string" }, minItems: 1 },
131
+ },
132
+ required: ["type", "id", "relationship", "relatedType", "relatedIds"],
133
+ },
134
+ readOnly: false,
135
+ execute: (input, ctx) => this.removeRelationship(input, ctx),
136
+ },
137
+ ];
138
+ }
139
+ /** Create a new entity of the given type. RBAC action: `create`. */
140
+ async createEntity(params, ctx) {
141
+ const gate = await this.gate(params.type, "create", ctx);
142
+ if ("error" in gate)
143
+ return gate.error;
144
+ const { entity, service } = gate;
145
+ const invalid = this.unknownAttributes(entity, params.attributes);
146
+ if (invalid)
147
+ return invalid;
148
+ try {
149
+ const data = {
150
+ id: (0, node_crypto_1.randomUUID)(),
151
+ type: params.type,
152
+ attributes: params.attributes,
153
+ ...(params.relationships ? { relationships: params.relationships } : {}),
154
+ };
155
+ const result = await service.createFromDTO({ data });
156
+ return { content: [{ type: "text", text: JSON.stringify(result) }] };
157
+ }
158
+ catch (e) {
159
+ return (0, mcp_errors_1.mcpError)(e);
160
+ }
161
+ }
162
+ /**
163
+ * Update an existing entity. RBAC action: `update`.
164
+ *
165
+ * PATCH semantics via `patchFromDTO` — only the provided attributes change.
166
+ * Deliberately NOT `putFromDTO`: the framework's PUT maps every descriptor
167
+ * relationship and treats the ones absent from the DTO as "delete all
168
+ * edges". The HTTP path is safe because the frontend model always sends the
169
+ * complete relationship set on PUT, but an MCP caller sends attributes only —
170
+ * a PUT here would silently strip every mutable relationship off the record.
171
+ */
172
+ async updateEntity(params, ctx) {
173
+ const gate = await this.gate(params.type, "update", ctx);
174
+ if ("error" in gate)
175
+ return gate.error;
176
+ const { entity, service } = gate;
177
+ const invalid = this.unknownAttributes(entity, params.attributes);
178
+ if (invalid)
179
+ return invalid;
180
+ try {
181
+ const before = await service.findRecordById({ id: params.id });
182
+ if (!before)
183
+ return (0, mcp_errors_1.mcpFlatError)("not_found", `No ${params.type} record with id ${params.id}.`);
184
+ const data = { id: params.id, type: params.type, attributes: params.attributes };
185
+ const result = await service.patchFromDTO({ data });
186
+ return { content: [{ type: "text", text: JSON.stringify(result) }] };
187
+ }
188
+ catch (e) {
189
+ return (0, mcp_errors_1.mcpError)(e);
190
+ }
191
+ }
192
+ /** Add items to a to-many relationship. RBAC action: `update`. */
193
+ async addRelationship(params, ctx) {
194
+ const gate = await this.gate(params.type, "update", ctx);
195
+ if ("error" in gate)
196
+ return gate.error;
197
+ const { service } = gate;
198
+ try {
199
+ const data = params.relatedIds.map((id) => ({ type: params.relatedType, id }));
200
+ const result = await service.addToRelationshipFromDTO({
201
+ id: params.id,
202
+ relationship: params.relationship,
203
+ data,
204
+ });
205
+ return { content: [{ type: "text", text: JSON.stringify(result) }] };
206
+ }
207
+ catch (e) {
208
+ return (0, mcp_errors_1.mcpError)(e);
209
+ }
210
+ }
211
+ /** Remove items from a to-many relationship. RBAC action: `update`. */
212
+ async removeRelationship(params, ctx) {
213
+ const gate = await this.gate(params.type, "update", ctx);
214
+ if ("error" in gate)
215
+ return gate.error;
216
+ const { service } = gate;
217
+ try {
218
+ const data = params.relatedIds.map((id) => ({ type: params.relatedType, id }));
219
+ const result = await service.removeFromRelationshipFromDTO({
220
+ id: params.id,
221
+ relationship: params.relationship,
222
+ data,
223
+ });
224
+ return { content: [{ type: "text", text: JSON.stringify(result) }] };
225
+ }
226
+ catch (e) {
227
+ return (0, mcp_errors_1.mcpError)(e);
228
+ }
229
+ }
230
+ /**
231
+ * Shared gate: catalog visibility (unknown_type), RBAC (forbidden), and
232
+ * service registration (unknown_type).
233
+ */
234
+ async gate(type, action, ctx) {
235
+ const entity = this.catalog.getEntityDetail(type, ctx.userModuleIds);
236
+ if (!entity) {
237
+ return {
238
+ error: (0, mcp_errors_1.mcpFlatError)("unknown_type", `Unknown or inaccessible entity type: ${type}. Call describe_entity first.`),
239
+ };
240
+ }
241
+ if (!(await this.rbac.can({ userId: ctx.userId, moduleId: entity.moduleId, action }))) {
242
+ return { error: (0, mcp_errors_1.mcpFlatError)("forbidden", `You lack ${action} permission on ${type}.`) };
243
+ }
244
+ const service = this.registry.get(type);
245
+ if (!service) {
246
+ return { error: (0, mcp_errors_1.mcpFlatError)("unknown_type", `No service registered for ${type}.`) };
247
+ }
248
+ return { entity, service };
249
+ }
250
+ /**
251
+ * Rejects attribute keys that are not in the entity's catalog field list.
252
+ * Catalog fields are a CatalogField[] array — keys are the `name` property.
253
+ */
254
+ unknownAttributes(entity, attributes) {
255
+ const known = new Set(entity.fields.map((f) => f.name));
256
+ const unknown = Object.keys(attributes).filter((k) => !known.has(k));
257
+ if (unknown.length) {
258
+ return (0, mcp_errors_1.mcpFlatError)("validation_failed", `Unknown attributes: ${unknown.join(", ")}. Call describe_entity("${entity.type}") for the field list.`);
259
+ }
260
+ return null;
261
+ }
262
+ };
263
+ exports.McpEntityWriteService = McpEntityWriteService;
264
+ exports.McpEntityWriteService = McpEntityWriteService = __decorate([
265
+ (0, common_1.Injectable)(),
266
+ __metadata("design:paramtypes", [entity_service_registry_1.EntityServiceRegistry,
267
+ graph_catalog_service_1.GraphCatalogService,
268
+ rbac_permission_service_1.RbacPermissionService])
269
+ ], McpEntityWriteService);
270
+ //# sourceMappingURL=mcp.entity.write.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.entity.write.service.js","sourceRoot":"","sources":["../../../src/mcp/services/mcp.entity.write.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6CAAyC;AAEzC,6FAAwF;AACxF,6FAAwF;AAExF,qGAAgG;AAEhG,6CAAsD;AAEtD,MAAM,gBAAgB,GACpB,6LAA6L,CAAC;AAEhM;;;;;;;;;;GAUG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAChC,YACmB,QAA+B,EAC/B,OAA4B,EAC5B,IAA2B;QAF3B,aAAQ,GAAR,QAAQ,CAAuB;QAC/B,YAAO,GAAP,OAAO,CAAqB;QAC5B,SAAI,GAAJ,IAAI,CAAuB;IAC3C,CAAC;IAEJ;;;OAGG;IACH,UAAU,CAAC,IAAoB;QAC7B,MAAM,YAAY,GAAG;YACnB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,8FAA8F;SAC5G,CAAC;QACF,MAAM,UAAU,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,8BAA8B,EAAE,CAAC;QACnF,OAAO;YACL;gBACE,IAAI,EAAE,eAAe;gBACrB,WAAW,EACT,yDAAyD;oBACzD,6EAA6E;gBAC/E,WAAW,EAAE;oBACX,IAAI,EAAE,QA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AI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,EAAE,KAAK,EAAE,IAAA,yBAAY,EAAC,cAAc,EAAE,6BAA6B,IAAI,GAAG,CAAC,EAAE,CAAC;QACvF,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACK,iBAAiB,CAAC,MAAqB,EAAE,UAAmC;QAClF,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACxD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,OAAO,IAAA,yBAAY,EACjB,mBAAmB,EACnB,uBAAuB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,2BAA2B,MAAM,CAAC,IAAI,wBAAwB,CACxG,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAlRY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;qCAGkB,+CAAqB;QACtB,2CAAmB;QACtB,+CAAqB;GAJnC,qBAAqB,CAkRjC"}
@@ -0,0 +1,24 @@
1
+ import type { McpToolResult } from "../interfaces/mcp.tool.interface";
2
+ /**
3
+ * MCP tool error codes (C10). Every executor failure is returned to the MCP
4
+ * client as a FLAT JSON payload `{ code, message, ...meta }` — mirroring the
5
+ * flat-error convention used by the HTTP layer's HttpExceptionFilter.
6
+ */
7
+ export type McpErrorCode = "unknown_type" | "forbidden" | "validation_failed" | "not_found" | "internal";
8
+ /**
9
+ * Maps an unknown thrown value to a flat MCP error result.
10
+ *
11
+ * - `HttpException` → status-derived code (404 → not_found, 403 → forbidden,
12
+ * 400/422 → validation_failed, anything else → internal)
13
+ * - `ZodError` → validation_failed with per-issue `issues` meta
14
+ * - other `Error` → internal with the error message
15
+ *
16
+ * Never includes stack traces.
17
+ */
18
+ export declare function mcpError(e: unknown): McpToolResult;
19
+ /**
20
+ * Builds a flat MCP error result directly from a code + message (+ optional meta).
21
+ * The payload shape is intentionally flat: `{ code, message, ...meta }`.
22
+ */
23
+ export declare function mcpFlatError(code: string, message: string, meta?: Record<string, unknown>): McpToolResult;
24
+ //# sourceMappingURL=mcp.errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.errors.d.ts","sourceRoot":"","sources":["../../../src/mcp/services/mcp.errors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,WAAW,GAAG,mBAAmB,GAAG,WAAW,GAAG,UAAU,CAAC;AAEzG;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,aAAa,CAuBlD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,aAAa,CAE7G"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mcpError = mcpError;
4
+ exports.mcpFlatError = mcpFlatError;
5
+ const common_1 = require("@nestjs/common");
6
+ const zod_1 = require("zod");
7
+ /**
8
+ * Maps an unknown thrown value to a flat MCP error result.
9
+ *
10
+ * - `HttpException` → status-derived code (404 → not_found, 403 → forbidden,
11
+ * 400/422 → validation_failed, anything else → internal)
12
+ * - `ZodError` → validation_failed with per-issue `issues` meta
13
+ * - other `Error` → internal with the error message
14
+ *
15
+ * Never includes stack traces.
16
+ */
17
+ function mcpError(e) {
18
+ let code = "internal";
19
+ let message = "Unexpected error";
20
+ let meta = {};
21
+ if (e instanceof common_1.HttpException) {
22
+ const status = e.getStatus();
23
+ code =
24
+ status === 404
25
+ ? "not_found"
26
+ : status === 403
27
+ ? "forbidden"
28
+ : status === 400 || status === 422
29
+ ? "validation_failed"
30
+ : "internal";
31
+ message = e.message;
32
+ }
33
+ else if (e instanceof zod_1.ZodError) {
34
+ code = "validation_failed";
35
+ message = "Input validation failed";
36
+ meta = { issues: e.issues.map((i) => ({ path: i.path.join("."), message: i.message })) };
37
+ }
38
+ else if (e instanceof Error) {
39
+ message = e.message;
40
+ }
41
+ return mcpFlatError(code, message, meta);
42
+ }
43
+ /**
44
+ * Builds a flat MCP error result directly from a code + message (+ optional meta).
45
+ * The payload shape is intentionally flat: `{ code, message, ...meta }`.
46
+ */
47
+ function mcpFlatError(code, message, meta = {}) {
48
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ code, message, ...meta }) }] };
49
+ }
50
+ //# sourceMappingURL=mcp.errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.errors.js","sourceRoot":"","sources":["../../../src/mcp/services/mcp.errors.ts"],"names":[],"mappings":";;AAqBA,4BAuBC;AAMD,oCAEC;AApDD,2CAA+C;AAC/C,6BAA+B;AAU/B;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,CAAU;IACjC,IAAI,IAAI,GAAiB,UAAU,CAAC;IACpC,IAAI,OAAO,GAAG,kBAAkB,CAAC;IACjC,IAAI,IAAI,GAA4B,EAAE,CAAC;IACvC,IAAI,CAAC,YAAY,sBAAa,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC;QAC7B,IAAI;YACF,MAAM,KAAK,GAAG;gBACZ,CAAC,CAAC,WAAW;gBACb,CAAC,CAAC,MAAM,KAAK,GAAG;oBACd,CAAC,CAAC,WAAW;oBACb,CAAC,CAAC,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG;wBAChC,CAAC,CAAC,mBAAmB;wBACrB,CAAC,CAAC,UAAU,CAAC;QACrB,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;IACtB,CAAC;SAAM,IAAI,CAAC,YAAY,cAAQ,EAAE,CAAC;QACjC,IAAI,GAAG,mBAAmB,CAAC;QAC3B,OAAO,GAAG,yBAAyB,CAAC;QACpC,IAAI,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC;IAC3F,CAAC;SAAM,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;QAC9B,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,OAAO,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,IAAY,EAAE,OAAe,EAAE,OAAgC,EAAE;IAC5F,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAC1G,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { DescribeEntityTool } from "../../agents/graph/tools/describe-entity.tool";
2
+ import { ReadEntityTool } from "../../agents/graph/tools/read-entity.tool";
3
+ import { ResolveEntityTool } from "../../agents/graph/tools/resolve-entity.tool";
4
+ import { SearchEntitiesTool } from "../../agents/graph/tools/search-entities.tool";
5
+ import { TraverseTool } from "../../agents/graph/tools/traverse.tool";
6
+ import { SearchDocumentsTool } from "../../agents/operator/tools/search-documents.tool";
7
+ import { McpToolDefinition, McpUserContext } from "../interfaces/mcp.tool.interface";
8
+ import { McpEntityWriteService } from "./mcp.entity.write.service";
9
+ /**
10
+ * Builds the generic MCP tool set for one authenticated request:
11
+ * the five graph read tools, the document-retrieval tool, and the four
12
+ * entity write tools contributed by McpEntityWriteService.
13
+ */
14
+ export declare class McpGenericToolsService {
15
+ private readonly resolveEntityTool;
16
+ private readonly describeEntityTool;
17
+ private readonly searchEntitiesTool;
18
+ private readonly readEntityTool;
19
+ private readonly traverseTool;
20
+ private readonly searchDocumentsTool;
21
+ private readonly writeService;
22
+ constructor(resolveEntityTool: ResolveEntityTool, describeEntityTool: DescribeEntityTool, searchEntitiesTool: SearchEntitiesTool, readEntityTool: ReadEntityTool, traverseTool: TraverseTool, searchDocumentsTool: SearchDocumentsTool, writeService: McpEntityWriteService);
23
+ /** Builds the per-request generic tool definitions (read tools + write tools). */
24
+ build(ctx: McpUserContext): McpToolDefinition[];
25
+ }
26
+ //# sourceMappingURL=mcp.generic.tools.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.generic.tools.service.d.ts","sourceRoot":"","sources":["../../../src/mcp/services/mcp.generic.tools.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAA6B,MAAM,+CAA+C,CAAC;AAC9G,OAAO,EAAE,cAAc,EAAyB,MAAM,2CAA2C,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAA4B,MAAM,8CAA8C,CAAC;AAC3G,OAAO,EAAE,kBAAkB,EAA6B,MAAM,+CAA+C,CAAC;AAE9G,OAAO,EAAE,YAAY,EAAuB,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,mBAAmB,EAA8B,MAAM,mDAAmD,CAAC;AACpH,OAAO,EAAE,iBAAiB,EAAiB,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAEpG,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAgBnE;;;;GAIG;AACH,qBACa,sBAAsB;IAE/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY;gBANZ,iBAAiB,EAAE,iBAAiB,EACpC,kBAAkB,EAAE,kBAAkB,EACtC,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,YAAY,EAC1B,mBAAmB,EAAE,mBAAmB,EACxC,YAAY,EAAE,qBAAqB;IAGtD,kFAAkF;IAClF,KAAK,CAAC,GAAG,EAAE,cAAc,GAAG,iBAAiB,EAAE;CA2EhD"}