@cicctencent/agent-midway 0.1.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/README.md +280 -0
- package/dist/adapters/express.d.ts +8 -0
- package/dist/adapters/express.js +91 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.js +21 -0
- package/dist/adapters/koa.d.ts +3 -0
- package/dist/adapters/koa.js +75 -0
- package/dist/adapters/midway.d.ts +5 -0
- package/dist/adapters/midway.js +11 -0
- package/dist/adapters/next.d.ts +12 -0
- package/dist/adapters/next.js +89 -0
- package/dist/adapters/shared.d.ts +4 -0
- package/dist/adapters/shared.js +31 -0
- package/dist/channel/dingtalk.d.ts +18 -0
- package/dist/channel/dingtalk.js +68 -0
- package/dist/channel/feishu.d.ts +20 -0
- package/dist/channel/feishu.js +96 -0
- package/dist/channel/index.d.ts +46 -0
- package/dist/channel/index.js +311 -0
- package/dist/channel/types.d.ts +77 -0
- package/dist/channel/types.js +7 -0
- package/dist/channel/wecom.d.ts +22 -0
- package/dist/channel/wecom.js +106 -0
- package/dist/component.d.ts +49 -0
- package/dist/component.js +129 -0
- package/dist/connector/calendar-adapter.d.ts +19 -0
- package/dist/connector/calendar-adapter.js +236 -0
- package/dist/connector/db-adapter.d.ts +28 -0
- package/dist/connector/db-adapter.js +193 -0
- package/dist/connector/email-adapter.d.ts +23 -0
- package/dist/connector/email-adapter.js +192 -0
- package/dist/connector/fs-adapter.d.ts +15 -0
- package/dist/connector/fs-adapter.js +199 -0
- package/dist/connector/http-adapter.d.ts +29 -0
- package/dist/connector/http-adapter.js +181 -0
- package/dist/connector/index.d.ts +24 -0
- package/dist/connector/index.js +454 -0
- package/dist/connector/mcp-adapter.d.ts +27 -0
- package/dist/connector/mcp-adapter.js +156 -0
- package/dist/connector/mq-adapter.d.ts +25 -0
- package/dist/connector/mq-adapter.js +181 -0
- package/dist/connector/types.d.ts +205 -0
- package/dist/connector/types.js +9 -0
- package/dist/controller/a2a.controller.d.ts +41 -0
- package/dist/controller/a2a.controller.js +150 -0
- package/dist/controller/agent-profile.controller.d.ts +97 -0
- package/dist/controller/agent-profile.controller.js +200 -0
- package/dist/controller/agent.controller.d.ts +199 -0
- package/dist/controller/agent.controller.js +414 -0
- package/dist/controller/application.controller.d.ts +113 -0
- package/dist/controller/application.controller.js +217 -0
- package/dist/controller/automation.controller.d.ts +113 -0
- package/dist/controller/automation.controller.js +246 -0
- package/dist/controller/channel.controller.d.ts +73 -0
- package/dist/controller/channel.controller.js +183 -0
- package/dist/controller/chat.controller.d.ts +188 -0
- package/dist/controller/chat.controller.js +375 -0
- package/dist/controller/connector.controller.d.ts +134 -0
- package/dist/controller/connector.controller.js +257 -0
- package/dist/controller/knowledge-base.controller.d.ts +157 -0
- package/dist/controller/knowledge-base.controller.js +278 -0
- package/dist/controller/mcp-server.controller.d.ts +115 -0
- package/dist/controller/mcp-server.controller.js +236 -0
- package/dist/controller/model-config.controller.d.ts +139 -0
- package/dist/controller/model-config.controller.js +274 -0
- package/dist/controller/observability.controller.d.ts +124 -0
- package/dist/controller/observability.controller.js +142 -0
- package/dist/controller/security.controller.d.ts +91 -0
- package/dist/controller/security.controller.js +172 -0
- package/dist/controller/settings.controller.d.ts +83 -0
- package/dist/controller/settings.controller.js +280 -0
- package/dist/core/ai-workstation.d.ts +17 -0
- package/dist/core/ai-workstation.js +129 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +20 -0
- package/dist/core/service-container.d.ts +12 -0
- package/dist/core/service-container.js +54 -0
- package/dist/core/sse.d.ts +6 -0
- package/dist/core/sse.js +56 -0
- package/dist/core/types.d.ts +72 -0
- package/dist/core/types.js +2 -0
- package/dist/dto/agent.dto.d.ts +21 -0
- package/dist/dto/agent.dto.js +79 -0
- package/dist/dto/ai-config.dto.d.ts +67 -0
- package/dist/dto/ai-config.dto.js +249 -0
- package/dist/dto/chat.dto.d.ts +40 -0
- package/dist/dto/chat.dto.js +122 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +195 -0
- package/dist/memory/db-store.d.ts +33 -0
- package/dist/memory/db-store.js +143 -0
- package/dist/memory/index.d.ts +187 -0
- package/dist/memory/index.js +443 -0
- package/dist/model/ai-agent-profile.entity.d.ts +32 -0
- package/dist/model/ai-agent-profile.entity.js +289 -0
- package/dist/model/ai-application.entity.d.ts +20 -0
- package/dist/model/ai-application.entity.js +166 -0
- package/dist/model/ai-chat-memory.entity.d.ts +16 -0
- package/dist/model/ai-chat-memory.entity.js +123 -0
- package/dist/model/ai-chat-message.entity.d.ts +16 -0
- package/dist/model/ai-chat-message.entity.js +122 -0
- package/dist/model/ai-chat-skill.entity.d.ts +19 -0
- package/dist/model/ai-chat-skill.entity.js +155 -0
- package/dist/model/ai-chat-thread.entity.d.ts +15 -0
- package/dist/model/ai-chat-thread.entity.js +113 -0
- package/dist/model/ai-chat-workspace.entity.d.ts +17 -0
- package/dist/model/ai-chat-workspace.entity.js +136 -0
- package/dist/model/ai-kb-document.entity.d.ts +16 -0
- package/dist/model/ai-kb-document.entity.js +122 -0
- package/dist/model/ai-knowledge-base.entity.d.ts +22 -0
- package/dist/model/ai-knowledge-base.entity.js +185 -0
- package/dist/model/ai-mcp-server.entity.d.ts +23 -0
- package/dist/model/ai-mcp-server.entity.js +198 -0
- package/dist/model/ai-model-config.entity.d.ts +24 -0
- package/dist/model/ai-model-config.entity.js +200 -0
- package/dist/service/a2a.service.d.ts +142 -0
- package/dist/service/a2a.service.js +537 -0
- package/dist/service/agent-profile.service.d.ts +34 -0
- package/dist/service/agent-profile.service.js +110 -0
- package/dist/service/agent-server.service.d.ts +91 -0
- package/dist/service/agent-server.service.js +634 -0
- package/dist/service/agent-task-queue.service.d.ts +98 -0
- package/dist/service/agent-task-queue.service.js +283 -0
- package/dist/service/ai-chat.service.d.ts +103 -0
- package/dist/service/ai-chat.service.js +431 -0
- package/dist/service/ai-skill.service.d.ts +116 -0
- package/dist/service/ai-skill.service.js +457 -0
- package/dist/service/application.service.d.ts +42 -0
- package/dist/service/application.service.js +139 -0
- package/dist/service/automation.service.d.ts +37 -0
- package/dist/service/automation.service.js +196 -0
- package/dist/service/connector.service.d.ts +136 -0
- package/dist/service/connector.service.js +524 -0
- package/dist/service/knowledge-base.service.d.ts +138 -0
- package/dist/service/knowledge-base.service.js +528 -0
- package/dist/service/mcp-server.service.d.ts +39 -0
- package/dist/service/mcp-server.service.js +143 -0
- package/dist/service/model-config.service.d.ts +57 -0
- package/dist/service/model-config.service.js +168 -0
- package/dist/service/observability.service.d.ts +145 -0
- package/dist/service/observability.service.js +281 -0
- package/dist/service/openai.service.d.ts +88 -0
- package/dist/service/openai.service.js +406 -0
- package/dist/service/prompt-builder.service.d.ts +50 -0
- package/dist/service/prompt-builder.service.js +246 -0
- package/dist/tools/code-exec.tool.d.ts +37 -0
- package/dist/tools/code-exec.tool.js +162 -0
- package/dist/tools/datetime.tool.d.ts +21 -0
- package/dist/tools/datetime.tool.js +379 -0
- package/dist/tools/http-request.tool.d.ts +43 -0
- package/dist/tools/http-request.tool.js +455 -0
- package/dist/tools/registry.d.ts +71 -0
- package/dist/tools/registry.js +77 -0
- package/dist/tools/text-process.tool.d.ts +7 -0
- package/dist/tools/text-process.tool.js +366 -0
- package/dist/tools/web-search.tool.d.ts +28 -0
- package/dist/tools/web-search.tool.js +304 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +7 -0
- package/package.json +69 -0
|
@@ -0,0 +1,217 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ApplicationController = void 0;
|
|
16
|
+
const core_1 = require("@midwayjs/core");
|
|
17
|
+
const midwayjs_base_1 = require("@cicctencent/midwayjs-base");
|
|
18
|
+
const application_service_1 = require("../service/application.service");
|
|
19
|
+
/**
|
|
20
|
+
* AI 应用管理 Controller
|
|
21
|
+
*/
|
|
22
|
+
let ApplicationController = class ApplicationController extends midwayjs_base_1.BaseController {
|
|
23
|
+
/** 获取应用列表 */
|
|
24
|
+
async list() {
|
|
25
|
+
try {
|
|
26
|
+
const apps = await this.appService.list({ status: 'active' });
|
|
27
|
+
return { ret: 0, data: apps, msg: 'success' };
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return { ret: 1, msg: error.message };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** 获取单个应用 */
|
|
34
|
+
async detail(id) {
|
|
35
|
+
try {
|
|
36
|
+
const app = await this.appService.resolveApp(id);
|
|
37
|
+
if (!app) {
|
|
38
|
+
return { ret: 1, msg: '应用不存在' };
|
|
39
|
+
}
|
|
40
|
+
return { ret: 0, data: app, msg: 'success' };
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return { ret: 1, msg: error.message };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** 获取应用完整配置 */
|
|
47
|
+
async fullConfig(id) {
|
|
48
|
+
try {
|
|
49
|
+
const config = await this.appService.getFullConfig(id);
|
|
50
|
+
if (!config) {
|
|
51
|
+
return { ret: 1, msg: '应用不存在' };
|
|
52
|
+
}
|
|
53
|
+
return { ret: 0, data: config, msg: 'success' };
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
return { ret: 1, msg: error.message };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** 获取默认应用 */
|
|
60
|
+
async getDefault() {
|
|
61
|
+
try {
|
|
62
|
+
const app = await this.appService.getDefault();
|
|
63
|
+
return { ret: 0, data: app, msg: 'success' };
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return { ret: 1, msg: error.message };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** 创建应用 */
|
|
70
|
+
async create(body) {
|
|
71
|
+
try {
|
|
72
|
+
const app = await this.appService.create(body);
|
|
73
|
+
return { ret: 0, data: app, msg: 'success' };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return { ret: 1, msg: error.message };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** 更新应用 */
|
|
80
|
+
async update(id, body) {
|
|
81
|
+
try {
|
|
82
|
+
const app = await this.appService.update(Number(id), body);
|
|
83
|
+
return { ret: 0, data: app, msg: 'success' };
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return { ret: 1, msg: error.message };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** 删除应用 */
|
|
90
|
+
async remove(id) {
|
|
91
|
+
try {
|
|
92
|
+
await this.appService.delete(Number(id));
|
|
93
|
+
return { ret: 0, data: null, msg: 'success' };
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return { ret: 1, msg: error.message };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** 设置为默认 */
|
|
100
|
+
async setDefault(id) {
|
|
101
|
+
try {
|
|
102
|
+
const app = await this.appService.setDefault(Number(id));
|
|
103
|
+
return { ret: 0, data: app, msg: 'success' };
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
return { ret: 1, msg: error.message };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** 归档应用 */
|
|
110
|
+
async archive(id) {
|
|
111
|
+
try {
|
|
112
|
+
const app = await this.appService.archive(Number(id));
|
|
113
|
+
return { ret: 0, data: app, msg: 'success' };
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
return { ret: 1, msg: error.message };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** 激活应用 */
|
|
120
|
+
async activate(id) {
|
|
121
|
+
try {
|
|
122
|
+
const app = await this.appService.activate(Number(id));
|
|
123
|
+
return { ret: 0, data: app, msg: 'success' };
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
return { ret: 1, msg: error.message };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
exports.ApplicationController = ApplicationController;
|
|
131
|
+
__decorate([
|
|
132
|
+
(0, core_1.Inject)(),
|
|
133
|
+
__metadata("design:type", application_service_1.ApplicationService)
|
|
134
|
+
], ApplicationController.prototype, "appService", void 0);
|
|
135
|
+
__decorate([
|
|
136
|
+
(0, core_1.Get)('/'),
|
|
137
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
138
|
+
__metadata("design:type", Function),
|
|
139
|
+
__metadata("design:paramtypes", []),
|
|
140
|
+
__metadata("design:returntype", Promise)
|
|
141
|
+
], ApplicationController.prototype, "list", null);
|
|
142
|
+
__decorate([
|
|
143
|
+
(0, core_1.Get)('/:id'),
|
|
144
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
145
|
+
__param(0, (0, core_1.Param)('id')),
|
|
146
|
+
__metadata("design:type", Function),
|
|
147
|
+
__metadata("design:paramtypes", [String]),
|
|
148
|
+
__metadata("design:returntype", Promise)
|
|
149
|
+
], ApplicationController.prototype, "detail", null);
|
|
150
|
+
__decorate([
|
|
151
|
+
(0, core_1.Get)('/:id/full'),
|
|
152
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
153
|
+
__param(0, (0, core_1.Param)('id')),
|
|
154
|
+
__metadata("design:type", Function),
|
|
155
|
+
__metadata("design:paramtypes", [String]),
|
|
156
|
+
__metadata("design:returntype", Promise)
|
|
157
|
+
], ApplicationController.prototype, "fullConfig", null);
|
|
158
|
+
__decorate([
|
|
159
|
+
(0, core_1.Get)('/default'),
|
|
160
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
161
|
+
__metadata("design:type", Function),
|
|
162
|
+
__metadata("design:paramtypes", []),
|
|
163
|
+
__metadata("design:returntype", Promise)
|
|
164
|
+
], ApplicationController.prototype, "getDefault", null);
|
|
165
|
+
__decorate([
|
|
166
|
+
(0, core_1.Post)('/'),
|
|
167
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
168
|
+
__param(0, (0, core_1.Body)()),
|
|
169
|
+
__metadata("design:type", Function),
|
|
170
|
+
__metadata("design:paramtypes", [Object]),
|
|
171
|
+
__metadata("design:returntype", Promise)
|
|
172
|
+
], ApplicationController.prototype, "create", null);
|
|
173
|
+
__decorate([
|
|
174
|
+
(0, core_1.Put)('/:id'),
|
|
175
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
176
|
+
__param(0, (0, core_1.Param)('id')),
|
|
177
|
+
__param(1, (0, core_1.Body)()),
|
|
178
|
+
__metadata("design:type", Function),
|
|
179
|
+
__metadata("design:paramtypes", [Number, Object]),
|
|
180
|
+
__metadata("design:returntype", Promise)
|
|
181
|
+
], ApplicationController.prototype, "update", null);
|
|
182
|
+
__decorate([
|
|
183
|
+
(0, core_1.Del)('/:id'),
|
|
184
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
185
|
+
__param(0, (0, core_1.Param)('id')),
|
|
186
|
+
__metadata("design:type", Function),
|
|
187
|
+
__metadata("design:paramtypes", [Number]),
|
|
188
|
+
__metadata("design:returntype", Promise)
|
|
189
|
+
], ApplicationController.prototype, "remove", null);
|
|
190
|
+
__decorate([
|
|
191
|
+
(0, core_1.Post)('/:id/default'),
|
|
192
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
193
|
+
__param(0, (0, core_1.Param)('id')),
|
|
194
|
+
__metadata("design:type", Function),
|
|
195
|
+
__metadata("design:paramtypes", [Number]),
|
|
196
|
+
__metadata("design:returntype", Promise)
|
|
197
|
+
], ApplicationController.prototype, "setDefault", null);
|
|
198
|
+
__decorate([
|
|
199
|
+
(0, core_1.Post)('/:id/archive'),
|
|
200
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
201
|
+
__param(0, (0, core_1.Param)('id')),
|
|
202
|
+
__metadata("design:type", Function),
|
|
203
|
+
__metadata("design:paramtypes", [Number]),
|
|
204
|
+
__metadata("design:returntype", Promise)
|
|
205
|
+
], ApplicationController.prototype, "archive", null);
|
|
206
|
+
__decorate([
|
|
207
|
+
(0, core_1.Post)('/:id/activate'),
|
|
208
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
209
|
+
__param(0, (0, core_1.Param)('id')),
|
|
210
|
+
__metadata("design:type", Function),
|
|
211
|
+
__metadata("design:paramtypes", [Number]),
|
|
212
|
+
__metadata("design:returntype", Promise)
|
|
213
|
+
], ApplicationController.prototype, "activate", null);
|
|
214
|
+
exports.ApplicationController = ApplicationController = __decorate([
|
|
215
|
+
(0, core_1.Provide)(),
|
|
216
|
+
(0, core_1.Controller)('/api/applications')
|
|
217
|
+
], ApplicationController);
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { BaseController } from '@cicctencent/midwayjs-base';
|
|
2
|
+
import { DataSource } from 'typeorm';
|
|
3
|
+
import { AutomationService } from '../service/automation.service';
|
|
4
|
+
/**
|
|
5
|
+
* 自动化任务 Controller
|
|
6
|
+
*
|
|
7
|
+
* 管理 Cron 定时任务和事件触发器。
|
|
8
|
+
* 集成 AutomationService 实现 cron 调度。
|
|
9
|
+
*/
|
|
10
|
+
export declare class AutomationController extends BaseController {
|
|
11
|
+
dataSource: DataSource;
|
|
12
|
+
automationService: AutomationService;
|
|
13
|
+
/** 获取自动化任务列表 */
|
|
14
|
+
list(): Promise<{
|
|
15
|
+
ret: number;
|
|
16
|
+
data: any;
|
|
17
|
+
msg: string;
|
|
18
|
+
} | {
|
|
19
|
+
ret: number;
|
|
20
|
+
msg: any;
|
|
21
|
+
data?: undefined;
|
|
22
|
+
}>;
|
|
23
|
+
/** 获取单个自动化任务 */
|
|
24
|
+
detail(id: number): Promise<{
|
|
25
|
+
ret: number;
|
|
26
|
+
data: any;
|
|
27
|
+
msg: string;
|
|
28
|
+
} | {
|
|
29
|
+
ret: number;
|
|
30
|
+
msg: any;
|
|
31
|
+
data?: undefined;
|
|
32
|
+
}>;
|
|
33
|
+
/** 创建自动化任务 */
|
|
34
|
+
create(body: {
|
|
35
|
+
name: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
type: 'cron' | 'event_trigger' | 'price_trigger';
|
|
38
|
+
config: any;
|
|
39
|
+
status?: 'active' | 'paused';
|
|
40
|
+
}): Promise<{
|
|
41
|
+
ret: number;
|
|
42
|
+
data: {
|
|
43
|
+
id: any;
|
|
44
|
+
};
|
|
45
|
+
msg: string;
|
|
46
|
+
} | {
|
|
47
|
+
ret: number;
|
|
48
|
+
msg: any;
|
|
49
|
+
data?: undefined;
|
|
50
|
+
}>;
|
|
51
|
+
/** 更新自动化任务 */
|
|
52
|
+
update(id: number, body: {
|
|
53
|
+
name?: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
config?: any;
|
|
56
|
+
status?: 'active' | 'paused';
|
|
57
|
+
}): Promise<{
|
|
58
|
+
ret: number;
|
|
59
|
+
data: any;
|
|
60
|
+
msg: string;
|
|
61
|
+
} | {
|
|
62
|
+
ret: number;
|
|
63
|
+
msg: any;
|
|
64
|
+
data?: undefined;
|
|
65
|
+
}>;
|
|
66
|
+
/** 删除自动化任务 */
|
|
67
|
+
remove(id: number): Promise<{
|
|
68
|
+
ret: number;
|
|
69
|
+
data: any;
|
|
70
|
+
msg: string;
|
|
71
|
+
} | {
|
|
72
|
+
ret: number;
|
|
73
|
+
msg: any;
|
|
74
|
+
data?: undefined;
|
|
75
|
+
}>;
|
|
76
|
+
/** 手动触发自动化任务 */
|
|
77
|
+
runAutomation(id: number): Promise<{
|
|
78
|
+
ret: number;
|
|
79
|
+
data: {
|
|
80
|
+
result: string;
|
|
81
|
+
};
|
|
82
|
+
msg: string;
|
|
83
|
+
} | {
|
|
84
|
+
ret: number;
|
|
85
|
+
msg: any;
|
|
86
|
+
data?: undefined;
|
|
87
|
+
}>;
|
|
88
|
+
/** 获取执行历史 */
|
|
89
|
+
getRuns(id: number, body?: {
|
|
90
|
+
limit?: number;
|
|
91
|
+
offset?: number;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
ret: number;
|
|
94
|
+
data: any;
|
|
95
|
+
msg: string;
|
|
96
|
+
} | {
|
|
97
|
+
ret: number;
|
|
98
|
+
msg: any;
|
|
99
|
+
data?: undefined;
|
|
100
|
+
}>;
|
|
101
|
+
/** 获取活跃调度任务数 */
|
|
102
|
+
getSchedulerStatus(): Promise<{
|
|
103
|
+
ret: number;
|
|
104
|
+
data: {
|
|
105
|
+
activeJobCount: number;
|
|
106
|
+
};
|
|
107
|
+
msg: string;
|
|
108
|
+
} | {
|
|
109
|
+
ret: number;
|
|
110
|
+
msg: any;
|
|
111
|
+
data?: undefined;
|
|
112
|
+
}>;
|
|
113
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AutomationController = void 0;
|
|
16
|
+
const core_1 = require("@midwayjs/core");
|
|
17
|
+
const midwayjs_base_1 = require("@cicctencent/midwayjs-base");
|
|
18
|
+
const typeorm_1 = require("@midwayjs/typeorm");
|
|
19
|
+
const typeorm_2 = require("typeorm");
|
|
20
|
+
const automation_service_1 = require("../service/automation.service");
|
|
21
|
+
/**
|
|
22
|
+
* 自动化任务 Controller
|
|
23
|
+
*
|
|
24
|
+
* 管理 Cron 定时任务和事件触发器。
|
|
25
|
+
* 集成 AutomationService 实现 cron 调度。
|
|
26
|
+
*/
|
|
27
|
+
let AutomationController = class AutomationController extends midwayjs_base_1.BaseController {
|
|
28
|
+
/** 获取自动化任务列表 */
|
|
29
|
+
async list() {
|
|
30
|
+
try {
|
|
31
|
+
// 确保调度器已初始化
|
|
32
|
+
await this.automationService.ensureInitialized();
|
|
33
|
+
const automations = await this.dataSource.query('SELECT * FROM t_ai_automation WHERE is_deleted = 0 ORDER BY create_time DESC');
|
|
34
|
+
return { ret: 0, data: automations, msg: 'success' };
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return { ret: 1, msg: error.message };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** 获取单个自动化任务 */
|
|
41
|
+
async detail(id) {
|
|
42
|
+
try {
|
|
43
|
+
const automations = await this.dataSource.query('SELECT * FROM t_ai_automation WHERE id = ? AND is_deleted = 0', [id]);
|
|
44
|
+
if (!automations || automations.length === 0) {
|
|
45
|
+
return { ret: 1, msg: '自动化任务不存在' };
|
|
46
|
+
}
|
|
47
|
+
return { ret: 0, data: automations[0], msg: 'success' };
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return { ret: 1, msg: error.message };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** 创建自动化任务 */
|
|
54
|
+
async create(body) {
|
|
55
|
+
try {
|
|
56
|
+
const result = await this.dataSource.query(`INSERT INTO t_ai_automation (name, description, type, config, status, is_deleted, create_time)
|
|
57
|
+
VALUES (?, ?, ?, ?, ?, 0, NOW())`, [
|
|
58
|
+
body.name,
|
|
59
|
+
body.description || '',
|
|
60
|
+
body.type,
|
|
61
|
+
JSON.stringify(body.config),
|
|
62
|
+
body.status || 'active',
|
|
63
|
+
]);
|
|
64
|
+
const insertId = result.insertId;
|
|
65
|
+
// 如果任务状态为 active,注册 cron 调度
|
|
66
|
+
if (body.status !== 'paused') {
|
|
67
|
+
const created = await this.dataSource.query('SELECT * FROM t_ai_automation WHERE id = ?', [insertId]);
|
|
68
|
+
if (created.length > 0) {
|
|
69
|
+
this.automationService.scheduleJob(created[0]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
ret: 0,
|
|
74
|
+
data: { id: insertId },
|
|
75
|
+
msg: '创建成功',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return { ret: 1, msg: error.message };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** 更新自动化任务 */
|
|
83
|
+
async update(id, body) {
|
|
84
|
+
try {
|
|
85
|
+
const updates = [];
|
|
86
|
+
const params = [];
|
|
87
|
+
if (body.name) {
|
|
88
|
+
updates.push('name = ?');
|
|
89
|
+
params.push(body.name);
|
|
90
|
+
}
|
|
91
|
+
if (body.description !== undefined) {
|
|
92
|
+
updates.push('description = ?');
|
|
93
|
+
params.push(body.description);
|
|
94
|
+
}
|
|
95
|
+
if (body.config) {
|
|
96
|
+
updates.push('config = ?');
|
|
97
|
+
params.push(JSON.stringify(body.config));
|
|
98
|
+
}
|
|
99
|
+
if (body.status) {
|
|
100
|
+
updates.push('status = ?');
|
|
101
|
+
params.push(body.status);
|
|
102
|
+
}
|
|
103
|
+
if (updates.length > 0) {
|
|
104
|
+
params.push(id);
|
|
105
|
+
await this.dataSource.query(`UPDATE t_ai_automation SET ${updates.join(', ')} WHERE id = ?`, params);
|
|
106
|
+
}
|
|
107
|
+
// 刷新调度:先注销再重新注册
|
|
108
|
+
this.automationService.unscheduleJob(id);
|
|
109
|
+
const updated = await this.dataSource.query('SELECT * FROM t_ai_automation WHERE id = ? AND is_deleted = 0', [id]);
|
|
110
|
+
if (updated.length > 0 && updated[0].status === 'active') {
|
|
111
|
+
this.automationService.scheduleJob(updated[0]);
|
|
112
|
+
}
|
|
113
|
+
return { ret: 0, data: null, msg: '更新成功' };
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
return { ret: 1, msg: error.message };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** 删除自动化任务 */
|
|
120
|
+
async remove(id) {
|
|
121
|
+
try {
|
|
122
|
+
// 注销调度
|
|
123
|
+
this.automationService.unscheduleJob(id);
|
|
124
|
+
await this.dataSource.query('UPDATE t_ai_automation SET is_deleted = 1 WHERE id = ?', [id]);
|
|
125
|
+
return { ret: 0, data: null, msg: '删除成功' };
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
return { ret: 1, msg: error.message };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** 手动触发自动化任务 */
|
|
132
|
+
async runAutomation(id) {
|
|
133
|
+
try {
|
|
134
|
+
// 通过 AutomationService 实际执行任务
|
|
135
|
+
const result = await this.automationService.executeAutomation(id, 'manual');
|
|
136
|
+
return { ret: 0, data: { result }, msg: '任务执行完成' };
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
return { ret: 1, msg: error.message };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** 获取执行历史 */
|
|
143
|
+
async getRuns(id, body = {}) {
|
|
144
|
+
try {
|
|
145
|
+
const limit = body.limit || 20;
|
|
146
|
+
const offset = body.offset || 0;
|
|
147
|
+
const runs = await this.dataSource.query('SELECT * FROM t_ai_automation_run WHERE automation_id = ? ORDER BY started_at DESC LIMIT ? OFFSET ?', [id, limit, offset]);
|
|
148
|
+
return { ret: 0, data: runs, msg: 'success' };
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return { ret: 1, msg: error.message };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** 获取活跃调度任务数 */
|
|
155
|
+
async getSchedulerStatus() {
|
|
156
|
+
try {
|
|
157
|
+
return {
|
|
158
|
+
ret: 0,
|
|
159
|
+
data: {
|
|
160
|
+
activeJobCount: this.automationService.getActiveJobCount(),
|
|
161
|
+
},
|
|
162
|
+
msg: 'success',
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
return { ret: 1, msg: error.message };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
exports.AutomationController = AutomationController;
|
|
171
|
+
__decorate([
|
|
172
|
+
(0, typeorm_1.InjectDataSource)('default'),
|
|
173
|
+
__metadata("design:type", typeorm_2.DataSource)
|
|
174
|
+
], AutomationController.prototype, "dataSource", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
(0, core_1.Inject)(),
|
|
177
|
+
__metadata("design:type", automation_service_1.AutomationService)
|
|
178
|
+
], AutomationController.prototype, "automationService", void 0);
|
|
179
|
+
__decorate([
|
|
180
|
+
(0, core_1.Get)('/'),
|
|
181
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
182
|
+
__metadata("design:type", Function),
|
|
183
|
+
__metadata("design:paramtypes", []),
|
|
184
|
+
__metadata("design:returntype", Promise)
|
|
185
|
+
], AutomationController.prototype, "list", null);
|
|
186
|
+
__decorate([
|
|
187
|
+
(0, core_1.Get)('/:id'),
|
|
188
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
189
|
+
__param(0, (0, core_1.Param)('id')),
|
|
190
|
+
__metadata("design:type", Function),
|
|
191
|
+
__metadata("design:paramtypes", [Number]),
|
|
192
|
+
__metadata("design:returntype", Promise)
|
|
193
|
+
], AutomationController.prototype, "detail", null);
|
|
194
|
+
__decorate([
|
|
195
|
+
(0, core_1.Post)('/'),
|
|
196
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
197
|
+
__param(0, (0, core_1.Body)()),
|
|
198
|
+
__metadata("design:type", Function),
|
|
199
|
+
__metadata("design:paramtypes", [Object]),
|
|
200
|
+
__metadata("design:returntype", Promise)
|
|
201
|
+
], AutomationController.prototype, "create", null);
|
|
202
|
+
__decorate([
|
|
203
|
+
(0, core_1.Put)('/:id'),
|
|
204
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
205
|
+
__param(0, (0, core_1.Param)('id')),
|
|
206
|
+
__param(1, (0, core_1.Body)()),
|
|
207
|
+
__metadata("design:type", Function),
|
|
208
|
+
__metadata("design:paramtypes", [Number, Object]),
|
|
209
|
+
__metadata("design:returntype", Promise)
|
|
210
|
+
], AutomationController.prototype, "update", null);
|
|
211
|
+
__decorate([
|
|
212
|
+
(0, core_1.Del)('/:id'),
|
|
213
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
214
|
+
__param(0, (0, core_1.Param)('id')),
|
|
215
|
+
__metadata("design:type", Function),
|
|
216
|
+
__metadata("design:paramtypes", [Number]),
|
|
217
|
+
__metadata("design:returntype", Promise)
|
|
218
|
+
], AutomationController.prototype, "remove", null);
|
|
219
|
+
__decorate([
|
|
220
|
+
(0, core_1.Post)('/:id/run'),
|
|
221
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
222
|
+
__param(0, (0, core_1.Param)('id')),
|
|
223
|
+
__metadata("design:type", Function),
|
|
224
|
+
__metadata("design:paramtypes", [Number]),
|
|
225
|
+
__metadata("design:returntype", Promise)
|
|
226
|
+
], AutomationController.prototype, "runAutomation", null);
|
|
227
|
+
__decorate([
|
|
228
|
+
(0, core_1.Get)('/:id/runs'),
|
|
229
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
230
|
+
__param(0, (0, core_1.Param)('id')),
|
|
231
|
+
__param(1, (0, core_1.Body)()),
|
|
232
|
+
__metadata("design:type", Function),
|
|
233
|
+
__metadata("design:paramtypes", [Number, Object]),
|
|
234
|
+
__metadata("design:returntype", Promise)
|
|
235
|
+
], AutomationController.prototype, "getRuns", null);
|
|
236
|
+
__decorate([
|
|
237
|
+
(0, core_1.Get)('/scheduler/status'),
|
|
238
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
239
|
+
__metadata("design:type", Function),
|
|
240
|
+
__metadata("design:paramtypes", []),
|
|
241
|
+
__metadata("design:returntype", Promise)
|
|
242
|
+
], AutomationController.prototype, "getSchedulerStatus", null);
|
|
243
|
+
exports.AutomationController = AutomationController = __decorate([
|
|
244
|
+
(0, core_1.Provide)(),
|
|
245
|
+
(0, core_1.Controller)('/api/automations')
|
|
246
|
+
], AutomationController);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BaseController } from '@cicctencent/midwayjs-base';
|
|
2
|
+
import { ChannelManager } from '../channel';
|
|
3
|
+
export declare class ChannelController extends BaseController {
|
|
4
|
+
channelManager: ChannelManager;
|
|
5
|
+
/**
|
|
6
|
+
* 获取所有渠道状态
|
|
7
|
+
* GET /api/channels/
|
|
8
|
+
*/
|
|
9
|
+
getStatuses(): Promise<{
|
|
10
|
+
ret: number;
|
|
11
|
+
data: import("../channel").ChannelStatus[];
|
|
12
|
+
msg: string;
|
|
13
|
+
} | {
|
|
14
|
+
ret: number;
|
|
15
|
+
msg: any;
|
|
16
|
+
data?: undefined;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* 获取渠道配置(敏感字段脱敏)
|
|
20
|
+
* GET /api/channels/:channel/config
|
|
21
|
+
*/
|
|
22
|
+
getConfig(channel: string): Promise<{
|
|
23
|
+
ret: number;
|
|
24
|
+
data: import("../channel").ChannelConfig;
|
|
25
|
+
msg: string;
|
|
26
|
+
} | {
|
|
27
|
+
ret: number;
|
|
28
|
+
msg: any;
|
|
29
|
+
data?: undefined;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* 更新渠道配置
|
|
33
|
+
* PUT /api/channels/:channel/config
|
|
34
|
+
*/
|
|
35
|
+
updateConfig(channel: string, body: any): Promise<{
|
|
36
|
+
ret: number;
|
|
37
|
+
data: import("../channel").ChannelConfig;
|
|
38
|
+
msg: string;
|
|
39
|
+
} | {
|
|
40
|
+
ret: number;
|
|
41
|
+
msg: any;
|
|
42
|
+
data?: undefined;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Webhook 接收端点
|
|
46
|
+
* POST /api/channels/:channel/webhook
|
|
47
|
+
* 不需要登录,IM 平台直接调用
|
|
48
|
+
*/
|
|
49
|
+
webhook(channel: string, body: any): Promise<any>;
|
|
50
|
+
/**
|
|
51
|
+
* 发送消息(测试用)
|
|
52
|
+
* POST /api/channels/:channel/send
|
|
53
|
+
*/
|
|
54
|
+
sendMessage(channel: string, body: {
|
|
55
|
+
receiveId: string;
|
|
56
|
+
message: string;
|
|
57
|
+
}): Promise<{
|
|
58
|
+
ret: number;
|
|
59
|
+
data: {
|
|
60
|
+
success: boolean;
|
|
61
|
+
};
|
|
62
|
+
msg: string;
|
|
63
|
+
} | {
|
|
64
|
+
ret: number;
|
|
65
|
+
msg: any;
|
|
66
|
+
data?: undefined;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* 异步处理接收到的消息
|
|
70
|
+
* IM 平台要求 webhook 快速返回,消息处理在后台进行
|
|
71
|
+
*/
|
|
72
|
+
private processMessageAsync;
|
|
73
|
+
}
|