@ajna-inc/workflow 0.5.37 → 0.6.1
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/.npmvc/attestations.jsonld +32 -0
- package/LICENSE +202 -0
- package/build/WorkflowEvents.d.mts +40 -0
- package/build/WorkflowEvents.d.mts.map +1 -0
- package/build/WorkflowEvents.mjs +11 -0
- package/build/WorkflowEvents.mjs.map +1 -0
- package/build/WorkflowModule.d.mts +17 -0
- package/build/WorkflowModule.d.mts.map +1 -0
- package/build/WorkflowModule.mjs +446 -0
- package/build/WorkflowModule.mjs.map +1 -0
- package/build/WorkflowModuleConfig.d.mts +39 -0
- package/build/WorkflowModuleConfig.d.mts.map +1 -0
- package/build/WorkflowModuleConfig.mjs +19 -0
- package/build/WorkflowModuleConfig.mjs.map +1 -0
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs +14 -0
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs +11 -0
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateParam.mjs +9 -0
- package/build/_virtual/rolldown_runtime.mjs +41 -0
- package/build/actions/ActionRegistry.d.mts +64 -0
- package/build/actions/ActionRegistry.d.mts.map +1 -0
- package/build/actions/ActionRegistry.mjs +304 -0
- package/build/actions/ActionRegistry.mjs.map +1 -0
- package/build/api/WorkflowApi.d.mts +99 -0
- package/build/api/WorkflowApi.d.mts.map +1 -0
- package/build/api/WorkflowApi.mjs +228 -0
- package/build/api/WorkflowApi.mjs.map +1 -0
- package/build/engine/AttributePlanner.d.mts +12 -0
- package/build/engine/AttributePlanner.d.mts.map +1 -0
- package/build/engine/AttributePlanner.mjs +58 -0
- package/build/engine/AttributePlanner.mjs.map +1 -0
- package/build/engine/GuardEvaluator.d.mts +16 -0
- package/build/engine/GuardEvaluator.d.mts.map +1 -0
- package/build/engine/GuardEvaluator.mjs +38 -0
- package/build/engine/GuardEvaluator.mjs.map +1 -0
- package/build/index.d.mts +46 -0
- package/build/index.mjs +53 -0
- package/build/index.mjs.map +1 -0
- package/build/model/TemplateValidation.d.mts +8 -0
- package/build/model/TemplateValidation.d.mts.map +1 -0
- package/build/model/TemplateValidation.mjs +278 -0
- package/build/model/TemplateValidation.mjs.map +1 -0
- package/build/model/types.d.mts +120 -0
- package/build/model/types.d.mts.map +1 -0
- package/build/model/types.mjs +11 -0
- package/build/model/types.mjs.map +1 -0
- package/build/protocol/WorkflowMessageTypes.d.mts +19 -0
- package/build/protocol/WorkflowMessageTypes.d.mts.map +1 -0
- package/build/protocol/WorkflowMessageTypes.mjs +20 -0
- package/build/protocol/WorkflowMessageTypes.mjs.map +1 -0
- package/build/protocol/handlers/AdvanceHandler.d.mts +16 -0
- package/build/protocol/handlers/AdvanceHandler.d.mts.map +1 -0
- package/build/protocol/handlers/AdvanceHandler.mjs +148 -0
- package/build/protocol/handlers/AdvanceHandler.mjs.map +1 -0
- package/build/protocol/handlers/CancelHandler.d.mts +16 -0
- package/build/protocol/handlers/CancelHandler.d.mts.map +1 -0
- package/build/protocol/handlers/CancelHandler.mjs +103 -0
- package/build/protocol/handlers/CancelHandler.mjs.map +1 -0
- package/build/protocol/handlers/CompleteHandler.d.mts +16 -0
- package/build/protocol/handlers/CompleteHandler.d.mts.map +1 -0
- package/build/protocol/handlers/CompleteHandler.mjs +103 -0
- package/build/protocol/handlers/CompleteHandler.mjs.map +1 -0
- package/build/protocol/handlers/DiscoverHandler.d.mts +15 -0
- package/build/protocol/handlers/DiscoverHandler.d.mts.map +1 -0
- package/build/protocol/handlers/DiscoverHandler.mjs +73 -0
- package/build/protocol/handlers/DiscoverHandler.mjs.map +1 -0
- package/build/protocol/handlers/FetchTemplateHandler.d.mts +16 -0
- package/build/protocol/handlers/FetchTemplateHandler.d.mts.map +1 -0
- package/build/protocol/handlers/FetchTemplateHandler.mjs +64 -0
- package/build/protocol/handlers/FetchTemplateHandler.mjs.map +1 -0
- package/build/protocol/handlers/PauseHandler.d.mts +16 -0
- package/build/protocol/handlers/PauseHandler.d.mts.map +1 -0
- package/build/protocol/handlers/PauseHandler.mjs +103 -0
- package/build/protocol/handlers/PauseHandler.mjs.map +1 -0
- package/build/protocol/handlers/ProblemReportHandler.d.mts +11 -0
- package/build/protocol/handlers/ProblemReportHandler.d.mts.map +1 -0
- package/build/protocol/handlers/ProblemReportHandler.mjs +26 -0
- package/build/protocol/handlers/ProblemReportHandler.mjs.map +1 -0
- package/build/protocol/handlers/PublishTemplateHandler.d.mts +15 -0
- package/build/protocol/handlers/PublishTemplateHandler.d.mts.map +1 -0
- package/build/protocol/handlers/PublishTemplateHandler.mjs +47 -0
- package/build/protocol/handlers/PublishTemplateHandler.mjs.map +1 -0
- package/build/protocol/handlers/ResumeHandler.d.mts +16 -0
- package/build/protocol/handlers/ResumeHandler.d.mts.map +1 -0
- package/build/protocol/handlers/ResumeHandler.mjs +103 -0
- package/build/protocol/handlers/ResumeHandler.mjs.map +1 -0
- package/build/protocol/handlers/StartHandler.d.mts +16 -0
- package/build/protocol/handlers/StartHandler.d.mts.map +1 -0
- package/build/protocol/handlers/StartHandler.mjs +238 -0
- package/build/protocol/handlers/StartHandler.mjs.map +1 -0
- package/build/protocol/handlers/StatusHandler.d.mts +16 -0
- package/build/protocol/handlers/StatusHandler.d.mts.map +1 -0
- package/build/protocol/handlers/StatusHandler.mjs +169 -0
- package/build/protocol/handlers/StatusHandler.mjs.map +1 -0
- package/build/protocol/handlers/TemplateHandler.d.mts +14 -0
- package/build/protocol/handlers/TemplateHandler.d.mts.map +1 -0
- package/build/protocol/handlers/TemplateHandler.mjs +66 -0
- package/build/protocol/handlers/TemplateHandler.mjs.map +1 -0
- package/build/protocol/messages/AdvanceMessage.d.mts +22 -0
- package/build/protocol/messages/AdvanceMessage.d.mts.map +1 -0
- package/build/protocol/messages/AdvanceMessage.mjs +25 -0
- package/build/protocol/messages/AdvanceMessage.mjs.map +1 -0
- package/build/protocol/messages/CancelMessage.d.mts +20 -0
- package/build/protocol/messages/CancelMessage.d.mts.map +1 -0
- package/build/protocol/messages/CancelMessage.mjs +25 -0
- package/build/protocol/messages/CancelMessage.mjs.map +1 -0
- package/build/protocol/messages/CompleteMessage.d.mts +20 -0
- package/build/protocol/messages/CompleteMessage.d.mts.map +1 -0
- package/build/protocol/messages/CompleteMessage.mjs +25 -0
- package/build/protocol/messages/CompleteMessage.mjs.map +1 -0
- package/build/protocol/messages/DiscoverMessage.d.mts +29 -0
- package/build/protocol/messages/DiscoverMessage.d.mts.map +1 -0
- package/build/protocol/messages/DiscoverMessage.mjs +25 -0
- package/build/protocol/messages/DiscoverMessage.mjs.map +1 -0
- package/build/protocol/messages/FetchTemplateMessage.d.mts +21 -0
- package/build/protocol/messages/FetchTemplateMessage.d.mts.map +1 -0
- package/build/protocol/messages/FetchTemplateMessage.mjs +31 -0
- package/build/protocol/messages/FetchTemplateMessage.mjs.map +1 -0
- package/build/protocol/messages/PauseMessage.d.mts +20 -0
- package/build/protocol/messages/PauseMessage.d.mts.map +1 -0
- package/build/protocol/messages/PauseMessage.mjs +25 -0
- package/build/protocol/messages/PauseMessage.mjs.map +1 -0
- package/build/protocol/messages/ProblemReportMessage.d.mts +21 -0
- package/build/protocol/messages/ProblemReportMessage.d.mts.map +1 -0
- package/build/protocol/messages/ProblemReportMessage.mjs +25 -0
- package/build/protocol/messages/ProblemReportMessage.mjs.map +1 -0
- package/build/protocol/messages/PublishTemplateMessage.d.mts +23 -0
- package/build/protocol/messages/PublishTemplateMessage.d.mts.map +1 -0
- package/build/protocol/messages/PublishTemplateMessage.mjs +24 -0
- package/build/protocol/messages/PublishTemplateMessage.mjs.map +1 -0
- package/build/protocol/messages/ResumeMessage.d.mts +20 -0
- package/build/protocol/messages/ResumeMessage.d.mts.map +1 -0
- package/build/protocol/messages/ResumeMessage.mjs +25 -0
- package/build/protocol/messages/ResumeMessage.mjs.map +1 -0
- package/build/protocol/messages/StartMessage.d.mts +27 -0
- package/build/protocol/messages/StartMessage.d.mts.map +1 -0
- package/build/protocol/messages/StartMessage.mjs +25 -0
- package/build/protocol/messages/StartMessage.mjs.map +1 -0
- package/build/protocol/messages/StatusMessage.d.mts +35 -0
- package/build/protocol/messages/StatusMessage.d.mts.map +1 -0
- package/build/protocol/messages/StatusMessage.mjs +25 -0
- package/build/protocol/messages/StatusMessage.mjs.map +1 -0
- package/build/protocol/messages/StatusRequestMessage.d.mts +29 -0
- package/build/protocol/messages/StatusRequestMessage.d.mts.map +1 -0
- package/build/protocol/messages/StatusRequestMessage.mjs +25 -0
- package/build/protocol/messages/StatusRequestMessage.mjs.map +1 -0
- package/build/protocol/messages/TemplateMessage.d.mts +20 -0
- package/build/protocol/messages/TemplateMessage.d.mts.map +1 -0
- package/build/protocol/messages/TemplateMessage.mjs +25 -0
- package/build/protocol/messages/TemplateMessage.mjs.map +1 -0
- package/build/protocol/messages/WorkflowsMessage.d.mts +28 -0
- package/build/protocol/messages/WorkflowsMessage.d.mts.map +1 -0
- package/build/protocol/messages/WorkflowsMessage.mjs +25 -0
- package/build/protocol/messages/WorkflowsMessage.mjs.map +1 -0
- package/build/queue/CommandQueue.d.mts +22 -0
- package/build/queue/CommandQueue.d.mts.map +1 -0
- package/build/queue/CommandQueue.mjs +6 -0
- package/build/queue/CommandQueue.mjs.map +1 -0
- package/build/queue/PersistentCommandQueue.d.mts +56 -0
- package/build/queue/PersistentCommandQueue.d.mts.map +1 -0
- package/build/queue/PersistentCommandQueue.mjs +273 -0
- package/build/queue/PersistentCommandQueue.mjs.map +1 -0
- package/build/repository/WorkflowCommandRecord.d.mts +50 -0
- package/build/repository/WorkflowCommandRecord.d.mts.map +1 -0
- package/build/repository/WorkflowCommandRecord.mjs +48 -0
- package/build/repository/WorkflowCommandRecord.mjs.map +1 -0
- package/build/repository/WorkflowCommandRepository.d.mts +59 -0
- package/build/repository/WorkflowCommandRepository.d.mts.map +1 -0
- package/build/repository/WorkflowCommandRepository.mjs +136 -0
- package/build/repository/WorkflowCommandRepository.mjs.map +1 -0
- package/build/repository/WorkflowInstanceRecord.d.mts +65 -0
- package/build/repository/WorkflowInstanceRecord.d.mts.map +1 -0
- package/build/repository/WorkflowInstanceRecord.mjs +44 -0
- package/build/repository/WorkflowInstanceRecord.mjs.map +1 -0
- package/build/repository/WorkflowInstanceRepository.d.mts +15 -0
- package/build/repository/WorkflowInstanceRepository.d.mts.map +1 -0
- package/build/repository/WorkflowInstanceRepository.mjs +48 -0
- package/build/repository/WorkflowInstanceRepository.mjs.map +1 -0
- package/build/repository/WorkflowTemplateRecord.d.mts +27 -0
- package/build/repository/WorkflowTemplateRecord.d.mts.map +1 -0
- package/build/repository/WorkflowTemplateRecord.mjs +29 -0
- package/build/repository/WorkflowTemplateRecord.mjs.map +1 -0
- package/build/repository/WorkflowTemplateRepository.d.mts +11 -0
- package/build/repository/WorkflowTemplateRepository.d.mts.map +1 -0
- package/build/repository/WorkflowTemplateRepository.mjs +43 -0
- package/build/repository/WorkflowTemplateRepository.mjs.map +1 -0
- package/build/services/WorkflowService.d.mts +107 -0
- package/build/services/WorkflowService.d.mts.map +1 -0
- package/build/services/WorkflowService.mjs +582 -0
- package/build/services/WorkflowService.mjs.map +1 -0
- package/build/ui/UiFilter.mjs +85 -0
- package/build/ui/UiFilter.mjs.map +1 -0
- package/package.json +27 -33
- package/build/WorkflowEvents.d.ts +0 -35
- package/build/WorkflowEvents.js +0 -10
- package/build/WorkflowEvents.js.map +0 -1
- package/build/WorkflowModule.d.ts +0 -13
- package/build/WorkflowModule.js +0 -647
- package/build/WorkflowModule.js.map +0 -1
- package/build/WorkflowModuleConfig.d.ts +0 -35
- package/build/WorkflowModuleConfig.js +0 -19
- package/build/WorkflowModuleConfig.js.map +0 -1
- package/build/actions/ActionRegistry.d.ts +0 -59
- package/build/actions/ActionRegistry.js +0 -367
- package/build/actions/ActionRegistry.js.map +0 -1
- package/build/api/WorkflowApi.d.ts +0 -94
- package/build/api/WorkflowApi.js +0 -241
- package/build/api/WorkflowApi.js.map +0 -1
- package/build/engine/AttributePlanner.d.ts +0 -7
- package/build/engine/AttributePlanner.js +0 -81
- package/build/engine/AttributePlanner.js.map +0 -1
- package/build/engine/GuardEvaluator.d.ts +0 -11
- package/build/engine/GuardEvaluator.js +0 -40
- package/build/engine/GuardEvaluator.js.map +0 -1
- package/build/index.d.ts +0 -45
- package/build/index.js +0 -69
- package/build/index.js.map +0 -1
- package/build/model/TemplateValidation.d.ts +0 -3
- package/build/model/TemplateValidation.js +0 -231
- package/build/model/TemplateValidation.js.map +0 -1
- package/build/model/types.d.ts +0 -116
- package/build/model/types.js +0 -15
- package/build/model/types.js.map +0 -1
- package/build/protocol/WorkflowMessageTypes.d.ts +0 -15
- package/build/protocol/WorkflowMessageTypes.js +0 -22
- package/build/protocol/WorkflowMessageTypes.js.map +0 -1
- package/build/protocol/handlers/AdvanceHandler.d.ts +0 -12
- package/build/protocol/handlers/AdvanceHandler.js +0 -149
- package/build/protocol/handlers/AdvanceHandler.js.map +0 -1
- package/build/protocol/handlers/CancelHandler.d.ts +0 -12
- package/build/protocol/handlers/CancelHandler.js +0 -124
- package/build/protocol/handlers/CancelHandler.js.map +0 -1
- package/build/protocol/handlers/CompleteHandler.d.ts +0 -12
- package/build/protocol/handlers/CompleteHandler.js +0 -125
- package/build/protocol/handlers/CompleteHandler.js.map +0 -1
- package/build/protocol/handlers/DiscoverHandler.d.ts +0 -11
- package/build/protocol/handlers/DiscoverHandler.js +0 -71
- package/build/protocol/handlers/DiscoverHandler.js.map +0 -1
- package/build/protocol/handlers/FetchTemplateHandler.d.ts +0 -12
- package/build/protocol/handlers/FetchTemplateHandler.js +0 -71
- package/build/protocol/handlers/FetchTemplateHandler.js.map +0 -1
- package/build/protocol/handlers/PauseHandler.d.ts +0 -12
- package/build/protocol/handlers/PauseHandler.js +0 -124
- package/build/protocol/handlers/PauseHandler.js.map +0 -1
- package/build/protocol/handlers/ProblemReportHandler.d.ts +0 -6
- package/build/protocol/handlers/ProblemReportHandler.js +0 -28
- package/build/protocol/handlers/ProblemReportHandler.js.map +0 -1
- package/build/protocol/handlers/PublishTemplateHandler.d.ts +0 -11
- package/build/protocol/handlers/PublishTemplateHandler.js +0 -53
- package/build/protocol/handlers/PublishTemplateHandler.js.map +0 -1
- package/build/protocol/handlers/ResumeHandler.d.ts +0 -12
- package/build/protocol/handlers/ResumeHandler.js +0 -124
- package/build/protocol/handlers/ResumeHandler.js.map +0 -1
- package/build/protocol/handlers/StartHandler.d.ts +0 -12
- package/build/protocol/handlers/StartHandler.js +0 -274
- package/build/protocol/handlers/StartHandler.js.map +0 -1
- package/build/protocol/handlers/StatusHandler.d.ts +0 -12
- package/build/protocol/handlers/StatusHandler.js +0 -202
- package/build/protocol/handlers/StatusHandler.js.map +0 -1
- package/build/protocol/handlers/TemplateHandler.d.ts +0 -9
- package/build/protocol/handlers/TemplateHandler.js +0 -83
- package/build/protocol/handlers/TemplateHandler.js.map +0 -1
- package/build/protocol/messages/AdvanceMessage.d.ts +0 -16
- package/build/protocol/messages/AdvanceMessage.js +0 -33
- package/build/protocol/messages/AdvanceMessage.js.map +0 -1
- package/build/protocol/messages/CancelMessage.d.ts +0 -14
- package/build/protocol/messages/CancelMessage.js +0 -33
- package/build/protocol/messages/CancelMessage.js.map +0 -1
- package/build/protocol/messages/CompleteMessage.d.ts +0 -14
- package/build/protocol/messages/CompleteMessage.js +0 -33
- package/build/protocol/messages/CompleteMessage.js.map +0 -1
- package/build/protocol/messages/DiscoverMessage.d.ts +0 -23
- package/build/protocol/messages/DiscoverMessage.js +0 -33
- package/build/protocol/messages/DiscoverMessage.js.map +0 -1
- package/build/protocol/messages/FetchTemplateMessage.d.ts +0 -15
- package/build/protocol/messages/FetchTemplateMessage.js +0 -33
- package/build/protocol/messages/FetchTemplateMessage.js.map +0 -1
- package/build/protocol/messages/PauseMessage.d.ts +0 -14
- package/build/protocol/messages/PauseMessage.js +0 -33
- package/build/protocol/messages/PauseMessage.js.map +0 -1
- package/build/protocol/messages/ProblemReportMessage.d.ts +0 -15
- package/build/protocol/messages/ProblemReportMessage.js +0 -33
- package/build/protocol/messages/ProblemReportMessage.js.map +0 -1
- package/build/protocol/messages/PublishTemplateMessage.d.ts +0 -17
- package/build/protocol/messages/PublishTemplateMessage.js +0 -31
- package/build/protocol/messages/PublishTemplateMessage.js.map +0 -1
- package/build/protocol/messages/ResumeMessage.d.ts +0 -14
- package/build/protocol/messages/ResumeMessage.js +0 -33
- package/build/protocol/messages/ResumeMessage.js.map +0 -1
- package/build/protocol/messages/StartMessage.d.ts +0 -21
- package/build/protocol/messages/StartMessage.js +0 -33
- package/build/protocol/messages/StartMessage.js.map +0 -1
- package/build/protocol/messages/StatusMessage.d.ts +0 -29
- package/build/protocol/messages/StatusMessage.js +0 -33
- package/build/protocol/messages/StatusMessage.js.map +0 -1
- package/build/protocol/messages/StatusRequestMessage.d.ts +0 -23
- package/build/protocol/messages/StatusRequestMessage.js +0 -33
- package/build/protocol/messages/StatusRequestMessage.js.map +0 -1
- package/build/protocol/messages/TemplateMessage.d.ts +0 -14
- package/build/protocol/messages/TemplateMessage.js +0 -33
- package/build/protocol/messages/TemplateMessage.js.map +0 -1
- package/build/protocol/messages/WorkflowsMessage.d.ts +0 -22
- package/build/protocol/messages/WorkflowsMessage.js +0 -33
- package/build/protocol/messages/WorkflowsMessage.js.map +0 -1
- package/build/queue/CommandQueue.d.ts +0 -18
- package/build/queue/CommandQueue.js +0 -8
- package/build/queue/CommandQueue.js.map +0 -1
- package/build/queue/PersistentCommandQueue.d.ts +0 -51
- package/build/queue/PersistentCommandQueue.js +0 -348
- package/build/queue/PersistentCommandQueue.js.map +0 -1
- package/build/repository/WorkflowCommandRecord.d.ts +0 -46
- package/build/repository/WorkflowCommandRecord.js +0 -52
- package/build/repository/WorkflowCommandRecord.js.map +0 -1
- package/build/repository/WorkflowCommandRepository.d.ts +0 -55
- package/build/repository/WorkflowCommandRepository.js +0 -149
- package/build/repository/WorkflowCommandRepository.js.map +0 -1
- package/build/repository/WorkflowInstanceRecord.d.ts +0 -61
- package/build/repository/WorkflowInstanceRecord.js +0 -43
- package/build/repository/WorkflowInstanceRecord.js.map +0 -1
- package/build/repository/WorkflowInstanceRepository.d.ts +0 -10
- package/build/repository/WorkflowInstanceRepository.js +0 -52
- package/build/repository/WorkflowInstanceRepository.js.map +0 -1
- package/build/repository/WorkflowTemplateRecord.d.ts +0 -23
- package/build/repository/WorkflowTemplateRecord.js +0 -28
- package/build/repository/WorkflowTemplateRecord.js.map +0 -1
- package/build/repository/WorkflowTemplateRepository.d.ts +0 -6
- package/build/repository/WorkflowTemplateRepository.js +0 -56
- package/build/repository/WorkflowTemplateRepository.js.map +0 -1
- package/build/services/WorkflowService.d.ts +0 -102
- package/build/services/WorkflowService.js +0 -704
- package/build/services/WorkflowService.js.map +0 -1
- package/build/ui/UiFilter.d.ts +0 -5
- package/build/ui/UiFilter.js +0 -104
- package/build/ui/UiFilter.js.map +0 -1
- package/build/ui/UiTypes.d.ts +0 -28
- package/build/ui/UiTypes.js +0 -3
- package/build/ui/UiTypes.js.map +0 -1
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { __toCommonJS } from "../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { WorkflowModuleConfig } from "../WorkflowModuleConfig.mjs";
|
|
3
|
+
import { __decorateMetadata, init_decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
4
|
+
import { __decorate, init_decorate } from "../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
5
|
+
import { WorkflowInstanceRecord } from "../repository/WorkflowInstanceRecord.mjs";
|
|
6
|
+
import { WorkflowInstanceRepository } from "../repository/WorkflowInstanceRepository.mjs";
|
|
7
|
+
import { WorkflowTemplateRecord } from "../repository/WorkflowTemplateRecord.mjs";
|
|
8
|
+
import { WorkflowTemplateRepository } from "../repository/WorkflowTemplateRepository.mjs";
|
|
9
|
+
import { WorkflowEventTypes } from "../WorkflowEvents.mjs";
|
|
10
|
+
import { ActionRegistry, IssueCredentialMessageV2Action, IssueCredentialV2Action, LocalStateSetAction, PresentProofV2Action, ProposeCredentialV2Action, RequestCredentialV2Action } from "../actions/ActionRegistry.mjs";
|
|
11
|
+
import { GuardEvaluator, init_GuardEvaluator } from "../engine/GuardEvaluator.mjs";
|
|
12
|
+
import { validateTemplateJson, validateTemplateRefs } from "../model/TemplateValidation.mjs";
|
|
13
|
+
import { ensureArray, findSectionForState, transitionsFromState } from "../model/types.mjs";
|
|
14
|
+
import { CompleteMessage } from "../protocol/messages/CompleteMessage.mjs";
|
|
15
|
+
import { UiFilter_exports, init_UiFilter } from "../ui/UiFilter.mjs";
|
|
16
|
+
import { AgentConfig, AgentContext, EventEmitter, Hasher, TypedArrayEncoder, injectable } from "@credo-ts/core";
|
|
17
|
+
import { DidCommConnectionService, DidCommMessageSender, DidCommOutboundMessageContext, ReturnRouteTypes } from "@credo-ts/didcomm";
|
|
18
|
+
|
|
19
|
+
//#region src/services/WorkflowService.ts
|
|
20
|
+
init_GuardEvaluator();
|
|
21
|
+
init_decorateMetadata();
|
|
22
|
+
init_decorate();
|
|
23
|
+
var _ref, _ref2, _ref3, _ref4, _ref5;
|
|
24
|
+
const stableStringify = (obj) => {
|
|
25
|
+
const allKeys = [];
|
|
26
|
+
JSON.stringify(obj, (k, v) => {
|
|
27
|
+
allKeys.push(k);
|
|
28
|
+
return v;
|
|
29
|
+
});
|
|
30
|
+
allKeys.sort();
|
|
31
|
+
return JSON.stringify(obj, allKeys);
|
|
32
|
+
};
|
|
33
|
+
const sha256 = (input) => {
|
|
34
|
+
const hash = Hasher.hash(TypedArrayEncoder.fromString(input), "sha-256");
|
|
35
|
+
return TypedArrayEncoder.toHex(hash);
|
|
36
|
+
};
|
|
37
|
+
let WorkflowService = class WorkflowService$1 {
|
|
38
|
+
constructor(templateRepo, instanceRepo, config, agentConfig, eventEmitter) {
|
|
39
|
+
this.templateRepo = templateRepo;
|
|
40
|
+
this.instanceRepo = instanceRepo;
|
|
41
|
+
this.config = config;
|
|
42
|
+
this.agentConfig = agentConfig;
|
|
43
|
+
this.eventEmitter = eventEmitter;
|
|
44
|
+
this.actions = new ActionRegistry();
|
|
45
|
+
this.actions.register(new LocalStateSetAction());
|
|
46
|
+
this.actions.register(new ProposeCredentialV2Action());
|
|
47
|
+
this.actions.register(new IssueCredentialV2Action());
|
|
48
|
+
this.actions.register(new RequestCredentialV2Action());
|
|
49
|
+
this.actions.register(new IssueCredentialMessageV2Action());
|
|
50
|
+
this.actions.register(new PresentProofV2Action());
|
|
51
|
+
}
|
|
52
|
+
registerActions(actions) {
|
|
53
|
+
for (const a of actions) this.actions.register(a);
|
|
54
|
+
}
|
|
55
|
+
async publishTemplate(agentContext, template) {
|
|
56
|
+
validateTemplateJson(template);
|
|
57
|
+
validateTemplateRefs(template);
|
|
58
|
+
const hash = sha256(stableStringify(template));
|
|
59
|
+
const existing = await this.templateRepo.findByTemplateIdAndVersion(agentContext, template.template_id, template.version);
|
|
60
|
+
if (existing) {
|
|
61
|
+
existing.template = template;
|
|
62
|
+
existing.hash = hash;
|
|
63
|
+
await this.templateRepo.update(agentContext, existing);
|
|
64
|
+
return existing;
|
|
65
|
+
}
|
|
66
|
+
const record = new WorkflowTemplateRecord({
|
|
67
|
+
template,
|
|
68
|
+
hash
|
|
69
|
+
});
|
|
70
|
+
await this.templateRepo.save(agentContext, record);
|
|
71
|
+
return record;
|
|
72
|
+
}
|
|
73
|
+
async start(agentContext, opts) {
|
|
74
|
+
if (opts.instance_id) try {
|
|
75
|
+
const existingByInstance = await this.instanceRepo.getByInstanceId(agentContext, opts.instance_id);
|
|
76
|
+
if (existingByInstance) return existingByInstance;
|
|
77
|
+
} catch {}
|
|
78
|
+
const tplRec = await this.templateRepo.findByTemplateIdAndVersion(agentContext, opts.template_id, opts.template_version);
|
|
79
|
+
if (!tplRec) throw this.problem("invalid_template", `template not found: ${opts.template_id}@${opts.template_version || "latest"}`);
|
|
80
|
+
const tpl = tplRec.template;
|
|
81
|
+
const startState = tpl.states.find((s) => s.type === "start")?.name || tpl.states[0]?.name;
|
|
82
|
+
if (!startState) throw this.problem("invalid_template", "no start state");
|
|
83
|
+
const policy = tpl.instance_policy;
|
|
84
|
+
const connectionId = opts.connection_id;
|
|
85
|
+
if (policy.mode === "singleton_per_connection") {
|
|
86
|
+
const existing = ensureArray(await this.instanceRepo.findByTemplateAndConnection(agentContext, tpl.template_id, connectionId)).shift();
|
|
87
|
+
if (existing) {
|
|
88
|
+
if (this.config.autoReturnExistingOnSingleton) return existing;
|
|
89
|
+
throw this.problem("already_exists", "instance already exists for template/connection");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
let multiplicityKeyValue;
|
|
93
|
+
if (policy.mode === "multi_per_connection" && policy.multiplicity_key) {
|
|
94
|
+
multiplicityKeyValue = this.evalMultiplicity(policy.multiplicity_key, opts.context || {});
|
|
95
|
+
const dup = ensureArray(await this.instanceRepo.findByTemplateConnAndMultiplicity(agentContext, tpl.template_id, connectionId, multiplicityKeyValue)).shift();
|
|
96
|
+
if (dup) return dup;
|
|
97
|
+
}
|
|
98
|
+
let participants = opts.participants || {};
|
|
99
|
+
try {
|
|
100
|
+
if (connectionId) {
|
|
101
|
+
const conn = await agentContext.dependencyManager.resolve(DidCommConnectionService).getById(agentContext, connectionId);
|
|
102
|
+
const theirDid = conn?.theirDid;
|
|
103
|
+
const myDid = conn?.did || conn?.myDid;
|
|
104
|
+
if (theirDid) {
|
|
105
|
+
const holder = participants.holder || {};
|
|
106
|
+
if (!holder.did) holder.did = theirDid;
|
|
107
|
+
participants.holder = holder;
|
|
108
|
+
}
|
|
109
|
+
if (myDid) {
|
|
110
|
+
const issuer = participants.issuer || {};
|
|
111
|
+
if (!issuer.did) issuer.did = myDid;
|
|
112
|
+
participants.issuer = issuer;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} catch {}
|
|
116
|
+
const instanceId = opts.instance_id || this.uuid();
|
|
117
|
+
const section = findSectionForState(tpl, startState);
|
|
118
|
+
const rec = new WorkflowInstanceRecord({
|
|
119
|
+
instanceId,
|
|
120
|
+
templateId: tpl.template_id,
|
|
121
|
+
templateVersion: tpl.version,
|
|
122
|
+
connectionId,
|
|
123
|
+
participants,
|
|
124
|
+
state: startState,
|
|
125
|
+
section,
|
|
126
|
+
context: { ...opts.context || {} },
|
|
127
|
+
artifacts: {},
|
|
128
|
+
status: "active",
|
|
129
|
+
history: [],
|
|
130
|
+
multiplicityKeyValue,
|
|
131
|
+
idempotencyKeys: []
|
|
132
|
+
});
|
|
133
|
+
await this.instanceRepo.save(agentContext, rec);
|
|
134
|
+
try {
|
|
135
|
+
this.eventEmitter?.emit(agentContext, {
|
|
136
|
+
type: WorkflowEventTypes.WorkflowInstanceStateChanged,
|
|
137
|
+
payload: {
|
|
138
|
+
instanceRecord: rec,
|
|
139
|
+
previousState: null,
|
|
140
|
+
newState: rec.state,
|
|
141
|
+
event: "start",
|
|
142
|
+
actionKey: void 0,
|
|
143
|
+
msgId: void 0
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
} catch (_e) {}
|
|
147
|
+
return rec;
|
|
148
|
+
}
|
|
149
|
+
async advance(agentContext, opts, instanceRecord) {
|
|
150
|
+
let inst;
|
|
151
|
+
if (instanceRecord) inst = instanceRecord;
|
|
152
|
+
else try {
|
|
153
|
+
inst = await this.instanceRepo.getById(agentContext, opts.instance_id);
|
|
154
|
+
} catch {
|
|
155
|
+
const found = await this.instanceRepo.getByInstanceId(agentContext, opts.instance_id);
|
|
156
|
+
if (!found) throw this.problem("invalid_event", "instance not found");
|
|
157
|
+
inst = found;
|
|
158
|
+
}
|
|
159
|
+
const tplRec = await this.templateRepo.findByTemplateIdAndVersion(agentContext, inst.templateId, inst.templateVersion);
|
|
160
|
+
if (!tplRec) throw this.problem("invalid_template", "template not found for instance");
|
|
161
|
+
const tpl = tplRec.template;
|
|
162
|
+
if (inst.status === "paused") throw this.problem("forbidden", "instance is paused");
|
|
163
|
+
if (inst.status === "canceled") throw this.problem("forbidden", "instance is canceled");
|
|
164
|
+
if (inst.status === "completed") throw this.problem("invalid_event", "instance already completed");
|
|
165
|
+
if (opts.idempotency_key && inst.idempotencyKeys?.includes(opts.idempotency_key)) {
|
|
166
|
+
const prior = inst.idempotency?.find?.((i) => i.key === opts.idempotency_key);
|
|
167
|
+
if (prior && prior.event !== opts.event) throw this.problem("idempotency_conflict", "same key, different event");
|
|
168
|
+
return inst;
|
|
169
|
+
}
|
|
170
|
+
const candidates = transitionsFromState(tpl, inst.state).filter((t$1) => t$1.on === opts.event);
|
|
171
|
+
if (!candidates.length) throw this.problem("invalid_event", `no transition for event ${opts.event} from ${inst.state}`);
|
|
172
|
+
const env = GuardEvaluator.envFromInstance(this.toInstanceData(inst));
|
|
173
|
+
const enabled = candidates.filter((t$1) => GuardEvaluator.evalGuard(t$1.guard, env));
|
|
174
|
+
if (!enabled.length) throw this.problem("guard_failed", "guard evaluated false");
|
|
175
|
+
const t = enabled[0];
|
|
176
|
+
let artifactsDelta = {};
|
|
177
|
+
let messageId;
|
|
178
|
+
if (t.action) {
|
|
179
|
+
const def = tpl.actions.find((a) => a.key === t.action);
|
|
180
|
+
if (!def) throw this.problem("invalid_template", `action not defined: ${t.action}`);
|
|
181
|
+
const handler = this.actions.get(def.typeURI);
|
|
182
|
+
if (!handler) throw this.problem("action_error", `no handler for type ${def.typeURI}`);
|
|
183
|
+
const exec = async () => handler.execute({
|
|
184
|
+
agentContext,
|
|
185
|
+
template: tpl,
|
|
186
|
+
instance: this.toInstanceData(inst),
|
|
187
|
+
action: def,
|
|
188
|
+
input: opts.input
|
|
189
|
+
});
|
|
190
|
+
const timeoutMs = this.config.actionTimeoutMs ?? 15e3;
|
|
191
|
+
const race = Promise.race([exec(), new Promise((_, rej) => setTimeout(() => rej(/* @__PURE__ */ new Error("action timeout")), timeoutMs))]);
|
|
192
|
+
let result;
|
|
193
|
+
try {
|
|
194
|
+
result = await race;
|
|
195
|
+
} catch (e) {
|
|
196
|
+
throw Object.assign(new Error(e.message || "action timeout"), { code: "action_error" });
|
|
197
|
+
}
|
|
198
|
+
artifactsDelta = result?.artifacts || {};
|
|
199
|
+
if (result?.contextMerge) inst.context = result.contextMerge;
|
|
200
|
+
if (result?.messageId) messageId = result.messageId;
|
|
201
|
+
}
|
|
202
|
+
const fromState = inst.state;
|
|
203
|
+
try {
|
|
204
|
+
if ((await this.instanceRepo.getById(agentContext, inst.id)).state !== fromState) throw this.problem("state_conflict", "state changed concurrently");
|
|
205
|
+
} catch (_e) {}
|
|
206
|
+
const prevState = inst.state;
|
|
207
|
+
inst.history.push({
|
|
208
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
209
|
+
event: opts.event,
|
|
210
|
+
from: inst.state,
|
|
211
|
+
to: t.to,
|
|
212
|
+
actionKey: t.action,
|
|
213
|
+
msg_id: messageId
|
|
214
|
+
});
|
|
215
|
+
inst.state = t.to;
|
|
216
|
+
inst.section = findSectionForState(tpl, t.to);
|
|
217
|
+
inst.artifacts = {
|
|
218
|
+
...inst.artifacts,
|
|
219
|
+
...artifactsDelta
|
|
220
|
+
};
|
|
221
|
+
if (opts.idempotency_key) {
|
|
222
|
+
inst.idempotencyKeys = [...inst.idempotencyKeys || [], opts.idempotency_key];
|
|
223
|
+
inst.idempotency = [...inst.idempotency || [], {
|
|
224
|
+
key: opts.idempotency_key,
|
|
225
|
+
event: opts.event,
|
|
226
|
+
to: t.to,
|
|
227
|
+
actionKey: t.action
|
|
228
|
+
}];
|
|
229
|
+
const limit = Math.max(1, this.config.idempotencyHistoryLimit ?? 100);
|
|
230
|
+
if ((inst.idempotencyKeys?.length || 0) > limit) inst.idempotencyKeys = inst.idempotencyKeys.slice(-limit);
|
|
231
|
+
if ((inst.idempotency?.length || 0) > limit) inst.idempotency = inst.idempotency.slice(-limit);
|
|
232
|
+
}
|
|
233
|
+
let reachedFinal = false;
|
|
234
|
+
try {
|
|
235
|
+
if (tpl.states.find((s) => s.name === t.to)?.type === "final") {
|
|
236
|
+
inst.status = "completed";
|
|
237
|
+
reachedFinal = true;
|
|
238
|
+
}
|
|
239
|
+
} catch (_e) {}
|
|
240
|
+
await this.instanceRepo.update(agentContext, inst);
|
|
241
|
+
try {
|
|
242
|
+
this.eventEmitter?.emit(agentContext, {
|
|
243
|
+
type: WorkflowEventTypes.WorkflowInstanceStateChanged,
|
|
244
|
+
payload: {
|
|
245
|
+
instanceRecord: inst,
|
|
246
|
+
previousState: prevState,
|
|
247
|
+
newState: inst.state,
|
|
248
|
+
event: opts.event,
|
|
249
|
+
actionKey: t.action,
|
|
250
|
+
msgId: messageId
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
} catch (_e) {}
|
|
254
|
+
if (reachedFinal) {
|
|
255
|
+
try {
|
|
256
|
+
this.eventEmitter?.emit(agentContext, {
|
|
257
|
+
type: WorkflowEventTypes.WorkflowInstanceStatusChanged,
|
|
258
|
+
payload: {
|
|
259
|
+
instanceRecord: inst,
|
|
260
|
+
previousStatus: "active",
|
|
261
|
+
newStatus: "completed"
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
} catch (_e) {}
|
|
265
|
+
try {
|
|
266
|
+
this.eventEmitter?.emit(agentContext, {
|
|
267
|
+
type: WorkflowEventTypes.WorkflowInstanceCompleted,
|
|
268
|
+
payload: {
|
|
269
|
+
instanceRecord: inst,
|
|
270
|
+
state: inst.state,
|
|
271
|
+
section: inst.section
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
} catch (_e) {}
|
|
275
|
+
await this.sendCompleteMessage(agentContext, inst);
|
|
276
|
+
}
|
|
277
|
+
return inst;
|
|
278
|
+
}
|
|
279
|
+
async status(agentContext, opts, instanceRecord) {
|
|
280
|
+
let inst;
|
|
281
|
+
if (instanceRecord) inst = instanceRecord;
|
|
282
|
+
else try {
|
|
283
|
+
inst = await this.instanceRepo.getById(agentContext, opts.instance_id);
|
|
284
|
+
} catch {
|
|
285
|
+
const found = await this.instanceRepo.getByInstanceId(agentContext, opts.instance_id);
|
|
286
|
+
if (!found) throw this.problem("invalid_event", "instance not found");
|
|
287
|
+
inst = found;
|
|
288
|
+
}
|
|
289
|
+
const tplRec = await this.templateRepo.findByTemplateIdAndVersion(agentContext, inst.templateId, inst.templateVersion);
|
|
290
|
+
if (!tplRec) throw this.problem("invalid_template", "template not found for instance");
|
|
291
|
+
const tpl = tplRec.template;
|
|
292
|
+
const instData = this.toInstanceData(inst);
|
|
293
|
+
const env = GuardEvaluator.envFromInstance(instData);
|
|
294
|
+
const allowed = transitionsFromState(tpl, inst.state).filter((t) => GuardEvaluator.evalGuard(t.guard, env)).map((t) => t.on);
|
|
295
|
+
const includeActions = opts.include_actions ?? true;
|
|
296
|
+
const includeUi = opts.include_ui ?? true;
|
|
297
|
+
const uiEnv = {
|
|
298
|
+
context: instData.context || {},
|
|
299
|
+
participants: instData.participants || {},
|
|
300
|
+
artifacts: instData.artifacts || {},
|
|
301
|
+
viewer: opts.viewer
|
|
302
|
+
};
|
|
303
|
+
const Ui = (init_UiFilter(), __toCommonJS(UiFilter_exports));
|
|
304
|
+
let derivedProfile = opts.ui_profile;
|
|
305
|
+
try {
|
|
306
|
+
const viewerRole = opts.viewer?.role;
|
|
307
|
+
const viewerKey = opts.viewer?.participantKey;
|
|
308
|
+
const viewerDid = opts.viewer?.did;
|
|
309
|
+
const mapKeyToProfile = (k) => {
|
|
310
|
+
if (!k) return void 0;
|
|
311
|
+
const key = k.toLowerCase();
|
|
312
|
+
if (key === "sender" || key === "issuer") return "sender";
|
|
313
|
+
if (key === "receiver" || key === "holder") return "receiver";
|
|
314
|
+
};
|
|
315
|
+
if (!derivedProfile) derivedProfile = mapKeyToProfile(viewerRole) || mapKeyToProfile(viewerKey);
|
|
316
|
+
if (!derivedProfile && viewerDid && instData?.participants && typeof instData.participants === "object") for (const [pKey, pVal] of Object.entries(instData.participants)) {
|
|
317
|
+
const did = pVal?.did;
|
|
318
|
+
if (did && did === viewerDid) {
|
|
319
|
+
derivedProfile = mapKeyToProfile(pKey);
|
|
320
|
+
if (derivedProfile) break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (!derivedProfile) {
|
|
324
|
+
let myDid;
|
|
325
|
+
if (instData?.connection_id) try {
|
|
326
|
+
const conn = await agentContext.dependencyManager.resolve(DidCommConnectionService).getById(agentContext, instData.connection_id);
|
|
327
|
+
myDid = conn?.did || conn?.myDid;
|
|
328
|
+
} catch {}
|
|
329
|
+
if (myDid && instData?.participants && typeof instData.participants === "object") for (const [pKey, pVal] of Object.entries(instData.participants)) {
|
|
330
|
+
const did = pVal?.did;
|
|
331
|
+
if (did && did === myDid) {
|
|
332
|
+
derivedProfile = mapKeyToProfile(pKey);
|
|
333
|
+
if (derivedProfile) break;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
} catch {}
|
|
338
|
+
const selected = Ui.selectUi(tpl?.display_hints, inst.state, derivedProfile);
|
|
339
|
+
const filtered = Ui.filterAndBindUi(selected, uiEnv, opts.viewer, derivedProfile);
|
|
340
|
+
const menu = includeActions ? filtered.filter((i) => i?.type === "button" || i?.type === "submit-button").map((i) => ({
|
|
341
|
+
label: i?.label,
|
|
342
|
+
event: i?.event
|
|
343
|
+
})) : [];
|
|
344
|
+
const assets = Ui.collectAssets(filtered, tpl?.display_hints?.assets);
|
|
345
|
+
const ui = includeUi ? filtered : void 0;
|
|
346
|
+
let connection;
|
|
347
|
+
if (inst.connectionId) try {
|
|
348
|
+
const conn = await agentContext.dependencyManager.resolve(DidCommConnectionService).getById(agentContext, inst.connectionId);
|
|
349
|
+
connection = {
|
|
350
|
+
id: conn?.id,
|
|
351
|
+
myDid: conn?.did || conn?.myDid,
|
|
352
|
+
theirDid: conn?.theirDid
|
|
353
|
+
};
|
|
354
|
+
} catch {}
|
|
355
|
+
return {
|
|
356
|
+
instance_id: inst.instanceId,
|
|
357
|
+
template_id: inst.templateId,
|
|
358
|
+
template_version: inst.templateVersion,
|
|
359
|
+
connection_id: inst.connectionId,
|
|
360
|
+
connection,
|
|
361
|
+
participants: inst.participants,
|
|
362
|
+
context: inst.context,
|
|
363
|
+
status: inst.status,
|
|
364
|
+
createdAt: inst.createdAt,
|
|
365
|
+
updatedAt: inst?.updatedAt,
|
|
366
|
+
state: inst.state,
|
|
367
|
+
section: inst.section,
|
|
368
|
+
allowed_events: allowed,
|
|
369
|
+
action_menu: menu,
|
|
370
|
+
artifacts: inst.artifacts,
|
|
371
|
+
...includeUi ? { ui } : {},
|
|
372
|
+
...derivedProfile ? { ui_profile: derivedProfile } : {},
|
|
373
|
+
...assets ? { assets } : {}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
async pause(agentContext, opts, instanceRecord) {
|
|
377
|
+
const inst = instanceRecord || await this.getInstanceByIdOrTag(agentContext, opts.instance_id);
|
|
378
|
+
const prev = inst.status;
|
|
379
|
+
inst.status = "paused";
|
|
380
|
+
await this.instanceRepo.update(agentContext, inst);
|
|
381
|
+
try {
|
|
382
|
+
this.eventEmitter?.emit(agentContext, {
|
|
383
|
+
type: WorkflowEventTypes.WorkflowInstanceStatusChanged,
|
|
384
|
+
payload: {
|
|
385
|
+
instanceRecord: inst,
|
|
386
|
+
previousStatus: prev,
|
|
387
|
+
newStatus: inst.status,
|
|
388
|
+
reason: opts.reason
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
} catch (_e) {}
|
|
392
|
+
return inst;
|
|
393
|
+
}
|
|
394
|
+
async resume(agentContext, opts, instanceRecord) {
|
|
395
|
+
const inst = instanceRecord || await this.getInstanceByIdOrTag(agentContext, opts.instance_id);
|
|
396
|
+
const prev = inst.status;
|
|
397
|
+
inst.status = "active";
|
|
398
|
+
await this.instanceRepo.update(agentContext, inst);
|
|
399
|
+
try {
|
|
400
|
+
this.eventEmitter?.emit(agentContext, {
|
|
401
|
+
type: WorkflowEventTypes.WorkflowInstanceStatusChanged,
|
|
402
|
+
payload: {
|
|
403
|
+
instanceRecord: inst,
|
|
404
|
+
previousStatus: prev,
|
|
405
|
+
newStatus: inst.status,
|
|
406
|
+
reason: opts.reason
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
} catch (_e) {}
|
|
410
|
+
return inst;
|
|
411
|
+
}
|
|
412
|
+
async cancel(agentContext, opts, instanceRecord) {
|
|
413
|
+
const inst = instanceRecord || await this.getInstanceByIdOrTag(agentContext, opts.instance_id);
|
|
414
|
+
const prev = inst.status;
|
|
415
|
+
inst.status = "canceled";
|
|
416
|
+
await this.instanceRepo.update(agentContext, inst);
|
|
417
|
+
try {
|
|
418
|
+
this.eventEmitter?.emit(agentContext, {
|
|
419
|
+
type: WorkflowEventTypes.WorkflowInstanceStatusChanged,
|
|
420
|
+
payload: {
|
|
421
|
+
instanceRecord: inst,
|
|
422
|
+
previousStatus: prev,
|
|
423
|
+
newStatus: inst.status,
|
|
424
|
+
reason: opts.reason
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
} catch (_e) {}
|
|
428
|
+
return inst;
|
|
429
|
+
}
|
|
430
|
+
async complete(agentContext, opts, instanceRecord) {
|
|
431
|
+
const inst = instanceRecord || await this.getInstanceByIdOrTag(agentContext, opts.instance_id);
|
|
432
|
+
const tplRec = await this.templateRepo.findByTemplateIdAndVersion(agentContext, inst.templateId, inst.templateVersion);
|
|
433
|
+
if (!tplRec) throw this.problem("invalid_template", "template not found for instance");
|
|
434
|
+
if (tplRec.template.states.find((s) => s.name === inst.state)?.type !== "final") throw this.problem("forbidden", "cannot complete: state is not final");
|
|
435
|
+
const prev = inst.status;
|
|
436
|
+
inst.status = "completed";
|
|
437
|
+
await this.instanceRepo.update(agentContext, inst);
|
|
438
|
+
try {
|
|
439
|
+
this.eventEmitter?.emit(agentContext, {
|
|
440
|
+
type: WorkflowEventTypes.WorkflowInstanceStatusChanged,
|
|
441
|
+
payload: {
|
|
442
|
+
instanceRecord: inst,
|
|
443
|
+
previousStatus: prev,
|
|
444
|
+
newStatus: inst.status,
|
|
445
|
+
reason: opts.reason
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
this.eventEmitter?.emit(agentContext, {
|
|
449
|
+
type: WorkflowEventTypes.WorkflowInstanceCompleted,
|
|
450
|
+
payload: {
|
|
451
|
+
instanceRecord: inst,
|
|
452
|
+
state: inst.state,
|
|
453
|
+
section: inst.section
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
} catch (_e) {}
|
|
457
|
+
return inst;
|
|
458
|
+
}
|
|
459
|
+
async autoAdvanceByConnection(agentContext, connectionId, event) {
|
|
460
|
+
const inst = await this.instanceRepo.findLatestByConnection(agentContext, connectionId);
|
|
461
|
+
if (!inst) return;
|
|
462
|
+
try {
|
|
463
|
+
await this.advance(agentContext, {
|
|
464
|
+
instance_id: inst.instanceId,
|
|
465
|
+
event,
|
|
466
|
+
idempotency_key: `auto:${event}:${inst.instanceId}`
|
|
467
|
+
});
|
|
468
|
+
} catch (e) {
|
|
469
|
+
this.agentConfig.logger.debug(`Workflow autoAdvance error: ${e.message}`);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
evalMultiplicity(expr, context) {
|
|
473
|
+
try {
|
|
474
|
+
const env = {
|
|
475
|
+
context,
|
|
476
|
+
participants: {},
|
|
477
|
+
artifacts: {}
|
|
478
|
+
};
|
|
479
|
+
const val = GuardEvaluator.evalValue(expr, env);
|
|
480
|
+
return val != null ? String(val) : "";
|
|
481
|
+
} catch {
|
|
482
|
+
return "";
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
toInstanceData(rec) {
|
|
486
|
+
return {
|
|
487
|
+
instance_id: rec.instanceId,
|
|
488
|
+
template_id: rec.templateId,
|
|
489
|
+
template_version: rec.templateVersion,
|
|
490
|
+
connection_id: rec.connectionId,
|
|
491
|
+
participants: rec.participants,
|
|
492
|
+
state: rec.state,
|
|
493
|
+
section: rec.section,
|
|
494
|
+
context: rec.context,
|
|
495
|
+
artifacts: rec.artifacts,
|
|
496
|
+
status: rec.status,
|
|
497
|
+
history: rec.history,
|
|
498
|
+
multiplicityKeyValue: rec.multiplicityKeyValue,
|
|
499
|
+
idempotencyKeys: rec.idempotencyKeys
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
problem(code, comment) {
|
|
503
|
+
const err = new Error(comment);
|
|
504
|
+
err.code = code;
|
|
505
|
+
return err;
|
|
506
|
+
}
|
|
507
|
+
async getInstanceByIdOrTag(agentContext, instanceId) {
|
|
508
|
+
try {
|
|
509
|
+
return await this.instanceRepo.getById(agentContext, instanceId);
|
|
510
|
+
} catch {
|
|
511
|
+
const found = await this.instanceRepo.getByInstanceId(agentContext, instanceId);
|
|
512
|
+
if (!found) throw this.problem("invalid_event", "instance not found");
|
|
513
|
+
return found;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
uuid() {
|
|
517
|
+
return `wf_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
|
|
518
|
+
}
|
|
519
|
+
validateTemplate(t) {
|
|
520
|
+
const fail = (msg) => {
|
|
521
|
+
throw this.problem("invalid_template", msg);
|
|
522
|
+
};
|
|
523
|
+
if (!t.template_id || !t.version || !t.title) fail("missing required fields");
|
|
524
|
+
if (!Array.isArray(t.states) || !t.states.length) fail("states required");
|
|
525
|
+
if (!Array.isArray(t.transitions)) fail("transitions required");
|
|
526
|
+
if (!Array.isArray(t.actions)) fail("actions required");
|
|
527
|
+
const stateNames = new Set(t.states.map((s) => s.name));
|
|
528
|
+
if (![...t.states].some((s) => s.type === "start")) fail("start state required");
|
|
529
|
+
for (const s of t.states) if (s.section && !t.sections?.some((sec) => sec.name === s.section)) fail(`state.section not found: ${s.section}`);
|
|
530
|
+
for (const tr of t.transitions) {
|
|
531
|
+
if (!stateNames.has(tr.from)) fail(`transition.from unknown: ${tr.from}`);
|
|
532
|
+
if (!stateNames.has(tr.to)) fail(`transition.to unknown: ${tr.to}`);
|
|
533
|
+
if (tr.action && !t.actions.some((a) => a.key === tr.action)) fail(`transition.action unknown: ${tr.action}`);
|
|
534
|
+
}
|
|
535
|
+
for (const a of t.actions) if ("profile_ref" in a && a.profile_ref) {
|
|
536
|
+
const pr = a.profile_ref;
|
|
537
|
+
if (pr.startsWith("cp.")) {
|
|
538
|
+
const key = pr.slice(3);
|
|
539
|
+
if (!t.catalog?.credential_profiles || !t.catalog.credential_profiles[key]) fail(`catalog.cp missing: ${key}`);
|
|
540
|
+
} else if (pr.startsWith("pp.")) {
|
|
541
|
+
const key = pr.slice(3);
|
|
542
|
+
if (!t.catalog?.proof_profiles || !t.catalog.proof_profiles[key]) fail(`catalog.pp missing: ${key}`);
|
|
543
|
+
} else fail(`invalid profile_ref: ${pr}`);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
async sendCompleteMessage(agentContext, inst) {
|
|
547
|
+
try {
|
|
548
|
+
if (!inst.connectionId) return;
|
|
549
|
+
const connectionSvc = agentContext.dependencyManager.resolve(DidCommConnectionService);
|
|
550
|
+
const messageSender = agentContext.dependencyManager.resolve(DidCommMessageSender);
|
|
551
|
+
const connection = await connectionSvc.getById(agentContext, inst.connectionId);
|
|
552
|
+
const msg = new CompleteMessage({
|
|
553
|
+
thid: inst.instanceId,
|
|
554
|
+
body: {
|
|
555
|
+
instance_id: inst.instanceId,
|
|
556
|
+
reason: "state_final"
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
try {
|
|
560
|
+
msg.setReturnRouting(ReturnRouteTypes.thread, inst.instanceId);
|
|
561
|
+
} catch (_e) {}
|
|
562
|
+
const outbound = new DidCommOutboundMessageContext(msg, {
|
|
563
|
+
agentContext,
|
|
564
|
+
connection
|
|
565
|
+
});
|
|
566
|
+
await messageSender.sendMessage(outbound);
|
|
567
|
+
} catch (e) {
|
|
568
|
+
this.agentConfig.logger.debug(`Workflow complete notify error: ${e.message}`);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
WorkflowService = __decorate([injectable(), __decorateMetadata("design:paramtypes", [
|
|
573
|
+
typeof (_ref = typeof WorkflowTemplateRepository !== "undefined" && WorkflowTemplateRepository) === "function" ? _ref : Object,
|
|
574
|
+
typeof (_ref2 = typeof WorkflowInstanceRepository !== "undefined" && WorkflowInstanceRepository) === "function" ? _ref2 : Object,
|
|
575
|
+
typeof (_ref3 = typeof WorkflowModuleConfig !== "undefined" && WorkflowModuleConfig) === "function" ? _ref3 : Object,
|
|
576
|
+
typeof (_ref4 = typeof AgentConfig !== "undefined" && AgentConfig) === "function" ? _ref4 : Object,
|
|
577
|
+
typeof (_ref5 = typeof EventEmitter !== "undefined" && EventEmitter) === "function" ? _ref5 : Object
|
|
578
|
+
])], WorkflowService);
|
|
579
|
+
|
|
580
|
+
//#endregion
|
|
581
|
+
export { WorkflowService };
|
|
582
|
+
//# sourceMappingURL=WorkflowService.mjs.map
|