@hexabot-ai/api 3.2.2-alpha.8 → 3.2.2-beta.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.
- package/dist/actions/actions.service.d.ts +1 -0
- package/dist/actions/actions.service.js +19 -1
- package/dist/actions/actions.service.js.map +1 -1
- package/dist/actions/types.d.ts +3 -1
- package/dist/app.controller.d.ts +1 -0
- package/dist/app.controller.js +1 -0
- package/dist/app.controller.js.map +1 -1
- package/dist/app.module.js +13 -1
- package/dist/app.module.js.map +1 -1
- package/dist/channel/lib/__test__/label.mock.js +0 -24
- package/dist/channel/lib/__test__/label.mock.js.map +1 -1
- package/dist/chat/dto/label.dto.d.ts +0 -1
- package/dist/chat/dto/label.dto.js +0 -6
- package/dist/chat/dto/label.dto.js.map +1 -1
- package/dist/chat/entities/label-group.entity.d.ts +0 -2
- package/dist/chat/entities/label.entity.d.ts +0 -4
- package/dist/chat/entities/label.entity.js +0 -5
- package/dist/chat/entities/label.entity.js.map +1 -1
- package/dist/chat/services/subscriber.service.d.ts +0 -1
- package/dist/config/index.js +14 -2
- package/dist/config/index.js.map +1 -1
- package/dist/config/types.d.ts +9 -0
- package/dist/extensions/actions/ai/agent.action.d.ts +1 -1
- package/dist/extensions/actions/ai/agent.action.js +6 -3
- package/dist/extensions/actions/ai/agent.action.js.map +1 -1
- package/dist/extensions/actions/ai/ai-base.action.d.ts +1 -1
- package/dist/extensions/actions/ai/ai-base.action.js +18 -5
- package/dist/extensions/actions/ai/ai-base.action.js.map +1 -1
- package/dist/extensions/actions/ai/generate-object.base.action.d.ts +1 -1
- package/dist/extensions/actions/ai/generate-object.base.action.js +3 -2
- package/dist/extensions/actions/ai/generate-object.base.action.js.map +1 -1
- package/dist/extensions/actions/ai/generate-text.base.action.d.ts +1 -1
- package/dist/extensions/actions/ai/generate-text.base.action.js +3 -2
- package/dist/extensions/actions/ai/generate-text.base.action.js.map +1 -1
- package/dist/extensions/actions/ai/mcp.binding.js +2 -0
- package/dist/extensions/actions/ai/mcp.binding.js.map +1 -1
- package/dist/extensions/actions/ai/memory.binding.js +2 -0
- package/dist/extensions/actions/ai/memory.binding.js.map +1 -1
- package/dist/extensions/actions/ai/retrieve-content-rag.action.js +2 -0
- package/dist/extensions/actions/ai/retrieve-content-rag.action.js.map +1 -1
- package/dist/extensions/actions/messaging/list.action.d.ts +2 -2
- package/dist/extensions/actions/messaging/list.action.js +7 -0
- package/dist/extensions/actions/messaging/list.action.js.map +1 -1
- package/dist/extensions/actions/subscriber/update-labels.action.js +3 -0
- package/dist/extensions/actions/subscriber/update-labels.action.js.map +1 -1
- package/dist/extensions/actions/web/http-request.action.js +12 -1
- package/dist/extensions/actions/web/http-request.action.js.map +1 -1
- package/dist/extensions/actions/workflow/call-workflow.action.d.ts +19 -0
- package/dist/extensions/actions/workflow/call-workflow.action.js +83 -0
- package/dist/extensions/actions/workflow/call-workflow.action.js.map +1 -0
- package/dist/extensions/actions/workflow/i18n/en.translations.json +9 -0
- package/dist/extensions/actions/workflow/i18n/fr.translations.json +9 -0
- package/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/index.js +1 -0
- package/dist/extensions/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/controllers/mcp-token.controller.d.ts +47 -0
- package/dist/mcp/controllers/mcp-token.controller.js +70 -0
- package/dist/mcp/controllers/mcp-token.controller.js.map +1 -0
- package/dist/mcp/decorators/mcp-permission.decorator.d.ts +8 -0
- package/dist/mcp/decorators/mcp-permission.decorator.js +11 -0
- package/dist/mcp/decorators/mcp-permission.decorator.js.map +1 -0
- package/dist/mcp/dto/mcp-token.dto.d.ts +17 -0
- package/dist/mcp/dto/mcp-token.dto.js +40 -0
- package/dist/mcp/dto/mcp-token.dto.js.map +1 -0
- package/dist/mcp/entities/mcp-token.entity.d.ts +111 -0
- package/dist/mcp/entities/mcp-token.entity.js +69 -0
- package/dist/mcp/entities/mcp-token.entity.js.map +1 -0
- package/dist/mcp/guards/hexabot-mcp-token.guard.d.ts +9 -0
- package/dist/mcp/guards/hexabot-mcp-token.guard.js +49 -0
- package/dist/mcp/guards/hexabot-mcp-token.guard.js.map +1 -0
- package/dist/mcp/guards/mcp-permission.guard.d.ts +9 -0
- package/dist/mcp/guards/mcp-permission.guard.js +47 -0
- package/dist/mcp/guards/mcp-permission.guard.js.map +1 -0
- package/dist/mcp/mcp-api.module.d.ts +2 -0
- package/dist/mcp/mcp-api.module.js +65 -0
- package/dist/mcp/mcp-api.module.js.map +1 -0
- package/dist/mcp/repositories/mcp-token.repository.d.ts +8 -0
- package/dist/mcp/repositories/mcp-token.repository.js +41 -0
- package/dist/mcp/repositories/mcp-token.repository.js.map +1 -0
- package/dist/mcp/services/mcp-token.service.d.ts +24 -0
- package/dist/mcp/services/mcp-token.service.js +106 -0
- package/dist/mcp/services/mcp-token.service.js.map +1 -0
- package/dist/mcp/tools/catalog-mcp.tools.d.ts +63 -0
- package/dist/mcp/tools/catalog-mcp.tools.js +135 -0
- package/dist/mcp/tools/catalog-mcp.tools.js.map +1 -0
- package/dist/mcp/tools/cms-mcp.tools.d.ts +128 -0
- package/dist/mcp/tools/cms-mcp.tools.js +242 -0
- package/dist/mcp/tools/cms-mcp.tools.js.map +1 -0
- package/dist/mcp/tools/credential-mcp.tools.d.ts +19 -0
- package/dist/mcp/tools/credential-mcp.tools.js +82 -0
- package/dist/mcp/tools/credential-mcp.tools.js.map +1 -0
- package/dist/mcp/tools/hexabot-mcp-tool.base.d.ts +22 -0
- package/dist/mcp/tools/hexabot-mcp-tool.base.js +48 -0
- package/dist/mcp/tools/hexabot-mcp-tool.base.js.map +1 -0
- package/dist/mcp/tools/hexabot-mcp.schemas.d.ts +41 -0
- package/dist/mcp/tools/hexabot-mcp.schemas.js +36 -0
- package/dist/mcp/tools/hexabot-mcp.schemas.js.map +1 -0
- package/dist/mcp/tools/hexabot-mcp.tools.d.ts +1 -0
- package/dist/mcp/tools/hexabot-mcp.tools.js +18 -0
- package/dist/mcp/tools/hexabot-mcp.tools.js.map +1 -0
- package/dist/mcp/tools/hexabot-mcp.utils.d.ts +2 -0
- package/dist/mcp/tools/hexabot-mcp.utils.js +21 -0
- package/dist/mcp/tools/hexabot-mcp.utils.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +22 -0
- package/dist/mcp/tools/index.js +50 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/mcp-server-mcp.tools.d.ts +77 -0
- package/dist/mcp/tools/mcp-server-mcp.tools.js +130 -0
- package/dist/mcp/tools/mcp-server-mcp.tools.js.map +1 -0
- package/dist/mcp/tools/memory-definition-mcp.tools.d.ts +57 -0
- package/dist/mcp/tools/memory-definition-mcp.tools.js +128 -0
- package/dist/mcp/tools/memory-definition-mcp.tools.js.map +1 -0
- package/dist/mcp/tools/workflow-mcp.helper.d.ts +156 -0
- package/dist/mcp/tools/workflow-mcp.helper.js +128 -0
- package/dist/mcp/tools/workflow-mcp.helper.js.map +1 -0
- package/dist/mcp/tools/workflow-mcp.tools.d.ts +790 -0
- package/dist/mcp/tools/workflow-mcp.tools.js +227 -0
- package/dist/mcp/tools/workflow-mcp.tools.js.map +1 -0
- package/dist/mcp/tools/workflow-run-mcp.tools.d.ts +349 -0
- package/dist/mcp/tools/workflow-run-mcp.tools.js +242 -0
- package/dist/mcp/tools/workflow-run-mcp.tools.js.map +1 -0
- package/dist/mcp/tools/workflow-version-mcp.tools.d.ts +238 -0
- package/dist/mcp/tools/workflow-version-mcp.tools.js +368 -0
- package/dist/mcp/tools/workflow-version-mcp.tools.js.map +1 -0
- package/dist/mcp/types.d.ts +7 -0
- package/dist/mcp/types.js +3 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/static/assets/{browser-ponyfill-IkrOfrbH.js → browser-ponyfill-AQYxeOz6.js} +1 -1
- package/dist/static/assets/{cssMode-BVh8Ojbf.js → cssMode-CU7XHFDD.js} +1 -1
- package/dist/static/assets/{freemarker2-Cnk90W15.js → freemarker2-DA_oH4Qs.js} +1 -1
- package/dist/static/assets/{handlebars-DDmCOyIG.js → handlebars-DXFzBSlw.js} +1 -1
- package/dist/static/assets/{html-cDkAkcNZ.js → html-CnQNXujK.js} +1 -1
- package/dist/static/assets/{htmlMode-BKekdtGx.js → htmlMode-BpX8KTMR.js} +1 -1
- package/dist/static/assets/{index-CnXiX03v.js → index-BIqNbcu4.js} +2379 -2330
- package/dist/static/assets/{index-BI1BtkYv.css → index-D-b9KTZd.css} +1 -1
- package/dist/static/assets/{javascript-bO_Y-MtP.js → javascript-DeoOxUBN.js} +1 -1
- package/dist/static/assets/{jsonMode-p7oe1x6a.js → jsonMode-YGmaNoOG.js} +1 -1
- package/dist/static/assets/{liquid-DehK5Toi.js → liquid-K6wF5n3k.js} +1 -1
- package/dist/static/assets/{lspLanguageFeatures-C8ni2Y8s.js → lspLanguageFeatures-DFIoRPyQ.js} +1 -1
- package/dist/static/assets/{mdx-BqE3GcoU.js → mdx-CWEgpRjI.js} +1 -1
- package/dist/static/assets/{python-DYGyqTrT.js → python-22vBz2Ov.js} +1 -1
- package/dist/static/assets/{razor-CTOqYwI_.js → razor-CEUwDwv_.js} +1 -1
- package/dist/static/assets/{tsMode-n7ps72jb.js → tsMode-kpHfzhoP.js} +1 -1
- package/dist/static/assets/{typescript-B0sRB56_.js → typescript-PCkEoDOe.js} +1 -1
- package/dist/static/assets/{xml-C4I4RxHC.js → xml-OzOqd-hy.js} +1 -1
- package/dist/static/assets/{yaml-V_o23lNz.js → yaml-B3P_vvCy.js} +1 -1
- package/dist/static/index.html +2 -2
- package/dist/static/locales/en/translation.json +89 -5
- package/dist/static/locales/fr/translation.json +90 -6
- package/dist/transfer/adapters/content-type-transfer.adapter.d.ts +14 -0
- package/dist/transfer/adapters/content-type-transfer.adapter.js +102 -0
- package/dist/transfer/adapters/content-type-transfer.adapter.js.map +1 -0
- package/dist/transfer/adapters/credential-transfer.adapter.d.ts +13 -0
- package/dist/transfer/adapters/credential-transfer.adapter.js +110 -0
- package/dist/transfer/adapters/credential-transfer.adapter.js.map +1 -0
- package/dist/transfer/adapters/label-transfer.adapter.d.ts +15 -0
- package/dist/transfer/adapters/label-transfer.adapter.js +189 -0
- package/dist/transfer/adapters/label-transfer.adapter.js.map +1 -0
- package/dist/transfer/adapters/mcp-server-transfer.adapter.d.ts +16 -0
- package/dist/transfer/adapters/mcp-server-transfer.adapter.js +169 -0
- package/dist/transfer/adapters/mcp-server-transfer.adapter.js.map +1 -0
- package/dist/transfer/adapters/memory-definition-transfer.adapter.d.ts +14 -0
- package/dist/transfer/adapters/memory-definition-transfer.adapter.js +111 -0
- package/dist/transfer/adapters/memory-definition-transfer.adapter.js.map +1 -0
- package/dist/transfer/index.d.ts +7 -0
- package/dist/transfer/index.js +24 -0
- package/dist/transfer/index.js.map +1 -0
- package/dist/transfer/workflow-transfer-adapter.registry.d.ts +27 -0
- package/dist/transfer/workflow-transfer-adapter.registry.js +164 -0
- package/dist/transfer/workflow-transfer-adapter.registry.js.map +1 -0
- package/dist/transfer/workflow-transfer-definition.service.d.ts +40 -0
- package/dist/transfer/workflow-transfer-definition.service.js +353 -0
- package/dist/transfer/workflow-transfer-definition.service.js.map +1 -0
- package/dist/transfer/workflow-transfer-resource-adapter.d.ts +33 -0
- package/dist/transfer/workflow-transfer-resource-adapter.js +81 -0
- package/dist/transfer/workflow-transfer-resource-adapter.js.map +1 -0
- package/dist/transfer/workflow-transfer.controller.d.ts +9 -0
- package/dist/transfer/workflow-transfer.controller.js +63 -0
- package/dist/transfer/workflow-transfer.controller.js.map +1 -0
- package/dist/transfer/workflow-transfer.module.d.ts +2 -0
- package/dist/transfer/workflow-transfer.module.js +47 -0
- package/dist/transfer/workflow-transfer.module.js.map +1 -0
- package/dist/transfer/workflow-transfer.service.d.ts +51 -0
- package/dist/transfer/workflow-transfer.service.js +509 -0
- package/dist/transfer/workflow-transfer.service.js.map +1 -0
- package/dist/transfer/workflow-transfer.types.d.ts +31 -0
- package/dist/transfer/workflow-transfer.types.js +35 -0
- package/dist/transfer/workflow-transfer.types.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/event-emitter.d.ts +12 -5
- package/dist/user/controllers/user.controller.d.ts +0 -2
- package/dist/user/dto/user.dto.d.ts +1 -1
- package/dist/user/entities/user.entity.d.ts +0 -2
- package/dist/user/guards/ability.guard.js +12 -2
- package/dist/user/guards/ability.guard.js.map +1 -1
- package/dist/utils/test/fixtures/label-group.d.ts +1 -2
- package/dist/utils/test/fixtures/label.d.ts +1 -2
- package/dist/utils/test/fixtures/label.js +0 -19
- package/dist/utils/test/fixtures/label.js.map +1 -1
- package/dist/utils/test/fixtures/subscriber.d.ts +1 -1
- package/dist/utils/test/fixtures/workflow-run.js +4 -1
- package/dist/utils/test/fixtures/workflow-run.js.map +1 -1
- package/dist/utils/test/port.d.ts +8 -0
- package/dist/utils/test/port.js +34 -0
- package/dist/utils/test/port.js.map +1 -0
- package/dist/websocket/websocket.gateway.d.ts +2 -1
- package/dist/websocket/websocket.gateway.js.map +1 -1
- package/dist/workflow/contexts/workflow-runtime.context.d.ts +3 -1
- package/dist/workflow/contexts/workflow-runtime.context.js +5 -0
- package/dist/workflow/contexts/workflow-runtime.context.js.map +1 -1
- package/dist/workflow/controllers/workflow-run.controller.js +2 -0
- package/dist/workflow/controllers/workflow-run.controller.js.map +1 -1
- package/dist/workflow/dto/workflow-run.dto.d.ts +1 -0
- package/dist/workflow/dto/workflow-run.dto.js +11 -0
- package/dist/workflow/dto/workflow-run.dto.js.map +1 -1
- package/dist/workflow/entities/memory-record.entity.d.ts +2 -0
- package/dist/workflow/entities/workflow-run.entity.d.ts +62 -0
- package/dist/workflow/entities/workflow-run.entity.js +15 -1
- package/dist/workflow/entities/workflow-run.entity.js.map +1 -1
- package/dist/workflow/index.d.ts +7 -0
- package/dist/workflow/index.js +7 -0
- package/dist/workflow/index.js.map +1 -1
- package/dist/workflow/repositories/workflow-run.repository.js +7 -1
- package/dist/workflow/repositories/workflow-run.repository.js.map +1 -1
- package/dist/workflow/resource-refs.d.ts +17 -0
- package/dist/workflow/resource-refs.js +15 -0
- package/dist/workflow/resource-refs.js.map +1 -0
- package/dist/workflow/services/agentic.service.d.ts +9 -2
- package/dist/workflow/services/agentic.service.js +142 -19
- package/dist/workflow/services/agentic.service.js.map +1 -1
- package/dist/workflow/services/workflow-run.service.d.ts +3 -0
- package/dist/workflow/services/workflow-run.service.js +75 -3
- package/dist/workflow/services/workflow-run.service.js.map +1 -1
- package/dist/workflow/services/workflow-version.service.d.ts +2 -0
- package/dist/workflow/services/workflow-version.service.js +19 -0
- package/dist/workflow/services/workflow-version.service.js.map +1 -1
- package/dist/workflow/services/workflow.service.d.ts +13 -9
- package/dist/workflow/services/workflow.service.js +64 -35
- package/dist/workflow/services/workflow.service.js.map +1 -1
- package/dist/workflow/types.d.ts +31 -0
- package/dist/workflow/types.js +2 -1
- package/dist/workflow/types.js.map +1 -1
- package/dist/workflow/workflow.module.js +3 -0
- package/dist/workflow/workflow.module.js.map +1 -1
- package/package.json +7 -5
- package/src/actions/actions.service.ts +34 -4
- package/src/actions/types.ts +6 -5
- package/src/app.controller.ts +1 -0
- package/src/app.module.ts +17 -1
- package/src/channel/lib/__test__/label.mock.ts +0 -24
- package/src/chat/dto/label.dto.ts +1 -12
- package/src/chat/entities/label.entity.ts +0 -4
- package/src/config/index.ts +17 -2
- package/src/config/types.ts +9 -0
- package/src/extensions/actions/ai/agent.action.ts +6 -1
- package/src/extensions/actions/ai/ai-base.action.ts +39 -5
- package/src/extensions/actions/ai/generate-object.base.action.ts +3 -0
- package/src/extensions/actions/ai/generate-text.base.action.ts +3 -0
- package/src/extensions/actions/ai/mcp.binding.ts +2 -0
- package/src/extensions/actions/ai/memory.binding.ts +2 -0
- package/src/extensions/actions/ai/retrieve-content-rag.action.ts +2 -0
- package/src/extensions/actions/messaging/list.action.ts +7 -0
- package/src/extensions/actions/subscriber/update-labels.action.ts +3 -0
- package/src/extensions/actions/web/http-request.action.ts +17 -1
- package/src/extensions/actions/workflow/call-workflow.action.ts +112 -0
- package/src/extensions/actions/workflow/i18n/en.translations.json +9 -0
- package/src/extensions/actions/workflow/i18n/fr.translations.json +9 -0
- package/src/extensions/index.ts +2 -0
- package/src/index.ts +2 -0
- package/src/mcp/README.md +277 -0
- package/src/mcp/controllers/mcp-token.controller.ts +64 -0
- package/src/mcp/decorators/mcp-permission.decorator.ts +23 -0
- package/src/mcp/dto/mcp-token.dto.ts +48 -0
- package/src/mcp/entities/mcp-token.entity.ts +60 -0
- package/src/mcp/guards/hexabot-mcp-token.guard.ts +55 -0
- package/src/mcp/guards/mcp-permission.guard.ts +61 -0
- package/src/mcp/mcp-api.module.ts +61 -0
- package/src/mcp/repositories/mcp-token.repository.ts +34 -0
- package/src/mcp/services/mcp-token.service.ts +138 -0
- package/src/mcp/tools/catalog-mcp.tools.ts +122 -0
- package/src/mcp/tools/cms-mcp.tools.ts +239 -0
- package/src/mcp/tools/credential-mcp.tools.ts +81 -0
- package/src/mcp/tools/hexabot-mcp-tool.base.ts +74 -0
- package/src/mcp/tools/hexabot-mcp.schemas.ts +55 -0
- package/src/mcp/tools/hexabot-mcp.tools.ts +7 -0
- package/src/mcp/tools/hexabot-mcp.utils.ts +29 -0
- package/src/mcp/tools/index.ts +51 -0
- package/src/mcp/tools/mcp-server-mcp.tools.ts +135 -0
- package/src/mcp/tools/memory-definition-mcp.tools.ts +125 -0
- package/src/mcp/tools/workflow-mcp.helper.ts +219 -0
- package/src/mcp/tools/workflow-mcp.tools.ts +271 -0
- package/src/mcp/tools/workflow-run-mcp.tools.ts +292 -0
- package/src/mcp/tools/workflow-version-mcp.tools.ts +459 -0
- package/src/mcp/types.ts +14 -0
- package/src/transfer/adapters/content-type-transfer.adapter.ts +154 -0
- package/src/transfer/adapters/credential-transfer.adapter.ts +158 -0
- package/src/transfer/adapters/label-transfer.adapter.ts +291 -0
- package/src/transfer/adapters/mcp-server-transfer.adapter.ts +255 -0
- package/src/transfer/adapters/memory-definition-transfer.adapter.ts +167 -0
- package/src/transfer/index.ts +19 -0
- package/src/transfer/workflow-transfer-adapter.registry.ts +250 -0
- package/src/transfer/workflow-transfer-definition.service.ts +587 -0
- package/src/transfer/workflow-transfer-resource-adapter.ts +132 -0
- package/src/transfer/workflow-transfer.controller.ts +86 -0
- package/src/transfer/workflow-transfer.module.ts +46 -0
- package/src/transfer/workflow-transfer.service.ts +858 -0
- package/src/transfer/workflow-transfer.types.ts +98 -0
- package/src/user/guards/ability.guard.ts +15 -3
- package/src/utils/test/fixtures/label.ts +0 -19
- package/src/utils/test/fixtures/workflow-run.ts +4 -1
- package/src/utils/test/port.ts +48 -0
- package/src/websocket/websocket.gateway.ts +2 -1
- package/src/workflow/contexts/workflow-runtime.context.ts +12 -1
- package/src/workflow/controllers/workflow-run.controller.ts +2 -0
- package/src/workflow/dto/workflow-run.dto.ts +10 -0
- package/src/workflow/entities/workflow-run.entity.ts +22 -1
- package/src/workflow/index.ts +14 -0
- package/src/workflow/repositories/workflow-run.repository.ts +7 -1
- package/src/workflow/resource-refs.ts +44 -0
- package/src/workflow/services/agentic.service.ts +271 -30
- package/src/workflow/services/workflow-run.service.ts +120 -7
- package/src/workflow/services/workflow-version.service.ts +33 -0
- package/src/workflow/services/workflow.service.ts +86 -31
- package/src/workflow/types.ts +52 -0
- package/src/workflow/workflow.module.ts +3 -0
- package/types/event-emitter.d.ts +12 -5
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { validateWorkflow } from '@hexabot-ai/agentic';
|
|
8
|
+
import {
|
|
9
|
+
Action,
|
|
10
|
+
type WorkflowVersion,
|
|
11
|
+
type WorkflowVersionFull,
|
|
12
|
+
} from '@hexabot-ai/types';
|
|
13
|
+
import {
|
|
14
|
+
BadRequestException,
|
|
15
|
+
Injectable,
|
|
16
|
+
NotFoundException,
|
|
17
|
+
} from '@nestjs/common';
|
|
18
|
+
import { Tool, ToolGuards } from '@rekog/mcp-nest';
|
|
19
|
+
import { z } from 'zod';
|
|
20
|
+
|
|
21
|
+
import { ActionService } from '@/actions/actions.service';
|
|
22
|
+
import { RuntimeBindingsService } from '@/bindings/runtime-bindings.service';
|
|
23
|
+
import { WorkflowVersionOrmEntity } from '@/workflow/entities/workflow-version.entity';
|
|
24
|
+
import { WorkflowVersionService } from '@/workflow/services/workflow-version.service';
|
|
25
|
+
import { WorkflowVersionAction } from '@/workflow/types';
|
|
26
|
+
|
|
27
|
+
import { McpPermission } from '../decorators/mcp-permission.decorator';
|
|
28
|
+
import { McpPermissionGuard } from '../guards/mcp-permission.guard';
|
|
29
|
+
import { HexabotMcpRequest } from '../types';
|
|
30
|
+
|
|
31
|
+
import { HexabotMcpToolBase } from './hexabot-mcp-tool.base';
|
|
32
|
+
import {
|
|
33
|
+
PaginationArgs,
|
|
34
|
+
paginationSchema,
|
|
35
|
+
uuidSchema,
|
|
36
|
+
} from './hexabot-mcp.schemas';
|
|
37
|
+
import { HexabotWorkflowMcpHelper } from './workflow-mcp.helper';
|
|
38
|
+
|
|
39
|
+
@Injectable()
|
|
40
|
+
export class HexabotWorkflowVersionMcpTools extends HexabotMcpToolBase {
|
|
41
|
+
constructor(
|
|
42
|
+
private readonly workflowVersionService: WorkflowVersionService,
|
|
43
|
+
private readonly actionService: ActionService,
|
|
44
|
+
private readonly runtimeBindingsService: RuntimeBindingsService,
|
|
45
|
+
private readonly workflowHelper: HexabotWorkflowMcpHelper,
|
|
46
|
+
) {
|
|
47
|
+
super();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@McpPermission('workflowversion', Action.CREATE)
|
|
51
|
+
@ToolGuards([McpPermissionGuard])
|
|
52
|
+
@Tool({
|
|
53
|
+
name: 'hexabot_workflow_yaml_commit',
|
|
54
|
+
description:
|
|
55
|
+
'Validate and commit workflow definition YAML as a new version.',
|
|
56
|
+
parameters: z.object({
|
|
57
|
+
workflowId: uuidSchema,
|
|
58
|
+
definitionYml: z.string().min(1),
|
|
59
|
+
message: z.string().optional(),
|
|
60
|
+
parentVersion: uuidSchema.nullable().optional(),
|
|
61
|
+
action: z
|
|
62
|
+
.enum(WorkflowVersionAction)
|
|
63
|
+
.default(WorkflowVersionAction.update),
|
|
64
|
+
}),
|
|
65
|
+
})
|
|
66
|
+
async commitWorkflowYaml(
|
|
67
|
+
args: {
|
|
68
|
+
workflowId: string;
|
|
69
|
+
definitionYml: string;
|
|
70
|
+
message?: string;
|
|
71
|
+
parentVersion?: string | null;
|
|
72
|
+
action: WorkflowVersionAction;
|
|
73
|
+
},
|
|
74
|
+
_context: unknown,
|
|
75
|
+
request?: HexabotMcpRequest,
|
|
76
|
+
) {
|
|
77
|
+
const actorId = this.getActorId(request);
|
|
78
|
+
const version = await this.workflowHelper.commitWorkflowDefinition({
|
|
79
|
+
...args,
|
|
80
|
+
createdBy: actorId,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return this.workflowHelper.summarizeWorkflowVersion(version, {
|
|
84
|
+
includeDefinitionYmlByteLength: true,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@McpPermission('workflow', Action.READ)
|
|
89
|
+
@ToolGuards([McpPermissionGuard])
|
|
90
|
+
@Tool({
|
|
91
|
+
name: 'hexabot_workflow_yaml_validate',
|
|
92
|
+
description:
|
|
93
|
+
'Validate workflow definition YAML without creating a workflow version.',
|
|
94
|
+
parameters: z.object({
|
|
95
|
+
definitionYml: z.string().min(1),
|
|
96
|
+
validateActions: z.boolean().default(true),
|
|
97
|
+
}),
|
|
98
|
+
})
|
|
99
|
+
async validateWorkflowYaml(args: {
|
|
100
|
+
definitionYml: string;
|
|
101
|
+
validateActions?: boolean;
|
|
102
|
+
}) {
|
|
103
|
+
const validateActions = args.validateActions ?? true;
|
|
104
|
+
const validation = validateWorkflow(args.definitionYml, {
|
|
105
|
+
bindingKinds: this.runtimeBindingsService.getRegistry(),
|
|
106
|
+
...(validateActions
|
|
107
|
+
? { actions: this.getWorkflowValidationActions() }
|
|
108
|
+
: {}),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (!validation.success) {
|
|
112
|
+
return { valid: false, errors: validation.errors };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { valid: true, errors: [], definition: validation.data };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@McpPermission('workflowversion', Action.READ)
|
|
119
|
+
@ToolGuards([McpPermissionGuard])
|
|
120
|
+
@Tool({
|
|
121
|
+
name: 'hexabot_workflow_version_search',
|
|
122
|
+
description:
|
|
123
|
+
'List compact workflow definition version metadata for a workflow, excluding YAML bodies.',
|
|
124
|
+
parameters: z.object({
|
|
125
|
+
workflowId: uuidSchema,
|
|
126
|
+
...paginationSchema,
|
|
127
|
+
sortBy: z.string().default('version'),
|
|
128
|
+
sortDirection: z.enum(['ASC', 'DESC']).default('DESC'),
|
|
129
|
+
}),
|
|
130
|
+
})
|
|
131
|
+
async searchWorkflowVersions(args: { workflowId: string } & PaginationArgs) {
|
|
132
|
+
const where = { workflow: { id: args.workflowId } } as any;
|
|
133
|
+
const result = await this.listWithCount(
|
|
134
|
+
this.workflowVersionService,
|
|
135
|
+
this.findOptions<WorkflowVersionOrmEntity>(args, where),
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
...result,
|
|
140
|
+
items: result.items.map((version) =>
|
|
141
|
+
this.workflowHelper.summarizeWorkflowVersion(
|
|
142
|
+
version as WorkflowVersion,
|
|
143
|
+
{ includeDefinitionYmlByteLength: true },
|
|
144
|
+
),
|
|
145
|
+
),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@McpPermission('workflowversion', Action.READ)
|
|
150
|
+
@ToolGuards([McpPermissionGuard])
|
|
151
|
+
@Tool({
|
|
152
|
+
name: 'hexabot_workflow_version_get',
|
|
153
|
+
description:
|
|
154
|
+
'Read compact workflow definition version metadata, excluding the YAML body.',
|
|
155
|
+
parameters: z.object({
|
|
156
|
+
id: uuidSchema,
|
|
157
|
+
workflowId: uuidSchema.optional(),
|
|
158
|
+
}),
|
|
159
|
+
})
|
|
160
|
+
async getWorkflowVersion(args: { id: string; workflowId?: string }) {
|
|
161
|
+
const version = await this.workflowVersionService.findOneAndPopulate({
|
|
162
|
+
where: {
|
|
163
|
+
id: args.id,
|
|
164
|
+
...(args.workflowId ? { workflow: { id: args.workflowId } } : {}),
|
|
165
|
+
} as any,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
if (!version) {
|
|
169
|
+
throw new NotFoundException(`Workflow version ${args.id} not found`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return this.workflowHelper.summarizeWorkflowVersion(version, {
|
|
173
|
+
includeDefinitionYmlByteLength: true,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@McpPermission('workflowversion', Action.READ)
|
|
178
|
+
@ToolGuards([McpPermissionGuard])
|
|
179
|
+
@Tool({
|
|
180
|
+
name: 'hexabot_workflow_yaml_get',
|
|
181
|
+
description:
|
|
182
|
+
'Read workflow definition YAML by workflowId/current version or versionId, with checksum, byte length, and UTF-8 byte offset/limit chunking.',
|
|
183
|
+
parameters: z.object({
|
|
184
|
+
workflowId: uuidSchema.optional(),
|
|
185
|
+
versionId: uuidSchema.optional(),
|
|
186
|
+
offset: z.number().int().min(0).default(0),
|
|
187
|
+
limit: z.number().int().min(1).max(64000).default(16000),
|
|
188
|
+
}),
|
|
189
|
+
})
|
|
190
|
+
async getWorkflowYaml(args: {
|
|
191
|
+
workflowId?: string;
|
|
192
|
+
versionId?: string;
|
|
193
|
+
offset?: number;
|
|
194
|
+
limit?: number;
|
|
195
|
+
}) {
|
|
196
|
+
const version = await this.requireWorkflowVersionForYaml(args);
|
|
197
|
+
const definitionYml = version.definitionYml;
|
|
198
|
+
const offset = args.offset ?? 0;
|
|
199
|
+
const limit = args.limit ?? 16000;
|
|
200
|
+
const { chunk, chunkByteLength, endOffset, totalByteLength } =
|
|
201
|
+
this.sliceUtf8Chunk(definitionYml, offset, limit);
|
|
202
|
+
const workflowId = this.resolveRelationId(version.workflow);
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
workflowId,
|
|
206
|
+
versionId: version.id,
|
|
207
|
+
version: version.version,
|
|
208
|
+
checksum: version.checksum,
|
|
209
|
+
definitionYmlByteLength: totalByteLength,
|
|
210
|
+
definitionYmlLength: definitionYml.length,
|
|
211
|
+
chunk: {
|
|
212
|
+
offset,
|
|
213
|
+
limit,
|
|
214
|
+
unit: 'utf8Bytes',
|
|
215
|
+
endOffset,
|
|
216
|
+
length: chunk.length,
|
|
217
|
+
byteLength: chunkByteLength,
|
|
218
|
+
hasMore: endOffset < totalByteLength,
|
|
219
|
+
nextOffset: endOffset < totalByteLength ? endOffset : null,
|
|
220
|
+
},
|
|
221
|
+
definitionYml: chunk,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@McpPermission('workflowversion', Action.UPDATE)
|
|
226
|
+
@ToolGuards([McpPermissionGuard])
|
|
227
|
+
@Tool({
|
|
228
|
+
name: 'hexabot_workflow_version_update',
|
|
229
|
+
description:
|
|
230
|
+
'Update workflow version metadata such as the version message.',
|
|
231
|
+
parameters: z.object({
|
|
232
|
+
id: uuidSchema,
|
|
233
|
+
message: z.string().nullable().optional(),
|
|
234
|
+
}),
|
|
235
|
+
})
|
|
236
|
+
async updateWorkflowVersion(args: { id: string; message?: string | null }) {
|
|
237
|
+
const version = await this.workflowVersionService.updateOne(args.id, {
|
|
238
|
+
message: args.message ?? undefined,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
return this.workflowHelper.summarizeWorkflowVersion(version, {
|
|
242
|
+
includeDefinitionYmlByteLength: true,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
@McpPermission('workflowversion', Action.CREATE)
|
|
247
|
+
@ToolGuards([McpPermissionGuard])
|
|
248
|
+
@Tool({
|
|
249
|
+
name: 'hexabot_workflow_version_restore',
|
|
250
|
+
description:
|
|
251
|
+
'Restore a workflow to a previous YAML version by creating a new restore snapshot.',
|
|
252
|
+
parameters: z.object({
|
|
253
|
+
workflowId: uuidSchema,
|
|
254
|
+
versionId: uuidSchema,
|
|
255
|
+
message: z.string().optional(),
|
|
256
|
+
}),
|
|
257
|
+
})
|
|
258
|
+
async restoreWorkflowVersion(
|
|
259
|
+
args: { workflowId: string; versionId: string; message?: string },
|
|
260
|
+
_context: unknown,
|
|
261
|
+
request?: HexabotMcpRequest,
|
|
262
|
+
) {
|
|
263
|
+
const version = await this.workflowHelper.restoreWorkflowVersionSnapshot(
|
|
264
|
+
args,
|
|
265
|
+
this.getActorId(request),
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
return this.workflowHelper.summarizeWorkflowVersion(version, {
|
|
269
|
+
includeDefinitionYmlByteLength: true,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
@McpPermission('workflowversion', Action.CREATE)
|
|
274
|
+
@ToolGuards([McpPermissionGuard])
|
|
275
|
+
@Tool({
|
|
276
|
+
name: 'hexabot_workflow_rollback',
|
|
277
|
+
description:
|
|
278
|
+
'Rollback a workflow to a previous YAML version by creating a new current restore snapshot.',
|
|
279
|
+
parameters: z.object({
|
|
280
|
+
workflowId: uuidSchema,
|
|
281
|
+
versionId: uuidSchema,
|
|
282
|
+
message: z.string().optional(),
|
|
283
|
+
}),
|
|
284
|
+
})
|
|
285
|
+
async rollbackWorkflowVersion(
|
|
286
|
+
args: { workflowId: string; versionId: string; message?: string },
|
|
287
|
+
_context: unknown,
|
|
288
|
+
request?: HexabotMcpRequest,
|
|
289
|
+
) {
|
|
290
|
+
const version = await this.workflowHelper.restoreWorkflowVersionSnapshot(
|
|
291
|
+
args,
|
|
292
|
+
this.getActorId(request),
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
return this.workflowHelper.summarizeWorkflowVersion(version, {
|
|
296
|
+
includeDefinitionYmlByteLength: true,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
private getWorkflowValidationActions() {
|
|
301
|
+
return Object.fromEntries(
|
|
302
|
+
Object.entries(this.actionService.getRegistry()).map(
|
|
303
|
+
([actionName, action]) => [
|
|
304
|
+
actionName,
|
|
305
|
+
{ supportedBindings: action.supportedBindings ?? [] },
|
|
306
|
+
],
|
|
307
|
+
),
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
private async requireWorkflowVersionForYaml(args: {
|
|
312
|
+
workflowId?: string;
|
|
313
|
+
versionId?: string;
|
|
314
|
+
}): Promise<WorkflowVersion | WorkflowVersionFull> {
|
|
315
|
+
if (!args.workflowId && !args.versionId) {
|
|
316
|
+
throw new BadRequestException(
|
|
317
|
+
'workflowId or versionId is required to read workflow YAML',
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (args.versionId) {
|
|
322
|
+
const version = await this.workflowVersionService.findOneAndPopulate({
|
|
323
|
+
where: {
|
|
324
|
+
id: args.versionId,
|
|
325
|
+
...(args.workflowId ? { workflow: { id: args.workflowId } } : {}),
|
|
326
|
+
} as any,
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
if (!version) {
|
|
330
|
+
throw new NotFoundException(
|
|
331
|
+
`Workflow version ${args.versionId} not found`,
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return version;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const workflowId = args.workflowId;
|
|
339
|
+
if (!workflowId) {
|
|
340
|
+
throw new BadRequestException(
|
|
341
|
+
'workflowId is required when versionId is not provided',
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
const workflow = await this.workflowHelper.requireWorkflow(workflowId);
|
|
345
|
+
const currentVersionId = this.resolveRelationId(workflow.currentVersion);
|
|
346
|
+
if (!currentVersionId) {
|
|
347
|
+
throw new NotFoundException(
|
|
348
|
+
`Workflow ${workflowId} has no current version`,
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const version = await this.workflowVersionService.findOneAndPopulate({
|
|
353
|
+
where: {
|
|
354
|
+
id: currentVersionId,
|
|
355
|
+
workflow: { id: workflowId },
|
|
356
|
+
} as any,
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
if (!version) {
|
|
360
|
+
throw new NotFoundException(
|
|
361
|
+
`Workflow version ${currentVersionId} not found`,
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return version;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private sliceUtf8Chunk(
|
|
369
|
+
value: string,
|
|
370
|
+
offset: number,
|
|
371
|
+
limit: number,
|
|
372
|
+
): {
|
|
373
|
+
chunk: string;
|
|
374
|
+
chunkByteLength: number;
|
|
375
|
+
endOffset: number;
|
|
376
|
+
totalByteLength: number;
|
|
377
|
+
} {
|
|
378
|
+
const totalByteLength = Buffer.byteLength(value, 'utf8');
|
|
379
|
+
if (offset > totalByteLength) {
|
|
380
|
+
throw new BadRequestException(
|
|
381
|
+
`Offset ${offset} exceeds workflow YAML byte length ${totalByteLength}`,
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const startIndex = this.findUtf8IndexForOffset(value, offset);
|
|
386
|
+
let endIndex = value.length;
|
|
387
|
+
let byteOffset = offset;
|
|
388
|
+
|
|
389
|
+
for (let index = startIndex; index < value.length; ) {
|
|
390
|
+
const char = this.readCodePoint(value, index);
|
|
391
|
+
const nextByteOffset = byteOffset + Buffer.byteLength(char, 'utf8');
|
|
392
|
+
|
|
393
|
+
if (nextByteOffset > offset + limit) {
|
|
394
|
+
if (index === startIndex) {
|
|
395
|
+
throw new BadRequestException(
|
|
396
|
+
`Limit ${limit} is too small to include the next UTF-8 character at offset ${offset}`,
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
endIndex = index;
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
byteOffset = nextByteOffset;
|
|
404
|
+
index += char.length;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const chunk = value.slice(startIndex, endIndex);
|
|
408
|
+
const chunkByteLength = Buffer.byteLength(chunk, 'utf8');
|
|
409
|
+
|
|
410
|
+
return {
|
|
411
|
+
chunk,
|
|
412
|
+
chunkByteLength,
|
|
413
|
+
endOffset: offset + chunkByteLength,
|
|
414
|
+
totalByteLength,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private findUtf8IndexForOffset(value: string, offset: number): number {
|
|
419
|
+
if (offset === 0) {
|
|
420
|
+
return 0;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
let byteOffset = 0;
|
|
424
|
+
for (let index = 0; index < value.length; ) {
|
|
425
|
+
const char = this.readCodePoint(value, index);
|
|
426
|
+
const nextByteOffset = byteOffset + Buffer.byteLength(char, 'utf8');
|
|
427
|
+
|
|
428
|
+
if (offset === nextByteOffset) {
|
|
429
|
+
return index + char.length;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (offset < nextByteOffset) {
|
|
433
|
+
throw new BadRequestException(
|
|
434
|
+
`Offset ${offset} is not aligned to a UTF-8 character boundary`,
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
byteOffset = nextByteOffset;
|
|
439
|
+
index += char.length;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (offset === byteOffset) {
|
|
443
|
+
return value.length;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
throw new BadRequestException(
|
|
447
|
+
`Offset ${offset} exceeds workflow YAML byte length ${byteOffset}`,
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
private readCodePoint(value: string, index: number): string {
|
|
452
|
+
const codePoint = value.codePointAt(index);
|
|
453
|
+
if (codePoint === undefined) {
|
|
454
|
+
return '';
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return String.fromCodePoint(codePoint);
|
|
458
|
+
}
|
|
459
|
+
}
|
package/src/mcp/types.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { User } from '@hexabot-ai/types';
|
|
8
|
+
import type { Request } from 'express';
|
|
9
|
+
|
|
10
|
+
export type HexabotMcpRequest = Request & {
|
|
11
|
+
user?: User;
|
|
12
|
+
hexabotUser?: User;
|
|
13
|
+
mcpTokenId?: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
type WorkflowExportBundle,
|
|
11
|
+
type WorkflowExportBundleContentType,
|
|
12
|
+
type WorkflowImportResourceResult,
|
|
13
|
+
} from '@hexabot-ai/types';
|
|
14
|
+
import { ConflictException, Injectable } from '@nestjs/common';
|
|
15
|
+
import { In } from 'typeorm';
|
|
16
|
+
|
|
17
|
+
import { ContentTypeOrmEntity } from '@/cms/entities/content-type.entity';
|
|
18
|
+
import { ContentTypeService } from '@/cms/services/content-type.service';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
WorkflowTransferAdapter,
|
|
22
|
+
WorkflowTransferExportContext,
|
|
23
|
+
WorkflowTransferImportContext,
|
|
24
|
+
WorkflowTransferResourceAdapter,
|
|
25
|
+
} from '../workflow-transfer-resource-adapter';
|
|
26
|
+
import {
|
|
27
|
+
assertFoundAll,
|
|
28
|
+
buildPostCreateEvent,
|
|
29
|
+
buildResourceResult,
|
|
30
|
+
uniqueResourceIds,
|
|
31
|
+
type WorkflowTransferImportAdapterResult,
|
|
32
|
+
} from '../workflow-transfer.types';
|
|
33
|
+
|
|
34
|
+
@WorkflowTransferAdapter()
|
|
35
|
+
@Injectable()
|
|
36
|
+
export class ContentTypeTransferAdapter extends WorkflowTransferResourceAdapter {
|
|
37
|
+
override readonly kind = 'contentType';
|
|
38
|
+
|
|
39
|
+
override readonly resourceKeys = ['contentTypes'];
|
|
40
|
+
|
|
41
|
+
constructor(private readonly contentTypeService: ContentTypeService) {
|
|
42
|
+
super();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override async buildExportResources(
|
|
46
|
+
ctx: WorkflowTransferExportContext,
|
|
47
|
+
): Promise<Record<string, WorkflowExportBundleContentType[]>> {
|
|
48
|
+
return {
|
|
49
|
+
contentTypes: await this.buildContentTypeExportResources(
|
|
50
|
+
ctx.getRefs(this.kind),
|
|
51
|
+
),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private async buildContentTypeExportResources(
|
|
56
|
+
ids: string[],
|
|
57
|
+
): Promise<WorkflowExportBundleContentType[]> {
|
|
58
|
+
const uniqueIds = uniqueResourceIds(ids);
|
|
59
|
+
if (uniqueIds.length === 0) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const contentTypes = await this.contentTypeService.find({
|
|
64
|
+
where: { id: In(uniqueIds) },
|
|
65
|
+
});
|
|
66
|
+
assertFoundAll(
|
|
67
|
+
'content type',
|
|
68
|
+
uniqueIds,
|
|
69
|
+
contentTypes.map((contentType) => contentType.id),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return contentTypes.map((contentType) => ({
|
|
73
|
+
exportId: contentType.id,
|
|
74
|
+
name: contentType.name,
|
|
75
|
+
schema: contentType.schema,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
override async importResources(
|
|
80
|
+
ctx: WorkflowTransferImportContext,
|
|
81
|
+
): Promise<WorkflowTransferImportAdapterResult> {
|
|
82
|
+
const contentTypes =
|
|
83
|
+
ctx.getResources<
|
|
84
|
+
WorkflowExportBundle['resources']['contentTypes'][number]
|
|
85
|
+
>('contentTypes');
|
|
86
|
+
const idMap: Record<string, string> = {};
|
|
87
|
+
const resources: WorkflowImportResourceResult[] = [];
|
|
88
|
+
const postCreateEvents: WorkflowTransferImportAdapterResult['postCreateEvents'] =
|
|
89
|
+
[];
|
|
90
|
+
|
|
91
|
+
for (const contentType of contentTypes) {
|
|
92
|
+
const existing = await ctx.manager.findOne(ContentTypeOrmEntity, {
|
|
93
|
+
where: { name: contentType.name },
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (existing) {
|
|
97
|
+
if (!this.isEquivalentContentType(existing, contentType)) {
|
|
98
|
+
throw new ConflictException(
|
|
99
|
+
`Content type "${contentType.name}" already exists with different configuration`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
idMap[contentType.exportId] = existing.id;
|
|
104
|
+
resources.push(
|
|
105
|
+
buildResourceResult({
|
|
106
|
+
kind: 'contentType',
|
|
107
|
+
exportId: contentType.exportId,
|
|
108
|
+
localId: existing.id,
|
|
109
|
+
name: contentType.name,
|
|
110
|
+
action: 'reused',
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const payload = {
|
|
117
|
+
name: contentType.name,
|
|
118
|
+
schema: contentType.schema,
|
|
119
|
+
};
|
|
120
|
+
const created = await ctx.manager.save(
|
|
121
|
+
ContentTypeOrmEntity,
|
|
122
|
+
ctx.manager.create(ContentTypeOrmEntity, payload),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
idMap[contentType.exportId] = created.id;
|
|
126
|
+
resources.push(
|
|
127
|
+
buildResourceResult({
|
|
128
|
+
kind: 'contentType',
|
|
129
|
+
exportId: contentType.exportId,
|
|
130
|
+
localId: created.id,
|
|
131
|
+
name: contentType.name,
|
|
132
|
+
action: 'created',
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
postCreateEvents.push(
|
|
136
|
+
buildPostCreateEvent('contentType', created, payload),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
idMap,
|
|
142
|
+
resources,
|
|
143
|
+
warnings: [],
|
|
144
|
+
postCreateEvents,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private isEquivalentContentType(
|
|
149
|
+
existing: ContentTypeOrmEntity,
|
|
150
|
+
imported: WorkflowExportBundle['resources']['contentTypes'][number],
|
|
151
|
+
): boolean {
|
|
152
|
+
return isDeepStrictEqual(existing.schema, imported.schema);
|
|
153
|
+
}
|
|
154
|
+
}
|