@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.
- package/build/WorkflowEvents.d.ts +35 -0
- package/build/WorkflowEvents.js +10 -0
- package/build/WorkflowEvents.js.map +1 -0
- package/build/WorkflowModule.d.ts +13 -0
- package/build/WorkflowModule.js +459 -0
- package/build/WorkflowModule.js.map +1 -0
- package/build/WorkflowModuleConfig.d.ts +33 -0
- package/build/WorkflowModuleConfig.js +18 -0
- package/build/WorkflowModuleConfig.js.map +1 -0
- package/build/actions/ActionRegistry.d.ts +35 -0
- package/build/actions/ActionRegistry.js +193 -0
- package/build/actions/ActionRegistry.js.map +1 -0
- package/build/api/WorkflowApi.d.ts +57 -0
- package/build/api/WorkflowApi.js +50 -0
- package/build/api/WorkflowApi.js.map +1 -0
- package/build/engine/AttributePlanner.d.ts +7 -0
- package/build/engine/AttributePlanner.js +81 -0
- package/build/engine/AttributePlanner.js.map +1 -0
- package/build/engine/GuardEvaluator.d.ts +11 -0
- package/build/engine/GuardEvaluator.js +40 -0
- package/build/engine/GuardEvaluator.js.map +1 -0
- package/build/index.d.ts +45 -0
- package/build/index.js +69 -0
- package/build/index.js.map +1 -0
- package/build/model/TemplateValidation.d.ts +3 -0
- package/build/model/TemplateValidation.js +231 -0
- package/build/model/TemplateValidation.js.map +1 -0
- package/build/model/types.d.ts +116 -0
- package/build/model/types.js +15 -0
- package/build/model/types.js.map +1 -0
- package/build/protocol/WorkflowMessageTypes.d.ts +15 -0
- package/build/protocol/WorkflowMessageTypes.js +22 -0
- package/build/protocol/WorkflowMessageTypes.js.map +1 -0
- package/build/protocol/handlers/AdvanceHandler.d.ts +12 -0
- package/build/protocol/handlers/AdvanceHandler.js +113 -0
- package/build/protocol/handlers/AdvanceHandler.js.map +1 -0
- package/build/protocol/handlers/CancelHandler.d.ts +12 -0
- package/build/protocol/handlers/CancelHandler.js +116 -0
- package/build/protocol/handlers/CancelHandler.js.map +1 -0
- package/build/protocol/handlers/CompleteHandler.d.ts +12 -0
- package/build/protocol/handlers/CompleteHandler.js +117 -0
- package/build/protocol/handlers/CompleteHandler.js.map +1 -0
- package/build/protocol/handlers/DiscoverHandler.d.ts +11 -0
- package/build/protocol/handlers/DiscoverHandler.js +71 -0
- package/build/protocol/handlers/DiscoverHandler.js.map +1 -0
- package/build/protocol/handlers/FetchTemplateHandler.d.ts +12 -0
- package/build/protocol/handlers/FetchTemplateHandler.js +71 -0
- package/build/protocol/handlers/FetchTemplateHandler.js.map +1 -0
- package/build/protocol/handlers/PauseHandler.d.ts +12 -0
- package/build/protocol/handlers/PauseHandler.js +116 -0
- package/build/protocol/handlers/PauseHandler.js.map +1 -0
- package/build/protocol/handlers/ProblemReportHandler.d.ts +6 -0
- package/build/protocol/handlers/ProblemReportHandler.js +28 -0
- package/build/protocol/handlers/ProblemReportHandler.js.map +1 -0
- package/build/protocol/handlers/PublishTemplateHandler.d.ts +11 -0
- package/build/protocol/handlers/PublishTemplateHandler.js +53 -0
- package/build/protocol/handlers/PublishTemplateHandler.js.map +1 -0
- package/build/protocol/handlers/ResumeHandler.d.ts +12 -0
- package/build/protocol/handlers/ResumeHandler.js +116 -0
- package/build/protocol/handlers/ResumeHandler.js.map +1 -0
- package/build/protocol/handlers/StartHandler.d.ts +12 -0
- package/build/protocol/handlers/StartHandler.js +211 -0
- package/build/protocol/handlers/StartHandler.js.map +1 -0
- package/build/protocol/handlers/StatusHandler.d.ts +12 -0
- package/build/protocol/handlers/StatusHandler.js +100 -0
- package/build/protocol/handlers/StatusHandler.js.map +1 -0
- package/build/protocol/handlers/TemplateHandler.d.ts +9 -0
- package/build/protocol/handlers/TemplateHandler.js +43 -0
- package/build/protocol/handlers/TemplateHandler.js.map +1 -0
- package/build/protocol/messages/AdvanceMessage.d.ts +15 -0
- package/build/protocol/messages/AdvanceMessage.js +33 -0
- package/build/protocol/messages/AdvanceMessage.js.map +1 -0
- package/build/protocol/messages/CancelMessage.d.ts +14 -0
- package/build/protocol/messages/CancelMessage.js +33 -0
- package/build/protocol/messages/CancelMessage.js.map +1 -0
- package/build/protocol/messages/CompleteMessage.d.ts +14 -0
- package/build/protocol/messages/CompleteMessage.js +33 -0
- package/build/protocol/messages/CompleteMessage.js.map +1 -0
- package/build/protocol/messages/DiscoverMessage.d.ts +23 -0
- package/build/protocol/messages/DiscoverMessage.js +33 -0
- package/build/protocol/messages/DiscoverMessage.js.map +1 -0
- package/build/protocol/messages/FetchTemplateMessage.d.ts +15 -0
- package/build/protocol/messages/FetchTemplateMessage.js +33 -0
- package/build/protocol/messages/FetchTemplateMessage.js.map +1 -0
- package/build/protocol/messages/PauseMessage.d.ts +14 -0
- package/build/protocol/messages/PauseMessage.js +33 -0
- package/build/protocol/messages/PauseMessage.js.map +1 -0
- package/build/protocol/messages/ProblemReportMessage.d.ts +15 -0
- package/build/protocol/messages/ProblemReportMessage.js +33 -0
- package/build/protocol/messages/ProblemReportMessage.js.map +1 -0
- package/build/protocol/messages/PublishTemplateMessage.d.ts +17 -0
- package/build/protocol/messages/PublishTemplateMessage.js +31 -0
- package/build/protocol/messages/PublishTemplateMessage.js.map +1 -0
- package/build/protocol/messages/ResumeMessage.d.ts +14 -0
- package/build/protocol/messages/ResumeMessage.js +33 -0
- package/build/protocol/messages/ResumeMessage.js.map +1 -0
- package/build/protocol/messages/StartMessage.d.ts +21 -0
- package/build/protocol/messages/StartMessage.js +33 -0
- package/build/protocol/messages/StartMessage.js.map +1 -0
- package/build/protocol/messages/StatusMessage.d.ts +23 -0
- package/build/protocol/messages/StatusMessage.js +33 -0
- package/build/protocol/messages/StatusMessage.js.map +1 -0
- package/build/protocol/messages/StatusRequestMessage.d.ts +15 -0
- package/build/protocol/messages/StatusRequestMessage.js +33 -0
- package/build/protocol/messages/StatusRequestMessage.js.map +1 -0
- package/build/protocol/messages/TemplateMessage.d.ts +14 -0
- package/build/protocol/messages/TemplateMessage.js +33 -0
- package/build/protocol/messages/TemplateMessage.js.map +1 -0
- package/build/protocol/messages/WorkflowsMessage.d.ts +22 -0
- package/build/protocol/messages/WorkflowsMessage.js +33 -0
- package/build/protocol/messages/WorkflowsMessage.js.map +1 -0
- package/build/queue/CommandQueue.d.ts +17 -0
- package/build/queue/CommandQueue.js +8 -0
- package/build/queue/CommandQueue.js.map +1 -0
- package/build/queue/PersistentCommandQueue.d.ts +50 -0
- package/build/queue/PersistentCommandQueue.js +265 -0
- package/build/queue/PersistentCommandQueue.js.map +1 -0
- package/build/repository/WorkflowCommandRecord.d.ts +44 -0
- package/build/repository/WorkflowCommandRecord.js +38 -0
- package/build/repository/WorkflowCommandRecord.js.map +1 -0
- package/build/repository/WorkflowCommandRepository.d.ts +51 -0
- package/build/repository/WorkflowCommandRepository.js +135 -0
- package/build/repository/WorkflowCommandRepository.js.map +1 -0
- package/build/repository/WorkflowInstanceRecord.d.ts +61 -0
- package/build/repository/WorkflowInstanceRecord.js +43 -0
- package/build/repository/WorkflowInstanceRecord.js.map +1 -0
- package/build/repository/WorkflowInstanceRepository.d.ts +10 -0
- package/build/repository/WorkflowInstanceRepository.js +52 -0
- package/build/repository/WorkflowInstanceRepository.js.map +1 -0
- package/build/repository/WorkflowTemplateRecord.d.ts +23 -0
- package/build/repository/WorkflowTemplateRecord.js +28 -0
- package/build/repository/WorkflowTemplateRecord.js.map +1 -0
- package/build/repository/WorkflowTemplateRepository.d.ts +6 -0
- package/build/repository/WorkflowTemplateRepository.js +56 -0
- package/build/repository/WorkflowTemplateRepository.js.map +1 -0
- package/build/services/WorkflowService.d.ts +75 -0
- package/build/services/WorkflowService.js +566 -0
- package/build/services/WorkflowService.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProblemReportHandler.js","sourceRoot":"","sources":["../../../src/protocol/handlers/ProblemReportHandler.ts"],"names":[],"mappings":";;;;;;;;;AAEA,yCAAwD;AAExD,2EAAuE;AAGhE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAA1B;QACE,sBAAiB,GAAG,CAAC,2CAAoB,CAAC,CAAA;IAQnD,CAAC;IAPQ,KAAK,CAAC,MAAM,CAAC,cAAkE;QACpF,MAAM,MAAM,GAAG,cAAc,CAAC,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,kBAAW,CAAC,CAAC,MAAM,CAAA;QACxF,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,IAAI,CAAA;QACxC,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,QAAQ,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE,CAAA;QACzE,MAAM,CAAC,IAAI,CAAC,oCAAoC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;QACrG,OAAO,SAAS,CAAA;IAClB,CAAC;CACF,CAAA;AATY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,iBAAU,GAAE;GACA,oBAAoB,CAShC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core';
|
|
2
|
+
import { OutboundMessageContext } from '@credo-ts/core';
|
|
3
|
+
import { WorkflowService } from '../../services/WorkflowService';
|
|
4
|
+
import { ProblemReportMessage } from '../messages/ProblemReportMessage';
|
|
5
|
+
import { PublishTemplateMessage } from '../messages/PublishTemplateMessage';
|
|
6
|
+
export declare class PublishTemplateHandler implements MessageHandler {
|
|
7
|
+
private readonly service;
|
|
8
|
+
supportedMessages: (typeof PublishTemplateMessage)[];
|
|
9
|
+
constructor(service: WorkflowService);
|
|
10
|
+
handle(messageContext: MessageHandlerInboundMessage<PublishTemplateHandler>): Promise<OutboundMessageContext<ProblemReportMessage> | undefined>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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.PublishTemplateHandler = void 0;
|
|
13
|
+
const core_1 = require("@credo-ts/core");
|
|
14
|
+
const WorkflowModuleConfig_1 = require("../../WorkflowModuleConfig");
|
|
15
|
+
const WorkflowService_1 = require("../../services/WorkflowService");
|
|
16
|
+
const ProblemReportMessage_1 = require("../messages/ProblemReportMessage");
|
|
17
|
+
const PublishTemplateMessage_1 = require("../messages/PublishTemplateMessage");
|
|
18
|
+
let PublishTemplateHandler = class PublishTemplateHandler {
|
|
19
|
+
constructor(service) {
|
|
20
|
+
this.service = service;
|
|
21
|
+
this.supportedMessages = [PublishTemplateMessage_1.PublishTemplateMessage];
|
|
22
|
+
}
|
|
23
|
+
async handle(messageContext) {
|
|
24
|
+
const dm = messageContext.agentContext.dependencyManager;
|
|
25
|
+
const logger = dm.resolve(core_1.AgentConfig).logger;
|
|
26
|
+
const config = dm.resolve(WorkflowModuleConfig_1.WorkflowModuleConfig);
|
|
27
|
+
logger.info('[Workflow] publish-template received');
|
|
28
|
+
try {
|
|
29
|
+
await this.service.publishTemplate(messageContext.agentContext, messageContext.message.body.template);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
if (config.enableProblemReport && messageContext.connection) {
|
|
34
|
+
const pr = new ProblemReportMessage_1.ProblemReportMessage({
|
|
35
|
+
thid: messageContext.message.threadId || messageContext.message.id,
|
|
36
|
+
body: { code: e.code || 'action_error', comment: e.message },
|
|
37
|
+
});
|
|
38
|
+
return new core_1.OutboundMessageContext(pr, {
|
|
39
|
+
agentContext: messageContext.agentContext,
|
|
40
|
+
inboundMessageContext: messageContext,
|
|
41
|
+
connection: messageContext.connection,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
throw e;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.PublishTemplateHandler = PublishTemplateHandler;
|
|
49
|
+
exports.PublishTemplateHandler = PublishTemplateHandler = __decorate([
|
|
50
|
+
(0, core_1.injectable)(),
|
|
51
|
+
__metadata("design:paramtypes", [WorkflowService_1.WorkflowService])
|
|
52
|
+
], PublishTemplateHandler);
|
|
53
|
+
//# sourceMappingURL=PublishTemplateHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PublishTemplateHandler.js","sourceRoot":"","sources":["../../../src/protocol/handlers/PublishTemplateHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yCAAgF;AAEhF,qEAAiE;AACjE,oEAAgE;AAChE,2EAAuE;AACvE,+EAA2E;AAGpE,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAEjC,YAAoC,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QADrD,sBAAiB,GAAG,CAAC,+CAAsB,CAAC,CAAA;IACY,CAAC;IACzD,KAAK,CAAC,MAAM,CAAC,cAAoE;QACtF,MAAM,EAAE,GAAG,cAAc,CAAC,YAAY,CAAC,iBAAiB,CAAA;QACxD,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,kBAAW,CAAC,CAAC,MAAM,CAAA;QAC7C,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,2CAAoB,CAAC,CAAA;QAC/C,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAA;QACnD,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC,YAAY,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YACrG,OAAM;QACR,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,MAAM,CAAC,mBAAmB,IAAI,cAAc,CAAC,UAAU,EAAE,CAAC;gBAC5D,MAAM,EAAE,GAAG,IAAI,2CAAoB,CAAC;oBAClC,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,QAAQ,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE;oBAClE,IAAI,EAAE,EAAE,IAAI,EAAG,CAAuB,CAAC,IAAI,IAAI,cAAc,EAAE,OAAO,EAAG,CAAW,CAAC,OAAO,EAAE;iBAC/F,CAAC,CAAA;gBACF,OAAO,IAAI,6BAAsB,CAAC,EAAE,EAAE;oBACpC,YAAY,EAAE,cAAc,CAAC,YAAY;oBACzC,qBAAqB,EAAE,cAAc;oBACrC,UAAU,EAAE,cAAc,CAAC,UAAU;iBACtC,CAAC,CAAA;YACJ,CAAC;YACD,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;CACF,CAAA;AA1BY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,iBAAU,GAAE;qCAGkC,iCAAe;GAFjD,sBAAsB,CA0BlC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core';
|
|
2
|
+
import { OutboundMessageContext } from '@credo-ts/core';
|
|
3
|
+
import { WorkflowService } from '../../services/WorkflowService';
|
|
4
|
+
import { ProblemReportMessage } from '../messages/ProblemReportMessage';
|
|
5
|
+
import { ResumeMessage } from '../messages/ResumeMessage';
|
|
6
|
+
import { StatusMessage } from '../messages/StatusMessage';
|
|
7
|
+
export declare class ResumeHandler implements MessageHandler {
|
|
8
|
+
private readonly service;
|
|
9
|
+
supportedMessages: (typeof ResumeMessage)[];
|
|
10
|
+
constructor(service: WorkflowService);
|
|
11
|
+
handle(messageContext: MessageHandlerInboundMessage<ResumeHandler>): Promise<OutboundMessageContext<StatusMessage> | OutboundMessageContext<ProblemReportMessage> | undefined>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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.ResumeHandler = void 0;
|
|
13
|
+
const core_1 = require("@credo-ts/core");
|
|
14
|
+
const WorkflowModuleConfig_1 = require("../../WorkflowModuleConfig");
|
|
15
|
+
const CommandQueue_1 = require("../../queue/CommandQueue");
|
|
16
|
+
const WorkflowService_1 = require("../../services/WorkflowService");
|
|
17
|
+
const ProblemReportMessage_1 = require("../messages/ProblemReportMessage");
|
|
18
|
+
const ResumeMessage_1 = require("../messages/ResumeMessage");
|
|
19
|
+
const StatusMessage_1 = require("../messages/StatusMessage");
|
|
20
|
+
const WorkflowInstanceRepository_1 = require("../../repository/WorkflowInstanceRepository");
|
|
21
|
+
let ResumeHandler = class ResumeHandler {
|
|
22
|
+
constructor(service) {
|
|
23
|
+
this.service = service;
|
|
24
|
+
this.supportedMessages = [ResumeMessage_1.ResumeMessage];
|
|
25
|
+
}
|
|
26
|
+
async handle(messageContext) {
|
|
27
|
+
const dm = messageContext.agentContext.dependencyManager;
|
|
28
|
+
const logger = dm.resolve(core_1.AgentConfig).logger;
|
|
29
|
+
const config = dm.resolve(WorkflowModuleConfig_1.WorkflowModuleConfig);
|
|
30
|
+
const instId = messageContext.message.body?.instance_id;
|
|
31
|
+
const thid = messageContext.message.threadId || messageContext.message.id;
|
|
32
|
+
logger.info('[Workflow] resume received', { instance_id: instId, thid });
|
|
33
|
+
// Strict correlation: thid MUST equal instance_id
|
|
34
|
+
try {
|
|
35
|
+
const _id = messageContext.message.body?.instance_id;
|
|
36
|
+
if (_id && thid && _id !== thid) {
|
|
37
|
+
throw Object.assign(new Error('threadId does not match instance_id'), { code: 'correlation_mismatch' });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (_e) {
|
|
41
|
+
void 0;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
// Enforce inbound connection matches instance binding
|
|
45
|
+
const inboundConnId = messageContext.connection?.id;
|
|
46
|
+
const instIdBody = messageContext.message.body?.instance_id;
|
|
47
|
+
if (!inboundConnId || !instIdBody) {
|
|
48
|
+
throw Object.assign(new Error('missing inbound connection'), { code: 'forbidden' });
|
|
49
|
+
}
|
|
50
|
+
const repo = messageContext.agentContext.dependencyManager.resolve(WorkflowInstanceRepository_1.WorkflowInstanceRepository);
|
|
51
|
+
const instRec = await repo.getByInstanceId(messageContext.agentContext, instIdBody);
|
|
52
|
+
if (!instRec) {
|
|
53
|
+
throw Object.assign(new Error('instance not found'), { code: 'invalid_event' });
|
|
54
|
+
}
|
|
55
|
+
if (instRec.connectionId && instRec.connectionId !== inboundConnId) {
|
|
56
|
+
throw Object.assign(new Error('connection mismatch'), { code: 'forbidden' });
|
|
57
|
+
}
|
|
58
|
+
// Enqueue command for async processing (always async now)
|
|
59
|
+
const queue = dm.resolve(CommandQueue_1.CommandQueueService);
|
|
60
|
+
if (queue && typeof queue.enqueue === 'function' && typeof queue.isReady === 'function') {
|
|
61
|
+
const ready = await queue.isReady();
|
|
62
|
+
if (ready) {
|
|
63
|
+
await queue.enqueue(messageContext.agentContext, {
|
|
64
|
+
cmd: 'resume',
|
|
65
|
+
thid: instIdBody,
|
|
66
|
+
connectionId: inboundConnId,
|
|
67
|
+
payload: messageContext.message.body,
|
|
68
|
+
contextCorrelationId: messageContext.agentContext.contextCorrelationId,
|
|
69
|
+
});
|
|
70
|
+
// Immediate response with CURRENT state
|
|
71
|
+
const status = await this.service.status(messageContext.agentContext, { instance_id: instIdBody }, instRec);
|
|
72
|
+
const reply = new StatusMessage_1.StatusMessage({ thid, body: status });
|
|
73
|
+
return new core_1.OutboundMessageContext(reply, {
|
|
74
|
+
agentContext: messageContext.agentContext,
|
|
75
|
+
inboundMessageContext: messageContext,
|
|
76
|
+
connection: messageContext.connection,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Fallback: queue not available, process synchronously
|
|
81
|
+
logger.warn('[Workflow] Queue not available for resume, processing synchronously');
|
|
82
|
+
const updated = await this.service.resume(messageContext.agentContext, messageContext.message.body, instRec);
|
|
83
|
+
const status = await this.service.status(messageContext.agentContext, { instance_id: instId }, updated);
|
|
84
|
+
const reply = new StatusMessage_1.StatusMessage({ thid, body: status });
|
|
85
|
+
return new core_1.OutboundMessageContext(reply, {
|
|
86
|
+
agentContext: messageContext.agentContext,
|
|
87
|
+
inboundMessageContext: messageContext,
|
|
88
|
+
connection: messageContext.connection,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
if (e?.code === 'invalid_event') {
|
|
93
|
+
logger.info('[Workflow] resume ignored (no local instance)', { instance_id: instId });
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
if (config.enableProblemReport && messageContext.connection) {
|
|
97
|
+
const pr = new ProblemReportMessage_1.ProblemReportMessage({
|
|
98
|
+
thid: messageContext.message.threadId || messageContext.message.id,
|
|
99
|
+
body: { code: e.code || 'action_error', comment: e.message },
|
|
100
|
+
});
|
|
101
|
+
return new core_1.OutboundMessageContext(pr, {
|
|
102
|
+
agentContext: messageContext.agentContext,
|
|
103
|
+
inboundMessageContext: messageContext,
|
|
104
|
+
connection: messageContext.connection,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
throw e;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
exports.ResumeHandler = ResumeHandler;
|
|
112
|
+
exports.ResumeHandler = ResumeHandler = __decorate([
|
|
113
|
+
(0, core_1.injectable)(),
|
|
114
|
+
__metadata("design:paramtypes", [WorkflowService_1.WorkflowService])
|
|
115
|
+
], ResumeHandler);
|
|
116
|
+
//# sourceMappingURL=ResumeHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResumeHandler.js","sourceRoot":"","sources":["../../../src/protocol/handlers/ResumeHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yCAAgF;AAEhF,qEAAiE;AACjE,2DAA8D;AAC9D,oEAAgE;AAChE,2EAAuE;AACvE,6DAAyD;AACzD,6DAAyD;AACzD,4FAAwF;AAGjF,IAAM,aAAa,GAAnB,MAAM,aAAa;IAExB,YAAoC,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QADrD,sBAAiB,GAAG,CAAC,6BAAa,CAAC,CAAA;IACqB,CAAC;IACzD,KAAK,CAAC,MAAM,CAAC,cAA2D;QAC7E,MAAM,EAAE,GAAG,cAAc,CAAC,YAAY,CAAC,iBAAiB,CAAA;QACxD,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,kBAAW,CAAC,CAAC,MAAM,CAAA;QAC7C,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,2CAAoB,CAAC,CAAA;QAC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OAAO,EAAE;iBAC/F,CAAC,CAAA;gBACF,OAAO,IAAI,6BAAsB,CAAC,EAAE,EAAE;oBACpC,YAAY,EAAE,cAAc,CAAC,YAAY;oBACzC,qBAAqB,EAAE,cAAc;oBACrC,UAAU,EAAE,cAAc,CAAC,UAAU;iBACtC,CAAC,CAAA;YACJ,CAAC;YACD,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;CACF,CAAA;AA5FY,sCAAa;wBAAb,aAAa;IADzB,IAAA,iBAAU,GAAE;qCAGkC,iCAAe;GAFjD,aAAa,CA4FzB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core';
|
|
2
|
+
import { OutboundMessageContext } from '@credo-ts/core';
|
|
3
|
+
import { WorkflowService } from '../../services/WorkflowService';
|
|
4
|
+
import { ProblemReportMessage } from '../messages/ProblemReportMessage';
|
|
5
|
+
import { StartMessage } from '../messages/StartMessage';
|
|
6
|
+
import { StatusMessage } from '../messages/StatusMessage';
|
|
7
|
+
export declare class StartHandler implements MessageHandler {
|
|
8
|
+
private readonly service;
|
|
9
|
+
supportedMessages: (typeof StartMessage)[];
|
|
10
|
+
constructor(service: WorkflowService);
|
|
11
|
+
handle(messageContext: MessageHandlerInboundMessage<StartHandler>): Promise<OutboundMessageContext<StatusMessage> | OutboundMessageContext<ProblemReportMessage>>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
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.StartHandler = void 0;
|
|
13
|
+
const core_1 = require("@credo-ts/core");
|
|
14
|
+
const WorkflowModuleConfig_1 = require("../../WorkflowModuleConfig");
|
|
15
|
+
const CommandQueue_1 = require("../../queue/CommandQueue");
|
|
16
|
+
const WorkflowService_1 = require("../../services/WorkflowService");
|
|
17
|
+
const ProblemReportMessage_1 = require("../messages/ProblemReportMessage");
|
|
18
|
+
const StartMessage_1 = require("../messages/StartMessage");
|
|
19
|
+
const StatusMessage_1 = require("../messages/StatusMessage");
|
|
20
|
+
const FetchTemplateMessage_1 = require("../messages/FetchTemplateMessage");
|
|
21
|
+
const WorkflowTemplateRepository_1 = require("../../repository/WorkflowTemplateRepository");
|
|
22
|
+
const WorkflowInstanceRepository_1 = require("../../repository/WorkflowInstanceRepository");
|
|
23
|
+
let StartHandler = class StartHandler {
|
|
24
|
+
constructor(service) {
|
|
25
|
+
this.service = service;
|
|
26
|
+
this.supportedMessages = [StartMessage_1.StartMessage];
|
|
27
|
+
}
|
|
28
|
+
async handle(messageContext) {
|
|
29
|
+
const dm = messageContext.agentContext.dependencyManager;
|
|
30
|
+
const logger = dm.resolve(core_1.AgentConfig).logger;
|
|
31
|
+
const config = dm.resolve(WorkflowModuleConfig_1.WorkflowModuleConfig);
|
|
32
|
+
const thid = messageContext.message.threadId || messageContext.message.id;
|
|
33
|
+
const iid = messageContext.message.body?.instance_id;
|
|
34
|
+
logger.info('[Workflow] start received', {
|
|
35
|
+
template_id: messageContext.message.body?.template_id,
|
|
36
|
+
instance_id: iid,
|
|
37
|
+
thid,
|
|
38
|
+
});
|
|
39
|
+
// Strict correlation: when instance_id is present, it MUST equal thid
|
|
40
|
+
try {
|
|
41
|
+
const _id = messageContext.message.body?.instance_id;
|
|
42
|
+
if (_id && thid && _id !== thid) {
|
|
43
|
+
throw Object.assign(new Error('threadId does not match instance_id'), { code: 'correlation_mismatch' });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (_e) {
|
|
47
|
+
void 0;
|
|
48
|
+
}
|
|
49
|
+
// Default connection_id from inbound connection when not provided
|
|
50
|
+
const startBody = { ...messageContext.message.body };
|
|
51
|
+
// Always bind instance to the inbound connection (if present), ignoring any provided connection_id
|
|
52
|
+
const connectionId = messageContext.connection?.id;
|
|
53
|
+
if (connectionId) {
|
|
54
|
+
startBody.connection_id = connectionId;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
// Validate template exists BEFORE enqueueing (for discovery to work)
|
|
58
|
+
// Guard for tests where WorkflowTemplateRepository isn't registered or is a minimal stub
|
|
59
|
+
const maybeRepo = dm.resolve(WorkflowTemplateRepository_1.WorkflowTemplateRepository);
|
|
60
|
+
const hasFinder = !!maybeRepo?.findByTemplateIdAndVersion;
|
|
61
|
+
if (hasFinder) {
|
|
62
|
+
const templateRepo = maybeRepo;
|
|
63
|
+
const templateId = startBody.template_id;
|
|
64
|
+
const templateVersion = startBody.template_version;
|
|
65
|
+
const templateRecord = await templateRepo.findByTemplateIdAndVersion(messageContext.agentContext, templateId, templateVersion);
|
|
66
|
+
if (!templateRecord) {
|
|
67
|
+
// Template not found - trigger discovery/fetch if enabled
|
|
68
|
+
const allowDiscover = messageContext.message.body?.allow_discover ?? true;
|
|
69
|
+
const conn = messageContext.connection;
|
|
70
|
+
if (allowDiscover && config.enableAutoDiscoverOnStart && conn) {
|
|
71
|
+
try {
|
|
72
|
+
const sender = dm.resolve(core_1.MessageSender);
|
|
73
|
+
const fetch = new FetchTemplateMessage_1.FetchTemplateMessage({
|
|
74
|
+
thid: thid,
|
|
75
|
+
body: {
|
|
76
|
+
template_id: templateId,
|
|
77
|
+
template_version: templateVersion,
|
|
78
|
+
prefer_hash: messageContext.message.body?.template_hash,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
fetch.setReturnRouting(core_1.ReturnRouteTypes.thread, thid);
|
|
83
|
+
}
|
|
84
|
+
catch { /* noop */ }
|
|
85
|
+
await sender.sendMessage(new core_1.OutboundMessageContext(fetch, {
|
|
86
|
+
agentContext: messageContext.agentContext,
|
|
87
|
+
connection: conn,
|
|
88
|
+
}));
|
|
89
|
+
// Return problem report - client should retry after template is received
|
|
90
|
+
throw Object.assign(new Error('template not found - fetch-template sent, please retry start after template is received'), { code: 'template_not_found' });
|
|
91
|
+
}
|
|
92
|
+
catch (discoverErr) {
|
|
93
|
+
throw Object.assign(new Error(discoverErr.message), { code: 'template_not_found' });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Template not found and discovery not enabled/failed
|
|
97
|
+
throw Object.assign(new Error(`Template '${templateId}' not found`), { code: 'invalid_template' });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Template exists - proceed with async enqueue
|
|
101
|
+
const queue = dm.resolve(CommandQueue_1.CommandQueueService);
|
|
102
|
+
if (queue && typeof queue.enqueue === 'function' && typeof queue.isReady === 'function') {
|
|
103
|
+
const ready = await queue.isReady();
|
|
104
|
+
if (ready) {
|
|
105
|
+
// Ensure instance_id is set for correlation
|
|
106
|
+
const instanceId = startBody.instance_id || thid;
|
|
107
|
+
startBody.instance_id = instanceId;
|
|
108
|
+
await queue.enqueue(messageContext.agentContext, {
|
|
109
|
+
cmd: 'start',
|
|
110
|
+
thid: instanceId,
|
|
111
|
+
connectionId: connectionId,
|
|
112
|
+
payload: startBody,
|
|
113
|
+
contextCorrelationId: messageContext.agentContext.contextCorrelationId,
|
|
114
|
+
});
|
|
115
|
+
// Try to get existing instance for immediate status (may not exist yet)
|
|
116
|
+
const repo = dm.resolve(WorkflowInstanceRepository_1.WorkflowInstanceRepository);
|
|
117
|
+
let inst;
|
|
118
|
+
try {
|
|
119
|
+
inst = await repo.getByInstanceId(messageContext.agentContext, instanceId);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// Instance doesn't exist yet, will be created by worker
|
|
123
|
+
}
|
|
124
|
+
const status = inst
|
|
125
|
+
? await this.service.status(messageContext.agentContext, { instance_id: instanceId }, inst)
|
|
126
|
+
: {
|
|
127
|
+
instance_id: instanceId,
|
|
128
|
+
state: 'pending',
|
|
129
|
+
allowed_events: [],
|
|
130
|
+
action_menu: [],
|
|
131
|
+
artifacts: {},
|
|
132
|
+
};
|
|
133
|
+
const reply = new StatusMessage_1.StatusMessage({ thid, body: status });
|
|
134
|
+
return new core_1.OutboundMessageContext(reply, {
|
|
135
|
+
agentContext: messageContext.agentContext,
|
|
136
|
+
inboundMessageContext: messageContext,
|
|
137
|
+
connection: messageContext.connection,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Fallback: queue not available, process synchronously
|
|
142
|
+
logger.warn('[Workflow] Queue not available for start, processing synchronously');
|
|
143
|
+
const rec = await this.service.start(messageContext.agentContext, startBody);
|
|
144
|
+
const status = await this.service.status(messageContext.agentContext, { instance_id: rec.instanceId }, rec);
|
|
145
|
+
const reply = new StatusMessage_1.StatusMessage({ thid, body: status });
|
|
146
|
+
return new core_1.OutboundMessageContext(reply, {
|
|
147
|
+
agentContext: messageContext.agentContext,
|
|
148
|
+
inboundMessageContext: messageContext,
|
|
149
|
+
connection: messageContext.connection,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
if (config.enableProblemReport && messageContext.connection) {
|
|
154
|
+
// Attempt auto-discover/fetch when template not found and allowed
|
|
155
|
+
const errCode = e.code;
|
|
156
|
+
const allowDiscover = messageContext.message.body?.allow_discover ?? true;
|
|
157
|
+
const conn = messageContext.connection;
|
|
158
|
+
const th = messageContext.message.threadId || messageContext.message.id;
|
|
159
|
+
if (errCode === 'invalid_template' && allowDiscover && config.enableAutoDiscoverOnStart && conn) {
|
|
160
|
+
try {
|
|
161
|
+
const sender = messageContext.agentContext.dependencyManager.resolve(core_1.MessageSender);
|
|
162
|
+
// If version unspecified, optionally ask for listing to determine latest
|
|
163
|
+
const wantedId = messageContext.message.body?.template_id;
|
|
164
|
+
const wantedVersion = messageContext.message.body?.template_version;
|
|
165
|
+
// Skip separate discover roundtrip; we will directly fetch and allow the counterparty to reply via return-route
|
|
166
|
+
// Fetch directly (either specific version or let responder decide latest)
|
|
167
|
+
const fetch = new FetchTemplateMessage_1.FetchTemplateMessage({
|
|
168
|
+
thid: th,
|
|
169
|
+
body: { template_id: wantedId, template_version: wantedVersion, prefer_hash: messageContext.message.body?.template_hash },
|
|
170
|
+
});
|
|
171
|
+
// Request reply over same HTTP session for faster turnaround
|
|
172
|
+
try {
|
|
173
|
+
fetch.setReturnRouting(core_1.ReturnRouteTypes.thread, th);
|
|
174
|
+
}
|
|
175
|
+
catch { /* noop */ }
|
|
176
|
+
await sender.sendMessage(new core_1.OutboundMessageContext(fetch, { agentContext: messageContext.agentContext, connection: conn }));
|
|
177
|
+
// Return problem report immediately - client should retry start after receiving template
|
|
178
|
+
throw new Error('template not found - fetch-template sent, please retry start after template is received');
|
|
179
|
+
}
|
|
180
|
+
catch (discoverErr) {
|
|
181
|
+
const pr = new ProblemReportMessage_1.ProblemReportMessage({
|
|
182
|
+
thid: th,
|
|
183
|
+
body: { code: 'template_not_found', comment: discoverErr.message },
|
|
184
|
+
});
|
|
185
|
+
return new core_1.OutboundMessageContext(pr, {
|
|
186
|
+
agentContext: messageContext.agentContext,
|
|
187
|
+
inboundMessageContext: messageContext,
|
|
188
|
+
connection: messageContext.connection,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const pr = new ProblemReportMessage_1.ProblemReportMessage({
|
|
193
|
+
thid,
|
|
194
|
+
body: { code: errCode || 'action_error', comment: e.message },
|
|
195
|
+
});
|
|
196
|
+
return new core_1.OutboundMessageContext(pr, {
|
|
197
|
+
agentContext: messageContext.agentContext,
|
|
198
|
+
inboundMessageContext: messageContext,
|
|
199
|
+
connection: messageContext.connection,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
throw e;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
exports.StartHandler = StartHandler;
|
|
207
|
+
exports.StartHandler = StartHandler = __decorate([
|
|
208
|
+
(0, core_1.injectable)(),
|
|
209
|
+
__metadata("design:paramtypes", [WorkflowService_1.WorkflowService])
|
|
210
|
+
], StartHandler);
|
|
211
|
+
//# sourceMappingURL=StartHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StartHandler.js","sourceRoot":"","sources":["../../../src/protocol/handlers/StartHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yCAAiH;AAEjH,qEAAiE;AACjE,2DAA8D;AAC9D,oEAAgE;AAChE,2EAAuE;AACvE,2DAAuD;AACvD,6DAAyD;AACzD,2EAAuE;AAEvE,4FAAwF;AACxF,4FAAwF;AAGjF,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEvB,YAAoC,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QADrD,sBAAiB,GAAG,CAAC,2BAAY,CAAC,CAAA;IACsB,CAAC;IACzD,KAAK,CAAC,MAAM,CAAC,cAA0D;QAC5E,MAAM,EAAE,GAAG,cAAc,CAAC,YAAY,CAAC,iBAAiB,CAAA;QACxD,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,kBAAW,CAAC,CAAC,MAAM,CAAA;QAC7C,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,2CAAoB,CAAC,CAAA;QAC/C,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,QAAQ,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE,CAAA;QACzE,MAAM,GAAG,GAAG,cAAc,CAAC,OAA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CAAA;wBAE5H,yFAAyF;wBACzF,MAAM,IAAI,KAAK,CAAC,yFAAyF,CAAC,CAAA;oBAC5G,CAAC;oBAAC,OAAO,WAAW,EAAE,CAAC;wBACrB,MAAM,EAAE,GAAG,IAAI,2CAAoB,CAAC;4BAClC,IAAI,EAAE,EAAE;4BACR,IAAI,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAG,WAAqB,CAAC,OAAO,EAAE;yBAC9E,CAAC,CAAA;wBACF,OAAO,IAAI,6BAAsB,CAAC,EAAE,EAAE;4BACpC,YAAY,EAAE,cAAc,CAAC,YAAY;4BACzC,qBAAqB,EAAE,cAAc;4BACrC,UAAU,EAAE,cAAc,CAAC,UAAU;yBACtC,CAAC,CAAA;oBACJ,CAAC;gBACH,CAAC;gBACD,MAAM,EAAE,GAAG,IAAI,2CAAoB,CAAC;oBAClC,IAAI;oBACJ,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,IAAI,cAAc,EAAE,OAAO,EAAG,CAAW,CAAC,OAAO,EAAE;iBACzE,CAAC,CAAA;gBACF,OAAO,IAAI,6BAAsB,CAAC,EAAE,EAAE;oBACpC,YAAY,EAAE,cAAc,CAAC,YAAY;oBACzC,qBAAqB,EAAE,cAAc;oBACrC,UAAU,EAAE,cAAc,CAAC,UAAU;iBACtC,CAAC,CAAA;YACJ,CAAC;YACD,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;CACF,CAAA;AArMY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,iBAAU,GAAE;qCAGkC,iCAAe;GAFjD,YAAY,CAqMxB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core';
|
|
2
|
+
import { OutboundMessageContext } from '@credo-ts/core';
|
|
3
|
+
import { WorkflowService } from '../../services/WorkflowService';
|
|
4
|
+
import { ProblemReportMessage } from '../messages/ProblemReportMessage';
|
|
5
|
+
import { StatusMessage } from '../messages/StatusMessage';
|
|
6
|
+
import { StatusRequestMessage } from '../messages/StatusRequestMessage';
|
|
7
|
+
export declare class StatusHandler implements MessageHandler {
|
|
8
|
+
private readonly service;
|
|
9
|
+
supportedMessages: (typeof StatusRequestMessage)[];
|
|
10
|
+
constructor(service: WorkflowService);
|
|
11
|
+
handle(messageContext: MessageHandlerInboundMessage<StatusHandler>): Promise<OutboundMessageContext<StatusMessage> | OutboundMessageContext<ProblemReportMessage>>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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.StatusHandler = void 0;
|
|
13
|
+
const core_1 = require("@credo-ts/core");
|
|
14
|
+
const WorkflowModuleConfig_1 = require("../../WorkflowModuleConfig");
|
|
15
|
+
const WorkflowService_1 = require("../../services/WorkflowService");
|
|
16
|
+
const ProblemReportMessage_1 = require("../messages/ProblemReportMessage");
|
|
17
|
+
const StatusMessage_1 = require("../messages/StatusMessage");
|
|
18
|
+
const StatusRequestMessage_1 = require("../messages/StatusRequestMessage");
|
|
19
|
+
const WorkflowInstanceRepository_1 = require("../../repository/WorkflowInstanceRepository");
|
|
20
|
+
let StatusHandler = class StatusHandler {
|
|
21
|
+
constructor(service) {
|
|
22
|
+
this.service = service;
|
|
23
|
+
this.supportedMessages = [StatusRequestMessage_1.StatusRequestMessage];
|
|
24
|
+
}
|
|
25
|
+
async handle(messageContext) {
|
|
26
|
+
const dm = messageContext.agentContext.dependencyManager;
|
|
27
|
+
const logger = dm.resolve(core_1.AgentConfig).logger;
|
|
28
|
+
const config = dm.resolve(WorkflowModuleConfig_1.WorkflowModuleConfig);
|
|
29
|
+
const thid = messageContext.message.threadId || messageContext.message.id;
|
|
30
|
+
const iid = messageContext.message.body?.instance_id;
|
|
31
|
+
logger.info('[Workflow] status request received', {
|
|
32
|
+
instance_id: iid,
|
|
33
|
+
thid,
|
|
34
|
+
include_actions: messageContext.message.body?.include_actions,
|
|
35
|
+
include_ui: messageContext.message.body?.include_ui,
|
|
36
|
+
});
|
|
37
|
+
// Strict correlation: thid MUST equal instance_id
|
|
38
|
+
try {
|
|
39
|
+
const _id = messageContext.message.body?.instance_id;
|
|
40
|
+
if (_id && thid && _id !== thid) {
|
|
41
|
+
throw Object.assign(new Error('threadId does not match instance_id'), { code: 'correlation_mismatch' });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (_e) {
|
|
45
|
+
void 0;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
// Enforce inbound connection matches instance binding for status queries
|
|
49
|
+
const inboundConnId = messageContext.connection?.id;
|
|
50
|
+
const instId = messageContext.message.body?.instance_id;
|
|
51
|
+
if (!inboundConnId || !instId) {
|
|
52
|
+
throw Object.assign(new Error('missing inbound connection'), { code: 'forbidden' });
|
|
53
|
+
}
|
|
54
|
+
const repo = messageContext.agentContext.dependencyManager.resolve(WorkflowInstanceRepository_1.WorkflowInstanceRepository);
|
|
55
|
+
const inst = await repo.getByInstanceId(messageContext.agentContext, instId);
|
|
56
|
+
if (!inst) {
|
|
57
|
+
throw Object.assign(new Error('instance not found'), { code: 'invalid_event' });
|
|
58
|
+
}
|
|
59
|
+
if (inst.connectionId && inst.connectionId !== inboundConnId) {
|
|
60
|
+
throw Object.assign(new Error('connection mismatch'), { code: 'forbidden' });
|
|
61
|
+
}
|
|
62
|
+
const status = await this.service.status(messageContext.agentContext, {
|
|
63
|
+
instance_id: messageContext.message.body.instance_id,
|
|
64
|
+
include_actions: messageContext.message.body.include_actions,
|
|
65
|
+
include_ui: messageContext.message.body.include_ui,
|
|
66
|
+
}, inst);
|
|
67
|
+
const reply = new StatusMessage_1.StatusMessage({
|
|
68
|
+
thid: messageContext.message.threadId || messageContext.message.id,
|
|
69
|
+
body: status,
|
|
70
|
+
});
|
|
71
|
+
return new core_1.OutboundMessageContext(reply, {
|
|
72
|
+
agentContext: messageContext.agentContext,
|
|
73
|
+
// Reply over the same inbound session when available to avoid outbound HTTP timeouts
|
|
74
|
+
inboundMessageContext: messageContext,
|
|
75
|
+
connection: messageContext.connection,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
if (config.enableProblemReport && messageContext.connection) {
|
|
80
|
+
const pr = new ProblemReportMessage_1.ProblemReportMessage({
|
|
81
|
+
thid: messageContext.message.threadId || messageContext.message.id,
|
|
82
|
+
body: { code: e.code || 'action_error', comment: e.message },
|
|
83
|
+
});
|
|
84
|
+
return new core_1.OutboundMessageContext(pr, {
|
|
85
|
+
agentContext: messageContext.agentContext,
|
|
86
|
+
// Reply over the same inbound session when available
|
|
87
|
+
inboundMessageContext: messageContext,
|
|
88
|
+
connection: messageContext.connection,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
exports.StatusHandler = StatusHandler;
|
|
96
|
+
exports.StatusHandler = StatusHandler = __decorate([
|
|
97
|
+
(0, core_1.injectable)(),
|
|
98
|
+
__metadata("design:paramtypes", [WorkflowService_1.WorkflowService])
|
|
99
|
+
], StatusHandler);
|
|
100
|
+
//# sourceMappingURL=StatusHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatusHandler.js","sourceRoot":"","sources":["../../../src/protocol/handlers/StatusHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yCAAgF;AAEhF,qEAAiE;AACjE,oEAAgE;AAChE,2EAAuE;AACvE,6DAAyD;AACzD,2EAAuE;AACvE,4FAAwF;AAGjF,IAAM,aAAa,GAAnB,MAAM,aAAa;IAExB,YAAoC,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QADrD,sBAAiB,GAAG,CAAC,2CAAoB,CAAC,CAAA;IACc,CAAC;IACzD,KAAK,CAAC,MAAM,CAAC,cAA2D;QAC7E,MAAM,EAAE,GAAG,cAAc,CAAC,YAAY,CAAC,iBAAiB,CAAA;QACxD,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,kBAAW,CAAC,CAAC,MAAM,CAAA;QAC7C,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,2CAAoB,CAAC,CAAA;QAC/C,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,QAAQ,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE,CAAA;QACzE,MAAM,GAAG,GAAG,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAA;QACpD,MAAM,CAAC,IAAI,CAAC,oCAAoC,EAAE;YAChD,WAAW,EAAE,GAAG;YAChB,IAAI;YACJ,eAAe,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,eAAe;YAC7D,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU;SACpD,CAAC,CAAA;QACF,kDAAkD;QAClD,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAA;YACpD,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;gBAChC,MAAM,MAAM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A2EzB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core';
|
|
2
|
+
import { WorkflowService } from '../../services/WorkflowService';
|
|
3
|
+
import { TemplateMessage } from '../messages/TemplateMessage';
|
|
4
|
+
export declare class TemplateHandler implements MessageHandler {
|
|
5
|
+
private readonly service;
|
|
6
|
+
supportedMessages: (typeof TemplateMessage)[];
|
|
7
|
+
constructor(service: WorkflowService);
|
|
8
|
+
handle(messageContext: MessageHandlerInboundMessage<TemplateHandler>): Promise<undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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.TemplateHandler = void 0;
|
|
13
|
+
const core_1 = require("@credo-ts/core");
|
|
14
|
+
const WorkflowService_1 = require("../../services/WorkflowService");
|
|
15
|
+
const TemplateMessage_1 = require("../messages/TemplateMessage");
|
|
16
|
+
let TemplateHandler = class TemplateHandler {
|
|
17
|
+
constructor(service) {
|
|
18
|
+
this.service = service;
|
|
19
|
+
this.supportedMessages = [TemplateMessage_1.TemplateMessage];
|
|
20
|
+
}
|
|
21
|
+
async handle(messageContext) {
|
|
22
|
+
const logger = messageContext.agentContext.dependencyManager.resolve(core_1.AgentConfig).logger;
|
|
23
|
+
const thid = messageContext.message.threadId || messageContext.message.id;
|
|
24
|
+
logger.info('[Workflow] template received', {
|
|
25
|
+
thid,
|
|
26
|
+
template_id: messageContext.message.body?.template?.template_id,
|
|
27
|
+
template_version: messageContext.message.body?.template?.version,
|
|
28
|
+
});
|
|
29
|
+
try {
|
|
30
|
+
await this.service.publishTemplate(messageContext.agentContext, messageContext.message.body.template);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
logger.warn('[Workflow] template store failed', { thid, error: e.message });
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.TemplateHandler = TemplateHandler;
|
|
39
|
+
exports.TemplateHandler = TemplateHandler = __decorate([
|
|
40
|
+
(0, core_1.injectable)(),
|
|
41
|
+
__metadata("design:paramtypes", [WorkflowService_1.WorkflowService])
|
|
42
|
+
], TemplateHandler);
|
|
43
|
+
//# sourceMappingURL=TemplateHandler.js.map
|