@ajna-inc/workflow 0.5.17

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 (139) hide show
  1. package/build/WorkflowEvents.d.ts +35 -0
  2. package/build/WorkflowEvents.js +10 -0
  3. package/build/WorkflowEvents.js.map +1 -0
  4. package/build/WorkflowModule.d.ts +13 -0
  5. package/build/WorkflowModule.js +459 -0
  6. package/build/WorkflowModule.js.map +1 -0
  7. package/build/WorkflowModuleConfig.d.ts +33 -0
  8. package/build/WorkflowModuleConfig.js +18 -0
  9. package/build/WorkflowModuleConfig.js.map +1 -0
  10. package/build/actions/ActionRegistry.d.ts +35 -0
  11. package/build/actions/ActionRegistry.js +193 -0
  12. package/build/actions/ActionRegistry.js.map +1 -0
  13. package/build/api/WorkflowApi.d.ts +57 -0
  14. package/build/api/WorkflowApi.js +50 -0
  15. package/build/api/WorkflowApi.js.map +1 -0
  16. package/build/engine/AttributePlanner.d.ts +7 -0
  17. package/build/engine/AttributePlanner.js +81 -0
  18. package/build/engine/AttributePlanner.js.map +1 -0
  19. package/build/engine/GuardEvaluator.d.ts +11 -0
  20. package/build/engine/GuardEvaluator.js +40 -0
  21. package/build/engine/GuardEvaluator.js.map +1 -0
  22. package/build/index.d.ts +45 -0
  23. package/build/index.js +69 -0
  24. package/build/index.js.map +1 -0
  25. package/build/model/TemplateValidation.d.ts +3 -0
  26. package/build/model/TemplateValidation.js +231 -0
  27. package/build/model/TemplateValidation.js.map +1 -0
  28. package/build/model/types.d.ts +116 -0
  29. package/build/model/types.js +15 -0
  30. package/build/model/types.js.map +1 -0
  31. package/build/protocol/WorkflowMessageTypes.d.ts +15 -0
  32. package/build/protocol/WorkflowMessageTypes.js +22 -0
  33. package/build/protocol/WorkflowMessageTypes.js.map +1 -0
  34. package/build/protocol/handlers/AdvanceHandler.d.ts +12 -0
  35. package/build/protocol/handlers/AdvanceHandler.js +113 -0
  36. package/build/protocol/handlers/AdvanceHandler.js.map +1 -0
  37. package/build/protocol/handlers/CancelHandler.d.ts +12 -0
  38. package/build/protocol/handlers/CancelHandler.js +116 -0
  39. package/build/protocol/handlers/CancelHandler.js.map +1 -0
  40. package/build/protocol/handlers/CompleteHandler.d.ts +12 -0
  41. package/build/protocol/handlers/CompleteHandler.js +117 -0
  42. package/build/protocol/handlers/CompleteHandler.js.map +1 -0
  43. package/build/protocol/handlers/DiscoverHandler.d.ts +11 -0
  44. package/build/protocol/handlers/DiscoverHandler.js +71 -0
  45. package/build/protocol/handlers/DiscoverHandler.js.map +1 -0
  46. package/build/protocol/handlers/FetchTemplateHandler.d.ts +12 -0
  47. package/build/protocol/handlers/FetchTemplateHandler.js +71 -0
  48. package/build/protocol/handlers/FetchTemplateHandler.js.map +1 -0
  49. package/build/protocol/handlers/PauseHandler.d.ts +12 -0
  50. package/build/protocol/handlers/PauseHandler.js +116 -0
  51. package/build/protocol/handlers/PauseHandler.js.map +1 -0
  52. package/build/protocol/handlers/ProblemReportHandler.d.ts +6 -0
  53. package/build/protocol/handlers/ProblemReportHandler.js +28 -0
  54. package/build/protocol/handlers/ProblemReportHandler.js.map +1 -0
  55. package/build/protocol/handlers/PublishTemplateHandler.d.ts +11 -0
  56. package/build/protocol/handlers/PublishTemplateHandler.js +53 -0
  57. package/build/protocol/handlers/PublishTemplateHandler.js.map +1 -0
  58. package/build/protocol/handlers/ResumeHandler.d.ts +12 -0
  59. package/build/protocol/handlers/ResumeHandler.js +116 -0
  60. package/build/protocol/handlers/ResumeHandler.js.map +1 -0
  61. package/build/protocol/handlers/StartHandler.d.ts +12 -0
  62. package/build/protocol/handlers/StartHandler.js +211 -0
  63. package/build/protocol/handlers/StartHandler.js.map +1 -0
  64. package/build/protocol/handlers/StatusHandler.d.ts +12 -0
  65. package/build/protocol/handlers/StatusHandler.js +100 -0
  66. package/build/protocol/handlers/StatusHandler.js.map +1 -0
  67. package/build/protocol/handlers/TemplateHandler.d.ts +9 -0
  68. package/build/protocol/handlers/TemplateHandler.js +43 -0
  69. package/build/protocol/handlers/TemplateHandler.js.map +1 -0
  70. package/build/protocol/messages/AdvanceMessage.d.ts +15 -0
  71. package/build/protocol/messages/AdvanceMessage.js +33 -0
  72. package/build/protocol/messages/AdvanceMessage.js.map +1 -0
  73. package/build/protocol/messages/CancelMessage.d.ts +14 -0
  74. package/build/protocol/messages/CancelMessage.js +33 -0
  75. package/build/protocol/messages/CancelMessage.js.map +1 -0
  76. package/build/protocol/messages/CompleteMessage.d.ts +14 -0
  77. package/build/protocol/messages/CompleteMessage.js +33 -0
  78. package/build/protocol/messages/CompleteMessage.js.map +1 -0
  79. package/build/protocol/messages/DiscoverMessage.d.ts +23 -0
  80. package/build/protocol/messages/DiscoverMessage.js +33 -0
  81. package/build/protocol/messages/DiscoverMessage.js.map +1 -0
  82. package/build/protocol/messages/FetchTemplateMessage.d.ts +15 -0
  83. package/build/protocol/messages/FetchTemplateMessage.js +33 -0
  84. package/build/protocol/messages/FetchTemplateMessage.js.map +1 -0
  85. package/build/protocol/messages/PauseMessage.d.ts +14 -0
  86. package/build/protocol/messages/PauseMessage.js +33 -0
  87. package/build/protocol/messages/PauseMessage.js.map +1 -0
  88. package/build/protocol/messages/ProblemReportMessage.d.ts +15 -0
  89. package/build/protocol/messages/ProblemReportMessage.js +33 -0
  90. package/build/protocol/messages/ProblemReportMessage.js.map +1 -0
  91. package/build/protocol/messages/PublishTemplateMessage.d.ts +17 -0
  92. package/build/protocol/messages/PublishTemplateMessage.js +31 -0
  93. package/build/protocol/messages/PublishTemplateMessage.js.map +1 -0
  94. package/build/protocol/messages/ResumeMessage.d.ts +14 -0
  95. package/build/protocol/messages/ResumeMessage.js +33 -0
  96. package/build/protocol/messages/ResumeMessage.js.map +1 -0
  97. package/build/protocol/messages/StartMessage.d.ts +21 -0
  98. package/build/protocol/messages/StartMessage.js +33 -0
  99. package/build/protocol/messages/StartMessage.js.map +1 -0
  100. package/build/protocol/messages/StatusMessage.d.ts +23 -0
  101. package/build/protocol/messages/StatusMessage.js +33 -0
  102. package/build/protocol/messages/StatusMessage.js.map +1 -0
  103. package/build/protocol/messages/StatusRequestMessage.d.ts +15 -0
  104. package/build/protocol/messages/StatusRequestMessage.js +33 -0
  105. package/build/protocol/messages/StatusRequestMessage.js.map +1 -0
  106. package/build/protocol/messages/TemplateMessage.d.ts +14 -0
  107. package/build/protocol/messages/TemplateMessage.js +33 -0
  108. package/build/protocol/messages/TemplateMessage.js.map +1 -0
  109. package/build/protocol/messages/WorkflowsMessage.d.ts +22 -0
  110. package/build/protocol/messages/WorkflowsMessage.js +33 -0
  111. package/build/protocol/messages/WorkflowsMessage.js.map +1 -0
  112. package/build/queue/CommandQueue.d.ts +17 -0
  113. package/build/queue/CommandQueue.js +8 -0
  114. package/build/queue/CommandQueue.js.map +1 -0
  115. package/build/queue/PersistentCommandQueue.d.ts +50 -0
  116. package/build/queue/PersistentCommandQueue.js +265 -0
  117. package/build/queue/PersistentCommandQueue.js.map +1 -0
  118. package/build/repository/WorkflowCommandRecord.d.ts +44 -0
  119. package/build/repository/WorkflowCommandRecord.js +38 -0
  120. package/build/repository/WorkflowCommandRecord.js.map +1 -0
  121. package/build/repository/WorkflowCommandRepository.d.ts +51 -0
  122. package/build/repository/WorkflowCommandRepository.js +135 -0
  123. package/build/repository/WorkflowCommandRepository.js.map +1 -0
  124. package/build/repository/WorkflowInstanceRecord.d.ts +61 -0
  125. package/build/repository/WorkflowInstanceRecord.js +43 -0
  126. package/build/repository/WorkflowInstanceRecord.js.map +1 -0
  127. package/build/repository/WorkflowInstanceRepository.d.ts +10 -0
  128. package/build/repository/WorkflowInstanceRepository.js +52 -0
  129. package/build/repository/WorkflowInstanceRepository.js.map +1 -0
  130. package/build/repository/WorkflowTemplateRecord.d.ts +23 -0
  131. package/build/repository/WorkflowTemplateRecord.js +28 -0
  132. package/build/repository/WorkflowTemplateRecord.js.map +1 -0
  133. package/build/repository/WorkflowTemplateRepository.d.ts +6 -0
  134. package/build/repository/WorkflowTemplateRepository.js +56 -0
  135. package/build/repository/WorkflowTemplateRepository.js.map +1 -0
  136. package/build/services/WorkflowService.d.ts +75 -0
  137. package/build/services/WorkflowService.js +566 -0
  138. package/build/services/WorkflowService.js.map +1 -0
  139. package/package.json +47 -0
@@ -0,0 +1,15 @@
1
+ import { AgentMessage } from '@credo-ts/core';
2
+ export declare class StatusRequestMessage extends AgentMessage {
3
+ static readonly type: import("@credo-ts/core").ParsedMessageType;
4
+ type: string;
5
+ body: {
6
+ instance_id: string;
7
+ include_actions?: boolean;
8
+ include_ui?: boolean;
9
+ };
10
+ constructor(options?: {
11
+ id?: string;
12
+ body: StatusRequestMessage['body'];
13
+ thid?: string;
14
+ });
15
+ }
@@ -0,0 +1,33 @@
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.StatusRequestMessage = void 0;
13
+ const core_1 = require("@credo-ts/core");
14
+ class StatusRequestMessage extends core_1.AgentMessage {
15
+ constructor(options) {
16
+ super();
17
+ this.type = StatusRequestMessage.type.messageTypeUri;
18
+ this.type = StatusRequestMessage.type.messageTypeUri;
19
+ if (options) {
20
+ this.id = options.id || this.generateId();
21
+ this.body = options.body;
22
+ if (options.thid)
23
+ this.setThread({ threadId: options.thid });
24
+ }
25
+ }
26
+ }
27
+ exports.StatusRequestMessage = StatusRequestMessage;
28
+ StatusRequestMessage.type = (0, core_1.parseMessageType)('https://didcomm.org/workflow/1.0/status');
29
+ __decorate([
30
+ (0, core_1.IsValidMessageType)(StatusRequestMessage.type),
31
+ __metadata("design:type", Object)
32
+ ], StatusRequestMessage.prototype, "type", void 0);
33
+ //# sourceMappingURL=StatusRequestMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatusRequestMessage.js","sourceRoot":"","sources":["../../../src/protocol/messages/StatusRequestMessage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAmF;AAEnF,MAAa,oBAAqB,SAAQ,mBAAY;IAQpD,YAAmB,OAA4E;QAC7F,KAAK,EAAE,CAAA;QALF,SAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,cAAc,CAAA;QAMpD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,cAAc,CAAA;QACpD,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAA;YACzC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;YACxB,IAAI,OAAO,CAAC,IAAI;gBAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;QAC9D,CAAC;IACH,CAAC;;AAhBH,oDAiBC;AAhBwB,yBAAI,GAAG,IAAA,uBAAgB,EAAC,yCAAyC,CAAC,AAA9D,CAA8D;AAGlF;IADN,IAAA,yBAAkB,EAAC,oBAAoB,CAAC,IAAI,CAAC;;kDACQ"}
@@ -0,0 +1,14 @@
1
+ import type { WorkflowTemplate } from '../../model/types';
2
+ import { AgentMessage } from '@credo-ts/core';
3
+ export declare class TemplateMessage extends AgentMessage {
4
+ static readonly type: import("@credo-ts/core").ParsedMessageType;
5
+ type: string;
6
+ body: {
7
+ template: WorkflowTemplate;
8
+ };
9
+ constructor(options?: {
10
+ id?: string;
11
+ body: TemplateMessage['body'];
12
+ thid?: string;
13
+ });
14
+ }
@@ -0,0 +1,33 @@
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.TemplateMessage = void 0;
13
+ const core_1 = require("@credo-ts/core");
14
+ class TemplateMessage extends core_1.AgentMessage {
15
+ constructor(options) {
16
+ super();
17
+ this.type = TemplateMessage.type.messageTypeUri;
18
+ this.type = TemplateMessage.type.messageTypeUri;
19
+ if (options) {
20
+ this.id = options.id || this.generateId();
21
+ this.body = options.body;
22
+ if (options.thid)
23
+ this.setThread({ threadId: options.thid });
24
+ }
25
+ }
26
+ }
27
+ exports.TemplateMessage = TemplateMessage;
28
+ TemplateMessage.type = (0, core_1.parseMessageType)('https://didcomm.org/workflow/1.0/template');
29
+ __decorate([
30
+ (0, core_1.IsValidMessageType)(TemplateMessage.type),
31
+ __metadata("design:type", Object)
32
+ ], TemplateMessage.prototype, "type", void 0);
33
+ //# sourceMappingURL=TemplateMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TemplateMessage.js","sourceRoot":"","sources":["../../../src/protocol/messages/TemplateMessage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yCAAmF;AAEnF,MAAa,eAAgB,SAAQ,mBAAY;IAQ/C,YAAmB,OAAuE;QACxF,KAAK,EAAE,CAAA;QALF,SAAI,GAAG,eAAe,CAAC,IAAI,CAAC,cAAc,CAAA;QAM/C,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,cAAc,CAAA;QAC/C,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAA;YACzC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;YACxB,IAAI,OAAO,CAAC,IAAI;gBAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;QAC9D,CAAC;IACH,CAAC;;AAhBH,0CAiBC;AAhBwB,oBAAI,GAAG,IAAA,uBAAgB,EAAC,2CAA2C,CAAC,AAAhE,CAAgE;AAGpF;IADN,IAAA,yBAAkB,EAAC,eAAe,CAAC,IAAI,CAAC;;6CACQ"}
@@ -0,0 +1,22 @@
1
+ import { AgentMessage } from '@credo-ts/core';
2
+ export declare class WorkflowsMessage extends AgentMessage {
3
+ static readonly type: import("@credo-ts/core").ParsedMessageType;
4
+ type: string;
5
+ body: {
6
+ workflows: Array<{
7
+ template_id: string;
8
+ versions: string[];
9
+ title?: string;
10
+ hash?: string;
11
+ }>;
12
+ paging?: {
13
+ total?: number;
14
+ next_offset?: number;
15
+ };
16
+ };
17
+ constructor(options?: {
18
+ id?: string;
19
+ body: WorkflowsMessage['body'];
20
+ thid?: string;
21
+ });
22
+ }
@@ -0,0 +1,33 @@
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.WorkflowsMessage = void 0;
13
+ const core_1 = require("@credo-ts/core");
14
+ class WorkflowsMessage extends core_1.AgentMessage {
15
+ constructor(options) {
16
+ super();
17
+ this.type = WorkflowsMessage.type.messageTypeUri;
18
+ this.type = WorkflowsMessage.type.messageTypeUri;
19
+ if (options) {
20
+ this.id = options.id || this.generateId();
21
+ this.body = options.body;
22
+ if (options.thid)
23
+ this.setThread({ threadId: options.thid });
24
+ }
25
+ }
26
+ }
27
+ exports.WorkflowsMessage = WorkflowsMessage;
28
+ WorkflowsMessage.type = (0, core_1.parseMessageType)('https://didcomm.org/workflow/1.0/workflows');
29
+ __decorate([
30
+ (0, core_1.IsValidMessageType)(WorkflowsMessage.type),
31
+ __metadata("design:type", Object)
32
+ ], WorkflowsMessage.prototype, "type", void 0);
33
+ //# sourceMappingURL=WorkflowsMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkflowsMessage.js","sourceRoot":"","sources":["../../../src/protocol/messages/WorkflowsMessage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAmF;AAEnF,MAAa,gBAAiB,SAAQ,mBAAY;IAWhD,YAAmB,OAAwE;QACzF,KAAK,EAAE,CAAA;QARF,SAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,cAAc,CAAA;QAShD,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,cAAc,CAAA;QAChD,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAA;YACzC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;YACxB,IAAI,OAAO,CAAC,IAAI;gBAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;QAC9D,CAAC;IACH,CAAC;;AAnBH,4CAoBC;AAnBwB,qBAAI,GAAG,IAAA,uBAAgB,EAAC,4CAA4C,CAAC,AAAjE,CAAiE;AAGrF;IADN,IAAA,yBAAkB,EAAC,gBAAgB,CAAC,IAAI,CAAC;;8CACQ"}
@@ -0,0 +1,17 @@
1
+ import type { AgentContext } from '@credo-ts/core';
2
+ export type WorkflowCommandJob = {
3
+ cmd: 'start' | 'advance' | 'pause' | 'resume' | 'cancel' | 'complete';
4
+ thid: string;
5
+ connectionId?: string;
6
+ idempotency_key?: string;
7
+ payload: Record<string, unknown>;
8
+ contextCorrelationId: string;
9
+ };
10
+ export interface CommandQueue {
11
+ enqueue(agentContext: AgentContext, job: WorkflowCommandJob): Promise<void>;
12
+ startWorker(onJob: (job: WorkflowCommandJob) => Promise<void>): Promise<void>;
13
+ stop(): Promise<void>;
14
+ isReady(): Promise<boolean>;
15
+ }
16
+ export declare class CommandQueueService {
17
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandQueueService = void 0;
4
+ // DI token for the queue instance
5
+ class CommandQueueService {
6
+ }
7
+ exports.CommandQueueService = CommandQueueService;
8
+ //# sourceMappingURL=CommandQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandQueue.js","sourceRoot":"","sources":["../../src/queue/CommandQueue.ts"],"names":[],"mappings":";;;AAkBA,kCAAkC;AAClC,MAAa,mBAAmB;CAAG;AAAnC,kDAAmC"}
@@ -0,0 +1,50 @@
1
+ import type { AgentContext, AgentContextProvider } from '@credo-ts/core';
2
+ import type { CommandQueue, WorkflowCommandJob } from './CommandQueue';
3
+ import { WorkflowCommandRepository } from '../repository/WorkflowCommandRepository';
4
+ export interface PersistentCommandQueueOptions {
5
+ pollIntervalMs?: number;
6
+ concurrency?: number;
7
+ processingTimeoutMs?: number;
8
+ staleCheckIntervalMs?: number;
9
+ cleanupIntervalMs?: number;
10
+ commandRetentionMs?: number;
11
+ failedRetentionMs?: number;
12
+ maxAttempts?: number;
13
+ }
14
+ export declare class PersistentCommandQueue implements CommandQueue {
15
+ private readonly pollIntervalMs;
16
+ private readonly concurrency;
17
+ private readonly processingTimeoutMs;
18
+ private readonly staleCheckIntervalMs;
19
+ private readonly cleanupIntervalMs;
20
+ private readonly commandRetentionMs;
21
+ private readonly failedRetentionMs;
22
+ private readonly maxAttempts;
23
+ private running;
24
+ private activeCount;
25
+ private onJobHandler?;
26
+ private readonly repository;
27
+ private readonly contextProvider;
28
+ private readonly rootContext;
29
+ private readonly logger;
30
+ private readonly pendingSleeps;
31
+ constructor(repository: WorkflowCommandRepository, contextProvider: AgentContextProvider, rootContext: AgentContext, options?: PersistentCommandQueueOptions);
32
+ isReady(): Promise<boolean>;
33
+ enqueue(agentContext: AgentContext, job: WorkflowCommandJob): Promise<void>;
34
+ startWorker(onJob: (job: WorkflowCommandJob) => Promise<void>): Promise<void>;
35
+ stop(): Promise<void>;
36
+ private pollLoop;
37
+ private poll;
38
+ private processCommand;
39
+ private staleCheckLoop;
40
+ private cleanupLoop;
41
+ private resolveContext;
42
+ private sleep;
43
+ getMetrics(): Promise<{
44
+ pending: number;
45
+ processing: number;
46
+ completed: number;
47
+ failed: number;
48
+ active: number;
49
+ }>;
50
+ }
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PersistentCommandQueue = void 0;
4
+ const core_1 = require("@credo-ts/core");
5
+ const WorkflowCommandRecord_1 = require("../repository/WorkflowCommandRecord");
6
+ class PersistentCommandQueue {
7
+ constructor(repository, contextProvider, rootContext, options) {
8
+ this.running = false;
9
+ this.activeCount = 0;
10
+ this.pendingSleeps = new Set();
11
+ this.repository = repository;
12
+ this.contextProvider = contextProvider;
13
+ this.rootContext = rootContext;
14
+ this.logger = rootContext.dependencyManager.resolve(core_1.AgentConfig).logger;
15
+ this.pollIntervalMs = options?.pollIntervalMs ?? 100;
16
+ this.concurrency = Math.max(1, options?.concurrency ?? 3);
17
+ this.processingTimeoutMs = options?.processingTimeoutMs ?? 30000;
18
+ this.staleCheckIntervalMs = options?.staleCheckIntervalMs ?? 5000;
19
+ this.cleanupIntervalMs = options?.cleanupIntervalMs ?? 60000;
20
+ this.commandRetentionMs = options?.commandRetentionMs ?? 3600000; // 1 hour
21
+ this.failedRetentionMs = options?.failedRetentionMs ?? 86400000; // 24 hours
22
+ this.maxAttempts = options?.maxAttempts ?? 3;
23
+ }
24
+ async isReady() {
25
+ return true; // Always ready (uses existing storage)
26
+ }
27
+ async enqueue(agentContext, job) {
28
+ const record = new WorkflowCommandRecord_1.WorkflowCommandRecord({
29
+ cmd: job.cmd,
30
+ thid: job.thid,
31
+ connectionId: job.connectionId,
32
+ idempotencyKey: job.idempotency_key,
33
+ payload: job.payload,
34
+ contextCorrelationId: job.contextCorrelationId,
35
+ status: 'pending',
36
+ attempts: 0,
37
+ createdAt: new Date(),
38
+ });
39
+ await this.repository.save(agentContext, record);
40
+ this.logger.debug(`[PersistentQueue] Enqueued command: ${job.cmd} for ${job.thid}`);
41
+ // Trigger immediate poll (non-blocking)
42
+ setImmediate(() => void this.poll());
43
+ }
44
+ async startWorker(onJob) {
45
+ this.onJobHandler = onJob;
46
+ this.running = true;
47
+ this.logger.info('[PersistentQueue] Starting worker loops', {
48
+ pollIntervalMs: this.pollIntervalMs,
49
+ concurrency: this.concurrency,
50
+ processingTimeoutMs: this.processingTimeoutMs,
51
+ });
52
+ // Start background loops (non-blocking)
53
+ void this.pollLoop();
54
+ void this.staleCheckLoop();
55
+ void this.cleanupLoop();
56
+ }
57
+ async stop() {
58
+ this.logger.info('[PersistentQueue] Stopping worker...');
59
+ this.running = false;
60
+ // Cancel any pending sleep timers and resolve sleepers
61
+ for (const entry of Array.from(this.pendingSleeps)) {
62
+ try {
63
+ clearTimeout(entry.timer);
64
+ }
65
+ catch { }
66
+ try {
67
+ entry.resolve();
68
+ }
69
+ catch { }
70
+ this.pendingSleeps.delete(entry);
71
+ }
72
+ // Wait for active jobs to complete (with timeout)
73
+ const maxWait = 10000;
74
+ const start = Date.now();
75
+ while (this.activeCount > 0 && Date.now() - start < maxWait) {
76
+ await this.sleep(100);
77
+ }
78
+ if (this.activeCount > 0) {
79
+ this.logger.warn(`[PersistentQueue] Stopped with ${this.activeCount} active jobs`);
80
+ }
81
+ else {
82
+ this.logger.info('[PersistentQueue] Stopped cleanly');
83
+ }
84
+ }
85
+ async pollLoop() {
86
+ while (this.running) {
87
+ try {
88
+ await this.poll();
89
+ }
90
+ catch (err) {
91
+ if (this.running && this.logger && typeof this.logger.error === 'function') {
92
+ this.logger.error('[PersistentQueue] Poll error', { error: err.message });
93
+ }
94
+ }
95
+ await this.sleep(this.pollIntervalMs);
96
+ }
97
+ }
98
+ async poll() {
99
+ if (this.activeCount >= this.concurrency)
100
+ return;
101
+ if (!this.onJobHandler)
102
+ return;
103
+ const limit = this.concurrency - this.activeCount;
104
+ const pending = await this.repository.findPending(this.rootContext, limit);
105
+ for (const record of pending) {
106
+ // Check max attempts before processing
107
+ if (record.attempts >= this.maxAttempts) {
108
+ await this.repository.markFailed(this.rootContext, record, `Max attempts (${this.maxAttempts}) exceeded`);
109
+ this.logger.warn(`[PersistentQueue] Command ${record.id} failed after ${this.maxAttempts} attempts`);
110
+ continue;
111
+ }
112
+ // Mark as processing
113
+ await this.repository.markProcessing(this.rootContext, record);
114
+ this.activeCount++;
115
+ // Process in background
116
+ void this.processCommand(record);
117
+ }
118
+ }
119
+ async processCommand(record) {
120
+ try {
121
+ // Resolve tenant context
122
+ const context = await this.resolveContext(record.contextCorrelationId);
123
+ if (!context) {
124
+ throw new Error(`Unable to resolve context: ${record.contextCorrelationId}`);
125
+ }
126
+ const job = {
127
+ cmd: record.cmd,
128
+ thid: record.thid,
129
+ connectionId: record.connectionId,
130
+ idempotency_key: record.idempotencyKey,
131
+ payload: record.payload,
132
+ contextCorrelationId: record.contextCorrelationId,
133
+ };
134
+ this.logger.debug(`[PersistentQueue] Processing command: ${record.cmd} for ${record.thid}`);
135
+ await this.onJobHandler(job);
136
+ // Mark as completed
137
+ await this.repository.markCompleted(context.context, record);
138
+ this.logger.debug(`[PersistentQueue] Completed command: ${record.cmd} for ${record.thid}`);
139
+ // Release context
140
+ await context.release();
141
+ }
142
+ catch (err) {
143
+ const errorMsg = err.message || 'Unknown error';
144
+ if (this.running && this.logger && typeof this.logger.error === 'function') {
145
+ this.logger.error(`[PersistentQueue] Command processing failed: ${record.cmd} for ${record.thid}`, {
146
+ error: errorMsg,
147
+ attempts: record.attempts,
148
+ });
149
+ }
150
+ // Mark as failed if max attempts reached, otherwise reset to pending for retry
151
+ if (record.attempts >= this.maxAttempts) {
152
+ await this.repository.markFailed(this.rootContext, record, errorMsg);
153
+ }
154
+ else {
155
+ await this.repository.resetToPending(this.rootContext, record);
156
+ }
157
+ }
158
+ finally {
159
+ this.activeCount--;
160
+ }
161
+ }
162
+ async staleCheckLoop() {
163
+ while (this.running) {
164
+ await this.sleep(this.staleCheckIntervalMs);
165
+ try {
166
+ const stale = await this.repository.findStale(this.rootContext, this.processingTimeoutMs);
167
+ for (const record of stale) {
168
+ this.logger.warn(`[PersistentQueue] Resetting stale command: ${record.cmd} for ${record.thid}`, {
169
+ attempts: record.attempts,
170
+ lastAttempt: record.lastAttemptAt?.toISOString(),
171
+ });
172
+ if (record.attempts >= this.maxAttempts) {
173
+ await this.repository.markFailed(this.rootContext, record, 'Stale after max attempts');
174
+ }
175
+ else {
176
+ await this.repository.resetToPending(this.rootContext, record);
177
+ }
178
+ }
179
+ }
180
+ catch (err) {
181
+ if (this.running && this.logger && typeof this.logger.error === 'function') {
182
+ this.logger.error('[PersistentQueue] Stale check error', { error: err.message });
183
+ }
184
+ }
185
+ }
186
+ }
187
+ async cleanupLoop() {
188
+ while (this.running) {
189
+ await this.sleep(this.cleanupIntervalMs);
190
+ try {
191
+ const completedCutoff = new Date(Date.now() - this.commandRetentionMs);
192
+ const failedCutoff = new Date(Date.now() - this.failedRetentionMs);
193
+ const [completedDeleted, failedDeleted] = await Promise.all([
194
+ this.repository.deleteCompleted(this.rootContext, completedCutoff),
195
+ this.repository.deleteFailed(this.rootContext, failedCutoff),
196
+ ]);
197
+ if (completedDeleted > 0 || failedDeleted > 0) {
198
+ this.logger.debug(`[PersistentQueue] Cleanup: deleted ${completedDeleted} completed, ${failedDeleted} failed`);
199
+ }
200
+ }
201
+ catch (err) {
202
+ if (this.running && this.logger && typeof this.logger.error === 'function') {
203
+ this.logger.error('[PersistentQueue] Cleanup error', { error: err.message });
204
+ }
205
+ }
206
+ }
207
+ }
208
+ async resolveContext(correlationId) {
209
+ const rootId = this.rootContext.contextCorrelationId;
210
+ if (!correlationId || correlationId === rootId) {
211
+ return { context: this.rootContext, release: async () => { } };
212
+ }
213
+ try {
214
+ const scopedContext = await this.contextProvider.getAgentContextForContextCorrelationId(correlationId);
215
+ return {
216
+ context: scopedContext,
217
+ release: async () => {
218
+ try {
219
+ await this.contextProvider.endSessionForAgentContext(scopedContext);
220
+ }
221
+ catch (error) {
222
+ this.logger.debug('[PersistentQueue] Failed to end tenant session', {
223
+ contextCorrelationId: correlationId,
224
+ error: error.message,
225
+ });
226
+ }
227
+ },
228
+ };
229
+ }
230
+ catch (error) {
231
+ if (this.running && this.logger && typeof this.logger.error === 'function') {
232
+ this.logger.error('[PersistentQueue] Unable to resolve context', {
233
+ contextCorrelationId: correlationId,
234
+ error: error.message,
235
+ });
236
+ }
237
+ return null;
238
+ }
239
+ }
240
+ sleep(ms) {
241
+ return new Promise((outerResolve) => {
242
+ const entry = { timer: undefined, resolve: () => { } };
243
+ const resolve = () => {
244
+ try {
245
+ outerResolve();
246
+ }
247
+ finally {
248
+ this.pendingSleeps.delete(entry);
249
+ }
250
+ };
251
+ entry.resolve = resolve;
252
+ entry.timer = setTimeout(resolve, ms);
253
+ this.pendingSleeps.add(entry);
254
+ });
255
+ }
256
+ async getMetrics() {
257
+ const repoMetrics = await this.repository.getMetrics(this.rootContext);
258
+ return {
259
+ ...repoMetrics,
260
+ active: this.activeCount,
261
+ };
262
+ }
263
+ }
264
+ exports.PersistentCommandQueue = PersistentCommandQueue;
265
+ //# sourceMappingURL=PersistentCommandQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersistentCommandQueue.js","sourceRoot":"","sources":["../../src/queue/PersistentCommandQueue.ts"],"names":[],"mappings":";;;AAGA,yCAA8D;AAC9D,+EAA2E;AAc3E,MAAa,sBAAsB;IAoBjC,YACE,UAAqC,EACrC,eAAqC,EACrC,WAAyB,EACzB,OAAuC;QAdjC,YAAO,GAAG,KAAK,CAAA;QACf,gBAAW,GAAG,CAAC,CAAA;QAON,kBAAa,GAAG,IAAI,GAAG,EAAkD,CAAA;QAQxF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,kBAAW,CAAC,CAAC,MAAM,CAAA;QAEvE,IAAI,CAAC,cAAc,GAAG,OAAO,EAAE,cAAc,IAAI,GAAG,CAAA;QACpD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,IAAI,CAAC,CAAC,CAAA;QACzD,IAAI,CAAC,mBAAmB,GAAG,OAAO,EAAE,mBAAmB,IAAI,KAAK,CAAA;QAChE,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,oBAAoB,IAAI,IAAI,CAAA;QACjE,IAAI,CAAC,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI,K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A;IACJ,CAAC;IAEM,KAAK,CAAC,UAAU;QAOrB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACtE,OAAO;YACL,GAAG,WAAW;YACd,MAAM,EAAE,IAAI,CAAC,WAAW;SACzB,CAAA;IACH,CAAC;CACF;AAvTD,wDAuTC"}
@@ -0,0 +1,44 @@
1
+ import type { TagsBase } from '@credo-ts/core';
2
+ import { BaseRecord } from '@credo-ts/core';
3
+ export type WorkflowCommandType = 'start' | 'advance' | 'pause' | 'resume' | 'cancel' | 'complete';
4
+ export type WorkflowCommandStatus = 'pending' | 'processing' | 'completed' | 'failed';
5
+ export interface WorkflowCommandRecordProps {
6
+ id?: string;
7
+ cmd: WorkflowCommandType;
8
+ thid: string;
9
+ connectionId?: string;
10
+ idempotencyKey?: string;
11
+ payload: Record<string, unknown>;
12
+ contextCorrelationId: string;
13
+ status?: WorkflowCommandStatus;
14
+ attempts?: number;
15
+ lastAttemptAt?: Date;
16
+ error?: string;
17
+ createdAt?: Date;
18
+ completedAt?: Date;
19
+ }
20
+ export type WorkflowCommandRecordTags = TagsBase & {
21
+ status: WorkflowCommandStatus;
22
+ thid: string;
23
+ connectionId: string;
24
+ contextCorrelationId: string;
25
+ cmd: WorkflowCommandType;
26
+ };
27
+ export declare class WorkflowCommandRecord extends BaseRecord<WorkflowCommandRecordTags, TagsBase> {
28
+ static readonly type: "WorkflowCommandRecord";
29
+ readonly type: "WorkflowCommandRecord";
30
+ cmd: WorkflowCommandType;
31
+ thid: string;
32
+ connectionId?: string;
33
+ idempotencyKey?: string;
34
+ payload: Record<string, unknown>;
35
+ contextCorrelationId: string;
36
+ status: WorkflowCommandStatus;
37
+ attempts: number;
38
+ lastAttemptAt?: Date;
39
+ error?: string;
40
+ createdAt: Date;
41
+ completedAt?: Date;
42
+ constructor(props: WorkflowCommandRecordProps);
43
+ getTags(): WorkflowCommandRecordTags;
44
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkflowCommandRecord = void 0;
4
+ const core_1 = require("@credo-ts/core");
5
+ class WorkflowCommandRecord extends core_1.BaseRecord {
6
+ constructor(props) {
7
+ super();
8
+ this.type = WorkflowCommandRecord.type;
9
+ if (props) {
10
+ this.id = props.id ?? core_1.utils.uuid();
11
+ this.cmd = props.cmd;
12
+ this.thid = props.thid;
13
+ this.connectionId = props.connectionId;
14
+ this.idempotencyKey = props.idempotencyKey;
15
+ this.payload = props.payload;
16
+ this.contextCorrelationId = props.contextCorrelationId;
17
+ this.status = props.status ?? 'pending';
18
+ this.attempts = props.attempts ?? 0;
19
+ this.lastAttemptAt = props.lastAttemptAt;
20
+ this.error = props.error;
21
+ this.createdAt = props.createdAt ?? new Date();
22
+ this.completedAt = props.completedAt;
23
+ }
24
+ }
25
+ getTags() {
26
+ return {
27
+ ...this._tags,
28
+ status: this.status,
29
+ thid: this.thid,
30
+ connectionId: this.connectionId ?? '',
31
+ contextCorrelationId: this.contextCorrelationId,
32
+ cmd: this.cmd,
33
+ };
34
+ }
35
+ }
36
+ exports.WorkflowCommandRecord = WorkflowCommandRecord;
37
+ WorkflowCommandRecord.type = 'WorkflowCommandRecord';
38
+ //# sourceMappingURL=WorkflowCommandRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkflowCommandRecord.js","sourceRoot":"","sources":["../../src/repository/WorkflowCommandRecord.ts"],"names":[],"mappings":";;;AAEA,yCAAkD;AA+BlD,MAAa,qBAAsB,SAAQ,iBAA+C;IAmBxF,YAAmB,KAAiC;QAClD,KAAK,EAAE,CAAA;QAlBO,SAAI,GAAG,qBAAqB,CAAC,IAAI,CAAA;QAoB/C,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,IAAI,YAAK,CAAC,IAAI,EAAE,CAAA;YAClC,IAAI,CAAC,GAAG,GAAG,KA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